cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 16 | |
| 17 | //Package main invokes the application |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 18 | package main |
| 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "errors" |
| 23 | "fmt" |
kdarapu | b67f49c | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 24 | "os" |
| 25 | "os/signal" |
| 26 | "strconv" |
| 27 | "syscall" |
| 28 | "time" |
| 29 | |
| 30 | "github.com/opencord/voltha-go/adapters/adapterif" |
| 31 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 32 | "github.com/opencord/voltha-go/adapters" |
| 33 | com "github.com/opencord/voltha-go/adapters/common" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 34 | "github.com/opencord/voltha-go/common/log" |
| 35 | "github.com/opencord/voltha-go/db/kvstore" |
| 36 | "github.com/opencord/voltha-go/kafka" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 37 | ac "github.com/opencord/voltha-openolt-adapter/adaptercore" |
| 38 | "github.com/opencord/voltha-openolt-adapter/config" |
Matt Jeanneret | 0c9ae28 | 2019-07-18 18:14:28 -0400 | [diff] [blame] | 39 | "github.com/opencord/voltha-openolt-adapter/config/version" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 40 | ic "github.com/opencord/voltha-protos/go/inter_container" |
| 41 | "github.com/opencord/voltha-protos/go/voltha" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 42 | ) |
| 43 | |
| 44 | type adapter struct { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 45 | instanceID string |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 46 | config *config.AdapterFlags |
| 47 | iAdapter adapters.IAdapter |
| 48 | kafkaClient kafka.Client |
| 49 | kvClient kvstore.Client |
| 50 | kip *kafka.InterContainerProxy |
kdarapu | b67f49c | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 51 | coreProxy adapterif.CoreProxy |
| 52 | adapterProxy adapterif.AdapterProxy |
| 53 | eventProxy adapterif.EventProxy |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 54 | halted bool |
| 55 | exitChannel chan int |
| 56 | receiverChannels []<-chan *ic.InterContainerMessage |
| 57 | } |
| 58 | |
| 59 | func init() { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 60 | _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | func newAdapter(cf *config.AdapterFlags) *adapter { |
| 64 | var a adapter |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 65 | a.instanceID = cf.InstanceID |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 66 | a.config = cf |
| 67 | a.halted = false |
| 68 | a.exitChannel = make(chan int, 1) |
| 69 | a.receiverChannels = make([]<-chan *ic.InterContainerMessage, 0) |
| 70 | return &a |
| 71 | } |
| 72 | |
| 73 | func (a *adapter) start(ctx context.Context) { |
| 74 | log.Info("Starting Core Adapter components") |
| 75 | var err error |
| 76 | |
| 77 | // Setup KV Client |
| 78 | log.Debugw("create-kv-client", log.Fields{"kvstore": a.config.KVStoreType}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 79 | if err = a.setKVClient(); err != nil { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 80 | log.Fatal("error-setting-kv-client") |
| 81 | } |
| 82 | |
| 83 | // Setup Kafka Client |
| 84 | if a.kafkaClient, err = newKafkaClient("sarama", a.config.KafkaAdapterHost, a.config.KafkaAdapterPort); err != nil { |
| 85 | log.Fatal("Unsupported-common-client") |
| 86 | } |
| 87 | |
| 88 | // Start the common InterContainer Proxy - retries indefinitely |
| 89 | if a.kip, err = a.startInterContainerProxy(-1); err != nil { |
| 90 | log.Fatal("error-starting-inter-container-proxy") |
| 91 | } |
| 92 | |
| 93 | // Create the core proxy to handle requests to the Core |
| 94 | a.coreProxy = com.NewCoreProxy(a.kip, a.config.Topic, a.config.CoreTopic) |
| 95 | |
| 96 | // Create the adaptor proxy to handle request between olt and onu |
| 97 | a.adapterProxy = com.NewAdapterProxy(a.kip, "brcm_openomci_onu", a.config.CoreTopic) |
| 98 | |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 99 | // Create the event proxy to post events to KAFKA |
| 100 | a.eventProxy = com.NewEventProxy(com.MsgClient(a.kafkaClient), com.MsgTopic(kafka.Topic{Name: a.config.EventTopic})) |
| 101 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 102 | // Create the open OLT adapter |
kdarapu | b67f49c | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 103 | if a.iAdapter, err = a.startOpenOLT(ctx, a.kip, a.coreProxy, a.adapterProxy, a.eventProxy, |
| 104 | a.config.OnuNumber, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 105 | a.config.KVStoreHost, a.config.KVStorePort, a.config.KVStoreType); err != nil { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 106 | log.Fatal("error-starting-inter-container-proxy") |
| 107 | } |
| 108 | |
| 109 | // Register the core request handler |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 110 | if err = a.setupRequestHandler(a.instanceID, a.iAdapter); err != nil { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 111 | log.Fatal("error-setting-core-request-handler") |
| 112 | } |
| 113 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 114 | // Register this adapter to the Core - retries indefinitely |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 115 | if err = a.registerWithCore(-1); err != nil { |
| 116 | log.Fatal("error-registering-with-core") |
| 117 | } |
| 118 | } |
| 119 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 120 | func (a *adapter) stop() { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 121 | // Stop leadership tracking |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 122 | a.halted = true |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 123 | |
| 124 | // send exit signal |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 125 | a.exitChannel <- 0 |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 126 | |
| 127 | // Cleanup - applies only if we had a kvClient |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 128 | if a.kvClient != nil { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 129 | // Release all reservations |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 130 | if err := a.kvClient.ReleaseAllReservations(); err != nil { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 131 | log.Infow("fail-to-release-all-reservations", log.Fields{"error": err}) |
| 132 | } |
| 133 | // Close the DB connection |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 134 | a.kvClient.Close() |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | // TODO: More cleanup |
| 138 | } |
| 139 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 140 | func newKVClient(storeType, address string, timeout int) (kvstore.Client, error) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 141 | |
| 142 | log.Infow("kv-store-type", log.Fields{"store": storeType}) |
| 143 | switch storeType { |
| 144 | case "consul": |
| 145 | return kvstore.NewConsulClient(address, timeout) |
| 146 | case "etcd": |
| 147 | return kvstore.NewEtcdClient(address, timeout) |
| 148 | } |
| 149 | return nil, errors.New("unsupported-kv-store") |
| 150 | } |
| 151 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 152 | func newKafkaClient(clientType, host string, port int) (kafka.Client, error) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 153 | |
| 154 | log.Infow("common-client-type", log.Fields{"client": clientType}) |
| 155 | switch clientType { |
| 156 | case "sarama": |
| 157 | return kafka.NewSaramaClient( |
| 158 | kafka.Host(host), |
| 159 | kafka.Port(port), |
| 160 | kafka.ProducerReturnOnErrors(true), |
| 161 | kafka.ProducerReturnOnSuccess(true), |
| 162 | kafka.ProducerMaxRetries(6), |
Abhilash S.L | 3b49463 | 2019-07-16 15:51:09 +0530 | [diff] [blame] | 163 | kafka.ProducerRetryBackoff(time.Millisecond*30), |
| 164 | kafka.MetadatMaxRetries(15)), nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 165 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 166 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 167 | return nil, errors.New("unsupported-client-type") |
| 168 | } |
| 169 | |
| 170 | func (a *adapter) setKVClient() error { |
| 171 | addr := a.config.KVStoreHost + ":" + strconv.Itoa(a.config.KVStorePort) |
| 172 | client, err := newKVClient(a.config.KVStoreType, addr, a.config.KVStoreTimeout) |
| 173 | if err != nil { |
| 174 | a.kvClient = nil |
| 175 | log.Error(err) |
| 176 | return err |
| 177 | } |
| 178 | a.kvClient = client |
| 179 | return nil |
| 180 | } |
| 181 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 182 | func (a *adapter) startInterContainerProxy(retries int) (*kafka.InterContainerProxy, error) { |
| 183 | log.Infow("starting-intercontainer-messaging-proxy", log.Fields{"host": a.config.KafkaAdapterHost, |
| 184 | "port": a.config.KafkaAdapterPort, "topic": a.config.Topic}) |
| 185 | var err error |
| 186 | var kip *kafka.InterContainerProxy |
| 187 | if kip, err = kafka.NewInterContainerProxy( |
| 188 | kafka.InterContainerHost(a.config.KafkaAdapterHost), |
| 189 | kafka.InterContainerPort(a.config.KafkaAdapterPort), |
| 190 | kafka.MsgClient(a.kafkaClient), |
| 191 | kafka.DefaultTopic(&kafka.Topic{Name: a.config.Topic})); err != nil { |
| 192 | log.Errorw("fail-to-create-common-proxy", log.Fields{"error": err}) |
| 193 | return nil, err |
| 194 | } |
| 195 | count := 0 |
| 196 | for { |
| 197 | if err = kip.Start(); err != nil { |
| 198 | log.Warnw("error-starting-messaging-proxy", log.Fields{"error": err}) |
| 199 | if retries == count { |
| 200 | return nil, err |
| 201 | } |
| 202 | count = +1 |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 203 | // Take a nap before retrying |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 204 | time.Sleep(2 * time.Second) |
| 205 | } else { |
| 206 | break |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | log.Info("common-messaging-proxy-created") |
| 211 | return kip, nil |
| 212 | } |
| 213 | |
kdarapu | b67f49c | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 214 | func (a *adapter) startOpenOLT(ctx context.Context, kip *kafka.InterContainerProxy, |
| 215 | cp adapterif.CoreProxy, ap adapterif.AdapterProxy, ep adapterif.EventProxy, onuNumber int, kvStoreHost string, |
| 216 | kvStorePort int, KVStoreType string) (*ac.OpenOLT, error) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 217 | log.Info("starting-open-olt") |
| 218 | var err error |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 219 | sOLT := ac.NewOpenOLT(ctx, a.kip, cp, ap, ep, onuNumber, kvStoreHost, kvStorePort, KVStoreType) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 220 | |
| 221 | if err = sOLT.Start(ctx); err != nil { |
| 222 | log.Fatalw("error-starting-messaging-proxy", log.Fields{"error": err}) |
| 223 | return nil, err |
| 224 | } |
| 225 | |
| 226 | log.Info("open-olt-started") |
| 227 | return sOLT, nil |
| 228 | } |
| 229 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 230 | func (a *adapter) setupRequestHandler(coreInstanceID string, iadapter adapters.IAdapter) error { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 231 | log.Info("setting-request-handler") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 232 | requestProxy := com.NewRequestHandlerProxy(coreInstanceID, iadapter, a.coreProxy) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 233 | if err := a.kip.SubscribeWithRequestHandlerInterface(kafka.Topic{Name: a.config.Topic}, requestProxy); err != nil { |
| 234 | log.Errorw("request-handler-setup-failed", log.Fields{"error": err}) |
| 235 | return err |
| 236 | |
| 237 | } |
| 238 | log.Info("request-handler-setup-done") |
| 239 | return nil |
| 240 | } |
| 241 | |
| 242 | func (a *adapter) registerWithCore(retries int) error { |
| 243 | log.Info("registering-with-core") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 244 | adapterDescription := &voltha.Adapter{Id: "openolt", // Unique name for the device type |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 245 | Vendor: "VOLTHA OpenOLT", |
| 246 | Version: version.VersionInfo.Version} |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 247 | types := []*voltha.DeviceType{{Id: "openolt", |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 248 | Adapter: "openolt", // Name of the adapter that handles device type |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 249 | AcceptsBulkFlowUpdate: false, // Currently openolt adapter does not support bulk flow handling |
| 250 | AcceptsAddRemoveFlowUpdates: true}} |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 251 | deviceTypes := &voltha.DeviceTypes{Items: types} |
| 252 | count := 0 |
| 253 | for { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 254 | if err := a.coreProxy.RegisterAdapter(context.TODO(), adapterDescription, deviceTypes); err != nil { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 255 | log.Warnw("registering-with-core-failed", log.Fields{"error": err}) |
| 256 | if retries == count { |
| 257 | return err |
| 258 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 259 | count++ |
| 260 | // Take a nap before retrying |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 261 | time.Sleep(2 * time.Second) |
| 262 | } else { |
| 263 | break |
| 264 | } |
| 265 | } |
| 266 | log.Info("registered-with-core") |
| 267 | return nil |
| 268 | } |
| 269 | |
| 270 | func waitForExit() int { |
| 271 | signalChannel := make(chan os.Signal, 1) |
| 272 | signal.Notify(signalChannel, |
| 273 | syscall.SIGHUP, |
| 274 | syscall.SIGINT, |
| 275 | syscall.SIGTERM, |
| 276 | syscall.SIGQUIT) |
| 277 | |
| 278 | exitChannel := make(chan int) |
| 279 | |
| 280 | go func() { |
| 281 | s := <-signalChannel |
| 282 | switch s { |
| 283 | case syscall.SIGHUP, |
| 284 | syscall.SIGINT, |
| 285 | syscall.SIGTERM, |
| 286 | syscall.SIGQUIT: |
| 287 | log.Infow("closing-signal-received", log.Fields{"signal": s}) |
| 288 | exitChannel <- 0 |
| 289 | default: |
| 290 | log.Infow("unexpected-signal-received", log.Fields{"signal": s}) |
| 291 | exitChannel <- 1 |
| 292 | } |
| 293 | }() |
| 294 | |
| 295 | code := <-exitChannel |
| 296 | return code |
| 297 | } |
| 298 | |
| 299 | func printBanner() { |
| 300 | fmt.Println(" ____ ____ _ _______ ") |
| 301 | fmt.Println(" / _ \\ / __\\| | |__ __|") |
| 302 | fmt.Println(" | | | |_ __ ___ _ __ | | | | | | | ") |
| 303 | fmt.Println(" | | | | '_\\ / _\\ '_\\ | | | | | | | ") |
| 304 | fmt.Println(" | |__| | |_) | __/ | | || |__| | |____| | ") |
| 305 | fmt.Println(" \\____/| .__/\\___|_| |_|\\____/|______|_| ") |
| 306 | fmt.Println(" | | ") |
| 307 | fmt.Println(" |_| ") |
| 308 | fmt.Println(" ") |
| 309 | } |
| 310 | |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 311 | func printVersion() { |
| 312 | fmt.Println("VOLTHA OpenOLT Adapter") |
| 313 | fmt.Println(version.VersionInfo.String(" ")) |
| 314 | } |
| 315 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 316 | func main() { |
| 317 | start := time.Now() |
| 318 | |
| 319 | cf := config.NewAdapterFlags() |
| 320 | cf.ParseCommandArguments() |
| 321 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 322 | // Setup logging |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 323 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 324 | // Setup default logger - applies for packages that do not have specific logger set |
Hardik Windlass | 1735a5b | 2019-10-10 08:34:32 +0000 | [diff] [blame] | 325 | if _, err := log.SetDefaultLogger(log.JSON, cf.LogLevel, log.Fields{"instanceId": cf.InstanceID}); err != nil { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 326 | log.With(log.Fields{"error": err}).Fatal("Cannot setup logging") |
| 327 | } |
| 328 | |
| 329 | // Update all loggers (provisionned via init) with a common field |
Hardik Windlass | 1735a5b | 2019-10-10 08:34:32 +0000 | [diff] [blame] | 330 | if err := log.UpdateAllLoggers(log.Fields{"instanceId": cf.InstanceID}); err != nil { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 331 | log.With(log.Fields{"error": err}).Fatal("Cannot setup logging") |
| 332 | } |
| 333 | |
| 334 | log.SetPackageLogLevel("github.com/opencord/voltha-go/adapters/common", log.DebugLevel) |
| 335 | |
| 336 | defer log.CleanUp() |
| 337 | |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 338 | // Print version / build information and exit |
| 339 | if cf.DisplayVersionOnly { |
| 340 | printVersion() |
| 341 | return |
| 342 | } |
| 343 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 344 | // Print banner if specified |
| 345 | if cf.Banner { |
| 346 | printBanner() |
| 347 | } |
| 348 | |
| 349 | log.Infow("config", log.Fields{"config": *cf}) |
| 350 | |
| 351 | ctx, cancel := context.WithCancel(context.Background()) |
| 352 | defer cancel() |
| 353 | |
| 354 | ad := newAdapter(cf) |
| 355 | go ad.start(ctx) |
| 356 | |
| 357 | code := waitForExit() |
| 358 | log.Infow("received-a-closing-signal", log.Fields{"code": code}) |
| 359 | |
| 360 | // Cleanup before leaving |
| 361 | ad.stop() |
| 362 | |
| 363 | elapsed := time.Since(start) |
Hardik Windlass | 1735a5b | 2019-10-10 08:34:32 +0000 | [diff] [blame] | 364 | log.Infow("run-time", log.Fields{"instanceId": ad.config.InstanceID, "time": elapsed / time.Second}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 365 | } |