Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1 | /* |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 3 | |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 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 |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 7 | |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 9 | |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 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. |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 15 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 16 | |
| 17 | //Package config provides the Log, kvstore, Kafka configuration |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 18 | package config |
| 19 | |
| 20 | import ( |
| 21 | "flag" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 22 | "os" |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 23 | "time" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | // Open OLT default constants |
| 27 | const ( |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 28 | EtcdStoreName = "etcd" |
| 29 | defaultInstanceid = "openOlt001" |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 30 | defaultKafkaadapteraddress = "127.0.0.1:9092" |
| 31 | defaultKafkaclusteraddress = "127.0.0.1:9094" |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 32 | defaultKvstoretype = EtcdStoreName |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 33 | defaultKvstoretimeout = 5 * time.Second |
| 34 | defaultKvstoreaddress = "127.0.0.1:2379" // Port: Consul = 8500; Etcd = 2379 |
David Bainbridge | 2b3d488 | 2020-03-17 15:06:39 -0700 | [diff] [blame] | 35 | defaultLoglevel = "WARN" |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 36 | defaultBanner = false |
| 37 | defaultDisplayVersionOnly = false |
| 38 | defaultTopic = "openolt" |
| 39 | defaultCoretopic = "rwcore" |
| 40 | defaultEventtopic = "voltha.events" |
| 41 | defaultOnunumber = 1 |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 42 | defaultProbeAddress = ":8080" |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 43 | defaultLiveProbeInterval = 60 * time.Second |
| 44 | defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive |
Girish Gowdra | 495dde4 | 2021-03-17 14:59:56 -0700 | [diff] [blame] | 45 | //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 Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 49 | //defaultGrpcTimeoutInterval is the time in seconds a grpc call will wait before returning error. |
Girish Kumar | 11e1597 | 2020-06-15 14:51:10 +0000 | [diff] [blame] | 50 | defaultGrpcTimeoutInterval = 2 * time.Second |
| 51 | defaultCurrentReplica = 1 |
| 52 | defaultTotalReplicas = 1 |
| 53 | defaultTraceEnabled = false |
| 54 | defaultTraceAgentAddress = "127.0.0.1:6831" |
| 55 | defaultLogCorrelationEnabled = true |
kesavand | 494c208 | 2020-08-31 11:16:12 +0530 | [diff] [blame] | 56 | defaultOmccEncryption = false |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 57 | defaultEnableONUStats = false |
| 58 | defaultEnableGEMStats = false |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 59 | ) |
| 60 | |
| 61 | // AdapterFlags represents the set of configurations used by the read-write adaptercore service |
| 62 | type AdapterFlags struct { |
| 63 | // Command line parameters |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 64 | AdapterName string |
| 65 | InstanceID string // NOTE what am I used for? why not cli but only ENV? TODO expose in the chart |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 66 | KafkaAdapterAddress string |
| 67 | KafkaClusterAddress string |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 68 | KVStoreType string |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 69 | KVStoreTimeout time.Duration |
| 70 | KVStoreAddress string |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 71 | Topic string |
| 72 | CoreTopic string |
| 73 | EventTopic string |
Rohan Agrawal | 2488f19 | 2020-01-31 09:26:55 +0000 | [diff] [blame] | 74 | LogLevel string |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 75 | OnuNumber int |
| 76 | Banner bool |
| 77 | DisplayVersionOnly bool |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 78 | ProbeAddress string |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 79 | LiveProbeInterval time.Duration |
| 80 | NotLiveProbeInterval time.Duration |
| 81 | HeartbeatCheckInterval time.Duration |
| 82 | HeartbeatFailReportInterval time.Duration |
| 83 | GrpcTimeoutInterval time.Duration |
Matteo Scandolo | 3ad5d2b | 2020-04-02 17:02:04 -0700 | [diff] [blame] | 84 | CurrentReplica int |
| 85 | TotalReplicas int |
Girish Kumar | 11e1597 | 2020-06-15 14:51:10 +0000 | [diff] [blame] | 86 | TraceEnabled bool |
| 87 | TraceAgentAddress string |
| 88 | LogCorrelationEnabled bool |
kesavand | 494c208 | 2020-08-31 11:16:12 +0530 | [diff] [blame] | 89 | OmccEncryption bool |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 90 | EnableONUStats bool |
| 91 | EnableGEMStats bool |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 92 | } |
| 93 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 94 | // NewAdapterFlags returns a new RWCore config |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 95 | func NewAdapterFlags() *AdapterFlags { |
| 96 | var adapterFlags = AdapterFlags{ // Default values |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 97 | InstanceID: defaultInstanceid, |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 98 | KafkaAdapterAddress: defaultKafkaadapteraddress, |
| 99 | KafkaClusterAddress: defaultKafkaclusteraddress, |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 100 | KVStoreType: defaultKvstoretype, |
| 101 | KVStoreTimeout: defaultKvstoretimeout, |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 102 | KVStoreAddress: defaultKvstoreaddress, |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 103 | Topic: defaultTopic, |
| 104 | CoreTopic: defaultCoretopic, |
| 105 | EventTopic: defaultEventtopic, |
| 106 | LogLevel: defaultLoglevel, |
| 107 | OnuNumber: defaultOnunumber, |
| 108 | Banner: defaultBanner, |
| 109 | DisplayVersionOnly: defaultDisplayVersionOnly, |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 110 | ProbeAddress: defaultProbeAddress, |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 111 | LiveProbeInterval: defaultLiveProbeInterval, |
| 112 | NotLiveProbeInterval: defaultNotLiveProbeInterval, |
Girish Gowdra | 495dde4 | 2021-03-17 14:59:56 -0700 | [diff] [blame] | 113 | HeartbeatCheckInterval: defaultHeartbeatCheckInterval, |
| 114 | HeartbeatFailReportInterval: defaultHeartbeatFailReportInterval, |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 115 | GrpcTimeoutInterval: defaultGrpcTimeoutInterval, |
Girish Kumar | 11e1597 | 2020-06-15 14:51:10 +0000 | [diff] [blame] | 116 | TraceEnabled: defaultTraceEnabled, |
| 117 | TraceAgentAddress: defaultTraceAgentAddress, |
| 118 | LogCorrelationEnabled: defaultLogCorrelationEnabled, |
kesavand | 494c208 | 2020-08-31 11:16:12 +0530 | [diff] [blame] | 119 | OmccEncryption: defaultOmccEncryption, |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 120 | EnableONUStats: defaultEnableONUStats, |
| 121 | EnableGEMStats: defaultEnableGEMStats, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 122 | } |
| 123 | return &adapterFlags |
| 124 | } |
| 125 | |
| 126 | // ParseCommandArguments parses the arguments when running read-write adaptercore service |
| 127 | func (so *AdapterFlags) ParseCommandArguments() { |
| 128 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 129 | flag.StringVar(&(so.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaadapteraddress, "Kafka - Adapter messaging address") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 130 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 131 | flag.StringVar(&(so.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaclusteraddress, "Kafka - Cluster messaging address") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 132 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 133 | flag.StringVar(&(so.Topic), "adapter_topic", defaultTopic, "Open OLT topic") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 134 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 135 | flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoretopic, "Core topic") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 136 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 137 | flag.StringVar(&(so.EventTopic), "event_topic", defaultEventtopic, "Event topic") |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 138 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 139 | flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, "KV store type") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 140 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 141 | flag.DurationVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, "The default timeout when making a kv store request") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 142 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 143 | flag.StringVar(&(so.KVStoreAddress), "kv_store_address", defaultKvstoreaddress, "KV store address") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 144 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 145 | flag.StringVar(&(so.LogLevel), "log_level", defaultLoglevel, "Log level") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 146 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 147 | flag.IntVar(&(so.OnuNumber), "onu_number", defaultOnunumber, "Number of ONUs") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 148 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 149 | flag.BoolVar(&(so.Banner), "banner", defaultBanner, "Show startup banner log lines") |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 150 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 151 | flag.BoolVar(&(so.DisplayVersionOnly), "version", defaultDisplayVersionOnly, "Show version information and exit") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 152 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 153 | flag.StringVar(&(so.ProbeAddress), "probe_address", defaultProbeAddress, "The address on which to listen to answer liveness and readiness probe queries over HTTP.") |
Rohan Agrawal | 828bf4e | 2019-10-22 10:13:19 +0000 | [diff] [blame] | 154 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 155 | flag.DurationVar(&(so.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, "Number of seconds for the default liveliness check") |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 156 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 157 | flag.DurationVar(&(so.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, "Number of seconds for liveliness check if probe is not running") |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 158 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 159 | flag.DurationVar(&(so.HeartbeatCheckInterval), "heartbeat_check_interval", defaultHeartbeatCheckInterval, "Number of seconds for heartbeat check interval") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 160 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 161 | flag.DurationVar(&(so.HeartbeatFailReportInterval), "heartbeat_fail_interval", defaultHeartbeatFailReportInterval, "Number of seconds adapter has to wait before reporting core on the heartbeat check failure") |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 162 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 163 | flag.DurationVar(&(so.GrpcTimeoutInterval), "grpc_timeout_interval", defaultGrpcTimeoutInterval, "Number of seconds for GRPC timeout") |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 164 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 165 | flag.IntVar(&(so.CurrentReplica), "current_replica", defaultCurrentReplica, "Replica number of this particular instance") |
Matteo Scandolo | 3ad5d2b | 2020-04-02 17:02:04 -0700 | [diff] [blame] | 166 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 167 | flag.IntVar(&(so.TotalReplicas), "total_replica", defaultTotalReplicas, "Total number of instances for this adapter") |
Matteo Scandolo | 3ad5d2b | 2020-04-02 17:02:04 -0700 | [diff] [blame] | 168 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 169 | flag.BoolVar(&(so.TraceEnabled), "trace_enabled", defaultTraceEnabled, "Whether to send logs to tracing agent?") |
Girish Kumar | 11e1597 | 2020-06-15 14:51:10 +0000 | [diff] [blame] | 170 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 171 | flag.StringVar(&(so.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, "The address of tracing agent to which span info should be sent") |
Girish Kumar | 11e1597 | 2020-06-15 14:51:10 +0000 | [diff] [blame] | 172 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 173 | flag.BoolVar(&(so.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?") |
Girish Kumar | 11e1597 | 2020-06-15 14:51:10 +0000 | [diff] [blame] | 174 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 175 | flag.BoolVar(&(so.OmccEncryption), "omcc_encryption", defaultOmccEncryption, "OMCI Channel encryption status") |
kesavand | 494c208 | 2020-08-31 11:16:12 +0530 | [diff] [blame] | 176 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 177 | flag.BoolVar(&(so.EnableONUStats), "enable_onu_stats", defaultEnableONUStats, "Enable ONU Statistics") |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 178 | |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 179 | flag.BoolVar(&(so.EnableGEMStats), "enable_gem_stats", defaultEnableGEMStats, "Enable GEM Statistics") |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 180 | |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 181 | flag.Parse() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 182 | containerName := getContainerInfo() |
| 183 | if len(containerName) > 0 { |
| 184 | so.InstanceID = containerName |
| 185 | } |
| 186 | |
| 187 | } |
| 188 | |
| 189 | func getContainerInfo() string { |
| 190 | return os.Getenv("HOSTNAME") |
| 191 | } |