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 | */ |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 16 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 17 | package config |
| 18 | |
| 19 | import ( |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 20 | "flag" |
| 21 | "fmt" |
Girish Kumar | 4d3887d | 2019-11-22 14:22:05 +0000 | [diff] [blame] | 22 | "time" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 23 | ) |
| 24 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 25 | // RW Core service default constants |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 26 | const ( |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 27 | ConsulStoreName = "consul" |
| 28 | EtcdStoreName = "etcd" |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 29 | defaultGrpcAddress = ":50057" |
| 30 | defaultKafkaAdapterAddress = "127.0.0.1:9092" |
| 31 | defaultKafkaClusterAddress = "127.0.0.1:9094" |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 32 | defaultKVStoreType = EtcdStoreName |
Neha Sharma | 7d6f3a9 | 2020-04-14 15:26:22 +0000 | [diff] [blame] | 33 | defaultKVStoreTimeout = 5 * time.Second |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 34 | defaultKVStoreAddress = "127.0.0.1:2379" // Consul = 8500; Etcd = 2379 |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 35 | defaultKVTxnKeyDelTime = 60 |
David Bainbridge | 48d46e1 | 2020-03-17 15:05:55 -0700 | [diff] [blame] | 36 | defaultLogLevel = "WARN" |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 37 | defaultBanner = false |
| 38 | defaultDisplayVersionOnly = false |
| 39 | defaultCoreTopic = "rwcore" |
| 40 | defaultRWCoreEndpoint = "rwcore" |
| 41 | defaultRWCoreKey = "pki/voltha.key" |
| 42 | defaultRWCoreCert = "pki/voltha.crt" |
| 43 | defaultRWCoreCA = "pki/voltha-CA.pem" |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 44 | defaultLongRunningRequestTimeout = 2000 * time.Millisecond |
| 45 | defaultDefaultRequestTimeout = 1000 * time.Millisecond |
| 46 | defaultCoreTimeout = 1000 * time.Millisecond |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 47 | defaultCoreBindingKey = "voltha_backend_name" |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 48 | defaultMaxConnectionRetries = -1 // retries forever |
| 49 | defaultConnectionRetryInterval = 2 * time.Second |
| 50 | defaultLiveProbeInterval = 60 * time.Second |
| 51 | defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 52 | defaultProbeAddress = ":8080" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 53 | ) |
| 54 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 55 | // RWCoreFlags represents the set of configurations used by the read-write core service |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 56 | type RWCoreFlags struct { |
| 57 | // Command line parameters |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 58 | RWCoreEndpoint string |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 59 | GrpcAddress string |
| 60 | KafkaAdapterAddress string |
| 61 | KafkaClusterAddress string |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 62 | KVStoreType string |
Neha Sharma | 7d6f3a9 | 2020-04-14 15:26:22 +0000 | [diff] [blame] | 63 | KVStoreTimeout time.Duration |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 64 | KVStoreAddress string |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 65 | KVTxnKeyDelTime int |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 66 | CoreTopic string |
Rohan Agrawal | 7f72f0c | 2020-01-14 12:05:51 +0000 | [diff] [blame] | 67 | LogLevel string |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 68 | Banner bool |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 69 | DisplayVersionOnly bool |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 70 | RWCoreKey string |
| 71 | RWCoreCert string |
| 72 | RWCoreCA string |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 73 | LongRunningRequestTimeout time.Duration |
| 74 | DefaultRequestTimeout time.Duration |
| 75 | DefaultCoreTimeout time.Duration |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 76 | CoreBindingKey string |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 77 | MaxConnectionRetries int |
Girish Kumar | 4d3887d | 2019-11-22 14:22:05 +0000 | [diff] [blame] | 78 | ConnectionRetryInterval time.Duration |
| 79 | LiveProbeInterval time.Duration |
| 80 | NotLiveProbeInterval time.Duration |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 81 | ProbeAddress string |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 82 | } |
| 83 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 84 | // NewRWCoreFlags returns a new RWCore config |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 85 | func NewRWCoreFlags() *RWCoreFlags { |
| 86 | var rwCoreFlag = RWCoreFlags{ // Default values |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 87 | RWCoreEndpoint: defaultRWCoreEndpoint, |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 88 | GrpcAddress: defaultGrpcAddress, |
| 89 | KafkaAdapterAddress: defaultKafkaAdapterAddress, |
| 90 | KafkaClusterAddress: defaultKafkaClusterAddress, |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 91 | KVStoreType: defaultKVStoreType, |
| 92 | KVStoreTimeout: defaultKVStoreTimeout, |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 93 | KVStoreAddress: defaultKVStoreAddress, |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 94 | KVTxnKeyDelTime: defaultKVTxnKeyDelTime, |
| 95 | CoreTopic: defaultCoreTopic, |
| 96 | LogLevel: defaultLogLevel, |
| 97 | Banner: defaultBanner, |
| 98 | DisplayVersionOnly: defaultDisplayVersionOnly, |
| 99 | RWCoreKey: defaultRWCoreKey, |
| 100 | RWCoreCert: defaultRWCoreCert, |
| 101 | RWCoreCA: defaultRWCoreCA, |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 102 | DefaultRequestTimeout: defaultDefaultRequestTimeout, |
| 103 | LongRunningRequestTimeout: defaultLongRunningRequestTimeout, |
| 104 | DefaultCoreTimeout: defaultCoreTimeout, |
| 105 | CoreBindingKey: defaultCoreBindingKey, |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 106 | MaxConnectionRetries: defaultMaxConnectionRetries, |
| 107 | ConnectionRetryInterval: defaultConnectionRetryInterval, |
| 108 | LiveProbeInterval: defaultLiveProbeInterval, |
| 109 | NotLiveProbeInterval: defaultNotLiveProbeInterval, |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 110 | ProbeAddress: defaultProbeAddress, |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 111 | } |
| 112 | return &rwCoreFlag |
| 113 | } |
| 114 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 115 | // ParseCommandArguments parses the arguments when running read-write core service |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 116 | func (cf *RWCoreFlags) ParseCommandArguments() { |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 117 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 118 | help := fmt.Sprintf("RW core endpoint address") |
| 119 | flag.StringVar(&(cf.RWCoreEndpoint), "vcore-endpoint", defaultRWCoreEndpoint, help) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 120 | |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 121 | help = fmt.Sprintf("GRPC server - address") |
| 122 | flag.StringVar(&(cf.GrpcAddress), "grpc_address", defaultGrpcAddress, help) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 123 | |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 124 | help = fmt.Sprintf("Kafka - Adapter messaging address") |
| 125 | flag.StringVar(&(cf.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaAdapterAddress, help) |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 126 | |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 127 | help = fmt.Sprintf("Kafka - Cluster messaging address") |
| 128 | flag.StringVar(&(cf.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaClusterAddress, help) |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 129 | |
| 130 | help = fmt.Sprintf("RW Core topic") |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 131 | flag.StringVar(&(cf.CoreTopic), "rw_core_topic", defaultCoreTopic, help) |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 132 | |
David Bainbridge | 9ae1313 | 2020-06-22 17:28:01 -0700 | [diff] [blame] | 133 | flag.Bool("in_competing_mode", false, "deprecated") |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 134 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 135 | help = fmt.Sprintf("KV store type") |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 136 | flag.StringVar(&(cf.KVStoreType), "kv_store_type", defaultKVStoreType, help) |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 137 | |
| 138 | help = fmt.Sprintf("The default timeout when making a kv store request") |
Neha Sharma | 7d6f3a9 | 2020-04-14 15:26:22 +0000 | [diff] [blame] | 139 | flag.DurationVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", defaultKVStoreTimeout, help) |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 140 | |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 141 | help = fmt.Sprintf("KV store address") |
| 142 | flag.StringVar(&(cf.KVStoreAddress), "kv_store_address", defaultKVStoreAddress, help) |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 143 | |
Richard Jankowski | e4d7766 | 2018-10-17 13:53:21 -0400 | [diff] [blame] | 144 | help = fmt.Sprintf("The time to wait before deleting a completed transaction key") |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 145 | flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", defaultKVTxnKeyDelTime, help) |
Richard Jankowski | e4d7766 | 2018-10-17 13:53:21 -0400 | [diff] [blame] | 146 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 147 | help = fmt.Sprintf("Log level") |
Rohan Agrawal | 7f72f0c | 2020-01-14 12:05:51 +0000 | [diff] [blame] | 148 | flag.StringVar(&(cf.LogLevel), "log_level", defaultLogLevel, help) |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 149 | |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 150 | help = fmt.Sprintf("Timeout for long running request") |
Neha Sharma | 7d6f3a9 | 2020-04-14 15:26:22 +0000 | [diff] [blame] | 151 | flag.DurationVar(&(cf.LongRunningRequestTimeout), "timeout_long_request", defaultLongRunningRequestTimeout, help) |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 152 | |
| 153 | help = fmt.Sprintf("Default timeout for regular request") |
Neha Sharma | 7d6f3a9 | 2020-04-14 15:26:22 +0000 | [diff] [blame] | 154 | flag.DurationVar(&(cf.DefaultRequestTimeout), "timeout_request", defaultDefaultRequestTimeout, help) |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 155 | |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 156 | help = fmt.Sprintf("Default Core timeout") |
Neha Sharma | 7d6f3a9 | 2020-04-14 15:26:22 +0000 | [diff] [blame] | 157 | flag.DurationVar(&(cf.DefaultCoreTimeout), "core_timeout", defaultCoreTimeout, help) |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 158 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 159 | help = fmt.Sprintf("Show startup banner log lines") |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 160 | flag.BoolVar(&cf.Banner, "banner", defaultBanner, help) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 161 | |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 162 | help = fmt.Sprintf("Show version information and exit") |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 163 | flag.BoolVar(&cf.DisplayVersionOnly, "version", defaultDisplayVersionOnly, help) |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 164 | |
Richard Jankowski | 46464e9 | 2019-03-05 11:53:55 -0500 | [diff] [blame] | 165 | help = fmt.Sprintf("The name of the meta-key whose value is the rw-core group to which the ofagent is bound") |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 166 | flag.StringVar(&(cf.CoreBindingKey), "core_binding_key", defaultCoreBindingKey, help) |
Richard Jankowski | 46464e9 | 2019-03-05 11:53:55 -0500 | [diff] [blame] | 167 | |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 168 | help = fmt.Sprintf("The number of retries to connect to a dependent component") |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 169 | flag.IntVar(&(cf.MaxConnectionRetries), "max_connection_retries", defaultMaxConnectionRetries, help) |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 170 | |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 171 | help = fmt.Sprintf("The number of seconds between each connection retry attempt") |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 172 | flag.DurationVar(&(cf.ConnectionRetryInterval), "connection_retry_interval", defaultConnectionRetryInterval, help) |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 173 | |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 174 | help = fmt.Sprintf("The number of seconds between liveness probes while in a live state") |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 175 | flag.DurationVar(&(cf.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help) |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 176 | |
| 177 | help = fmt.Sprintf("The number of seconds between liveness probes while in a not live state") |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 178 | flag.DurationVar(&(cf.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help) |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 179 | |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 180 | help = fmt.Sprintf("The address on which to listen to answer liveness and readiness probe queries over HTTP.") |
| 181 | flag.StringVar(&(cf.ProbeAddress), "probe_address", defaultProbeAddress, help) |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 182 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 183 | flag.Parse() |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 184 | } |