blob: e7e5c4f81cf0956303f4e63d7cd8689266417e75 [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
Neha Sharma7d6f3a92020-04-14 15:26:22 +000036 defaultKVStoreTimeout = 5 * time.Second
npujar1d86a522019-11-14 17:11:16 +053037 defaultKVStoreHost = "127.0.0.1"
38 defaultKVStorePort = 2379 // Consul = 8500; Etcd = 2379
39 defaultKVTxnKeyDelTime = 60
David Bainbridge48d46e12020-03-17 15:05:55 -070040 defaultLogLevel = "WARN"
npujar1d86a522019-11-14 17:11:16 +053041 defaultBanner = false
42 defaultDisplayVersionOnly = false
43 defaultCoreTopic = "rwcore"
44 defaultRWCoreEndpoint = "rwcore"
45 defaultRWCoreKey = "pki/voltha.key"
46 defaultRWCoreCert = "pki/voltha.crt"
47 defaultRWCoreCA = "pki/voltha-CA.pem"
48 defaultAffinityRouterTopic = "affinityRouter"
49 defaultInCompetingMode = true
khenaidoo442e7c72020-03-10 16:13:48 -040050 defaultLongRunningRequestTimeout = 2000 * time.Millisecond
51 defaultDefaultRequestTimeout = 1000 * time.Millisecond
52 defaultCoreTimeout = 1000 * time.Millisecond
npujar1d86a522019-11-14 17:11:16 +053053 defaultCoreBindingKey = "voltha_backend_name"
npujar1d86a522019-11-14 17:11:16 +053054 defaultMaxConnectionRetries = -1 // retries forever
55 defaultConnectionRetryInterval = 2 * time.Second
56 defaultLiveProbeInterval = 60 * time.Second
57 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
58 defaultProbeHost = ""
59 defaultProbePort = 8080
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
khenaidoo2c6a0992019-04-29 13:46:56 -040065 RWCoreEndpoint string
66 GrpcHost string
67 GrpcPort int
68 KafkaAdapterHost string
69 KafkaAdapterPort int
70 KafkaClusterHost string
71 KafkaClusterPort int
72 KVStoreType string
Neha Sharma7d6f3a92020-04-14 15:26:22 +000073 KVStoreTimeout time.Duration
khenaidoo2c6a0992019-04-29 13:46:56 -040074 KVStoreHost string
75 KVStorePort int
76 KVTxnKeyDelTime int
khenaidoo2c6a0992019-04-29 13:46:56 -040077 CoreTopic string
Rohan Agrawal7f72f0c2020-01-14 12:05:51 +000078 LogLevel string
khenaidoo2c6a0992019-04-29 13:46:56 -040079 Banner bool
David K. Bainbridgef430cd52019-05-28 15:00:35 -070080 DisplayVersionOnly bool
khenaidoo2c6a0992019-04-29 13:46:56 -040081 RWCoreKey string
82 RWCoreCert string
83 RWCoreCA string
84 AffinityRouterTopic string
85 InCompetingMode bool
khenaidoo442e7c72020-03-10 16:13:48 -040086 LongRunningRequestTimeout time.Duration
87 DefaultRequestTimeout time.Duration
88 DefaultCoreTimeout time.Duration
khenaidoo2c6a0992019-04-29 13:46:56 -040089 CoreBindingKey string
khenaidoob3244212019-08-27 14:32:27 -040090 MaxConnectionRetries int
Girish Kumar4d3887d2019-11-22 14:22:05 +000091 ConnectionRetryInterval time.Duration
92 LiveProbeInterval time.Duration
93 NotLiveProbeInterval time.Duration
Kent Hagermanc4618832019-10-07 12:24:36 -040094 ProbeHost string
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -070095 ProbePort int
khenaidoocfee5f42018-07-19 22:47:38 -040096}
97
khenaidoo5c11af72018-07-20 17:21:05 -040098// NewRWCoreFlags returns a new RWCore config
khenaidoocfee5f42018-07-19 22:47:38 -040099func NewRWCoreFlags() *RWCoreFlags {
100 var rwCoreFlag = RWCoreFlags{ // Default values
npujar1d86a522019-11-14 17:11:16 +0530101 RWCoreEndpoint: defaultRWCoreEndpoint,
102 GrpcHost: defaultGrpcHost,
103 GrpcPort: defaultGrpcPort,
104 KafkaAdapterHost: defaultKafkaAdapterHost,
105 KafkaAdapterPort: defaultKafkaAdapterPort,
106 KafkaClusterHost: defaultKafkaClusterHost,
107 KafkaClusterPort: defaultKafkaClusterPort,
108 KVStoreType: defaultKVStoreType,
109 KVStoreTimeout: defaultKVStoreTimeout,
110 KVStoreHost: defaultKVStoreHost,
111 KVStorePort: defaultKVStorePort,
npujar1d86a522019-11-14 17:11:16 +0530112 KVTxnKeyDelTime: defaultKVTxnKeyDelTime,
113 CoreTopic: defaultCoreTopic,
114 LogLevel: defaultLogLevel,
115 Banner: defaultBanner,
116 DisplayVersionOnly: defaultDisplayVersionOnly,
117 RWCoreKey: defaultRWCoreKey,
118 RWCoreCert: defaultRWCoreCert,
119 RWCoreCA: defaultRWCoreCA,
120 AffinityRouterTopic: defaultAffinityRouterTopic,
121 InCompetingMode: defaultInCompetingMode,
122 DefaultRequestTimeout: defaultDefaultRequestTimeout,
123 LongRunningRequestTimeout: defaultLongRunningRequestTimeout,
124 DefaultCoreTimeout: defaultCoreTimeout,
125 CoreBindingKey: defaultCoreBindingKey,
npujar1d86a522019-11-14 17:11:16 +0530126 MaxConnectionRetries: defaultMaxConnectionRetries,
127 ConnectionRetryInterval: defaultConnectionRetryInterval,
128 LiveProbeInterval: defaultLiveProbeInterval,
129 NotLiveProbeInterval: defaultNotLiveProbeInterval,
130 ProbeHost: defaultProbeHost,
131 ProbePort: defaultProbePort,
khenaidoocfee5f42018-07-19 22:47:38 -0400132 }
133 return &rwCoreFlag
134}
135
khenaidoo5c11af72018-07-20 17:21:05 -0400136// ParseCommandArguments parses the arguments when running read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -0400137func (cf *RWCoreFlags) ParseCommandArguments() {
khenaidoocfee5f42018-07-19 22:47:38 -0400138
npujar1d86a522019-11-14 17:11:16 +0530139 help := fmt.Sprintf("RW core endpoint address")
140 flag.StringVar(&(cf.RWCoreEndpoint), "vcore-endpoint", defaultRWCoreEndpoint, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400141
khenaidoo5c11af72018-07-20 17:21:05 -0400142 help = fmt.Sprintf("GRPC server - host")
npujar1d86a522019-11-14 17:11:16 +0530143 flag.StringVar(&(cf.GrpcHost), "grpc_host", defaultGrpcHost, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400144
khenaidoo5c11af72018-07-20 17:21:05 -0400145 help = fmt.Sprintf("GRPC server - port")
npujar1d86a522019-11-14 17:11:16 +0530146 flag.IntVar(&(cf.GrpcPort), "grpc_port", defaultGrpcPort, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400147
148 help = fmt.Sprintf("Kafka - Adapter messaging host")
npujar1d86a522019-11-14 17:11:16 +0530149 flag.StringVar(&(cf.KafkaAdapterHost), "kafka_adapter_host", defaultKafkaAdapterHost, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400150
151 help = fmt.Sprintf("Kafka - Adapter messaging port")
npujar1d86a522019-11-14 17:11:16 +0530152 flag.IntVar(&(cf.KafkaAdapterPort), "kafka_adapter_port", defaultKafkaAdapterPort, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400153
154 help = fmt.Sprintf("Kafka - Cluster messaging host")
npujar1d86a522019-11-14 17:11:16 +0530155 flag.StringVar(&(cf.KafkaClusterHost), "kafka_cluster_host", defaultKafkaClusterHost, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400156
157 help = fmt.Sprintf("Kafka - Cluster messaging port")
npujar1d86a522019-11-14 17:11:16 +0530158 flag.IntVar(&(cf.KafkaClusterPort), "kafka_cluster_port", defaultKafkaClusterPort, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400159
160 help = fmt.Sprintf("RW Core topic")
npujar1d86a522019-11-14 17:11:16 +0530161 flag.StringVar(&(cf.CoreTopic), "rw_core_topic", defaultCoreTopic, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400162
khenaidoo79232702018-12-04 11:00:41 -0500163 help = fmt.Sprintf("Affinity Router topic")
npujar1d86a522019-11-14 17:11:16 +0530164 flag.StringVar(&(cf.AffinityRouterTopic), "affinity_router_topic", defaultAffinityRouterTopic, help)
khenaidoo9cdc1a62019-01-24 21:57:40 -0500165
166 help = fmt.Sprintf("In competing Mode - two cores competing to handle a transaction ")
npujar1d86a522019-11-14 17:11:16 +0530167 flag.BoolVar(&cf.InCompetingMode, "in_competing_mode", defaultInCompetingMode, help)
khenaidoo79232702018-12-04 11:00:41 -0500168
khenaidoo5c11af72018-07-20 17:21:05 -0400169 help = fmt.Sprintf("KV store type")
npujar1d86a522019-11-14 17:11:16 +0530170 flag.StringVar(&(cf.KVStoreType), "kv_store_type", defaultKVStoreType, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400171
172 help = fmt.Sprintf("The default timeout when making a kv store request")
Neha Sharma7d6f3a92020-04-14 15:26:22 +0000173 flag.DurationVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", defaultKVStoreTimeout, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400174
175 help = fmt.Sprintf("KV store host")
npujar1d86a522019-11-14 17:11:16 +0530176 flag.StringVar(&(cf.KVStoreHost), "kv_store_host", defaultKVStoreHost, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400177
178 help = fmt.Sprintf("KV store port")
npujar1d86a522019-11-14 17:11:16 +0530179 flag.IntVar(&(cf.KVStorePort), "kv_store_port", defaultKVStorePort, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400180
Richard Jankowskie4d77662018-10-17 13:53:21 -0400181 help = fmt.Sprintf("The time to wait before deleting a completed transaction key")
npujar1d86a522019-11-14 17:11:16 +0530182 flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", defaultKVTxnKeyDelTime, help)
Richard Jankowskie4d77662018-10-17 13:53:21 -0400183
khenaidoo5c11af72018-07-20 17:21:05 -0400184 help = fmt.Sprintf("Log level")
Rohan Agrawal7f72f0c2020-01-14 12:05:51 +0000185 flag.StringVar(&(cf.LogLevel), "log_level", defaultLogLevel, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400186
khenaidoob6080322019-01-29 21:47:38 -0500187 help = fmt.Sprintf("Timeout for long running request")
Neha Sharma7d6f3a92020-04-14 15:26:22 +0000188 flag.DurationVar(&(cf.LongRunningRequestTimeout), "timeout_long_request", defaultLongRunningRequestTimeout, help)
khenaidoob6080322019-01-29 21:47:38 -0500189
190 help = fmt.Sprintf("Default timeout for regular request")
Neha Sharma7d6f3a92020-04-14 15:26:22 +0000191 flag.DurationVar(&(cf.DefaultRequestTimeout), "timeout_request", defaultDefaultRequestTimeout, help)
khenaidoob6080322019-01-29 21:47:38 -0500192
khenaidoo2c6a0992019-04-29 13:46:56 -0400193 help = fmt.Sprintf("Default Core timeout")
Neha Sharma7d6f3a92020-04-14 15:26:22 +0000194 flag.DurationVar(&(cf.DefaultCoreTimeout), "core_timeout", defaultCoreTimeout, help)
khenaidoo2c6a0992019-04-29 13:46:56 -0400195
khenaidoo5c11af72018-07-20 17:21:05 -0400196 help = fmt.Sprintf("Show startup banner log lines")
npujar1d86a522019-11-14 17:11:16 +0530197 flag.BoolVar(&cf.Banner, "banner", defaultBanner, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400198
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700199 help = fmt.Sprintf("Show version information and exit")
npujar1d86a522019-11-14 17:11:16 +0530200 flag.BoolVar(&cf.DisplayVersionOnly, "version", defaultDisplayVersionOnly, help)
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700201
Richard Jankowski46464e92019-03-05 11:53:55 -0500202 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 +0530203 flag.StringVar(&(cf.CoreBindingKey), "core_binding_key", defaultCoreBindingKey, help)
Richard Jankowski46464e92019-03-05 11:53:55 -0500204
khenaidoob3244212019-08-27 14:32:27 -0400205 help = fmt.Sprintf("The number of retries to connect to a dependent component")
npujar1d86a522019-11-14 17:11:16 +0530206 flag.IntVar(&(cf.MaxConnectionRetries), "max_connection_retries", defaultMaxConnectionRetries, help)
khenaidoob3244212019-08-27 14:32:27 -0400207
Scott Bakeree6a0872019-10-29 15:59:52 -0700208 help = fmt.Sprintf("The number of seconds between each connection retry attempt")
npujar1d86a522019-11-14 17:11:16 +0530209 flag.DurationVar(&(cf.ConnectionRetryInterval), "connection_retry_interval", defaultConnectionRetryInterval, help)
khenaidoob3244212019-08-27 14:32:27 -0400210
Scott Bakeree6a0872019-10-29 15:59:52 -0700211 help = fmt.Sprintf("The number of seconds between liveness probes while in a live state")
npujar1d86a522019-11-14 17:11:16 +0530212 flag.DurationVar(&(cf.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
Scott Bakeree6a0872019-10-29 15:59:52 -0700213
214 help = fmt.Sprintf("The number of seconds between liveness probes while in a not live state")
npujar1d86a522019-11-14 17:11:16 +0530215 flag.DurationVar(&(cf.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
Scott Bakeree6a0872019-10-29 15:59:52 -0700216
Kent Hagermanc4618832019-10-07 12:24:36 -0400217 help = fmt.Sprintf("The host on which to listen to answer liveness and readiness probe queries over HTTP.")
npujar1d86a522019-11-14 17:11:16 +0530218 flag.StringVar(&(cf.ProbeHost), "probe_host", defaultProbeHost, help)
Kent Hagermanc4618832019-10-07 12:24:36 -0400219
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -0700220 help = fmt.Sprintf("The port on which to listen to answer liveness and readiness probe queries over HTTP.")
npujar1d86a522019-11-14 17:11:16 +0530221 flag.IntVar(&(cf.ProbePort), "probe_port", defaultProbePort, help)
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -0700222
khenaidoocfee5f42018-07-19 22:47:38 -0400223 flag.Parse()
khenaidoocfee5f42018-07-19 22:47:38 -0400224}