[VOL-3069]Pass Context in methods which are performing logging and need the context
Change-Id: Ie84f9e240aa4f47d0046acaac0d82d21b17252e5
diff --git a/internal/pkg/resourcemanager/resourcemanager.go b/internal/pkg/resourcemanager/resourcemanager.go
index 8ab03f0..3557bbf 100755
--- a/internal/pkg/resourcemanager/resourcemanager.go
+++ b/internal/pkg/resourcemanager/resourcemanager.go
@@ -122,24 +122,24 @@
flowIDToGemInfoLock sync.RWMutex
}
-func newKVClient(storeType string, address string, timeout time.Duration) (kvstore.Client, error) {
- logger.Infow("kv-store-type", log.Fields{"store": storeType})
+func newKVClient(ctx context.Context, storeType string, address string, timeout time.Duration) (kvstore.Client, error) {
+ logger.Infow(ctx, "kv-store-type", log.Fields{"store": storeType})
switch storeType {
case "consul":
- return kvstore.NewConsulClient(address, timeout)
+ return kvstore.NewConsulClient(ctx, address, timeout)
case "etcd":
- return kvstore.NewEtcdClient(address, timeout, log.FatalLevel)
+ return kvstore.NewEtcdClient(ctx, address, timeout, log.FatalLevel)
}
return nil, errors.New("unsupported-kv-store")
}
// SetKVClient sets the KV client and return a kv backend
-func SetKVClient(backend string, addr string, DeviceID string) *db.Backend {
+func SetKVClient(ctx context.Context, backend string, addr string, DeviceID string) *db.Backend {
// TODO : Make sure direct call to NewBackend is working fine with backend , currently there is some
// issue between kv store and backend , core is not calling NewBackend directly
- kvClient, err := newKVClient(backend, addr, KvstoreTimeout)
+ kvClient, err := newKVClient(ctx, backend, addr, KvstoreTimeout)
if err != nil {
- logger.Fatalw("Failed to init KV client\n", log.Fields{"err": err})
+ logger.Fatalw(ctx, "Failed to init KV client\n", log.Fields{"err": err})
return nil
}
@@ -158,16 +158,16 @@
// the resources.
func NewResourceMgr(ctx context.Context, deviceID string, KVStoreAddress string, kvStoreType string, deviceType string, devInfo *openolt.DeviceInfo) *OpenOltResourceMgr {
var ResourceMgr OpenOltResourceMgr
- logger.Debugf("Init new resource manager , address: %s, deviceid: %s", KVStoreAddress, deviceID)
+ logger.Debugf(ctx, "Init new resource manager , address: %s, deviceid: %s", KVStoreAddress, deviceID)
ResourceMgr.Address = KVStoreAddress
ResourceMgr.DeviceType = deviceType
ResourceMgr.DevInfo = devInfo
NumPONPorts := devInfo.GetPonPorts()
Backend := kvStoreType
- ResourceMgr.KVStore = SetKVClient(Backend, ResourceMgr.Address, deviceID)
+ ResourceMgr.KVStore = SetKVClient(ctx, Backend, ResourceMgr.Address, deviceID)
if ResourceMgr.KVStore == nil {
- logger.Error("Failed to setup KV store")
+ logger.Error(ctx, "Failed to setup KV store")
}
Ranges := make(map[string]*openolt.DeviceInfo_DeviceResourceRanges)
RsrcMgrsByTech := make(map[string]*ponrmgr.PONResourceManager)
@@ -230,12 +230,13 @@
var err error
for _, TechRange := range devInfo.Ranges {
technology := TechRange.Technology
- logger.Debugf("Device info technology %s", technology)
+ logger.Debugf(ctx, "Device info technology %s", technology)
Ranges[technology] = TechRange
- RsrcMgrsByTech[technology], err = ponrmgr.NewPONResourceManager(technology, deviceType, deviceID,
+
+ RsrcMgrsByTech[technology], err = ponrmgr.NewPONResourceManager(ctx, technology, deviceType, deviceID,
Backend, ResourceMgr.Address)
if err != nil {
- logger.Errorf("Failed to create pon resource manager instance for technology %s", technology)
+ logger.Errorf(ctx, "Failed to create pon resource manager instance for technology %s", technology)
return nil
}
// resource_mgrs_by_tech[technology] = resource_mgr
@@ -254,7 +255,7 @@
for _, PONRMgr := range RsrcMgrsByTech {
_ = PONRMgr.InitDeviceResourcePool(ctx)
}
- logger.Info("Initialization of resource manager success!")
+ logger.Info(ctx, "Initialization of resource manager success!")
return &ResourceMgr
}
@@ -267,11 +268,11 @@
// init the resource range pool according to the sharing type
- logger.Debugf("Resource range pool init for technology %s", ponRMgr.Technology)
+ logger.Debugf(ctx, "Resource range pool init for technology %s", ponRMgr.Technology)
// first load from KV profiles
status := ponRMgr.InitResourceRangesFromKVStore(ctx)
if !status {
- logger.Debugf("Failed to load resource ranges from KV store for tech %s", ponRMgr.Technology)
+ logger.Debugf(ctx, "Failed to load resource ranges from KV store for tech %s", ponRMgr.Technology)
}
/*
@@ -279,7 +280,7 @@
or is broader than the device, the device's information will
dictate the range limits
*/
- logger.Debugw("Using device info to init pon resource ranges", log.Fields{"Tech": ponRMgr.Technology})
+ logger.Debugw(ctx, "Using device info to init pon resource ranges", log.Fields{"Tech": ponRMgr.Technology})
ONUIDStart := devInfo.OnuIdStart
ONUIDEnd := devInfo.OnuIdEnd
@@ -344,7 +345,7 @@
}
}
- logger.Debugw("Device info init", log.Fields{"technology": techRange.Technology,
+ logger.Debugw(ctx, "Device info init", log.Fields{"technology": techRange.Technology,
"onu_id_start": ONUIDStart, "onu_id_end": ONUIDEnd, "onu_id_shared_pool_id": ONUIDSharedPoolID,
"alloc_id_start": AllocIDStart, "alloc_id_end": AllocIDEnd,
"alloc_id_shared_pool_id": AllocIDSharedPoolID,
@@ -358,7 +359,7 @@
"uni_id_end_idx": 1, /*MaxUNIIDperONU()*/
})
- ponRMgr.InitDefaultPONResourceRanges(ONUIDStart, ONUIDEnd, ONUIDSharedPoolID,
+ ponRMgr.InitDefaultPONResourceRanges(ctx, ONUIDStart, ONUIDEnd, ONUIDSharedPoolID,
AllocIDStart, AllocIDEnd, AllocIDSharedPoolID,
GEMPortIDStart, GEMPortIDEnd, GEMPortIDSharedPoolID,
FlowIDStart, FlowIDEnd, FlowIDSharedPoolID, 0, 1,
@@ -367,33 +368,33 @@
// For global sharing, make sure to refresh both local and global resource manager instances' range
if ONUIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
- globalPONRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
+ globalPONRMgr.UpdateRanges(ctx, ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
"", 0, nil)
- ponRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
+ ponRMgr.UpdateRanges(ctx, ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
"", 0, globalPONRMgr)
}
if AllocIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
- globalPONRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
+ globalPONRMgr.UpdateRanges(ctx, ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
"", 0, nil)
- ponRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
+ ponRMgr.UpdateRanges(ctx, ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
"", 0, globalPONRMgr)
}
if GEMPortIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
- globalPONRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
+ globalPONRMgr.UpdateRanges(ctx, ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
"", 0, nil)
- ponRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
+ ponRMgr.UpdateRanges(ctx, ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
"", 0, globalPONRMgr)
}
if FlowIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
- globalPONRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
+ globalPONRMgr.UpdateRanges(ctx, ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
"", 0, nil)
- ponRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
+ ponRMgr.UpdateRanges(ctx, ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
"", 0, globalPONRMgr)
}
// Make sure loaded range fits the platform bit encoding ranges
- ponRMgr.UpdateRanges(ponrmgr.UNI_ID_START_IDX, 0, ponrmgr.UNI_ID_END_IDX /* TODO =OpenOltPlatform.MAX_UNIS_PER_ONU-1*/, 1, "", 0, nil)
+ ponRMgr.UpdateRanges(ctx, ponrmgr.UNI_ID_START_IDX, 0, ponrmgr.UNI_ID_END_IDX /* TODO =OpenOltPlatform.MAX_UNIS_PER_ONU-1*/, 1, "", 0, nil)
}
// Delete clears used resources for the particular olt device being deleted
@@ -421,11 +422,11 @@
*/
for _, rsrcMgr := range RsrcMgr.ResourceMgrs {
if err := rsrcMgr.ClearDeviceResourcePool(ctx); err != nil {
- logger.Debug("Failed to clear device resource pool")
+ logger.Debug(ctx, "Failed to clear device resource pool")
return err
}
}
- logger.Debug("Cleared device resource pool")
+ logger.Debug(ctx, "Cleared device resource pool")
return nil
}
@@ -443,7 +444,7 @@
ONUID, err := RsrcMgr.ResourceMgrs[ponIntfID].GetResourceID(ctx, ponIntfID,
ponrmgr.ONU_ID, 1)
if err != nil {
- logger.Errorf("Failed to get resource for interface %d for type %s",
+ logger.Errorf(ctx, "Failed to get resource for interface %d for type %s",
ponIntfID, ponrmgr.ONU_ID)
return 0, err
}
@@ -463,11 +464,11 @@
FlowPath := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID)
if err := RsrcMgr.ResourceMgrs[ponIntfID].GetFlowIDInfo(ctx, FlowPath, flowID, &flows); err != nil {
- logger.Errorw("Error while getting flows from KV store", log.Fields{"flowId": flowID})
+ logger.Errorw(ctx, "Error while getting flows from KV store", log.Fields{"flowId": flowID})
return nil
}
if len(flows) == 0 {
- logger.Debugw("No flowInfo found in KV store", log.Fields{"flowPath": FlowPath})
+ logger.Debugw(ctx, "No flowInfo found in KV store", log.Fields{"flowPath": FlowPath})
return nil
}
return &flows
@@ -508,10 +509,10 @@
FlowIDs := RsrcMgr.ResourceMgrs[ponIntfID].GetCurrentFlowIDsForOnu(ctx, FlowPath)
if FlowIDs != nil {
- logger.Debugw("Found flowId(s) for this ONU", log.Fields{"pon": ponIntfID, "ONUID": ONUID, "uniID": uniID, "KVpath": FlowPath})
+ logger.Debugw(ctx, "Found flowId(s) for this ONU", log.Fields{"pon": ponIntfID, "ONUID": ONUID, "uniID": uniID, "KVpath": FlowPath})
for _, flowID := range FlowIDs {
FlowInfo := RsrcMgr.GetFlowIDInfo(ctx, ponIntfID, int32(ONUID), int32(uniID), uint32(flowID))
- er := getFlowIDFromFlowInfo(FlowInfo, flowID, gemportID, flowStoreCookie, flowCategory, vlanVid, vlanPcp...)
+ er := getFlowIDFromFlowInfo(ctx, FlowInfo, flowID, gemportID, flowStoreCookie, flowCategory, vlanVid, vlanPcp...)
if er == nil {
log.Debugw("Found flowid for the vlan, pcp, and gem",
log.Fields{"flowID": flowID, "vlanVid": vlanVid, "vlanPcp": vlanPcp, "gemPortID": gemportID})
@@ -519,11 +520,11 @@
}
}
}
- logger.Debug("No matching flows with flow cookie or flow category, allocating new flowid")
+ logger.Debug(ctx, "No matching flows with flow cookie or flow category, allocating new flowid")
FlowIDs, err = RsrcMgr.ResourceMgrs[ponIntfID].GetResourceID(ctx, ponIntfID,
ponrmgr.FLOW_ID, 1)
if err != nil {
- logger.Errorf("Failed to get resource for interface %d for type %s",
+ logger.Errorf(ctx, "Failed to get resource for interface %d for type %s",
ponIntfID, ponrmgr.FLOW_ID)
return uint32(0), err
}
@@ -551,24 +552,24 @@
// Since we support only one alloc_id for the ONU at the moment,
// return the first alloc_id in the list, if available, for that
// ONU.
- logger.Debugw("Retrieved alloc ID from pon resource mgr", log.Fields{"AllocID": AllocID})
+ logger.Debugw(ctx, "Retrieved alloc ID from pon resource mgr", log.Fields{"AllocID": AllocID})
return AllocID[0]
}
AllocID, err = RsrcMgr.ResourceMgrs[intfID].GetResourceID(ctx, intfID,
ponrmgr.ALLOC_ID, 1)
if AllocID == nil || err != nil {
- logger.Error("Failed to allocate alloc id")
+ logger.Error(ctx, "Failed to allocate alloc id")
return 0
}
// update the resource map on KV store with the list of alloc_id
// allocated for the pon_intf_onu_id tuple
err = RsrcMgr.ResourceMgrs[intfID].UpdateAllocIdsForOnu(ctx, IntfOnuIDUniID, AllocID)
if err != nil {
- logger.Error("Failed to update Alloc ID")
+ logger.Error(ctx, "Failed to update Alloc ID")
return 0
}
- logger.Debugw("Allocated new Tcont from pon resource mgr", log.Fields{"AllocID": AllocID})
+ logger.Debugw(ctx, "Allocated new Tcont from pon resource mgr", log.Fields{"AllocID": AllocID})
return AllocID[0]
}
@@ -612,7 +613,7 @@
}
err := RsrcMgr.UpdateAllocIdsForOnu(ctx, intfID, onuID, uniID, allocIDs)
if err != nil {
- logger.Errorf("Failed to Remove Alloc Id For Onu. IntfID %d onuID %d uniID %d allocID %d",
+ logger.Errorf(ctx, "Failed to Remove Alloc Id For Onu. IntfID %d onuID %d uniID %d allocID %d",
intfID, onuID, uniID, allocID)
}
}
@@ -628,7 +629,7 @@
}
err := RsrcMgr.UpdateGEMPortIDsForOnu(ctx, intfID, onuID, uniID, gemPortIDs)
if err != nil {
- logger.Errorf("Failed to Remove Gem Id For Onu. IntfID %d onuID %d uniID %d gemPortId %d",
+ logger.Errorf(ctx, "Failed to Remove Gem Id For Onu. IntfID %d onuID %d uniID %d gemPortId %d",
intfID, onuID, uniID, gemPortID)
}
}
@@ -646,12 +647,12 @@
IntfGEMPortPath = fmt.Sprintf("%d,%d", PonPort, GEM)
Val, err := json.Marshal(Data)
if err != nil {
- logger.Error("failed to Marshal")
+ logger.Error(ctx, "failed to Marshal")
return err
}
if err = RsrcMgr.KVStore.Put(ctx, IntfGEMPortPath, Val); err != nil {
- logger.Errorf("Failed to update resource %s", IntfGEMPortPath)
+ logger.Errorf(ctx, "Failed to update resource %s", IntfGEMPortPath)
return err
}
}
@@ -663,7 +664,7 @@
IntfGEMPortPath := fmt.Sprintf("%d,%d", PonPort, GemPort)
err := RsrcMgr.KVStore.Delete(ctx, IntfGEMPortPath)
if err != nil {
- logger.Errorf("Failed to Remove Gem port-Pon port to onu map on kv store. Gem %d PonPort %d", GemPort, PonPort)
+ logger.Errorf(ctx, "Failed to Remove Gem port-Pon port to onu map on kv store. Gem %d PonPort %d", GemPort, PonPort)
}
}
@@ -690,7 +691,7 @@
GEMPortList, err = RsrcMgr.ResourceMgrs[ponPort].GetResourceID(ctx, ponPort,
ponrmgr.GEMPORT_ID, NumOfPorts)
if err != nil && GEMPortList == nil {
- logger.Errorf("Failed to get gem port id for %s", IntfOnuIDUniID)
+ logger.Errorf(ctx, "Failed to get gem port id for %s", IntfOnuIDUniID)
return nil, err
}
@@ -699,7 +700,7 @@
err = RsrcMgr.ResourceMgrs[ponPort].UpdateGEMPortIDsForOnu(ctx, IntfOnuIDUniID,
GEMPortList)
if err != nil {
- logger.Errorf("Failed to update GEM ports to kv store for %s", IntfOnuIDUniID)
+ logger.Errorf(ctx, "Failed to update GEM ports to kv store for %s", IntfOnuIDUniID)
return nil, err
}
_ = RsrcMgr.UpdateGEMportsPonportToOnuMapOnKVStore(ctx, GEMPortList, ponPort,
@@ -746,7 +747,7 @@
IntfONUID = fmt.Sprintf("%d,%d,%d", IntfID, onuID, uniID)
err = RsrcMgr.ResourceMgrs[IntfID].UpdateFlowIDForOnu(ctx, IntfONUID, FlowID, false)
if err != nil {
- logger.Errorw("Failed to Update flow id for", log.Fields{"intf": IntfONUID})
+ logger.Errorw(ctx, "Failed to Update flow id for", log.Fields{"intf": IntfONUID})
}
RsrcMgr.ResourceMgrs[IntfID].RemoveFlowIDInfo(ctx, IntfONUID, FlowID)
@@ -767,7 +768,7 @@
IntfOnuIDUniID = fmt.Sprintf("%d,%d,%d", IntfID, onuID, uniID)
err = RsrcMgr.ResourceMgrs[IntfID].UpdateFlowIDForOnu(ctx, IntfOnuIDUniID, flow, false)
if err != nil {
- logger.Errorw("Failed to Update flow id for", log.Fields{"intf": IntfOnuIDUniID})
+ logger.Errorw(ctx, "Failed to Update flow id for", log.Fields{"intf": IntfOnuIDUniID})
}
RsrcMgr.ResourceMgrs[IntfID].RemoveFlowIDInfo(ctx, IntfOnuIDUniID, flow)
}
@@ -843,14 +844,14 @@
FlowPath := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID)
FlowIDs := RsrcMgr.ResourceMgrs[ponIntfID].GetCurrentFlowIDsForOnu(ctx, FlowPath)
if FlowIDs != nil {
- logger.Debugw("Found flowId(s) for this ONU", log.Fields{"pon": ponIntfID, "onuID": onuID, "uniID": uniID, "KVpath": FlowPath})
+ logger.Debugw(ctx, "Found flowId(s) for this ONU", log.Fields{"pon": ponIntfID, "onuID": onuID, "uniID": uniID, "KVpath": FlowPath})
for _, flowID := range FlowIDs {
FlowInfo := RsrcMgr.GetFlowIDInfo(ctx, ponIntfID, int32(onuID), int32(uniID), uint32(flowID))
if FlowInfo != nil {
- logger.Debugw("Found flows", log.Fields{"flows": *FlowInfo, "flowId": flowID})
+ logger.Debugw(ctx, "Found flows", log.Fields{"flows": *FlowInfo, "flowId": flowID})
for _, Info := range *FlowInfo {
if Info.FlowStoreCookie == flowStoreCookie {
- logger.Debug("Found flow matching with flowStore cookie", log.Fields{"flowId": flowID, "flowStoreCookie": flowStoreCookie})
+ logger.Debug(ctx, "Found flow matching with flowStore cookie", log.Fields{"flowId": flowID, "flowStoreCookie": flowStoreCookie})
return true
}
}
@@ -870,18 +871,18 @@
if Value != nil {
Val, err := kvstore.ToByte(Value.Value)
if err != nil {
- logger.Errorw("Failed to convert into byte array", log.Fields{"error": err})
+ logger.Errorw(ctx, "Failed to convert into byte array", log.Fields{"error": err})
return Data
}
if err = json.Unmarshal(Val, &Data); err != nil {
- logger.Error("Failed to unmarshal", log.Fields{"error": err})
+ logger.Error(ctx, "Failed to unmarshal", log.Fields{"error": err})
return Data
}
}
} else {
- logger.Errorf("Failed to get TP id from kvstore for path %s", Path)
+ logger.Errorf(ctx, "Failed to get TP id from kvstore for path %s", Path)
}
- logger.Debugf("Getting TP id %d from path %s", Data, Path)
+ logger.Debugf(ctx, "Getting TP id %d from path %s", Data, Path)
return Data
}
@@ -891,7 +892,7 @@
func (RsrcMgr *OpenOltResourceMgr) RemoveTechProfileIDsForOnu(ctx context.Context, IntfID uint32, OnuID uint32, UniID uint32) error {
IntfOnuUniID := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID)
if err := RsrcMgr.KVStore.Delete(ctx, IntfOnuUniID); err != nil {
- logger.Errorw("Failed to delete techprofile id resource in KV store", log.Fields{"path": IntfOnuUniID})
+ logger.Errorw(ctx, "Failed to delete techprofile id resource in KV store", log.Fields{"path": IntfOnuUniID})
return err
}
return nil
@@ -909,11 +910,11 @@
IntfOnuUniID := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID)
Value, err := json.Marshal(tpIDList)
if err != nil {
- logger.Error("failed to Marshal")
+ logger.Error(ctx, "failed to Marshal")
return err
}
if err = RsrcMgr.KVStore.Put(ctx, IntfOnuUniID, Value); err != nil {
- logger.Errorf("Failed to update resource %s", IntfOnuUniID)
+ logger.Errorf(ctx, "Failed to update resource %s", IntfOnuUniID)
return err
}
return err
@@ -931,19 +932,19 @@
tpIDList := RsrcMgr.GetTechProfileIDForOnu(ctx, IntfID, OnuID, UniID)
for _, value := range tpIDList {
if value == TpID {
- logger.Debugf("TpID %d is already in tpIdList for the path %s", TpID, IntfOnuUniID)
+ logger.Debugf(ctx, "TpID %d is already in tpIdList for the path %s", TpID, IntfOnuUniID)
return err
}
}
- logger.Debugf("updating tp id %d on path %s", TpID, IntfOnuUniID)
+ logger.Debugf(ctx, "updating tp id %d on path %s", TpID, IntfOnuUniID)
tpIDList = append(tpIDList, TpID)
Value, err = json.Marshal(tpIDList)
if err != nil {
- logger.Error("failed to Marshal")
+ logger.Error(ctx, "failed to Marshal")
return err
}
if err = RsrcMgr.KVStore.Put(ctx, IntfOnuUniID, Value); err != nil {
- logger.Errorf("Failed to update resource %s", IntfOnuUniID)
+ logger.Errorf(ctx, "Failed to update resource %s", IntfOnuUniID)
return err
}
return err
@@ -959,11 +960,11 @@
IntfOnuUniID := fmt.Sprintf(MeterIDPathSuffix, IntfID, OnuID, UniID, TpID, Direction)
Value, err = json.Marshal(*MeterConfig)
if err != nil {
- logger.Error("failed to Marshal meter config")
+ logger.Error(ctx, "failed to Marshal meter config")
return err
}
if err = RsrcMgr.KVStore.Put(ctx, IntfOnuUniID, Value); err != nil {
- logger.Errorf("Failed to store meter into KV store %s", IntfOnuUniID)
+ logger.Errorf(ctx, "Failed to store meter into KV store %s", IntfOnuUniID)
return err
}
return err
@@ -978,22 +979,22 @@
Value, err := RsrcMgr.KVStore.Get(ctx, Path)
if err == nil {
if Value != nil {
- logger.Debug("Found meter in KV store", log.Fields{"Direction": Direction})
+ logger.Debug(ctx, "Found meter in KV store", log.Fields{"Direction": Direction})
Val, er := kvstore.ToByte(Value.Value)
if er != nil {
- logger.Errorw("Failed to convert into byte array", log.Fields{"error": er})
+ logger.Errorw(ctx, "Failed to convert into byte array", log.Fields{"error": er})
return nil, er
}
if er = json.Unmarshal(Val, &meterConfig); er != nil {
- logger.Error("Failed to unmarshal meterconfig", log.Fields{"error": er})
+ logger.Error(ctx, "Failed to unmarshal meterconfig", log.Fields{"error": er})
return nil, er
}
} else {
- logger.Debug("meter-does-not-exists-in-KVStore")
+ logger.Debug(ctx, "meter-does-not-exists-in-KVStore")
return nil, err
}
} else {
- logger.Errorf("Failed to get Meter config from kvstore for path %s", Path)
+ logger.Errorf(ctx, "Failed to get Meter config from kvstore for path %s", Path)
}
return &meterConfig, err
@@ -1005,18 +1006,18 @@
UniID uint32, TpID uint32) error {
Path := fmt.Sprintf(MeterIDPathSuffix, IntfID, OnuID, UniID, TpID, Direction)
if err := RsrcMgr.KVStore.Delete(ctx, Path); err != nil {
- logger.Errorf("Failed to delete meter id %s from kvstore ", Path)
+ logger.Errorf(ctx, "Failed to delete meter id %s from kvstore ", Path)
return err
}
return nil
}
-func getFlowIDFromFlowInfo(FlowInfo *[]FlowInfo, flowID, gemportID uint32, flowStoreCookie uint64, flowCategory string,
+func getFlowIDFromFlowInfo(ctx context.Context, FlowInfo *[]FlowInfo, flowID, gemportID uint32, flowStoreCookie uint64, flowCategory string,
vlanVid uint32, vlanPcp ...uint32) error {
if FlowInfo != nil {
for _, Info := range *FlowInfo {
if int32(gemportID) == Info.Flow.GemportId && flowCategory != "" && Info.FlowCategory == flowCategory {
- logger.Debug("Found flow matching with flow category", log.Fields{"flowId": flowID, "FlowCategory": flowCategory})
+ logger.Debug(ctx, "Found flow matching with flow category", log.Fields{"flowId": flowID, "FlowCategory": flowCategory})
if Info.FlowCategory == "HSIA_FLOW" {
if err := checkVlanAndPbitEqualityForFlows(vlanVid, Info, vlanPcp[0]); err == nil {
return nil
@@ -1025,13 +1026,13 @@
}
if int32(gemportID) == Info.Flow.GemportId && flowStoreCookie != 0 && Info.FlowStoreCookie == flowStoreCookie {
if flowCategory != "" && Info.FlowCategory == flowCategory {
- logger.Debug("Found flow matching with flow category", log.Fields{"flowId": flowID, "FlowCategory": flowCategory})
+ logger.Debug(ctx, "Found flow matching with flow category", log.Fields{"flowId": flowID, "FlowCategory": flowCategory})
return nil
}
}
}
}
- logger.Debugw("the flow can be related to a different service", log.Fields{"flow_info": FlowInfo})
+ logger.Debugw(ctx, "the flow can be related to a different service", log.Fields{"flow_info": FlowInfo})
return errors.New("invalid flow-info")
}
@@ -1068,11 +1069,11 @@
var err error
if err = RsrcMgr.ResourceMgrs[intfID].GetOnuGemInfo(ctx, intfID, &onuGemData); err != nil {
- logger.Errorf("failed to get onuifo for intfid %d", intfID)
+ logger.Errorf(ctx, "failed to get onuifo for intfid %d", intfID)
return err
}
if len(onuGemData) == 0 {
- logger.Errorw("failed to ger Onuid info ", log.Fields{"intfid": intfID, "onuid": onuID})
+ logger.Errorw(ctx, "failed to ger Onuid info ", log.Fields{"intfid": intfID, "onuid": onuID})
return err
}
@@ -1080,18 +1081,18 @@
if onugem.OnuID == onuID {
for _, gem := range onuGemData[idx].GemPorts {
if gem == gemPort {
- logger.Debugw("Gem already present in onugem info, skpping addition", log.Fields{"gem": gem})
+ logger.Debugw(ctx, "Gem already present in onugem info, skpping addition", log.Fields{"gem": gem})
return nil
}
}
- logger.Debugw("Added gem to onugem info", log.Fields{"gem": gemPort})
+ logger.Debugw(ctx, "Added gem to onugem info", log.Fields{"gem": gemPort})
onuGemData[idx].GemPorts = append(onuGemData[idx].GemPorts, gemPort)
break
}
}
err = RsrcMgr.ResourceMgrs[intfID].AddOnuGemInfo(ctx, intfID, onuGemData)
if err != nil {
- logger.Error("Failed to add onugem to kv store")
+ logger.Error(ctx, "Failed to add onugem to kv store")
return err
}
return err
@@ -1102,7 +1103,7 @@
var onuGemData []OnuGemInfo
if err := RsrcMgr.ResourceMgrs[IntfID].GetOnuGemInfo(ctx, IntfID, &onuGemData); err != nil {
- logger.Errorf("failed to get onuifo for intfid %d", IntfID)
+ logger.Errorf(ctx, "failed to get onuifo for intfid %d", IntfID)
return nil, err
}
@@ -1115,19 +1116,19 @@
var err error
if err = RsrcMgr.ResourceMgrs[IntfID].GetOnuGemInfo(ctx, IntfID, &onuGemData); err != nil {
- logger.Errorf("failed to get onuifo for intfid %d", IntfID)
+ logger.Errorf(ctx, "failed to get onuifo for intfid %d", IntfID)
return olterrors.NewErrPersistence("get", "OnuGemInfo", IntfID,
log.Fields{"onuGem": onuGem, "intfID": IntfID}, err)
}
onuGemData = append(onuGemData, onuGem)
err = RsrcMgr.ResourceMgrs[IntfID].AddOnuGemInfo(ctx, IntfID, onuGemData)
if err != nil {
- logger.Error("Failed to add onugem to kv store")
+ logger.Error(ctx, "Failed to add onugem to kv store")
return olterrors.NewErrPersistence("set", "OnuGemInfo", IntfID,
log.Fields{"onuGemData": onuGemData, "intfID": IntfID}, err)
}
- logger.Debugw("added onu to onugeminfo", log.Fields{"intf": IntfID, "onugem": onuGem})
+ logger.Debugw(ctx, "added onu to onugeminfo", log.Fields{"intf": IntfID, "onugem": onuGem})
return nil
}
@@ -1137,14 +1138,14 @@
var err error
if err = RsrcMgr.ResourceMgrs[intfID].GetOnuGemInfo(ctx, intfID, &onuGemData); err != nil {
- logger.Errorf("failed to get onuifo for intfid %d", intfID)
+ logger.Errorf(ctx, "failed to get onuifo for intfid %d", intfID)
return
}
for idx, onu := range onuGemData {
if onu.OnuID == onuID {
for _, uni := range onu.UniPorts {
if uni == portNo {
- logger.Debugw("uni already present in onugem info", log.Fields{"uni": portNo})
+ logger.Debugw(ctx, "uni already present in onugem info", log.Fields{"uni": portNo})
return
}
}
@@ -1154,7 +1155,7 @@
}
err = RsrcMgr.ResourceMgrs[intfID].AddOnuGemInfo(ctx, intfID, onuGemData)
if err != nil {
- logger.Errorw("Failed to add uin port in onugem to kv store", log.Fields{"uni": portNo})
+ logger.Errorw(ctx, "Failed to add uin port in onugem to kv store", log.Fields{"uni": portNo})
return
}
return
@@ -1166,14 +1167,14 @@
path := fmt.Sprintf(OnuPacketINPath, pktIn.IntfID, pktIn.OnuID, pktIn.LogicalPort)
Value, err := json.Marshal(gemPort)
if err != nil {
- logger.Error("Failed to marshal data")
+ logger.Error(ctx, "Failed to marshal data")
return
}
if err = RsrcMgr.KVStore.Put(ctx, path, Value); err != nil {
- logger.Errorw("Failed to put to kvstore", log.Fields{"path": path, "value": gemPort})
+ logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"path": path, "value": gemPort})
return
}
- logger.Debugw("added gem packet in successfully", log.Fields{"path": path, "gem": gemPort})
+ logger.Debugw(ctx, "added gem packet in successfully", log.Fields{"path": path, "gem": gemPort})
return
}
@@ -1188,22 +1189,22 @@
value, err := RsrcMgr.KVStore.Get(ctx, path)
if err != nil {
- logger.Errorw("Failed to get from kv store", log.Fields{"path": path})
+ logger.Errorw(ctx, "Failed to get from kv store", log.Fields{"path": path})
return uint32(0), err
} else if value == nil {
- logger.Debugw("No pkt in gem found", log.Fields{"path": path})
+ logger.Debugw(ctx, "No pkt in gem found", log.Fields{"path": path})
return uint32(0), nil
}
if Val, err = kvstore.ToByte(value.Value); err != nil {
- logger.Error("Failed to convert to byte array")
+ logger.Error(ctx, "Failed to convert to byte array")
return uint32(0), err
}
if err = json.Unmarshal(Val, &gemPort); err != nil {
- logger.Error("Failed to unmarshall")
+ logger.Error(ctx, "Failed to unmarshall")
return uint32(0), err
}
- logger.Debugw("found packein gemport from path", log.Fields{"path": path, "gem": gemPort})
+ logger.Debugw(ctx, "found packein gemport from path", log.Fields{"path": path, "gem": gemPort})
return gemPort, nil
}
@@ -1213,7 +1214,7 @@
path := fmt.Sprintf(OnuPacketINPath, intfID, onuID, logicalPort)
if err := RsrcMgr.KVStore.Delete(ctx, path); err != nil {
- logger.Errorf("Falied to remove resource %s", path)
+ logger.Errorf(ctx, "Falied to remove resource %s", path)
return err
}
return nil
@@ -1222,7 +1223,7 @@
// DelOnuGemInfoForIntf deletes the onugem info from kvstore per interface
func (RsrcMgr *OpenOltResourceMgr) DelOnuGemInfoForIntf(ctx context.Context, intfID uint32) error {
if err := RsrcMgr.ResourceMgrs[intfID].DelOnuGemInfoForIntf(ctx, intfID); err != nil {
- logger.Errorw("failed to delete onu gem info for", log.Fields{"intfid": intfID})
+ logger.Errorw(ctx, "failed to delete onu gem info for", log.Fields{"intfid": intfID})
return err
}
return nil
@@ -1237,16 +1238,16 @@
path := fmt.Sprintf(NnniIntfID)
value, err := RsrcMgr.KVStore.Get(ctx, path)
if err != nil {
- logger.Error("failed to get data from kv store")
+ logger.Error(ctx, "failed to get data from kv store")
return nil, err
}
if value != nil {
if Val, err = kvstore.ToByte(value.Value); err != nil {
- logger.Error("Failed to convert to byte array")
+ logger.Error(ctx, "Failed to convert to byte array")
return nil, err
}
if err = json.Unmarshal(Val, &nni); err != nil {
- logger.Error("Failed to unmarshall")
+ logger.Error(ctx, "Failed to unmarshall")
return nil, err
}
}
@@ -1259,7 +1260,7 @@
nni, err := RsrcMgr.GetNNIFromKVStore(ctx)
if err != nil {
- logger.Error("failed to fetch nni interfaces from kv store")
+ logger.Error(ctx, "failed to fetch nni interfaces from kv store")
return err
}
@@ -1267,13 +1268,13 @@
nni = append(nni, nniIntf)
Value, err = json.Marshal(nni)
if err != nil {
- logger.Error("Failed to marshal data")
+ logger.Error(ctx, "Failed to marshal data")
}
if err = RsrcMgr.KVStore.Put(ctx, path, Value); err != nil {
- logger.Errorw("Failed to put to kvstore", log.Fields{"path": path, "value": Value})
+ logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"path": path, "value": Value})
return err
}
- logger.Debugw("added nni to kv successfully", log.Fields{"path": path, "nni": nniIntf})
+ logger.Debugw(ctx, "added nni to kv successfully", log.Fields{"path": path, "nni": nniIntf})
return nil
}
@@ -1283,7 +1284,7 @@
path := fmt.Sprintf(NnniIntfID)
if err := RsrcMgr.KVStore.Delete(ctx, path); err != nil {
- logger.Errorw("Failed to delete nni interfaces from kv store", log.Fields{"path": path})
+ logger.Errorw(ctx, "Failed to delete nni interfaces from kv store", log.Fields{"path": path})
return err
}
return nil
@@ -1296,7 +1297,7 @@
flowsForGem, err := RsrcMgr.GetFlowIDsGemMapForInterface(ctx, intf)
if err != nil {
- logger.Error("Failed to ger flowids for interface", log.Fields{"error": err, "intf": intf})
+ logger.Error(ctx, "Failed to ger flowids for interface", log.Fields{"error": err, "intf": intf})
return err
}
if flowsForGem == nil {
@@ -1305,17 +1306,17 @@
flowsForGem[gem] = flowIDs
val, err = json.Marshal(flowsForGem)
if err != nil {
- logger.Error("Failed to marshal data", log.Fields{"error": err})
+ logger.Error(ctx, "Failed to marshal data", log.Fields{"error": err})
return err
}
RsrcMgr.flowIDToGemInfoLock.Lock()
defer RsrcMgr.flowIDToGemInfoLock.Unlock()
if err = RsrcMgr.KVStore.Put(ctx, path, val); err != nil {
- logger.Errorw("Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val})
+ logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val})
return err
}
- logger.Debugw("added flowid list for gem to kv successfully", log.Fields{"path": path, "flowidlist": flowsForGem[gem]})
+ logger.Debugw(ctx, "added flowid list for gem to kv successfully", log.Fields{"path": path, "flowidlist": flowsForGem[gem]})
return nil
}
@@ -1326,11 +1327,11 @@
flowsForGem, err := RsrcMgr.GetFlowIDsGemMapForInterface(ctx, intf)
if err != nil {
- logger.Error("Failed to ger flowids for interface", log.Fields{"error": err, "intf": intf})
+ logger.Error(ctx, "Failed to ger flowids for interface", log.Fields{"error": err, "intf": intf})
return
}
if flowsForGem == nil {
- logger.Error("No flowids found ", log.Fields{"intf": intf, "gemport": gem})
+ logger.Error(ctx, "No flowids found ", log.Fields{"intf": intf, "gemport": gem})
return
}
// once we get the flows per gem map from kv , just delete the gem entry from the map
@@ -1338,14 +1339,14 @@
// once gem entry is deleted update the kv store.
val, err = json.Marshal(flowsForGem)
if err != nil {
- logger.Error("Failed to marshal data", log.Fields{"error": err})
+ logger.Error(ctx, "Failed to marshal data", log.Fields{"error": err})
return
}
RsrcMgr.flowIDToGemInfoLock.Lock()
defer RsrcMgr.flowIDToGemInfoLock.Unlock()
if err = RsrcMgr.KVStore.Put(ctx, path, val); err != nil {
- logger.Errorw("Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val})
+ logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val})
return
}
return
@@ -1360,16 +1361,16 @@
value, err := RsrcMgr.KVStore.Get(ctx, path)
RsrcMgr.flowIDToGemInfoLock.RUnlock()
if err != nil {
- logger.Error("failed to get data from kv store")
+ logger.Error(ctx, "failed to get data from kv store")
return nil, err
}
if value != nil && value.Value != nil {
if val, err = kvstore.ToByte(value.Value); err != nil {
- logger.Error("Failed to convert to byte array ", log.Fields{"error": err})
+ logger.Error(ctx, "Failed to convert to byte array ", log.Fields{"error": err})
return nil, err
}
if err = json.Unmarshal(val, &flowsForGem); err != nil {
- logger.Error("Failed to unmarshall", log.Fields{"error": err})
+ logger.Error(ctx, "Failed to unmarshall", log.Fields{"error": err})
return nil, err
}
}
@@ -1382,7 +1383,7 @@
RsrcMgr.flowIDToGemInfoLock.Lock()
defer RsrcMgr.flowIDToGemInfoLock.Unlock()
if err := RsrcMgr.KVStore.Delete(ctx, path); err != nil {
- logger.Errorw("Failed to delete nni interfaces from kv store", log.Fields{"path": path})
+ logger.Errorw(ctx, "Failed to delete nni interfaces from kv store", log.Fields{"path": path})
return
}
return
@@ -1402,16 +1403,16 @@
kvPair, err := RsrcMgr.KVStore.Get(ctx, path)
if err != nil {
- logger.Error("failed to get data from kv store")
+ logger.Error(ctx, "failed to get data from kv store")
return nil, err
}
if kvPair != nil && kvPair.Value != nil {
if val, err = kvstore.ToByte(kvPair.Value); err != nil {
- logger.Error("Failed to convert to byte array ", log.Fields{"error": err})
+ logger.Error(ctx, "Failed to convert to byte array ", log.Fields{"error": err})
return nil, err
}
if err = json.Unmarshal(val, &mcastQueueToIntfMap); err != nil {
- logger.Error("Failed to unmarshall ", log.Fields{"error": err})
+ logger.Error(ctx, "Failed to unmarshall ", log.Fields{"error": err})
return nil, err
}
}
@@ -1425,7 +1426,7 @@
mcastQueues, err := RsrcMgr.GetMcastQueuePerInterfaceMap(ctx)
if err != nil {
- logger.Errorw("Failed to get multicast queue info for interface", log.Fields{"error": err, "intf": intf})
+ logger.Errorw(ctx, "Failed to get multicast queue info for interface", log.Fields{"error": err, "intf": intf})
return err
}
if mcastQueues == nil {
@@ -1433,14 +1434,14 @@
}
mcastQueues[intf] = []uint32{gem, servicePriority}
if val, err = json.Marshal(mcastQueues); err != nil {
- logger.Errorw("Failed to marshal data", log.Fields{"error": err})
+ logger.Errorw(ctx, "Failed to marshal data", log.Fields{"error": err})
return err
}
if err = RsrcMgr.KVStore.Put(ctx, path, val); err != nil {
- logger.Errorw("Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val})
+ logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val})
return err
}
- logger.Debugw("added multicast queue info to KV store successfully", log.Fields{"path": path, "mcastQueueInfo": mcastQueues[intf], "interfaceId": intf})
+ logger.Debugw(ctx, "added multicast queue info to KV store successfully", log.Fields{"path": path, "mcastQueueInfo": mcastQueues[intf], "interfaceId": intf})
return nil
}
@@ -1471,12 +1472,12 @@
Value, err = json.Marshal(groupInfo)
if err != nil {
- logger.Error("failed to Marshal flow group object")
+ logger.Error(ctx, "failed to Marshal flow group object")
return err
}
if err = RsrcMgr.KVStore.Put(ctx, path, Value); err != nil {
- logger.Errorf("Failed to update resource %s", path)
+ logger.Errorf(ctx, "Failed to update resource %s", path)
return err
}
return nil
@@ -1491,7 +1492,7 @@
path = fmt.Sprintf(FlowGroup, groupID)
}
if err := RsrcMgr.KVStore.Delete(ctx, path); err != nil {
- logger.Errorf("Failed to remove resource %s due to %s", path, err)
+ logger.Errorf(ctx, "Failed to remove resource %s due to %s", path, err)
return false
}
return true
@@ -1515,11 +1516,11 @@
if kvPair != nil && kvPair.Value != nil {
Val, err := kvstore.ToByte(kvPair.Value)
if err != nil {
- logger.Errorw("Failed to convert flow group into byte array", log.Fields{"error": err})
+ logger.Errorw(ctx, "Failed to convert flow group into byte array", log.Fields{"error": err})
return false, groupInfo, err
}
if err = json.Unmarshal(Val, &groupInfo); err != nil {
- logger.Errorw("Failed to unmarshal", log.Fields{"error": err})
+ logger.Errorw(ctx, "Failed to unmarshal", log.Fields{"error": err})
return false, groupInfo, err
}
return true, groupInfo, nil