[VOL-3069]Pass Context in methods which are performing logging and need the context
Change-Id: Ie84f9e240aa4f47d0046acaac0d82d21b17252e5
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/techprofile/tech_profile.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/techprofile/tech_profile.go
index ff37326..a12df1d 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/techprofile/tech_profile.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/techprofile/tech_profile.go
@@ -379,10 +379,10 @@
epon = "EPON"
)
-func (t *TechProfileMgr) SetKVClient() *db.Backend {
- kvClient, err := newKVClient(t.config.KVStoreType, t.config.KVStoreAddress, t.config.KVStoreTimeout)
+func (t *TechProfileMgr) SetKVClient(ctx context.Context) *db.Backend {
+ kvClient, err := newKVClient(ctx, t.config.KVStoreType, t.config.KVStoreAddress, t.config.KVStoreTimeout)
if err != nil {
- logger.Errorw("failed-to-create-kv-client",
+ logger.Errorw(ctx, "failed-to-create-kv-client",
log.Fields{
"type": t.config.KVStoreType, "address": t.config.KVStoreAddress,
"timeout": t.config.KVStoreTimeout, "prefix": t.config.TPKVPathPrefix,
@@ -404,34 +404,34 @@
*/
}
-func newKVClient(storeType string, address string, timeout time.Duration) (kvstore.Client, error) {
+func newKVClient(ctx context.Context, storeType string, address string, timeout time.Duration) (kvstore.Client, error) {
- logger.Infow("kv-store", log.Fields{"storeType": storeType, "address": address})
+ logger.Infow(ctx, "kv-store", log.Fields{"storeType": storeType, "address": address})
switch storeType {
case "consul":
- return kvstore.NewConsulClient(address, timeout)
+ return kvstore.NewConsulClient(ctx, address, timeout)
case "etcd":
- return kvstore.NewEtcdClient(address, timeout, log.WarnLevel)
+ return kvstore.NewEtcdClient(ctx, address, timeout, log.WarnLevel)
}
return nil, errors.New("unsupported-kv-store")
}
-func NewTechProfile(resourceMgr iPonResourceMgr, KVStoreType string, KVStoreAddress string) (*TechProfileMgr, error) {
+func NewTechProfile(ctx context.Context, resourceMgr iPonResourceMgr, KVStoreType string, KVStoreAddress string) (*TechProfileMgr, error) {
var techprofileObj TechProfileMgr
- logger.Debug("Initializing techprofile Manager")
+ logger.Debug(ctx, "Initializing techprofile Manager")
techprofileObj.config = NewTechProfileFlags(KVStoreType, KVStoreAddress)
- techprofileObj.config.KVBackend = techprofileObj.SetKVClient()
+ techprofileObj.config.KVBackend = techprofileObj.SetKVClient(ctx)
if techprofileObj.config.KVBackend == nil {
- logger.Error("Failed to initialize KV backend\n")
+ logger.Error(ctx, "Failed to initialize KV backend\n")
return nil, errors.New("KV backend init failed")
}
techprofileObj.resourceMgr = resourceMgr
- logger.Debug("Initializing techprofile object instance success")
+ logger.Debug(ctx, "Initializing techprofile object instance success")
return &techprofileObj, nil
}
-func (t *TechProfileMgr) GetTechProfileInstanceKVPath(techProfiletblID uint32, uniPortName string) string {
- logger.Debugw("get-tp-instance-kv-path", log.Fields{
+func (t *TechProfileMgr) GetTechProfileInstanceKVPath(ctx context.Context, techProfiletblID uint32, uniPortName string) string {
+ logger.Debugw(ctx, "get-tp-instance-kv-path", log.Fields{
"uniPortName": uniPortName,
"tpId": techProfiletblID,
})
@@ -460,12 +460,12 @@
kvResult, _ = t.config.KVBackend.Get(ctx, path)
if kvResult == nil {
- log.Infow("tp-instance-not-found-on-kv", log.Fields{"key": path})
+ logger.Infow(ctx, "tp-instance-not-found-on-kv", log.Fields{"key": path})
return nil, nil
} else {
if value, err := kvstore.ToByte(kvResult.Value); err == nil {
if err = json.Unmarshal(value, resPtr); err != nil {
- log.Errorw("error-unmarshal-kv-result", log.Fields{"key": path, "value": value})
+ logger.Errorw(ctx, "error-unmarshal-kv-result", log.Fields{"key": path, "value": value})
return nil, errors.New("error-unmarshal-kv-result")
} else {
return resPtr, nil
@@ -476,29 +476,29 @@
}
func (t *TechProfileMgr) addTechProfInstanceToKVStore(ctx context.Context, techProfiletblID uint32, uniPortName string, tpInstance *TechProfile) error {
- path := t.GetTechProfileInstanceKVPath(techProfiletblID, uniPortName)
- logger.Debugw("Adding techprof instance to kvstore", log.Fields{"key": path, "tpinstance": tpInstance})
+ path := t.GetTechProfileInstanceKVPath(ctx, techProfiletblID, uniPortName)
+ logger.Debugw(ctx, "Adding techprof instance to kvstore", log.Fields{"key": path, "tpinstance": tpInstance})
tpInstanceJson, err := json.Marshal(*tpInstance)
if err == nil {
// Backend will convert JSON byte array into string format
- logger.Debugw("Storing tech profile instance to KV Store", log.Fields{"key": path, "val": tpInstanceJson})
+ logger.Debugw(ctx, "Storing tech profile instance to KV Store", log.Fields{"key": path, "val": tpInstanceJson})
err = t.config.KVBackend.Put(ctx, path, tpInstanceJson)
} else {
- logger.Errorw("Error in marshaling into Json format", log.Fields{"key": path, "tpinstance": tpInstance})
+ logger.Errorw(ctx, "Error in marshaling into Json format", log.Fields{"key": path, "tpinstance": tpInstance})
}
return err
}
func (t *TechProfileMgr) addEponProfInstanceToKVStore(ctx context.Context, techProfiletblID uint32, uniPortName string, tpInstance *EponProfile) error {
- path := t.GetTechProfileInstanceKVPath(techProfiletblID, uniPortName)
- logger.Debugw("Adding techprof instance to kvstore", log.Fields{"key": path, "tpinstance": tpInstance})
+ path := t.GetTechProfileInstanceKVPath(ctx, techProfiletblID, uniPortName)
+ logger.Debugw(ctx, "Adding techprof instance to kvstore", log.Fields{"key": path, "tpinstance": tpInstance})
tpInstanceJson, err := json.Marshal(*tpInstance)
if err == nil {
// Backend will convert JSON byte array into string format
- logger.Debugw("Storing tech profile instance to KV Store", log.Fields{"key": path, "val": tpInstanceJson})
+ logger.Debugw(ctx, "Storing tech profile instance to KV Store", log.Fields{"key": path, "val": tpInstanceJson})
err = t.config.KVBackend.Put(ctx, path, tpInstanceJson)
} else {
- logger.Errorw("Error in marshaling into Json format", log.Fields{"key": path, "tpinstance": tpInstance})
+ logger.Errorw(ctx, "Error in marshaling into Json format", log.Fields{"key": path, "tpinstance": tpInstance})
}
return err
}
@@ -506,21 +506,21 @@
func (t *TechProfileMgr) getTPFromKVStore(ctx context.Context, techProfiletblID uint32) *DefaultTechProfile {
var kvtechprofile DefaultTechProfile
key := fmt.Sprintf(t.config.TPFileKVPath, t.resourceMgr.GetTechnology(), techProfiletblID)
- logger.Debugw("Getting techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "Key": key})
+ logger.Debugw(ctx, "Getting techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "Key": key})
kvresult, err := t.config.KVBackend.Get(ctx, key)
if err != nil {
- logger.Errorw("Error while fetching value from KV store", log.Fields{"key": key})
+ logger.Errorw(ctx, "Error while fetching value from KV store", log.Fields{"key": key})
return nil
}
if kvresult != nil {
/* Backend will return Value in string format,needs to be converted to []byte before unmarshal*/
if value, err := kvstore.ToByte(kvresult.Value); err == nil {
if err = json.Unmarshal(value, &kvtechprofile); err != nil {
- logger.Errorw("Error unmarshaling techprofile fetched from KV store", log.Fields{"techProfiletblID": techProfiletblID, "error": err, "techprofile_json": value})
+ logger.Errorw(ctx, "Error unmarshaling techprofile fetched from KV store", log.Fields{"techProfiletblID": techProfiletblID, "error": err, "techprofile_json": value})
return nil
}
- logger.Debugw("Success fetched techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "value": kvtechprofile})
+ logger.Debugw(ctx, "Success fetched techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "value": kvtechprofile})
return &kvtechprofile
}
}
@@ -530,21 +530,21 @@
func (t *TechProfileMgr) getEponTPFromKVStore(ctx context.Context, techProfiletblID uint32) *DefaultEponProfile {
var kvtechprofile DefaultEponProfile
key := fmt.Sprintf(t.config.TPFileKVPath, t.resourceMgr.GetTechnology(), techProfiletblID)
- logger.Debugw("Getting techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "Key": key})
+ logger.Debugw(ctx, "Getting techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "Key": key})
kvresult, err := t.config.KVBackend.Get(ctx, key)
if err != nil {
- logger.Errorw("Error while fetching value from KV store", log.Fields{"key": key})
+ logger.Errorw(ctx, "Error while fetching value from KV store", log.Fields{"key": key})
return nil
}
if kvresult != nil {
/* Backend will return Value in string format,needs to be converted to []byte before unmarshal*/
if value, err := kvstore.ToByte(kvresult.Value); err == nil {
if err = json.Unmarshal(value, &kvtechprofile); err != nil {
- logger.Errorw("Error unmarshaling techprofile fetched from KV store", log.Fields{"techProfiletblID": techProfiletblID, "error": err, "techprofile_json": value})
+ logger.Errorw(ctx, "Error unmarshaling techprofile fetched from KV store", log.Fields{"techProfiletblID": techProfiletblID, "error": err, "techprofile_json": value})
return nil
}
- logger.Debugw("Success fetched techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "value": kvtechprofile})
+ logger.Debugw(ctx, "Success fetched techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "value": kvtechprofile})
return &kvtechprofile
}
}
@@ -555,14 +555,14 @@
var tpInstance *TechProfile
var tpEponInstance *EponProfile
- logger.Infow("creating-tp-instance", log.Fields{"tableid": techProfiletblID, "uni": uniPortName, "intId": intfId})
+ logger.Infow(ctx, "creating-tp-instance", log.Fields{"tableid": techProfiletblID, "uni": uniPortName, "intId": intfId})
// Make sure the uniPortName is as per format pon-{[0-9]+}/onu-{[0-9]+}/uni-{[0-9]+}
if !uniPortNameFormat.Match([]byte(uniPortName)) {
- logger.Errorw("uni-port-name-not-confirming-to-format", log.Fields{"uniPortName": uniPortName})
+ logger.Errorw(ctx, "uni-port-name-not-confirming-to-format", log.Fields{"uniPortName": uniPortName})
return nil, errors.New("uni-port-name-not-confirming-to-format")
}
- tpInstancePath := t.GetTechProfileInstanceKVPath(techProfiletblID, uniPortName)
+ tpInstancePath := t.GetTechProfileInstanceKVPath(ctx, techProfiletblID, uniPortName)
// For example:
// tpInstPath like "XGS-PON/64/uni_port_name"
// is broken into ["XGS-PON" "64" ...]
@@ -570,74 +570,74 @@
if pathSlice[0] == epon {
tp := t.getEponTPFromKVStore(ctx, techProfiletblID)
if tp != nil {
- if err := t.validateInstanceControlAttr(tp.InstanceCtrl); err != nil {
- logger.Error("invalid-instance-ctrl-attr--using-default-tp")
+ if err := t.validateInstanceControlAttr(ctx, tp.InstanceCtrl); err != nil {
+ logger.Error(ctx, "invalid-instance-ctrl-attr--using-default-tp")
tp = t.getDefaultEponProfile()
} else {
- logger.Infow("using-specified-tp-from-kv-store", log.Fields{"tpid": techProfiletblID})
+ logger.Infow(ctx, "using-specified-tp-from-kv-store", log.Fields{"tpid": techProfiletblID})
}
} else {
- logger.Info("tp-not-found-on-kv--creating-default-tp")
+ logger.Info(ctx, "tp-not-found-on-kv--creating-default-tp")
tp = t.getDefaultEponProfile()
}
if tpEponInstance = t.allocateEponTPInstance(ctx, uniPortName, tp, intfId, tpInstancePath); tpEponInstance == nil {
- logger.Error("tp-intance-allocation-failed")
+ logger.Error(ctx, "tp-intance-allocation-failed")
return nil, errors.New("tp-intance-allocation-failed")
}
if err := t.addEponProfInstanceToKVStore(ctx, techProfiletblID, uniPortName, tpEponInstance); err != nil {
- logger.Errorw("error-adding-tp-to-kv-store", log.Fields{"tableid": techProfiletblID, "uni": uniPortName})
+ logger.Errorw(ctx, "error-adding-tp-to-kv-store", log.Fields{"tableid": techProfiletblID, "uni": uniPortName})
return nil, errors.New("error-adding-tp-to-kv-store")
}
- logger.Infow("tp-added-to-kv-store-successfully",
+ logger.Infow(ctx, "tp-added-to-kv-store-successfully",
log.Fields{"tpid": techProfiletblID, "uni": uniPortName, "intfId": intfId})
return tpEponInstance, nil
} else {
tp := t.getTPFromKVStore(ctx, techProfiletblID)
if tp != nil {
- if err := t.validateInstanceControlAttr(tp.InstanceCtrl); err != nil {
- logger.Error("invalid-instance-ctrl-attr--using-default-tp")
- tp = t.getDefaultTechProfile()
+ if err := t.validateInstanceControlAttr(ctx, tp.InstanceCtrl); err != nil {
+ logger.Error(ctx, "invalid-instance-ctrl-attr--using-default-tp")
+ tp = t.getDefaultTechProfile(ctx)
} else {
- logger.Infow("using-specified-tp-from-kv-store", log.Fields{"tpid": techProfiletblID})
+ logger.Infow(ctx, "using-specified-tp-from-kv-store", log.Fields{"tpid": techProfiletblID})
}
} else {
- logger.Info("tp-not-found-on-kv--creating-default-tp")
- tp = t.getDefaultTechProfile()
+ logger.Info(ctx, "tp-not-found-on-kv--creating-default-tp")
+ tp = t.getDefaultTechProfile(ctx)
}
if tpInstance = t.allocateTPInstance(ctx, uniPortName, tp, intfId, tpInstancePath); tpInstance == nil {
- logger.Error("tp-intance-allocation-failed")
+ logger.Error(ctx, "tp-intance-allocation-failed")
return nil, errors.New("tp-intance-allocation-failed")
}
if err := t.addTechProfInstanceToKVStore(ctx, techProfiletblID, uniPortName, tpInstance); err != nil {
- logger.Errorw("error-adding-tp-to-kv-store", log.Fields{"tableid": techProfiletblID, "uni": uniPortName})
+ logger.Errorw(ctx, "error-adding-tp-to-kv-store", log.Fields{"tableid": techProfiletblID, "uni": uniPortName})
return nil, errors.New("error-adding-tp-to-kv-store")
}
- logger.Infow("tp-added-to-kv-store-successfully",
+ logger.Infow(ctx, "tp-added-to-kv-store-successfully",
log.Fields{"tpid": techProfiletblID, "uni": uniPortName, "intfId": intfId})
return tpInstance, nil
}
}
func (t *TechProfileMgr) DeleteTechProfileInstance(ctx context.Context, techProfiletblID uint32, uniPortName string) error {
- path := t.GetTechProfileInstanceKVPath(techProfiletblID, uniPortName)
+ path := t.GetTechProfileInstanceKVPath(ctx, techProfiletblID, uniPortName)
return t.config.KVBackend.Delete(ctx, path)
}
-func (t *TechProfileMgr) validateInstanceControlAttr(instCtl InstanceControl) error {
+func (t *TechProfileMgr) validateInstanceControlAttr(ctx context.Context, instCtl InstanceControl) error {
if instCtl.Onu != "single-instance" && instCtl.Onu != "multi-instance" {
- logger.Errorw("invalid-onu-instance-control-attribute", log.Fields{"onu-inst": instCtl.Onu})
+ logger.Errorw(ctx, "invalid-onu-instance-control-attribute", log.Fields{"onu-inst": instCtl.Onu})
return errors.New("invalid-onu-instance-ctl-attr")
}
if instCtl.Uni != "single-instance" && instCtl.Uni != "multi-instance" {
- logger.Errorw("invalid-uni-instance-control-attribute", log.Fields{"uni-inst": instCtl.Uni})
+ logger.Errorw(ctx, "invalid-uni-instance-control-attribute", log.Fields{"uni-inst": instCtl.Uni})
return errors.New("invalid-uni-instance-ctl-attr")
}
if instCtl.Uni == "multi-instance" {
- logger.Error("uni-multi-instance-tp-not-supported")
+ logger.Error(ctx, "uni-multi-instance-tp-not-supported")
return errors.New("uni-multi-instance-tp-not-supported")
}
@@ -654,19 +654,19 @@
var gemPorts []uint32
var err error
- logger.Infow("Allocating TechProfileMgr instance from techprofile template", log.Fields{"uniPortName": uniPortName, "intfId": intfId, "numGem": tp.NumGemPorts})
+ logger.Infow(ctx, "Allocating TechProfileMgr instance from techprofile template", log.Fields{"uniPortName": uniPortName, "intfId": intfId, "numGem": tp.NumGemPorts})
if tp.InstanceCtrl.Onu == "multi-instance" {
t.AllocIDMgmtLock.Lock()
tcontIDs, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeAllocID(), 1)
t.AllocIDMgmtLock.Unlock()
if err != nil {
- logger.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId})
+ logger.Errorw(ctx, "Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId})
return nil
}
} else { // "single-instance"
if tpInst, err := t.getSingleInstanceTp(ctx, tpInstPath); err != nil {
- logger.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId})
+ logger.Errorw(ctx, "Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId})
return nil
} else if tpInst == nil {
// No "single-instance" tp found on one any uni port for the given TP ID
@@ -675,7 +675,7 @@
tcontIDs, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeAllocID(), 1)
t.AllocIDMgmtLock.Unlock()
if err != nil {
- logger.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId})
+ logger.Errorw(ctx, "Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId})
return nil
}
} else {
@@ -683,15 +683,15 @@
tcontIDs = append(tcontIDs, tpInst.UsScheduler.AllocID)
}
}
- logger.Debugw("Num GEM ports in TP:", log.Fields{"NumGemPorts": tp.NumGemPorts})
+ logger.Debugw(ctx, "Num GEM ports in TP:", log.Fields{"NumGemPorts": tp.NumGemPorts})
t.GemPortIDMgmtLock.Lock()
gemPorts, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeGemPortID(), tp.NumGemPorts)
t.GemPortIDMgmtLock.Unlock()
if err != nil {
- logger.Errorw("Error getting gemport ids from rsrcrMgr", log.Fields{"intfId": intfId, "numGemports": tp.NumGemPorts})
+ logger.Errorw(ctx, "Error getting gemport ids from rsrcrMgr", log.Fields{"intfId": intfId, "numGemports": tp.NumGemPorts})
return nil
}
- logger.Infow("Allocated tconts and GEM ports successfully", log.Fields{"tconts": tcontIDs, "gemports": gemPorts})
+ logger.Infow(ctx, "Allocated tconts and GEM ports successfully", log.Fields{"tconts": tcontIDs, "gemports": gemPorts})
for index := 0; index < int(tp.NumGemPorts); index++ {
usGemPortAttributeList = append(usGemPortAttributeList,
iGemPortAttribute{GemportID: gemPorts[index],
@@ -705,7 +705,7 @@
DiscardConfig: tp.UpstreamGemPortAttributeList[index].DiscardConfig})
}
- logger.Info("length of DownstreamGemPortAttributeList", len(tp.DownstreamGemPortAttributeList))
+ logger.Info(ctx, "length of DownstreamGemPortAttributeList", len(tp.DownstreamGemPortAttributeList))
//put multicast and unicast downstream GEM port attributes in different lists first
for index := 0; index < int(len(tp.DownstreamGemPortAttributeList)); index++ {
if isMulticastGem(tp.DownstreamGemPortAttributeList[index].IsMulticast) {
@@ -879,10 +879,10 @@
for keyPath, kvPair := range kvPairs {
if value, err := kvstore.ToByte(kvPair.Value); err == nil {
if err = json.Unmarshal(value, &tpInst); err != nil {
- logger.Errorw("error-unmarshal-kv-pair", log.Fields{"keyPath": keyPath, "value": value})
+ logger.Errorw(ctx, "error-unmarshal-kv-pair", log.Fields{"keyPath": keyPath, "value": value})
return nil, errors.New("error-unmarshal-kv-pair")
} else {
- logger.Debugw("found-valid-tp-instance-on-another-uni", log.Fields{"keyPath": keyPath})
+ logger.Debugw(ctx, "found-valid-tp-instance-on-another-uni", log.Fields{"keyPath": keyPath})
return &tpInst, nil
}
}
@@ -903,10 +903,10 @@
for keyPath, kvPair := range kvPairs {
if value, err := kvstore.ToByte(kvPair.Value); err == nil {
if err = json.Unmarshal(value, &tpInst); err != nil {
- logger.Errorw("error-unmarshal-kv-pair", log.Fields{"keyPath": keyPath, "value": value})
+ logger.Errorw(ctx, "error-unmarshal-kv-pair", log.Fields{"keyPath": keyPath, "value": value})
return nil, errors.New("error-unmarshal-kv-pair")
} else {
- logger.Debugw("found-valid-tp-instance-on-another-uni", log.Fields{"keyPath": keyPath})
+ logger.Debugw(ctx, "found-valid-tp-instance-on-another-uni", log.Fields{"keyPath": keyPath})
return &tpInst, nil
}
}
@@ -914,13 +914,12 @@
return nil, nil
}
-func (t *TechProfileMgr) getDefaultTechProfile() *DefaultTechProfile {
-
+func (t *TechProfileMgr) getDefaultTechProfile(ctx context.Context) *DefaultTechProfile {
var usGemPortAttributeList []GemPortAttribute
var dsGemPortAttributeList []GemPortAttribute
for _, pbit := range t.config.DefaultPbits {
- logger.Debugw("Creating GEM port", log.Fields{"pbit": pbit})
+ logger.Debugw(ctx, "Creating GEM port", log.Fields{"pbit": pbit})
usGemPortAttributeList = append(usGemPortAttributeList,
GemPortAttribute{
MaxQueueSize: defaultMaxQueueSize,
@@ -1041,7 +1040,7 @@
DownstreamQueueAttributeList: dsQueueAttributeList}
}
-func (t *TechProfileMgr) GetprotoBufParamValue(paramType string, paramKey string) int32 {
+func (t *TechProfileMgr) GetprotoBufParamValue(ctx context.Context, paramType string, paramKey string) int32 {
var result int32 = -1
if paramType == "direction" {
@@ -1059,7 +1058,7 @@
} else if paramType == "sched_policy" {
for key, val := range tp_pb.SchedulingPolicy_value {
if key == paramKey {
- logger.Debugw("Got value in proto", log.Fields{"key": key, "value": val})
+ logger.Debugw(ctx, "Got value in proto", log.Fields{"key": key, "value": val})
result = val
}
}
@@ -1070,29 +1069,29 @@
}
}
} else {
- logger.Error("Could not find proto parameter", log.Fields{"paramType": paramType, "key": paramKey})
+ logger.Error(ctx, "Could not find proto parameter", log.Fields{"paramType": paramType, "key": paramKey})
return -1
}
- logger.Debugw("Got value in proto", log.Fields{"key": paramKey, "value": result})
+ logger.Debugw(ctx, "Got value in proto", log.Fields{"key": paramKey, "value": result})
return result
}
-func (t *TechProfileMgr) GetUsScheduler(tpInstance *TechProfile) (*tp_pb.SchedulerConfig, error) {
- dir := tp_pb.Direction(t.GetprotoBufParamValue("direction", tpInstance.UsScheduler.Direction))
+func (t *TechProfileMgr) GetUsScheduler(ctx context.Context, tpInstance *TechProfile) (*tp_pb.SchedulerConfig, error) {
+ dir := tp_pb.Direction(t.GetprotoBufParamValue(ctx, "direction", tpInstance.UsScheduler.Direction))
if dir == -1 {
- logger.Errorf("Error in getting proto id for direction %s for upstream scheduler", tpInstance.UsScheduler.Direction)
+ logger.Errorf(ctx, "Error in getting proto id for direction %s for upstream scheduler", tpInstance.UsScheduler.Direction)
return nil, fmt.Errorf("unable to get proto id for direction %s for upstream scheduler", tpInstance.UsScheduler.Direction)
}
- bw := tp_pb.AdditionalBW(t.GetprotoBufParamValue("additional_bw", tpInstance.UsScheduler.AdditionalBw))
+ bw := tp_pb.AdditionalBW(t.GetprotoBufParamValue(ctx, "additional_bw", tpInstance.UsScheduler.AdditionalBw))
if bw == -1 {
- logger.Errorf("Error in getting proto id for bandwidth %s for upstream scheduler", tpInstance.UsScheduler.AdditionalBw)
+ logger.Errorf(ctx, "Error in getting proto id for bandwidth %s for upstream scheduler", tpInstance.UsScheduler.AdditionalBw)
return nil, fmt.Errorf("unable to get proto id for bandwidth %s for upstream scheduler", tpInstance.UsScheduler.AdditionalBw)
}
- policy := tp_pb.SchedulingPolicy(t.GetprotoBufParamValue("sched_policy", tpInstance.UsScheduler.QSchedPolicy))
+ policy := tp_pb.SchedulingPolicy(t.GetprotoBufParamValue(ctx, "sched_policy", tpInstance.UsScheduler.QSchedPolicy))
if policy == -1 {
- logger.Errorf("Error in getting proto id for scheduling policy %s for upstream scheduler", tpInstance.UsScheduler.QSchedPolicy)
+ logger.Errorf(ctx, "Error in getting proto id for scheduling policy %s for upstream scheduler", tpInstance.UsScheduler.QSchedPolicy)
return nil, fmt.Errorf("unable to get proto id for scheduling policy %s for upstream scheduler", tpInstance.UsScheduler.QSchedPolicy)
}
@@ -1104,23 +1103,23 @@
SchedPolicy: policy}, nil
}
-func (t *TechProfileMgr) GetDsScheduler(tpInstance *TechProfile) (*tp_pb.SchedulerConfig, error) {
+func (t *TechProfileMgr) GetDsScheduler(ctx context.Context, tpInstance *TechProfile) (*tp_pb.SchedulerConfig, error) {
- dir := tp_pb.Direction(t.GetprotoBufParamValue("direction", tpInstance.DsScheduler.Direction))
+ dir := tp_pb.Direction(t.GetprotoBufParamValue(ctx, "direction", tpInstance.DsScheduler.Direction))
if dir == -1 {
- logger.Errorf("Error in getting proto id for direction %s for downstream scheduler", tpInstance.DsScheduler.Direction)
+ logger.Errorf(ctx, "Error in getting proto id for direction %s for downstream scheduler", tpInstance.DsScheduler.Direction)
return nil, fmt.Errorf("unable to get proto id for direction %s for downstream scheduler", tpInstance.DsScheduler.Direction)
}
- bw := tp_pb.AdditionalBW(t.GetprotoBufParamValue("additional_bw", tpInstance.DsScheduler.AdditionalBw))
+ bw := tp_pb.AdditionalBW(t.GetprotoBufParamValue(ctx, "additional_bw", tpInstance.DsScheduler.AdditionalBw))
if bw == -1 {
- logger.Errorf("Error in getting proto id for bandwidth %s for downstream scheduler", tpInstance.DsScheduler.AdditionalBw)
+ logger.Errorf(ctx, "Error in getting proto id for bandwidth %s for downstream scheduler", tpInstance.DsScheduler.AdditionalBw)
return nil, fmt.Errorf("unable to get proto id for bandwidth %s for downstream scheduler", tpInstance.DsScheduler.AdditionalBw)
}
- policy := tp_pb.SchedulingPolicy(t.GetprotoBufParamValue("sched_policy", tpInstance.DsScheduler.QSchedPolicy))
+ policy := tp_pb.SchedulingPolicy(t.GetprotoBufParamValue(ctx, "sched_policy", tpInstance.DsScheduler.QSchedPolicy))
if policy == -1 {
- logger.Errorf("Error in getting proto id for scheduling policy %s for downstream scheduler", tpInstance.DsScheduler.QSchedPolicy)
+ logger.Errorf(ctx, "Error in getting proto id for scheduling policy %s for downstream scheduler", tpInstance.DsScheduler.QSchedPolicy)
return nil, fmt.Errorf("unable to get proto id for scheduling policy %s for downstream scheduler", tpInstance.DsScheduler.QSchedPolicy)
}
@@ -1144,7 +1143,7 @@
return tSched
}
-func (tpm *TechProfileMgr) GetTrafficQueues(tp *TechProfile, Dir tp_pb.Direction) ([]*tp_pb.TrafficQueue, error) {
+func (tpm *TechProfileMgr) GetTrafficQueues(ctx context.Context, tp *TechProfile, Dir tp_pb.Direction) ([]*tp_pb.TrafficQueue, error) {
var encryp bool
if Dir == tp_pb.Direction_UPSTREAM {
@@ -1158,20 +1157,20 @@
encryp = false
}
- schedPolicy := tpm.GetprotoBufParamValue("sched_policy", tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy)
+ schedPolicy := tpm.GetprotoBufParamValue(ctx, "sched_policy", tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy)
if schedPolicy == -1 {
- logger.Errorf("Error in getting Proto Id for scheduling policy %s for Upstream Gem Port %d", tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy, Count)
+ logger.Errorf(ctx, "Error in getting Proto Id for scheduling policy %s for Upstream Gem Port %d", tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy, Count)
return nil, fmt.Errorf("upstream gem port traffic queue creation failed due to unrecognized scheduling policy %s", tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy)
}
- discardPolicy := tpm.GetprotoBufParamValue("discard_policy", tp.UpstreamGemPortAttributeList[Count].DiscardPolicy)
+ discardPolicy := tpm.GetprotoBufParamValue(ctx, "discard_policy", tp.UpstreamGemPortAttributeList[Count].DiscardPolicy)
if discardPolicy == -1 {
- logger.Errorf("Error in getting Proto Id for discard policy %s for Upstream Gem Port %d", tp.UpstreamGemPortAttributeList[Count].DiscardPolicy, Count)
+ logger.Errorf(ctx, "Error in getting Proto Id for discard policy %s for Upstream Gem Port %d", tp.UpstreamGemPortAttributeList[Count].DiscardPolicy, Count)
return nil, fmt.Errorf("upstream gem port traffic queue creation failed due to unrecognized discard policy %s", tp.UpstreamGemPortAttributeList[Count].DiscardPolicy)
}
GemPorts = append(GemPorts, &tp_pb.TrafficQueue{
- Direction: tp_pb.Direction(tpm.GetprotoBufParamValue("direction", tp.UsScheduler.Direction)),
+ Direction: tp_pb.Direction(tpm.GetprotoBufParamValue(ctx, "direction", tp.UsScheduler.Direction)),
GemportId: tp.UpstreamGemPortAttributeList[Count].GemportID,
PbitMap: tp.UpstreamGemPortAttributeList[Count].PbitMap,
AesEncryption: encryp,
@@ -1181,7 +1180,7 @@
DiscardPolicy: tp_pb.DiscardPolicy(discardPolicy),
})
}
- logger.Debugw("Upstream Traffic queue list ", log.Fields{"queuelist": GemPorts})
+ logger.Debugw(ctx, "Upstream Traffic queue list ", log.Fields{"queuelist": GemPorts})
return GemPorts, nil
} else if Dir == tp_pb.Direction_DOWNSTREAM {
//downstream GEM ports
@@ -1198,20 +1197,20 @@
encryp = false
}
- schedPolicy := tpm.GetprotoBufParamValue("sched_policy", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy)
+ schedPolicy := tpm.GetprotoBufParamValue(ctx, "sched_policy", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy)
if schedPolicy == -1 {
- logger.Errorf("Error in getting Proto Id for scheduling policy %s for Downstream Gem Port %d", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy, Count)
+ logger.Errorf(ctx, "Error in getting Proto Id for scheduling policy %s for Downstream Gem Port %d", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy, Count)
return nil, fmt.Errorf("downstream gem port traffic queue creation failed due to unrecognized scheduling policy %s", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy)
}
- discardPolicy := tpm.GetprotoBufParamValue("discard_policy", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy)
+ discardPolicy := tpm.GetprotoBufParamValue(ctx, "discard_policy", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy)
if discardPolicy == -1 {
- logger.Errorf("Error in getting Proto Id for discard policy %s for Downstream Gem Port %d", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy, Count)
+ logger.Errorf(ctx, "Error in getting Proto Id for discard policy %s for Downstream Gem Port %d", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy, Count)
return nil, fmt.Errorf("downstream gem port traffic queue creation failed due to unrecognized discard policy %s", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy)
}
GemPorts = append(GemPorts, &tp_pb.TrafficQueue{
- Direction: tp_pb.Direction(tpm.GetprotoBufParamValue("direction", tp.DsScheduler.Direction)),
+ Direction: tp_pb.Direction(tpm.GetprotoBufParamValue(ctx, "direction", tp.DsScheduler.Direction)),
GemportId: tp.DownstreamGemPortAttributeList[Count].GemportID,
PbitMap: tp.DownstreamGemPortAttributeList[Count].PbitMap,
AesEncryption: encryp,
@@ -1221,11 +1220,11 @@
DiscardPolicy: tp_pb.DiscardPolicy(discardPolicy),
})
}
- logger.Debugw("Downstream Traffic queue list ", log.Fields{"queuelist": GemPorts})
+ logger.Debugw(ctx, "Downstream Traffic queue list ", log.Fields{"queuelist": GemPorts})
return GemPorts, nil
}
- logger.Errorf("Unsupported direction %s used for generating Traffic Queue list", Dir)
+ logger.Errorf(ctx, "Unsupported direction %s used for generating Traffic Queue list", Dir)
return nil, fmt.Errorf("downstream gem port traffic queue creation failed due to unsupported direction %s", Dir)
}
@@ -1235,7 +1234,7 @@
(isMulticastAttrValue == "True" || isMulticastAttrValue == "true" || isMulticastAttrValue == "TRUE")
}
-func (tpm *TechProfileMgr) GetMulticastTrafficQueues(tp *TechProfile) []*tp_pb.TrafficQueue {
+func (tpm *TechProfileMgr) GetMulticastTrafficQueues(ctx context.Context, tp *TechProfile) []*tp_pb.TrafficQueue {
var encryp bool
NumGemPorts := len(tp.DownstreamGemPortAttributeList)
mcastTrafficQueues := make([]*tp_pb.TrafficQueue, 0)
@@ -1249,29 +1248,29 @@
encryp = false
}
mcastTrafficQueues = append(mcastTrafficQueues, &tp_pb.TrafficQueue{
- Direction: tp_pb.Direction(tpm.GetprotoBufParamValue("direction", tp.DsScheduler.Direction)),
+ Direction: tp_pb.Direction(tpm.GetprotoBufParamValue(ctx, "direction", tp.DsScheduler.Direction)),
GemportId: tp.DownstreamGemPortAttributeList[Count].McastGemID,
PbitMap: tp.DownstreamGemPortAttributeList[Count].PbitMap,
AesEncryption: encryp,
- SchedPolicy: tp_pb.SchedulingPolicy(tpm.GetprotoBufParamValue("sched_policy", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy)),
+ SchedPolicy: tp_pb.SchedulingPolicy(tpm.GetprotoBufParamValue(ctx, "sched_policy", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy)),
Priority: tp.DownstreamGemPortAttributeList[Count].PriorityQueue,
Weight: tp.DownstreamGemPortAttributeList[Count].Weight,
- DiscardPolicy: tp_pb.DiscardPolicy(tpm.GetprotoBufParamValue("discard_policy", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy)),
+ DiscardPolicy: tp_pb.DiscardPolicy(tpm.GetprotoBufParamValue(ctx, "discard_policy", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy)),
})
}
- logger.Debugw("Downstream Multicast Traffic queue list ", log.Fields{"queuelist": mcastTrafficQueues})
+ logger.Debugw(ctx, "Downstream Multicast Traffic queue list ", log.Fields{"queuelist": mcastTrafficQueues})
return mcastTrafficQueues
}
-func (tpm *TechProfileMgr) GetUsTrafficScheduler(tp *TechProfile) *tp_pb.TrafficScheduler {
- UsScheduler, _ := tpm.GetUsScheduler(tp)
+func (tpm *TechProfileMgr) GetUsTrafficScheduler(ctx context.Context, tp *TechProfile) *tp_pb.TrafficScheduler {
+ UsScheduler, _ := tpm.GetUsScheduler(ctx, tp)
return &tp_pb.TrafficScheduler{Direction: UsScheduler.Direction,
AllocId: tp.UsScheduler.AllocID,
Scheduler: UsScheduler}
}
-func (t *TechProfileMgr) GetGemportIDForPbit(tp interface{}, dir tp_pb.Direction, pbit uint32) uint32 {
+func (t *TechProfileMgr) GetGemportIDForPbit(ctx context.Context, tp interface{}, dir tp_pb.Direction, pbit uint32) uint32 {
/*
Function to get the Gemport ID mapped to a pbit.
*/
@@ -1287,7 +1286,7 @@
// "lenOfPbitMap - pbitMapIdx + 1" will give pbit-i th value from LSB position in the pbit map string
if p, err := strconv.Atoi(string(tp.UpstreamGemPortAttributeList[gemCnt].PbitMap[lenOfPbitMap-pbitMapIdx+1])); err == nil {
if uint32(pbitMapIdx-2) == pbit && p == 1 { // Check this p-bit is set
- logger.Debugw("Found-US-GEMport-for-Pcp", log.Fields{"pbit": pbit, "GEMport": tp.UpstreamGemPortAttributeList[gemCnt].GemportID})
+ logger.Debugw(ctx, "Found-US-GEMport-for-Pcp", log.Fields{"pbit": pbit, "GEMport": tp.UpstreamGemPortAttributeList[gemCnt].GemportID})
return tp.UpstreamGemPortAttributeList[gemCnt].GemportID
}
}
@@ -1303,14 +1302,14 @@
// "lenOfPbitMap - pbitMapIdx + 1" will give pbit-i th value from LSB position in the pbit map string
if p, err := strconv.Atoi(string(tp.DownstreamGemPortAttributeList[gemCnt].PbitMap[lenOfPbitMap-pbitMapIdx+1])); err == nil {
if uint32(pbitMapIdx-2) == pbit && p == 1 { // Check this p-bit is set
- logger.Debugw("Found-DS-GEMport-for-Pcp", log.Fields{"pbit": pbit, "GEMport": tp.DownstreamGemPortAttributeList[gemCnt].GemportID})
+ logger.Debugw(ctx, "Found-DS-GEMport-for-Pcp", log.Fields{"pbit": pbit, "GEMport": tp.DownstreamGemPortAttributeList[gemCnt].GemportID})
return tp.DownstreamGemPortAttributeList[gemCnt].GemportID
}
}
}
}
}
- logger.Errorw("No-GemportId-Found-For-Pcp", log.Fields{"pcpVlan": pbit})
+ logger.Errorw(ctx, "No-GemportId-Found-For-Pcp", log.Fields{"pcpVlan": pbit})
case *EponProfile:
if dir == tp_pb.Direction_UPSTREAM {
// upstream GEM ports
@@ -1322,7 +1321,7 @@
// "lenOfPbitMap - pbitMapIdx + 1" will give pbit-i th value from LSB position in the pbit map string
if p, err := strconv.Atoi(string(tp.UpstreamQueueAttributeList[gemCnt].PbitMap[lenOfPbitMap-pbitMapIdx+1])); err == nil {
if uint32(pbitMapIdx-2) == pbit && p == 1 { // Check this p-bit is set
- logger.Debugw("Found-US-Queue-for-Pcp", log.Fields{"pbit": pbit, "Queue": tp.UpstreamQueueAttributeList[gemCnt].GemportID})
+ logger.Debugw(ctx, "Found-US-Queue-for-Pcp", log.Fields{"pbit": pbit, "Queue": tp.UpstreamQueueAttributeList[gemCnt].GemportID})
return tp.UpstreamQueueAttributeList[gemCnt].GemportID
}
}
@@ -1338,16 +1337,16 @@
// "lenOfPbitMap - pbitMapIdx + 1" will give pbit-i th value from LSB position in the pbit map string
if p, err := strconv.Atoi(string(tp.DownstreamQueueAttributeList[gemCnt].PbitMap[lenOfPbitMap-pbitMapIdx+1])); err == nil {
if uint32(pbitMapIdx-2) == pbit && p == 1 { // Check this p-bit is set
- logger.Debugw("Found-DS-Queue-for-Pcp", log.Fields{"pbit": pbit, "Queue": tp.DownstreamQueueAttributeList[gemCnt].GemportID})
+ logger.Debugw(ctx, "Found-DS-Queue-for-Pcp", log.Fields{"pbit": pbit, "Queue": tp.DownstreamQueueAttributeList[gemCnt].GemportID})
return tp.DownstreamQueueAttributeList[gemCnt].GemportID
}
}
}
}
}
- logger.Errorw("No-QueueId-Found-For-Pcp", log.Fields{"pcpVlan": pbit})
+ logger.Errorw(ctx, "No-QueueId-Found-For-Pcp", log.Fields{"pcpVlan": pbit})
default:
- logger.Errorw("unknown-tech", log.Fields{"tp": tp})
+ logger.Errorw(ctx, "unknown-tech", log.Fields{"tp": tp})
}
return 0
}
@@ -1368,14 +1367,14 @@
if value, err := kvstore.ToByte(kvPair.Value); err == nil {
if tech == xgspon || tech == gpon {
if err = json.Unmarshal(value, &tpTech); err != nil {
- logger.Errorw("error-unmarshal-kv-pair", log.Fields{"kvPath": kvPath, "value": value})
+ logger.Errorw(ctx, "error-unmarshal-kv-pair", log.Fields{"kvPath": kvPath, "value": value})
continue
} else {
tpInstancesTech = append(tpInstancesTech, tpTech)
}
} else if tech == epon {
if err = json.Unmarshal(value, &tpEpon); err != nil {
- logger.Errorw("error-unmarshal-kv-pair", log.Fields{"kvPath": kvPath, "value": value})
+ logger.Errorw(ctx, "error-unmarshal-kv-pair", log.Fields{"kvPath": kvPath, "value": value})
continue
} else {
tpInstancesEpon = append(tpInstancesEpon, tpEpon)