blob: 39ba9ba40a4954b1b4e138110a8d4c2d171bde01 [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 (
npujar1d86a522019-11-14 17:11:16 +053027 ConsulStoreName = "consul"
28 EtcdStoreName = "etcd"
29 defaultGrpcPort = 50057
30 defaultGrpcHost = ""
31 defaultKafkaAdapterHost = "127.0.0.1"
32 defaultKafkaAdapterPort = 9092
33 defaultKafkaClusterHost = "127.0.0.1"
34 defaultKafkaClusterPort = 9094
35 defaultKVStoreType = EtcdStoreName
36 defaultKVStoreTimeout = 5 //in seconds
37 defaultKVStoreHost = "127.0.0.1"
38 defaultKVStorePort = 2379 // Consul = 8500; Etcd = 2379
39 defaultKVTxnKeyDelTime = 60
40 defaultKVStoreDataPrefix = "service/voltha"
David Bainbridge48d46e12020-03-17 15:05:55 -070041 defaultLogLevel = "WARN"
npujar1d86a522019-11-14 17:11:16 +053042 defaultBanner = false
43 defaultDisplayVersionOnly = false
44 defaultCoreTopic = "rwcore"
45 defaultRWCoreEndpoint = "rwcore"
46 defaultRWCoreKey = "pki/voltha.key"
47 defaultRWCoreCert = "pki/voltha.crt"
48 defaultRWCoreCA = "pki/voltha-CA.pem"
49 defaultAffinityRouterTopic = "affinityRouter"
50 defaultInCompetingMode = true
khenaidoo442e7c72020-03-10 16:13:48 -040051 defaultLongRunningRequestTimeout = 2000 * time.Millisecond
52 defaultDefaultRequestTimeout = 1000 * time.Millisecond
53 defaultCoreTimeout = 1000 * time.Millisecond
npujar1d86a522019-11-14 17:11:16 +053054 defaultCoreBindingKey = "voltha_backend_name"
55 defaultCorePairTopic = "rwcore_1"
56 defaultMaxConnectionRetries = -1 // retries forever
57 defaultConnectionRetryInterval = 2 * time.Second
58 defaultLiveProbeInterval = 60 * time.Second
59 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
60 defaultProbeHost = ""
61 defaultProbePort = 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
Rohan Agrawal7f72f0c2020-01-14 12:05:51 +000081 LogLevel string
khenaidoo2c6a0992019-04-29 13:46:56 -040082 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
khenaidoo442e7c72020-03-10 16:13:48 -040089 LongRunningRequestTimeout time.Duration
90 DefaultRequestTimeout time.Duration
91 DefaultCoreTimeout time.Duration
khenaidoo2c6a0992019-04-29 13:46:56 -040092 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
khenaidoo5c11af72018-07-20 17:21:05 -0400102// NewRWCoreFlags returns a new RWCore config
khenaidoocfee5f42018-07-19 22:47:38 -0400103func NewRWCoreFlags() *RWCoreFlags {
104 var rwCoreFlag = RWCoreFlags{ // Default values
npujar1d86a522019-11-14 17:11:16 +0530105 RWCoreEndpoint: defaultRWCoreEndpoint,
106 GrpcHost: defaultGrpcHost,
107 GrpcPort: defaultGrpcPort,
108 KafkaAdapterHost: defaultKafkaAdapterHost,
109 KafkaAdapterPort: defaultKafkaAdapterPort,
110 KafkaClusterHost: defaultKafkaClusterHost,
111 KafkaClusterPort: defaultKafkaClusterPort,
112 KVStoreType: defaultKVStoreType,
113 KVStoreTimeout: defaultKVStoreTimeout,
114 KVStoreHost: defaultKVStoreHost,
115 KVStorePort: defaultKVStorePort,
116 KVStoreDataPrefix: defaultKVStoreDataPrefix,
117 KVTxnKeyDelTime: defaultKVTxnKeyDelTime,
118 CoreTopic: defaultCoreTopic,
119 LogLevel: defaultLogLevel,
120 Banner: defaultBanner,
121 DisplayVersionOnly: defaultDisplayVersionOnly,
122 RWCoreKey: defaultRWCoreKey,
123 RWCoreCert: defaultRWCoreCert,
124 RWCoreCA: defaultRWCoreCA,
125 AffinityRouterTopic: defaultAffinityRouterTopic,
126 InCompetingMode: defaultInCompetingMode,
127 DefaultRequestTimeout: defaultDefaultRequestTimeout,
128 LongRunningRequestTimeout: defaultLongRunningRequestTimeout,
129 DefaultCoreTimeout: defaultCoreTimeout,
130 CoreBindingKey: defaultCoreBindingKey,
131 CorePairTopic: defaultCorePairTopic,
132 MaxConnectionRetries: defaultMaxConnectionRetries,
133 ConnectionRetryInterval: defaultConnectionRetryInterval,
134 LiveProbeInterval: defaultLiveProbeInterval,
135 NotLiveProbeInterval: defaultNotLiveProbeInterval,
136 ProbeHost: defaultProbeHost,
137 ProbePort: defaultProbePort,
khenaidoocfee5f42018-07-19 22:47:38 -0400138 }
139 return &rwCoreFlag
140}
141
khenaidoo5c11af72018-07-20 17:21:05 -0400142// ParseCommandArguments parses the arguments when running read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -0400143func (cf *RWCoreFlags) ParseCommandArguments() {
khenaidoocfee5f42018-07-19 22:47:38 -0400144
npujar1d86a522019-11-14 17:11:16 +0530145 help := fmt.Sprintf("RW core endpoint address")
146 flag.StringVar(&(cf.RWCoreEndpoint), "vcore-endpoint", defaultRWCoreEndpoint, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400147
khenaidoo5c11af72018-07-20 17:21:05 -0400148 help = fmt.Sprintf("GRPC server - host")
npujar1d86a522019-11-14 17:11:16 +0530149 flag.StringVar(&(cf.GrpcHost), "grpc_host", defaultGrpcHost, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400150
khenaidoo5c11af72018-07-20 17:21:05 -0400151 help = fmt.Sprintf("GRPC server - port")
npujar1d86a522019-11-14 17:11:16 +0530152 flag.IntVar(&(cf.GrpcPort), "grpc_port", defaultGrpcPort, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400153
154 help = fmt.Sprintf("Kafka - Adapter messaging host")
npujar1d86a522019-11-14 17:11:16 +0530155 flag.StringVar(&(cf.KafkaAdapterHost), "kafka_adapter_host", defaultKafkaAdapterHost, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400156
157 help = fmt.Sprintf("Kafka - Adapter messaging port")
npujar1d86a522019-11-14 17:11:16 +0530158 flag.IntVar(&(cf.KafkaAdapterPort), "kafka_adapter_port", defaultKafkaAdapterPort, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400159
160 help = fmt.Sprintf("Kafka - Cluster messaging host")
npujar1d86a522019-11-14 17:11:16 +0530161 flag.StringVar(&(cf.KafkaClusterHost), "kafka_cluster_host", defaultKafkaClusterHost, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400162
163 help = fmt.Sprintf("Kafka - Cluster messaging port")
npujar1d86a522019-11-14 17:11:16 +0530164 flag.IntVar(&(cf.KafkaClusterPort), "kafka_cluster_port", defaultKafkaClusterPort, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400165
166 help = fmt.Sprintf("RW Core topic")
npujar1d86a522019-11-14 17:11:16 +0530167 flag.StringVar(&(cf.CoreTopic), "rw_core_topic", defaultCoreTopic, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400168
khenaidoo79232702018-12-04 11:00:41 -0500169 help = fmt.Sprintf("Affinity Router topic")
npujar1d86a522019-11-14 17:11:16 +0530170 flag.StringVar(&(cf.AffinityRouterTopic), "affinity_router_topic", defaultAffinityRouterTopic, help)
khenaidoo9cdc1a62019-01-24 21:57:40 -0500171
172 help = fmt.Sprintf("In competing Mode - two cores competing to handle a transaction ")
npujar1d86a522019-11-14 17:11:16 +0530173 flag.BoolVar(&cf.InCompetingMode, "in_competing_mode", defaultInCompetingMode, help)
khenaidoo79232702018-12-04 11:00:41 -0500174
khenaidoo5c11af72018-07-20 17:21:05 -0400175 help = fmt.Sprintf("KV store type")
npujar1d86a522019-11-14 17:11:16 +0530176 flag.StringVar(&(cf.KVStoreType), "kv_store_type", defaultKVStoreType, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400177
178 help = fmt.Sprintf("The default timeout when making a kv store request")
npujar1d86a522019-11-14 17:11:16 +0530179 flag.IntVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", defaultKVStoreTimeout, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400180
181 help = fmt.Sprintf("KV store host")
npujar1d86a522019-11-14 17:11:16 +0530182 flag.StringVar(&(cf.KVStoreHost), "kv_store_host", defaultKVStoreHost, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400183
184 help = fmt.Sprintf("KV store port")
npujar1d86a522019-11-14 17:11:16 +0530185 flag.IntVar(&(cf.KVStorePort), "kv_store_port", defaultKVStorePort, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400186
Richard Jankowskie4d77662018-10-17 13:53:21 -0400187 help = fmt.Sprintf("The time to wait before deleting a completed transaction key")
npujar1d86a522019-11-14 17:11:16 +0530188 flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", defaultKVTxnKeyDelTime, help)
Richard Jankowskie4d77662018-10-17 13:53:21 -0400189
khenaidoo9cdc1a62019-01-24 21:57:40 -0500190 help = fmt.Sprintf("KV store data prefix")
npujar1d86a522019-11-14 17:11:16 +0530191 flag.StringVar(&(cf.KVStoreDataPrefix), "kv_store_data_prefix", defaultKVStoreDataPrefix, help)
khenaidoo9cdc1a62019-01-24 21:57:40 -0500192
khenaidoo5c11af72018-07-20 17:21:05 -0400193 help = fmt.Sprintf("Log level")
Rohan Agrawal7f72f0c2020-01-14 12:05:51 +0000194 flag.StringVar(&(cf.LogLevel), "log_level", defaultLogLevel, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400195
khenaidoob6080322019-01-29 21:47:38 -0500196 help = fmt.Sprintf("Timeout for long running request")
khenaidoo442e7c72020-03-10 16:13:48 -0400197 // TODO: Change this code once all the params and helm charts have been changed to use the different type
198 var temp int64
199 flag.Int64Var(&temp, "timeout_long_request", defaultLongRunningRequestTimeout.Milliseconds(), help)
200 cf.LongRunningRequestTimeout = time.Duration(temp) * time.Millisecond
khenaidoob6080322019-01-29 21:47:38 -0500201
202 help = fmt.Sprintf("Default timeout for regular request")
khenaidoo442e7c72020-03-10 16:13:48 -0400203 flag.Int64Var(&temp, "timeout_request", defaultDefaultRequestTimeout.Milliseconds(), help)
204 cf.DefaultRequestTimeout = time.Duration(temp) * time.Millisecond
khenaidoob6080322019-01-29 21:47:38 -0500205
khenaidoo2c6a0992019-04-29 13:46:56 -0400206 help = fmt.Sprintf("Default Core timeout")
khenaidoo442e7c72020-03-10 16:13:48 -0400207 flag.Int64Var(&temp, "core_timeout", defaultCoreTimeout.Milliseconds(), help)
208 cf.DefaultCoreTimeout = time.Duration(temp) * time.Millisecond
khenaidoo2c6a0992019-04-29 13:46:56 -0400209
khenaidoo5c11af72018-07-20 17:21:05 -0400210 help = fmt.Sprintf("Show startup banner log lines")
npujar1d86a522019-11-14 17:11:16 +0530211 flag.BoolVar(&cf.Banner, "banner", defaultBanner, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400212
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700213 help = fmt.Sprintf("Show version information and exit")
npujar1d86a522019-11-14 17:11:16 +0530214 flag.BoolVar(&cf.DisplayVersionOnly, "version", defaultDisplayVersionOnly, help)
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700215
Richard Jankowski46464e92019-03-05 11:53:55 -0500216 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 +0530217 flag.StringVar(&(cf.CoreBindingKey), "core_binding_key", defaultCoreBindingKey, help)
Richard Jankowski46464e92019-03-05 11:53:55 -0500218
Kent Hagermana6d0c362019-07-30 12:50:21 -0400219 help = fmt.Sprintf("Core pairing group topic")
npujar1d86a522019-11-14 17:11:16 +0530220 flag.StringVar(&cf.CorePairTopic, "core_pair_topic", defaultCorePairTopic, help)
Kent Hagermana6d0c362019-07-30 12:50:21 -0400221
khenaidoob3244212019-08-27 14:32:27 -0400222 help = fmt.Sprintf("The number of retries to connect to a dependent component")
npujar1d86a522019-11-14 17:11:16 +0530223 flag.IntVar(&(cf.MaxConnectionRetries), "max_connection_retries", defaultMaxConnectionRetries, help)
khenaidoob3244212019-08-27 14:32:27 -0400224
Scott Bakeree6a0872019-10-29 15:59:52 -0700225 help = fmt.Sprintf("The number of seconds between each connection retry attempt")
npujar1d86a522019-11-14 17:11:16 +0530226 flag.DurationVar(&(cf.ConnectionRetryInterval), "connection_retry_interval", defaultConnectionRetryInterval, help)
khenaidoob3244212019-08-27 14:32:27 -0400227
Scott Bakeree6a0872019-10-29 15:59:52 -0700228 help = fmt.Sprintf("The number of seconds between liveness probes while in a live state")
npujar1d86a522019-11-14 17:11:16 +0530229 flag.DurationVar(&(cf.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
Scott Bakeree6a0872019-10-29 15:59:52 -0700230
231 help = fmt.Sprintf("The number of seconds between liveness probes while in a not live state")
npujar1d86a522019-11-14 17:11:16 +0530232 flag.DurationVar(&(cf.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
Scott Bakeree6a0872019-10-29 15:59:52 -0700233
Kent Hagermanc4618832019-10-07 12:24:36 -0400234 help = fmt.Sprintf("The host on which to listen to answer liveness and readiness probe queries over HTTP.")
npujar1d86a522019-11-14 17:11:16 +0530235 flag.StringVar(&(cf.ProbeHost), "probe_host", defaultProbeHost, help)
Kent Hagermanc4618832019-10-07 12:24:36 -0400236
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -0700237 help = fmt.Sprintf("The port on which to listen to answer liveness and readiness probe queries over HTTP.")
npujar1d86a522019-11-14 17:11:16 +0530238 flag.IntVar(&(cf.ProbePort), "probe_port", defaultProbePort, help)
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -0700239
khenaidoocfee5f42018-07-19 22:47:38 -0400240 flag.Parse()
khenaidoocfee5f42018-07-19 22:47:38 -0400241}