How to read configuration file parameters in Spark without mapping each parameter

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to read configuration file parameters in Spark without mapping each parameter

Mich Talebzadeh
Hi,

Assume that I have a configuration file as below with static parameters some Strings, Integer and Double:

md_AerospikeAerospike {
dbHost = "rhes75"
dbPort = "3000"
dbConnection = "trading_user_RW"
namespace = "trading"
dbSetRead = "MARKETDATAAEROSPIKEBATCH"
dbSetWrite = "MARKETDATAAEROSPIKESPEED"
dbPassword = "aerospike"
bootstrapServers = "rhes75:9092, rhes75:9093, rhes75:9094, rhes564:9092, rhes564:9093, rhes564:9094, rhes76:9092, rhes76:9093, rhes76:9094"
schemaRegistryURL = "http://rhes75:8081"
zookeeperConnect = "rhes75:2181, rhes564:2181, rhes76:2181"
zookeeperConnectionTimeoutMs = "10000"
rebalanceBackoffMS = "15000"
zookeeperSessionTimeOutMs = "15000"
autoCommitIntervalMS = "12000"
topics = "md"
memorySet = "F"
enableHiveSupport = "true"
sparkStreamingReceiverMaxRate = "0"
checkpointdir = "/checkpoint"
hbaseHost = "rhes75"
zookeeperHost = "rhes75"
zooKeeperClientPort = "2181"
batchInterval = 2
tickerWatch = "VOD"
priceWatch = 300.0
op_type = 1
}

Now in Scala code I do the following to read these parameters in:

  val dbHost = conf.getString("dbHost")
  val dbPort = conf.getString("dbPort")
  val dbConnection = conf.getString("dbConnection")
  val namespace = conf.getString("namespace")
  val dbSetRead = conf.getString("dbSetRead")
  val dbSetWrite = conf.getString("dbSetWrite")
  val dbPassword = conf.getString("dbPassword")
  val bootstrapServers = conf.getString("bootstrapServers")
  val schemaRegistryURL = conf.getString("schemaRegistryURL")
  val zookeeperConnect = conf.getString("zookeeperConnect")
  val zookeeperConnectionTimeoutMs =    conf.getString("zookeeperConnectionTimeoutMs")
  val rebalanceBackoffMS = conf.getString("zookeeperConnectionTimeoutMs")
  val zookeeperSessionTimeOutMs = conf.getString("zookeeperSessionTimeOutMs")
  val autoCommitIntervalMS = conf.getString("autoCommitIntervalMS")
  val topics =  conf.getString("topics")
  val memorySet = conf.getString("memorySet")
  val enableHiveSupport = conf.getString("enableHiveSupport")
  val sparkStreamingReceiverMaxRate = conf.getString("sparkStreamingReceiverMaxRate")
  val checkpointdir = conf.getString("checkpointdir")
  val hbaseHost = conf.getString("hbaseHost")
  val zookeeperHost = conf.getString("zookeeperHost")
  val zooKeeperClientPort = conf.getString("zooKeeperClientPort")
  val batchInterval = conf.getInt("batchInterval")
  val tickerWatch = conf.getString("tickerWatch")
  val priceWatch= conf.getDouble("priceWatch")
  val op_type = conf.getInt("op_type")
  
This is obviously tedious and error prone. Is there anyway of reading these parameters generically through mapping or any other way please?

Thanks

Disclaimer: Use it at your own risk. Any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on this email's technical content is explicitly disclaimed. The author will in no case be liable for any monetary damages arising from such loss, damage or destruction.