khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 16 | package config |
| 17 | |
| 18 | import ( |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 19 | "flag" |
| 20 | "fmt" |
Scott Baker | 807addd | 2019-10-24 15:16:21 -0700 | [diff] [blame] | 21 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 22 | ) |
| 23 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 24 | // RW Core service default constants |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 25 | const ( |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 26 | ConsulStoreName = "consul" |
| 27 | EtcdStoreName = "etcd" |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 28 | default_GrpcPort = 50057 |
| 29 | default_GrpcHost = "" |
| 30 | default_KafkaAdapterHost = "127.0.0.1" |
| 31 | default_KafkaAdapterPort = 9092 |
| 32 | default_KafkaClusterHost = "127.0.0.1" |
| 33 | default_KafkaClusterPort = 9094 |
| 34 | default_KVStoreType = EtcdStoreName |
| 35 | default_KVStoreTimeout = 5 //in seconds |
| 36 | default_KVStoreHost = "127.0.0.1" |
| 37 | default_KVStorePort = 2379 // Consul = 8500; Etcd = 2379 |
| 38 | default_KVTxnKeyDelTime = 60 |
| 39 | default_KVStoreDataPrefix = "service/voltha" |
| 40 | default_LogLevel = 0 |
| 41 | default_Banner = false |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 42 | default_DisplayVersionOnly = false |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 43 | default_CoreTopic = "rwcore" |
| 44 | default_RWCoreEndpoint = "rwcore" |
| 45 | default_RWCoreKey = "pki/voltha.key" |
| 46 | default_RWCoreCert = "pki/voltha.crt" |
| 47 | default_RWCoreCA = "pki/voltha-CA.pem" |
| 48 | default_AffinityRouterTopic = "affinityRouter" |
| 49 | default_InCompetingMode = true |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 50 | default_LongRunningRequestTimeout = int64(2000) |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 51 | default_DefaultRequestTimeout = int64(500) |
| 52 | default_CoreTimeout = int64(500) |
| 53 | default_CoreBindingKey = "voltha_backend_name" |
Kent Hagerman | a6d0c36 | 2019-07-30 12:50:21 -0400 | [diff] [blame] | 54 | default_CorePairTopic = "rwcore_1" |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 55 | default_MaxConnectionRetries = -1 // retries forever |
| 56 | default_ConnectionRetryInterval = 2 // in seconds |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 57 | default_LiveProbeInterval = 60 // in seconds |
| 58 | default_NotLiveProbeInterval = 60 // in seconds |
Kent Hagerman | c461883 | 2019-10-07 12:24:36 -0400 | [diff] [blame] | 59 | default_ProbeHost = "" |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 60 | default_ProbePort = 8080 |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 61 | ) |
| 62 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 63 | // RWCoreFlags represents the set of configurations used by the read-write core service |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 64 | type RWCoreFlags struct { |
| 65 | // Command line parameters |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 66 | RWCoreEndpoint string |
| 67 | GrpcHost string |
| 68 | GrpcPort int |
| 69 | KafkaAdapterHost string |
| 70 | KafkaAdapterPort int |
| 71 | KafkaClusterHost string |
| 72 | KafkaClusterPort int |
| 73 | KVStoreType string |
| 74 | KVStoreTimeout int // in seconds |
| 75 | KVStoreHost string |
| 76 | KVStorePort int |
| 77 | KVTxnKeyDelTime int |
| 78 | KVStoreDataPrefix string |
| 79 | CoreTopic string |
| 80 | LogLevel int |
| 81 | Banner bool |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 82 | DisplayVersionOnly bool |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 83 | RWCoreKey string |
| 84 | RWCoreCert string |
| 85 | RWCoreCA string |
| 86 | AffinityRouterTopic string |
| 87 | InCompetingMode bool |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 88 | LongRunningRequestTimeout int64 |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 89 | DefaultRequestTimeout int64 |
| 90 | DefaultCoreTimeout int64 |
| 91 | CoreBindingKey string |
Kent Hagerman | a6d0c36 | 2019-07-30 12:50:21 -0400 | [diff] [blame] | 92 | CorePairTopic string |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 93 | MaxConnectionRetries int |
| 94 | ConnectionRetryInterval int |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 95 | LiveProbeInterval int |
| 96 | NotLiveProbeInterval int |
Kent Hagerman | c461883 | 2019-10-07 12:24:36 -0400 | [diff] [blame] | 97 | ProbeHost string |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 98 | ProbePort int |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 99 | } |
| 100 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 101 | func init() { |
| 102 | log.AddPackage(log.JSON, log.WarnLevel, nil) |
| 103 | } |
| 104 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 105 | // NewRWCoreFlags returns a new RWCore config |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 106 | func NewRWCoreFlags() *RWCoreFlags { |
| 107 | var rwCoreFlag = RWCoreFlags{ // Default values |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 108 | RWCoreEndpoint: default_RWCoreEndpoint, |
| 109 | GrpcHost: default_GrpcHost, |
| 110 | GrpcPort: default_GrpcPort, |
| 111 | KafkaAdapterHost: default_KafkaAdapterHost, |
| 112 | KafkaAdapterPort: default_KafkaAdapterPort, |
| 113 | KafkaClusterHost: default_KafkaClusterHost, |
| 114 | KafkaClusterPort: default_KafkaClusterPort, |
| 115 | KVStoreType: default_KVStoreType, |
| 116 | KVStoreTimeout: default_KVStoreTimeout, |
| 117 | KVStoreHost: default_KVStoreHost, |
| 118 | KVStorePort: default_KVStorePort, |
| 119 | KVStoreDataPrefix: default_KVStoreDataPrefix, |
| 120 | KVTxnKeyDelTime: default_KVTxnKeyDelTime, |
| 121 | CoreTopic: default_CoreTopic, |
| 122 | LogLevel: default_LogLevel, |
| 123 | Banner: default_Banner, |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 124 | DisplayVersionOnly: default_DisplayVersionOnly, |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 125 | RWCoreKey: default_RWCoreKey, |
| 126 | RWCoreCert: default_RWCoreCert, |
| 127 | RWCoreCA: default_RWCoreCA, |
| 128 | AffinityRouterTopic: default_AffinityRouterTopic, |
| 129 | InCompetingMode: default_InCompetingMode, |
| 130 | DefaultRequestTimeout: default_DefaultRequestTimeout, |
| 131 | LongRunningRequestTimeout: default_LongRunningRequestTimeout, |
| 132 | DefaultCoreTimeout: default_CoreTimeout, |
| 133 | CoreBindingKey: default_CoreBindingKey, |
Kent Hagerman | a6d0c36 | 2019-07-30 12:50:21 -0400 | [diff] [blame] | 134 | CorePairTopic: default_CorePairTopic, |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 135 | MaxConnectionRetries: default_MaxConnectionRetries, |
| 136 | ConnectionRetryInterval: default_ConnectionRetryInterval, |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 137 | LiveProbeInterval: default_LiveProbeInterval, |
| 138 | NotLiveProbeInterval: default_NotLiveProbeInterval, |
Kent Hagerman | c461883 | 2019-10-07 12:24:36 -0400 | [diff] [blame] | 139 | ProbeHost: default_ProbeHost, |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 140 | ProbePort: default_ProbePort, |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 141 | } |
| 142 | return &rwCoreFlag |
| 143 | } |
| 144 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 145 | // ParseCommandArguments parses the arguments when running read-write core service |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 146 | func (cf *RWCoreFlags) ParseCommandArguments() { |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 147 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 148 | var help string |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 149 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 150 | help = fmt.Sprintf("RW core endpoint address") |
| 151 | flag.StringVar(&(cf.RWCoreEndpoint), "vcore-endpoint", default_RWCoreEndpoint, help) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 152 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 153 | help = fmt.Sprintf("GRPC server - host") |
| 154 | flag.StringVar(&(cf.GrpcHost), "grpc_host", default_GrpcHost, help) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 155 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 156 | help = fmt.Sprintf("GRPC server - port") |
| 157 | flag.IntVar(&(cf.GrpcPort), "grpc_port", default_GrpcPort, help) |
| 158 | |
| 159 | help = fmt.Sprintf("Kafka - Adapter messaging host") |
| 160 | flag.StringVar(&(cf.KafkaAdapterHost), "kafka_adapter_host", default_KafkaAdapterHost, help) |
| 161 | |
| 162 | help = fmt.Sprintf("Kafka - Adapter messaging port") |
| 163 | flag.IntVar(&(cf.KafkaAdapterPort), "kafka_adapter_port", default_KafkaAdapterPort, help) |
| 164 | |
| 165 | help = fmt.Sprintf("Kafka - Cluster messaging host") |
| 166 | flag.StringVar(&(cf.KafkaClusterHost), "kafka_cluster_host", default_KafkaClusterHost, help) |
| 167 | |
| 168 | help = fmt.Sprintf("Kafka - Cluster messaging port") |
| 169 | flag.IntVar(&(cf.KafkaClusterPort), "kafka_cluster_port", default_KafkaClusterPort, help) |
| 170 | |
| 171 | help = fmt.Sprintf("RW Core topic") |
| 172 | flag.StringVar(&(cf.CoreTopic), "rw_core_topic", default_CoreTopic, help) |
| 173 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 174 | help = fmt.Sprintf("Affinity Router topic") |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 175 | flag.StringVar(&(cf.AffinityRouterTopic), "affinity_router_topic", default_AffinityRouterTopic, help) |
| 176 | |
| 177 | help = fmt.Sprintf("In competing Mode - two cores competing to handle a transaction ") |
| 178 | flag.BoolVar(&cf.InCompetingMode, "in_competing_mode", default_InCompetingMode, help) |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 179 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 180 | help = fmt.Sprintf("KV store type") |
| 181 | flag.StringVar(&(cf.KVStoreType), "kv_store_type", default_KVStoreType, help) |
| 182 | |
| 183 | help = fmt.Sprintf("The default timeout when making a kv store request") |
| 184 | flag.IntVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", default_KVStoreTimeout, help) |
| 185 | |
| 186 | help = fmt.Sprintf("KV store host") |
| 187 | flag.StringVar(&(cf.KVStoreHost), "kv_store_host", default_KVStoreHost, help) |
| 188 | |
| 189 | help = fmt.Sprintf("KV store port") |
| 190 | flag.IntVar(&(cf.KVStorePort), "kv_store_port", default_KVStorePort, help) |
| 191 | |
Richard Jankowski | e4d7766 | 2018-10-17 13:53:21 -0400 | [diff] [blame] | 192 | help = fmt.Sprintf("The time to wait before deleting a completed transaction key") |
| 193 | flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", default_KVTxnKeyDelTime, help) |
| 194 | |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 195 | help = fmt.Sprintf("KV store data prefix") |
| 196 | flag.StringVar(&(cf.KVStoreDataPrefix), "kv_store_data_prefix", default_KVStoreDataPrefix, help) |
| 197 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 198 | help = fmt.Sprintf("Log level") |
| 199 | flag.IntVar(&(cf.LogLevel), "log_level", default_LogLevel, help) |
| 200 | |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 201 | help = fmt.Sprintf("Timeout for long running request") |
| 202 | flag.Int64Var(&(cf.LongRunningRequestTimeout), "timeout_long_request", default_LongRunningRequestTimeout, help) |
| 203 | |
| 204 | help = fmt.Sprintf("Default timeout for regular request") |
| 205 | flag.Int64Var(&(cf.DefaultRequestTimeout), "timeout_request", default_DefaultRequestTimeout, help) |
| 206 | |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 207 | help = fmt.Sprintf("Default Core timeout") |
| 208 | flag.Int64Var(&(cf.DefaultCoreTimeout), "core_timeout", default_CoreTimeout, help) |
| 209 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 210 | help = fmt.Sprintf("Show startup banner log lines") |
| 211 | flag.BoolVar(&cf.Banner, "banner", default_Banner, help) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 212 | |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 213 | help = fmt.Sprintf("Show version information and exit") |
| 214 | flag.BoolVar(&cf.DisplayVersionOnly, "version", default_DisplayVersionOnly, help) |
| 215 | |
Richard Jankowski | 46464e9 | 2019-03-05 11:53:55 -0500 | [diff] [blame] | 216 | help = fmt.Sprintf("The name of the meta-key whose value is the rw-core group to which the ofagent is bound") |
| 217 | flag.StringVar(&(cf.CoreBindingKey), "core_binding_key", default_CoreBindingKey, help) |
| 218 | |
Kent Hagerman | a6d0c36 | 2019-07-30 12:50:21 -0400 | [diff] [blame] | 219 | help = fmt.Sprintf("Core pairing group topic") |
| 220 | flag.StringVar(&cf.CorePairTopic, "core_pair_topic", default_CorePairTopic, help) |
| 221 | |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 222 | help = fmt.Sprintf("The number of retries to connect to a dependent component") |
| 223 | flag.IntVar(&(cf.MaxConnectionRetries), "max_connection_retries", default_MaxConnectionRetries, help) |
| 224 | |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 225 | help = fmt.Sprintf("The number of seconds between each connection retry attempt") |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 226 | flag.IntVar(&(cf.ConnectionRetryInterval), "connection_retry_interval", default_ConnectionRetryInterval, help) |
| 227 | |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 228 | help = fmt.Sprintf("The number of seconds between liveness probes while in a live state") |
| 229 | flag.IntVar(&(cf.LiveProbeInterval), "live_probe_interval", default_LiveProbeInterval, help) |
| 230 | |
| 231 | help = fmt.Sprintf("The number of seconds between liveness probes while in a not live state") |
| 232 | flag.IntVar(&(cf.NotLiveProbeInterval), "not_live_probe_interval", default_NotLiveProbeInterval, help) |
| 233 | |
Kent Hagerman | c461883 | 2019-10-07 12:24:36 -0400 | [diff] [blame] | 234 | help = fmt.Sprintf("The host on which to listen to answer liveness and readiness probe queries over HTTP.") |
| 235 | flag.StringVar(&(cf.ProbeHost), "probe_host", default_ProbeHost, help) |
| 236 | |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 237 | help = fmt.Sprintf("The port on which to listen to answer liveness and readiness probe queries over HTTP.") |
| 238 | flag.IntVar(&(cf.ProbePort), "probe_port", default_ProbePort, help) |
| 239 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 240 | flag.Parse() |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 241 | } |