X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=reader%2FrNibReader.go;fp=reader%2FrNibReader.go;h=ed87ff7a335541a0784170ce85a7173ad7a647c1;hb=3519d193f64372d84b638179e2d050ba3f9dc3ca;hp=70bbdb223ec743503e344be233d0598ab62f316c;hpb=3910f469611577225239aceaf65abfa0962c586b;p=ric-plt%2Fnodeb-rnib.git diff --git a/reader/rNibReader.go b/reader/rNibReader.go index 70bbdb2..ed87ff7 100644 --- a/reader/rNibReader.go +++ b/reader/rNibReader.go @@ -17,8 +17,8 @@ package reader import ( - "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" "gerrit.o-ran-sc.org/r/ric-plt/sdlgo" "github.com/golang/protobuf/proto" "github.com/pkg/errors" @@ -33,7 +33,7 @@ type rNibReaderInstance struct { /* RNibReader interface allows retrieving data from redis BD by various keys - */ +*/ type RNibReader interface { // GetNodeb retrieves responding nodeb entity from redis DB by nodeb inventory name GetNodeb(inventoryName string) (*entities.NodebInfo, common.IRNibError) @@ -42,28 +42,29 @@ type RNibReader interface { // GetCellList retrieves the list of cell entities belonging to responding nodeb entity from redis DB by nodeb inventory name GetCellList(inventoryName string) (*entities.Cells, common.IRNibError) // GetListGnbIds retrieves the list of gNodeb identity entities - GetListGnbIds()(*[]*entities.NbIdentity, common.IRNibError) + GetListGnbIds() (*[]*entities.NbIdentity, common.IRNibError) // GetListEnbIds retrieves the list of eNodeb identity entities - GetListEnbIds()(*[]*entities.NbIdentity, common.IRNibError) + GetListEnbIds() (*[]*entities.NbIdentity, common.IRNibError) // Close closes reader's pool - GetCountGnbList()(int, common.IRNibError) + GetCountGnbList() (int, common.IRNibError) // GetCell retrieves the cell entity belonging to responding nodeb from redis DB by nodeb inventory name and cell pci GetCell(inventoryName string, pci uint32) (*entities.Cell, common.IRNibError) // GetCellById retrieves the cell entity from redis DB by cell type and cell Id GetCellById(cellType entities.Cell_Type, cellId string) (*entities.Cell, common.IRNibError) } + /* Init initializes the infrastructure required for the RNibReader instance */ func Init(namespace string, poolSize int) { initPool(poolSize, - func() interface{} { - var sdlI common.ISdlInstance = sdlgo.NewSdlInstance(namespace, sdlgo.NewDatabase()) - return &rNibReaderInstance{sdl: &sdlI, namespace: namespace} - }, + func() interface{} { + var sdlI common.ISdlInstance = sdlgo.NewSdlInstance(namespace, sdlgo.NewDatabase()) + return &rNibReaderInstance{sdl: &sdlI, namespace: namespace} + }, func(obj interface{}) { - (*obj.(*rNibReaderInstance).sdl).Close() - }) + (*obj.(*rNibReaderInstance).sdl).Close() + }) } func initPool(poolSize int, newObj func() interface{}, destroyObj func(interface{})) { @@ -72,25 +73,25 @@ func initPool(poolSize int, newObj func() interface{}, destroyObj func(interface /* GetRNibReader returns RNibReader instance from the pool - */ +*/ func GetRNibReader() RNibReader { return readerPool.Get().(RNibReader) } func (w *rNibReaderInstance) GetNodeb(inventoryName string) (*entities.NodebInfo, common.IRNibError) { name, rNibErr := common.ValidateAndBuildNodeBNameKey(inventoryName) - if rNibErr != nil{ + if rNibErr != nil { return nil, rNibErr } defer readerPool.Put(w) data, err := (*w.sdl).Get([]string{name}) - if err != nil{ + if err != nil { return nil, common.NewInternalError(err) } nb := entities.NodebInfo{} - if data != nil && data[name] != nil{ - err = proto.Unmarshal( []byte(data[name].(string)), &nb) - if err != nil{ + if data != nil && data[name] != nil { + err = proto.Unmarshal([]byte(data[name].(string)), &nb) + if err != nil { return nil, common.NewInternalError(err) } return &nb, nil @@ -100,18 +101,18 @@ func (w *rNibReaderInstance) GetNodeb(inventoryName string) (*entities.NodebInfo func (w *rNibReaderInstance) GetNodebByGlobalNbId(nodeType entities.Node_Type, globalNbId *entities.GlobalNbId) (*entities.NodebInfo, common.IRNibError) { key, rNibErr := common.ValidateAndBuildNodeBIdKey(nodeType.String(), globalNbId.GetPlmnId(), globalNbId.GetNbId()) - if rNibErr != nil{ + if rNibErr != nil { return nil, rNibErr } defer readerPool.Put(w) data, err := (*w.sdl).Get([]string{key}) - if err != nil{ + if err != nil { return nil, common.NewInternalError(err) } nb := entities.NodebInfo{} - if data != nil && data[key] != nil{ - err = proto.Unmarshal( []byte(data[key].(string)), &nb) - if err != nil{ + if data != nil && data[key] != nil { + err = proto.Unmarshal([]byte(data[key].(string)), &nb) + if err != nil { return nil, common.NewInternalError(err) } return &nb, nil @@ -119,60 +120,60 @@ func (w *rNibReaderInstance) GetNodebByGlobalNbId(nodeType entities.Node_Type, g return nil, common.NewResourceNotFoundError(errors.Errorf("#rNibReader.GetNodebByGlobalNbId - responding node not found, global nodeb Id: %s", key)) } -func (w *rNibReaderInstance) GetCellList(inventoryName string) (*entities.Cells, common.IRNibError){ +func (w *rNibReaderInstance) GetCellList(inventoryName string) (*entities.Cells, common.IRNibError) { cells := &entities.Cells{} nb, err := w.GetNodeb(inventoryName) - if err != nil{ + if err != nil { return nil, err } - if nb.GetEnb() != nil && len(nb.GetEnb().GetServedCells()) > 0{ + if nb.GetEnb() != nil && len(nb.GetEnb().GetServedCells()) > 0 { cells.Type = entities.Cell_LTE_CELL - cells.List = &entities.Cells_ServedCellInfos{ServedCellInfos:&entities.ServedCellInfoList{ServedCells:nb.GetEnb().GetServedCells()}} + cells.List = &entities.Cells_ServedCellInfos{ServedCellInfos: &entities.ServedCellInfoList{ServedCells: nb.GetEnb().GetServedCells()}} return cells, nil - } else if nb.GetGnb() != nil && len(nb.GetGnb().GetServedNrCells()) > 0{ + } else if nb.GetGnb() != nil && len(nb.GetGnb().GetServedNrCells()) > 0 { cells.Type = entities.Cell_NR_CELL - cells.List = &entities.Cells_ServedNrCells{ServedNrCells:&entities.ServedNRCellList{ServedCells:nb.GetGnb().GetServedNrCells()}} + cells.List = &entities.Cells_ServedNrCells{ServedNrCells: &entities.ServedNRCellList{ServedCells: nb.GetGnb().GetServedNrCells()}} return cells, nil } return nil, common.NewResourceNotFoundError(errors.Errorf("#rNibReader.GetCellList - served cells not found. Responding node RAN name: %s.", inventoryName)) } -func (w *rNibReaderInstance) GetListGnbIds()(*[]*entities.NbIdentity, common.IRNibError){ +func (w *rNibReaderInstance) GetListGnbIds() (*[]*entities.NbIdentity, common.IRNibError) { defer readerPool.Put(w) data, err := (*w.sdl).GetMembers("GNB") - if err != nil{ + if err != nil { return nil, common.NewInternalError(err) } return unmarshalIdentityList(data) } -func (w *rNibReaderInstance) GetListEnbIds()(*[]*entities.NbIdentity, common.IRNibError){ +func (w *rNibReaderInstance) GetListEnbIds() (*[]*entities.NbIdentity, common.IRNibError) { defer readerPool.Put(w) data, err := (*w.sdl).GetMembers("ENB") - if err != nil{ + if err != nil { return nil, common.NewInternalError(err) } return unmarshalIdentityList(data) } -func (w *rNibReaderInstance) GetCountGnbList()(int, common.IRNibError){ +func (w *rNibReaderInstance) GetCountGnbList() (int, common.IRNibError) { defer readerPool.Put(w) data, err := (*w.sdl).GetMembers("GNB") - if err != nil{ + if err != nil { return 0, common.NewInternalError(err) } return len(data), nil } -func (w *rNibReaderInstance) GetCell(inventoryName string, pci uint32) (*entities.Cell, common.IRNibError){ +func (w *rNibReaderInstance) GetCell(inventoryName string, pci uint32) (*entities.Cell, common.IRNibError) { key, rNibErr := common.ValidateAndBuildCellNamePciKey(inventoryName, pci) - if rNibErr != nil{ + if rNibErr != nil { return nil, rNibErr } return (*w).getCellByKey(key) } -func (w *rNibReaderInstance) GetCellById(cellType entities.Cell_Type, cellId string) (*entities.Cell, common.IRNibError){ +func (w *rNibReaderInstance) GetCellById(cellType entities.Cell_Type, cellId string) (*entities.Cell, common.IRNibError) { var key string var rNibErr common.IRNibError if cellType == entities.Cell_LTE_CELL { @@ -182,22 +183,22 @@ func (w *rNibReaderInstance) GetCellById(cellType entities.Cell_Type, cellId str } else { return nil, common.NewValidationError(errors.Errorf("#rNibReader.GetCellById - invalid cell type: %v", cellType)) } - if rNibErr != nil{ + if rNibErr != nil { return nil, rNibErr } return (*w).getCellByKey(key) } -func (w *rNibReaderInstance) getCellByKey(key string) (*entities.Cell, common.IRNibError){ +func (w *rNibReaderInstance) getCellByKey(key string) (*entities.Cell, common.IRNibError) { defer readerPool.Put(w) data, err := (*w.sdl).Get([]string{key}) - if err != nil{ + if err != nil { return nil, common.NewInternalError(err) } cell := entities.Cell{} - if data != nil && data[key] != nil{ - err = proto.Unmarshal( []byte(data[key].(string)), &cell) - if err != nil{ + if data != nil && data[key] != nil { + err = proto.Unmarshal([]byte(data[key].(string)), &cell) + if err != nil { return nil, common.NewInternalError(err) } return &cell, nil @@ -205,12 +206,12 @@ func (w *rNibReaderInstance) getCellByKey(key string) (*entities.Cell, common.IR return nil, common.NewResourceNotFoundError(errors.Errorf("#rNibReader.getCellByKey - cell not found, key: %s", key)) } -func unmarshalIdentityList(data []string ) (*[]*entities.NbIdentity, common.IRNibError){ +func unmarshalIdentityList(data []string) (*[]*entities.NbIdentity, common.IRNibError) { var members []*entities.NbIdentity - for _, d := range data{ + for _, d := range data { member := entities.NbIdentity{} err := proto.Unmarshal([]byte(d), &member) - if err != nil{ + if err != nil { return nil, common.NewInternalError(err) } members = append(members, &member) @@ -218,6 +219,6 @@ func unmarshalIdentityList(data []string ) (*[]*entities.NbIdentity, common.IRNi return &members, nil } -func Close(){ +func Close() { readerPool.Close() -} \ No newline at end of file +}