blob: be78228fdcd660a7bb78a8bfccc6156972dac49e [file] [log] [blame]
Stephane Barbariea75791c2019-01-24 10:58:06 -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// RO Core service default constants
26const (
27 ConsulStoreName = "consul"
28 EtcdStoreName = "etcd"
29 default_InstanceID = "rocore001"
30 default_GrpcPort = 50057
31 default_GrpcHost = ""
32 default_KVStoreType = EtcdStoreName
33 default_KVStoreTimeout = 5 //in seconds
34 default_KVStoreHost = "127.0.0.1"
35 default_KVStorePort = 2379 // Consul = 8500; Etcd = 2379
36 default_KVTxnKeyDelTime = 60
37 default_LogLevel = 0
38 default_Banner = false
David K. Bainbridgef430cd52019-05-28 15:00:35 -070039 default_DisplayVersionOnly = false
Stephane Barbariea75791c2019-01-24 10:58:06 -050040 default_CoreTopic = "rocore"
41 default_ROCoreEndpoint = "rocore"
42 default_ROCoreKey = "pki/voltha.key"
43 default_ROCoreCert = "pki/voltha.crt"
44 default_ROCoreCA = "pki/voltha-CA.pem"
45 default_Affinity_Router_Topic = "affinityRouter"
Hardik Windlass17c2c742019-09-30 07:15:13 +000046 default_ProbePort = 8080
Stephane Barbariea75791c2019-01-24 10:58:06 -050047)
48
49// ROCoreFlags represents the set of configurations used by the read-only core service
50type ROCoreFlags struct {
51 // Command line parameters
52 InstanceID string
53 ROCoreEndpoint string
54 GrpcHost string
55 GrpcPort int
56 KVStoreType string
57 KVStoreTimeout int // in seconds
58 KVStoreHost string
59 KVStorePort int
60 KVTxnKeyDelTime int
61 CoreTopic string
62 LogLevel int
63 Banner bool
David K. Bainbridgef430cd52019-05-28 15:00:35 -070064 DisplayVersionOnly bool
Stephane Barbariea75791c2019-01-24 10:58:06 -050065 ROCoreKey string
66 ROCoreCert string
67 ROCoreCA string
68 AffinityRouterTopic string
Hardik Windlass17c2c742019-09-30 07:15:13 +000069 ProbePort int
Stephane Barbariea75791c2019-01-24 10:58:06 -050070}
71
72func init() {
73 log.AddPackage(log.JSON, log.WarnLevel, nil)
74}
75
76// NewROCoreFlags returns a new ROCore config
77func NewROCoreFlags() *ROCoreFlags {
78 var roCoreFlag = ROCoreFlags{ // Default values
79 InstanceID: default_InstanceID,
80 ROCoreEndpoint: default_ROCoreEndpoint,
81 GrpcHost: default_GrpcHost,
82 GrpcPort: default_GrpcPort,
83 KVStoreType: default_KVStoreType,
84 KVStoreTimeout: default_KVStoreTimeout,
85 KVStoreHost: default_KVStoreHost,
86 KVStorePort: default_KVStorePort,
87 KVTxnKeyDelTime: default_KVTxnKeyDelTime,
88 CoreTopic: default_CoreTopic,
89 LogLevel: default_LogLevel,
90 Banner: default_Banner,
David K. Bainbridgef430cd52019-05-28 15:00:35 -070091 DisplayVersionOnly: default_DisplayVersionOnly,
Stephane Barbariea75791c2019-01-24 10:58:06 -050092 ROCoreKey: default_ROCoreKey,
93 ROCoreCert: default_ROCoreCert,
94 ROCoreCA: default_ROCoreCA,
95 AffinityRouterTopic: default_Affinity_Router_Topic,
Hardik Windlass17c2c742019-09-30 07:15:13 +000096 ProbePort: default_ProbePort,
Stephane Barbariea75791c2019-01-24 10:58:06 -050097 }
98 return &roCoreFlag
99}
100
101// ParseCommandArguments parses the arguments when running read-only core service
102func (cf *ROCoreFlags) ParseCommandArguments() {
103
104 var help string
105
106 help = fmt.Sprintf("RO core endpoint address")
107 flag.StringVar(&(cf.ROCoreEndpoint), "vcore-endpoint", default_ROCoreEndpoint, help)
108
109 help = fmt.Sprintf("GRPC server - host")
110 flag.StringVar(&(cf.GrpcHost), "grpc_host", default_GrpcHost, help)
111
112 help = fmt.Sprintf("GRPC server - port")
113 flag.IntVar(&(cf.GrpcPort), "grpc_port", default_GrpcPort, help)
114
115 help = fmt.Sprintf("RO Core topic")
116 flag.StringVar(&(cf.CoreTopic), "ro_core_topic", default_CoreTopic, help)
117
118 help = fmt.Sprintf("Affinity Router topic")
119 flag.StringVar(&(cf.AffinityRouterTopic), "affinity_router_topic", default_Affinity_Router_Topic, help)
120
121 help = fmt.Sprintf("KV store type")
122 flag.StringVar(&(cf.KVStoreType), "kv_store_type", default_KVStoreType, help)
123
124 help = fmt.Sprintf("The default timeout when making a kv store request")
125 flag.IntVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", default_KVStoreTimeout, help)
126
127 help = fmt.Sprintf("KV store host")
128 flag.StringVar(&(cf.KVStoreHost), "kv_store_host", default_KVStoreHost, help)
129
130 help = fmt.Sprintf("KV store port")
131 flag.IntVar(&(cf.KVStorePort), "kv_store_port", default_KVStorePort, help)
132
133 help = fmt.Sprintf("The time to wait before deleting a completed transaction key")
134 flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", default_KVTxnKeyDelTime, help)
135
136 help = fmt.Sprintf("Log level")
137 flag.IntVar(&(cf.LogLevel), "log_level", default_LogLevel, help)
138
139 help = fmt.Sprintf("Show startup banner log lines")
140 flag.BoolVar(&cf.Banner, "banner", default_Banner, help)
141
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700142 help = fmt.Sprintf("Show version information and exit")
143 flag.BoolVar(&cf.DisplayVersionOnly, "version", default_DisplayVersionOnly, help)
144
Hardik Windlass17c2c742019-09-30 07:15:13 +0000145 help = fmt.Sprintf("The port on which to listen to answer liveness and readiness probe queries over HTTP.")
146 flag.IntVar(&(cf.ProbePort), "probe_port", default_ProbePort, help)
147
Stephane Barbariea75791c2019-01-24 10:58:06 -0500148 flag.Parse()
149
150 containerName := getContainerInfo()
151 if len(containerName) > 0 {
152 cf.InstanceID = containerName
153 }
154
155}
156
157func getContainerInfo() string {
158 return os.Getenv("HOSTNAME")
159}