|
| 1 | +setOldClass("jobj") |
| 2 | + |
| 3 | + |
| 4 | +swifturl = function(name, container_name, object_name){ |
| 5 | + return(paste0('swift2d://',container_name,'.',name,'/',object_name)) |
| 6 | +} |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +#' sparkcontext is a SparkContext object. |
| 11 | +#' |
| 12 | +#' name is a string that identifies this configuration. You can |
| 13 | +#' use any string you like. This allows you to create |
| 14 | +#' multiple configurations to different Object Storage accounts. |
| 15 | +#' auth_url, username and password are string credentials for your |
| 16 | +#' Softlayer Object Store |
| 17 | +#' @export softlayer |
| 18 | +#' @exportClass softlayer |
| 19 | + |
| 20 | +softlayer <- setRefClass("softlayer", |
| 21 | + fields=list(name="character", container_name="character", object_name="character", |
| 22 | + sparkcontext='jobj', auth_url="character", |
| 23 | + tenant = "character", username="character", password="character"), |
| 24 | + methods=list(initialize = |
| 25 | + function( sparkcontext, name, auth_url, tenant, username, password,public=FALSE, |
| 26 | + swift2d_driver='com.ibm.stocator.fs.ObjectStoreFileSystem'){ |
| 27 | + |
| 28 | + .self$name = name |
| 29 | + # get spark_context |
| 30 | + ctx <- spark_context(sparkcontext) |
| 31 | + |
| 32 | + #set the java spark context |
| 33 | + jsc <- invoke_static( |
| 34 | + sparkcontext, |
| 35 | + "org.apache.spark.api.java.JavaSparkContext", |
| 36 | + "fromSparkContext", |
| 37 | + ctx |
| 38 | + ) |
| 39 | + |
| 40 | + #set the swift configs: |
| 41 | + prefix = paste("fs.swift2d.service" , name, sep =".") |
| 42 | + hconf = jsc %>% invoke("hadoopConfiguration") |
| 43 | + hconf %>% invoke("set", "fs.swift2d.impl", swift2d_driver) |
| 44 | + hconf %>% invoke("set", paste(prefix, "auth.url", sep='.'), auth_url) |
| 45 | + hconf %>% invoke("set", paste(prefix, "username", sep='.'), username) |
| 46 | + hconf %>% invoke("set", paste(prefix, "tenant", sep='.'), tenant) |
| 47 | + hconf %>% invoke("set", paste(prefix, "auth.endpoint.prefix", sep='.'), "endpoints") |
| 48 | + hconf %>% invoke("set", paste(prefix, "auth.method", sep='.'), "swiftauth") |
| 49 | + hconf %>% invoke("set", paste(prefix, "http.port", sep='.'), "8080") |
| 50 | + hconf %>% invoke("set", paste(prefix, "apikey", sep='.'), password) |
| 51 | + invisible(hconf %>% invoke("setBoolean", paste(prefix, "public", sep='.'), public)) |
| 52 | + hconf %>% invoke("set", paste(prefix, "use.get.auth", sep='.'), "true") |
| 53 | + invisible(hconf %>% invoke("setBoolean", paste(prefix, "location-aware", sep='.'), FALSE)) |
| 54 | + hconf %>% invoke("set", paste(prefix, "password", sep='.'), password) |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + }, |
| 59 | + |
| 60 | + url = function(container_name, object_name){ |
| 61 | + return(swifturl(name, container_name, object_name))} |
| 62 | + ) |
| 63 | +) |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +#' sparkcontext: a SparkContext object. |
| 68 | +#' |
| 69 | +#' credentials: a dictionary with the following required keys: |
| 70 | +#' |
| 71 | +#' auth_url |
| 72 | +#' project_id (or projectId) |
| 73 | +#' user_id (or userId) |
| 74 | +#' password |
| 75 | +#' region |
| 76 | +#' and optional key: |
| 77 | +#' name #[to be deprecated] The name of the configuration. |
| 78 | +#' name: string that identifies this configuration. You can |
| 79 | +#' use any string you like. This allows you to create |
| 80 | +#' multiple configurations to different Object Storage accounts. |
| 81 | +#' This is not required at the moment, since credentials['name'] |
| 82 | +#' is still supported. |
| 83 | +#' When using this from a IBM Spark service instance that |
| 84 | +#' is configured to connect to particular Bluemix object store |
| 85 | +#' instances, the values for these credentials can be obtained |
| 86 | +#' by clicking on the 'insert to code' link just below a data |
| 87 | +#' source. |
| 88 | +#' @export bluemix |
| 89 | +#' @exportClass bluemix |
| 90 | + |
| 91 | + |
| 92 | +bluemix <- setRefClass("bluemix", |
| 93 | + fields=list(name="character", credentials = "list", |
| 94 | + sparkcontext='jobj', public = "character"), |
| 95 | + methods=list(initialize = |
| 96 | + function(..., sparkcontext, name=NULL, credentials, |
| 97 | + public=FALSE,swift2d_driver='com.ibm.stocator.fs.ObjectStoreFileSystem'){ |
| 98 | + |
| 99 | + callSuper(...,credentials=credentials) |
| 100 | + |
| 101 | + if ( is.null(name)) name <<- credentials["name"][[1]] |
| 102 | + |
| 103 | + user_id = try( credentials['user_id'][[1]]) |
| 104 | + if(class(user_id)=="try-error") user_id = credentials['userId'][[1]] |
| 105 | + |
| 106 | + tenant = try( credentials['project_id'][[1]]) |
| 107 | + if(class(tenant)=="try-error") tenant = credentials['projectId'][[1]] |
| 108 | + |
| 109 | + .self$name = name |
| 110 | + # get spark_context |
| 111 | + ctx <- spark_context(sparkcontext) |
| 112 | + |
| 113 | + #set the java spark context |
| 114 | + jsc <- invoke_static( |
| 115 | + sparkcontext, |
| 116 | + "org.apache.spark.api.java.JavaSparkContext", |
| 117 | + "fromSparkContext", |
| 118 | + ctx |
| 119 | + ) |
| 120 | + |
| 121 | + #set the swift configs: |
| 122 | + prefix = paste("fs.swift2d.service" , name, sep =".") |
| 123 | + hconf = jsc %>% invoke("hadoopConfiguration") |
| 124 | + hconf %>% invoke("set", "fs.swift2d.impl", swift2d_driver) |
| 125 | + hconf %>% invoke("set", paste(prefix, "auth.url", sep='.'), paste(credentials['auth_url'][[1]],"/v3/auth/tokens",sep="")) |
| 126 | + hconf %>% invoke("set", paste(prefix, "auth.endpoint.prefix", sep='.'), "endpoints") |
| 127 | + hconf %>% invoke("set", paste(prefix, "tenant", sep='.'), tenant) |
| 128 | + hconf %>% invoke("set", paste(prefix, "username", sep='.'), user_id) |
| 129 | + hconf %>% invoke("set", paste(prefix, "password", sep='.'), credentials['password'][[1]]) |
| 130 | + hconf %>% invoke("set", paste(prefix, "auth.method", sep='.'), "keystoneV3") |
| 131 | + hconf %>% invoke("set", paste(prefix, "region", sep='.'), credentials['region'][[1]]) |
| 132 | + invisible(hconf %>% invoke("setBoolean", paste(prefix, "public", sep='.'), public)) |
| 133 | + #invisible(SparkR:::callJMethod(hConf, "setInt", paste(prefix, "http.port", sep='.'), 8080)) |
| 134 | + }, |
| 135 | + |
| 136 | + url = function( container_name, object_name){ |
| 137 | + return(swifturl(name, container_name, object_name))} |
| 138 | + ) |
| 139 | +) |
0 commit comments