Enable setting log level from command line
[dcaegen2/collectors/hv-ves.git] / sources / hv-collector-utils / src / main / kotlin / org / onap / dcae / collectors / veshv / utils / commandline / CommandLineOption.kt
1 /*
2  * ============LICENSE_START=======================================================
3  * dcaegen2-collectors-veshv
4  * ================================================================================
5  * Copyright (C) 2018 NOKIA
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.dcae.collectors.veshv.utils.commandline
21
22 import org.apache.commons.cli.Option
23
24
25 enum class CommandLineOption(val option: Option, val required: Boolean = false) {
26     HEALTH_CHECK_API_PORT(
27         Option.builder("H")
28             .longOpt("health-check-api-port")
29             .hasArg()
30             .desc("Health check rest api listen port")
31             .build()
32     ),
33     LISTEN_PORT(
34         Option.builder("p")
35             .longOpt("listen-port")
36             .hasArg()
37             .desc("Listen port")
38             .build(),
39         required = true
40     ),
41     CONSUL_CONFIG_URL(
42         Option.builder("c")
43             .longOpt("config-url")
44             .hasArg()
45             .desc("URL of ves configuration on consul")
46             .build(),
47         required = true
48     ),
49     CONSUL_FIRST_REQUEST_DELAY(
50         Option.builder("d")
51             .longOpt("first-request-delay")
52             .hasArg()
53             .desc("Delay of first request to consul in seconds")
54             .build()
55     ),
56     CONSUL_REQUEST_INTERVAL(
57         Option.builder("I")
58             .longOpt("request-interval")
59             .hasArg()
60             .desc("Interval of consul configuration requests in seconds")
61             .build()
62     ),
63     VES_HV_PORT(
64         Option.builder("v")
65             .longOpt("ves-port")
66             .hasArg()
67             .desc("VesHvCollector port")
68             .build(),
69         required = true
70     ),
71     VES_HV_HOST(
72         Option.builder("h")
73             .longOpt("ves-host")
74             .hasArg()
75             .desc("VesHvCollector host")
76             .build(),
77         required = true
78     ),
79     KAFKA_SERVERS(
80         Option.builder("s")
81             .longOpt("kafka-bootstrap-servers")
82             .hasArg()
83             .desc("Comma-separated Kafka bootstrap servers in <host>:<port> format")
84             .build(),
85         required = true
86     ),
87     KAFKA_TOPICS(
88         Option.builder("f")
89             .longOpt("kafka-topics")
90             .hasArg()
91             .desc("Comma-separated Kafka topics")
92             .build(),
93         required = true
94     ),
95     SSL_DISABLE(
96         Option.builder("l")
97             .longOpt("ssl-disable")
98             .desc("Disable SSL encryption")
99             .build()
100     ),
101     KEY_STORE_FILE(
102         Option.builder("k")
103             .longOpt("key-store")
104             .hasArg()
105             .desc("Key store in PKCS12 format")
106             .build()
107     ),
108     KEY_STORE_PASSWORD(
109         Option.builder("kp")
110             .longOpt("key-store-password")
111             .hasArg()
112             .desc("Key store password")
113             .build()
114     ),
115     TRUST_STORE_FILE(
116         Option.builder("t")
117             .longOpt("trust-store")
118             .hasArg()
119             .desc("File with trusted certificate bundle in PKCS12 format")
120             .build()
121     ),
122     TRUST_STORE_PASSWORD(
123         Option.builder("tp")
124             .longOpt("trust-store-password")
125             .hasArg()
126             .desc("Trust store password")
127             .build()
128     ),
129     IDLE_TIMEOUT_SEC(
130         Option.builder("i")
131             .longOpt("idle-timeout-sec")
132             .hasArg()
133             .desc(
134                 """Idle timeout for remote hosts. After given time without any data exchange the
135                 |connection might be closed.""".trimMargin()
136             )
137             .build()
138     ),
139     MAXIMUM_PAYLOAD_SIZE_BYTES(
140         Option.builder("m")
141             .longOpt("max-payload-size")
142             .hasArg()
143             .desc("Maximum supported payload size in bytes")
144             .build()
145     ),
146     LOG_LEVEL(
147         Option.builder("ll")
148             .longOpt("log-level")
149             .hasArg()
150             .desc("Log level")
151             .build()
152     ),
153     DUMMY_MODE(
154         Option.builder("u")
155             .longOpt("dummy")
156             .desc("If present will start in dummy mode (dummy external services)")
157             .build()
158     );
159
160     fun environmentVariableName(prefix: String = DEFAULT_ENV_PREFIX): String =
161         option.longOpt.toUpperCase().replace('-', '_').let { mainPart ->
162             "${prefix}_${mainPart}"
163         }
164
165     companion object {
166         private const val DEFAULT_ENV_PREFIX = "VESHV"
167     }
168 }