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" |
| 31 | defaultKafkaadapterhost = "127.0.0.1" |
| 32 | defaultKafkaadapterport = 9092 |
| 33 | defaultKafkaclusterhost = "127.0.0.1" |
| 34 | defaultKafkaclusterport = 9094 |
| 35 | defaultKvstoretype = EtcdStoreName |
| 36 | defaultKvstoretimeout = 5 //in seconds |
| 37 | defaultKvstorehost = "127.0.0.1" |
| 38 | defaultKvstoreport = 2379 // Consul = 8500; Etcd = 2379 |
David Bainbridge | 2b3d488 | 2020-03-17 15:06:39 -0700 | [diff] [blame] | 39 | defaultLoglevel = "WARN" |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 40 | defaultBanner = false |
| 41 | defaultDisplayVersionOnly = false |
| 42 | defaultTopic = "openolt" |
| 43 | defaultCoretopic = "rwcore" |
| 44 | defaultEventtopic = "voltha.events" |
| 45 | defaultOnunumber = 1 |
| 46 | defaultProbeHost = "" |
| 47 | defaultProbePort = 8080 |
| 48 | defaultLiveProbeInterval = 60 * time.Second |
| 49 | defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 50 | //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] | 51 | defaultHearbeatCheckInterval = 15 * time.Second |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 52 | // 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] | 53 | defaultHearbeatFailReportInterval = 0 * time.Second |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 54 | //defaultGrpcTimeoutInterval is the time in seconds a grpc call will wait before returning error. |
| 55 | defaultGrpcTimeoutInterval = 2 * time.Second |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 56 | ) |
| 57 | |
| 58 | // AdapterFlags represents the set of configurations used by the read-write adaptercore service |
| 59 | type AdapterFlags struct { |
| 60 | // Command line parameters |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 61 | InstanceID string |
| 62 | KafkaAdapterHost string |
| 63 | KafkaAdapterPort int |
| 64 | KafkaClusterHost string |
| 65 | KafkaClusterPort int |
| 66 | KVStoreType string |
| 67 | KVStoreTimeout int // in seconds |
| 68 | KVStoreHost string |
| 69 | KVStorePort int |
| 70 | Topic string |
| 71 | CoreTopic string |
| 72 | EventTopic string |
Rohan Agrawal | 2488f19 | 2020-01-31 09:26:55 +0000 | [diff] [blame] | 73 | LogLevel string |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 74 | OnuNumber int |
| 75 | Banner bool |
| 76 | DisplayVersionOnly bool |
| 77 | ProbeHost string |
| 78 | ProbePort int |
| 79 | LiveProbeInterval time.Duration |
| 80 | NotLiveProbeInterval time.Duration |
| 81 | HeartbeatCheckInterval time.Duration |
| 82 | HeartbeatFailReportInterval time.Duration |
| 83 | GrpcTimeoutInterval time.Duration |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 86 | // NewAdapterFlags returns a new RWCore config |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 87 | func NewAdapterFlags() *AdapterFlags { |
| 88 | var adapterFlags = AdapterFlags{ // Default values |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 89 | InstanceID: defaultInstanceid, |
| 90 | KafkaAdapterHost: defaultKafkaadapterhost, |
| 91 | KafkaAdapterPort: defaultKafkaadapterport, |
| 92 | KafkaClusterHost: defaultKafkaclusterhost, |
| 93 | KafkaClusterPort: defaultKafkaclusterport, |
| 94 | KVStoreType: defaultKvstoretype, |
| 95 | KVStoreTimeout: defaultKvstoretimeout, |
| 96 | KVStoreHost: defaultKvstorehost, |
| 97 | KVStorePort: defaultKvstoreport, |
| 98 | Topic: defaultTopic, |
| 99 | CoreTopic: defaultCoretopic, |
| 100 | EventTopic: defaultEventtopic, |
| 101 | LogLevel: defaultLoglevel, |
| 102 | OnuNumber: defaultOnunumber, |
| 103 | Banner: defaultBanner, |
| 104 | DisplayVersionOnly: defaultDisplayVersionOnly, |
| 105 | ProbeHost: defaultProbeHost, |
| 106 | ProbePort: defaultProbePort, |
| 107 | LiveProbeInterval: defaultLiveProbeInterval, |
| 108 | NotLiveProbeInterval: defaultNotLiveProbeInterval, |
| 109 | HeartbeatCheckInterval: defaultHearbeatCheckInterval, |
| 110 | HeartbeatFailReportInterval: defaultHearbeatFailReportInterval, |
| 111 | GrpcTimeoutInterval: defaultGrpcTimeoutInterval, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 112 | } |
| 113 | return &adapterFlags |
| 114 | } |
| 115 | |
| 116 | // ParseCommandArguments parses the arguments when running read-write adaptercore service |
| 117 | func (so *AdapterFlags) ParseCommandArguments() { |
| 118 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 119 | help := fmt.Sprintf("Kafka - Adapter messaging host") |
| 120 | flag.StringVar(&(so.KafkaAdapterHost), "kafka_adapter_host", defaultKafkaadapterhost, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 121 | |
| 122 | help = fmt.Sprintf("Kafka - Adapter messaging port") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 123 | flag.IntVar(&(so.KafkaAdapterPort), "kafka_adapter_port", defaultKafkaadapterport, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 124 | |
| 125 | help = fmt.Sprintf("Kafka - Cluster messaging host") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 126 | flag.StringVar(&(so.KafkaClusterHost), "kafka_cluster_host", defaultKafkaclusterhost, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 127 | |
| 128 | help = fmt.Sprintf("Kafka - Cluster messaging port") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 129 | flag.IntVar(&(so.KafkaClusterPort), "kafka_cluster_port", defaultKafkaclusterport, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 130 | |
| 131 | help = fmt.Sprintf("Open OLT topic") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 132 | flag.StringVar(&(so.Topic), "adapter_topic", defaultTopic, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 133 | |
| 134 | help = fmt.Sprintf("Core topic") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 135 | flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoretopic, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 136 | |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 137 | help = fmt.Sprintf("Event topic") |
| 138 | flag.StringVar(&(so.EventTopic), "event_topic", defaultEventtopic, help) |
| 139 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 140 | help = fmt.Sprintf("KV store type") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 141 | flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 142 | |
| 143 | help = fmt.Sprintf("The default timeout when making a kv store request") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 144 | flag.IntVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 145 | |
| 146 | help = fmt.Sprintf("KV store host") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 147 | flag.StringVar(&(so.KVStoreHost), "kv_store_host", defaultKvstorehost, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 148 | |
| 149 | help = fmt.Sprintf("KV store port") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 150 | flag.IntVar(&(so.KVStorePort), "kv_store_port", defaultKvstoreport, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 151 | |
| 152 | help = fmt.Sprintf("Log level") |
Rohan Agrawal | 2488f19 | 2020-01-31 09:26:55 +0000 | [diff] [blame] | 153 | flag.StringVar(&(so.LogLevel), "log_level", defaultLoglevel, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 154 | |
| 155 | help = fmt.Sprintf("Number of ONUs") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 156 | flag.IntVar(&(so.OnuNumber), "onu_number", defaultOnunumber, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 157 | |
| 158 | help = fmt.Sprintf("Show startup banner log lines") |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 159 | flag.BoolVar(&(so.Banner), "banner", defaultBanner, help) |
| 160 | |
| 161 | help = fmt.Sprintf("Show version information and exit") |
| 162 | flag.BoolVar(&(so.DisplayVersionOnly), "version", defaultDisplayVersionOnly, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 163 | |
Rohan Agrawal | 828bf4e | 2019-10-22 10:13:19 +0000 | [diff] [blame] | 164 | help = fmt.Sprintf("The address on which to listen to answer liveness and readiness probe queries over HTTP.") |
| 165 | flag.StringVar(&(so.ProbeHost), "probe_host", defaultProbeHost, help) |
| 166 | |
| 167 | help = fmt.Sprintf("The port on which to listen to answer liveness and readiness probe queries over HTTP.") |
| 168 | flag.IntVar(&(so.ProbePort), "probe_port", defaultProbePort, help) |
| 169 | |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 170 | help = fmt.Sprintf("Number of seconds for the default liveliness check") |
| 171 | flag.DurationVar(&(so.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help) |
| 172 | |
| 173 | help = fmt.Sprintf("Number of seconds for liveliness check if probe is not running") |
| 174 | flag.DurationVar(&(so.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help) |
| 175 | |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 176 | help = fmt.Sprintf("Number of seconds for heartbeat check interval.") |
| 177 | flag.DurationVar(&(so.HeartbeatCheckInterval), "hearbeat_check_interval", defaultHearbeatCheckInterval, help) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 178 | |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 179 | help = fmt.Sprintf("Number of seconds adapter has to wait before reporting core on the hearbeat check failure.") |
| 180 | flag.DurationVar(&(so.HeartbeatFailReportInterval), "hearbeat_fail_interval", defaultHearbeatFailReportInterval, help) |
| 181 | |
| 182 | help = fmt.Sprintf("Number of seconds for GRPC timeout.") |
| 183 | flag.DurationVar(&(so.GrpcTimeoutInterval), "grpc_timeout_interval", defaultGrpcTimeoutInterval, help) |
| 184 | |
| 185 | flag.Parse() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 186 | containerName := getContainerInfo() |
| 187 | if len(containerName) > 0 { |
| 188 | so.InstanceID = containerName |
| 189 | } |
| 190 | |
| 191 | } |
| 192 | |
| 193 | func getContainerInfo() string { |
| 194 | return os.Getenv("HOSTNAME") |
| 195 | } |