blob: 65109646742a61422a7ec3ac066b71599763adec [file] [log] [blame]
khenaidoobf6e7bb2018-08-14 22:27:29 -04001/*
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 */
npujar1d86a522019-11-14 17:11:16 +053016
khenaidoocfee5f42018-07-19 22:47:38 -040017package config
18
19import (
khenaidoocfee5f42018-07-19 22:47:38 -040020 "flag"
21 "fmt"
Girish Kumar4d3887d2019-11-22 14:22:05 +000022 "time"
khenaidoocfee5f42018-07-19 22:47:38 -040023)
24
khenaidoo5c11af72018-07-20 17:21:05 -040025// RW Core service default constants
khenaidoocfee5f42018-07-19 22:47:38 -040026const (
khenaidoo5e4fca32021-05-12 16:02:23 -040027 EtcdStoreName = "etcd"
28 defaultGrpcAddress = ":50057"
29 defaultKafkaAdapterAddress = "127.0.0.1:9092"
30 defaultKafkaClusterAddress = "127.0.0.1:9094"
31 defaultKVStoreType = EtcdStoreName
32 defaultKVStoreTimeout = 5 * time.Second
33 defaultKVStoreAddress = "127.0.0.1:2379" // Etcd = 2379
34 defaultKVTxnKeyDelTime = 60
35 defaultLogLevel = "WARN"
36 defaultBanner = false
37 defaultDisplayVersionOnly = false
38 defaultCoreTopic = "rwcore"
39 defaultEventTopic = "voltha.events"
40 defaultRWCoreEndpoint = "rwcore"
41 defaultRWCoreKey = "pki/voltha.key"
42 defaultRWCoreCert = "pki/voltha.crt"
43 defaultRWCoreCA = "pki/voltha-CA.pem"
44 defaultLongRunningRequestTimeout = 2000 * time.Millisecond
45 defaultDefaultRequestTimeout = 1000 * time.Millisecond
46 defaultCoreTimeout = 1000 * time.Millisecond
47 defaultCoreBindingKey = "voltha_backend_name"
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
52 defaultProbeAddress = ":8080"
53 defaultTraceEnabled = false
54 defaultTraceAgentAddress = "127.0.0.1:6831"
55 defaultLogCorrelationEnabled = true
56 defaultVolthaStackID = "voltha"
57 defaultBackoffRetryInitialInterval = 500 * time.Millisecond
58 defaultBackoffRetryMaxElapsedTime = 0
59 defaultBackoffRetryMaxInterval = 1 * time.Minute
khenaidoocfee5f42018-07-19 22:47:38 -040060)
61
khenaidoo5c11af72018-07-20 17:21:05 -040062// RWCoreFlags represents the set of configurations used by the read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -040063type RWCoreFlags struct {
64 // Command line parameters
khenaidoo5e4fca32021-05-12 16:02:23 -040065 RWCoreEndpoint string
66 GrpcAddress string
67 KafkaAdapterAddress string
68 KafkaClusterAddress string
69 KVStoreType string
70 KVStoreTimeout time.Duration
71 KVStoreAddress string
72 KVTxnKeyDelTime int
73 CoreTopic string
74 EventTopic string
75 LogLevel string
76 Banner bool
77 DisplayVersionOnly bool
78 RWCoreKey string
79 RWCoreCert string
80 RWCoreCA string
81 LongRunningRequestTimeout time.Duration
82 DefaultRequestTimeout time.Duration
83 DefaultCoreTimeout time.Duration
84 CoreBindingKey string
85 MaxConnectionRetries int
86 ConnectionRetryInterval time.Duration
87 LiveProbeInterval time.Duration
88 NotLiveProbeInterval time.Duration
89 ProbeAddress string
90 TraceEnabled bool
91 TraceAgentAddress string
92 LogCorrelationEnabled bool
93 VolthaStackID string
94 BackoffRetryInitialInterval time.Duration
95 BackoffRetryMaxElapsedTime time.Duration
96 BackoffRetryMaxInterval time.Duration
khenaidoocfee5f42018-07-19 22:47:38 -040097}
98
khenaidoo5c11af72018-07-20 17:21:05 -040099// NewRWCoreFlags returns a new RWCore config
khenaidoocfee5f42018-07-19 22:47:38 -0400100func NewRWCoreFlags() *RWCoreFlags {
101 var rwCoreFlag = RWCoreFlags{ // Default values
khenaidoo5e4fca32021-05-12 16:02:23 -0400102 RWCoreEndpoint: defaultRWCoreEndpoint,
103 GrpcAddress: defaultGrpcAddress,
104 KafkaAdapterAddress: defaultKafkaAdapterAddress,
105 KafkaClusterAddress: defaultKafkaClusterAddress,
106 KVStoreType: defaultKVStoreType,
107 KVStoreTimeout: defaultKVStoreTimeout,
108 KVStoreAddress: defaultKVStoreAddress,
109 KVTxnKeyDelTime: defaultKVTxnKeyDelTime,
110 CoreTopic: defaultCoreTopic,
111 EventTopic: defaultEventTopic,
112 LogLevel: defaultLogLevel,
113 Banner: defaultBanner,
114 DisplayVersionOnly: defaultDisplayVersionOnly,
115 RWCoreKey: defaultRWCoreKey,
116 RWCoreCert: defaultRWCoreCert,
117 RWCoreCA: defaultRWCoreCA,
118 DefaultRequestTimeout: defaultDefaultRequestTimeout,
119 LongRunningRequestTimeout: defaultLongRunningRequestTimeout,
120 DefaultCoreTimeout: defaultCoreTimeout,
121 CoreBindingKey: defaultCoreBindingKey,
122 MaxConnectionRetries: defaultMaxConnectionRetries,
123 ConnectionRetryInterval: defaultConnectionRetryInterval,
124 LiveProbeInterval: defaultLiveProbeInterval,
125 NotLiveProbeInterval: defaultNotLiveProbeInterval,
126 ProbeAddress: defaultProbeAddress,
127 TraceEnabled: defaultTraceEnabled,
128 TraceAgentAddress: defaultTraceAgentAddress,
129 LogCorrelationEnabled: defaultLogCorrelationEnabled,
130 VolthaStackID: defaultVolthaStackID,
131 BackoffRetryInitialInterval: defaultBackoffRetryInitialInterval,
132 BackoffRetryMaxElapsedTime: defaultBackoffRetryMaxElapsedTime,
133 BackoffRetryMaxInterval: defaultBackoffRetryMaxInterval,
khenaidoocfee5f42018-07-19 22:47:38 -0400134 }
135 return &rwCoreFlag
136}
137
khenaidoo5c11af72018-07-20 17:21:05 -0400138// ParseCommandArguments parses the arguments when running read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -0400139func (cf *RWCoreFlags) ParseCommandArguments() {
khenaidoocfee5f42018-07-19 22:47:38 -0400140
npujar1d86a522019-11-14 17:11:16 +0530141 help := fmt.Sprintf("RW core endpoint address")
142 flag.StringVar(&(cf.RWCoreEndpoint), "vcore-endpoint", defaultRWCoreEndpoint, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400143
Neha Sharmad1387da2020-05-07 20:07:28 +0000144 help = fmt.Sprintf("GRPC server - address")
145 flag.StringVar(&(cf.GrpcAddress), "grpc_address", defaultGrpcAddress, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400146
Neha Sharmad1387da2020-05-07 20:07:28 +0000147 help = fmt.Sprintf("Kafka - Adapter messaging address")
148 flag.StringVar(&(cf.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaAdapterAddress, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400149
Neha Sharmad1387da2020-05-07 20:07:28 +0000150 help = fmt.Sprintf("Kafka - Cluster messaging address")
151 flag.StringVar(&(cf.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaClusterAddress, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400152
153 help = fmt.Sprintf("RW Core topic")
npujar1d86a522019-11-14 17:11:16 +0530154 flag.StringVar(&(cf.CoreTopic), "rw_core_topic", defaultCoreTopic, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400155
Himani Chawlab4c25912020-11-12 17:16:38 +0530156 help = fmt.Sprintf("RW Core Event topic")
157 flag.StringVar(&(cf.EventTopic), "event_topic", defaultEventTopic, help)
158
David Bainbridge9ae13132020-06-22 17:28:01 -0700159 flag.Bool("in_competing_mode", false, "deprecated")
khenaidoo79232702018-12-04 11:00:41 -0500160
khenaidoo5c11af72018-07-20 17:21:05 -0400161 help = fmt.Sprintf("KV store type")
npujar1d86a522019-11-14 17:11:16 +0530162 flag.StringVar(&(cf.KVStoreType), "kv_store_type", defaultKVStoreType, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400163
164 help = fmt.Sprintf("The default timeout when making a kv store request")
Neha Sharma7d6f3a92020-04-14 15:26:22 +0000165 flag.DurationVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", defaultKVStoreTimeout, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400166
Neha Sharmad1387da2020-05-07 20:07:28 +0000167 help = fmt.Sprintf("KV store address")
168 flag.StringVar(&(cf.KVStoreAddress), "kv_store_address", defaultKVStoreAddress, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400169
Richard Jankowskie4d77662018-10-17 13:53:21 -0400170 help = fmt.Sprintf("The time to wait before deleting a completed transaction key")
npujar1d86a522019-11-14 17:11:16 +0530171 flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", defaultKVTxnKeyDelTime, help)
Richard Jankowskie4d77662018-10-17 13:53:21 -0400172
khenaidoo5c11af72018-07-20 17:21:05 -0400173 help = fmt.Sprintf("Log level")
Rohan Agrawal7f72f0c2020-01-14 12:05:51 +0000174 flag.StringVar(&(cf.LogLevel), "log_level", defaultLogLevel, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400175
khenaidoob6080322019-01-29 21:47:38 -0500176 help = fmt.Sprintf("Timeout for long running request")
Neha Sharma7d6f3a92020-04-14 15:26:22 +0000177 flag.DurationVar(&(cf.LongRunningRequestTimeout), "timeout_long_request", defaultLongRunningRequestTimeout, help)
khenaidoob6080322019-01-29 21:47:38 -0500178
179 help = fmt.Sprintf("Default timeout for regular request")
Neha Sharma7d6f3a92020-04-14 15:26:22 +0000180 flag.DurationVar(&(cf.DefaultRequestTimeout), "timeout_request", defaultDefaultRequestTimeout, help)
khenaidoob6080322019-01-29 21:47:38 -0500181
khenaidoo2c6a0992019-04-29 13:46:56 -0400182 help = fmt.Sprintf("Default Core timeout")
Neha Sharma7d6f3a92020-04-14 15:26:22 +0000183 flag.DurationVar(&(cf.DefaultCoreTimeout), "core_timeout", defaultCoreTimeout, help)
khenaidoo2c6a0992019-04-29 13:46:56 -0400184
khenaidoo5c11af72018-07-20 17:21:05 -0400185 help = fmt.Sprintf("Show startup banner log lines")
npujar1d86a522019-11-14 17:11:16 +0530186 flag.BoolVar(&cf.Banner, "banner", defaultBanner, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400187
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700188 help = fmt.Sprintf("Show version information and exit")
npujar1d86a522019-11-14 17:11:16 +0530189 flag.BoolVar(&cf.DisplayVersionOnly, "version", defaultDisplayVersionOnly, help)
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700190
Richard Jankowski46464e92019-03-05 11:53:55 -0500191 help = fmt.Sprintf("The name of the meta-key whose value is the rw-core group to which the ofagent is bound")
npujar1d86a522019-11-14 17:11:16 +0530192 flag.StringVar(&(cf.CoreBindingKey), "core_binding_key", defaultCoreBindingKey, help)
Richard Jankowski46464e92019-03-05 11:53:55 -0500193
khenaidoob3244212019-08-27 14:32:27 -0400194 help = fmt.Sprintf("The number of retries to connect to a dependent component")
npujar1d86a522019-11-14 17:11:16 +0530195 flag.IntVar(&(cf.MaxConnectionRetries), "max_connection_retries", defaultMaxConnectionRetries, help)
khenaidoob3244212019-08-27 14:32:27 -0400196
Scott Bakeree6a0872019-10-29 15:59:52 -0700197 help = fmt.Sprintf("The number of seconds between each connection retry attempt")
npujar1d86a522019-11-14 17:11:16 +0530198 flag.DurationVar(&(cf.ConnectionRetryInterval), "connection_retry_interval", defaultConnectionRetryInterval, help)
khenaidoob3244212019-08-27 14:32:27 -0400199
Scott Bakeree6a0872019-10-29 15:59:52 -0700200 help = fmt.Sprintf("The number of seconds between liveness probes while in a live state")
npujar1d86a522019-11-14 17:11:16 +0530201 flag.DurationVar(&(cf.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
Scott Bakeree6a0872019-10-29 15:59:52 -0700202
203 help = fmt.Sprintf("The number of seconds between liveness probes while in a not live state")
npujar1d86a522019-11-14 17:11:16 +0530204 flag.DurationVar(&(cf.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
Scott Bakeree6a0872019-10-29 15:59:52 -0700205
Neha Sharmad1387da2020-05-07 20:07:28 +0000206 help = fmt.Sprintf("The address on which to listen to answer liveness and readiness probe queries over HTTP.")
207 flag.StringVar(&(cf.ProbeAddress), "probe_address", defaultProbeAddress, help)
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -0700208
Girish Kumar33470e82020-06-15 13:53:13 +0000209 help = fmt.Sprintf("Whether to send logs to tracing agent?")
210 flag.BoolVar(&(cf.TraceEnabled), "trace_enabled", defaultTraceEnabled, help)
211
212 help = fmt.Sprintf("The address of tracing agent to which span info should be sent.")
213 flag.StringVar(&(cf.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, help)
214
215 help = fmt.Sprintf("Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
216 flag.BoolVar(&(cf.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, help)
217
Himani Chawla9cfc4992021-03-22 12:43:01 +0530218 help = fmt.Sprintf("ID for the current voltha stack")
219 flag.StringVar(&cf.VolthaStackID, "stack_id", defaultVolthaStackID, help)
220
khenaidoo5e4fca32021-05-12 16:02:23 -0400221 help = fmt.Sprintf("The initial number of milliseconds an exponential backoff will wait before a retry")
222 flag.DurationVar(&(cf.BackoffRetryInitialInterval), "backoff_retry_initial_interval", defaultBackoffRetryInitialInterval, help)
223
224 help = fmt.Sprintf("The maximum number of milliseconds an exponential backoff can elasped")
225 flag.DurationVar(&(cf.BackoffRetryMaxElapsedTime), "backoff_retry_max_elapsed_time", defaultBackoffRetryMaxElapsedTime, help)
226
227 help = fmt.Sprintf("The maximum number of milliseconds of an exponential backoff interval")
228 flag.DurationVar(&(cf.BackoffRetryMaxInterval), "backoff_retry_max_interval", defaultBackoffRetryMaxInterval, help)
229
khenaidoocfee5f42018-07-19 22:47:38 -0400230 flag.Parse()
khenaidoocfee5f42018-07-19 22:47:38 -0400231}