blob: f7ac79429795bd29e86e2a228a1234c3baa30504 [file] [log] [blame]
khenaidoobf6e7bb2018-08-14 22:27:29 -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 */
khenaidoocfee5f42018-07-19 22:47:38 -040016package config
17
18import (
khenaidoocfee5f42018-07-19 22:47:38 -040019 "flag"
20 "fmt"
khenaidoob9203542018-09-17 22:56:37 -040021 "github.com/opencord/voltha-go/common/log"
khenaidoocfee5f42018-07-19 22:47:38 -040022 "os"
khenaidoocfee5f42018-07-19 22:47:38 -040023)
24
khenaidoo5c11af72018-07-20 17:21:05 -040025// RW Core service default constants
khenaidoocfee5f42018-07-19 22:47:38 -040026const (
khenaidoo79232702018-12-04 11:00:41 -050027 ConsulStoreName = "consul"
28 EtcdStoreName = "etcd"
29 default_InstanceID = "rwcore001"
30 default_GrpcPort = 50057
31 default_GrpcHost = ""
32 default_KafkaAdapterHost = "127.0.0.1"
33 default_KafkaAdapterPort = 9092
34 default_KafkaClusterHost = "127.0.0.1"
35 default_KafkaClusterPort = 9094
36 default_KVStoreType = EtcdStoreName
37 default_KVStoreTimeout = 5 //in seconds
38 default_KVStoreHost = "127.0.0.1"
39 default_KVStorePort = 2379 // Consul = 8500; Etcd = 2379
40 default_KVTxnKeyDelTime = 60
41 default_LogLevel = 0
42 default_Banner = false
43 default_CoreTopic = "rwcore"
44 default_RWCoreEndpoint = "rwcore"
45 default_RWCoreKey = "pki/voltha.key"
46 default_RWCoreCert = "pki/voltha.crt"
47 default_RWCoreCA = "pki/voltha-CA.pem"
48 default_Affinity_Router_Topic = "affinityRouter"
khenaidoocfee5f42018-07-19 22:47:38 -040049)
50
khenaidoo5c11af72018-07-20 17:21:05 -040051// RWCoreFlags represents the set of configurations used by the read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -040052type RWCoreFlags struct {
53 // Command line parameters
khenaidoo79232702018-12-04 11:00:41 -050054 InstanceID string
55 RWCoreEndpoint string
56 GrpcHost string
57 GrpcPort int
58 KafkaAdapterHost string
59 KafkaAdapterPort int
60 KafkaClusterHost string
61 KafkaClusterPort int
62 KVStoreType string
63 KVStoreTimeout int // in seconds
64 KVStoreHost string
65 KVStorePort int
66 KVTxnKeyDelTime int
67 CoreTopic string
68 LogLevel int
69 Banner bool
70 RWCoreKey string
71 RWCoreCert string
72 RWCoreCA string
73 AffinityRouterTopic string
khenaidoocfee5f42018-07-19 22:47:38 -040074}
75
khenaidoob9203542018-09-17 22:56:37 -040076func init() {
77 log.AddPackage(log.JSON, log.WarnLevel, nil)
78}
79
khenaidoo5c11af72018-07-20 17:21:05 -040080// NewRWCoreFlags returns a new RWCore config
khenaidoocfee5f42018-07-19 22:47:38 -040081func NewRWCoreFlags() *RWCoreFlags {
82 var rwCoreFlag = RWCoreFlags{ // Default values
khenaidoo79232702018-12-04 11:00:41 -050083 InstanceID: default_InstanceID,
84 RWCoreEndpoint: default_RWCoreEndpoint,
85 GrpcHost: default_GrpcHost,
86 GrpcPort: default_GrpcPort,
87 KafkaAdapterHost: default_KafkaAdapterHost,
88 KafkaAdapterPort: default_KafkaAdapterPort,
89 KafkaClusterHost: default_KafkaClusterHost,
90 KafkaClusterPort: default_KafkaClusterPort,
91 KVStoreType: default_KVStoreType,
92 KVStoreTimeout: default_KVStoreTimeout,
93 KVStoreHost: default_KVStoreHost,
94 KVStorePort: default_KVStorePort,
95 KVTxnKeyDelTime: default_KVTxnKeyDelTime,
96 CoreTopic: default_CoreTopic,
97 LogLevel: default_LogLevel,
98 Banner: default_Banner,
99 RWCoreKey: default_RWCoreKey,
100 RWCoreCert: default_RWCoreCert,
101 RWCoreCA: default_RWCoreCA,
102 AffinityRouterTopic: default_Affinity_Router_Topic,
khenaidoocfee5f42018-07-19 22:47:38 -0400103 }
104 return &rwCoreFlag
105}
106
khenaidoo5c11af72018-07-20 17:21:05 -0400107// ParseCommandArguments parses the arguments when running read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -0400108func (cf *RWCoreFlags) ParseCommandArguments() {
khenaidoocfee5f42018-07-19 22:47:38 -0400109
khenaidoo5c11af72018-07-20 17:21:05 -0400110 var help string
khenaidoocfee5f42018-07-19 22:47:38 -0400111
khenaidoo5c11af72018-07-20 17:21:05 -0400112 help = fmt.Sprintf("RW core endpoint address")
113 flag.StringVar(&(cf.RWCoreEndpoint), "vcore-endpoint", default_RWCoreEndpoint, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400114
khenaidoo5c11af72018-07-20 17:21:05 -0400115 help = fmt.Sprintf("GRPC server - host")
116 flag.StringVar(&(cf.GrpcHost), "grpc_host", default_GrpcHost, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400117
khenaidoo5c11af72018-07-20 17:21:05 -0400118 help = fmt.Sprintf("GRPC server - port")
119 flag.IntVar(&(cf.GrpcPort), "grpc_port", default_GrpcPort, help)
120
121 help = fmt.Sprintf("Kafka - Adapter messaging host")
122 flag.StringVar(&(cf.KafkaAdapterHost), "kafka_adapter_host", default_KafkaAdapterHost, help)
123
124 help = fmt.Sprintf("Kafka - Adapter messaging port")
125 flag.IntVar(&(cf.KafkaAdapterPort), "kafka_adapter_port", default_KafkaAdapterPort, help)
126
127 help = fmt.Sprintf("Kafka - Cluster messaging host")
128 flag.StringVar(&(cf.KafkaClusterHost), "kafka_cluster_host", default_KafkaClusterHost, help)
129
130 help = fmt.Sprintf("Kafka - Cluster messaging port")
131 flag.IntVar(&(cf.KafkaClusterPort), "kafka_cluster_port", default_KafkaClusterPort, help)
132
133 help = fmt.Sprintf("RW Core topic")
134 flag.StringVar(&(cf.CoreTopic), "rw_core_topic", default_CoreTopic, help)
135
khenaidoo79232702018-12-04 11:00:41 -0500136 help = fmt.Sprintf("Affinity Router topic")
137 flag.StringVar(&(cf.AffinityRouterTopic), "affinity_router_topic", default_Affinity_Router_Topic, help)
138
khenaidoo5c11af72018-07-20 17:21:05 -0400139 help = fmt.Sprintf("KV store type")
140 flag.StringVar(&(cf.KVStoreType), "kv_store_type", default_KVStoreType, help)
141
142 help = fmt.Sprintf("The default timeout when making a kv store request")
143 flag.IntVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", default_KVStoreTimeout, help)
144
145 help = fmt.Sprintf("KV store host")
146 flag.StringVar(&(cf.KVStoreHost), "kv_store_host", default_KVStoreHost, help)
147
148 help = fmt.Sprintf("KV store port")
149 flag.IntVar(&(cf.KVStorePort), "kv_store_port", default_KVStorePort, help)
150
Richard Jankowskie4d77662018-10-17 13:53:21 -0400151 help = fmt.Sprintf("The time to wait before deleting a completed transaction key")
152 flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", default_KVTxnKeyDelTime, help)
153
khenaidoo5c11af72018-07-20 17:21:05 -0400154 help = fmt.Sprintf("Log level")
155 flag.IntVar(&(cf.LogLevel), "log_level", default_LogLevel, help)
156
157 help = fmt.Sprintf("Show startup banner log lines")
158 flag.BoolVar(&cf.Banner, "banner", default_Banner, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400159
160 flag.Parse()
161
khenaidoocfee5f42018-07-19 22:47:38 -0400162 containerName := getContainerInfo()
khenaidoocfee5f42018-07-19 22:47:38 -0400163 if len(containerName) > 0 {
164 cf.InstanceID = containerName
165 }
166
khenaidoocfee5f42018-07-19 22:47:38 -0400167}
168
169func getContainerInfo() string {
170 return os.Getenv("HOSTNAME")
171}