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