blob: 297116976356828358b6e0e5228ef5d5a927e001 [file] [log] [blame]
khenaidood2b6df92018-12-13 16:37:20 -05001/*
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 */
16package config
17
18import (
19 "flag"
20 "fmt"
21 "github.com/opencord/voltha-go/common/log"
22 "os"
23)
24
25// Simulated OLT default constants
26const (
27 EtcdStoreName = "etcd"
28 default_InstanceID = "simulatedOnu001"
29 default_KafkaAdapterHost = "127.0.0.1"
30 default_KafkaAdapterPort = 9092
31 default_KafkaClusterHost = "127.0.0.1"
32 default_KafkaClusterPort = 9094
33 default_KVStoreType = EtcdStoreName
34 default_KVStoreTimeout = 5 //in seconds
35 default_KVStoreHost = "127.0.0.1"
36 default_KVStorePort = 2379 // Consul = 8500; Etcd = 2379
37 default_LogLevel = 0
38 default_Banner = false
39 default_Topic = "simulated_onu"
40 default_CoreTopic = "rwcore"
41)
42
43// AdapterFlags represents the set of configurations used by the read-write adaptercore service
44type AdapterFlags struct {
45 // Command line parameters
46 InstanceID string
47 KafkaAdapterHost string
48 KafkaAdapterPort int
49 KafkaClusterHost string
50 KafkaClusterPort int
51 KVStoreType string
52 KVStoreTimeout int // in seconds
53 KVStoreHost string
54 KVStorePort int
55 Topic string
56 CoreTopic string
57 LogLevel int
58 Banner bool
59}
60
61func init() {
62 log.AddPackage(log.JSON, log.WarnLevel, nil)
63}
64
65// NewRWCoreFlags returns a new RWCore config
66func NewAdapterFlags() *AdapterFlags {
67 var adapterFlags = AdapterFlags{ // Default values
68 InstanceID: default_InstanceID,
69 KafkaAdapterHost: default_KafkaAdapterHost,
70 KafkaAdapterPort: default_KafkaAdapterPort,
71 KafkaClusterHost: default_KafkaClusterHost,
72 KafkaClusterPort: default_KafkaClusterPort,
73 KVStoreType: default_KVStoreType,
74 KVStoreTimeout: default_KVStoreTimeout,
75 KVStoreHost: default_KVStoreHost,
76 KVStorePort: default_KVStorePort,
77 Topic: default_Topic,
78 CoreTopic: default_CoreTopic,
79 LogLevel: default_LogLevel,
80 Banner: default_Banner,
81 }
82 return &adapterFlags
83}
84
85// ParseCommandArguments parses the arguments when running read-write adaptercore service
86func (so *AdapterFlags) ParseCommandArguments() {
87
88 var help string
89
90 help = fmt.Sprintf("Kafka - Adapter messaging host")
91 flag.StringVar(&(so.KafkaAdapterHost), "kafka_adapter_host", default_KafkaAdapterHost, help)
92
93 help = fmt.Sprintf("Kafka - Adapter messaging port")
94 flag.IntVar(&(so.KafkaAdapterPort), "kafka_adapter_port", default_KafkaAdapterPort, help)
95
96 help = fmt.Sprintf("Kafka - Cluster messaging host")
97 flag.StringVar(&(so.KafkaClusterHost), "kafka_cluster_host", default_KafkaClusterHost, help)
98
99 help = fmt.Sprintf("Kafka - Cluster messaging port")
100 flag.IntVar(&(so.KafkaClusterPort), "kafka_cluster_port", default_KafkaClusterPort, help)
101
102 help = fmt.Sprintf("Simulated ONU topic")
103 flag.StringVar(&(so.Topic), "simulator_topic", default_Topic, help)
104
105 help = fmt.Sprintf("Core topic")
106 flag.StringVar(&(so.CoreTopic), "core_topic", default_CoreTopic, help)
107
108 help = fmt.Sprintf("KV store type")
109 flag.StringVar(&(so.KVStoreType), "kv_store_type", default_KVStoreType, help)
110
111 help = fmt.Sprintf("The default timeout when making a kv store request")
112 flag.IntVar(&(so.KVStoreTimeout), "kv_store_request_timeout", default_KVStoreTimeout, help)
113
114 help = fmt.Sprintf("KV store host")
115 flag.StringVar(&(so.KVStoreHost), "kv_store_host", default_KVStoreHost, help)
116
117 help = fmt.Sprintf("KV store port")
118 flag.IntVar(&(so.KVStorePort), "kv_store_port", default_KVStorePort, help)
119
120 help = fmt.Sprintf("Log level")
121 flag.IntVar(&(so.LogLevel), "log_level", default_LogLevel, help)
122
123 help = fmt.Sprintf("Show startup banner log lines")
124 flag.BoolVar(&so.Banner, "banner", default_Banner, help)
125
126 flag.Parse()
127
128 containerName := getContainerInfo()
129 if len(containerName) > 0 {
130 so.InstanceID = containerName
131 }
132
133}
134
135func getContainerInfo() string {
136 return os.Getenv("HOSTNAME")
137}