9d875571daa855fe6da33e715c44c5b08edc2373
[dcaegen2/collectors/hv-ves.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * dcaegen2-collectors-veshv
4  * ================================================================================
5  * Copyright (C) 2018-2019 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.commandline
21
22 import org.apache.commons.cli.Option
23
24
25 enum class CommandLineOption(val option: Option, val required: Boolean = false) {
26     CONFIGURATION_FILE(required = true,
27             option = option {
28                 shortOpt = "c"
29                 longOpt = "configuration-file"
30                 desc = "Json file containing HV-VES configuration"
31                 hasArgument = true
32             }),
33     LISTEN_PORT(required = true,
34             option = option {
35                 shortOpt = "p"
36                 longOpt = "listen-port"
37                 desc = "Listen port"
38                 hasArgument = true
39             }),
40     VES_HV_PORT(required = true,
41             option = option {
42                 shortOpt = "v"
43                 longOpt = "ves-port"
44                 desc = "VesHvCollector port"
45                 hasArgument = true
46             }),
47     VES_HV_HOST(required = true,
48             option = option {
49                 shortOpt = "h"
50                 longOpt = "ves-host"
51                 desc = "VesHvCollector host"
52                 hasArgument = true
53             }),
54     KAFKA_SERVERS(required = true,
55             option = option {
56                 shortOpt = "s"
57                 longOpt = "kafka-bootstrap-servers"
58                 desc = "Comma-separated Kafka bootstrap servers in <host>:<port> format"
59                 hasArgument = true
60             }),
61     KAFKA_TOPICS(required = true,
62             option = option {
63                 shortOpt = "f"
64                 longOpt = "kafka-topics"
65                 desc = "Comma-separated Kafka topics"
66                 hasArgument = true
67             }),
68     HEALTH_CHECK_API_PORT(option {
69         shortOpt = "H"
70         longOpt = "health-check-api-port"
71         desc = "Health check rest api listen port"
72         hasArgument = true
73     }),
74     SSL_DISABLE(option {
75         shortOpt = "l"
76         longOpt = "ssl-disable"
77         desc = "Disable SSL encryption"
78     }),
79     KEY_STORE_FILE(option {
80         shortOpt = "k"
81         longOpt = "key-store"
82         desc = "Key store in PKCS12 format"
83         hasArgument = true
84     }),
85     KEY_STORE_PASSWORD_FILE(option {
86         shortOpt = "kp"
87         longOpt = "key-store-password-file"
88         desc = "File with key store password"
89         hasArgument = true
90     }),
91     TRUST_STORE_FILE(option {
92         shortOpt = "t"
93         longOpt = "trust-store"
94         desc = "File with trusted certificate bundle in PKCS12 format"
95         hasArgument = true
96     }),
97     TRUST_STORE_PASSWORD_FILE(option {
98         shortOpt = "tp"
99         longOpt = "trust-store-password-file"
100         desc = "File with trust store password"
101         hasArgument = true
102     }),
103     MAXIMUM_PAYLOAD_SIZE_BYTES(option {
104         shortOpt = "m"
105         longOpt = "max-payload-size"
106         desc = "Maximum supported payload size in bytes"
107         hasArgument = true
108     }),
109     DISABLE_PROCESSING(option {
110         shortOpt = "d"
111         longOpt = "disable-processing"
112         desc = "Message queue consumer option. Indicates whether messages should be fully processed"
113     });
114
115     fun environmentVariableName(prefix: String = ""): String =
116             option.longOpt.toUpperCase().replace('-', '_').let { mainPart ->
117                 if (prefix.isNotBlank()) {
118                     "${prefix}_${mainPart}"
119                 } else {
120                     mainPart
121                 }
122             }
123 }
124
125
126 private class OptionDSL {
127     lateinit var shortOpt: String
128     lateinit var longOpt: String
129     lateinit var desc: String
130     var hasArgument: Boolean = false
131 }
132
133 private fun option(conf: OptionDSL.() -> Unit): Option {
134     val dsl = OptionDSL().apply(conf)
135     return Option.builder(dsl.shortOpt)
136             .longOpt(dsl.longOpt)
137             .hasArg(dsl.hasArgument)
138             .desc(dsl.desc)
139             .build()
140 }