blob: 6c2283d2feaeb7e1ac0d96d76e91abdf9dc207f5 [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
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 */
16
17//Package config provides the Log, kvstore, Kafka configuration
18package config
19
20import (
21 "flag"
22 "fmt"
23 "os"
24 "time"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000025)
26
27// Open ONU default constants
28const (
Himani Chawla6d2ae152020-09-02 13:11:20 +053029 etcdStoreName = "etcd"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000030 defaultInstanceid = "openonu"
31 defaultKafkaadapterhost = "192.168.0.20"
32 defaultKafkaadapterport = 9092
33 defaultKafkaclusterhost = "10.100.198.220"
34 defaultKafkaclusterport = 9092
Himani Chawla6d2ae152020-09-02 13:11:20 +053035 defaultKvstoretype = etcdStoreName
mpagenkoaf801632020-07-03 10:00:42 +000036 defaultKvstoretimeout = 5 * time.Second
Holger Hildebrandtfa074992020-03-27 15:42:06 +000037 defaultKvstorehost = "localhost"
38 defaultKvstoreport = 2379 // Consul = 8500; Etcd = 2379
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000039 defaultLoglevel = "WARN"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000040 defaultBanner = false
41 defaultDisplayVersionOnly = false
mpagenkodff5dda2020-08-28 11:52:01 +000042 defaultAccIncrEvto = false
Holger Hildebrandtfa074992020-03-27 15:42:06 +000043 defaultTopic = "openonu"
Holger Hildebrandta768fe92020-10-01 13:06:21 +000044 defaultOltTopic = "openolt"
45 defaultCoreTopic = "rwcore"
46 defaultEventTopic = "voltha.events"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000047 defaultOnunumber = 1
48 defaultProbeHost = ""
49 defaultProbePort = 8080
50 defaultLiveProbeInterval = 60 * time.Second
51 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
52 //defaultHearbeatFailReportInterval is the time in seconds the adapter will keep checking the hardware for heartbeat.
53 defaultHearbeatCheckInterval = 30 * time.Second
54 // defaultHearbeatFailReportInterval is the time adapter will wait before updating the state to the core.
55 defaultHearbeatFailReportInterval = 180 * time.Second
56 //defaultKafkaReconnectRetries -1: reconnect endlessly.
Himani Chawlad96df182020-09-28 11:12:02 +053057 defaultKafkaReconnectRetries = -1
58 defaultCurrentReplica = 1
59 defaultTotalReplicas = 1
60 defaultMaxTimeoutInterAdapterComm = 30 * time.Second
dbainbri4d3a0dc2020-12-02 00:33:42 +000061
62 // For Tracing
63 defaultTraceEnabled = false
64 defaultTraceAgentAddress = "127.0.0.1:6831"
65 defaultLogCorrelationEnabled = true
Holger Hildebrandtfa074992020-03-27 15:42:06 +000066)
67
68// AdapterFlags represents the set of configurations used by the read-write adaptercore service
69type AdapterFlags struct {
70 // Command line parameters
71 InstanceID string
72 KafkaAdapterHost string
73 KafkaAdapterPort int
74 KafkaClusterHost string
75 KafkaClusterPort int
76 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000077 KVStoreTimeout time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +000078 KVStoreHost string
79 KVStorePort int
80 Topic string
Holger Hildebrandta768fe92020-10-01 13:06:21 +000081 OltTopic string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000082 CoreTopic string
83 EventTopic string
84 LogLevel string
85 OnuNumber int
86 Banner bool
87 DisplayVersionOnly bool
mpagenkodff5dda2020-08-28 11:52:01 +000088 AccIncrEvto bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000089 ProbeHost string
90 ProbePort int
91 LiveProbeInterval time.Duration
92 NotLiveProbeInterval time.Duration
93 HeartbeatCheckInterval time.Duration
94 HeartbeatFailReportInterval time.Duration
95 KafkaReconnectRetries int
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000096 CurrentReplica int
97 TotalReplicas int
Himani Chawlad96df182020-09-28 11:12:02 +053098 MaxTimeoutInterAdapterComm time.Duration
dbainbri4d3a0dc2020-12-02 00:33:42 +000099 TraceEnabled bool
100 TraceAgentAddress string
101 LogCorrelationEnabled bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000102}
103
104// NewAdapterFlags returns a new RWCore config
105func NewAdapterFlags() *AdapterFlags {
106 var adapterFlags = AdapterFlags{ // Default values
107 InstanceID: defaultInstanceid,
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 Topic: defaultTopic,
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000117 OltTopic: defaultOltTopic,
118 CoreTopic: defaultCoreTopic,
119 EventTopic: defaultEventTopic,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000120 LogLevel: defaultLoglevel,
121 OnuNumber: defaultOnunumber,
122 Banner: defaultBanner,
123 DisplayVersionOnly: defaultDisplayVersionOnly,
mpagenkodff5dda2020-08-28 11:52:01 +0000124 AccIncrEvto: defaultAccIncrEvto,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000125 ProbeHost: defaultProbeHost,
126 ProbePort: defaultProbePort,
127 LiveProbeInterval: defaultLiveProbeInterval,
128 NotLiveProbeInterval: defaultNotLiveProbeInterval,
129 HeartbeatCheckInterval: defaultHearbeatCheckInterval,
130 HeartbeatFailReportInterval: defaultHearbeatFailReportInterval,
131 KafkaReconnectRetries: defaultKafkaReconnectRetries,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000132 CurrentReplica: defaultCurrentReplica,
133 TotalReplicas: defaultTotalReplicas,
Himani Chawlad96df182020-09-28 11:12:02 +0530134 MaxTimeoutInterAdapterComm: defaultMaxTimeoutInterAdapterComm,
dbainbri4d3a0dc2020-12-02 00:33:42 +0000135 TraceEnabled: defaultTraceEnabled,
136 TraceAgentAddress: defaultTraceAgentAddress,
137 LogCorrelationEnabled: defaultLogCorrelationEnabled,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000138 }
139 return &adapterFlags
140}
141
142// ParseCommandArguments parses the arguments when running read-write adaptercore service
143func (so *AdapterFlags) ParseCommandArguments() {
144
145 help := fmt.Sprintf("Kafka - Adapter messaging host")
146 flag.StringVar(&(so.KafkaAdapterHost), "kafka_adapter_host", defaultKafkaadapterhost, help)
147
148 help = fmt.Sprintf("Kafka - Adapter messaging port")
149 flag.IntVar(&(so.KafkaAdapterPort), "kafka_adapter_port", defaultKafkaadapterport, help)
150
151 help = fmt.Sprintf("Kafka - Cluster messaging host")
152 flag.StringVar(&(so.KafkaClusterHost), "kafka_cluster_host", defaultKafkaclusterhost, help)
153
154 help = fmt.Sprintf("Kafka - Cluster messaging port")
155 flag.IntVar(&(so.KafkaClusterPort), "kafka_cluster_port", defaultKafkaclusterport, help)
156
157 help = fmt.Sprintf("Open ONU topic")
158 flag.StringVar(&(so.Topic), "adapter_topic", defaultTopic, help)
159
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000160 help = fmt.Sprintf("Open OLT topic")
161 flag.StringVar(&(so.OltTopic), "olt_adapter_topic", defaultOltTopic, help)
162
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000163 help = fmt.Sprintf("Core topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000164 flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoreTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000165
166 help = fmt.Sprintf("Event topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000167 flag.StringVar(&(so.EventTopic), "event_topic", defaultEventTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000168
169 help = fmt.Sprintf("KV store type")
170 flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, help)
171
172 help = fmt.Sprintf("The default timeout when making a kv store request")
mpagenkoaf801632020-07-03 10:00:42 +0000173 flag.DurationVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000174
175 help = fmt.Sprintf("KV store host")
176 flag.StringVar(&(so.KVStoreHost), "kv_store_host", defaultKvstorehost, help)
177
178 help = fmt.Sprintf("KV store port")
179 flag.IntVar(&(so.KVStorePort), "kv_store_port", defaultKvstoreport, help)
180
181 help = fmt.Sprintf("Log level")
182 flag.StringVar(&(so.LogLevel), "log_level", defaultLoglevel, help)
183
184 help = fmt.Sprintf("Number of ONUs")
185 flag.IntVar(&(so.OnuNumber), "onu_number", defaultOnunumber, help)
186
187 help = fmt.Sprintf("Show startup banner log lines")
188 flag.BoolVar(&(so.Banner), "banner", defaultBanner, help)
189
190 help = fmt.Sprintf("Show version information and exit")
191 flag.BoolVar(&(so.DisplayVersionOnly), "version", defaultDisplayVersionOnly, help)
192
mpagenkodff5dda2020-08-28 11:52:01 +0000193 help = fmt.Sprintf("Acceptance of incremental EVTOCD configuration")
194 flag.BoolVar(&(so.AccIncrEvto), "accept_incr_evto", defaultAccIncrEvto, help)
195
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000196 help = fmt.Sprintf("The address on which to listen to answer liveness and readiness probe queries over HTTP.")
197 flag.StringVar(&(so.ProbeHost), "probe_host", defaultProbeHost, help)
198
199 help = fmt.Sprintf("The port on which to listen to answer liveness and readiness probe queries over HTTP.")
200 flag.IntVar(&(so.ProbePort), "probe_port", defaultProbePort, help)
201
202 help = fmt.Sprintf("Number of seconds for the default liveliness check")
203 flag.DurationVar(&(so.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
204
205 help = fmt.Sprintf("Number of seconds for liveliness check if probe is not running")
206 flag.DurationVar(&(so.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
207
208 help = fmt.Sprintf("Number of seconds for heartbeat check interval.")
209 flag.DurationVar(&(so.HeartbeatCheckInterval), "hearbeat_check_interval", defaultHearbeatCheckInterval, help)
210
211 help = fmt.Sprintf("Number of seconds adapter has to wait before reporting core on the hearbeat check failure.")
212 flag.DurationVar(&(so.HeartbeatFailReportInterval), "hearbeat_fail_interval", defaultHearbeatFailReportInterval, help)
213
214 help = fmt.Sprintf("Number of retries to connect to Kafka.")
215 flag.IntVar(&(so.KafkaReconnectRetries), "kafka_reconnect_retries", defaultKafkaReconnectRetries, help)
216
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000217 help = "Replica number of this particular instance (default: %s)"
218 flag.IntVar(&(so.CurrentReplica), "current_replica", defaultCurrentReplica, help)
219
220 help = "Total number of instances for this adapter"
221 flag.IntVar(&(so.TotalReplicas), "total_replica", defaultTotalReplicas, help)
222
Himani Chawlad96df182020-09-28 11:12:02 +0530223 help = fmt.Sprintf("Maximum Number of seconds for the default interadapter communication timeout")
224 flag.DurationVar(&(so.MaxTimeoutInterAdapterComm), "max_timeout_interadapter_comm",
225 defaultMaxTimeoutInterAdapterComm, help)
226
dbainbri4d3a0dc2020-12-02 00:33:42 +0000227 help = fmt.Sprintf("Whether to send logs to tracing agent?")
228 flag.BoolVar(&(so.TraceEnabled), "trace_enabled", defaultTraceEnabled, help)
229
230 help = fmt.Sprintf("The address of tracing agent to which span info should be sent.")
231 flag.StringVar(&(so.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, help)
232
233 help = fmt.Sprintf("Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
234 flag.BoolVar(&(so.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, help)
235
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000236 flag.Parse()
237 containerName := getContainerInfo()
238 if len(containerName) > 0 {
239 so.InstanceID = containerName
240 }
241
242}
243
244func getContainerInfo() string {
245 return os.Getenv("HOSTNAME")
246}