@@ -3,6 +3,10 @@ package com.ibm.ibmos2spark
3
3
import scala .collection .mutable .HashMap
4
4
import org .apache .spark .SparkContext
5
5
6
+ object globalVariables {
7
+ val DEFAULT_SERVICE_NAME = " service"
8
+ }
9
+
6
10
7
11
object urlbuilder {
8
12
def swifturl2d (name : String , container_name : String , object_name : String ): String = {
@@ -140,22 +144,12 @@ class bluemix(sc: SparkContext, name: String, creds: HashMap[String, String],
140
144
141
145
* secretKey
142
146
143
- * cosId [optional]: this parameter is the cloud object storage unique id. It is useful
144
- to keep in the class instance for further checks after the initialization. However,
145
- it is not mandatory for the class instance to work. This value can be retrieved by
146
- calling the getCosId function.
147
-
148
- bucket_name (projectId in DSX) [optional]: string that identifies the defult
149
- bucket nameyou want to access files from in the COS service instance.
150
- In DSX, bucket_name is the same as projectId. One bucket is
151
- associated with one project.
152
- If this value is not specified, you need to pass it when
153
- you use the url function.
154
- *
155
- Warning: creating a new instance of this class would overwrite the existing
156
- spark hadoop configs if set before if used with the same spark context instance.
147
+ * configurationName [optional]: string that identifies this configuration. You can
148
+ use any string you like. This allows you to create
149
+ multiple configurations to different Object Storage accounts.
150
+ if a configuration name is not passed the default one will be used "service".
157
151
*/
158
- class CloudObjectStorage (sc : SparkContext , credentials : HashMap [String , String ], cosId : String = " " ) {
152
+ class CloudObjectStorage (sc : SparkContext , credentials : HashMap [String , String ], configurationName : String = " " ) {
159
153
160
154
// check if all credentials are available
161
155
val requiredValues = Array (" endPoint" , " accessKey" , " secretKey" )
@@ -167,16 +161,22 @@ class CloudObjectStorage(sc: SparkContext, credentials: HashMap[String, String],
167
161
168
162
// set config
169
163
val hadoopConf = sc.hadoopConfiguration
170
- val prefix = " fs.s3d.service"
164
+ val prefix = " fs.cos." + getConfigurationName()
165
+
171
166
hadoopConf.set(prefix + " .endpoint" , credentials(" endPoint" ))
172
167
hadoopConf.set(prefix + " .access.key" , credentials(" accessKey" ))
173
168
hadoopConf.set(prefix + " .secret.key" , credentials(" secretKey" ))
174
169
175
- def getCosId () : String = {
176
- return cosId
170
+ private def getConfigurationName () : String = {
171
+ if (configurationName != " " ) {
172
+ return configurationName
173
+ } else {
174
+ return globalVariables.DEFAULT_SERVICE_NAME
175
+ }
177
176
}
178
177
179
178
def url (bucketName : String , objectName : String ) : String = {
180
- return " s3d://" + bucketName + " .service/" + objectName
179
+ var serviceName = getConfigurationName()
180
+ return " cos://" + bucketName + " ." + serviceName + " /" + objectName
181
181
}
182
182
}
0 commit comments