Skip to content

Commit 74463f2

Browse files
committed
update code to support cos scheme + support multiple configs
1 parent f857cca commit 74463f2

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

scala/src/main/scala/Osconfig.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.ibm.ibmos2spark
33
import scala.collection.mutable.HashMap
44
import org.apache.spark.SparkContext
55

6+
val DEFAULT_SERVICE_NAME = "service"
67

78
object urlbuilder{
89
def swifturl2d(name: String, container_name: String, object_name: String): String = {
@@ -155,7 +156,7 @@ class bluemix(sc: SparkContext, name: String, creds: HashMap[String, String],
155156
Warning: creating a new instance of this class would overwrite the existing
156157
spark hadoop configs if set before if used with the same spark context instance.
157158
*/
158-
class CloudObjectStorage(sc: SparkContext, credentials: HashMap[String, String], cosId: String = "") {
159+
class CloudObjectStorage(sc: SparkContext, credentials: HashMap[String, String], configurationName: String = "") {
159160

160161
// check if all credentials are available
161162
val requiredValues = Array("endPoint", "accessKey", "secretKey")
@@ -167,16 +168,22 @@ class CloudObjectStorage(sc: SparkContext, credentials: HashMap[String, String],
167168

168169
// set config
169170
val hadoopConf = sc.hadoopConfiguration
170-
val prefix = "fs.s3d.service"
171+
val prefix = "fs.cos." + getConfigurationName()
172+
171173
hadoopConf.set(prefix + ".endpoint", credentials("endPoint"))
172174
hadoopConf.set(prefix + ".access.key", credentials("accessKey"))
173175
hadoopConf.set(prefix + ".secret.key", credentials("secretKey"))
174176

175-
def getCosId() : String = {
176-
return cosId
177+
private def getConfigurationName() : String = {
178+
if (configurationName != "") {
179+
return configurationName
180+
} else {
181+
return DEFAULT_SERVICE_NAME
182+
}
177183
}
178184

179185
def url(bucketName: String, objectName: String) : String = {
180-
return "s3d://" + bucketName + ".service/" + objectName
186+
var serviceName = getConfigurationName()
187+
return "cos://" + bucketName + "." + serviceName + "/" + objectName
181188
}
182189
}

0 commit comments

Comments
 (0)