VOL-2970 - Improved readability & traceability of startup code.
Changed Start() function to implement majority of the startup functionality, with less helpers. Start() also defines local variables for each component created, to avoid accidentally using a component that isn't ready.
Also merged the rwCore into the Core.
Also changed Core to cancel a local context to on shutdown, and then wait for shutdown to complete.
Change-Id: I285e8486773476531e20ec352ff85a1b145432bf
diff --git a/rw_core/core/adapter/manager.go b/rw_core/core/adapter/manager.go
index 11752e1..b552d8f 100644
--- a/rw_core/core/adapter/manager.go
+++ b/rw_core/core/adapter/manager.go
@@ -40,14 +40,12 @@
clusterDataProxy *model.Proxy
onAdapterRestart adapterRestartedHandler
coreInstanceID string
- exitChannel chan int
lockAdaptersMap sync.RWMutex
lockdDeviceTypeToAdapterMap sync.RWMutex
}
func NewAdapterManager(cdProxy *model.Proxy, coreInstanceID string, kafkaClient kafka.Client) *Manager {
aMgr := &Manager{
- exitChannel: make(chan int, 1),
coreInstanceID: coreInstanceID,
clusterDataProxy: cdProxy,
deviceTypes: make(map[string]*voltha.DeviceType),
@@ -65,20 +63,19 @@
aMgr.onAdapterRestart = onAdapterRestart
}
-func (aMgr *Manager) Start(ctx context.Context) error {
+func (aMgr *Manager) Start(ctx context.Context) {
+ probe.UpdateStatusFromContext(ctx, "adapter-manager", probe.ServiceStatusPreparing)
logger.Info("starting-adapter-manager")
// Load the existing adapterAgents and device types - this will also ensure the correct paths have been
// created if there are no data in the dB to start
err := aMgr.loadAdaptersAndDevicetypesInMemory()
if err != nil {
- logger.Errorw("Failed-to-load-adapters-and-device-types-in-memeory", log.Fields{"error": err})
- return err
+ logger.Fatalf("failed-to-load-adapters-and-device-types-in-memory: %s", err)
}
probe.UpdateStatusFromContext(ctx, "adapter-manager", probe.ServiceStatusRunning)
logger.Info("adapter-manager-started")
- return nil
}
//loadAdaptersAndDevicetypesInMemory loads the existing set of adapters and device types in memory