blob: dca40d005ba103cd16ac85e5dca252579cccece9 [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"
Neha Sharmad1387da2020-05-07 20:07:28 +000029 defaultGrpcAddress = ":50057"
30 defaultKafkaAdapterAddress = "127.0.0.1:9092"
31 defaultKafkaClusterAddress = "127.0.0.1:9094"
npujar1d86a522019-11-14 17:11:16 +053032 defaultKVStoreType = EtcdStoreName
Neha Sharma7d6f3a92020-04-14 15:26:22 +000033 defaultKVStoreTimeout = 5 * time.Second
Neha Sharmad1387da2020-05-07 20:07:28 +000034 defaultKVStoreAddress = "127.0.0.1:2379" // Consul = 8500; Etcd = 2379
npujar1d86a522019-11-14 17:11:16 +053035 defaultKVTxnKeyDelTime = 60
David Bainbridge48d46e12020-03-17 15:05:55 -070036 defaultLogLevel = "WARN"
npujar1d86a522019-11-14 17:11:16 +053037 defaultBanner = false
38 defaultDisplayVersionOnly = false
39 defaultCoreTopic = "rwcore"
40 defaultRWCoreEndpoint = "rwcore"
41 defaultRWCoreKey = "pki/voltha.key"
42 defaultRWCoreCert = "pki/voltha.crt"
43 defaultRWCoreCA = "pki/voltha-CA.pem"
44 defaultAffinityRouterTopic = "affinityRouter"
45 defaultInCompetingMode = true
khenaidoo442e7c72020-03-10 16:13:48 -040046 defaultLongRunningRequestTimeout = 2000 * time.Millisecond
47 defaultDefaultRequestTimeout = 1000 * time.Millisecond
48 defaultCoreTimeout = 1000 * time.Millisecond
npujar1d86a522019-11-14 17:11:16 +053049 defaultCoreBindingKey = "voltha_backend_name"
npujar1d86a522019-11-14 17:11:16 +053050 defaultMaxConnectionRetries = -1 // retries forever
51 defaultConnectionRetryInterval = 2 * time.Second
52 defaultLiveProbeInterval = 60 * time.Second
53 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
Neha Sharmad1387da2020-05-07 20:07:28 +000054 defaultProbeAddress = ":8080"
khenaidoocfee5f42018-07-19 22:47:38 -040055)
56
khenaidoo5c11af72018-07-20 17:21:05 -040057// RWCoreFlags represents the set of configurations used by the read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -040058type RWCoreFlags struct {
59 // Command line parameters
khenaidoo2c6a0992019-04-29 13:46:56 -040060 RWCoreEndpoint string
Neha Sharmad1387da2020-05-07 20:07:28 +000061 GrpcAddress string
62 KafkaAdapterAddress string
63 KafkaClusterAddress string
khenaidoo2c6a0992019-04-29 13:46:56 -040064 KVStoreType string
Neha Sharma7d6f3a92020-04-14 15:26:22 +000065 KVStoreTimeout time.Duration
Neha Sharmad1387da2020-05-07 20:07:28 +000066 KVStoreAddress string
khenaidoo2c6a0992019-04-29 13:46:56 -040067 KVTxnKeyDelTime int
khenaidoo2c6a0992019-04-29 13:46:56 -040068 CoreTopic string
Rohan Agrawal7f72f0c2020-01-14 12:05:51 +000069 LogLevel string
khenaidoo2c6a0992019-04-29 13:46:56 -040070 Banner bool
David K. Bainbridgef430cd52019-05-28 15:00:35 -070071 DisplayVersionOnly bool
khenaidoo2c6a0992019-04-29 13:46:56 -040072 RWCoreKey string
73 RWCoreCert string
74 RWCoreCA string
75 AffinityRouterTopic string
76 InCompetingMode bool
khenaidoo442e7c72020-03-10 16:13:48 -040077 LongRunningRequestTimeout time.Duration
78 DefaultRequestTimeout time.Duration
79 DefaultCoreTimeout time.Duration
khenaidoo2c6a0992019-04-29 13:46:56 -040080 CoreBindingKey string
khenaidoob3244212019-08-27 14:32:27 -040081 MaxConnectionRetries int
Girish Kumar4d3887d2019-11-22 14:22:05 +000082 ConnectionRetryInterval time.Duration
83 LiveProbeInterval time.Duration
84 NotLiveProbeInterval time.Duration
Neha Sharmad1387da2020-05-07 20:07:28 +000085 ProbeAddress string
khenaidoocfee5f42018-07-19 22:47:38 -040086}
87
khenaidoo5c11af72018-07-20 17:21:05 -040088// NewRWCoreFlags returns a new RWCore config
khenaidoocfee5f42018-07-19 22:47:38 -040089func NewRWCoreFlags() *RWCoreFlags {
90 var rwCoreFlag = RWCoreFlags{ // Default values
npujar1d86a522019-11-14 17:11:16 +053091 RWCoreEndpoint: defaultRWCoreEndpoint,
Neha Sharmad1387da2020-05-07 20:07:28 +000092 GrpcAddress: defaultGrpcAddress,
93 KafkaAdapterAddress: defaultKafkaAdapterAddress,
94 KafkaClusterAddress: defaultKafkaClusterAddress,
npujar1d86a522019-11-14 17:11:16 +053095 KVStoreType: defaultKVStoreType,
96 KVStoreTimeout: defaultKVStoreTimeout,
Neha Sharmad1387da2020-05-07 20:07:28 +000097 KVStoreAddress: defaultKVStoreAddress,
npujar1d86a522019-11-14 17:11:16 +053098 KVTxnKeyDelTime: defaultKVTxnKeyDelTime,
99 CoreTopic: defaultCoreTopic,
100 LogLevel: defaultLogLevel,
101 Banner: defaultBanner,
102 DisplayVersionOnly: defaultDisplayVersionOnly,
103 RWCoreKey: defaultRWCoreKey,
104 RWCoreCert: defaultRWCoreCert,
105 RWCoreCA: defaultRWCoreCA,
106 AffinityRouterTopic: defaultAffinityRouterTopic,
107 InCompetingMode: defaultInCompetingMode,
108 DefaultRequestTimeout: defaultDefaultRequestTimeout,
109 LongRunningRequestTimeout: defaultLongRunningRequestTimeout,
110 DefaultCoreTimeout: defaultCoreTimeout,
111 CoreBindingKey: defaultCoreBindingKey,
npujar1d86a522019-11-14 17:11:16 +0530112 MaxConnectionRetries: defaultMaxConnectionRetries,
113 ConnectionRetryInterval: defaultConnectionRetryInterval,
114 LiveProbeInterval: defaultLiveProbeInterval,
115 NotLiveProbeInterval: defaultNotLiveProbeInterval,
Neha Sharmad1387da2020-05-07 20:07:28 +0000116 ProbeAddress: defaultProbeAddress,
khenaidoocfee5f42018-07-19 22:47:38 -0400117 }
118 return &rwCoreFlag
119}
120
khenaidoo5c11af72018-07-20 17:21:05 -0400121// ParseCommandArguments parses the arguments when running read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -0400122func (cf *RWCoreFlags) ParseCommandArguments() {
khenaidoocfee5f42018-07-19 22:47:38 -0400123
npujar1d86a522019-11-14 17:11:16 +0530124 help := fmt.Sprintf("RW core endpoint address")
125 flag.StringVar(&(cf.RWCoreEndpoint), "vcore-endpoint", defaultRWCoreEndpoint, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400126
Neha Sharmad1387da2020-05-07 20:07:28 +0000127 help = fmt.Sprintf("GRPC server - address")
128 flag.StringVar(&(cf.GrpcAddress), "grpc_address", defaultGrpcAddress, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400129
Neha Sharmad1387da2020-05-07 20:07:28 +0000130 help = fmt.Sprintf("Kafka - Adapter messaging address")
131 flag.StringVar(&(cf.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaAdapterAddress, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400132
Neha Sharmad1387da2020-05-07 20:07:28 +0000133 help = fmt.Sprintf("Kafka - Cluster messaging address")
134 flag.StringVar(&(cf.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaClusterAddress, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400135
136 help = fmt.Sprintf("RW Core topic")
npujar1d86a522019-11-14 17:11:16 +0530137 flag.StringVar(&(cf.CoreTopic), "rw_core_topic", defaultCoreTopic, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400138
khenaidoo79232702018-12-04 11:00:41 -0500139 help = fmt.Sprintf("Affinity Router topic")
npujar1d86a522019-11-14 17:11:16 +0530140 flag.StringVar(&(cf.AffinityRouterTopic), "affinity_router_topic", defaultAffinityRouterTopic, help)
khenaidoo9cdc1a62019-01-24 21:57:40 -0500141
142 help = fmt.Sprintf("In competing Mode - two cores competing to handle a transaction ")
npujar1d86a522019-11-14 17:11:16 +0530143 flag.BoolVar(&cf.InCompetingMode, "in_competing_mode", defaultInCompetingMode, help)
khenaidoo79232702018-12-04 11:00:41 -0500144
khenaidoo5c11af72018-07-20 17:21:05 -0400145 help = fmt.Sprintf("KV store type")
npujar1d86a522019-11-14 17:11:16 +0530146 flag.StringVar(&(cf.KVStoreType), "kv_store_type", defaultKVStoreType, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400147
148 help = fmt.Sprintf("The default timeout when making a kv store request")
Neha Sharma7d6f3a92020-04-14 15:26:22 +0000149 flag.DurationVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", defaultKVStoreTimeout, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400150
Neha Sharmad1387da2020-05-07 20:07:28 +0000151 help = fmt.Sprintf("KV store address")
152 flag.StringVar(&(cf.KVStoreAddress), "kv_store_address", defaultKVStoreAddress, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400153
Richard Jankowskie4d77662018-10-17 13:53:21 -0400154 help = fmt.Sprintf("The time to wait before deleting a completed transaction key")
npujar1d86a522019-11-14 17:11:16 +0530155 flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", defaultKVTxnKeyDelTime, help)
Richard Jankowskie4d77662018-10-17 13:53:21 -0400156
khenaidoo5c11af72018-07-20 17:21:05 -0400157 help = fmt.Sprintf("Log level")
Rohan Agrawal7f72f0c2020-01-14 12:05:51 +0000158 flag.StringVar(&(cf.LogLevel), "log_level", defaultLogLevel, help)
khenaidoo5c11af72018-07-20 17:21:05 -0400159
khenaidoob6080322019-01-29 21:47:38 -0500160 help = fmt.Sprintf("Timeout for long running request")
Neha Sharma7d6f3a92020-04-14 15:26:22 +0000161 flag.DurationVar(&(cf.LongRunningRequestTimeout), "timeout_long_request", defaultLongRunningRequestTimeout, help)
khenaidoob6080322019-01-29 21:47:38 -0500162
163 help = fmt.Sprintf("Default timeout for regular request")
Neha Sharma7d6f3a92020-04-14 15:26:22 +0000164 flag.DurationVar(&(cf.DefaultRequestTimeout), "timeout_request", defaultDefaultRequestTimeout, help)
khenaidoob6080322019-01-29 21:47:38 -0500165
khenaidoo2c6a0992019-04-29 13:46:56 -0400166 help = fmt.Sprintf("Default Core timeout")
Neha Sharma7d6f3a92020-04-14 15:26:22 +0000167 flag.DurationVar(&(cf.DefaultCoreTimeout), "core_timeout", defaultCoreTimeout, help)
khenaidoo2c6a0992019-04-29 13:46:56 -0400168
khenaidoo5c11af72018-07-20 17:21:05 -0400169 help = fmt.Sprintf("Show startup banner log lines")
npujar1d86a522019-11-14 17:11:16 +0530170 flag.BoolVar(&cf.Banner, "banner", defaultBanner, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400171
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700172 help = fmt.Sprintf("Show version information and exit")
npujar1d86a522019-11-14 17:11:16 +0530173 flag.BoolVar(&cf.DisplayVersionOnly, "version", defaultDisplayVersionOnly, help)
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700174
Richard Jankowski46464e92019-03-05 11:53:55 -0500175 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 +0530176 flag.StringVar(&(cf.CoreBindingKey), "core_binding_key", defaultCoreBindingKey, help)
Richard Jankowski46464e92019-03-05 11:53:55 -0500177
khenaidoob3244212019-08-27 14:32:27 -0400178 help = fmt.Sprintf("The number of retries to connect to a dependent component")
npujar1d86a522019-11-14 17:11:16 +0530179 flag.IntVar(&(cf.MaxConnectionRetries), "max_connection_retries", defaultMaxConnectionRetries, help)
khenaidoob3244212019-08-27 14:32:27 -0400180
Scott Bakeree6a0872019-10-29 15:59:52 -0700181 help = fmt.Sprintf("The number of seconds between each connection retry attempt")
npujar1d86a522019-11-14 17:11:16 +0530182 flag.DurationVar(&(cf.ConnectionRetryInterval), "connection_retry_interval", defaultConnectionRetryInterval, help)
khenaidoob3244212019-08-27 14:32:27 -0400183
Scott Bakeree6a0872019-10-29 15:59:52 -0700184 help = fmt.Sprintf("The number of seconds between liveness probes while in a live state")
npujar1d86a522019-11-14 17:11:16 +0530185 flag.DurationVar(&(cf.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
Scott Bakeree6a0872019-10-29 15:59:52 -0700186
187 help = fmt.Sprintf("The number of seconds between liveness probes while in a not live state")
npujar1d86a522019-11-14 17:11:16 +0530188 flag.DurationVar(&(cf.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
Scott Bakeree6a0872019-10-29 15:59:52 -0700189
Neha Sharmad1387da2020-05-07 20:07:28 +0000190 help = fmt.Sprintf("The address on which to listen to answer liveness and readiness probe queries over HTTP.")
191 flag.StringVar(&(cf.ProbeAddress), "probe_address", defaultProbeAddress, help)
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -0700192
khenaidoocfee5f42018-07-19 22:47:38 -0400193 flag.Parse()
khenaidoocfee5f42018-07-19 22:47:38 -0400194}