VOL-2867 - Replaced coreif interface package with smaller per-package interfaces.
Also moved state transition logic into its own package.
Also removed unused interfaces & mocks.
Change-Id: I849741853620684e6ceafe6e098a9c4f64fbdc6f
diff --git a/rw_core/core/device/manager.go b/rw_core/core/device/manager.go
index 0afddbe..3b98cf8 100755
--- a/rw_core/core/device/manager.go
+++ b/rw_core/core/device/manager.go
@@ -19,8 +19,6 @@
import (
"context"
"errors"
- "reflect"
- "runtime"
"sync"
"time"
@@ -29,6 +27,7 @@
"github.com/opencord/voltha-go/rw_core/core/adapter"
"github.com/opencord/voltha-go/rw_core/core/device/event"
"github.com/opencord/voltha-go/rw_core/core/device/remote"
+ "github.com/opencord/voltha-go/rw_core/core/device/state"
"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"
@@ -50,7 +49,7 @@
adapterMgr *adapter.Manager
logicalDeviceMgr *LogicalManager
kafkaICProxy kafka.InterContainerProxy
- stateTransitions *TransitionMap
+ stateTransitions *state.TransitionMap
dbPath *model.Path
dProxy *model.Proxy
coreInstanceID string
@@ -72,7 +71,7 @@
defaultTimeout: defaultCoreTimeout,
deviceLoadingInProgress: make(map[string][]chan int),
}
- deviceMgr.stateTransitions = NewTransitionMap(deviceMgr)
+ deviceMgr.stateTransitions = state.NewTransitionMap(deviceMgr)
logicalDeviceMgr := &LogicalManager{
Manager: event.NewManager(),
@@ -291,7 +290,7 @@
func (dMgr *Manager) stopManagingDevice(ctx context.Context, id string) {
logger.Infow(ctx, "stopManagingDevice", log.Fields{"device-id": id})
if dMgr.IsDeviceInCache(id) { // Proceed only if an agent is present for this device
- if root, _ := dMgr.IsRootDevice(id); root {
+ if device, err := dMgr.getDeviceReadOnly(ctx, id); err == nil && device.Root {
// stop managing the logical device
_ = dMgr.logicalDeviceMgr.stopManagingLogicalDeviceWithDeviceID(ctx, id)
}
@@ -434,16 +433,6 @@
return exist
}
-// IsRootDevice returns true if root device is found in the map
-func (dMgr *Manager) IsRootDevice(id string) (bool, error) {
- dMgr.lockRootDeviceMap.RLock()
- defer dMgr.lockRootDeviceMap.RUnlock()
- if exist := dMgr.rootDevices[id]; exist {
- return dMgr.rootDevices[id], nil
- }
- return false, nil
-}
-
// ListDevices retrieves the latest devices from the data model
func (dMgr *Manager) ListDevices(ctx context.Context, _ *empty.Empty) (*voltha.Devices, error) {
logger.Debug(ctx, "ListDevices")
@@ -1076,33 +1065,6 @@
return childDevice, nil
}
-func (dMgr *Manager) processTransition(ctx context.Context, device *voltha.Device, previousState *deviceState) error {
- // This will be triggered on every state update
- logger.Debugw(ctx, "state-transition", log.Fields{
- "device": device.Id,
- "prev-admin-state": previousState.Admin,
- "prev-oper-state": previousState.Operational,
- "prev-conn-state": previousState.Connection,
- "curr-admin-state": device.AdminState,
- "curr-oper-state": device.OperStatus,
- "curr-conn-state": device.ConnectStatus,
- })
- handlers := dMgr.stateTransitions.GetTransitionHandler(ctx, device, previousState)
- if handlers == nil {
- logger.Debugw(ctx, "no-op-transition", log.Fields{"device-id": device.Id})
- return nil
- }
- logger.Debugw(ctx, "handler-found", log.Fields{"num-expectedHandlers": len(handlers), "isParent": device.Root, "current-data": device, "previous-state": previousState})
- for _, handler := range handlers {
- logger.Debugw(ctx, "running-handler", log.Fields{"handler": funcName(handler)})
- if err := handler(ctx, device); err != nil {
- logger.Warnw(ctx, "handler-failed", log.Fields{"handler": funcName(handler), "error": err})
- return err
- }
- }
- return nil
-}
-
func (dMgr *Manager) packetOut(ctx context.Context, deviceID string, outPort uint32, packet *ofp.OfpPacketOut) error {
logger.Debugw(ctx, "packetOut", log.Fields{"device-id": deviceID, "outPort": outPort})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
@@ -1494,12 +1456,6 @@
return nil
}
-func funcName(f interface{}) string {
- p := reflect.ValueOf(f).Pointer()
- rf := runtime.FuncForPC(p)
- return rf.Name()
-}
-
// UpdateDeviceAttribute updates value of particular device attribute
func (dMgr *Manager) UpdateDeviceAttribute(ctx context.Context, deviceID string, attribute string, value interface{}) {
if agent, ok := dMgr.deviceAgents.Load(deviceID); ok {