cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1 | /* |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 3 | |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 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 |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 7 | |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 9 | |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 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. |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 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 | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 24 | "os" |
| 25 | "os/signal" |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 26 | "syscall" |
| 27 | "time" |
| 28 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 29 | conf "github.com/opencord/voltha-lib-go/v7/pkg/config" |
| 30 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 31 | "github.com/opencord/voltha-lib-go/v7/pkg/events" |
| 32 | "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif" |
| 33 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| 34 | "github.com/opencord/voltha-lib-go/v7/pkg/kafka" |
| 35 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| 36 | "github.com/opencord/voltha-lib-go/v7/pkg/probe" |
| 37 | "github.com/opencord/voltha-lib-go/v7/pkg/version" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 38 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/config" |
| 39 | ac "github.com/opencord/voltha-openolt-adapter/internal/pkg/core" |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 40 | "github.com/opencord/voltha-protos/v5/go/adapter_service" |
| 41 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
| 42 | "github.com/opencord/voltha-protos/v5/go/core_service" |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 43 | "github.com/opencord/voltha-protos/v5/go/olt_inter_adapter_service" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 44 | "github.com/opencord/voltha-protos/v5/go/voltha" |
| 45 | "google.golang.org/grpc" |
| 46 | ) |
| 47 | |
| 48 | const ( |
| 49 | clusterMessagingService = "cluster-message-service" |
| 50 | oltAdapterService = "olt-adapter-service" |
| 51 | kvService = "kv-service" |
| 52 | coreService = "core-service" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 53 | ) |
| 54 | |
| 55 | type adapter struct { |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 56 | instanceID string |
| 57 | config *config.AdapterFlags |
| 58 | grpcServer *vgrpc.GrpcServer |
| 59 | oltAdapter *ac.OpenOLT |
| 60 | oltInterAdapter *ac.OpenOLTInterAdapter |
| 61 | kafkaClient kafka.Client |
| 62 | kvClient kvstore.Client |
| 63 | coreClient *vgrpc.Client |
| 64 | eventProxy eventif.EventProxy |
| 65 | halted bool |
| 66 | exitChannel chan int |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 67 | } |
| 68 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 69 | func newAdapter(cf *config.AdapterFlags) *adapter { |
| 70 | var a adapter |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 71 | a.instanceID = cf.InstanceID |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 72 | a.config = cf |
| 73 | a.halted = false |
| 74 | a.exitChannel = make(chan int, 1) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 75 | return &a |
| 76 | } |
| 77 | |
| 78 | func (a *adapter) start(ctx context.Context) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 79 | logger.Info(ctx, "Starting Core Adapter components") |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 80 | var err error |
| 81 | |
Rohan Agrawal | 828bf4e | 2019-10-22 10:13:19 +0000 | [diff] [blame] | 82 | var p *probe.Probe |
| 83 | if value := ctx.Value(probe.ProbeContextKey); value != nil { |
| 84 | if _, ok := value.(*probe.Probe); ok { |
| 85 | p = value.(*probe.Probe) |
| 86 | p.RegisterService( |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 87 | ctx, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 88 | clusterMessagingService, |
| 89 | kvService, |
| 90 | oltAdapterService, |
| 91 | coreService, |
Rohan Agrawal | 828bf4e | 2019-10-22 10:13:19 +0000 | [diff] [blame] | 92 | ) |
| 93 | } |
| 94 | } |
| 95 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 96 | // Setup KV Client |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 97 | logger.Debugw(ctx, "create-kv-client", log.Fields{"kvstore": a.config.KVStoreType}) |
| 98 | if err = a.setKVClient(ctx); err != nil { |
| 99 | logger.Fatalw(ctx, "error-setting-kv-client", log.Fields{"error": err}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Rohan Agrawal | 828bf4e | 2019-10-22 10:13:19 +0000 | [diff] [blame] | 102 | if p != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 103 | p.UpdateStatus(ctx, kvService, probe.ServiceStatusRunning) |
Rohan Agrawal | 828bf4e | 2019-10-22 10:13:19 +0000 | [diff] [blame] | 104 | } |
| 105 | |
divyadesai | a37f78b | 2020-02-07 12:41:22 +0000 | [diff] [blame] | 106 | // Setup Log Config |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 107 | cm := conf.NewConfigManager(ctx, a.kvClient, a.config.KVStoreType, a.config.KVStoreAddress, a.config.KVStoreTimeout) |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 108 | |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 109 | go conf.StartLogLevelConfigProcessing(cm, ctx) |
Girish Kumar | 935f7af | 2020-08-18 11:59:42 +0000 | [diff] [blame] | 110 | go conf.StartLogFeaturesConfigProcessing(cm, ctx) |
divyadesai | a37f78b | 2020-02-07 12:41:22 +0000 | [diff] [blame] | 111 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 112 | // Setup Kafka Client |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 113 | if a.kafkaClient, err = newKafkaClient(ctx, "sarama", a.config.KafkaClusterAddress); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 114 | logger.Fatalw(ctx, "Unsupported-common-client", log.Fields{"error": err}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 115 | } |
| 116 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 117 | // Start kafka communication with the broker |
| 118 | if err := kafka.StartAndWaitUntilKafkaConnectionIsUp(ctx, a.kafkaClient, a.config.HeartbeatCheckInterval, clusterMessagingService); err != nil { |
| 119 | logger.Fatal(ctx, "unable-to-connect-to-kafka") |
Rohan Agrawal | 828bf4e | 2019-10-22 10:13:19 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 122 | // Create the event proxy to post events to KAFKA |
Himani Chawla | cd40780 | 2020-12-10 12:08:59 +0530 | [diff] [blame] | 123 | a.eventProxy = events.NewEventProxy(events.MsgClient(a.kafkaClient), events.MsgTopic(kafka.Topic{Name: a.config.EventTopic})) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 124 | go func() { |
| 125 | if err := a.eventProxy.Start(); err != nil { |
| 126 | logger.Fatalw(ctx, "event-proxy-cannot-start", log.Fields{"error": err}) |
| 127 | } |
| 128 | }() |
| 129 | |
| 130 | // Create the Core client to handle requests to the Core. Note that the coreClient is an interface and needs to be |
| 131 | // cast to the appropriate grpc client by invoking GetCoreGrpcClient on the a.coreClient |
khenaidoo | 27e7ac9 | 2021-12-08 14:43:09 -0500 | [diff] [blame] | 132 | if a.coreClient, err = vgrpc.NewClient( |
| 133 | a.config.AdapterEndpoint, |
| 134 | a.config.CoreEndpoint, |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 135 | "core_service.CoreService", |
khenaidoo | 27e7ac9 | 2021-12-08 14:43:09 -0500 | [diff] [blame] | 136 | a.coreRestarted); err != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 137 | logger.Fatal(ctx, "grpc-client-not-created") |
| 138 | } |
| 139 | // Start the core grpc client |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 140 | go a.coreClient.Start(ctx, getCoreServiceClientHandler) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 141 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 142 | // Create the open OLT adapter |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 143 | if a.oltAdapter, err = a.startOpenOLT(ctx, a.coreClient, a.eventProxy, a.config, cm); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 144 | logger.Fatalw(ctx, "error-starting-openolt", log.Fields{"error": err}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 145 | } |
| 146 | |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 147 | // Create the open OLT Inter adapter adapter |
| 148 | if a.oltInterAdapter, err = a.startOpenOLTInterAdapter(ctx, a.oltAdapter); err != nil { |
| 149 | logger.Fatalw(ctx, "error-starting-openolt-inter-adapter", log.Fields{"error": err}) |
| 150 | } |
| 151 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 152 | // Create and start the grpc server |
| 153 | a.grpcServer = vgrpc.NewGrpcServer(a.config.GrpcAddress, nil, false, p) |
| 154 | |
| 155 | //Register the adapter service |
| 156 | a.addAdapterService(ctx, a.grpcServer, a.oltAdapter) |
| 157 | |
| 158 | //Register the olt inter-adapter service |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 159 | a.addOltInterAdapterService(ctx, a.grpcServer, a.oltInterAdapter) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 160 | |
| 161 | // Start the grpc server |
| 162 | go a.startGRPCService(ctx, a.grpcServer, oltAdapterService) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 163 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 164 | // Register this adapter to the Core - retries indefinitely |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 165 | if err = a.registerWithCore(ctx, coreService, -1); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 166 | logger.Fatal(ctx, "error-registering-with-core") |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 167 | } |
cbabu | 95f2152 | 2019-11-13 14:25:18 +0100 | [diff] [blame] | 168 | |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 169 | // check the readiness and liveliness and update the probe status |
| 170 | a.checkServicesReadiness(ctx) |
cbabu | 95f2152 | 2019-11-13 14:25:18 +0100 | [diff] [blame] | 171 | } |
| 172 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 173 | // TODO: Any action the adapter needs to do following a Core restart? |
| 174 | func (a *adapter) coreRestarted(ctx context.Context, endPoint string) error { |
| 175 | logger.Errorw(ctx, "core-restarted", log.Fields{"endpoint": endPoint}) |
| 176 | return nil |
| 177 | } |
| 178 | |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 179 | // getCoreServiceClientHandler is used to test whether the remote gRPC service is up |
| 180 | func getCoreServiceClientHandler(ctx context.Context, conn *grpc.ClientConn) interface{} { |
| 181 | if conn == nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 182 | return nil |
| 183 | } |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 184 | return core_service.NewCoreServiceClient(conn) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 185 | } |
| 186 | |
cbabu | 95f2152 | 2019-11-13 14:25:18 +0100 | [diff] [blame] | 187 | /** |
| 188 | This function checks the liveliness and readiness of the kakfa and kv-client services |
| 189 | and update the status in the probe. |
| 190 | */ |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 191 | func (a *adapter) checkServicesReadiness(ctx context.Context) { |
| 192 | // checks the kafka readiness |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 193 | go kafka.MonitorKafkaReadiness(ctx, a.kafkaClient, a.config.LiveProbeInterval, a.config.NotLiveProbeInterval, clusterMessagingService) |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 194 | |
| 195 | // checks the kv-store readiness |
| 196 | go a.checkKvStoreReadiness(ctx) |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | This function checks the liveliness and readiness of the kv-store service |
| 201 | and update the status in the probe. |
| 202 | */ |
| 203 | func (a *adapter) checkKvStoreReadiness(ctx context.Context) { |
| 204 | // dividing the live probe interval by 2 to get updated status every 30s |
| 205 | timeout := a.config.LiveProbeInterval / 2 |
| 206 | kvStoreChannel := make(chan bool, 1) |
| 207 | |
| 208 | // Default false to check the liveliness. |
| 209 | kvStoreChannel <- false |
cbabu | 95f2152 | 2019-11-13 14:25:18 +0100 | [diff] [blame] | 210 | for { |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 211 | timeoutTimer := time.NewTimer(timeout) |
| 212 | select { |
| 213 | case liveliness := <-kvStoreChannel: |
| 214 | if !liveliness { |
| 215 | // kv-store not reachable or down, updating the status to not ready state |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 216 | probe.UpdateStatusFromContext(ctx, kvService, probe.ServiceStatusNotReady) |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 217 | timeout = a.config.NotLiveProbeInterval |
| 218 | } else { |
| 219 | // kv-store is reachable , updating the status to running state |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 220 | probe.UpdateStatusFromContext(ctx, kvService, probe.ServiceStatusRunning) |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 221 | timeout = a.config.LiveProbeInterval / 2 |
| 222 | } |
| 223 | // Check if the timer has expired or not |
| 224 | if !timeoutTimer.Stop() { |
| 225 | <-timeoutTimer.C |
| 226 | } |
| 227 | case <-timeoutTimer.C: |
Girish Kumar | beadc11 | 2020-02-26 18:41:02 +0000 | [diff] [blame] | 228 | // Check the status of the kv-store. Use timeout of 2 seconds to avoid forever blocking |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 229 | logger.Info(ctx, "kv-store liveliness-recheck") |
Girish Kumar | beadc11 | 2020-02-26 18:41:02 +0000 | [diff] [blame] | 230 | timeoutCtx, cancelFunc := context.WithTimeout(ctx, 2*time.Second) |
| 231 | |
| 232 | kvStoreChannel <- a.kvClient.IsConnectionUp(timeoutCtx) |
| 233 | // Cleanup cancel func resources |
| 234 | cancelFunc() |
cbabu | 95f2152 | 2019-11-13 14:25:18 +0100 | [diff] [blame] | 235 | } |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 239 | func (a *adapter) stop(ctx context.Context) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 240 | // Stop leadership tracking |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 241 | a.halted = true |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 242 | |
| 243 | // send exit signal |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 244 | a.exitChannel <- 0 |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 245 | |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 246 | // Stop all grpc processing |
| 247 | if err := a.oltAdapter.Stop(ctx); err != nil { |
| 248 | logger.Errorw(ctx, "failure-stopping-olt-adapter-service", log.Fields{"error": err, "adapter": a.config.AdapterName}) |
| 249 | } |
| 250 | if err := a.oltInterAdapter.Stop(ctx); err != nil { |
| 251 | logger.Errorw(ctx, "failure-stopping-olt-inter-adapter-service", log.Fields{"error": err, "adapter": a.config.AdapterName}) |
| 252 | } |
| 253 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 254 | // Cleanup - applies only if we had a kvClient |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 255 | if a.kvClient != nil { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 256 | // Release all reservations |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 257 | if err := a.kvClient.ReleaseAllReservations(ctx); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 258 | logger.Infow(ctx, "fail-to-release-all-reservations", log.Fields{"error": err}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 259 | } |
| 260 | // Close the DB connection |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 261 | a.kvClient.Close(ctx) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 262 | } |
| 263 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 264 | if a.eventProxy != nil { |
| 265 | a.eventProxy.Stop() |
Scott Baker | e701b86 | 2020-02-20 16:19:16 -0800 | [diff] [blame] | 266 | } |
| 267 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 268 | if a.kafkaClient != nil { |
| 269 | a.kafkaClient.Stop(ctx) |
| 270 | } |
| 271 | |
| 272 | // Stop core client |
| 273 | if a.coreClient != nil { |
| 274 | a.coreClient.Stop(ctx) |
| 275 | } |
| 276 | |
| 277 | // TODO: Stop child devices connections |
| 278 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 279 | // TODO: More cleanup |
| 280 | } |
| 281 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 282 | func newKVClient(ctx context.Context, storeType, address string, timeout time.Duration) (kvstore.Client, error) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 283 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 284 | logger.Infow(ctx, "kv-store-type", log.Fields{"store": storeType}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 285 | switch storeType { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 286 | case "etcd": |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 287 | return kvstore.NewEtcdClient(ctx, address, timeout, log.FatalLevel) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 288 | } |
| 289 | return nil, errors.New("unsupported-kv-store") |
| 290 | } |
| 291 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 292 | func newKafkaClient(ctx context.Context, clientType, address string) (kafka.Client, error) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 293 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 294 | logger.Infow(ctx, "common-client-type", log.Fields{"client": clientType}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 295 | switch clientType { |
| 296 | case "sarama": |
| 297 | return kafka.NewSaramaClient( |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 298 | kafka.Address(address), |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 299 | kafka.ProducerReturnOnErrors(true), |
| 300 | kafka.ProducerReturnOnSuccess(true), |
| 301 | kafka.ProducerMaxRetries(6), |
Abhilash S.L | 3b49463 | 2019-07-16 15:51:09 +0530 | [diff] [blame] | 302 | kafka.ProducerRetryBackoff(time.Millisecond*30), |
| 303 | kafka.MetadatMaxRetries(15)), nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 304 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 305 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 306 | return nil, errors.New("unsupported-client-type") |
| 307 | } |
| 308 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 309 | func (a *adapter) setKVClient(ctx context.Context) error { |
| 310 | client, err := newKVClient(ctx, a.config.KVStoreType, a.config.KVStoreAddress, a.config.KVStoreTimeout) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 311 | if err != nil { |
| 312 | a.kvClient = nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 313 | return err |
| 314 | } |
| 315 | a.kvClient = client |
divyadesai | a37f78b | 2020-02-07 12:41:22 +0000 | [diff] [blame] | 316 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 317 | return nil |
| 318 | } |
| 319 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 320 | // startGRPCService creates the grpc service handlers, registers it to the grpc server and starts the server |
| 321 | func (a *adapter) startGRPCService(ctx context.Context, server *vgrpc.GrpcServer, serviceName string) { |
| 322 | logger.Infow(ctx, "starting-grpc-service", log.Fields{"service": serviceName}) |
| 323 | |
| 324 | probe.UpdateStatusFromContext(ctx, serviceName, probe.ServiceStatusRunning) |
| 325 | logger.Infow(ctx, "grpc-service-started", log.Fields{"service": serviceName}) |
| 326 | |
| 327 | server.Start(ctx) |
| 328 | probe.UpdateStatusFromContext(ctx, serviceName, probe.ServiceStatusStopped) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 329 | } |
| 330 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 331 | func (a *adapter) addAdapterService(ctx context.Context, server *vgrpc.GrpcServer, handler adapter_service.AdapterServiceServer) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 332 | logger.Info(ctx, "adding-adapter-service") |
| 333 | |
| 334 | server.AddService(func(gs *grpc.Server) { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 335 | adapter_service.RegisterAdapterServiceServer(gs, handler) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 336 | }) |
| 337 | } |
| 338 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 339 | func (a *adapter) addOltInterAdapterService(ctx context.Context, server *vgrpc.GrpcServer, handler olt_inter_adapter_service.OltInterAdapterServiceServer) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 340 | logger.Info(ctx, "adding-olt-inter-adapter-service") |
| 341 | |
| 342 | server.AddService(func(gs *grpc.Server) { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 343 | olt_inter_adapter_service.RegisterOltInterAdapterServiceServer(gs, handler) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 344 | }) |
| 345 | } |
| 346 | |
| 347 | func (a *adapter) startOpenOLT(ctx context.Context, cc *vgrpc.Client, ep eventif.EventProxy, |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 348 | cfg *config.AdapterFlags, cm *conf.ConfigManager) (*ac.OpenOLT, error) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 349 | logger.Info(ctx, "starting-open-olt") |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 350 | var err error |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 351 | sOLT := ac.NewOpenOLT(ctx, cc, ep, cfg, cm) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 352 | |
| 353 | if err = sOLT.Start(ctx); err != nil { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 354 | return nil, err |
| 355 | } |
| 356 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 357 | logger.Info(ctx, "open-olt-started") |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 358 | return sOLT, nil |
| 359 | } |
| 360 | |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 361 | func (a *adapter) startOpenOLTInterAdapter(ctx context.Context, oo *ac.OpenOLT) (*ac.OpenOLTInterAdapter, error) { |
| 362 | logger.Info(ctx, "starting-open-olt-inter-adapter") |
| 363 | var err error |
| 364 | sOLTInterAdapter := ac.NewOpenOLTInterAdapter(oo) |
| 365 | |
| 366 | if err = sOLTInterAdapter.Start(ctx); err != nil { |
| 367 | return nil, err |
| 368 | } |
| 369 | |
| 370 | logger.Info(ctx, "open-olt-inter-adapter-started") |
| 371 | return sOLTInterAdapter, nil |
| 372 | } |
| 373 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 374 | func (a *adapter) registerWithCore(ctx context.Context, serviceName string, retries int) error { |
Matteo Scandolo | 3ad5d2b | 2020-04-02 17:02:04 -0700 | [diff] [blame] | 375 | adapterID := fmt.Sprintf("openolt_%d", a.config.CurrentReplica) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 376 | logger.Infow(ctx, "registering-with-core", log.Fields{ |
Matteo Scandolo | 3ad5d2b | 2020-04-02 17:02:04 -0700 | [diff] [blame] | 377 | "adapterID": adapterID, |
| 378 | "currentReplica": a.config.CurrentReplica, |
| 379 | "totalReplicas": a.config.TotalReplicas, |
| 380 | }) |
| 381 | adapterDescription := &voltha.Adapter{ |
| 382 | Id: adapterID, // Unique name for the device type |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 383 | Vendor: "VOLTHA OpenOLT", |
Matteo Scandolo | 3ad5d2b | 2020-04-02 17:02:04 -0700 | [diff] [blame] | 384 | Version: version.VersionInfo.Version, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 385 | // The Endpoint refers to the address this service is listening on. |
| 386 | Endpoint: a.config.AdapterEndpoint, |
Matteo Scandolo | 3ad5d2b | 2020-04-02 17:02:04 -0700 | [diff] [blame] | 387 | Type: "openolt", |
| 388 | CurrentReplica: int32(a.config.CurrentReplica), |
| 389 | TotalReplicas: int32(a.config.TotalReplicas), |
| 390 | } |
| 391 | types := []*voltha.DeviceType{{ |
| 392 | Id: "openolt", |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 393 | AdapterType: "openolt", // Type of the adapter that handles device type |
| 394 | Adapter: "openolt", // Deprecated attribute |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 395 | AcceptsBulkFlowUpdate: false, // Currently openolt adapter does not support bulk flow handling |
| 396 | AcceptsAddRemoveFlowUpdates: true}} |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 397 | deviceTypes := &voltha.DeviceTypes{Items: types} |
| 398 | count := 0 |
| 399 | for { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 400 | gClient, err := a.coreClient.GetCoreServiceClient() |
| 401 | if gClient != nil { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 402 | if _, err = gClient.RegisterAdapter(log.WithSpanFromContext(context.TODO(), ctx), &ca.AdapterRegistration{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 403 | Adapter: adapterDescription, |
| 404 | DTypes: deviceTypes}); err == nil { |
| 405 | break |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 406 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 407 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 408 | logger.Warnw(ctx, "registering-with-core-failed", log.Fields{"endpoint": a.config.CoreEndpoint, "error": err, "count": count, "gclient": gClient}) |
| 409 | if retries == count { |
| 410 | return err |
| 411 | } |
| 412 | count++ |
| 413 | // Take a nap before retrying |
| 414 | time.Sleep(2 * time.Second) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 415 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 416 | probe.UpdateStatusFromContext(ctx, serviceName, probe.ServiceStatusRunning) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 417 | logger.Info(ctx, "registered-with-core") |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 418 | return nil |
| 419 | } |
| 420 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 421 | func waitForExit(ctx context.Context) int { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 422 | signalChannel := make(chan os.Signal, 1) |
| 423 | signal.Notify(signalChannel, |
| 424 | syscall.SIGHUP, |
| 425 | syscall.SIGINT, |
| 426 | syscall.SIGTERM, |
| 427 | syscall.SIGQUIT) |
| 428 | |
| 429 | exitChannel := make(chan int) |
| 430 | |
| 431 | go func() { |
| 432 | s := <-signalChannel |
| 433 | switch s { |
| 434 | case syscall.SIGHUP, |
| 435 | syscall.SIGINT, |
| 436 | syscall.SIGTERM, |
| 437 | syscall.SIGQUIT: |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 438 | logger.Infow(ctx, "closing-signal-received", log.Fields{"signal": s}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 439 | exitChannel <- 0 |
| 440 | default: |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 441 | logger.Infow(ctx, "unexpected-signal-received", log.Fields{"signal": s}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 442 | exitChannel <- 1 |
| 443 | } |
| 444 | }() |
| 445 | |
| 446 | code := <-exitChannel |
| 447 | return code |
| 448 | } |
| 449 | |
| 450 | func printBanner() { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 451 | fmt.Println(` ____ ____ _ _______ `) |
| 452 | fmt.Println(` / _ \ / __ \| | |__ __|`) |
| 453 | fmt.Println(` | | | |_ __ ___ _ __ | | | | | | | `) |
| 454 | fmt.Println(` | | | | '_ \ / _ \ '_ \ | | | | | | | `) |
| 455 | fmt.Println(` | |__| | |_) | __/ | | || |__| | |____| | `) |
| 456 | fmt.Println(` \____/| .__/ \___|_| |_| \____/|______|_| `) |
| 457 | fmt.Println(` | | `) |
| 458 | fmt.Println(` |_| `) |
| 459 | fmt.Println(` `) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 462 | func printVersion() { |
| 463 | fmt.Println("VOLTHA OpenOLT Adapter") |
| 464 | fmt.Println(version.VersionInfo.String(" ")) |
| 465 | } |
| 466 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 467 | func main() { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 468 | ctx := context.Background() |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 469 | start := time.Now() |
| 470 | |
| 471 | cf := config.NewAdapterFlags() |
| 472 | cf.ParseCommandArguments() |
| 473 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 474 | // Setup logging |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 475 | |
Rohan Agrawal | 02f784d | 2020-02-14 09:34:02 +0000 | [diff] [blame] | 476 | logLevel, err := log.StringToLogLevel(cf.LogLevel) |
| 477 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 478 | logger.Fatalf(ctx, "Cannot setup logging, %s", err) |
Rohan Agrawal | 02f784d | 2020-02-14 09:34:02 +0000 | [diff] [blame] | 479 | } |
Rohan Agrawal | 2488f19 | 2020-01-31 09:26:55 +0000 | [diff] [blame] | 480 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 481 | // Setup default logger - applies for packages that do not have specific logger set |
Rohan Agrawal | 02f784d | 2020-02-14 09:34:02 +0000 | [diff] [blame] | 482 | if _, err := log.SetDefaultLogger(log.JSON, logLevel, log.Fields{"instanceId": cf.InstanceID}); err != nil { |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 483 | logger.With(log.Fields{"error": err}).Fatal(ctx, "Cannot setup logging") |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | // Update all loggers (provisionned via init) with a common field |
Hardik Windlass | b9c869b | 2019-10-10 08:34:32 +0000 | [diff] [blame] | 487 | if err := log.UpdateAllLoggers(log.Fields{"instanceId": cf.InstanceID}); err != nil { |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 488 | logger.With(log.Fields{"error": err}).Fatal(ctx, "Cannot setup logging") |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Rohan Agrawal | 02f784d | 2020-02-14 09:34:02 +0000 | [diff] [blame] | 491 | log.SetAllLogLevel(logLevel) |
Rohan Agrawal | 93bced3 | 2020-02-11 10:16:01 +0000 | [diff] [blame] | 492 | |
Matteo Scandolo | 8f2b957 | 2020-02-28 15:35:23 -0800 | [diff] [blame] | 493 | realMain() |
| 494 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 495 | defer func() { |
| 496 | err := log.CleanUp() |
| 497 | if err != nil { |
| 498 | logger.Errorw(context.Background(), "unable-to-flush-any-buffered-log-entries", log.Fields{"error": err}) |
| 499 | } |
| 500 | }() |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 501 | |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 502 | // Print version / build information and exit |
| 503 | if cf.DisplayVersionOnly { |
| 504 | printVersion() |
| 505 | return |
| 506 | } |
| 507 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 508 | // Print banner if specified |
| 509 | if cf.Banner { |
| 510 | printBanner() |
| 511 | } |
| 512 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 513 | logger.Infow(ctx, "config", log.Fields{"config": *cf}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 514 | |
| 515 | ctx, cancel := context.WithCancel(context.Background()) |
| 516 | defer cancel() |
| 517 | |
| 518 | ad := newAdapter(cf) |
Rohan Agrawal | 828bf4e | 2019-10-22 10:13:19 +0000 | [diff] [blame] | 519 | |
| 520 | p := &probe.Probe{} |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 521 | go p.ListenAndServe(ctx, ad.config.ProbeAddress) |
Rohan Agrawal | 828bf4e | 2019-10-22 10:13:19 +0000 | [diff] [blame] | 522 | |
| 523 | probeCtx := context.WithValue(ctx, probe.ProbeContextKey, p) |
| 524 | |
Girish Kumar | 935f7af | 2020-08-18 11:59:42 +0000 | [diff] [blame] | 525 | closer, err := log.GetGlobalLFM().InitTracingAndLogCorrelation(cf.TraceEnabled, cf.TraceAgentAddress, cf.LogCorrelationEnabled) |
Girish Kumar | 11e1597 | 2020-06-15 14:51:10 +0000 | [diff] [blame] | 526 | if err != nil { |
| 527 | logger.Warnw(ctx, "unable-to-initialize-tracing-and-log-correlation-module", log.Fields{"error": err}) |
| 528 | } else { |
| 529 | defer log.TerminateTracing(closer) |
| 530 | } |
| 531 | |
Rohan Agrawal | 828bf4e | 2019-10-22 10:13:19 +0000 | [diff] [blame] | 532 | go ad.start(probeCtx) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 533 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 534 | code := waitForExit(ctx) |
| 535 | logger.Infow(ctx, "received-a-closing-signal", log.Fields{"code": code}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 536 | |
| 537 | // Cleanup before leaving |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 538 | ad.stop(ctx) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 539 | |
| 540 | elapsed := time.Since(start) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 541 | logger.Infow(ctx, "run-time", log.Fields{"instanceId": ad.config.InstanceID, "time": elapsed / time.Second}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 542 | } |