Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-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 | */ |
| 16 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 17 | //Package main -> this is the entry point of the OpenOnuAdapter |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 18 | package main |
| 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "errors" |
| 23 | "fmt" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 24 | "io/ioutil" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 25 | "os" |
| 26 | "os/signal" |
Andrea Campanella | 3d7c931 | 2021-01-19 09:20:49 +0100 | [diff] [blame] | 27 | "strings" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 28 | "syscall" |
| 29 | "time" |
| 30 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 31 | "github.com/golang/protobuf/ptypes/empty" |
| 32 | conf "github.com/opencord/voltha-lib-go/v7/pkg/config" |
| 33 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 34 | "github.com/opencord/voltha-lib-go/v7/pkg/events" |
| 35 | "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif" |
| 36 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| 37 | "github.com/opencord/voltha-lib-go/v7/pkg/kafka" |
| 38 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| 39 | "github.com/opencord/voltha-lib-go/v7/pkg/probe" |
| 40 | "github.com/opencord/voltha-lib-go/v7/pkg/version" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 41 | "github.com/opencord/voltha-protos/v5/go/adapter_service" |
| 42 | "github.com/opencord/voltha-protos/v5/go/core_service" |
| 43 | "github.com/opencord/voltha-protos/v5/go/health" |
| 44 | "github.com/opencord/voltha-protos/v5/go/onu_inter_adapter_service" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 45 | "github.com/opencord/voltha-protos/v5/go/voltha" |
| 46 | "google.golang.org/grpc" |
| 47 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 48 | "github.com/opencord/voltha-protos/v5/go/core_adapter" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 49 | |
Matteo Scandolo | 761f751 | 2020-11-23 15:52:40 -0800 | [diff] [blame] | 50 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 51 | ac "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/core" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 52 | ) |
| 53 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 54 | const ( |
| 55 | clusterMessagingService = "cluster-message-service" |
| 56 | onuAdapterService = "onu-adapter-service" |
| 57 | kvService = "kv-service" |
| 58 | coreService = "core-service" |
| 59 | ) |
| 60 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 61 | type adapter struct { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 62 | //defaultAppName string |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 63 | instanceID string |
| 64 | config *config.AdapterFlags |
| 65 | kafkaClient kafka.Client |
| 66 | kvClient kvstore.Client |
| 67 | eventProxy eventif.EventProxy |
| 68 | grpcServer *vgrpc.GrpcServer |
| 69 | onuAdapter *ac.OpenONUAC |
| 70 | coreClient *vgrpc.Client |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 73 | func newAdapter(cf *config.AdapterFlags) *adapter { |
| 74 | var a adapter |
| 75 | a.instanceID = cf.InstanceID |
| 76 | a.config = cf |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 77 | return &a |
| 78 | } |
| 79 | |
| 80 | func (a *adapter) start(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 81 | logger.Info(ctx, "Starting Core Adapter components") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 82 | var err error |
| 83 | |
| 84 | var p *probe.Probe |
| 85 | if value := ctx.Value(probe.ProbeContextKey); value != nil { |
| 86 | if _, ok := value.(*probe.Probe); ok { |
| 87 | p = value.(*probe.Probe) |
| 88 | p.RegisterService( |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 89 | ctx, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 90 | clusterMessagingService, |
| 91 | kvService, |
| 92 | onuAdapterService, |
| 93 | coreService, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 94 | ) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // Setup KV Client |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 99 | logger.Debugw(ctx, "create-kv-client", log.Fields{"kvstore": a.config.KVStoreType}) |
| 100 | if err = a.setKVClient(ctx); err != nil { |
| 101 | logger.Fatalw(ctx, "error-setting-kv-client", log.Fields{"error": err}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 104 | // Setup Log Config |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 105 | cm := conf.NewConfigManager(ctx, a.kvClient, a.config.KVStoreType, a.config.KVStoreAddress, a.config.KVStoreTimeout) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 106 | go conf.StartLogLevelConfigProcessing(cm, ctx) |
| 107 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 108 | // Setup Kafka Client |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 109 | if a.kafkaClient, err = newKafkaClient(ctx, "sarama", a.config.KafkaClusterAddress); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 110 | logger.Fatalw(ctx, "Unsupported-common-client", log.Fields{"error": err}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 111 | } |
| 112 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 113 | // Start kafka communication with the broker |
| 114 | if err := kafka.StartAndWaitUntilKafkaConnectionIsUp(ctx, a.kafkaClient, a.config.HeartbeatCheckInterval, clusterMessagingService); err != nil { |
| 115 | logger.Fatal(ctx, "unable-to-connect-to-kafka") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 116 | } |
| 117 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 118 | // Wait until connection to KV store is established |
| 119 | if err := WaitUntilKvStoreConnectionIsUp(ctx, a.kvClient, a.config.KVStoreTimeout, kvService); err != nil { |
| 120 | logger.Fatal(ctx, "unable-to-connect-to-kv-store") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 123 | // Create the event proxy to post events to KAFKA |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 124 | a.eventProxy = events.NewEventProxy(events.MsgClient(a.kafkaClient), events.MsgTopic(kafka.Topic{Name: a.config.EventTopic})) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 125 | go func() { |
| 126 | if err := a.eventProxy.Start(); err != nil { |
| 127 | logger.Fatalw(ctx, "event-proxy-cannot-start", log.Fields{"error": err}) |
| 128 | } |
| 129 | }() |
| 130 | |
| 131 | // Create the Core client to handle requests to the Core. Note that the coreClient is an interface and needs to be |
| 132 | // cast to the appropriate grpc client by invoking GetCoreGrpcClient on the a.coreClient |
| 133 | if a.coreClient, err = vgrpc.NewClient(a.config.CoreEndpoint, |
| 134 | a.coreRestarted, |
| 135 | vgrpc.ActivityCheck(true)); err != nil { |
| 136 | logger.Fatal(ctx, "grpc-client-not-created") |
| 137 | } |
| 138 | // Start the core grpc client |
| 139 | go a.coreClient.Start(ctx, setAndTestCoreServiceHandler) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 140 | |
| 141 | // Create the open ONU interface adapter |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 142 | if a.onuAdapter, err = a.startVolthaInterfaceAdapter(ctx, a.coreClient, a.eventProxy, a.config, cm); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 143 | logger.Fatalw(ctx, "error-starting-volthaInterfaceAdapter for OpenOnt", log.Fields{"error": err}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 144 | } |
| 145 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 146 | // Create and start the grpc server |
| 147 | a.grpcServer = vgrpc.NewGrpcServer(a.config.GrpcAddress, nil, false, p) |
| 148 | |
| 149 | //Register the adapter service |
| 150 | a.addAdapterService(ctx, a.grpcServer, a.onuAdapter) |
| 151 | |
| 152 | //Register the onu inter adapter service |
| 153 | a.addOnuInterAdapterService(ctx, a.grpcServer, a.onuAdapter) |
| 154 | |
| 155 | go a.startGRPCService(ctx, a.grpcServer, onuAdapterService) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 156 | |
| 157 | // Register this adapter to the Core - retries indefinitely |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 158 | if err = a.registerWithCore(ctx, coreService, -1); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 159 | logger.Fatalw(ctx, "error-registering-with-core", log.Fields{"error": err}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 160 | } |
| 161 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 162 | // Start the readiness and liveliness check and update the probe status |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 163 | a.checkServicesReadiness(ctx) |
| 164 | return err |
| 165 | } |
| 166 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 167 | // TODO: Any action the adapter needs to do following a Core restart? |
| 168 | func (a *adapter) coreRestarted(ctx context.Context, endPoint string) error { |
| 169 | logger.Errorw(ctx, "core-restarted", log.Fields{"endpoint": endPoint}) |
| 170 | return nil |
| 171 | } |
| 172 | |
| 173 | // setAndTestCoreServiceHandler is used to test whether the remote gRPC service is up |
| 174 | func setAndTestCoreServiceHandler(ctx context.Context, conn *grpc.ClientConn) interface{} { |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 175 | svc := core_service.NewCoreServiceClient(conn) |
| 176 | if h, err := svc.GetHealthStatus(ctx, &empty.Empty{}); err != nil || h.State != health.HealthStatus_HEALTHY { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 177 | return nil |
| 178 | } |
| 179 | return svc |
| 180 | } |
| 181 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 182 | func (a *adapter) stop(ctx context.Context) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 183 | // Cleanup - applies only if we had a kvClient |
| 184 | if a.kvClient != nil { |
| 185 | // Release all reservations |
| 186 | if err := a.kvClient.ReleaseAllReservations(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 187 | logger.Infow(ctx, "fail-to-release-all-reservations", log.Fields{"error": err}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 188 | } |
| 189 | // Close the DB connection |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 190 | a.kvClient.Close(ctx) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 191 | } |
| 192 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 193 | if a.eventProxy != nil { |
| 194 | a.eventProxy.Stop() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 195 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 196 | |
| 197 | if a.kafkaClient != nil { |
| 198 | a.kafkaClient.Stop(ctx) |
| 199 | } |
| 200 | |
| 201 | // Stop core client |
| 202 | if a.coreClient != nil { |
| 203 | a.coreClient.Stop(ctx) |
| 204 | } |
| 205 | |
| 206 | // TODO: More cleanup |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | // ############################################# |
| 210 | // Adapter Utility methods ##### begin ######### |
| 211 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 212 | func newKVClient(ctx context.Context, storeType, address string, timeout time.Duration) (kvstore.Client, error) { |
| 213 | logger.Infow(ctx, "kv-store-type", log.Fields{"store": storeType}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 214 | switch storeType { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 215 | case "etcd": |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 216 | return kvstore.NewEtcdClient(ctx, address, timeout, log.FatalLevel) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 217 | } |
| 218 | return nil, errors.New("unsupported-kv-store") |
| 219 | } |
| 220 | |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 221 | func newKafkaClient(ctx context.Context, clientType, addr string) (kafka.Client, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 222 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 223 | logger.Infow(ctx, "common-client-type", log.Fields{"client": clientType}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 224 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 225 | switch clientType { |
| 226 | case "sarama": |
| 227 | return kafka.NewSaramaClient( |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 228 | kafka.Address(addr), |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 229 | kafka.ProducerReturnOnErrors(true), |
| 230 | kafka.ProducerReturnOnSuccess(true), |
| 231 | kafka.ProducerMaxRetries(6), |
| 232 | kafka.ProducerRetryBackoff(time.Millisecond*30), |
| 233 | kafka.MetadatMaxRetries(15)), nil |
| 234 | } |
| 235 | |
| 236 | return nil, errors.New("unsupported-client-type") |
| 237 | } |
| 238 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 239 | func (a *adapter) setKVClient(ctx context.Context) error { |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 240 | client, err := newKVClient(ctx, a.config.KVStoreType, a.config.KVStoreAddress, a.config.KVStoreTimeout) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 241 | if err != nil { |
| 242 | a.kvClient = nil |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 243 | logger.Errorw(ctx, "error-starting-KVClient", log.Fields{"error": err}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 244 | return err |
| 245 | } |
| 246 | a.kvClient = client |
| 247 | return nil |
| 248 | } |
| 249 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 250 | func (a *adapter) startVolthaInterfaceAdapter(ctx context.Context, cc *vgrpc.Client, ep eventif.EventProxy, |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 251 | cfg *config.AdapterFlags, cm *conf.ConfigManager) (*ac.OpenONUAC, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 252 | var err error |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 253 | sAcONU := ac.NewOpenONUAC(ctx, cc, ep, a.kvClient, cfg, cm) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 254 | |
| 255 | if err = sAcONU.Start(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 256 | logger.Fatalw(ctx, "error-starting-OpenOnuAdapterCore", log.Fields{"error": err}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 257 | return nil, err |
| 258 | } |
| 259 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 260 | logger.Info(ctx, "open-ont-OpenOnuAdapterCore-started") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 261 | return sAcONU, nil |
| 262 | } |
| 263 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 264 | func (a *adapter) registerWithCore(ctx context.Context, serviceName string, retries int) error { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 265 | adapterID := fmt.Sprintf("brcm_openomci_onu_%d", a.config.CurrentReplica) |
Andrea Campanella | 3d7c931 | 2021-01-19 09:20:49 +0100 | [diff] [blame] | 266 | vendorIdsList := strings.Split(a.config.OnuVendorIds, ",") |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 267 | logger.Infow(ctx, "registering-with-core", log.Fields{ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 268 | "adapterID": adapterID, |
| 269 | "currentReplica": a.config.CurrentReplica, |
| 270 | "totalReplicas": a.config.TotalReplicas, |
Andrea Campanella | 3d7c931 | 2021-01-19 09:20:49 +0100 | [diff] [blame] | 271 | "onuVendorIds": vendorIdsList, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 272 | }) |
Matteo Scandolo | 2e6f1e3 | 2020-04-15 11:28:45 -0700 | [diff] [blame] | 273 | adapterDescription := &voltha.Adapter{ |
Andrea Campanella | 961734c | 2021-01-18 11:44:47 +0100 | [diff] [blame] | 274 | Id: adapterID, // Unique name for the device type ->exact type required for OLT comm???? |
| 275 | Vendor: "VOLTHA OpenONUGo", |
| 276 | Version: version.VersionInfo.Version, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 277 | Endpoint: a.config.AdapterEndpoint, |
Matteo Scandolo | 2e6f1e3 | 2020-04-15 11:28:45 -0700 | [diff] [blame] | 278 | Type: "brcm_openomci_onu", |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 279 | CurrentReplica: int32(a.config.CurrentReplica), |
| 280 | TotalReplicas: int32(a.config.TotalReplicas), |
Matteo Scandolo | 2e6f1e3 | 2020-04-15 11:28:45 -0700 | [diff] [blame] | 281 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 282 | types := []*voltha.DeviceType{{Id: "brcm_openomci_onu", |
Andrea Campanella | 3d7c931 | 2021-01-19 09:20:49 +0100 | [diff] [blame] | 283 | VendorIds: vendorIdsList, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 284 | AdapterType: "brcm_openomci_onu", // Type of adapter that handles this device type |
| 285 | Adapter: "brcm_openomci_onu", // Deprecated attribute |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 286 | AcceptsBulkFlowUpdate: false, // Currently openolt adapter does not support bulk flow handling |
| 287 | AcceptsAddRemoveFlowUpdates: true}} |
| 288 | deviceTypes := &voltha.DeviceTypes{Items: types} |
| 289 | count := 0 |
| 290 | for { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 291 | gClient, err := a.coreClient.GetCoreServiceClient() |
| 292 | if gClient != nil { |
| 293 | if gClient != nil { |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 294 | if _, err = gClient.RegisterAdapter(log.WithSpanFromContext(context.TODO(), ctx), &core_adapter.AdapterRegistration{ |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 295 | Adapter: adapterDescription, |
| 296 | DTypes: deviceTypes}); err == nil { |
| 297 | break |
| 298 | } |
| 299 | } |
| 300 | logger.Warnw(ctx, "registering-with-core-failed", log.Fields{"endpoint": a.config.CoreEndpoint, "error": err, "count": count, "gclient": gClient}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 301 | if retries == count { |
| 302 | return err |
| 303 | } |
| 304 | count++ |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 305 | // Take a power nap before retrying |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 306 | time.Sleep(2 * time.Second) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 307 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 308 | } |
| 309 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 310 | probe.UpdateStatusFromContext(ctx, serviceName, probe.ServiceStatusRunning) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 311 | logger.Info(ctx, "registered-with-core") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 312 | return nil |
| 313 | } |
| 314 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 315 | // startGRPCService creates the grpc service handlers, registers it to the grpc server and starts the server |
| 316 | func (a *adapter) startGRPCService(ctx context.Context, server *vgrpc.GrpcServer, serviceName string) { |
| 317 | logger.Infow(ctx, "service-created", log.Fields{"service": serviceName}) |
| 318 | |
| 319 | probe.UpdateStatusFromContext(ctx, serviceName, probe.ServiceStatusRunning) |
| 320 | logger.Infow(ctx, "service-started", log.Fields{"service": serviceName}) |
| 321 | |
| 322 | server.Start(ctx) |
| 323 | probe.UpdateStatusFromContext(ctx, serviceName, probe.ServiceStatusStopped) |
| 324 | } |
| 325 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 326 | func (a *adapter) addAdapterService(ctx context.Context, server *vgrpc.GrpcServer, handler adapter_service.AdapterServiceServer) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 327 | logger.Info(ctx, "adding-adapter-service") |
| 328 | |
| 329 | server.AddService(func(gs *grpc.Server) { |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 330 | adapter_service.RegisterAdapterServiceServer(gs, handler) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 331 | }) |
| 332 | } |
| 333 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 334 | func (a *adapter) addOnuInterAdapterService(ctx context.Context, server *vgrpc.GrpcServer, handler onu_inter_adapter_service.OnuInterAdapterServiceServer) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 335 | logger.Info(ctx, "adding-onu-inter-adapter-service") |
| 336 | |
| 337 | server.AddService(func(gs *grpc.Server) { |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 338 | onu_inter_adapter_service.RegisterOnuInterAdapterServiceServer(gs, handler) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 339 | }) |
| 340 | } |
| 341 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 342 | /** |
| 343 | This function checks the liveliness and readiness of the kakfa and kv-client services |
| 344 | and update the status in the probe. |
| 345 | */ |
| 346 | func (a *adapter) checkServicesReadiness(ctx context.Context) { |
| 347 | // checks the kafka readiness |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 348 | go kafka.MonitorKafkaReadiness(ctx, a.kafkaClient, a.config.LiveProbeInterval, a.config.NotLiveProbeInterval, clusterMessagingService) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 349 | |
| 350 | // checks the kv-store readiness |
| 351 | go a.checkKvStoreReadiness(ctx) |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | This function checks the liveliness and readiness of the kv-store service |
| 356 | and update the status in the probe. |
| 357 | */ |
| 358 | func (a *adapter) checkKvStoreReadiness(ctx context.Context) { |
| 359 | // dividing the live probe interval by 2 to get updated status every 30s |
| 360 | timeout := a.config.LiveProbeInterval / 2 |
| 361 | kvStoreChannel := make(chan bool, 1) |
| 362 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 363 | // Default true - we are here only after we already had a KV store connection |
| 364 | kvStoreChannel <- true |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 365 | for { |
| 366 | timeoutTimer := time.NewTimer(timeout) |
| 367 | select { |
| 368 | case liveliness := <-kvStoreChannel: |
| 369 | if !liveliness { |
| 370 | // kv-store not reachable or down, updating the status to not ready state |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 371 | probe.UpdateStatusFromContext(ctx, kvService, probe.ServiceStatusNotReady) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 372 | timeout = a.config.NotLiveProbeInterval |
| 373 | } else { |
| 374 | // kv-store is reachable , updating the status to running state |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 375 | probe.UpdateStatusFromContext(ctx, kvService, probe.ServiceStatusRunning) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 376 | timeout = a.config.LiveProbeInterval / 2 |
| 377 | } |
| 378 | // Check if the timer has expired or not |
| 379 | if !timeoutTimer.Stop() { |
| 380 | <-timeoutTimer.C |
| 381 | } |
| 382 | case <-timeoutTimer.C: |
| 383 | // Check the status of the kv-store |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 384 | logger.Info(ctx, "kv-store liveliness-recheck") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 385 | if a.kvClient.IsConnectionUp(ctx) { |
| 386 | kvStoreChannel <- true |
| 387 | } else { |
| 388 | kvStoreChannel <- false |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 394 | // WaitUntilKvStoreConnectionIsUp waits until the KV client can establish a connection to the KV server or until the |
| 395 | // context times out. |
| 396 | func WaitUntilKvStoreConnectionIsUp(ctx context.Context, kvClient kvstore.Client, connectionRetryInterval time.Duration, serviceName string) error { |
| 397 | if kvClient == nil { |
| 398 | return errors.New("kvclient-is-nil") |
| 399 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 400 | for { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 401 | if !kvClient.IsConnectionUp(ctx) { |
| 402 | probe.UpdateStatusFromContext(ctx, serviceName, probe.ServiceStatusNotReady) |
| 403 | logger.Warnw(ctx, "kvconnection-down", log.Fields{"service-name": serviceName, "connect-retry-interval": connectionRetryInterval}) |
| 404 | select { |
| 405 | case <-time.After(connectionRetryInterval): |
| 406 | continue |
| 407 | case <-ctx.Done(): |
| 408 | return ctx.Err() |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 409 | } |
| 410 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 411 | probe.UpdateStatusFromContext(ctx, serviceName, probe.ServiceStatusRunning) |
| 412 | logger.Info(ctx, "kv-connection-up") |
| 413 | break |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 414 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 415 | return nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | // Adapter Utility methods ##### end ######### |
| 419 | // ############################################# |
| 420 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 421 | func getVerifiedCodeVersion(ctx context.Context) string { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 422 | if version.VersionInfo.Version == "unknown-version" { |
| 423 | content, err := ioutil.ReadFile("VERSION") |
| 424 | if err == nil { |
Andrea Campanella | 3d7c931 | 2021-01-19 09:20:49 +0100 | [diff] [blame] | 425 | return string(content) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 426 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 427 | logger.Error(ctx, "'VERSION'-file not readable") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 428 | } |
| 429 | return version.VersionInfo.Version |
| 430 | } |
| 431 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 432 | func printVersion(appName string) { |
| 433 | fmt.Println(appName) |
| 434 | fmt.Println(version.VersionInfo.String(" ")) |
| 435 | } |
| 436 | |
| 437 | func printBanner() { |
| 438 | fmt.Println(" ____ ____ ___ ___ _ ") |
| 439 | fmt.Println(" / __ \\ / __ \\| \\ \\ | | | | |") |
| 440 | fmt.Println(" | | | |_ __ ___ _ __ | | | | |\\ \\ | | | | | ____ ____") |
| 441 | fmt.Println(" | | | | '_ \\ / _ \\ '_ \\ | | | | | \\ \\ | | | | | / '_ \\ / _' \\") |
| 442 | fmt.Println(" | |__| | |_) | __/| | | || |__| | | \\ \\| | \\__/ || (__) | (__) |") |
| 443 | fmt.Println(" \\___ /| .__/ \\___|_| |_| \\____/|_| \\___|______| \\.___ |\\___./") |
| 444 | fmt.Println(" | | __| |") |
| 445 | fmt.Println(" |_| |____/") |
| 446 | fmt.Println(" ") |
| 447 | } |
| 448 | |
| 449 | func waitForExit(ctx context.Context) int { |
| 450 | signalChannel := make(chan os.Signal, 1) |
| 451 | signal.Notify(signalChannel, |
| 452 | syscall.SIGHUP, |
| 453 | syscall.SIGINT, |
| 454 | syscall.SIGTERM, |
| 455 | syscall.SIGQUIT) |
| 456 | |
| 457 | exitChannel := make(chan int) |
| 458 | |
| 459 | go func() { |
| 460 | select { |
| 461 | case <-ctx.Done(): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 462 | logger.Infow(ctx, "Adapter run aborted due to internal errors", log.Fields{"context": "done"}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 463 | exitChannel <- 2 |
| 464 | case s := <-signalChannel: |
| 465 | switch s { |
| 466 | case syscall.SIGHUP, |
| 467 | syscall.SIGINT, |
| 468 | syscall.SIGTERM, |
| 469 | syscall.SIGQUIT: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 470 | logger.Infow(ctx, "closing-signal-received", log.Fields{"signal": s}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 471 | exitChannel <- 0 |
| 472 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 473 | logger.Infow(ctx, "unexpected-signal-received", log.Fields{"signal": s}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 474 | exitChannel <- 1 |
| 475 | } |
| 476 | } |
| 477 | }() |
| 478 | |
| 479 | code := <-exitChannel |
| 480 | return code |
| 481 | } |
| 482 | |
| 483 | func main() { |
| 484 | start := time.Now() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 485 | ctx, cancel := context.WithCancel(context.Background()) |
| 486 | defer cancel() |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 487 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 488 | cf := &config.AdapterFlags{} |
| 489 | cf.ParseCommandArguments(os.Args[1:]) |
| 490 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 491 | defaultAppName := cf.InstanceID + "_" + getVerifiedCodeVersion(ctx) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 492 | |
| 493 | // Setup logging |
| 494 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 495 | logLevel, err := log.StringToLogLevel(cf.LogLevel) |
Matteo Scandolo | 2e6f1e3 | 2020-04-15 11:28:45 -0700 | [diff] [blame] | 496 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 497 | logger.Fatalf(ctx, "Cannot setup logging, %s", err) |
Matteo Scandolo | 2e6f1e3 | 2020-04-15 11:28:45 -0700 | [diff] [blame] | 498 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 499 | |
| 500 | // Setup default logger - applies for packages that do not have specific logger set |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 501 | if _, err := log.SetDefaultLogger(log.JSON, logLevel, log.Fields{"instanceId": cf.InstanceID}); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 502 | logger.With(log.Fields{"error": err}).Fatal(ctx, "Cannot setup logging") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 505 | // Update all loggers (provisioned via init) with a common field |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 506 | if err := log.UpdateAllLoggers(log.Fields{"instanceId": cf.InstanceID}); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 507 | logger.With(log.Fields{"error": err}).Fatal(ctx, "Cannot setup logging") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 510 | log.SetAllLogLevel(logLevel) |
| 511 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 512 | realMain(ctx) //fatal on httpListen(0,6060) ... |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 513 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 514 | defer func() { |
| 515 | _ = log.CleanUp() |
| 516 | }() |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 517 | // Print version / build information and exit |
| 518 | if cf.DisplayVersionOnly { |
| 519 | printVersion(defaultAppName) |
| 520 | return |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 521 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 522 | logger.Infow(ctx, "config", log.Fields{"StartName": defaultAppName}) |
| 523 | logger.Infow(ctx, "config", log.Fields{"BuildVersion": version.VersionInfo.String(" ")}) |
| 524 | logger.Infow(ctx, "config", log.Fields{"Arguments": os.Args[1:]}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 525 | |
| 526 | // Print banner if specified |
| 527 | if cf.Banner { |
| 528 | printBanner() |
| 529 | } |
| 530 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 531 | logger.Infow(ctx, "config", log.Fields{"config": *cf}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 532 | |
| 533 | ad := newAdapter(cf) |
| 534 | |
| 535 | p := &probe.Probe{} |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 536 | logger.Infow(ctx, "resources", log.Fields{"Context": ctx, "Adapter": ad.instanceID, "ProbeCoreState": p.GetStatus("register-with-core")}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 537 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 538 | go p.ListenAndServe(ctx, fmt.Sprintf("%s:%d", ad.config.ProbeHost, ad.config.ProbePort)) |
| 539 | logger.Infow(ctx, "probeState", log.Fields{"ProbeCoreState": p.GetStatus("register-with-core")}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 540 | |
| 541 | probeCtx := context.WithValue(ctx, probe.ProbeContextKey, p) |
| 542 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 543 | closer, err := log.GetGlobalLFM().InitTracingAndLogCorrelation(cf.TraceEnabled, cf.TraceAgentAddress, cf.LogCorrelationEnabled) |
| 544 | if err != nil { |
| 545 | logger.Warnw(ctx, "unable-to-initialize-tracing-and-log-correlation-module", log.Fields{"error": err}) |
| 546 | } else { |
| 547 | defer log.TerminateTracing(closer) |
| 548 | } |
| 549 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 550 | go func() { |
| 551 | err := ad.start(probeCtx) |
| 552 | // If this operation returns an error |
| 553 | // cancel all operations using this context |
| 554 | if err != nil { |
| 555 | cancel() |
| 556 | } |
| 557 | }() |
| 558 | |
| 559 | code := waitForExit(ctx) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 560 | logger.Infow(ctx, "received-a-closing-signal", log.Fields{"code": code}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 561 | |
khenaidoo | 1fd58e0 | 2021-10-13 11:51:20 -0400 | [diff] [blame] | 562 | // Set the ONU adapter GRPC service as not ready. This will prevent any request from coming to this adapter instance |
| 563 | probe.UpdateStatusFromContext(probeCtx, onuAdapterService, probe.ServiceStatusStopped) |
| 564 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 565 | // Cleanup before leaving |
| 566 | ad.stop(ctx) |
| 567 | |
| 568 | elapsed := time.Since(start) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 569 | logger.Infow(ctx, "run-time", log.Fields{"Name": "openadapter", "time": elapsed / time.Microsecond}) |
| 570 | //logger.Infow(ctx,"run-time", log.Fields{"instanceId": ad.config.InstanceID, "time": elapsed / time.Second}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 571 | } |