当前位置:网站首页>Args parameter parsing
Args parameter parsing
2022-07-25 15:16:00 【The south wind knows what I mean】
List of articles
Pain points
def main(args: Array[String]): Unit
In general, we go through args(0),args(1)... Take the parameters passed into the program , It's ok if there's less , Once there are many parameters It's going to be messy , After a long time , We don't know the meaning of the passed parameters
Similar effect
Usage: hadoop fs [generic options]
[-appendToFile <localsrc> ... <dst>]
[-cat [-ignoreCrc] <src> ...]
[-checksum <src> ...]
[-chgrp [-R] GROUP PATH...]
[-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...]
[-chown [-R] [OWNER][:[GROUP]] PATH...]
[-copyFromLocal [-f] [-p] [-l] [-d] [-t <thread count>] <localsrc> ... <dst>]
[-copyToLocal [-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-count [-q] [-h] [-v] [-t [<storage type>]] [-u] [-x] [-e] <path> ...]
[-cp [-f] [-p | -p[topax]] [-d] <src> ... <dst>]
[-createSnapshot <snapshotDir> [<snapshotName>]]
[-deleteSnapshot <snapshotDir> <snapshotName>]
[-df [-h] [<path> ...]]
[-du [-s] [-h] [-v] [-x] <path> ...]
[-expunge]
Realization -scala
private val options: Options = new Options
private val option_h_desc: String =
""" |print help info |usage: | java -cp jarLocation fullClassName [-h] || [-t]&&[-g]&&[-maxR] 1> applicationName.log 2>&1 & | |data flow: | kafka => Spark Streaming | RedisStateStorePerDay | |programs: | SampleFirstScanStateLaunch => -t&&-g&&-i&&-maxR | SampleFirstScanSinkHbaseLaunch => -pn&&-pt&&-t&&-g&&-i&&-maxR | SampleFirstScanSinkHiveLaunch => -hd&&-ht&&-t&&-g&&-i&&-maxR |outer: | 1.maxRatePerPartition throughput default 1000. | 2.phoenix table name && namespace Capital | | |""".stripMargin
options.addOption("h", "help", false, option_h_desc)
options.addOption("t", "topic", true, "kafka topic")
options.addOption("g", "group.id", true, "kafka consumer group id")
options.addOption("maxR", "maxRatePerPartition", true, "kafka topic partition max Rate")
options.addOption("i", "interval", true, "SparkStreaming direct Kafka Batch Interval [s]")
//hive || phoenix
// options.addOption("hd", "hive.database", true, "FirstScanSinkHive hive database")
// options.addOption("ht", "hive.table", true, "FirstScanSinkHive hive table")
options.addOption("pn", "phoenix.namespace", true, "FirstScanSinkPhoenix phoenix namespace")
options.addOption("pt", "phoenix.table", true, "FirstSinkPhoenix phoenix table")
options.addOption("hp", "hp", true, " write in hive still hbase h=hive p=phoenix hp=hive and phoenix")
options.addOption("local", "local", true, " Is it enabled? loncal(*)")
private val parser: PosixParser = new PosixParser
def parseParam(args: Array[String], applicationName: String): ExecutorParam = {
if (args == null) {
logger.error("HR => param is NULL")
System.exit(ERROR_EXIT_STATUS)
}
var line: CommandLine = null
try {
line = parser.parse(options, args)
} catch {
case e: Exception => logger.error("HR => args parse Exception. parse check param")
println(e.getStackTrace.mkString("Array(", ", ", ")"))
System.exit(ERROR_EXIT_STATUS)
}
if (line.hasOption("h")) {
new HelpFormatter().printHelp("desc", options)
System.exit(ERROR_EXIT_STATUS)
}
val topic: String = line.getOptionValue("topic")
val groupId: String = line.getOptionValue("group.id")
val maxRatePerPartition: String = line.getOptionValue("maxRatePerPartition", "1000")
val interval: String = line.getOptionValue("interval")
val hp: String = line.getOptionValue("hp")
val local: String = line.getOptionValue("local")
if (topic == null || groupId == null || interval == null || hp == null || local == null) {
logger.error(s"HR => topic|groupId|interval Exception.parse check param")
System.exit(ERROR_EXIT_STATUS)
}
logger.info(s"HR => paramList[topic : $topic \n groupId : $groupId \n maxRatePerPartition : $maxRatePerPartition \n interval : $interval]")
val phoenixNameSpace: String = line.getOptionValue("phoenix.namespace")
val phoenixTable: String = line.getOptionValue("phoenix.table")
logger.info(s"HR => paramList[ phoenix.namespace : $phoenixNameSpace \n phoenix.table : $phoenixTable]")
// val hiveDatabase: String = line.getOptionValue("hive.database")
// val hiveTable: String = line.getOptionValue("hive.table")
// logger.info(s"HR => paramList[ hive.database : $hiveDatabase \n hive.table : $hiveTable]")
ExecutorParam(topic, groupId, maxRatePerPartition.toInt, interval.toInt, applicationName + hp, phoenixNameSpace, phoenixTable, hp, local.toBoolean)
}
}
case class ExecutorParam(
topic: String,
groupId: String,
maxRatePerPartition: Int,
interval: Int,
applicationName: String,
phoenixNameSpace: String,
phoenixTable: String,
hp: String,
local: Boolean)
How to transmit reference - Example
-maxR 500 \
-t hr_task_scan \
-i 3 \
-g SplitTaskTypeUOFFICIAL \
-pn OFFICIAL \
-pt SAMPLE_U_SCAN,SAMPLE_U_SCAN_LATEST,SAMPLE_T_SCAN_LATEST \
-local false
How to get parameters - Example
// Analytical parameters
val param: ExecutorParam = Constant.parseParam(args, this.getClass.getSimpleName)
// To obtain parameters
val applicationName: String = param.applicationName
val maxRatePerPartition: Int = param.maxRatePerPartition
val conf: SparkConf = new SparkConf()
val topic: String = param.topic
val groupId: String = param.groupId
val local: Boolean = param.local
边栏推荐
- 万能通用智能JS表单验证
- [Nacos] what does nacosclient do during service registration
- C语言函数复习(传值传址【二分查找】,递归【阶乘,汉诺塔等】)
- Spark SQL common time functions
- 一个程序最多可以使用多少内存?
- Meanshift clustering-01 principle analysis
- 继承的实现过程及ES5和ES6实现的区别
- MFC 线程AfxBeginThread基本用法,传多个参数
- Object.prototype. Hasownproperty() and in
- NPM's nexus private server e401 E500 error handling record
猜你喜欢

延迟加载源码剖析:

Boosting之GBDT源码分析

如何解决Visual Studio中scanf编译报错的问题

Overview of JS synchronous, asynchronous, macro task and micro task

VS2010 add WAP mobile form template

Example of password strength verification

Docker上运行redis以配置文件方式启动,连接客户端报错Error: Server closed the connection

Spark提交参数--files的使用

在win10系统下使用命令查看WiFi连接密码

MySQL installation and configuration super detailed tutorial and simple database and table building method
随机推荐
js URLEncode函数
The number of query results of maxcompute SQL is limited to 1W
Object.prototype. Hasownproperty() and in
golang复习总结
When using jetty to run items, an error is reported: form too large or form too many keys
C#,C/S升级更新
ES5写继承的思路
Application of object detection based on OpenCV and yolov3
Single or multiple human posture estimation using openpose
Outline and box shadow to achieve the highlight effect of contour fillet
任务、微任务、队列和调度(动画展示每一步调用)
What is the Internet of things
Rediscluster setup and capacity expansion
String type time comparison method with error string.compareto
Spark AQE
Cmake specify opencv version
MySQL之事务与MVCC
Boosting之GBDT源码分析
Spark002 --- spark task submission, pass JSON as a parameter
Spark sql 常用时间函数