@@ -174,15 +174,17 @@ def url(self, container_name, object_name):
174
174
175
175
class CloudObjectStorage (object ):
176
176
177
- def __init__ (self , sparkcontext , bucket_name , credentials ):
177
+ def __init__ (self , sparkcontext , credentials , bucket_name = '' ):
178
178
179
179
'''
180
180
sparkcontext: a SparkContext object.
181
181
182
- bucket_name (projectId in DSX): string that identifies the bucket you want
182
+ bucket_name (projectId in DSX) [optional] : string that identifies the bucket you want
183
183
to access files from in the COS service instance.
184
184
In DSX, bucket_name is the same as projectId. One bucket is
185
185
associated with one project.
186
+ If this value is not specified, you need to pass it when
187
+ you use the url function.
186
188
187
189
credentials: a dictionary with the following required keys:
188
190
* endpoint
@@ -194,7 +196,6 @@ def __init__(self, sparkcontext, bucket_name, credentials):
194
196
choose the datasource you want to access then hit insert credentials.
195
197
196
198
'''
197
-
198
199
self .bucket_name = bucket_name
199
200
200
201
# check if all required values are availble
@@ -212,5 +213,13 @@ def __init__(self, sparkcontext, bucket_name, credentials):
212
213
hconf .set (prefix + ".access.key" , credentials ['access_key' ])
213
214
hconf .set (prefix + ".secret.key" , credentials ['secret_key' ])
214
215
215
- def url (self , object_name ):
216
- return "s3d://{}.service/{}" .format (self .bucket_name , object_name )
216
+ def url (self , object_name , bucket_name = '' ):
217
+ bucket_name_var = ''
218
+ if (bucket_name ):
219
+ bucket_name_var = bucket_name
220
+ elif (self .bucket_name ):
221
+ bucket_name_var = self .bucket_name
222
+ else :
223
+ raise ValueError ("Invalid input: bucket_name is required!" )
224
+
225
+ return "s3d://{}.service/{}" .format (bucket_name_var , object_name )
0 commit comments