Skip to content

Commit 193194b

Browse files
authored
Merge pull request #1241 from ie3-institute/mh/#1192-parameter-cleanup-ArgsParser
Mh/#1192 parameter cleanup args parser
2 parents c50ec9a + 7f96785 commit 193194b

File tree

2 files changed

+3
-98
lines changed

2 files changed

+3
-98
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
202202

203203
### Removed
204204
- Removed `SimonaListerner` and related code [#1205](https://github.com/ie3-institute/simona/issues/1205)
205+
- Removed unused parameters in `ArgsParser` [#1192](https://github.com/ie3-institute/simona/issues/1192), [#1178](https://github.com/ie3-institute/simona/issues/1178)
205206

206207
## [3.0.0] - 2023-08-07
207208

src/main/scala/edu/ie3/simona/config/ArgsParser.scala

Lines changed: 2 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,7 @@ object ArgsParser extends LazyLogging {
2121
mainArgs: Array[String],
2222
configLocation: Option[String] = None,
2323
config: Option[TypesafeConfig] = None,
24-
selectedSubgrids: Option[String] = None,
25-
selectedVoltLvls: Option[String] = None,
26-
clusterType: Option[ClusterType] = None,
27-
nodeHost: Option[String] = None,
28-
nodePort: Option[String] = None,
29-
seedAddress: Option[String] = None,
30-
useLocalWorker: Option[Boolean] = None,
31-
tArgs: Map[String, String] = Map.empty,
32-
) {
33-
val useCluster: Boolean = clusterType.isDefined
34-
}
24+
)
3525

3626
// build the config parser using scopt library
3727
private def buildParser: scoptOptionParser[Arguments] = {
@@ -49,72 +39,6 @@ object ArgsParser extends LazyLogging {
4939
)
5040
.text("Location of the simona config file")
5141
.minOccurs(1)
52-
opt[Map[String, String]]("tArgs")
53-
.action((x, c) => c.copy(tArgs = x))
54-
.text(
55-
"Comma separated list (no whitespaces!) of substitution arguments for simona config."
56-
)
57-
opt[String](name = "subnets")
58-
.action((value, args) => args.copy(selectedSubgrids = Some(value)))
59-
.text("Comma separated list (no whitespaces!) of selected subnets.")
60-
opt[String](name = "voltlevels")
61-
.action((value, args) => args.copy(selectedVoltLvls = Some(value)))
62-
.text("Comma separated list (no whitespaces!) of selected volt levels.")
63-
opt[String]("cluster-type")
64-
.action((value, args) =>
65-
args.copy(clusterType = value.trim.toLowerCase match {
66-
case "master" => Some(MasterNode)
67-
case "seed" => Some(SeedNode)
68-
case _ => None
69-
})
70-
)
71-
.text("If running as a cluster, specify master or seed node.")
72-
opt[String]("node-host")
73-
.action((value, args) => args.copy(nodeHost = Option(value)))
74-
.validate(value =>
75-
if (value.trim.isEmpty) failure("node-host cannot be empty")
76-
else success
77-
)
78-
.text("Host used to run the remote actor system")
79-
opt[String]("node-port")
80-
.action((value, args) => args.copy(nodePort = Option(value)))
81-
.validate(value =>
82-
if (value.trim.isEmpty) failure("node-port cannot be empty")
83-
else success
84-
)
85-
.text("Port used to run the remote actor system")
86-
opt[String]("seed-address")
87-
.action((value, args) => args.copy(seedAddress = Option(value)))
88-
.validate(value =>
89-
if (value.trim.isEmpty) failure("seed-address cannot be empty")
90-
else success
91-
)
92-
.text(
93-
"Comma separated list (no whitespaces!) of initial addresses used for the rest of the cluster to bootstrap"
94-
)
95-
opt[Boolean]("use-local-worker")
96-
.action((value, args) => args.copy(useLocalWorker = Some(value)))
97-
.text(
98-
"Boolean determining whether to use a local worker. " +
99-
"If cluster is NOT enabled this defaults to true and cannot be false. " +
100-
"If cluster is specified then this defaults to false and must be explicitly set to true. " +
101-
"NOTE: For cluster, this will ONLY be checked if cluster-type=master"
102-
)
103-
104-
checkConfig(args =>
105-
if (
106-
args.useCluster && (args.nodeHost.isEmpty || args.nodePort.isEmpty || args.seedAddress.isEmpty)
107-
)
108-
failure(
109-
"If using the cluster then node-host, node-port, and seed-address are required"
110-
)
111-
else if (args.useCluster && !args.useLocalWorker.getOrElse(true))
112-
failure(
113-
"If using the cluster then use-local-worker MUST be true (or unprovided)"
114-
)
115-
else success
116-
)
117-
11842
}
11943
}
12044

@@ -143,17 +67,6 @@ object ArgsParser extends LazyLogging {
14367
)
14468
}
14569

146-
// sealed trait for cluster type
147-
sealed trait ClusterType
148-
149-
private case object MasterNode extends ClusterType {
150-
override def toString = "master"
151-
}
152-
153-
private case object SeedNode extends ClusterType {
154-
override def toString = "worker"
155-
}
156-
15770
/** Prepare the config by parsing the provided program arguments
15871
*
15972
* @param args
@@ -184,23 +97,14 @@ object ArgsParser extends LazyLogging {
18497

18598
val argsConfig =
18699
ConfigFactory.parseString(
187-
s"""config = "${parsedArgs.configLocation.get.replace("\\", "\\\\")}"
188-
|simona.runtime_configuration {
189-
| selectedSubgrids = [${parsedArgs.selectedSubgrids.getOrElse("")}]
190-
| selectedVoltLvls = [${parsedArgs.selectedVoltLvls
191-
.getOrElse("")}]
192-
|}
193-
|""".stripMargin
100+
s"""config = "${parsedArgs.configLocation.get.replace("\\", "\\\\")}""""
194101
)
195102

196-
val tArgsSubstitution = ConfigFactory.parseMap(parsedArgs.tArgs.asJava)
197-
198103
// note: this overrides the default config values provided in the config file!
199104
// THE ORDER OF THE CALLS MATTERS -> the later the call, the more "fallback" -> first config is always the primary one!
200105
// hence if you add some more program arguments, you have to add them before(!) your default config!
201106
// see https://github.com/lightbend/config#merging-config-trees for details on merging configs
202107
val config = argsConfig
203-
.withFallback(tArgsSubstitution)
204108
.withFallback(parsedArgsConfig)
205109
.resolve()
206110

0 commit comments

Comments
 (0)