Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
238 changes: 234 additions & 4 deletions translib/common_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/Azure/sonic-mgmt-common/translib/db"
"github.com/Azure/sonic-mgmt-common/translib/ocbinds"
"github.com/Azure/sonic-mgmt-common/translib/path"
"github.com/Azure/sonic-mgmt-common/translib/tlerr"
"github.com/Azure/sonic-mgmt-common/translib/transformer"
"github.com/Azure/sonic-mgmt-common/translib/utils"
Expand Down Expand Up @@ -133,12 +134,223 @@ func (app *CommonApp) translateGet(dbs [db.MaxDB]*db.DB) error {
return err
}

func (app *CommonApp) translateSubscribe(req translateSubRequest) (translateSubResponse, error) {
return emptySubscribeResponse(req.path)
func (app *CommonApp) translateSubscribe(req *translateSubRequest) (*translateSubResponse, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signature does not match the appInterface method:

translateSubscribe(req translateSubRequest) (translateSubResponse, error)

txCache := new(sync.Map)
reqIdLogStr := "subReq Id:[" + fmt.Sprintf("%v", req.ctxID) + "] : "
if log.V(4) {
log.Info(reqIdLogStr, "tranlateSubscribe:path", req.path)
}
subMode := transformer.NotificationType(req.mode)
subReqXlator, err := transformer.NewSubscribeReqXlator(req.ctxID, req.path, subMode, req.dbs, txCache)
if err != nil {
if log.V(4) {
log.Warning(reqIdLogStr, "tranlateSubscribe:Error in initializing the SubscribeReqXlator for the subscribe path request: ", req.path)
}
return nil, err
}

if err = subReqXlator.Translate(!req.recurse); err != nil {
if log.V(4) {
log.Warning(reqIdLogStr, "translateSubscribe: Error in processing the subscribe path request: ", req.path)
}
return nil, err
}

subsReqXlateInfo, err := subReqXlator.GetSubscribeReqXlateInfo()
if err != nil {
return nil, err
}

if uriPath, err := ygot.PathToString(subsReqXlateInfo.TrgtPathInfo.Path); err == nil {
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: subsReqXlateInfo.TrgtPathInfo.path: ", uriPath)
}
} else {
if log.V(4) {
log.Warning(reqIdLogStr, "translateSubscribe: subsReqXlateInfo.TrgtPathInfo.path: Error in converting the gnmi path: ", *subsReqXlateInfo.TrgtPathInfo.Path)
}
}

if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: subsReqXlateInfo.TrgtPathInfo: ", subsReqXlateInfo.TrgtPathInfo.DbKeyXlateInfo)
}
ntfSubsAppInfo := new(translateSubResponse)

for _, dbKeyInfo := range subsReqXlateInfo.TrgtPathInfo.DbKeyXlateInfo {
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: Target node: DbNum: ", dbKeyInfo.DbNum)
}
if dbKeyInfo.Table != nil {
if log.V(4) {
log.Info(reqIdLogStr, "Target node: pathXlateInfo.Table: ", *dbKeyInfo.Table)
}
}
if dbKeyInfo.Key != nil {
if log.V(4) {
log.Info(reqIdLogStr, "Target node: pathXlateInfo.Key: ", *dbKeyInfo.Key)
}
}

ntfAppInfo := notificationAppInfo{
table: dbKeyInfo.Table,
key: dbKeyInfo.Key,
dbno: dbKeyInfo.DbNum,
path: subsReqXlateInfo.TrgtPathInfo.Path,
handlerFunc: subsReqXlateInfo.TrgtPathInfo.HandlerFunc,
deleteAction: dbKeyInfo.DeleteAction,
fieldScanPattern: dbKeyInfo.FieldScanPatt,
keyGroupComps: dbKeyInfo.KeyGroupComps,
isDataSrcDynamic: subsReqXlateInfo.TrgtPathInfo.IsDataSrcDynamic,
}

if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: Target node: ntfAppInfo.deleteAction: ", ntfAppInfo.deleteAction)
}

pType := subsReqXlateInfo.TrgtPathInfo.PType
if subsReqXlateInfo.TrgtPathInfo.OnChange != transformer.OnchangeEnable && dbKeyInfo.DbNum == db.CountersDB {
pType = transformer.Sample
}

if pType == transformer.Sample {
ntfAppInfo.pType = Sample
ntfAppInfo.mInterval = subsReqXlateInfo.TrgtPathInfo.MinInterval
} else if subsReqXlateInfo.TrgtPathInfo.OnChange == transformer.OnchangeEnable || subsReqXlateInfo.TrgtPathInfo.OnChange == transformer.OnchangeDefault {
ntfAppInfo.isOnChangeSupported = true
ntfAppInfo.pType = OnChange
}

for _, dbFldMapInfo := range dbKeyInfo.DbFldYgMapList {
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: Target node: RelPath: ", dbFldMapInfo.RltvPath,
"; db field YANG map: ", dbFldMapInfo.DbFldYgPathMap)
}
dbFldInfo := dbFldYgPathInfo{dbFldMapInfo.RltvPath, dbFldMapInfo.DbFldYgPathMap}
ntfAppInfo.dbFldYgPathInfoList = append(ntfAppInfo.dbFldYgPathInfoList, &dbFldInfo)
}

if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: target node: ntfAppInfo.path: ", ntfAppInfo.path,
"; ntfAppInfo.isOnChangeSupported: ", ntfAppInfo.isOnChangeSupported, "; ntfAppInfo.table: ",
ntfAppInfo.table, "; ntfAppInfo.key: ", ntfAppInfo.key)
}
for _, pathInfoList := range ntfAppInfo.dbFldYgPathInfoList {
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: target node: ntfAppInfo.dbFldYgPathInfoList entry: ", pathInfoList)
}
}
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: target node: ntfAppInfo.dbno: ", ntfAppInfo.dbno,
"; ntfAppInfo.mInterval: : ", ntfAppInfo.mInterval, "; ntfAppInfo.pType: ", ntfAppInfo.pType,
"; ntfAppInfo.fieldScanPattern: ", ntfAppInfo.fieldScanPattern, "; ntfAppInfo.opaque: ", ntfAppInfo.opaque, "isDataSrcDynamic: ", subsReqXlateInfo.TrgtPathInfo.IsDataSrcDynamic)
}
ntfSubsAppInfo.ntfAppInfoTrgt = append(ntfSubsAppInfo.ntfAppInfoTrgt, &ntfAppInfo)
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: target node ===========================================")
}
}

for _, pathXlateInfo := range subsReqXlateInfo.ChldPathsInfo {
if uriPath, err := ygot.PathToString(pathXlateInfo.Path); err == nil {
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: ChldPathsInfo: path: ", uriPath)
}
} else {
log.Warning(reqIdLogStr, "translateSubscribe: ChldPathsInfo: Error in converting the gnmi path: ", *pathXlateInfo.Path)
}
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: ChldPathsInfo.pathXlateInfo.DbKeyXlateInfo: ", pathXlateInfo.DbKeyXlateInfo)
}
for _, dbKeyInfo := range pathXlateInfo.DbKeyXlateInfo {
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: child node: DbNum: ", dbKeyInfo.DbNum)
}
if dbKeyInfo.Table != nil && log.V(4) {
log.Info(reqIdLogStr, "child node: pathXlateInfo.Table: ", *dbKeyInfo.Table)
}
if dbKeyInfo.Key != nil && log.V(4) {
log.Info(reqIdLogStr, "child node: pathXlateInfo.Key: ", *dbKeyInfo.Key)
}
ntfAppInfo := notificationAppInfo{
table: dbKeyInfo.Table,
key: dbKeyInfo.Key,
dbno: dbKeyInfo.DbNum,
path: pathXlateInfo.Path,
handlerFunc: pathXlateInfo.HandlerFunc,
deleteAction: dbKeyInfo.DeleteAction,
fieldScanPattern: dbKeyInfo.FieldScanPatt,
keyGroupComps: dbKeyInfo.KeyGroupComps,
isDataSrcDynamic: pathXlateInfo.IsDataSrcDynamic,
}
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: child node: ntfAppInfo.deleteAction: ", ntfAppInfo.deleteAction)
}
pType := pathXlateInfo.PType
if pathXlateInfo.OnChange != transformer.OnchangeEnable && dbKeyInfo.DbNum == db.CountersDB {
pType = transformer.Sample
}
if pType == transformer.Sample {
ntfAppInfo.pType = app.translateNotificationType(pType)
ntfAppInfo.mInterval = pathXlateInfo.MinInterval
} else if pathXlateInfo.OnChange == transformer.OnchangeEnable || pathXlateInfo.OnChange == transformer.OnchangeDefault {
ntfAppInfo.isOnChangeSupported = true
ntfAppInfo.pType = OnChange
}
for _, dbFldMapInfo := range dbKeyInfo.DbFldYgMapList {
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: child node: RelPath: ", dbFldMapInfo.RltvPath,
"; dbFldMapInfo.DbFldYgPathMap: ", dbFldMapInfo.DbFldYgPathMap)
}
dbFldInfo := dbFldYgPathInfo{dbFldMapInfo.RltvPath, dbFldMapInfo.DbFldYgPathMap}
ntfAppInfo.dbFldYgPathInfoList = append(ntfAppInfo.dbFldYgPathInfoList, &dbFldInfo)
}
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: child node: ntfAppInfo.path: ", ntfAppInfo.path,
"; ntfAppInfo.isOnChangeSupported: ", ntfAppInfo.isOnChangeSupported, "; ntfAppInfo.table: ",
ntfAppInfo.table, "; ntfAppInfo.key: ", ntfAppInfo.key)
}
for _, pathInfoList := range ntfAppInfo.dbFldYgPathInfoList {
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: child node: ntfAppInfo.dbFldYgPathInfoList entry: ", pathInfoList)
}
}
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: child node: ntfAppInfo.dbno: ", ntfAppInfo.dbno,
"; ntfAppInfo.mInterval: : ", ntfAppInfo.mInterval, "; ntfAppInfo.pType: ", ntfAppInfo.pType,
"; ntfAppInfo.fieldScanPattern: ", ntfAppInfo.fieldScanPattern, "; ntfAppInfo.opaque: ", ntfAppInfo.opaque, "; isDataSrcDynamic: ", pathXlateInfo.IsDataSrcDynamic)
}
if len(subsReqXlateInfo.TrgtPathInfo.DbKeyXlateInfo) == 0 && pathXlateInfo.TrgtNodeChld {
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: Added the child node notification app info into targt app info for the path: ", pathXlateInfo.Path)
}
ntfSubsAppInfo.ntfAppInfoTrgt = append(ntfSubsAppInfo.ntfAppInfoTrgt, &ntfAppInfo)
} else {
ntfSubsAppInfo.ntfAppInfoTrgtChlds = append(ntfSubsAppInfo.ntfAppInfoTrgtChlds, &ntfAppInfo)
}
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: child node =========================================")
}
}
}
if len(ntfSubsAppInfo.ntfAppInfoTrgt) == 0 && (!path.HasWildcardKey(subsReqXlateInfo.TrgtPathInfo.Path) &&
subsReqXlateInfo.TrgtPathInfo.PType == transformer.Sample) {
ntfAppInfo := &notificationAppInfo{path: subsReqXlateInfo.TrgtPathInfo.Path, pType: Sample, mInterval: subsReqXlateInfo.TrgtPathInfo.MinInterval}
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: no table mapping: non wild card path; sample mode - notificationAppInfo:", ntfAppInfo.String())
}
ntfSubsAppInfo.ntfAppInfoTrgt = append(ntfSubsAppInfo.ntfAppInfoTrgt, ntfAppInfo)
}
if log.V(4) {
log.Info(reqIdLogStr, "translateSubscribe: ntfSubsAppInfo: ", ntfSubsAppInfo)
}
return ntfSubsAppInfo, nil
}

func (app *CommonApp) processSubscribe(req processSubRequest) (processSubResponse, error) {
return processSubResponse{}, tlerr.New("not implemented")
func (app *CommonApp) translateNotificationType(t transformer.NotificationType) NotificationType {
if t == transformer.Sample {
return Sample
}
return OnChange
}

func (app *CommonApp) translateAction(dbs [db.MaxDB]*db.DB) error {
Expand Down Expand Up @@ -309,6 +521,24 @@ func (app *CommonApp) processAction(dbs [db.MaxDB]*db.DB) (ActionResponse, error
return resp, err
}

func (app *CommonApp) processSubscribe(param *processSubRequest) (processSubResponse, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signature does not match the appInterface method:

processSubscribe(req processSubRequest) (processSubResponse, error)

var resp processSubResponse

subNotfRespXlator, err := transformer.NewSubscribeNotfRespXlator(param.ctxID, param.path, param.dbno, param.table, param.key, param.entry, param.dbs, param.opaque)
if err != nil {
log.Warning("processSubscribe: Error in getting the NewSubscribeNotfRespXlator; error: ", err)
return resp, err
}
if log.V(4) {
log.Info("processSubscribe: subNotfRespXlator: ", *subNotfRespXlator)
}
if resp.path, err = subNotfRespXlator.Translate(); err != nil {
log.Warning("processSubscribe: Error in translating the subscribe notification; error: ", err)
return resp, err
}
return resp, nil
}

func (app *CommonApp) translateCRUDCommon(d *db.DB, opcode int) ([]db.WatchKeys, error) {
var err error
var keys []db.WatchKeys
Expand Down
34 changes: 10 additions & 24 deletions translib/transformer/subscribe_req_xlate.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (pathXltr *subscribePathXlator) setTrgtYgXpathInfo() error {
func (pathXlateInfo *XfmrSubscribePathXlateInfo) addPathXlateInfo(tblSpec *db.TableSpec, dbKey *db.Key, dBNum db.DBNum) *dbTableKeyInfo {
dbTblInfo := dbTableKeyInfo{Table: tblSpec, Key: dbKey, DbNum: dBNum}
pathXlateInfo.DbKeyXlateInfo = append(pathXlateInfo.DbKeyXlateInfo, &dbTblInfo)
if (pathXlateInfo.ygXpathInfo.yangType == YNG_LEAF || pathXlateInfo.ygXpathInfo.yangType == YNG_LEAF_LIST) &&
if (pathXlateInfo.ygXpathInfo.yangType == YANG_LEAF || pathXlateInfo.ygXpathInfo.yangType == YANG_LEAF_LIST) &&
pathXlateInfo.ygXpathInfo.subscriptionFlags.Has(subsDelAsUpdate) {
dbTblInfo.DeleteAction = apis.InspectPathOnDelete
}
Expand Down Expand Up @@ -1285,7 +1285,7 @@ func (reqXlator *subscribeReqXlator) translateChildNodePaths(ygXpathInfo *yangXp
}

func (pathXlateInfo *XfmrSubscribePathXlateInfo) isSamePathXlateInfo(parentPathXlateInfo *XfmrSubscribePathXlateInfo) bool {
if (pathXlateInfo.ygXpathInfo.yangType == YNG_LEAF || pathXlateInfo.ygXpathInfo.yangType == YNG_LEAF_LIST) &&
if (pathXlateInfo.ygXpathInfo.yangType == YANG_LEAF || pathXlateInfo.ygXpathInfo.yangType == YANG_LEAF_LIST) &&
pathXlateInfo.ygXpathInfo.subscriptionFlags.Has(subsDelAsUpdate) {
return false
}
Expand Down Expand Up @@ -1432,7 +1432,7 @@ func (reqXlator *subscribeReqXlator) traverseYgXpathAndTranslate(ygXpNode *ygXpa
}
}

if chldNode.ygXpathInfo.yangType != YNG_LIST && parentPathXlateInfo.hasDbTableInfo() {
if chldNode.ygXpathInfo.yangType != YANG_LIST && parentPathXlateInfo.hasDbTableInfo() {
// other than list node, that is for the container / leaf / leaf-list node
// the db key entry of the parent list node's table db key will be used as the table
// key for the container/leaf/leaf-list node's table
Expand Down Expand Up @@ -1849,8 +1849,7 @@ func (reqXlator *subscribeReqXlator) uriToAbsolutePath(rltvUri string) (*gnmipb.
}

func debugPrintXPathInfo(xpathInfo *yangXpathInfo) {
// TODO:INTG_CHANGES below commented code will be reverted during the code integration
//log.Infof(" yangType: %v\r\n", getYangTypeStrId(xpathInfo.yangType))
log.Infof(" yangType: %v\r\n", getYangTypeStrId(xpathInfo.yangType))
log.Info(" fieldName: ", xpathInfo.fieldName)
if xpathInfo.nameWithMod != nil {
log.Infof(" nameWithMod : %v\r\n", *xpathInfo.nameWithMod)
Expand Down Expand Up @@ -1924,11 +1923,9 @@ func debugPrintXPathInfo(xpathInfo *yangXpathInfo) {

func getYgEntry(reqLogId string, ygXpath *yangXpathInfo, ygPath string) (*yang.Entry, error) {
ygEntry := ygXpath.yangEntry
// TODO:INTG_CHANGES below commented lines will be reverted during the code integration
// since this function "getYangEntryForXPath" has to be merged first
//if ygEntry == nil && (ygXpath.yangType == YNG_LEAF || ygXpath.yangType == YNG_LEAF_LIST) {
// ygEntry = getYangEntryForXPath(ygPath)
//}
if ygEntry == nil && (ygXpath.yangType == YANG_LEAF || ygXpath.yangType == YANG_LEAF_LIST) {
ygEntry = getYangEntryForXPath(ygPath)
}
if ygEntry == nil {
if log.V(dbLgLvl) {
log.Warningf("%v : yangEntry is nil in the yangXpathInfo for the path:", reqLogId, ygPath)
Expand All @@ -1938,15 +1935,6 @@ func getYgEntry(reqLogId string, ygXpath *yangXpathInfo, ygPath string) (*yang.E
return ygEntry, nil
}

// TODO:INTG_CHANGES below const. are temporary changes, will be removed during the code integration
// reference to YNG_LEAF_LIST, YNG_LEAF in this file will be replaced with YANG_LEAF_LIST, YANG_LEAF
const (
YNG_LIST yangElementType = iota + 2
YNG_CONTAINER
YNG_LEAF
YNG_LEAF_LIST
)

func (keyRslvr *DbYangKeyResolver) handleValueXfmr(xfmrName string, operation Operation, keyName string, keyVal string) (keyLeafVal string, err error) {
if log.V(dbLgLvl) {
log.Info(keyRslvr.reqLogId, "resolveDbKey: keyLeafRefNode xfmrValue; ", xfmrName)
Expand Down Expand Up @@ -2107,11 +2095,9 @@ func (keyRslvr *DbYangKeyResolver) getDbYangListInfo(listName string) (*dbInfo,

func getYgDbEntry(reqLogId string, ygDbInfo *dbInfo, ygPath string) (*yang.Entry, error) {
ygEntry := ygDbInfo.dbEntry
// TODO:INTG_CHANGES below commented lines will be reverted during the code integration
// since this function "getYangEntryForXPath" has to be merged first
//if ygEntry == nil && (ygDbInfo.yangType == YANG_LEAF || ygDbInfo.yangType == YANG_LEAF_LIST) {
// ygEntry = getYangEntryForXPath(ygPath)
//}
if ygEntry == nil && (ygDbInfo.yangType == YANG_LEAF || ygDbInfo.yangType == YANG_LEAF_LIST) {
ygEntry = getYangEntryForXPath(ygPath)
}
if ygEntry == nil {
if log.V(dbLgLvl) {
log.Warningf("%v : yangEntry is nil in the yangXpathInfo for the path:", reqLogId, ygPath)
Expand Down
Loading