這是一個基本問題,但是,我試圖使用Apache Spark服務中Analytics上的Bluemix筆記本中Scala中的代碼檢索文件的內容,並且關於認證的錯誤不斷彈出。有人有一個用於訪問文件的Scala認證示例嗎?先謝謝你!Bluemix Apache Spark服務 - Scala - 讀取文件
我嘗試以下簡單的腳本:
val file = sc.textFile("swift://notebooks.keystone/kdd99.data")
file.take(1)
我也試過:
def setConfig(name:String) : Unit = {
val pfx = "fs.swift.service." + name
val conf = sc.getConf
conf.set(pfx + "auth.url", "hardcoded")
conf.set(pfx + "tenant", "hardcoded")
conf.set(pfx + "username", "hardcoded")
conf.set(pfx + "password", "hardcoded")
conf.set(pfx + "apikey", "hardcoded")
conf.set(pfx + "auth.endpoint.prefix", "endpoints")
}
setConfig("keystone")
我也試着從以前的問題,這個腳本:
import scala.collection.breakOut
val name= "keystone"
val YOUR_DATASOURCE = """auth_url:https://identity.open.softlayer.com
project: hardcoded
project_id: hardcoded
region: hardcoded
user_id: hardcoded
domain_id: hardcoded
domain_name: hardcoded
username: hardcoded
password: hardcoded
filename: hardcoded
container: hardcoded
tenantId: hardcoded
"""
val settings:Map[String,String] = YOUR_DATASOURCE.split("\\n").
map(l=>(l.split(":",2)(0).trim(), l.split(":",2)(1).trim()))(breakOut)
val conf = sc.getConf conf.set("fs.swift.service.keystone.auth.url",settings.getOrElse("auth_url",""))
conf.set("fs.swift.service.keystone.tenant", settings.getOrElse("tenantId", ""))
conf.set("fs.swift.service.keystone.username", settings.getOrElse("username", ""))
conf.set("fs.swift.service.keystone.password", settings.getOrElse("password", ""))
conf.set("fs.swift.service.keystone.apikey", settings.getOrElse("password", ""))
conf.set("fs.swift.service.keystone.auth.endpoint.prefix", "endpoints")
println("sett: "+ settings.getOrElse("auth_url",""))
val file = sc.textFile("swift://notebooks.keystone/kdd99.data")
/* The following line gives errors */
file.take(1)
誤差低於:
姓名:org.apache.hadoop.fs.swift.exceptions.SwiftConfigurationException 消息:缺少必需的配置選項:fs.swift.service.keystone.auth.url
編輯
這將是一個Python的好選擇。我試過以下,以「火花」作爲配置名稱爲兩個不同的文件:
def set_hadoop_config(credentials):
prefix = "fs.swift.service." + credentials['name']
hconf = sc._jsc.hadoopConfiguration()
hconf.set(prefix + ".auth.url", credentials['auth_url']+'/v3/auth/tokens')
hconf.set(prefix + ".auth.endpoint.prefix", "endpoints")
hconf.set(prefix + ".tenant", credentials['project_id'])
hconf.set(prefix + ".username", credentials['user_id'])
hconf.set(prefix + ".password", credentials['password'])
hconf.setInt(prefix + ".http.port", 8080)
hconf.set(prefix + ".region", credentials['region'])
hconf.setBoolean(prefix + ".public", True)
謝謝NSHUKLA – tbuda
我已經用Python版本編輯了這個問題。你能看看嗎? – tbuda
對於Python,代碼似乎是正確的(您可以參考示例「Analytics Notebooks和Apache Spark」,它具有用於def set_hadoop_config(憑證)的python代碼。 我嘗試過使用keystone名稱的.csv和.txt文件。您是否遇到spark問題,如.data文件中的配置文件,如您所說的與.txt文件一起使用的文件? – NSHUKLA