blob: a999d7b64db51f1f82e85e00d60dcba24264d0fb [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 (
khenaidoo5c11af72018-07-20 17:21:05 -040027 ConsulStoreName = "consul"
28 EtcdStoreName = "etcd"
29 default_InstanceID = "rwcore001"
30 default_GrpcPort = 50057
khenaidoobf6e7bb2018-08-14 22:27:29 -040031 default_GrpcHost = "127.0.0.1"
khenaidoob9203542018-09-17 22:56:37 -040032 default_KafkaAdapterHost = "10.176.230.190"
khenaidoo5c11af72018-07-20 17:21:05 -040033 default_KafkaAdapterPort = 9092
khenaidoob9203542018-09-17 22:56:37 -040034 default_KafkaClusterHost = "10.176.215.107"
khenaidoo5c11af72018-07-20 17:21:05 -040035 default_KafkaClusterPort = 9094
36 default_KVStoreType = ConsulStoreName
37 default_KVStoreTimeout = 5 //in seconds
khenaidoob9203542018-09-17 22:56:37 -040038 default_KVStoreHost = "10.176.230.190"
khenaidoo5c11af72018-07-20 17:21:05 -040039 default_KVStorePort = 8500 // Etcd = 2379
khenaidooabad44c2018-08-03 16:58:35 -040040 default_LogLevel = 0
khenaidoo5c11af72018-07-20 17:21:05 -040041 default_Banner = false
42 default_CoreTopic = "rwcore"
43 default_RWCoreEndpoint = "rwcore"
44 default_RWCoreKey = "pki/voltha.key"
45 default_RWCoreCert = "pki/voltha.crt"
46 default_RWCoreCA = "pki/voltha-CA.pem"
khenaidoocfee5f42018-07-19 22:47:38 -040047)
48
khenaidoo5c11af72018-07-20 17:21:05 -040049// RWCoreFlags represents the set of configurations used by the read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -040050type RWCoreFlags struct {
51 // Command line parameters
khenaidoo5c11af72018-07-20 17:21:05 -040052 InstanceID string
53 RWCoreEndpoint string
54 GrpcHost string
55 GrpcPort int
56 KafkaAdapterHost string
57 KafkaAdapterPort int
58 KafkaClusterHost string
59 KafkaClusterPort int
60 KVStoreType string
61 KVStoreTimeout int // in seconds
62 KVStoreHost string
63 KVStorePort int
64 CoreTopic string
65 LogLevel int
66 Banner bool
67 RWCoreKey string
68 RWCoreCert string
69 RWCoreCA string
khenaidoocfee5f42018-07-19 22:47:38 -040070}
71
khenaidoob9203542018-09-17 22:56:37 -040072func init() {
73 log.AddPackage(log.JSON, log.WarnLevel, nil)
74}
75
khenaidoo5c11af72018-07-20 17:21:05 -040076// NewRWCoreFlags returns a new RWCore config
khenaidoocfee5f42018-07-19 22:47:38 -040077func NewRWCoreFlags() *RWCoreFlags {
78 var rwCoreFlag = RWCoreFlags{ // Default values
khenaidoo5c11af72018-07-20 17:21:05 -040079 InstanceID: default_InstanceID,
80 RWCoreEndpoint: default_RWCoreEndpoint,
81 GrpcHost: default_GrpcHost,
82 GrpcPort: default_GrpcPort,
83 KafkaAdapterHost: default_KafkaAdapterHost,
84 KafkaAdapterPort: default_KafkaAdapterPort,
85 KafkaClusterHost: default_KafkaClusterHost,
86 KafkaClusterPort: default_KafkaClusterPort,
87 KVStoreType: default_KVStoreType,
88 KVStoreTimeout: default_KVStoreTimeout,
89 KVStoreHost: default_KVStoreHost,
90 KVStorePort: default_KVStorePort,
91 CoreTopic: default_CoreTopic,
92 LogLevel: default_LogLevel,
93 Banner: default_Banner,
94 RWCoreKey: default_RWCoreKey,
95 RWCoreCert: default_RWCoreCert,
96 RWCoreCA: default_RWCoreCA,
khenaidoocfee5f42018-07-19 22:47:38 -040097 }
98 return &rwCoreFlag
99}
100
khenaidoo5c11af72018-07-20 17:21:05 -0400101// ParseCommandArguments parses the arguments when running read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -0400102func (cf *RWCoreFlags) ParseCommandArguments() {
khenaidoocfee5f42018-07-19 22:47:38 -0400103
khenaidoo5c11af72018-07-20 17:21:05 -0400104 var help string
khenaidoocfee5f42018-07-19 22:47:38 -0400105
khenaidoo5c11af72018-07-20 17:21:05 -0400106 help = fmt.Sprintf("RW core endpoint address")
107 flag.StringVar(&(cf.RWCoreEndpoint), "vcore-endpoint", default_RWCoreEndpoint, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400108
khenaidoo5c11af72018-07-20 17:21:05 -0400109 help = fmt.Sprintf("GRPC server - host")
110 flag.StringVar(&(cf.GrpcHost), "grpc_host", default_GrpcHost, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400111
khenaidoo5c11af72018-07-20 17:21:05 -0400112 help = fmt.Sprintf("GRPC server - port")
113 flag.IntVar(&(cf.GrpcPort), "grpc_port", default_GrpcPort, help)
114
115 help = fmt.Sprintf("Kafka - Adapter messaging host")
116 flag.StringVar(&(cf.KafkaAdapterHost), "kafka_adapter_host", default_KafkaAdapterHost, help)
117
118 help = fmt.Sprintf("Kafka - Adapter messaging port")
119 flag.IntVar(&(cf.KafkaAdapterPort), "kafka_adapter_port", default_KafkaAdapterPort, help)
120
121 help = fmt.Sprintf("Kafka - Cluster messaging host")
122 flag.StringVar(&(cf.KafkaClusterHost), "kafka_cluster_host", default_KafkaClusterHost, help)
123
124 help = fmt.Sprintf("Kafka - Cluster messaging port")
125 flag.IntVar(&(cf.KafkaClusterPort), "kafka_cluster_port", default_KafkaClusterPort, help)
126
127 help = fmt.Sprintf("RW Core topic")
128 flag.StringVar(&(cf.CoreTopic), "rw_core_topic", default_CoreTopic, help)
129
130 help = fmt.Sprintf("KV store type")
131 flag.StringVar(&(cf.KVStoreType), "kv_store_type", default_KVStoreType, help)
132
133 help = fmt.Sprintf("The default timeout when making a kv store request")
134 flag.IntVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", default_KVStoreTimeout, help)
135
136 help = fmt.Sprintf("KV store host")
137 flag.StringVar(&(cf.KVStoreHost), "kv_store_host", default_KVStoreHost, help)
138
139 help = fmt.Sprintf("KV store port")
140 flag.IntVar(&(cf.KVStorePort), "kv_store_port", default_KVStorePort, help)
141
142 help = fmt.Sprintf("Log level")
143 flag.IntVar(&(cf.LogLevel), "log_level", default_LogLevel, help)
144
145 help = fmt.Sprintf("Show startup banner log lines")
146 flag.BoolVar(&cf.Banner, "banner", default_Banner, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400147
148 flag.Parse()
149
khenaidoocfee5f42018-07-19 22:47:38 -0400150 containerName := getContainerInfo()
khenaidoocfee5f42018-07-19 22:47:38 -0400151 if len(containerName) > 0 {
152 cf.InstanceID = containerName
153 }
154
khenaidoocfee5f42018-07-19 22:47:38 -0400155}
156
157func getContainerInfo() string {
158 return os.Getenv("HOSTNAME")
159}