blob: ad885c27c89f1dd290f8006739bddb7113174bee [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"
David K. Bainbridge6080c172021-07-24 00:22:28 +000021 "os"
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 (
David K. Bainbridge6080c172021-07-24 00:22:28 +000027 EtcdStoreName = "etcd"
khenaidoocfee5f42018-07-19 22:47:38 -040028)
29
khenaidoo5c11af72018-07-20 17:21:05 -040030// RWCoreFlags represents the set of configurations used by the read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -040031type RWCoreFlags struct {
32 // Command line parameters
khenaidood948f772021-08-11 17:49:24 -040033 GrpcNBIAddress string
34 GrpcSBIAddress string
khenaidoo5e4fca32021-05-12 16:02:23 -040035 KafkaClusterAddress string
36 KVStoreType string
37 KVStoreTimeout time.Duration
38 KVStoreAddress string
khenaidoo5e4fca32021-05-12 16:02:23 -040039 EventTopic string
40 LogLevel string
41 Banner bool
42 DisplayVersionOnly bool
43 RWCoreKey string
44 RWCoreCert string
45 RWCoreCA string
khenaidood948f772021-08-11 17:49:24 -040046 InternalTimeout time.Duration
47 RPCTimeout time.Duration
khenaidoo5e4fca32021-05-12 16:02:23 -040048 MaxConnectionRetries int
49 ConnectionRetryInterval time.Duration
50 LiveProbeInterval time.Duration
51 NotLiveProbeInterval time.Duration
52 ProbeAddress string
53 TraceEnabled bool
54 TraceAgentAddress string
55 LogCorrelationEnabled bool
56 VolthaStackID string
57 BackoffRetryInitialInterval time.Duration
58 BackoffRetryMaxElapsedTime time.Duration
59 BackoffRetryMaxInterval time.Duration
khenaidoocfee5f42018-07-19 22:47:38 -040060}
61
khenaidoo5c11af72018-07-20 17:21:05 -040062// ParseCommandArguments parses the arguments when running read-write core service
David K. Bainbridge6080c172021-07-24 00:22:28 +000063func (cf *RWCoreFlags) ParseCommandArguments(args []string) {
khenaidoocfee5f42018-07-19 22:47:38 -040064
David K. Bainbridge6080c172021-07-24 00:22:28 +000065 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
khenaidoocfee5f42018-07-19 22:47:38 -040066
khenaidood948f772021-08-11 17:49:24 -040067 fs.StringVar(&cf.GrpcNBIAddress,
68 "grpc_nbi_address",
69 ":50057",
70 "GRPC NBI server - address")
khenaidoocfee5f42018-07-19 22:47:38 -040071
khenaidood948f772021-08-11 17:49:24 -040072 fs.StringVar(&cf.GrpcSBIAddress,
73 "grpc_sbi_address",
74 ":50058",
75 "GRPC SBI server - address")
khenaidoo5c11af72018-07-20 17:21:05 -040076
khenaidood948f772021-08-11 17:49:24 -040077 fs.StringVar(&cf.KafkaClusterAddress,
78 "kafka_cluster_address",
79 "127.0.0.1:9092",
80 "Kafka - Cluster messaging address")
khenaidoo5c11af72018-07-20 17:21:05 -040081
khenaidood948f772021-08-11 17:49:24 -040082 fs.StringVar(&cf.EventTopic,
83 "event_topic",
84 "voltha.events",
85 "RW Core Event topic")
khenaidoo5c11af72018-07-20 17:21:05 -040086
khenaidood948f772021-08-11 17:49:24 -040087 fs.StringVar(&cf.KVStoreType,
88 "kv_store_type",
89 EtcdStoreName,
90 "KV store type")
Himani Chawlab4c25912020-11-12 17:16:38 +053091
khenaidood948f772021-08-11 17:49:24 -040092 fs.DurationVar(&cf.KVStoreTimeout,
93 "kv_store_request_timeout",
94 5*time.Second,
95 "The default timeout when making a kv store request")
khenaidoo79232702018-12-04 11:00:41 -050096
khenaidood948f772021-08-11 17:49:24 -040097 fs.StringVar(&cf.KVStoreAddress,
98 "kv_store_address",
99 "127.0.0.1:2379",
100 "KV store address")
khenaidoo5c11af72018-07-20 17:21:05 -0400101
khenaidood948f772021-08-11 17:49:24 -0400102 fs.StringVar(&cf.LogLevel,
103 "log_level",
104 "warn",
105 "Log level")
khenaidoo5c11af72018-07-20 17:21:05 -0400106
khenaidood948f772021-08-11 17:49:24 -0400107 fs.DurationVar(&(cf.InternalTimeout),
108 "internal_timeout",
109 5*time.Second,
110 "Core internal timeout")
khenaidoo5c11af72018-07-20 17:21:05 -0400111
khenaidood948f772021-08-11 17:49:24 -0400112 fs.DurationVar(&(cf.RPCTimeout),
113 "rpc_timeout",
114 5*time.Second,
115 "RPC timeout")
Richard Jankowskie4d77662018-10-17 13:53:21 -0400116
khenaidood948f772021-08-11 17:49:24 -0400117 fs.BoolVar(&cf.Banner,
118 "banner",
119 false,
120 "Show startup banner log lines")
khenaidoo5c11af72018-07-20 17:21:05 -0400121
khenaidood948f772021-08-11 17:49:24 -0400122 fs.BoolVar(&cf.DisplayVersionOnly,
123 "version",
124 false,
125 "Show version information and exit")
khenaidoob6080322019-01-29 21:47:38 -0500126
khenaidood948f772021-08-11 17:49:24 -0400127 fs.IntVar(&cf.MaxConnectionRetries,
128 "max_connection_retries",
129 -1,
130 "The number of retries to connect to a dependent component")
khenaidoob6080322019-01-29 21:47:38 -0500131
khenaidood948f772021-08-11 17:49:24 -0400132 fs.DurationVar(&cf.ConnectionRetryInterval,
133 "connection_retry_interval",
134 2*time.Second,
135 "The number of seconds between each connection retry attempt")
khenaidoo2c6a0992019-04-29 13:46:56 -0400136
khenaidood948f772021-08-11 17:49:24 -0400137 fs.DurationVar(&cf.LiveProbeInterval,
138 "live_probe_interval",
139 60*time.Second,
140 "The number of seconds between liveness probes while in a live state")
khenaidoocfee5f42018-07-19 22:47:38 -0400141
khenaidood948f772021-08-11 17:49:24 -0400142 fs.DurationVar(&cf.NotLiveProbeInterval,
143 "not_live_probe_interval",
144 5*time.Second,
145 "The number of seconds between liveness probes while in a not live state")
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700146
khenaidood948f772021-08-11 17:49:24 -0400147 fs.StringVar(&cf.ProbeAddress,
148 "probe_address",
149 ":8080",
150 "The address on which to listen to answer liveness and readiness probe queries over HTTP")
Richard Jankowski46464e92019-03-05 11:53:55 -0500151
khenaidood948f772021-08-11 17:49:24 -0400152 fs.BoolVar(&(cf.TraceEnabled),
153 "trace_enabled",
154 false,
155 "Whether to send logs to tracing agent?")
khenaidoob3244212019-08-27 14:32:27 -0400156
khenaidood948f772021-08-11 17:49:24 -0400157 fs.StringVar(&cf.TraceAgentAddress,
158 "trace_agent_address",
159 "127.0.0.1:6831",
160 "The address of tracing agent to which span info should be sent")
khenaidoob3244212019-08-27 14:32:27 -0400161
khenaidood948f772021-08-11 17:49:24 -0400162 fs.BoolVar(&cf.LogCorrelationEnabled,
163 "log_correlation_enabled",
164 true,
165 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Scott Bakeree6a0872019-10-29 15:59:52 -0700166
khenaidood948f772021-08-11 17:49:24 -0400167 fs.StringVar(&cf.VolthaStackID,
168 "stack_id",
169 "voltha",
170 "ID for the current voltha stack")
Himani Chawla9cfc4992021-03-22 12:43:01 +0530171
David K. Bainbridge6080c172021-07-24 00:22:28 +0000172 fs.DurationVar(&cf.BackoffRetryInitialInterval,
khenaidood948f772021-08-11 17:49:24 -0400173 "backoff_retry_initial_interval",
174 500*time.Millisecond,
David K. Bainbridge6080c172021-07-24 00:22:28 +0000175 "The initial number of milliseconds an exponential backoff will wait before a retry")
khenaidoo5e4fca32021-05-12 16:02:23 -0400176
David K. Bainbridge6080c172021-07-24 00:22:28 +0000177 fs.DurationVar(&cf.BackoffRetryMaxElapsedTime,
khenaidood948f772021-08-11 17:49:24 -0400178 "backoff_retry_max_elapsed_time",
179 0*time.Second,
David K. Bainbridge6080c172021-07-24 00:22:28 +0000180 "The maximum number of milliseconds an exponential backoff can elasped")
khenaidoo5e4fca32021-05-12 16:02:23 -0400181
khenaidood948f772021-08-11 17:49:24 -0400182 fs.DurationVar(&cf.BackoffRetryMaxInterval,
183 "backoff_retry_max_interval",
184 1*time.Minute,
185 "The maximum number of milliseconds of an exponential backoff interval")
khenaidoo5e4fca32021-05-12 16:02:23 -0400186
David K. Bainbridge6080c172021-07-24 00:22:28 +0000187 _ = fs.Parse(args)
khenaidoocfee5f42018-07-19 22:47:38 -0400188}