blob: 5850a03f86d3f3f3d109b58d9b1178f515a2f8a2 [file] [log] [blame]
Girish Gowdru0c588b22019-04-23 23:24:56 -04001/*
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 */
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"
22 "fmt"
23 "github.com/opencord/voltha-go/common/log"
24 "os"
25)
26
27// Open OLT default constants
28const (
Matt Jeanneretf880eb62019-07-16 20:08:03 -040029 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
39 defaultLoglevel = 0
40 defaultBanner = false
41 defaultDisplayVersionOnly = false
42 defaultTopic = "openolt"
43 defaultCoretopic = "rwcore"
Devmalya Paulfb990a52019-07-09 10:01:49 -040044 defaultEventtopic = "voltha.events"
Matt Jeanneretf880eb62019-07-16 20:08:03 -040045 defaultOnunumber = 1
Girish Gowdru0c588b22019-04-23 23:24:56 -040046)
47
48// AdapterFlags represents the set of configurations used by the read-write adaptercore service
49type AdapterFlags struct {
50 // Command line parameters
Matt Jeanneretf880eb62019-07-16 20:08:03 -040051 InstanceID string
52 KafkaAdapterHost string
53 KafkaAdapterPort int
54 KafkaClusterHost string
55 KafkaClusterPort int
56 KVStoreType string
57 KVStoreTimeout int // in seconds
58 KVStoreHost string
59 KVStorePort int
60 Topic string
61 CoreTopic string
Devmalya Paulfb990a52019-07-09 10:01:49 -040062 EventTopic string
Matt Jeanneretf880eb62019-07-16 20:08:03 -040063 LogLevel int
64 OnuNumber int
65 Banner bool
66 DisplayVersionOnly bool
Girish Gowdru0c588b22019-04-23 23:24:56 -040067}
68
69func init() {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070070 _, _ = log.AddPackage(log.JSON, log.WarnLevel, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -040071}
72
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070073// NewAdapterFlags returns a new RWCore config
Girish Gowdru0c588b22019-04-23 23:24:56 -040074func NewAdapterFlags() *AdapterFlags {
75 var adapterFlags = AdapterFlags{ // Default values
Matt Jeanneretf880eb62019-07-16 20:08:03 -040076 InstanceID: defaultInstanceid,
77 KafkaAdapterHost: defaultKafkaadapterhost,
78 KafkaAdapterPort: defaultKafkaadapterport,
79 KafkaClusterHost: defaultKafkaclusterhost,
80 KafkaClusterPort: defaultKafkaclusterport,
81 KVStoreType: defaultKvstoretype,
82 KVStoreTimeout: defaultKvstoretimeout,
83 KVStoreHost: defaultKvstorehost,
84 KVStorePort: defaultKvstoreport,
85 Topic: defaultTopic,
86 CoreTopic: defaultCoretopic,
Devmalya Paulfb990a52019-07-09 10:01:49 -040087 EventTopic: defaultEventtopic,
Matt Jeanneretf880eb62019-07-16 20:08:03 -040088 LogLevel: defaultLoglevel,
89 OnuNumber: defaultOnunumber,
90 Banner: defaultBanner,
91 DisplayVersionOnly: defaultDisplayVersionOnly,
Girish Gowdru0c588b22019-04-23 23:24:56 -040092 }
93 return &adapterFlags
94}
95
96// ParseCommandArguments parses the arguments when running read-write adaptercore service
97func (so *AdapterFlags) ParseCommandArguments() {
98
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070099 help := fmt.Sprintf("Kafka - Adapter messaging host")
100 flag.StringVar(&(so.KafkaAdapterHost), "kafka_adapter_host", defaultKafkaadapterhost, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400101
102 help = fmt.Sprintf("Kafka - Adapter messaging port")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700103 flag.IntVar(&(so.KafkaAdapterPort), "kafka_adapter_port", defaultKafkaadapterport, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400104
105 help = fmt.Sprintf("Kafka - Cluster messaging host")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700106 flag.StringVar(&(so.KafkaClusterHost), "kafka_cluster_host", defaultKafkaclusterhost, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400107
108 help = fmt.Sprintf("Kafka - Cluster messaging port")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700109 flag.IntVar(&(so.KafkaClusterPort), "kafka_cluster_port", defaultKafkaclusterport, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400110
111 help = fmt.Sprintf("Open OLT topic")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700112 flag.StringVar(&(so.Topic), "adapter_topic", defaultTopic, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400113
114 help = fmt.Sprintf("Core topic")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700115 flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoretopic, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400116
Devmalya Paulfb990a52019-07-09 10:01:49 -0400117 help = fmt.Sprintf("Event topic")
118 flag.StringVar(&(so.EventTopic), "event_topic", defaultEventtopic, help)
119
Girish Gowdru0c588b22019-04-23 23:24:56 -0400120 help = fmt.Sprintf("KV store type")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700121 flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400122
123 help = fmt.Sprintf("The default timeout when making a kv store request")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700124 flag.IntVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400125
126 help = fmt.Sprintf("KV store host")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700127 flag.StringVar(&(so.KVStoreHost), "kv_store_host", defaultKvstorehost, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400128
129 help = fmt.Sprintf("KV store port")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700130 flag.IntVar(&(so.KVStorePort), "kv_store_port", defaultKvstoreport, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400131
132 help = fmt.Sprintf("Log level")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700133 flag.IntVar(&(so.LogLevel), "log_level", defaultLoglevel, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400134
135 help = fmt.Sprintf("Number of ONUs")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700136 flag.IntVar(&(so.OnuNumber), "onu_number", defaultOnunumber, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400137
138 help = fmt.Sprintf("Show startup banner log lines")
Matt Jeanneretf880eb62019-07-16 20:08:03 -0400139 flag.BoolVar(&(so.Banner), "banner", defaultBanner, help)
140
141 help = fmt.Sprintf("Show version information and exit")
142 flag.BoolVar(&(so.DisplayVersionOnly), "version", defaultDisplayVersionOnly, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400143
144 flag.Parse()
145
146 containerName := getContainerInfo()
147 if len(containerName) > 0 {
148 so.InstanceID = containerName
149 }
150
151}
152
153func getContainerInfo() string {
154 return os.Getenv("HOSTNAME")
155}