blob: 133b1a41d228a54558572a32bd04f029771fc531 [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"
khenaidoob9203542018-09-17 22:56:37 -040021 "github.com/opencord/voltha-go/common/log"
khenaidoocfee5f42018-07-19 22:47:38 -040022)
23
khenaidoo5c11af72018-07-20 17:21:05 -040024// RW Core service default constants
khenaidoocfee5f42018-07-19 22:47:38 -040025const (
khenaidoo2c6a0992019-04-29 13:46:56 -040026 ConsulStoreName = "consul"
27 EtcdStoreName = "etcd"
khenaidoo2c6a0992019-04-29 13:46:56 -040028 default_GrpcPort = 50057
29 default_GrpcHost = ""
30 default_KafkaAdapterHost = "127.0.0.1"
31 default_KafkaAdapterPort = 9092
32 default_KafkaClusterHost = "127.0.0.1"
33 default_KafkaClusterPort = 9094
34 default_KVStoreType = EtcdStoreName
35 default_KVStoreTimeout = 5 //in seconds
36 default_KVStoreHost = "127.0.0.1"
37 default_KVStorePort = 2379 // Consul = 8500; Etcd = 2379
38 default_KVTxnKeyDelTime = 60
39 default_KVStoreDataPrefix = "service/voltha"
40 default_LogLevel = 0
41 default_Banner = false
David K. Bainbridgef430cd52019-05-28 15:00:35 -070042 default_DisplayVersionOnly = false
khenaidoo2c6a0992019-04-29 13:46:56 -040043 default_CoreTopic = "rwcore"
44 default_RWCoreEndpoint = "rwcore"
45 default_RWCoreKey = "pki/voltha.key"
46 default_RWCoreCert = "pki/voltha.crt"
47 default_RWCoreCA = "pki/voltha-CA.pem"
48 default_AffinityRouterTopic = "affinityRouter"
49 default_InCompetingMode = true
khenaidoob6080322019-01-29 21:47:38 -050050 default_LongRunningRequestTimeout = int64(2000)
khenaidoo2c6a0992019-04-29 13:46:56 -040051 default_DefaultRequestTimeout = int64(500)
52 default_CoreTimeout = int64(500)
53 default_CoreBindingKey = "voltha_backend_name"
Kent Hagermana6d0c362019-07-30 12:50:21 -040054 default_CorePairTopic = "rwcore_1"
khenaidoob3244212019-08-27 14:32:27 -040055 default_MaxConnectionRetries = -1 // retries forever
56 default_ConnectionRetryInterval = 2 // in seconds
khenaidoocfee5f42018-07-19 22:47:38 -040057)
58
khenaidoo5c11af72018-07-20 17:21:05 -040059// RWCoreFlags represents the set of configurations used by the read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -040060type RWCoreFlags struct {
61 // Command line parameters
khenaidoo2c6a0992019-04-29 13:46:56 -040062 RWCoreEndpoint string
63 GrpcHost string
64 GrpcPort int
65 KafkaAdapterHost string
66 KafkaAdapterPort int
67 KafkaClusterHost string
68 KafkaClusterPort int
69 KVStoreType string
70 KVStoreTimeout int // in seconds
71 KVStoreHost string
72 KVStorePort int
73 KVTxnKeyDelTime int
74 KVStoreDataPrefix string
75 CoreTopic string
76 LogLevel int
77 Banner bool
David K. Bainbridgef430cd52019-05-28 15:00:35 -070078 DisplayVersionOnly bool
khenaidoo2c6a0992019-04-29 13:46:56 -040079 RWCoreKey string
80 RWCoreCert string
81 RWCoreCA string
82 AffinityRouterTopic string
83 InCompetingMode bool
khenaidoob6080322019-01-29 21:47:38 -050084 LongRunningRequestTimeout int64
khenaidoo2c6a0992019-04-29 13:46:56 -040085 DefaultRequestTimeout int64
86 DefaultCoreTimeout int64
87 CoreBindingKey string
Kent Hagermana6d0c362019-07-30 12:50:21 -040088 CorePairTopic string
khenaidoob3244212019-08-27 14:32:27 -040089 MaxConnectionRetries int
90 ConnectionRetryInterval int
khenaidoocfee5f42018-07-19 22:47:38 -040091}
92
khenaidoob9203542018-09-17 22:56:37 -040093func init() {
94 log.AddPackage(log.JSON, log.WarnLevel, nil)
95}
96
khenaidoo5c11af72018-07-20 17:21:05 -040097// NewRWCoreFlags returns a new RWCore config
khenaidoocfee5f42018-07-19 22:47:38 -040098func NewRWCoreFlags() *RWCoreFlags {
99 var rwCoreFlag = RWCoreFlags{ // Default values
khenaidoo2c6a0992019-04-29 13:46:56 -0400100 RWCoreEndpoint: default_RWCoreEndpoint,
101 GrpcHost: default_GrpcHost,
102 GrpcPort: default_GrpcPort,
103 KafkaAdapterHost: default_KafkaAdapterHost,
104 KafkaAdapterPort: default_KafkaAdapterPort,
105 KafkaClusterHost: default_KafkaClusterHost,
106 KafkaClusterPort: default_KafkaClusterPort,
107 KVStoreType: default_KVStoreType,
108 KVStoreTimeout: default_KVStoreTimeout,
109 KVStoreHost: default_KVStoreHost,
110 KVStorePort: default_KVStorePort,
111 KVStoreDataPrefix: default_KVStoreDataPrefix,
112 KVTxnKeyDelTime: default_KVTxnKeyDelTime,
113 CoreTopic: default_CoreTopic,
114 LogLevel: default_LogLevel,
115 Banner: default_Banner,
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700116 DisplayVersionOnly: default_DisplayVersionOnly,
khenaidoo2c6a0992019-04-29 13:46:56 -0400117 RWCoreKey: default_RWCoreKey,
118 RWCoreCert: default_RWCoreCert,
119 RWCoreCA: default_RWCoreCA,
120 AffinityRouterTopic: default_AffinityRouterTopic,
121 InCompetingMode: default_InCompetingMode,
122 DefaultRequestTimeout: default_DefaultRequestTimeout,
123 LongRunningRequestTimeout: default_LongRunningRequestTimeout,
124 DefaultCoreTimeout: default_CoreTimeout,
125 CoreBindingKey: default_CoreBindingKey,
Kent Hagermana6d0c362019-07-30 12:50:21 -0400126 CorePairTopic: default_CorePairTopic,
khenaidoob3244212019-08-27 14:32:27 -0400127 MaxConnectionRetries: default_MaxConnectionRetries,
128 ConnectionRetryInterval: default_ConnectionRetryInterval,
khenaidoocfee5f42018-07-19 22:47:38 -0400129 }
130 return &rwCoreFlag
131}
132
khenaidoo5c11af72018-07-20 17:21:05 -0400133// ParseCommandArguments parses the arguments when running read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -0400134func (cf *RWCoreFlags) ParseCommandArguments() {
khenaidoocfee5f42018-07-19 22:47:38 -0400135
khenaidoo5c11af72018-07-20 17:21:05 -0400136 var help string
khenaidoocfee5f42018-07-19 22:47:38 -0400137
khenaidoo5c11af72018-07-20 17:21:05 -0400138 help = fmt.Sprintf("RW core endpoint address")
139 flag.StringVar(&(cf.RWCoreEndpoint), "vcore-endpoint", default_RWCoreEndpoint, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400140
khenaidoo5c11af72018-07-20 17:21:05 -0400141 help = fmt.Sprintf("GRPC server - host")
142 flag.StringVar(&(cf.GrpcHost), "grpc_host", default_GrpcHost, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400143
khenaidoo5c11af72018-07-20 17:21:05 -0400144 help = fmt.Sprintf("GRPC server - port")
145 flag.IntVar(&(cf.GrpcPort), "grpc_port", default_GrpcPort, help)
146
147 help = fmt.Sprintf("Kafka - Adapter messaging host")
148 flag.StringVar(&(cf.KafkaAdapterHost), "kafka_adapter_host", default_KafkaAdapterHost, help)
149
150 help = fmt.Sprintf("Kafka - Adapter messaging port")
151 flag.IntVar(&(cf.KafkaAdapterPort), "kafka_adapter_port", default_KafkaAdapterPort, help)
152
153 help = fmt.Sprintf("Kafka - Cluster messaging host")
154 flag.StringVar(&(cf.KafkaClusterHost), "kafka_cluster_host", default_KafkaClusterHost, help)
155
156 help = fmt.Sprintf("Kafka - Cluster messaging port")
157 flag.IntVar(&(cf.KafkaClusterPort), "kafka_cluster_port", default_KafkaClusterPort, help)
158
159 help = fmt.Sprintf("RW Core topic")
160 flag.StringVar(&(cf.CoreTopic), "rw_core_topic", default_CoreTopic, help)
161
khenaidoo79232702018-12-04 11:00:41 -0500162 help = fmt.Sprintf("Affinity Router topic")
khenaidoo9cdc1a62019-01-24 21:57:40 -0500163 flag.StringVar(&(cf.AffinityRouterTopic), "affinity_router_topic", default_AffinityRouterTopic, help)
164
165 help = fmt.Sprintf("In competing Mode - two cores competing to handle a transaction ")
166 flag.BoolVar(&cf.InCompetingMode, "in_competing_mode", default_InCompetingMode, help)
khenaidoo79232702018-12-04 11:00:41 -0500167
khenaidoo5c11af72018-07-20 17:21:05 -0400168 help = fmt.Sprintf("KV store type")
169 flag.StringVar(&(cf.KVStoreType), "kv_store_type", default_KVStoreType, help)
170
171 help = fmt.Sprintf("The default timeout when making a kv store request")
172 flag.IntVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", default_KVStoreTimeout, help)
173
174 help = fmt.Sprintf("KV store host")
175 flag.StringVar(&(cf.KVStoreHost), "kv_store_host", default_KVStoreHost, help)
176
177 help = fmt.Sprintf("KV store port")
178 flag.IntVar(&(cf.KVStorePort), "kv_store_port", default_KVStorePort, help)
179
Richard Jankowskie4d77662018-10-17 13:53:21 -0400180 help = fmt.Sprintf("The time to wait before deleting a completed transaction key")
181 flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", default_KVTxnKeyDelTime, help)
182
khenaidoo9cdc1a62019-01-24 21:57:40 -0500183 help = fmt.Sprintf("KV store data prefix")
184 flag.StringVar(&(cf.KVStoreDataPrefix), "kv_store_data_prefix", default_KVStoreDataPrefix, help)
185
khenaidoo5c11af72018-07-20 17:21:05 -0400186 help = fmt.Sprintf("Log level")
187 flag.IntVar(&(cf.LogLevel), "log_level", default_LogLevel, help)
188
khenaidoob6080322019-01-29 21:47:38 -0500189 help = fmt.Sprintf("Timeout for long running request")
190 flag.Int64Var(&(cf.LongRunningRequestTimeout), "timeout_long_request", default_LongRunningRequestTimeout, help)
191
192 help = fmt.Sprintf("Default timeout for regular request")
193 flag.Int64Var(&(cf.DefaultRequestTimeout), "timeout_request", default_DefaultRequestTimeout, help)
194
khenaidoo2c6a0992019-04-29 13:46:56 -0400195 help = fmt.Sprintf("Default Core timeout")
196 flag.Int64Var(&(cf.DefaultCoreTimeout), "core_timeout", default_CoreTimeout, help)
197
khenaidoo5c11af72018-07-20 17:21:05 -0400198 help = fmt.Sprintf("Show startup banner log lines")
199 flag.BoolVar(&cf.Banner, "banner", default_Banner, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400200
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700201 help = fmt.Sprintf("Show version information and exit")
202 flag.BoolVar(&cf.DisplayVersionOnly, "version", default_DisplayVersionOnly, help)
203
Richard Jankowski46464e92019-03-05 11:53:55 -0500204 help = fmt.Sprintf("The name of the meta-key whose value is the rw-core group to which the ofagent is bound")
205 flag.StringVar(&(cf.CoreBindingKey), "core_binding_key", default_CoreBindingKey, help)
206
Kent Hagermana6d0c362019-07-30 12:50:21 -0400207 help = fmt.Sprintf("Core pairing group topic")
208 flag.StringVar(&cf.CorePairTopic, "core_pair_topic", default_CorePairTopic, help)
209
khenaidoob3244212019-08-27 14:32:27 -0400210 help = fmt.Sprintf("The number of retries to connect to a dependent component")
211 flag.IntVar(&(cf.MaxConnectionRetries), "max_connection_retries", default_MaxConnectionRetries, help)
212
213 help = fmt.Sprintf("The number of seconds between each connection retry attempt ")
214 flag.IntVar(&(cf.ConnectionRetryInterval), "connection_retry_interval", default_ConnectionRetryInterval, help)
215
khenaidoocfee5f42018-07-19 22:47:38 -0400216 flag.Parse()
khenaidoocfee5f42018-07-19 22:47:38 -0400217}