blob: a08e73d3e6aaed65abfcaf828cc57e076e75c839 [file] [log] [blame]
Girish Gowdru0c588b22019-04-23 23:24:56 -04001/*
cbabu116b73f2019-12-10 17:56:32 +05302* Copyright 2018-present Open Networking Foundation
Girish Gowdru0c588b22019-04-23 23:24:56 -04003
cbabu116b73f2019-12-10 17:56:32 +05304* 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
Girish Gowdru0c588b22019-04-23 23:24:56 -04007
cbabu116b73f2019-12-10 17:56:32 +05308* http://www.apache.org/licenses/LICENSE-2.0
Girish Gowdru0c588b22019-04-23 23:24:56 -04009
cbabu116b73f2019-12-10 17:56:32 +053010* 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.
Girish Gowdru0c588b22019-04-23 23:24:56 -040015 */
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070016
17//Package config provides the Log, kvstore, Kafka configuration
Girish Gowdru0c588b22019-04-23 23:24:56 -040018package config
19
20import (
21 "flag"
Girish Gowdru0c588b22019-04-23 23:24:56 -040022 "os"
cbabu116b73f2019-12-10 17:56:32 +053023 "time"
Girish Gowdru0c588b22019-04-23 23:24:56 -040024)
25
26// Open OLT default constants
27const (
cbabu116b73f2019-12-10 17:56:32 +053028 EtcdStoreName = "etcd"
29 defaultInstanceid = "openOlt001"
Neha Sharma3f221ae2020-04-29 19:02:12 +000030 defaultKafkaadapteraddress = "127.0.0.1:9092"
31 defaultKafkaclusteraddress = "127.0.0.1:9094"
cbabu116b73f2019-12-10 17:56:32 +053032 defaultKvstoretype = EtcdStoreName
Neha Sharma3f221ae2020-04-29 19:02:12 +000033 defaultKvstoretimeout = 5 * time.Second
34 defaultKvstoreaddress = "127.0.0.1:2379" // Port: Consul = 8500; Etcd = 2379
David Bainbridge2b3d4882020-03-17 15:06:39 -070035 defaultLoglevel = "WARN"
cbabu116b73f2019-12-10 17:56:32 +053036 defaultBanner = false
37 defaultDisplayVersionOnly = false
38 defaultTopic = "openolt"
39 defaultCoretopic = "rwcore"
40 defaultEventtopic = "voltha.events"
41 defaultOnunumber = 1
Neha Sharma3f221ae2020-04-29 19:02:12 +000042 defaultProbeAddress = ":8080"
cbabu116b73f2019-12-10 17:56:32 +053043 defaultLiveProbeInterval = 60 * time.Second
44 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
Girish Gowdra495dde42021-03-17 14:59:56 -070045 //defaultHeartbeatCheckInterval is the time in seconds the adapter will keep checking the hardware for heartbeat.
46 defaultHeartbeatCheckInterval = 15 * time.Second
47 // defaultHeartbeatFailReportInterval is the time adapter will wait before updating the state to the core.
48 defaultHeartbeatFailReportInterval = 0 * time.Second
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053049 //defaultGrpcTimeoutInterval is the time in seconds a grpc call will wait before returning error.
Girish Kumar11e15972020-06-15 14:51:10 +000050 defaultGrpcTimeoutInterval = 2 * time.Second
51 defaultCurrentReplica = 1
52 defaultTotalReplicas = 1
53 defaultTraceEnabled = false
54 defaultTraceAgentAddress = "127.0.0.1:6831"
55 defaultLogCorrelationEnabled = true
kesavand494c2082020-08-31 11:16:12 +053056 defaultOmccEncryption = false
Gamze Abakafcbd6e72020-12-17 13:25:16 +000057 defaultEnableONUStats = false
58 defaultEnableGEMStats = false
Girish Gowdru0c588b22019-04-23 23:24:56 -040059)
60
61// AdapterFlags represents the set of configurations used by the read-write adaptercore service
62type AdapterFlags struct {
63 // Command line parameters
Matteo Scandolodfa7a972020-11-06 13:03:40 -080064 AdapterName string
65 InstanceID string // NOTE what am I used for? why not cli but only ENV? TODO expose in the chart
Neha Sharma3f221ae2020-04-29 19:02:12 +000066 KafkaAdapterAddress string
67 KafkaClusterAddress string
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053068 KVStoreType string
Neha Sharma3f221ae2020-04-29 19:02:12 +000069 KVStoreTimeout time.Duration
70 KVStoreAddress string
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053071 Topic string
72 CoreTopic string
73 EventTopic string
Rohan Agrawal2488f192020-01-31 09:26:55 +000074 LogLevel string
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053075 OnuNumber int
76 Banner bool
77 DisplayVersionOnly bool
Neha Sharma3f221ae2020-04-29 19:02:12 +000078 ProbeAddress string
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053079 LiveProbeInterval time.Duration
80 NotLiveProbeInterval time.Duration
81 HeartbeatCheckInterval time.Duration
82 HeartbeatFailReportInterval time.Duration
83 GrpcTimeoutInterval time.Duration
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -070084 CurrentReplica int
85 TotalReplicas int
Girish Kumar11e15972020-06-15 14:51:10 +000086 TraceEnabled bool
87 TraceAgentAddress string
88 LogCorrelationEnabled bool
kesavand494c2082020-08-31 11:16:12 +053089 OmccEncryption bool
Gamze Abakafcbd6e72020-12-17 13:25:16 +000090 EnableONUStats bool
91 EnableGEMStats bool
Girish Gowdru0c588b22019-04-23 23:24:56 -040092}
93
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070094// NewAdapterFlags returns a new RWCore config
Girish Gowdru0c588b22019-04-23 23:24:56 -040095func NewAdapterFlags() *AdapterFlags {
96 var adapterFlags = AdapterFlags{ // Default values
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053097 InstanceID: defaultInstanceid,
Neha Sharma3f221ae2020-04-29 19:02:12 +000098 KafkaAdapterAddress: defaultKafkaadapteraddress,
99 KafkaClusterAddress: defaultKafkaclusteraddress,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530100 KVStoreType: defaultKvstoretype,
101 KVStoreTimeout: defaultKvstoretimeout,
Neha Sharma3f221ae2020-04-29 19:02:12 +0000102 KVStoreAddress: defaultKvstoreaddress,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530103 Topic: defaultTopic,
104 CoreTopic: defaultCoretopic,
105 EventTopic: defaultEventtopic,
106 LogLevel: defaultLoglevel,
107 OnuNumber: defaultOnunumber,
108 Banner: defaultBanner,
109 DisplayVersionOnly: defaultDisplayVersionOnly,
Neha Sharma3f221ae2020-04-29 19:02:12 +0000110 ProbeAddress: defaultProbeAddress,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530111 LiveProbeInterval: defaultLiveProbeInterval,
112 NotLiveProbeInterval: defaultNotLiveProbeInterval,
Girish Gowdra495dde42021-03-17 14:59:56 -0700113 HeartbeatCheckInterval: defaultHeartbeatCheckInterval,
114 HeartbeatFailReportInterval: defaultHeartbeatFailReportInterval,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530115 GrpcTimeoutInterval: defaultGrpcTimeoutInterval,
Girish Kumar11e15972020-06-15 14:51:10 +0000116 TraceEnabled: defaultTraceEnabled,
117 TraceAgentAddress: defaultTraceAgentAddress,
118 LogCorrelationEnabled: defaultLogCorrelationEnabled,
kesavand494c2082020-08-31 11:16:12 +0530119 OmccEncryption: defaultOmccEncryption,
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000120 EnableONUStats: defaultEnableONUStats,
121 EnableGEMStats: defaultEnableGEMStats,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400122 }
123 return &adapterFlags
124}
125
126// ParseCommandArguments parses the arguments when running read-write adaptercore service
127func (so *AdapterFlags) ParseCommandArguments() {
128
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300129 flag.StringVar(&(so.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaadapteraddress, "Kafka - Adapter messaging address")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400130
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300131 flag.StringVar(&(so.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaclusteraddress, "Kafka - Cluster messaging address")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400132
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300133 flag.StringVar(&(so.Topic), "adapter_topic", defaultTopic, "Open OLT topic")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400134
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300135 flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoretopic, "Core topic")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400136
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300137 flag.StringVar(&(so.EventTopic), "event_topic", defaultEventtopic, "Event topic")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400138
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300139 flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, "KV store type")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400140
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300141 flag.DurationVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, "The default timeout when making a kv store request")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400142
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300143 flag.StringVar(&(so.KVStoreAddress), "kv_store_address", defaultKvstoreaddress, "KV store address")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400144
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300145 flag.StringVar(&(so.LogLevel), "log_level", defaultLoglevel, "Log level")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400146
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300147 flag.IntVar(&(so.OnuNumber), "onu_number", defaultOnunumber, "Number of ONUs")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400148
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300149 flag.BoolVar(&(so.Banner), "banner", defaultBanner, "Show startup banner log lines")
Matt Jeanneretf880eb62019-07-16 20:08:03 -0400150
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300151 flag.BoolVar(&(so.DisplayVersionOnly), "version", defaultDisplayVersionOnly, "Show version information and exit")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400152
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300153 flag.StringVar(&(so.ProbeAddress), "probe_address", defaultProbeAddress, "The address on which to listen to answer liveness and readiness probe queries over HTTP.")
Rohan Agrawal828bf4e2019-10-22 10:13:19 +0000154
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300155 flag.DurationVar(&(so.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, "Number of seconds for the default liveliness check")
cbabu116b73f2019-12-10 17:56:32 +0530156
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300157 flag.DurationVar(&(so.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, "Number of seconds for liveliness check if probe is not running")
cbabu116b73f2019-12-10 17:56:32 +0530158
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300159 flag.DurationVar(&(so.HeartbeatCheckInterval), "heartbeat_check_interval", defaultHeartbeatCheckInterval, "Number of seconds for heartbeat check interval")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400160
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300161 flag.DurationVar(&(so.HeartbeatFailReportInterval), "heartbeat_fail_interval", defaultHeartbeatFailReportInterval, "Number of seconds adapter has to wait before reporting core on the heartbeat check failure")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530162
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300163 flag.DurationVar(&(so.GrpcTimeoutInterval), "grpc_timeout_interval", defaultGrpcTimeoutInterval, "Number of seconds for GRPC timeout")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530164
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300165 flag.IntVar(&(so.CurrentReplica), "current_replica", defaultCurrentReplica, "Replica number of this particular instance")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700166
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300167 flag.IntVar(&(so.TotalReplicas), "total_replica", defaultTotalReplicas, "Total number of instances for this adapter")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700168
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300169 flag.BoolVar(&(so.TraceEnabled), "trace_enabled", defaultTraceEnabled, "Whether to send logs to tracing agent?")
Girish Kumar11e15972020-06-15 14:51:10 +0000170
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300171 flag.StringVar(&(so.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, "The address of tracing agent to which span info should be sent")
Girish Kumar11e15972020-06-15 14:51:10 +0000172
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300173 flag.BoolVar(&(so.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Girish Kumar11e15972020-06-15 14:51:10 +0000174
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300175 flag.BoolVar(&(so.OmccEncryption), "omcc_encryption", defaultOmccEncryption, "OMCI Channel encryption status")
kesavand494c2082020-08-31 11:16:12 +0530176
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300177 flag.BoolVar(&(so.EnableONUStats), "enable_onu_stats", defaultEnableONUStats, "Enable ONU Statistics")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000178
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300179 flag.BoolVar(&(so.EnableGEMStats), "enable_gem_stats", defaultEnableGEMStats, "Enable GEM Statistics")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000180
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530181 flag.Parse()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400182 containerName := getContainerInfo()
183 if len(containerName) > 0 {
184 so.InstanceID = containerName
185 }
186
187}
188
189func getContainerInfo() string {
190 return os.Getenv("HOSTNAME")
191}