X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=reader%2FrNibReader.go;fp=reader%2FrNibReader.go;h=0509326d67dedd1be39efd847276941c89c9fac1;hb=0ef0f0f391bd57b6b86c40de9f0819111cd54327;hp=ae9dcf3d432ac9448bc683103f77fb6430e49812;hpb=574eee8d3a9b7173f8ed05bb921e972b8074f74a;p=ric-plt%2Fnodeb-rnib.git diff --git a/reader/rNibReader.go b/reader/rNibReader.go index ae9dcf3..0509326 100644 --- a/reader/rNibReader.go +++ b/reader/rNibReader.go @@ -22,6 +22,7 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/sdlgo" "github.com/golang/protobuf/proto" "github.com/pkg/errors" + "reflect" ) var readerPool *common.Pool @@ -53,6 +54,8 @@ type RNibReader interface { GetCellById(cellType entities.Cell_Type, cellId string) (*entities.Cell, common.IRNibError) // GetListNodebIds returns the full list of Nodeb identity entities GetListNodebIds()([]*entities.NbIdentity, common.IRNibError) + // GetRanLoadInformation retrieves nodeb load information entity from redis DB by nodeb inventory name + GetRanLoadInformation(inventoryName string) (*entities.RanLoadInformation, common.IRNibError) } const( @@ -180,6 +183,34 @@ func (w *rNibReaderInstance) GetListNodebIds()([]*entities.NbIdentity, common.IR return *data, rnibErr } +func (w *rNibReaderInstance) GetRanLoadInformation(inventoryName string) (*entities.RanLoadInformation, common.IRNibError){ + key, rNibErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName) + if rNibErr != nil { + return nil, rNibErr + } + loadInfo := &entities.RanLoadInformation{} + err := w.getByKeyAndUnmarshal(key, loadInfo) + if err!= nil{ + return nil, err + } + return loadInfo, err +} + +func (w *rNibReaderInstance) getByKeyAndUnmarshal(key string, entity proto.Message)common.IRNibError{ + data, err := (*w.sdl).Get([]string{key}) + if err != nil { + return common.NewInternalError(err) + } + if data != nil && data[key] != nil { + err = proto.Unmarshal([]byte(data[key].(string)), entity) + if err != nil { + return common.NewInternalError(err) + } + return nil + } + return common.NewResourceNotFoundError(errors.Errorf("#rNibReader.getByKeyAndUnmarshal - entity of type %s not found. Key: %s", reflect.TypeOf(entity).String(), key)) +} + func (w *rNibReaderInstance) getNodeb(key string) (*entities.NodebInfo, common.IRNibError) { data, err := (*w.sdl).Get([]string{key}) if err != nil {