blob: 68dca2c5ffee6c911123dc158127c8fb36b48c47 [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 */
khenaidoocfee5f42018-07-19 22:47:38 -040016package config
17
18import (
khenaidoocfee5f42018-07-19 22:47:38 -040019 "flag"
20 "fmt"
Scott Baker807addd2019-10-24 15:16:21 -070021 "github.com/opencord/voltha-lib-go/v2/pkg/log"
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 (
khenaidoo2c6a0992019-04-29 13:46:56 -040027 ConsulStoreName = "consul"
28 EtcdStoreName = "etcd"
khenaidoo2c6a0992019-04-29 13:46:56 -040029 default_GrpcPort = 50057
30 default_GrpcHost = ""
31 default_KafkaAdapterHost = "127.0.0.1"
32 default_KafkaAdapterPort = 9092
33 default_KafkaClusterHost = "127.0.0.1"
34 default_KafkaClusterPort = 9094
35 default_KVStoreType = EtcdStoreName
36 default_KVStoreTimeout = 5 //in seconds
37 default_KVStoreHost = "127.0.0.1"
38 default_KVStorePort = 2379 // Consul = 8500; Etcd = 2379
39 default_KVTxnKeyDelTime = 60
40 default_KVStoreDataPrefix = "service/voltha"
41 default_LogLevel = 0
42 default_Banner = false
David K. Bainbridgef430cd52019-05-28 15:00:35 -070043 default_DisplayVersionOnly = false
khenaidoo2c6a0992019-04-29 13:46:56 -040044 default_CoreTopic = "rwcore"
45 default_RWCoreEndpoint = "rwcore"
46 default_RWCoreKey = "pki/voltha.key"
47 default_RWCoreCert = "pki/voltha.crt"
48 default_RWCoreCA = "pki/voltha-CA.pem"
49 default_AffinityRouterTopic = "affinityRouter"
50 default_InCompetingMode = true
khenaidoob6080322019-01-29 21:47:38 -050051 default_LongRunningRequestTimeout = int64(2000)
khenaidoo2c6a0992019-04-29 13:46:56 -040052 default_DefaultRequestTimeout = int64(500)
53 default_CoreTimeout = int64(500)
54 default_CoreBindingKey = "voltha_backend_name"
Kent Hagermana6d0c362019-07-30 12:50:21 -040055 default_CorePairTopic = "rwcore_1"
khenaidoob3244212019-08-27 14:32:27 -040056 default_MaxConnectionRetries = -1 // retries forever
Girish Kumar4d3887d2019-11-22 14:22:05 +000057 default_ConnectionRetryInterval = 2 * time.Second
58 default_LiveProbeInterval = 60 * time.Second
59 default_NotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
Kent Hagermanc4618832019-10-07 12:24:36 -040060 default_ProbeHost = ""
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -070061 default_ProbePort = 8080
khenaidoocfee5f42018-07-19 22:47:38 -040062)
63
khenaidoo5c11af72018-07-20 17:21:05 -040064// RWCoreFlags represents the set of configurations used by the read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -040065type RWCoreFlags struct {
66 // Command line parameters
khenaidoo2c6a0992019-04-29 13:46:56 -040067 RWCoreEndpoint string
68 GrpcHost string
69 GrpcPort int
70 KafkaAdapterHost string
71 KafkaAdapterPort int
72 KafkaClusterHost string
73 KafkaClusterPort int
74 KVStoreType string
75 KVStoreTimeout int // in seconds
76 KVStoreHost string
77 KVStorePort int
78 KVTxnKeyDelTime int
79 KVStoreDataPrefix string
80 CoreTopic string
81 LogLevel int
82 Banner bool
David K. Bainbridgef430cd52019-05-28 15:00:35 -070083 DisplayVersionOnly bool
khenaidoo2c6a0992019-04-29 13:46:56 -040084 RWCoreKey string
85 RWCoreCert string
86 RWCoreCA string
87 AffinityRouterTopic string
88 InCompetingMode bool
khenaidoob6080322019-01-29 21:47:38 -050089 LongRunningRequestTimeout int64
khenaidoo2c6a0992019-04-29 13:46:56 -040090 DefaultRequestTimeout int64
91 DefaultCoreTimeout int64
92 CoreBindingKey string
Kent Hagermana6d0c362019-07-30 12:50:21 -040093 CorePairTopic string
khenaidoob3244212019-08-27 14:32:27 -040094 MaxConnectionRetries int
Girish Kumar4d3887d2019-11-22 14:22:05 +000095 ConnectionRetryInterval time.Duration
96 LiveProbeInterval time.Duration
97 NotLiveProbeInterval time.Duration
Kent Hagermanc4618832019-10-07 12:24:36 -040098 ProbeHost string
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -070099 ProbePort int
khenaidoocfee5f42018-07-19 22:47:38 -0400100}
101
khenaidoob9203542018-09-17 22:56:37 -0400102func init() {
103 log.AddPackage(log.JSON, log.WarnLevel, nil)
104}
105
khenaidoo5c11af72018-07-20 17:21:05 -0400106// NewRWCoreFlags returns a new RWCore config
khenaidoocfee5f42018-07-19 22:47:38 -0400107func NewRWCoreFlags() *RWCoreFlags {
108 var rwCoreFlag = RWCoreFlags{ // Default values
khenaidoo2c6a0992019-04-29 13:46:56 -0400109 RWCoreEndpoint: default_RWCoreEndpoint,
110 GrpcHost: default_GrpcHost,
111 GrpcPort: default_GrpcPort,
112 KafkaAdapterHost: default_KafkaAdapterHost,
113 KafkaAdapterPort: default_KafkaAdapterPort,
114 KafkaClusterHost: default_KafkaClusterHost,
115 KafkaClusterPort: default_KafkaClusterPort,
116 KVStoreType: default_KVStoreType,
117 KVStoreTimeout: default_KVStoreTimeout,
118 KVStoreHost: default_KVStoreHost,
119 KVStorePort: default_KVStorePort,
120 KVStoreDataPrefix: default_KVStoreDataPrefix,
121 KVTxnKeyDelTime: default_KVTxnKeyDelTime,
122 CoreTopic: default_CoreTopic,
123 LogLevel: default_LogLevel,
124 Banner: default_Banner,
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700125 DisplayVersionOnly: default_DisplayVersionOnly,
khenaidoo2c6a0992019-04-29 13:46:56 -0400126 RWCoreKey: default_RWCoreKey,
127 RWCoreCert: default_RWCoreCert,
128 RWCoreCA: default_RWCoreCA,
129 AffinityRouterTopic: default_AffinityRouterTopic,
130 InCompetingMode: default_InCompetingMode,
131 DefaultRequestTimeout: default_DefaultRequestTimeout,
132 LongRunningRequestTimeout: default_LongRunningRequestTimeout,
133 DefaultCoreTimeout: default_CoreTimeout,
134 CoreBindingKey: default_CoreBindingKey,
Kent Hagermana6d0c362019-07-30 12:50:21 -0400135 CorePairTopic: default_CorePairTopic,
khenaidoob3244212019-08-27 14:32:27 -0400136 MaxConnectionRetries: default_MaxConnectionRetries,
137 ConnectionRetryInterval: default_ConnectionRetryInterval,
Scott Bakeree6a0872019-10-29 15:59:52 -0700138 LiveProbeInterval: default_LiveProbeInterval,
139 NotLiveProbeInterval: default_NotLiveProbeInterval,
Kent Hagermanc4618832019-10-07 12:24:36 -0400140 ProbeHost: default_ProbeHost,
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -0700141 ProbePort: default_ProbePort,
khenaidoocfee5f42018-07-19 22:47:38 -0400142 }
143 return &rwCoreFlag
144}
145
khenaidoo5c11af72018-07-20 17:21:05 -0400146// ParseCommandArguments parses the arguments when running read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -0400147func (cf *RWCoreFlags) ParseCommandArguments() {
khenaidoocfee5f42018-07-19 22:47:38 -0400148
khenaidoo5c11af72018-07-20 17:21:05 -0400149 var help string
khenaidoocfee5f42018-07-19 22:47:38 -0400150
khenaidoo5c11af72018-07-20 17:21:05 -0400151 help = fmt.Sprintf("RW core endpoint address")
152 flag.StringVar(&(cf.RWCoreEndpoint), "vcore-endpoint", default_RWCoreEndpoint, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400153
khenaidoo5c11af72018-07-20 17:21:05 -0400154 help = fmt.Sprintf("GRPC server - host")
155 flag.StringVar(&(cf.GrpcHost), "grpc_host", default_GrpcHost, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400156
khenaidoo5c11af72018-07-20 17:21:05 -0400157 help = fmt.Sprintf("GRPC server - port")
158 flag.IntVar(&(cf.GrpcPort), "grpc_port", default_GrpcPort, help)
159
160 help = fmt.Sprintf("Kafka - Adapter messaging host")
161 flag.StringVar(&(cf.KafkaAdapterHost), "kafka_adapter_host", default_KafkaAdapterHost, help)
162
163 help = fmt.Sprintf("Kafka - Adapter messaging port")
164 flag.IntVar(&(cf.KafkaAdapterPort), "kafka_adapter_port", default_KafkaAdapterPort, help)
165
166 help = fmt.Sprintf("Kafka - Cluster messaging host")
167 flag.StringVar(&(cf.KafkaClusterHost), "kafka_cluster_host", default_KafkaClusterHost, help)
168
169 help = fmt.Sprintf("Kafka - Cluster messaging port")
170 flag.IntVar(&(cf.KafkaClusterPort), "kafka_cluster_port", default_KafkaClusterPort, help)
171
172 help = fmt.Sprintf("RW Core topic")
173 flag.StringVar(&(cf.CoreTopic), "rw_core_topic", default_CoreTopic, help)
174
khenaidoo79232702018-12-04 11:00:41 -0500175 help = fmt.Sprintf("Affinity Router topic")
khenaidoo9cdc1a62019-01-24 21:57:40 -0500176 flag.StringVar(&(cf.AffinityRouterTopic), "affinity_router_topic", default_AffinityRouterTopic, help)
177
178 help = fmt.Sprintf("In competing Mode - two cores competing to handle a transaction ")
179 flag.BoolVar(&cf.InCompetingMode, "in_competing_mode", default_InCompetingMode, help)
khenaidoo79232702018-12-04 11:00:41 -0500180
khenaidoo5c11af72018-07-20 17:21:05 -0400181 help = fmt.Sprintf("KV store type")
182 flag.StringVar(&(cf.KVStoreType), "kv_store_type", default_KVStoreType, help)
183
184 help = fmt.Sprintf("The default timeout when making a kv store request")
185 flag.IntVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", default_KVStoreTimeout, help)
186
187 help = fmt.Sprintf("KV store host")
188 flag.StringVar(&(cf.KVStoreHost), "kv_store_host", default_KVStoreHost, help)
189
190 help = fmt.Sprintf("KV store port")
191 flag.IntVar(&(cf.KVStorePort), "kv_store_port", default_KVStorePort, help)
192
Richard Jankowskie4d77662018-10-17 13:53:21 -0400193 help = fmt.Sprintf("The time to wait before deleting a completed transaction key")
194 flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", default_KVTxnKeyDelTime, help)
195
khenaidoo9cdc1a62019-01-24 21:57:40 -0500196 help = fmt.Sprintf("KV store data prefix")
197 flag.StringVar(&(cf.KVStoreDataPrefix), "kv_store_data_prefix", default_KVStoreDataPrefix, help)
198
khenaidoo5c11af72018-07-20 17:21:05 -0400199 help = fmt.Sprintf("Log level")
200 flag.IntVar(&(cf.LogLevel), "log_level", default_LogLevel, help)
201
khenaidoob6080322019-01-29 21:47:38 -0500202 help = fmt.Sprintf("Timeout for long running request")
203 flag.Int64Var(&(cf.LongRunningRequestTimeout), "timeout_long_request", default_LongRunningRequestTimeout, help)
204
205 help = fmt.Sprintf("Default timeout for regular request")
206 flag.Int64Var(&(cf.DefaultRequestTimeout), "timeout_request", default_DefaultRequestTimeout, help)
207
khenaidoo2c6a0992019-04-29 13:46:56 -0400208 help = fmt.Sprintf("Default Core timeout")
209 flag.Int64Var(&(cf.DefaultCoreTimeout), "core_timeout", default_CoreTimeout, help)
210
khenaidoo5c11af72018-07-20 17:21:05 -0400211 help = fmt.Sprintf("Show startup banner log lines")
212 flag.BoolVar(&cf.Banner, "banner", default_Banner, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400213
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700214 help = fmt.Sprintf("Show version information and exit")
215 flag.BoolVar(&cf.DisplayVersionOnly, "version", default_DisplayVersionOnly, help)
216
Richard Jankowski46464e92019-03-05 11:53:55 -0500217 help = fmt.Sprintf("The name of the meta-key whose value is the rw-core group to which the ofagent is bound")
218 flag.StringVar(&(cf.CoreBindingKey), "core_binding_key", default_CoreBindingKey, help)
219
Kent Hagermana6d0c362019-07-30 12:50:21 -0400220 help = fmt.Sprintf("Core pairing group topic")
221 flag.StringVar(&cf.CorePairTopic, "core_pair_topic", default_CorePairTopic, help)
222
khenaidoob3244212019-08-27 14:32:27 -0400223 help = fmt.Sprintf("The number of retries to connect to a dependent component")
224 flag.IntVar(&(cf.MaxConnectionRetries), "max_connection_retries", default_MaxConnectionRetries, help)
225
Scott Bakeree6a0872019-10-29 15:59:52 -0700226 help = fmt.Sprintf("The number of seconds between each connection retry attempt")
Girish Kumar4d3887d2019-11-22 14:22:05 +0000227 flag.DurationVar(&(cf.ConnectionRetryInterval), "connection_retry_interval", default_ConnectionRetryInterval, help)
khenaidoob3244212019-08-27 14:32:27 -0400228
Scott Bakeree6a0872019-10-29 15:59:52 -0700229 help = fmt.Sprintf("The number of seconds between liveness probes while in a live state")
Girish Kumar4d3887d2019-11-22 14:22:05 +0000230 flag.DurationVar(&(cf.LiveProbeInterval), "live_probe_interval", default_LiveProbeInterval, help)
Scott Bakeree6a0872019-10-29 15:59:52 -0700231
232 help = fmt.Sprintf("The number of seconds between liveness probes while in a not live state")
Girish Kumar4d3887d2019-11-22 14:22:05 +0000233 flag.DurationVar(&(cf.NotLiveProbeInterval), "not_live_probe_interval", default_NotLiveProbeInterval, help)
Scott Bakeree6a0872019-10-29 15:59:52 -0700234
Kent Hagermanc4618832019-10-07 12:24:36 -0400235 help = fmt.Sprintf("The host on which to listen to answer liveness and readiness probe queries over HTTP.")
236 flag.StringVar(&(cf.ProbeHost), "probe_host", default_ProbeHost, help)
237
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -0700238 help = fmt.Sprintf("The port on which to listen to answer liveness and readiness probe queries over HTTP.")
239 flag.IntVar(&(cf.ProbePort), "probe_port", default_ProbePort, help)
240
khenaidoocfee5f42018-07-19 22:47:38 -0400241 flag.Parse()
khenaidoocfee5f42018-07-19 22:47:38 -0400242}