Skip to content

Commit 3f7b519

Browse files
Merge pull request #24 from ibm-watson-data-lab/cos_scheme_support_R
COS Scheme Support + Multiple Config Support [R]
2 parents 3bb7e26 + 5c55f15 commit 3f7b519

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

r/sparkr/R/osconfig.R

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,12 @@ bluemix <- setRefClass("bluemix",
126126
#'
127127
#' configurationName: string identifies the configurations that has been
128128
#' set.
129-
#' When using this from a IBM Spark service instance that
130-
#' is configured to connect to particular Bluemix object store
131-
#' instances, the values for these credentials can be obtained
132-
#' by clicking on the 'insert to code' link just below a data
133-
#' source.
134129
#' @export CloudObjectStorage
135130
#' @exportClass CloudObjectStorage
136131
CloudObjectStorage <- setRefClass("CloudObjectStorage",
137132
fields=list(configName="character"),
138133
methods=list(
139-
initialize = function(..., sparkContext, credentials, configurationName){
134+
initialize = function(..., sparkContext, credentials, configurationName="") {
140135

141136

142137
if (is.null(credentials["endpoint"][[1]])) {
@@ -151,20 +146,27 @@ CloudObjectStorage <- setRefClass("CloudObjectStorage",
151146
stop("Attribute secretKey in credentials is missing!")
152147
}
153148

149+
# bind config name
154150
.self$configName = configurationName
155-
prefix = "fs.s3d.service"
151+
152+
# set prefix for hadoop config
153+
prefix = paste("fs.cos", getConfigName(), sep='.')
156154
hConf = SparkR:::callJMethod(sparkContext, "hadoopConfiguration")
157155
SparkR:::callJMethod(hConf, "set", paste(prefix, "endpoint", sep='.'), credentials['endpoint'][[1]])
158156
SparkR:::callJMethod(hConf, "set", paste(prefix, "access.key", sep='.'), credentials['accessKey'][[1]])
159157
SparkR:::callJMethod(hConf, "set", paste(prefix, "secret.key", sep='.'), credentials['secretKey'][[1]])
160158
},
161159

162160
getConfigName = function() {
163-
return (.self$configName)
161+
if (.self$configName != "") {
162+
return (.self$configName)
163+
}
164+
return ("service")
164165
},
165166

166-
url = function(bucketName, objectName){
167-
return(paste("s3d://", bucketName, ".service/", objectName, sep = ""))
167+
url = function(bucketName, objectName) {
168+
serviceName = getConfigName()
169+
return (paste("cos://", bucketName, ".", serviceName, "/", objectName, sep = ""))
168170
}
169171
)
170172
)

0 commit comments

Comments
 (0)