blob: 8b2c165e30cc822e96cd7efdeb267e6b39216e84 [file] [log] [blame]
khenaidoocfee5f42018-07-19 22:47:38 -04001package config
2
3import (
4 //"context"
5 "flag"
6 "fmt"
7 //dt "github.com/docker/docker/api/types"
8 //dc "github.com/docker/docker/client"
9 "os"
khenaidoocfee5f42018-07-19 22:47:38 -040010)
11
khenaidoo5c11af72018-07-20 17:21:05 -040012// RW Core service default constants
khenaidoocfee5f42018-07-19 22:47:38 -040013const (
khenaidoo5c11af72018-07-20 17:21:05 -040014 ConsulStoreName = "consul"
15 EtcdStoreName = "etcd"
16 default_InstanceID = "rwcore001"
17 default_GrpcPort = 50057
18 default_GrpcHost = "10.100.198.240"
19 default_KafkaAdapterHost = "10.100.198.240"
20 default_KafkaAdapterPort = 9092
21 default_KafkaClusterHost = "10.100.198.240"
22 default_KafkaClusterPort = 9094
23 default_KVStoreType = ConsulStoreName
24 default_KVStoreTimeout = 5 //in seconds
25 default_KVStoreHost = "10.100.198.240"
26 default_KVStorePort = 8500 // Etcd = 2379
khenaidooabad44c2018-08-03 16:58:35 -040027 default_LogLevel = 0
khenaidoo5c11af72018-07-20 17:21:05 -040028 default_Banner = false
29 default_CoreTopic = "rwcore"
30 default_RWCoreEndpoint = "rwcore"
31 default_RWCoreKey = "pki/voltha.key"
32 default_RWCoreCert = "pki/voltha.crt"
33 default_RWCoreCA = "pki/voltha-CA.pem"
khenaidoocfee5f42018-07-19 22:47:38 -040034)
35
khenaidoo5c11af72018-07-20 17:21:05 -040036// RWCoreFlags represents the set of configurations used by the read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -040037type RWCoreFlags struct {
38 // Command line parameters
khenaidoo5c11af72018-07-20 17:21:05 -040039 InstanceID string
40 RWCoreEndpoint string
41 GrpcHost string
42 GrpcPort int
43 KafkaAdapterHost string
44 KafkaAdapterPort int
45 KafkaClusterHost string
46 KafkaClusterPort int
47 KVStoreType string
48 KVStoreTimeout int // in seconds
49 KVStoreHost string
50 KVStorePort int
51 CoreTopic string
52 LogLevel int
53 Banner bool
54 RWCoreKey string
55 RWCoreCert string
56 RWCoreCA string
khenaidoocfee5f42018-07-19 22:47:38 -040057}
58
khenaidoo5c11af72018-07-20 17:21:05 -040059// NewRWCoreFlags returns a new RWCore config
khenaidoocfee5f42018-07-19 22:47:38 -040060func NewRWCoreFlags() *RWCoreFlags {
61 var rwCoreFlag = RWCoreFlags{ // Default values
khenaidoo5c11af72018-07-20 17:21:05 -040062 InstanceID: default_InstanceID,
63 RWCoreEndpoint: default_RWCoreEndpoint,
64 GrpcHost: default_GrpcHost,
65 GrpcPort: default_GrpcPort,
66 KafkaAdapterHost: default_KafkaAdapterHost,
67 KafkaAdapterPort: default_KafkaAdapterPort,
68 KafkaClusterHost: default_KafkaClusterHost,
69 KafkaClusterPort: default_KafkaClusterPort,
70 KVStoreType: default_KVStoreType,
71 KVStoreTimeout: default_KVStoreTimeout,
72 KVStoreHost: default_KVStoreHost,
73 KVStorePort: default_KVStorePort,
74 CoreTopic: default_CoreTopic,
75 LogLevel: default_LogLevel,
76 Banner: default_Banner,
77 RWCoreKey: default_RWCoreKey,
78 RWCoreCert: default_RWCoreCert,
79 RWCoreCA: default_RWCoreCA,
khenaidoocfee5f42018-07-19 22:47:38 -040080 }
81 return &rwCoreFlag
82}
83
khenaidoo5c11af72018-07-20 17:21:05 -040084// ParseCommandArguments parses the arguments when running read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -040085func (cf *RWCoreFlags) ParseCommandArguments() {
khenaidoocfee5f42018-07-19 22:47:38 -040086
khenaidoo5c11af72018-07-20 17:21:05 -040087 var help string
khenaidoocfee5f42018-07-19 22:47:38 -040088
khenaidoo5c11af72018-07-20 17:21:05 -040089 help = fmt.Sprintf("RW core endpoint address")
90 flag.StringVar(&(cf.RWCoreEndpoint), "vcore-endpoint", default_RWCoreEndpoint, help)
khenaidoocfee5f42018-07-19 22:47:38 -040091
khenaidoo5c11af72018-07-20 17:21:05 -040092 help = fmt.Sprintf("GRPC server - host")
93 flag.StringVar(&(cf.GrpcHost), "grpc_host", default_GrpcHost, help)
khenaidoocfee5f42018-07-19 22:47:38 -040094
khenaidoo5c11af72018-07-20 17:21:05 -040095 help = fmt.Sprintf("GRPC server - port")
96 flag.IntVar(&(cf.GrpcPort), "grpc_port", default_GrpcPort, help)
97
98 help = fmt.Sprintf("Kafka - Adapter messaging host")
99 flag.StringVar(&(cf.KafkaAdapterHost), "kafka_adapter_host", default_KafkaAdapterHost, help)
100
101 help = fmt.Sprintf("Kafka - Adapter messaging port")
102 flag.IntVar(&(cf.KafkaAdapterPort), "kafka_adapter_port", default_KafkaAdapterPort, help)
103
104 help = fmt.Sprintf("Kafka - Cluster messaging host")
105 flag.StringVar(&(cf.KafkaClusterHost), "kafka_cluster_host", default_KafkaClusterHost, help)
106
107 help = fmt.Sprintf("Kafka - Cluster messaging port")
108 flag.IntVar(&(cf.KafkaClusterPort), "kafka_cluster_port", default_KafkaClusterPort, help)
109
110 help = fmt.Sprintf("RW Core topic")
111 flag.StringVar(&(cf.CoreTopic), "rw_core_topic", default_CoreTopic, help)
112
113 help = fmt.Sprintf("KV store type")
114 flag.StringVar(&(cf.KVStoreType), "kv_store_type", default_KVStoreType, help)
115
116 help = fmt.Sprintf("The default timeout when making a kv store request")
117 flag.IntVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", default_KVStoreTimeout, help)
118
119 help = fmt.Sprintf("KV store host")
120 flag.StringVar(&(cf.KVStoreHost), "kv_store_host", default_KVStoreHost, help)
121
122 help = fmt.Sprintf("KV store port")
123 flag.IntVar(&(cf.KVStorePort), "kv_store_port", default_KVStorePort, help)
124
125 help = fmt.Sprintf("Log level")
126 flag.IntVar(&(cf.LogLevel), "log_level", default_LogLevel, help)
127
128 help = fmt.Sprintf("Show startup banner log lines")
129 flag.BoolVar(&cf.Banner, "banner", default_Banner, help)
khenaidoocfee5f42018-07-19 22:47:38 -0400130
131 flag.Parse()
132
133 // Update the necessary keys with the prefixes
khenaidoo5c11af72018-07-20 17:21:05 -0400134 //start := time.Now()
khenaidoocfee5f42018-07-19 22:47:38 -0400135 containerName := getContainerInfo()
khenaidoo5c11af72018-07-20 17:21:05 -0400136 //fmt.Println("container name:", containerName)
khenaidoocfee5f42018-07-19 22:47:38 -0400137 if len(containerName) > 0 {
138 cf.InstanceID = containerName
139 }
140
khenaidoo5c11af72018-07-20 17:21:05 -0400141 //fmt.Println("Inside config:", cf)
142 //elapsed := time.Since(start)
143 //fmt.Println("time:", elapsed/time.Second)
khenaidoocfee5f42018-07-19 22:47:38 -0400144}
145
146func getContainerInfo() string {
147 return os.Getenv("HOSTNAME")
148}