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