[VOL-3187]Pass Context down the execution call hierarchy across voltha-go codebase
Change-Id: I6bc2a0f7226c1beed4ae01a15d7b5c4dc04358d8
diff --git a/rw_core/core/device/manager.go b/rw_core/core/device/manager.go
index 92b7f20..015c8a3 100755
--- a/rw_core/core/device/manager.go
+++ b/rw_core/core/device/manager.go
@@ -123,7 +123,7 @@
return agent.(*Agent)
}
//TODO: Change the return params to return an error as well
- logger.Errorw("loading-device-failed", log.Fields{"deviceId": deviceID, "error": err})
+ logger.Errorw(ctx, "loading-device-failed", log.Fields{"deviceId": deviceID, "error": err})
return nil
}
@@ -142,21 +142,21 @@
// CreateDevice creates a new parent device in the data model
func (dMgr *Manager) CreateDevice(ctx context.Context, device *voltha.Device) (*voltha.Device, error) {
if device.MacAddress == "" && device.GetHostAndPort() == "" {
- logger.Errorf("No Device Info Present")
+ logger.Errorf(ctx, "No Device Info Present")
return &voltha.Device{}, errors.New("no-device-info-present; MAC or HOSTIP&PORT")
}
- logger.Debugw("create-device", log.Fields{"device": *device})
+ logger.Debugw(ctx, "create-device", log.Fields{"device": *device})
deviceExist, err := dMgr.isParentDeviceExist(ctx, device)
if err != nil {
- logger.Errorf("Failed to fetch parent device info")
+ logger.Errorf(ctx, "Failed to fetch parent device info")
return nil, err
}
if deviceExist {
- logger.Errorf("Device is Pre-provisioned already with same IP-Port or MAC Address")
+ logger.Errorf(ctx, "Device is Pre-provisioned already with same IP-Port or MAC Address")
return nil, errors.New("device is already pre-provisioned")
}
- logger.Debugw("CreateDevice", log.Fields{"device": device, "aproxy": dMgr.adapterProxy})
+ logger.Debugw(ctx, "CreateDevice", log.Fields{"device": device, "aproxy": dMgr.adapterProxy})
// Ensure this device is set as root
device.Root = true
@@ -164,7 +164,7 @@
agent := newAgent(dMgr.adapterProxy, device, dMgr, dMgr.dbPath, dMgr.dProxy, dMgr.defaultTimeout)
device, err = agent.start(ctx, device)
if err != nil {
- logger.Errorw("Fail-to-start-device", log.Fields{"device-id": agent.deviceID, "error": err})
+ logger.Errorw(ctx, "Fail-to-start-device", log.Fields{"device-id": agent.deviceID, "error": err})
return nil, err
}
dMgr.addDeviceAgentToMap(agent)
@@ -173,7 +173,7 @@
// EnableDevice activates a device by invoking the adopt_device API on the appropriate adapter
func (dMgr *Manager) EnableDevice(ctx context.Context, id *voltha.ID) (*empty.Empty, error) {
- logger.Debugw("EnableDevice", log.Fields{"device-id": id.Id})
+ logger.Debugw(ctx, "EnableDevice", log.Fields{"device-id": id.Id})
agent := dMgr.getDeviceAgent(ctx, id.Id)
if agent == nil {
return nil, status.Errorf(codes.NotFound, "%s", id.Id)
@@ -183,7 +183,7 @@
// DisableDevice disables a device along with any child device it may have
func (dMgr *Manager) DisableDevice(ctx context.Context, id *voltha.ID) (*empty.Empty, error) {
- logger.Debugw("DisableDevice", log.Fields{"device-id": id.Id})
+ logger.Debugw(ctx, "DisableDevice", log.Fields{"device-id": id.Id})
agent := dMgr.getDeviceAgent(ctx, id.Id)
if agent == nil {
return nil, status.Errorf(codes.NotFound, "%s", id.Id)
@@ -193,7 +193,7 @@
//RebootDevice invoked the reboot API to the corresponding adapter
func (dMgr *Manager) RebootDevice(ctx context.Context, id *voltha.ID) (*empty.Empty, error) {
- logger.Debugw("RebootDevice", log.Fields{"device-id": id.Id})
+ logger.Debugw(ctx, "RebootDevice", log.Fields{"device-id": id.Id})
agent := dMgr.getDeviceAgent(ctx, id.Id)
if agent == nil {
return nil, status.Errorf(codes.NotFound, "%s", id.Id)
@@ -203,7 +203,7 @@
// DeleteDevice removes a device from the data model
func (dMgr *Manager) DeleteDevice(ctx context.Context, id *voltha.ID) (*empty.Empty, error) {
- logger.Debugw("DeleteDevice", log.Fields{"device-id": id.Id})
+ logger.Debugw(ctx, "DeleteDevice", log.Fields{"device-id": id.Id})
agent := dMgr.getDeviceAgent(ctx, id.Id)
if agent == nil {
return nil, status.Errorf(codes.NotFound, "%s", id.Id)
@@ -213,7 +213,7 @@
// ListDevicePorts returns the ports details for a specific device entry
func (dMgr *Manager) ListDevicePorts(ctx context.Context, id *voltha.ID) (*voltha.Ports, error) {
- logger.Debugw("ListDevicePorts", log.Fields{"device-id": id.Id})
+ logger.Debugw(ctx, "ListDevicePorts", log.Fields{"device-id": id.Id})
device, err := dMgr.getDevice(ctx, id.Id)
if err != nil {
return &voltha.Ports{}, err
@@ -223,7 +223,7 @@
// ListDeviceFlows returns the flow details for a specific device entry
func (dMgr *Manager) ListDeviceFlows(ctx context.Context, id *voltha.ID) (*ofp.Flows, error) {
- logger.Debugw("ListDeviceFlows", log.Fields{"device-id": id.Id})
+ logger.Debugw(ctx, "ListDeviceFlows", log.Fields{"device-id": id.Id})
agent := dMgr.getDeviceAgent(ctx, id.Id)
if agent == nil {
return &ofp.Flows{}, status.Errorf(codes.NotFound, "device-%s", id.Id)
@@ -240,7 +240,7 @@
// ListDeviceFlowGroups returns the flow group details for a specific device entry
func (dMgr *Manager) ListDeviceFlowGroups(ctx context.Context, id *voltha.ID) (*voltha.FlowGroups, error) {
- logger.Debugw("ListDeviceFlowGroups", log.Fields{"device-id": id.Id})
+ logger.Debugw(ctx, "ListDeviceFlowGroups", log.Fields{"device-id": id.Id})
agent := dMgr.getDeviceAgent(ctx, id.Id)
if agent == nil {
return nil, status.Errorf(codes.NotFound, "device-%s", id.Id)
@@ -258,7 +258,7 @@
// This function is called only in the Core that does not own this device. In the Core that owns this device then a
// deletion deletion also includes removal of any reference of this device.
func (dMgr *Manager) stopManagingDevice(ctx context.Context, id string) {
- logger.Infow("stopManagingDevice", log.Fields{"deviceId": id})
+ logger.Infow(ctx, "stopManagingDevice", log.Fields{"deviceId": id})
if dMgr.IsDeviceInCache(id) { // Proceed only if an agent is present for this device
if root, _ := dMgr.IsRootDevice(id); root {
// stop managing the logical device
@@ -266,7 +266,7 @@
}
if agent := dMgr.getDeviceAgent(ctx, id); agent != nil {
if err := agent.stop(ctx); err != nil {
- logger.Warnw("unable-to-stop-device-agent", log.Fields{"device-id": agent.deviceID, "error": err})
+ logger.Warnw(ctx, "unable-to-stop-device-agent", log.Fields{"device-id": agent.deviceID, "error": err})
}
dMgr.deleteDeviceAgentFromMap(agent)
}
@@ -275,7 +275,7 @@
// RunPostDeviceDelete removes any reference of this device
func (dMgr *Manager) RunPostDeviceDelete(ctx context.Context, cDevice *voltha.Device) error {
- logger.Infow("RunPostDeviceDelete", log.Fields{"deviceId": cDevice.Id})
+ logger.Infow(ctx, "RunPostDeviceDelete", log.Fields{"deviceId": cDevice.Id})
dMgr.stopManagingDevice(ctx, cDevice.Id)
return nil
}
@@ -286,7 +286,7 @@
// getDevice will returns a device, either from memory or from the dB, if present
func (dMgr *Manager) getDevice(ctx context.Context, id string) (*voltha.Device, error) {
- logger.Debugw("getDevice", log.Fields{"deviceid": id})
+ logger.Debugw(ctx, "getDevice", log.Fields{"deviceid": id})
if agent := dMgr.getDeviceAgent(ctx, id); agent != nil {
return agent.getDevice(ctx)
}
@@ -295,7 +295,7 @@
// GetChildDevice will return a device, either from memory or from the dB, if present
func (dMgr *Manager) GetChildDevice(ctx context.Context, parentDeviceID string, serialNumber string, onuID int64, parentPortNo int64) (*voltha.Device, error) {
- logger.Debugw("GetChildDevice", log.Fields{"parentDeviceid": parentDeviceID, "serialNumber": serialNumber,
+ logger.Debugw(ctx, "GetChildDevice", log.Fields{"parentDeviceid": parentDeviceID, "serialNumber": serialNumber,
"parentPortNo": parentPortNo, "onuId": onuID})
var parentDevice *voltha.Device
@@ -304,11 +304,11 @@
return nil, status.Errorf(codes.Aborted, "%s", err.Error())
}
var childDeviceIds []string
- if childDeviceIds, err = dMgr.getAllChildDeviceIds(parentDevice); err != nil {
+ if childDeviceIds, err = dMgr.getAllChildDeviceIds(ctx, parentDevice); err != nil {
return nil, status.Errorf(codes.Aborted, "%s", err.Error())
}
if len(childDeviceIds) == 0 {
- logger.Debugw("no-child-devices", log.Fields{"parentDeviceId": parentDevice.Id, "serialNumber": serialNumber, "onuId": onuID})
+ logger.Debugw(ctx, "no-child-devices", log.Fields{"parentDeviceId": parentDevice.Id, "serialNumber": serialNumber, "onuId": onuID})
return nil, status.Errorf(codes.NotFound, "%s", parentDeviceID)
}
@@ -320,14 +320,14 @@
foundOnuID := false
if searchDevice.ProxyAddress.OnuId == uint32(onuID) {
if searchDevice.ParentPortNo == uint32(parentPortNo) {
- logger.Debugw("found-child-by-onuid", log.Fields{"parentDeviceId": parentDevice.Id, "onuId": onuID})
+ logger.Debugw(ctx, "found-child-by-onuid", log.Fields{"parentDeviceId": parentDevice.Id, "onuId": onuID})
foundOnuID = true
}
}
foundSerialNumber := false
if searchDevice.SerialNumber == serialNumber {
- logger.Debugw("found-child-by-serialnumber", log.Fields{"parentDeviceId": parentDevice.Id, "serialNumber": serialNumber})
+ logger.Debugw(ctx, "found-child-by-serialnumber", log.Fields{"parentDeviceId": parentDevice.Id, "serialNumber": serialNumber})
foundSerialNumber = true
}
@@ -347,18 +347,18 @@
}
if foundChildDevice != nil {
- logger.Debugw("child-device-found", log.Fields{"parentDeviceId": parentDevice.Id, "foundChildDevice": foundChildDevice})
+ logger.Debugw(ctx, "child-device-found", log.Fields{"parentDeviceId": parentDevice.Id, "foundChildDevice": foundChildDevice})
return foundChildDevice, nil
}
- logger.Debugw("child-device-not-found", log.Fields{"parentDeviceId": parentDevice.Id,
+ logger.Debugw(ctx, "child-device-not-found", log.Fields{"parentDeviceId": parentDevice.Id,
"serialNumber": serialNumber, "onuId": onuID, "parentPortNo": parentPortNo})
return nil, status.Errorf(codes.NotFound, "%s", parentDeviceID)
}
// GetChildDeviceWithProxyAddress will return a device based on proxy address
func (dMgr *Manager) GetChildDeviceWithProxyAddress(ctx context.Context, proxyAddress *voltha.Device_ProxyAddress) (*voltha.Device, error) {
- logger.Debugw("GetChildDeviceWithProxyAddress", log.Fields{"proxyAddress": proxyAddress})
+ logger.Debugw(ctx, "GetChildDeviceWithProxyAddress", log.Fields{"proxyAddress": proxyAddress})
var parentDevice *voltha.Device
var err error
@@ -366,11 +366,11 @@
return nil, status.Errorf(codes.Aborted, "%s", err.Error())
}
var childDeviceIds []string
- if childDeviceIds, err = dMgr.getAllChildDeviceIds(parentDevice); err != nil {
+ if childDeviceIds, err = dMgr.getAllChildDeviceIds(ctx, parentDevice); err != nil {
return nil, status.Errorf(codes.Aborted, "%s", err.Error())
}
if len(childDeviceIds) == 0 {
- logger.Debugw("no-child-devices", log.Fields{"parentDeviceId": parentDevice.Id})
+ logger.Debugw(ctx, "no-child-devices", log.Fields{"parentDeviceId": parentDevice.Id})
return nil, status.Errorf(codes.NotFound, "%s", proxyAddress)
}
@@ -385,11 +385,11 @@
}
if foundChildDevice != nil {
- logger.Debugw("child-device-found", log.Fields{"proxyAddress": proxyAddress})
+ logger.Debugw(ctx, "child-device-found", log.Fields{"proxyAddress": proxyAddress})
return foundChildDevice, nil
}
- logger.Warnw("child-device-not-found", log.Fields{"proxyAddress": proxyAddress})
+ logger.Warnw(ctx, "child-device-not-found", log.Fields{"proxyAddress": proxyAddress})
return nil, status.Errorf(codes.NotFound, "%s", proxyAddress)
}
@@ -411,29 +411,29 @@
// ListDevices retrieves the latest devices from the data model
func (dMgr *Manager) ListDevices(ctx context.Context, _ *empty.Empty) (*voltha.Devices, error) {
- logger.Debug("ListDevices")
+ logger.Debug(ctx, "ListDevices")
result := &voltha.Devices{}
var devices []*voltha.Device
if err := dMgr.dProxy.List(ctx, &devices); err != nil {
- logger.Errorw("failed-to-list-devices-from-cluster-proxy", log.Fields{"error": err})
+ logger.Errorw(ctx, "failed-to-list-devices-from-cluster-proxy", log.Fields{"error": err})
return nil, err
}
for _, device := range devices {
// If device is not in memory then set it up
if !dMgr.IsDeviceInCache(device.Id) {
- logger.Debugw("loading-device-from-Model", log.Fields{"id": device.Id})
+ logger.Debugw(ctx, "loading-device-from-Model", log.Fields{"id": device.Id})
agent := newAgent(dMgr.adapterProxy, device, dMgr, dMgr.dbPath, dMgr.dProxy, dMgr.defaultTimeout)
if _, err := agent.start(ctx, nil); err != nil {
- logger.Warnw("failure-starting-agent", log.Fields{"deviceId": device.Id})
+ logger.Warnw(ctx, "failure-starting-agent", log.Fields{"deviceId": device.Id})
} else {
dMgr.addDeviceAgentToMap(agent)
}
}
result.Items = append(result.Items, device)
}
- logger.Debugw("ListDevices-end", log.Fields{"len": len(result.Items)})
+ logger.Debugw(ctx, "ListDevices-end", log.Fields{"len": len(result.Items)})
return result, nil
}
@@ -442,7 +442,7 @@
hostPort := newDevice.GetHostAndPort()
var devices []*voltha.Device
if err := dMgr.dProxy.List(ctx, &devices); err != nil {
- logger.Errorw("Failed to list devices from cluster data proxy", log.Fields{"error": err})
+ logger.Errorw(ctx, "Failed to list devices from cluster data proxy", log.Fields{"error": err})
return false, err
}
for _, device := range devices {
@@ -463,7 +463,7 @@
func (dMgr *Manager) getDeviceFromModel(ctx context.Context, deviceID string) (*voltha.Device, error) {
device := &voltha.Device{}
if have, err := dMgr.dProxy.Get(ctx, deviceID, device); err != nil {
- logger.Errorw("failed-to-get-device-info-from-cluster-proxy", log.Fields{"error": err})
+ logger.Errorw(ctx, "failed-to-get-device-info-from-cluster-proxy", log.Fields{"error": err})
return nil, err
} else if !have {
return nil, status.Error(codes.NotFound, deviceID)
@@ -486,15 +486,15 @@
dMgr.devicesLoadingLock.Unlock()
// Proceed with the loading only if the device exist in the Model (could have been deleted)
if device, err = dMgr.getDeviceFromModel(ctx, deviceID); err == nil {
- logger.Debugw("loading-device", log.Fields{"deviceId": deviceID})
+ logger.Debugw(ctx, "loading-device", log.Fields{"deviceId": deviceID})
agent := newAgent(dMgr.adapterProxy, device, dMgr, dMgr.dbPath, dMgr.dProxy, dMgr.defaultTimeout)
if _, err = agent.start(ctx, nil); err != nil {
- logger.Warnw("Failure loading device", log.Fields{"deviceId": deviceID, "error": err})
+ logger.Warnw(ctx, "Failure loading device", log.Fields{"deviceId": deviceID, "error": err})
} else {
dMgr.addDeviceAgentToMap(agent)
}
} else {
- logger.Debugw("Device not in model", log.Fields{"deviceId": deviceID})
+ logger.Debugw(ctx, "Device not in model", log.Fields{"deviceId": deviceID})
}
// announce completion of task to any number of waiting channels
dMgr.devicesLoadingLock.Lock()
@@ -523,28 +523,28 @@
// loadRootDeviceParentAndChildren loads the children and parents of a root device in memory
func (dMgr *Manager) loadRootDeviceParentAndChildren(ctx context.Context, device *voltha.Device) error {
- logger.Debugw("loading-parent-and-children", log.Fields{"deviceId": device.Id})
+ logger.Debugw(ctx, "loading-parent-and-children", log.Fields{"deviceId": device.Id})
if device.Root {
// Scenario A
if device.ParentId != "" {
// Load logical device if needed.
if err := dMgr.logicalDeviceMgr.load(ctx, device.ParentId); err != nil {
- logger.Warnw("failure-loading-logical-device", log.Fields{"lDeviceId": device.ParentId})
+ logger.Warnw(ctx, "failure-loading-logical-device", log.Fields{"lDeviceId": device.ParentId})
}
} else {
- logger.Debugw("no-parent-to-load", log.Fields{"deviceId": device.Id})
+ logger.Debugw(ctx, "no-parent-to-load", log.Fields{"deviceId": device.Id})
}
// Load all child devices, if needed
- if childDeviceIds, err := dMgr.getAllChildDeviceIds(device); err == nil {
+ if childDeviceIds, err := dMgr.getAllChildDeviceIds(ctx, device); err == nil {
for _, childDeviceID := range childDeviceIds {
if _, err := dMgr.loadDevice(ctx, childDeviceID); err != nil {
- logger.Warnw("failure-loading-device", log.Fields{"deviceId": childDeviceID, "error": err})
+ logger.Warnw(ctx, "failure-loading-device", log.Fields{"deviceId": childDeviceID, "error": err})
return err
}
}
- logger.Debugw("loaded-children", log.Fields{"deviceId": device.Id, "numChildren": len(childDeviceIds)})
+ logger.Debugw(ctx, "loaded-children", log.Fields{"deviceId": device.Id, "numChildren": len(childDeviceIds)})
} else {
- logger.Debugw("no-child-to-load", log.Fields{"deviceId": device.Id})
+ logger.Debugw(ctx, "no-child-to-load", log.Fields{"deviceId": device.Id})
}
}
return nil
@@ -555,7 +555,7 @@
// acting on the device is received by the core. In such a scenario, the Core will load the device in memory first
// and the proceed with the request.
func (dMgr *Manager) load(ctx context.Context, deviceID string) error {
- logger.Debug("load...")
+ logger.Debug(ctx, "load...")
// First load the device - this may fail in case the device was deleted intentionally by the other core
var dAgent *Agent
var err error
@@ -577,10 +577,10 @@
if device.Root {
// Load all children as well as the parent of this device (logical_device)
if err := dMgr.loadRootDeviceParentAndChildren(ctx, device); err != nil {
- logger.Warnw("failure-loading-device-parent-and-children", log.Fields{"deviceId": deviceID})
+ logger.Warnw(ctx, "failure-loading-device-parent-and-children", log.Fields{"deviceId": deviceID})
return err
}
- logger.Debugw("successfully-loaded-parent-and-children", log.Fields{"deviceId": deviceID})
+ logger.Debugw(ctx, "successfully-loaded-parent-and-children", log.Fields{"deviceId": deviceID})
} else {
// Scenario B - use the parentId of that device (root device) to trigger the loading
if device.ParentId != "" {
@@ -591,8 +591,8 @@
}
// ListDeviceIds retrieves the latest device IDs information from the data model (memory data only)
-func (dMgr *Manager) ListDeviceIds(_ context.Context, _ *empty.Empty) (*voltha.IDs, error) {
- logger.Debug("ListDeviceIDs")
+func (dMgr *Manager) ListDeviceIds(ctx context.Context, _ *empty.Empty) (*voltha.IDs, error) {
+ logger.Debug(ctx, "ListDeviceIDs")
// Report only device IDs that are in the device agent map
return dMgr.listDeviceIdsFromMap(), nil
}
@@ -600,14 +600,14 @@
// ReconcileDevices is a request to a voltha core to update its list of managed devices. This will
// trigger loading the devices along with their children and parent in memory
func (dMgr *Manager) ReconcileDevices(ctx context.Context, ids *voltha.IDs) (*empty.Empty, error) {
- logger.Debugw("ReconcileDevices", log.Fields{"numDevices": len(ids.Items)})
+ logger.Debugw(ctx, "ReconcileDevices", log.Fields{"numDevices": len(ids.Items)})
if ids != nil && len(ids.Items) != 0 {
toReconcile := len(ids.Items)
reconciled := 0
var err error
for _, id := range ids.Items {
if err = dMgr.load(ctx, id.Id); err != nil {
- logger.Warnw("failure-reconciling-device", log.Fields{"deviceId": id.Id, "error": err})
+ logger.Warnw(ctx, "failure-reconciling-device", log.Fields{"deviceId": id.Id, "error": err})
} else {
reconciled++
}
@@ -631,45 +631,45 @@
// adapterRestarted is invoked whenever an adapter is restarted
func (dMgr *Manager) adapterRestarted(ctx context.Context, adapter *voltha.Adapter) error {
- logger.Debugw("adapter-restarted", log.Fields{"adapterId": adapter.Id, "vendor": adapter.Vendor,
+ logger.Debugw(ctx, "adapter-restarted", log.Fields{"adapterId": adapter.Id, "vendor": adapter.Vendor,
"currentReplica": adapter.CurrentReplica, "totalReplicas": adapter.TotalReplicas, "endpoint": adapter.Endpoint})
// Let's reconcile the device managed by this Core only
if len(dMgr.rootDevices) == 0 {
- logger.Debugw("nothing-to-reconcile", log.Fields{"adapterId": adapter.Id})
+ logger.Debugw(ctx, "nothing-to-reconcile", log.Fields{"adapterId": adapter.Id})
return nil
}
responses := make([]utils.Response, 0)
for rootDeviceID := range dMgr.rootDevices {
if rootDevice, _ := dMgr.getDeviceFromModel(ctx, rootDeviceID); rootDevice != nil {
- isDeviceOwnedByService, err := dMgr.adapterProxy.IsDeviceOwnedByService(rootDeviceID, adapter.Type, adapter.CurrentReplica)
+ isDeviceOwnedByService, err := dMgr.adapterProxy.IsDeviceOwnedByService(ctx, rootDeviceID, adapter.Type, adapter.CurrentReplica)
if err != nil {
- logger.Warnw("is-device-owned-by-service", log.Fields{"error": err, "root-device-id": rootDeviceID, "adapterType": adapter.Type, "replica-number": adapter.CurrentReplica})
+ logger.Warnw(ctx, "is-device-owned-by-service", log.Fields{"error": err, "root-device-id": rootDeviceID, "adapterType": adapter.Type, "replica-number": adapter.CurrentReplica})
continue
}
if isDeviceOwnedByService {
if isOkToReconcile(rootDevice) {
- logger.Debugw("reconciling-root-device", log.Fields{"rootId": rootDevice.Id})
+ logger.Debugw(ctx, "reconciling-root-device", log.Fields{"rootId": rootDevice.Id})
responses = append(responses, dMgr.sendReconcileDeviceRequest(ctx, rootDevice))
} else {
- logger.Debugw("not-reconciling-root-device", log.Fields{"rootId": rootDevice.Id, "state": rootDevice.AdminState})
+ logger.Debugw(ctx, "not-reconciling-root-device", log.Fields{"rootId": rootDevice.Id, "state": rootDevice.AdminState})
}
} else { // Should we be reconciling the root's children instead?
childManagedByAdapter:
for _, port := range rootDevice.Ports {
for _, peer := range port.Peers {
if childDevice, _ := dMgr.getDeviceFromModel(ctx, peer.DeviceId); childDevice != nil {
- isDeviceOwnedByService, err := dMgr.adapterProxy.IsDeviceOwnedByService(childDevice.Id, adapter.Type, adapter.CurrentReplica)
+ isDeviceOwnedByService, err := dMgr.adapterProxy.IsDeviceOwnedByService(ctx, childDevice.Id, adapter.Type, adapter.CurrentReplica)
if err != nil {
- logger.Warnw("is-device-owned-by-service", log.Fields{"error": err, "child-device-id": childDevice.Id, "adapterType": adapter.Type, "replica-number": adapter.CurrentReplica})
+ logger.Warnw(ctx, "is-device-owned-by-service", log.Fields{"error": err, "child-device-id": childDevice.Id, "adapterType": adapter.Type, "replica-number": adapter.CurrentReplica})
}
if isDeviceOwnedByService {
if isOkToReconcile(childDevice) {
- logger.Debugw("reconciling-child-device", log.Fields{"child-device-id": childDevice.Id})
+ logger.Debugw(ctx, "reconciling-child-device", log.Fields{"child-device-id": childDevice.Id})
responses = append(responses, dMgr.sendReconcileDeviceRequest(ctx, childDevice))
} else {
- logger.Debugw("not-reconciling-child-device", log.Fields{"child-device-id": childDevice.Id, "state": childDevice.AdminState})
+ logger.Debugw(ctx, "not-reconciling-child-device", log.Fields{"child-device-id": childDevice.Id, "state": childDevice.AdminState})
}
} else {
// All child devices under a parent device are typically managed by the same adapter type.
@@ -688,7 +688,7 @@
return status.Errorf(codes.Aborted, "errors-%s", res)
}
} else {
- logger.Debugw("no-managed-device-to-reconcile", log.Fields{"adapterId": adapter.Id})
+ logger.Debugw(ctx, "no-managed-device-to-reconcile", log.Fields{"adapterId": adapter.Id})
}
return nil
}
@@ -735,7 +735,7 @@
}
func (dMgr *Manager) UpdateDeviceUsingAdapterData(ctx context.Context, device *voltha.Device) error {
- logger.Debugw("UpdateDeviceUsingAdapterData", log.Fields{"deviceid": device.Id, "device": device})
+ logger.Debugw(ctx, "UpdateDeviceUsingAdapterData", log.Fields{"deviceid": device.Id, "device": device})
if agent := dMgr.getDeviceAgent(ctx, device.Id); agent != nil {
return agent.updateDeviceUsingAdapterData(ctx, device)
}
@@ -772,8 +772,8 @@
}
// Setup peer ports in its own routine
go func() {
- if err := dMgr.addPeerPort(ctx, deviceID, port); err != nil {
- logger.Errorw("unable-to-add-peer-port", log.Fields{"error": err, "device-id": deviceID})
+ if err := dMgr.addPeerPort(context.Background(), deviceID, port); err != nil {
+ logger.Errorw(ctx, "unable-to-add-peer-port", log.Fields{"error": err, "device-id": deviceID})
}
}()
return nil
@@ -782,7 +782,7 @@
}
func (dMgr *Manager) addFlowsAndGroups(ctx context.Context, deviceID string, flows []*ofp.OfpFlowStats, groups []*ofp.OfpGroupEntry, flowMetadata *voltha.FlowMetadata) error {
- logger.Debugw("addFlowsAndGroups", log.Fields{"deviceid": deviceID, "groups:": groups, "flowMetadata": flowMetadata})
+ logger.Debugw(ctx, "addFlowsAndGroups", log.Fields{"deviceid": deviceID, "groups:": groups, "flowMetadata": flowMetadata})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
return agent.addFlowsAndGroups(ctx, flows, groups, flowMetadata)
}
@@ -791,7 +791,7 @@
// deleteParentFlows removes flows from the parent device based on specific attributes
func (dMgr *Manager) deleteParentFlows(ctx context.Context, deviceID string, uniPort uint32, metadata *voltha.FlowMetadata) error {
- logger.Debugw("deleteParentFlows", log.Fields{"device-id": deviceID, "uni-port": uniPort, "metadata": metadata})
+ logger.Debugw(ctx, "deleteParentFlows", log.Fields{"device-id": deviceID, "uni-port": uniPort, "metadata": metadata})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
if !agent.isRootdevice {
return status.Errorf(codes.FailedPrecondition, "not-a-parent-device-%s", deviceID)
@@ -802,7 +802,7 @@
}
func (dMgr *Manager) deleteFlowsAndGroups(ctx context.Context, deviceID string, flows []*ofp.OfpFlowStats, groups []*ofp.OfpGroupEntry, flowMetadata *voltha.FlowMetadata) error {
- logger.Debugw("deleteFlowsAndGroups", log.Fields{"deviceid": deviceID})
+ logger.Debugw(ctx, "deleteFlowsAndGroups", log.Fields{"deviceid": deviceID})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
return agent.deleteFlowsAndGroups(ctx, flows, groups, flowMetadata)
}
@@ -810,7 +810,7 @@
}
func (dMgr *Manager) updateFlowsAndGroups(ctx context.Context, deviceID string, flows []*ofp.OfpFlowStats, groups []*ofp.OfpGroupEntry, flowMetadata *voltha.FlowMetadata) error {
- logger.Debugw("updateFlowsAndGroups", log.Fields{"deviceid": deviceID})
+ logger.Debugw(ctx, "updateFlowsAndGroups", log.Fields{"deviceid": deviceID})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
return agent.updateFlowsAndGroups(ctx, flows, groups, flowMetadata)
}
@@ -851,7 +851,7 @@
}
func (dMgr *Manager) getSwitchCapability(ctx context.Context, deviceID string) (*ic.SwitchCapability, error) {
- logger.Debugw("getSwitchCapability", log.Fields{"deviceid": deviceID})
+ logger.Debugw(ctx, "getSwitchCapability", log.Fields{"deviceid": deviceID})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
return agent.getSwitchCapability(ctx)
}
@@ -859,7 +859,7 @@
}
func (dMgr *Manager) GetPorts(ctx context.Context, deviceID string, portType voltha.Port_PortType) (*voltha.Ports, error) {
- logger.Debugw("GetPorts", log.Fields{"deviceid": deviceID, "portType": portType})
+ logger.Debugw(ctx, "GetPorts", log.Fields{"deviceid": deviceID, "portType": portType})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
return agent.getPorts(ctx, portType), nil
}
@@ -867,7 +867,7 @@
}
func (dMgr *Manager) UpdateDeviceStatus(ctx context.Context, deviceID string, operStatus voltha.OperStatus_Types, connStatus voltha.ConnectStatus_Types) error {
- logger.Debugw("UpdateDeviceStatus", log.Fields{"deviceid": deviceID, "operStatus": operStatus, "connStatus": connStatus})
+ logger.Debugw(ctx, "UpdateDeviceStatus", log.Fields{"deviceid": deviceID, "operStatus": operStatus, "connStatus": connStatus})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
return agent.updateDeviceStatus(ctx, operStatus, connStatus)
}
@@ -875,18 +875,18 @@
}
func (dMgr *Manager) UpdateChildrenStatus(ctx context.Context, deviceID string, operStatus voltha.OperStatus_Types, connStatus voltha.ConnectStatus_Types) error {
- logger.Debugw("UpdateChildrenStatus", log.Fields{"parentDeviceid": deviceID, "operStatus": operStatus, "connStatus": connStatus})
+ logger.Debugw(ctx, "UpdateChildrenStatus", log.Fields{"parentDeviceid": deviceID, "operStatus": operStatus, "connStatus": connStatus})
var parentDevice *voltha.Device
var err error
if parentDevice, err = dMgr.getDevice(ctx, deviceID); err != nil {
return status.Errorf(codes.Aborted, "%s", err.Error())
}
var childDeviceIds []string
- if childDeviceIds, err = dMgr.getAllChildDeviceIds(parentDevice); err != nil {
+ if childDeviceIds, err = dMgr.getAllChildDeviceIds(ctx, parentDevice); err != nil {
return status.Errorf(codes.Aborted, "%s", err.Error())
}
if len(childDeviceIds) == 0 {
- logger.Debugw("no-child-device", log.Fields{"parentDeviceId": parentDevice.Id})
+ logger.Debugw(ctx, "no-child-device", log.Fields{"parentDeviceId": parentDevice.Id})
}
for _, childDeviceID := range childDeviceIds {
if agent := dMgr.getDeviceAgent(ctx, childDeviceID); agent != nil {
@@ -899,10 +899,10 @@
}
func (dMgr *Manager) UpdatePortState(ctx context.Context, deviceID string, portType voltha.Port_PortType, portNo uint32, operStatus voltha.OperStatus_Types) error {
- logger.Debugw("UpdatePortState", log.Fields{"deviceid": deviceID, "portType": portType, "portNo": portNo, "operStatus": operStatus})
+ logger.Debugw(ctx, "UpdatePortState", log.Fields{"deviceid": deviceID, "portType": portType, "portNo": portNo, "operStatus": operStatus})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
if err := agent.updatePortState(ctx, portType, portNo, operStatus); err != nil {
- logger.Errorw("updating-port-state-failed", log.Fields{"deviceid": deviceID, "portNo": portNo, "error": err})
+ logger.Errorw(ctx, "updating-port-state-failed", log.Fields{"deviceid": deviceID, "portNo": portNo, "error": err})
return err
}
// Notify the logical device manager to change the port state
@@ -917,7 +917,7 @@
// it as a warning and not an error because it
// doesn't stop or modify processing.
// TODO: VOL-2707
- logger.Warnw("unable-to-update-logical-port-state", log.Fields{"error": err})
+ logger.Warnw(ctx, "unable-to-update-logical-port-state", log.Fields{"error": err})
}
}()
}
@@ -927,7 +927,7 @@
}
func (dMgr *Manager) DeleteAllPorts(ctx context.Context, deviceID string) error {
- logger.Debugw("DeleteAllPorts", log.Fields{"deviceid": deviceID})
+ logger.Debugw(ctx, "DeleteAllPorts", log.Fields{"deviceid": deviceID})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
if err := agent.deleteAllPorts(ctx); err != nil {
return err
@@ -937,13 +937,13 @@
// typically is part of a device deletion phase.
if device, err := dMgr.getDevice(ctx, deviceID); err == nil {
go func() {
- err = dMgr.logicalDeviceMgr.deleteAllLogicalPorts(ctx, device)
+ err = dMgr.logicalDeviceMgr.deleteAllLogicalPorts(context.Background(), device)
if err != nil {
- logger.Errorw("unable-to-delete-logical-ports", log.Fields{"error": err})
+ logger.Errorw(ctx, "unable-to-delete-logical-ports", log.Fields{"error": err})
}
}()
} else {
- logger.Warnw("failed-to-retrieve-device", log.Fields{"deviceId": deviceID})
+ logger.Warnw(ctx, "failed-to-retrieve-device", log.Fields{"deviceId": deviceID})
return err
}
return nil
@@ -953,18 +953,18 @@
//UpdatePortsState updates all ports on the device
func (dMgr *Manager) UpdatePortsState(ctx context.Context, deviceID string, state voltha.OperStatus_Types) error {
- logger.Debugw("UpdatePortsState", log.Fields{"deviceid": deviceID})
+ logger.Debugw(ctx, "UpdatePortsState", log.Fields{"deviceid": deviceID})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
switch state {
case voltha.OperStatus_ACTIVE:
if err := agent.updatePortsOperState(ctx, state); err != nil {
- logger.Warnw("updatePortsOperState-failed", log.Fields{"deviceId": deviceID, "error": err})
+ logger.Warnw(ctx, "updatePortsOperState-failed", log.Fields{"deviceId": deviceID, "error": err})
return err
}
case voltha.OperStatus_UNKNOWN:
if err := agent.updatePortsOperState(ctx, state); err != nil {
- logger.Warnw("updatePortsOperState-failed", log.Fields{"deviceId": deviceID, "error": err})
+ logger.Warnw(ctx, "updatePortsOperState-failed", log.Fields{"deviceId": deviceID, "error": err})
return err
}
default:
@@ -973,11 +973,11 @@
// Notify the logical device about the state change
device, err := dMgr.getDevice(ctx, deviceID)
if err != nil {
- logger.Warnw("non-existent-device", log.Fields{"deviceId": deviceID, "error": err})
+ logger.Warnw(ctx, "non-existent-device", log.Fields{"deviceId": deviceID, "error": err})
return err
}
if err := dMgr.logicalDeviceMgr.updatePortsState(ctx, device, state); err != nil {
- logger.Warnw("failed-updating-ports-state", log.Fields{"deviceId": deviceID, "error": err})
+ logger.Warnw(ctx, "failed-updating-ports-state", log.Fields{"deviceId": deviceID, "error": err})
return err
}
return nil
@@ -987,10 +987,10 @@
func (dMgr *Manager) ChildDeviceDetected(ctx context.Context, parentDeviceID string, parentPortNo int64, deviceType string,
channelID int64, vendorID string, serialNumber string, onuID int64) (*voltha.Device, error) {
- logger.Debugw("ChildDeviceDetected", log.Fields{"parentDeviceId": parentDeviceID, "parentPortNo": parentPortNo, "deviceType": deviceType, "channelId": channelID, "vendorId": vendorID, "serialNumber": serialNumber, "onuId": onuID})
+ logger.Debugw(ctx, "ChildDeviceDetected", log.Fields{"parentDeviceId": parentDeviceID, "parentPortNo": parentPortNo, "deviceType": deviceType, "channelId": channelID, "vendorId": vendorID, "serialNumber": serialNumber, "onuId": onuID})
if deviceType == "" && vendorID != "" {
- logger.Debug("device-type-is-nil-fetching-device-type")
+ logger.Debug(ctx, "device-type-is-nil-fetching-device-type")
deviceTypes, err := dMgr.adapterMgr.ListDeviceTypes(ctx, nil)
if err != nil {
return nil, err
@@ -1007,7 +1007,7 @@
}
//if no match found for the vendorid,report adapter with the custom error message
if deviceType == "" {
- logger.Errorw("failed-to-fetch-adapter-name ", log.Fields{"vendorId": vendorID})
+ logger.Errorw(ctx, "failed-to-fetch-adapter-name ", log.Fields{"vendorId": vendorID})
return nil, status.Errorf(codes.NotFound, "%s", vendorID)
}
@@ -1030,7 +1030,7 @@
}
if device, err := dMgr.GetChildDevice(ctx, parentDeviceID, serialNumber, onuID, parentPortNo); err == nil {
- logger.Warnw("child-device-exists", log.Fields{"parentId": parentDeviceID, "serialNumber": serialNumber})
+ logger.Warnw(ctx, "child-device-exists", log.Fields{"parentId": parentDeviceID, "serialNumber": serialNumber})
return device, status.Errorf(codes.AlreadyExists, "%s", serialNumber)
}
@@ -1040,7 +1040,7 @@
agent := newAgent(dMgr.adapterProxy, childDevice, dMgr, dMgr.dbPath, dMgr.dProxy, dMgr.defaultTimeout)
childDevice, err := agent.start(ctx, childDevice)
if err != nil {
- logger.Errorw("error-starting-child-device", log.Fields{"parent-device-id": childDevice.ParentId, "child-device-id": agent.deviceID, "error": err})
+ logger.Errorw(ctx, "error-starting-child-device", log.Fields{"parent-device-id": childDevice.ParentId, "child-device-id": agent.deviceID, "error": err})
return nil, err
}
dMgr.addDeviceAgentToMap(agent)
@@ -1050,7 +1050,7 @@
go func() {
err := agent.enableDevice(context.Background())
if err != nil {
- logger.Errorw("unable-to-enable-device", log.Fields{"error": err})
+ logger.Errorw(ctx, "unable-to-enable-device", log.Fields{"error": err})
}
}()
}
@@ -1060,7 +1060,7 @@
func (dMgr *Manager) processTransition(ctx context.Context, device *voltha.Device, previousState *deviceState) error {
// This will be triggered on every state update
- logger.Debugw("state-transition", log.Fields{
+ logger.Debugw(ctx, "state-transition", log.Fields{
"device": device.Id,
"prev-admin-state": previousState.Admin,
"prev-oper-state": previousState.Operational,
@@ -1069,16 +1069,16 @@
"curr-oper-state": device.OperStatus,
"curr-conn-state": device.ConnectStatus,
})
- handlers := dMgr.stateTransitions.GetTransitionHandler(device, previousState)
+ handlers := dMgr.stateTransitions.GetTransitionHandler(ctx, device, previousState)
if handlers == nil {
- logger.Debugw("no-op-transition", log.Fields{"deviceId": device.Id})
+ logger.Debugw(ctx, "no-op-transition", log.Fields{"deviceId": device.Id})
return nil
}
- logger.Debugw("handler-found", log.Fields{"num-expectedHandlers": len(handlers), "isParent": device.Root, "current-data": device, "previous-state": previousState})
+ 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("running-handler", log.Fields{"handler": funcName(handler)})
+ logger.Debugw(ctx, "running-handler", log.Fields{"handler": funcName(handler)})
if err := handler(ctx, device); err != nil {
- logger.Warnw("handler-failed", log.Fields{"handler": funcName(handler), "error": err})
+ logger.Warnw(ctx, "handler-failed", log.Fields{"handler": funcName(handler), "error": err})
return err
}
}
@@ -1086,7 +1086,7 @@
}
func (dMgr *Manager) packetOut(ctx context.Context, deviceID string, outPort uint32, packet *ofp.OfpPacketOut) error {
- logger.Debugw("packetOut", log.Fields{"deviceId": deviceID, "outPort": outPort})
+ logger.Debugw(ctx, "packetOut", log.Fields{"deviceId": deviceID, "outPort": outPort})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
return agent.packetOut(ctx, outPort, packet)
}
@@ -1095,16 +1095,16 @@
// PacketIn receives packet from adapter
func (dMgr *Manager) PacketIn(ctx context.Context, deviceID string, port uint32, transactionID string, packet []byte) error {
- logger.Debugw("PacketIn", log.Fields{"deviceId": deviceID, "port": port})
+ logger.Debugw(ctx, "PacketIn", log.Fields{"deviceId": deviceID, "port": port})
// Get the logical device Id based on the deviceId
var device *voltha.Device
var err error
if device, err = dMgr.getDevice(ctx, deviceID); err != nil {
- logger.Errorw("device-not-found", log.Fields{"deviceId": deviceID})
+ logger.Errorw(ctx, "device-not-found", log.Fields{"deviceId": deviceID})
return err
}
if !device.Root {
- logger.Errorw("device-not-root", log.Fields{"deviceId": deviceID})
+ logger.Errorw(ctx, "device-not-root", log.Fields{"deviceId": deviceID})
return status.Errorf(codes.FailedPrecondition, "%s", deviceID)
}
@@ -1115,7 +1115,7 @@
}
func (dMgr *Manager) setParentID(ctx context.Context, device *voltha.Device, parentID string) error {
- logger.Debugw("setParentId", log.Fields{"deviceId": device.Id, "parentId": parentID})
+ logger.Debugw(ctx, "setParentId", log.Fields{"deviceId": device.Id, "parentId": parentID})
if agent := dMgr.getDeviceAgent(ctx, device.Id); agent != nil {
return agent.setParentID(ctx, device, parentID)
}
@@ -1124,15 +1124,15 @@
// CreateLogicalDevice creates logical device in core
func (dMgr *Manager) CreateLogicalDevice(ctx context.Context, cDevice *voltha.Device) error {
- logger.Info("CreateLogicalDevice")
+ logger.Info(ctx, "CreateLogicalDevice")
// Verify whether the logical device has already been created
if cDevice.ParentId != "" {
- logger.Debugw("Parent device already exist.", log.Fields{"deviceId": cDevice.Id, "logicalDeviceId": cDevice.Id})
+ logger.Debugw(ctx, "Parent device already exist.", log.Fields{"deviceId": cDevice.Id, "logicalDeviceId": cDevice.Id})
return nil
}
var err error
if _, err = dMgr.logicalDeviceMgr.createLogicalDevice(ctx, cDevice); err != nil {
- logger.Warnw("createlogical-device-error", log.Fields{"device": cDevice})
+ logger.Warnw(ctx, "createlogical-device-error", log.Fields{"device": cDevice})
return err
}
return nil
@@ -1140,10 +1140,10 @@
// DeleteLogicalDevice deletes logical device from core
func (dMgr *Manager) DeleteLogicalDevice(ctx context.Context, cDevice *voltha.Device) error {
- logger.Info("DeleteLogicalDevice")
+ logger.Info(ctx, "DeleteLogicalDevice")
var err error
if err = dMgr.logicalDeviceMgr.deleteLogicalDevice(ctx, cDevice); err != nil {
- logger.Warnw("deleteLogical-device-error", log.Fields{"deviceId": cDevice.Id})
+ logger.Warnw(ctx, "deleteLogical-device-error", log.Fields{"deviceId": cDevice.Id})
return err
}
// Remove the logical device Id from the parent device
@@ -1154,10 +1154,10 @@
// DeleteLogicalPorts removes the logical ports associated with that deviceId
func (dMgr *Manager) DeleteLogicalPorts(ctx context.Context, cDevice *voltha.Device) error {
- logger.Debugw("delete-all-logical-ports", log.Fields{"device-id": cDevice.Id})
+ logger.Debugw(ctx, "delete-all-logical-ports", log.Fields{"device-id": cDevice.Id})
if err := dMgr.logicalDeviceMgr.deleteLogicalPorts(ctx, cDevice.Id); err != nil {
// Just log the error. The logical device or port may already have been deleted before this callback is invoked.
- logger.Warnw("deleteLogical-ports-error", log.Fields{"device-id": cDevice.Id, "error": err})
+ logger.Warnw(ctx, "deleteLogical-ports-error", log.Fields{"device-id": cDevice.Id, "error": err})
}
return nil
}
@@ -1175,11 +1175,11 @@
//ChildDevicesLost is invoked by an adapter to indicate that a parent device is in a state (Disabled) where it
//cannot manage the child devices. This will trigger the Core to disable all the child devices.
func (dMgr *Manager) ChildDevicesLost(ctx context.Context, parentDeviceID string) error {
- logger.Debug("ChildDevicesLost")
+ logger.Debug(ctx, "ChildDevicesLost")
var err error
var parentDevice *voltha.Device
if parentDevice, err = dMgr.getDevice(ctx, parentDeviceID); err != nil {
- logger.Warnw("failed-getting-device", log.Fields{"deviceId": parentDeviceID, "error": err})
+ logger.Warnw(ctx, "failed-getting-device", log.Fields{"deviceId": parentDeviceID, "error": err})
return err
}
return dMgr.DisableAllChildDevices(ctx, parentDevice)
@@ -1188,35 +1188,35 @@
//ChildDevicesDetected is invoked by an adapter when child devices are found, typically after after a
// disable/enable sequence. This will trigger the Core to Enable all the child devices of that parent.
func (dMgr *Manager) ChildDevicesDetected(ctx context.Context, parentDeviceID string) error {
- logger.Debug("ChildDevicesDetected")
+ logger.Debug(ctx, "ChildDevicesDetected")
var err error
var parentDevice *voltha.Device
var childDeviceIds []string
if parentDevice, err = dMgr.getDevice(ctx, parentDeviceID); err != nil {
- logger.Warnw("failed-getting-device", log.Fields{"deviceId": parentDeviceID, "error": err})
+ logger.Warnw(ctx, "failed-getting-device", log.Fields{"deviceId": parentDeviceID, "error": err})
return err
}
- if childDeviceIds, err = dMgr.getAllChildDeviceIds(parentDevice); err != nil {
+ if childDeviceIds, err = dMgr.getAllChildDeviceIds(ctx, parentDevice); err != nil {
return status.Errorf(codes.NotFound, "%s", parentDevice.Id)
}
if len(childDeviceIds) == 0 {
- logger.Debugw("no-child-device", log.Fields{"parentDeviceId": parentDevice.Id})
+ logger.Debugw(ctx, "no-child-device", log.Fields{"parentDeviceId": parentDevice.Id})
}
allChildEnableRequestSent := true
for _, childDeviceID := range childDeviceIds {
if agent := dMgr.getDeviceAgent(ctx, childDeviceID); agent != nil {
// Run the children re-registration in its own routine
go func() {
- err = agent.enableDevice(ctx)
+ err = agent.enableDevice(context.Background())
if err != nil {
- logger.Errorw("unable-to-enable-device", log.Fields{"error": err})
+ logger.Errorw(ctx, "unable-to-enable-device", log.Fields{"error": err})
}
}()
} else {
err = status.Errorf(codes.Unavailable, "no agent for child device %s", childDeviceID)
- logger.Errorw("no-child-device-agent", log.Fields{"parentDeviceId": parentDevice.Id, "childId": childDeviceID})
+ logger.Errorw(ctx, "no-child-device-agent", log.Fields{"parentDeviceId": parentDevice.Id, "childId": childDeviceID})
allChildEnableRequestSent = false
}
}
@@ -1233,20 +1233,20 @@
//DisableAllChildDevices is invoked as a callback when the parent device is disabled
func (dMgr *Manager) DisableAllChildDevices(ctx context.Context, parentCurrDevice *voltha.Device) error {
- logger.Debug("DisableAllChildDevices")
+ logger.Debug(ctx, "DisableAllChildDevices")
var childDeviceIds []string
var err error
- if childDeviceIds, err = dMgr.getAllChildDeviceIds(parentCurrDevice); err != nil {
+ if childDeviceIds, err = dMgr.getAllChildDeviceIds(ctx, parentCurrDevice); err != nil {
return status.Errorf(codes.NotFound, "%s", parentCurrDevice.Id)
}
if len(childDeviceIds) == 0 {
- logger.Debugw("no-child-device", log.Fields{"parentDeviceId": parentCurrDevice.Id})
+ logger.Debugw(ctx, "no-child-device", log.Fields{"parentDeviceId": parentCurrDevice.Id})
}
for _, childDeviceID := range childDeviceIds {
if agent := dMgr.getDeviceAgent(ctx, childDeviceID); agent != nil {
if err = agent.disableDevice(ctx); err != nil {
// Just log the error - this error happens only if the child device was already in deleted state.
- logger.Errorw("failure-disable-device", log.Fields{"deviceId": childDeviceID, "error": err.Error()})
+ logger.Errorw(ctx, "failure-disable-device", log.Fields{"deviceId": childDeviceID, "error": err.Error()})
}
}
}
@@ -1255,19 +1255,19 @@
//DeleteAllChildDevices is invoked as a callback when the parent device is deleted
func (dMgr *Manager) DeleteAllChildDevices(ctx context.Context, parentCurrDevice *voltha.Device) error {
- logger.Debug("DeleteAllChildDevices")
+ logger.Debug(ctx, "DeleteAllChildDevices")
var childDeviceIds []string
var err error
- if childDeviceIds, err = dMgr.getAllChildDeviceIds(parentCurrDevice); err != nil {
+ if childDeviceIds, err = dMgr.getAllChildDeviceIds(ctx, parentCurrDevice); err != nil {
return status.Errorf(codes.NotFound, "%s", parentCurrDevice.Id)
}
if len(childDeviceIds) == 0 {
- logger.Debugw("no-child-device", log.Fields{"parentDeviceId": parentCurrDevice.Id})
+ logger.Debugw(ctx, "no-child-device", log.Fields{"parentDeviceId": parentCurrDevice.Id})
}
for _, childDeviceID := range childDeviceIds {
if agent := dMgr.getDeviceAgent(ctx, childDeviceID); agent != nil {
if err = agent.deleteDevice(ctx); err != nil {
- logger.Warnw("failure-delete-device", log.Fields{"deviceId": childDeviceID, "error": err.Error()})
+ logger.Warnw(ctx, "failure-delete-device", log.Fields{"deviceId": childDeviceID, "error": err.Error()})
}
// No further action is required here. The deleteDevice will change the device state where the resulting
// callback will take care of cleaning the child device agent.
@@ -1278,20 +1278,20 @@
//DeleteAllLogicalPorts is invoked as a callback when the parent device's connection status moves to UNREACHABLE
func (dMgr *Manager) DeleteAllLogicalPorts(ctx context.Context, parentDevice *voltha.Device) error {
- logger.Debugw("delete-all-logical-ports", log.Fields{"parent-device-id": parentDevice.Id})
+ logger.Debugw(ctx, "delete-all-logical-ports", log.Fields{"parent-device-id": parentDevice.Id})
if err := dMgr.logicalDeviceMgr.deleteAllLogicalPorts(ctx, parentDevice); err != nil {
// Just log error as logical device may already have been deleted
- logger.Warnw("delete-all-logical-ports-fail", log.Fields{"parent-device-id": parentDevice.Id, "error": err})
+ logger.Warnw(ctx, "delete-all-logical-ports-fail", log.Fields{"parent-device-id": parentDevice.Id, "error": err})
}
return nil
}
//DeleteAllDeviceFlows is invoked as a callback when the parent device's connection status moves to UNREACHABLE
func (dMgr *Manager) DeleteAllDeviceFlows(ctx context.Context, parentDevice *voltha.Device) error {
- logger.Debugw("delete-all-device-flows", log.Fields{"parent-device-id": parentDevice.Id})
+ logger.Debugw(ctx, "delete-all-device-flows", log.Fields{"parent-device-id": parentDevice.Id})
if agent := dMgr.getDeviceAgent(ctx, parentDevice.Id); agent != nil {
if err := agent.deleteAllFlows(ctx); err != nil {
- logger.Errorw("error-deleting-all-device-flows", log.Fields{"parent-device-id": parentDevice.Id})
+ logger.Errorw(ctx, "error-deleting-all-device-flows", log.Fields{"parent-device-id": parentDevice.Id})
return err
}
return nil
@@ -1300,8 +1300,8 @@
}
//getAllChildDeviceIds is a helper method to get all the child device IDs from the device passed as parameter
-func (dMgr *Manager) getAllChildDeviceIds(parentDevice *voltha.Device) ([]string, error) {
- logger.Debugw("getAllChildDeviceIds", log.Fields{"parentDeviceId": parentDevice.Id})
+func (dMgr *Manager) getAllChildDeviceIds(ctx context.Context, parentDevice *voltha.Device) ([]string, error) {
+ logger.Debugw(ctx, "getAllChildDeviceIds", log.Fields{"parentDeviceId": parentDevice.Id})
childDeviceIds := make([]string, 0)
if parentDevice != nil {
for _, port := range parentDevice.Ports {
@@ -1309,17 +1309,17 @@
childDeviceIds = append(childDeviceIds, peer.DeviceId)
}
}
- logger.Debugw("returning-getAllChildDeviceIds", log.Fields{"parentDeviceId": parentDevice.Id, "childDeviceIds": childDeviceIds})
+ logger.Debugw(ctx, "returning-getAllChildDeviceIds", log.Fields{"parentDeviceId": parentDevice.Id, "childDeviceIds": childDeviceIds})
}
return childDeviceIds, nil
}
//GetAllChildDevices is a helper method to get all the child device IDs from the device passed as parameter
func (dMgr *Manager) GetAllChildDevices(ctx context.Context, parentDeviceID string) (*voltha.Devices, error) {
- logger.Debugw("GetAllChildDevices", log.Fields{"parentDeviceId": parentDeviceID})
+ logger.Debugw(ctx, "GetAllChildDevices", log.Fields{"parentDeviceId": parentDeviceID})
if parentDevice, err := dMgr.getDevice(ctx, parentDeviceID); err == nil {
childDevices := make([]*voltha.Device, 0)
- if childDeviceIds, er := dMgr.getAllChildDeviceIds(parentDevice); er == nil {
+ if childDeviceIds, er := dMgr.getAllChildDeviceIds(ctx, parentDevice); er == nil {
for _, deviceID := range childDeviceIds {
if d, e := dMgr.getDevice(ctx, deviceID); e == nil && d != nil {
childDevices = append(childDevices, d)
@@ -1333,9 +1333,9 @@
// SetupUNILogicalPorts creates UNI ports on the logical device that represents a child UNI interface
func (dMgr *Manager) SetupUNILogicalPorts(ctx context.Context, cDevice *voltha.Device) error {
- logger.Info("addUNILogicalPort")
+ logger.Info(ctx, "addUNILogicalPort")
if err := dMgr.logicalDeviceMgr.setupUNILogicalPorts(ctx, cDevice); err != nil {
- logger.Warnw("addUNILogicalPort-error", log.Fields{"device": cDevice, "err": err})
+ logger.Warnw(ctx, "addUNILogicalPort-error", log.Fields{"device": cDevice, "err": err})
return err
}
return nil
@@ -1346,7 +1346,7 @@
// DownloadImage execute an image download request
func (dMgr *Manager) DownloadImage(ctx context.Context, img *voltha.ImageDownload) (*common.OperationResp, error) {
- logger.Debugw("DownloadImage", log.Fields{"device-id": img.Id, "imageName": img.Name})
+ logger.Debugw(ctx, "DownloadImage", log.Fields{"device-id": img.Id, "imageName": img.Name})
agent := dMgr.getDeviceAgent(ctx, img.Id)
if agent == nil {
return operationFailureResp, status.Errorf(codes.NotFound, "%s", img.Id)
@@ -1360,7 +1360,7 @@
// CancelImageDownload cancels image download request
func (dMgr *Manager) CancelImageDownload(ctx context.Context, img *voltha.ImageDownload) (*common.OperationResp, error) {
- logger.Debugw("CancelImageDownload", log.Fields{"device-id": img.Id, "imageName": img.Name})
+ logger.Debugw(ctx, "CancelImageDownload", log.Fields{"device-id": img.Id, "imageName": img.Name})
agent := dMgr.getDeviceAgent(ctx, img.Id)
if agent == nil {
return operationFailureResp, status.Errorf(codes.NotFound, "%s", img.Id)
@@ -1374,7 +1374,7 @@
// ActivateImageUpdate activates image update request
func (dMgr *Manager) ActivateImageUpdate(ctx context.Context, img *voltha.ImageDownload) (*common.OperationResp, error) {
- logger.Debugw("ActivateImageUpdate", log.Fields{"device-id": img.Id, "imageName": img.Name})
+ logger.Debugw(ctx, "ActivateImageUpdate", log.Fields{"device-id": img.Id, "imageName": img.Name})
agent := dMgr.getDeviceAgent(ctx, img.Id)
if agent == nil {
return operationFailureResp, status.Errorf(codes.NotFound, "%s", img.Id)
@@ -1388,7 +1388,7 @@
// RevertImageUpdate reverts image update
func (dMgr *Manager) RevertImageUpdate(ctx context.Context, img *voltha.ImageDownload) (*common.OperationResp, error) {
- logger.Debugw("RevertImageUpdate", log.Fields{"device-id": img.Id, "imageName": img.Name})
+ logger.Debugw(ctx, "RevertImageUpdate", log.Fields{"device-id": img.Id, "imageName": img.Name})
agent := dMgr.getDeviceAgent(ctx, img.Id)
if agent == nil {
return operationFailureResp, status.Errorf(codes.NotFound, "%s", img.Id)
@@ -1405,7 +1405,7 @@
// GetImageDownloadStatus returns status of image download
func (dMgr *Manager) GetImageDownloadStatus(ctx context.Context, img *voltha.ImageDownload) (*voltha.ImageDownload, error) {
- logger.Debugw("GetImageDownloadStatus", log.Fields{"device-id": img.Id, "imageName": img.Name})
+ logger.Debugw(ctx, "GetImageDownloadStatus", log.Fields{"device-id": img.Id, "imageName": img.Name})
agent := dMgr.getDeviceAgent(ctx, img.Id)
if agent == nil {
return imageDownloadFailureResp, status.Errorf(codes.NotFound, "%s", img.Id)
@@ -1418,10 +1418,10 @@
}
func (dMgr *Manager) UpdateImageDownload(ctx context.Context, deviceID string, img *voltha.ImageDownload) error {
- logger.Debugw("UpdateImageDownload", log.Fields{"device-id": img.Id, "imageName": img.Name})
+ logger.Debugw(ctx, "UpdateImageDownload", log.Fields{"device-id": img.Id, "imageName": img.Name})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
if err := agent.updateImageDownload(ctx, img); err != nil {
- logger.Debugw("UpdateImageDownload-failed", log.Fields{"err": err, "imageName": img.Name})
+ logger.Debugw(ctx, "UpdateImageDownload-failed", log.Fields{"err": err, "imageName": img.Name})
return err
}
} else {
@@ -1432,7 +1432,7 @@
// GetImageDownload returns image download
func (dMgr *Manager) GetImageDownload(ctx context.Context, img *voltha.ImageDownload) (*voltha.ImageDownload, error) {
- logger.Debugw("GetImageDownload", log.Fields{"device-id": img.Id, "imageName": img.Name})
+ logger.Debugw(ctx, "GetImageDownload", log.Fields{"device-id": img.Id, "imageName": img.Name})
agent := dMgr.getDeviceAgent(ctx, img.Id)
if agent == nil {
return imageDownloadFailureResp, status.Errorf(codes.NotFound, "%s", img.Id)
@@ -1446,7 +1446,7 @@
// ListImageDownloads returns image downloads
func (dMgr *Manager) ListImageDownloads(ctx context.Context, id *voltha.ID) (*voltha.ImageDownloads, error) {
- logger.Debugw("ListImageDownloads", log.Fields{"device-id": id.Id})
+ logger.Debugw(ctx, "ListImageDownloads", log.Fields{"device-id": id.Id})
agent := dMgr.getDeviceAgent(ctx, id.Id)
if agent == nil {
return &voltha.ImageDownloads{Items: []*voltha.ImageDownload{imageDownloadFailureResp}}, status.Errorf(codes.NotFound, "%s", id.Id)
@@ -1460,7 +1460,7 @@
// GetImages returns all images for a specific device entry
func (dMgr *Manager) GetImages(ctx context.Context, id *voltha.ID) (*voltha.Images, error) {
- logger.Debugw("GetImages", log.Fields{"device-id": id.Id})
+ logger.Debugw(ctx, "GetImages", log.Fields{"device-id": id.Id})
device, err := dMgr.getDevice(ctx, id.Id)
if err != nil {
return nil, err
@@ -1468,8 +1468,8 @@
return device.GetImages(), nil
}
-func (dMgr *Manager) NotifyInvalidTransition(_ context.Context, device *voltha.Device) error {
- logger.Errorw("NotifyInvalidTransition", log.Fields{
+func (dMgr *Manager) NotifyInvalidTransition(ctx context.Context, device *voltha.Device) error {
+ logger.Errorw(ctx, "NotifyInvalidTransition", log.Fields{
"device": device.Id,
"curr-admin-state": device.AdminState,
"curr-oper-state": device.OperStatus,
@@ -1495,14 +1495,14 @@
// GetParentDeviceID returns parent device id, either from memory or from the dB, if present
func (dMgr *Manager) GetParentDeviceID(ctx context.Context, deviceID string) string {
if device, _ := dMgr.getDevice(ctx, deviceID); device != nil {
- logger.Infow("GetParentDeviceId", log.Fields{"deviceId": device.Id, "parentId": device.ParentId})
+ logger.Infow(ctx, "GetParentDeviceId", log.Fields{"deviceId": device.Id, "parentId": device.ParentId})
return device.ParentId
}
return ""
}
func (dMgr *Manager) SimulateAlarm(ctx context.Context, simulateReq *voltha.SimulateAlarmRequest) (*common.OperationResp, error) {
- logger.Debugw("SimulateAlarm", log.Fields{"id": simulateReq.Id, "Indicator": simulateReq.Indicator, "IntfId": simulateReq.IntfId,
+ logger.Debugw(ctx, "SimulateAlarm", log.Fields{"id": simulateReq.Id, "Indicator": simulateReq.Indicator, "IntfId": simulateReq.IntfId,
"PortTypeName": simulateReq.PortTypeName, "OnuDeviceId": simulateReq.OnuDeviceId, "InverseBitErrorRate": simulateReq.InverseBitErrorRate,
"Drift": simulateReq.Drift, "NewEqd": simulateReq.NewEqd, "OnuSerialNumber": simulateReq.OnuSerialNumber, "Operation": simulateReq.Operation})
agent := dMgr.getDeviceAgent(ctx, simulateReq.Id)
@@ -1516,7 +1516,7 @@
}
func (dMgr *Manager) UpdateDeviceReason(ctx context.Context, deviceID string, reason string) error {
- logger.Debugw("UpdateDeviceReason", log.Fields{"deviceid": deviceID, "reason": reason})
+ logger.Debugw(ctx, "UpdateDeviceReason", log.Fields{"deviceid": deviceID, "reason": reason})
if agent := dMgr.getDeviceAgent(ctx, deviceID); agent != nil {
return agent.updateDeviceReason(ctx, reason)
}
@@ -1524,7 +1524,7 @@
}
func (dMgr *Manager) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
- logger.Debugw("EnablePort", log.Fields{"device-id": port.DeviceId, "port-no": port.PortNo})
+ logger.Debugw(ctx, "EnablePort", log.Fields{"device-id": port.DeviceId, "port-no": port.PortNo})
agent := dMgr.getDeviceAgent(ctx, port.DeviceId)
if agent == nil {
return nil, status.Errorf(codes.NotFound, "%s", port.DeviceId)
@@ -1533,7 +1533,7 @@
}
func (dMgr *Manager) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) {
- logger.Debugw("DisablePort", log.Fields{"device-id": port.DeviceId, "port-no": port.PortNo})
+ logger.Debugw(ctx, "DisablePort", log.Fields{"device-id": port.DeviceId, "port-no": port.PortNo})
agent := dMgr.getDeviceAgent(ctx, port.DeviceId)
if agent == nil {
return nil, status.Errorf(codes.NotFound, "%s", port.DeviceId)
@@ -1543,11 +1543,11 @@
// ChildDeviceLost calls parent adapter to delete child device and all its references
func (dMgr *Manager) ChildDeviceLost(ctx context.Context, curr *voltha.Device) error {
- logger.Debugw("childDeviceLost", log.Fields{"child-device-id": curr.Id, "parent-device-id": curr.ParentId})
+ logger.Debugw(ctx, "childDeviceLost", log.Fields{"child-device-id": curr.Id, "parent-device-id": curr.ParentId})
if parentAgent := dMgr.getDeviceAgent(ctx, curr.ParentId); parentAgent != nil {
if err := parentAgent.ChildDeviceLost(ctx, curr); err != nil {
// Just log the message and let the remaining pipeline proceed.
- logger.Warnw("childDeviceLost", log.Fields{"child-device-id": curr.Id, "parent-device-id": curr.ParentId, "error": err})
+ logger.Warnw(ctx, "childDeviceLost", log.Fields{"child-device-id": curr.Id, "parent-device-id": curr.ParentId, "error": err})
}
}
// Do not return an error as parent device may also have been deleted. Let the remaining pipeline proceed.
@@ -1555,7 +1555,7 @@
}
func (dMgr *Manager) StartOmciTestAction(ctx context.Context, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
- logger.Debugw("StartOmciTestAction", log.Fields{"device-id": request.Id, "uuid": request.Uuid})
+ logger.Debugw(ctx, "StartOmciTestAction", log.Fields{"device-id": request.Id, "uuid": request.Uuid})
agent := dMgr.getDeviceAgent(ctx, request.Id)
if agent == nil {
return nil, status.Errorf(codes.NotFound, "%s", request.Id)