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/device/agent_test.go b/rw_core/core/device/agent_test.go
index 8b003b4..2abfdeb 100755
--- a/rw_core/core/device/agent_test.go
+++ b/rw_core/core/device/agent_test.go
@@ -144,23 +144,13 @@
if err = dat.kmp.Start(); err != nil {
logger.Fatal("Cannot start InterContainerProxy")
}
- if err = adapterMgr.Start(context.Background()); err != nil {
- logger.Fatal("Cannot start adapterMgr")
- }
- dat.deviceMgr.Start(context.Background())
- dat.logicalDeviceMgr.Start(context.Background())
+ adapterMgr.Start(context.Background())
}
func (dat *DATest) stopAll() {
if dat.kClient != nil {
dat.kClient.Stop()
}
- if dat.logicalDeviceMgr != nil {
- dat.logicalDeviceMgr.Stop(context.Background())
- }
- if dat.deviceMgr != nil {
- dat.deviceMgr.Stop(context.Background())
- }
if dat.kmp != nil {
dat.kmp.Stop()
}
diff --git a/rw_core/core/device/logical_agent_test.go b/rw_core/core/device/logical_agent_test.go
index 64c42b5..e562400 100644
--- a/rw_core/core/device/logical_agent_test.go
+++ b/rw_core/core/device/logical_agent_test.go
@@ -487,23 +487,13 @@
if err = lda.kmp.Start(); err != nil {
logger.Fatal("Cannot start InterContainerProxy")
}
- if err = adapterMgr.Start(context.Background()); err != nil {
- logger.Fatal("Cannot start adapterMgr")
- }
- lda.deviceMgr.Start(context.Background())
- lda.logicalDeviceMgr.Start(context.Background())
+ adapterMgr.Start(context.Background())
}
func (lda *LDATest) stopAll() {
if lda.kClient != nil {
lda.kClient.Stop()
}
- if lda.logicalDeviceMgr != nil {
- lda.logicalDeviceMgr.Stop(context.Background())
- }
- if lda.deviceMgr != nil {
- lda.deviceMgr.Stop(context.Background())
- }
if lda.kmp != nil {
lda.kmp.Stop()
}
diff --git a/rw_core/core/device/logical_manager.go b/rw_core/core/device/logical_manager.go
index a5c47b9..53c3759 100644
--- a/rw_core/core/device/logical_manager.go
+++ b/rw_core/core/device/logical_manager.go
@@ -30,7 +30,6 @@
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
"github.com/opencord/voltha-lib-go/v3/pkg/log"
- "github.com/opencord/voltha-lib-go/v3/pkg/probe"
"github.com/opencord/voltha-protos/v3/go/openflow_13"
"github.com/opencord/voltha-protos/v3/go/voltha"
"google.golang.org/grpc/codes"
@@ -44,25 +43,11 @@
deviceMgr *Manager
kafkaICProxy kafka.InterContainerProxy
clusterDataProxy *model.Proxy
- exitChannel chan int
defaultTimeout time.Duration
logicalDevicesLoadingLock sync.RWMutex
logicalDeviceLoadingInProgress map[string][]chan int
}
-func (ldMgr *LogicalManager) Start(ctx context.Context) {
- logger.Info("starting-logical-device-manager")
- probe.UpdateStatusFromContext(ctx, "logical-device-manager", probe.ServiceStatusRunning)
- logger.Info("logical-device-manager-started")
-}
-
-func (ldMgr *LogicalManager) Stop(ctx context.Context) {
- logger.Info("stopping-logical-device-manager")
- ldMgr.exitChannel <- 1
- probe.UpdateStatusFromContext(ctx, "logical-device-manager", probe.ServiceStatusStopped)
- logger.Info("logical-device-manager-stopped")
-}
-
func (ldMgr *LogicalManager) addLogicalDeviceAgentToMap(agent *LogicalAgent) {
if _, exist := ldMgr.logicalDeviceAgents.Load(agent.logicalDeviceID); !exist {
ldMgr.logicalDeviceAgents.Store(agent.logicalDeviceID, agent)
diff --git a/rw_core/core/device/manager.go b/rw_core/core/device/manager.go
index b0128a5..9990104 100755
--- a/rw_core/core/device/manager.go
+++ b/rw_core/core/device/manager.go
@@ -32,7 +32,6 @@
"github.com/opencord/voltha-go/rw_core/utils"
"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
"github.com/opencord/voltha-lib-go/v3/pkg/log"
- "github.com/opencord/voltha-lib-go/v3/pkg/probe"
"github.com/opencord/voltha-protos/v3/go/common"
ic "github.com/opencord/voltha-protos/v3/go/inter_container"
ofp "github.com/opencord/voltha-protos/v3/go/openflow_13"
@@ -53,7 +52,6 @@
stateTransitions *TransitionMap
clusterDataProxy *model.Proxy
coreInstanceID string
- exitChannel chan int
defaultTimeout time.Duration
devicesLoadingLock sync.RWMutex
deviceLoadingInProgress map[string][]chan int
@@ -61,7 +59,6 @@
func NewManagers(proxy *model.Proxy, adapterMgr *adapter.Manager, kmp kafka.InterContainerProxy, endpointMgr kafka.EndpointManager, corePairTopic, coreInstanceID string, defaultCoreTimeout time.Duration) (*Manager, *LogicalManager) {
deviceMgr := &Manager{
- exitChannel: make(chan int, 1),
rootDevices: make(map[string]bool),
kafkaICProxy: kmp,
adapterProxy: remote.NewAdapterProxy(kmp, corePairTopic, endpointMgr),
@@ -71,9 +68,10 @@
defaultTimeout: defaultCoreTimeout * time.Millisecond,
deviceLoadingInProgress: make(map[string][]chan int),
}
+ deviceMgr.stateTransitions = NewTransitionMap(deviceMgr)
+
logicalDeviceMgr := &LogicalManager{
Manager: event.NewManager(),
- exitChannel: make(chan int, 1),
deviceMgr: deviceMgr,
kafkaICProxy: kmp,
clusterDataProxy: proxy,
@@ -87,20 +85,6 @@
return deviceMgr, logicalDeviceMgr
}
-func (dMgr *Manager) Start(ctx context.Context) {
- logger.Info("starting-device-manager")
- dMgr.stateTransitions = NewTransitionMap(dMgr)
- probe.UpdateStatusFromContext(ctx, "device-manager", probe.ServiceStatusRunning)
- logger.Info("device-manager-started")
-}
-
-func (dMgr *Manager) Stop(ctx context.Context) {
- logger.Info("stopping-device-manager")
- dMgr.exitChannel <- 1
- probe.UpdateStatusFromContext(ctx, "device-manager", probe.ServiceStatusStopped)
- logger.Info("device-manager-stopped")
-}
-
func (dMgr *Manager) addDeviceAgentToMap(agent *Agent) {
if _, exist := dMgr.deviceAgents.Load(agent.deviceID); !exist {
dMgr.deviceAgents.Store(agent.deviceID, agent)