当前位置:网站首页>Args parameter parsing
Args parameter parsing
2022-07-23 10:03: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
边栏推荐
猜你喜欢

kali下安装go环境

卡特兰数---

How to do the system security test? Let's talk about it in detail

Is the sub database and sub table really suitable for your system? Talk about how to select sub databases, sub tables and newsql

141.环形链表

BGP反射器,联邦,选路规则

60道测开面试题,背完直接涨工资

技术分享 | 大事务阻塞 show master status

面试官:解释一下ThreadLocal 核心原理

This is how the permission system is designed, yyds
随机推荐
express操作mysql,sql哪里写错了?
seatunnel 架构
【HiFlow】定期发送腾讯云短信发送群
non-Boost Asio 笔记: UDP UART SocketCAN Multicast UDS
60道测开面试题,背完直接涨工资
数学向量基本知识
This is how the permission system is designed, yyds
CAD如何绘制带有弧形的箭头
PHP 将 ASCII 码转为字符串,字符串转换 ASCII 码
电脑一直按键如何处理
Redis 6.0源码学习 Simple Dynamic String
【学习笔记】Node--从0基础到实战企业官网
nchar字符引起的ora-12899错误
pycharm安装库的时候报错Try to run this command from the system terminal. Make sure that you use the correct
es6相关面试题3
【PyTorch】cuda()与to(device)的区别
7月排行榜新看点?这个语言无敌了?
webshell管理工具及其流量特征分析
【Node中间层实践(三)】----模板引擎pug
《nlp入门+实战:第一章:深度学习和神经网络》