X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fdb.go;h=e422cfde69ebbcb034c4c1ce6ef9799a893720f2;hb=40bc000e6cafe3a7eea32e4361268574050c12c4;hp=542c755768f5a5fc4ff7263d3050e48568646dd5;hpb=192518d79ebcffe17bf569bf9037321a6fd26d44;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/db.go b/pkg/xapp/db.go index 542c755..e422cfd 100755 --- a/pkg/xapp/db.go +++ b/pkg/xapp/db.go @@ -20,7 +20,10 @@ package xapp import ( + rnibentities "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" + rnibreader "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader" sdl "gerrit.o-ran-sc.org/r/ric-plt/sdlgo" + rnibwriter "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/rnib" "sync" "time" ) @@ -40,12 +43,39 @@ type SDLClient struct { ready bool } +// Alias +type RNIBNodeType = rnibentities.Node_Type +type RNIBGlobalNbId = rnibentities.GlobalNbId +type RNIBNodebInfo = rnibentities.NodebInfo +type RNIBIRNibError = error +type RNIBCells = rnibentities.Cells +type RNIBNbIdentity = rnibentities.NbIdentity +type RNIBCellType = rnibentities.Cell_Type +type RNIBCell = rnibentities.Cell +type RNIBEnb = rnibentities.Enb +type RNIBGnb = rnibentities.Gnb + +const RNIBNodeENB = rnibentities.Node_ENB +const RNIBNodeGNB = rnibentities.Node_GNB + +type RNIBServedCellInfo = rnibentities.ServedCellInfo +type RNIBNodebInfoEnb = rnibentities.NodebInfo_Enb +type RNIBNodebInfoGnb = rnibentities.NodebInfo_Gnb +type RNIBServedNRCell = rnibentities.ServedNRCell +type RNIBServedNRCellInformation = rnibentities.ServedNRCellInformation +type RNIBNrNeighbourInformation = rnibentities.NrNeighbourInformation + type RNIBClient struct { - db *sdl.SdlInstance + db *sdl.SdlInstance + reader rnibreader.RNibReader + writer rnibwriter.RNibWriter } // NewSDLClient returns a new SDLClient. func NewSDLClient(ns string) *SDLClient { + if ns == "" { + ns = "sdl" + } return &SDLClient{ db: sdl.NewSdlInstance(ns, sdl.NewDatabase()), stat: Metric.RegisterCounterGroup(SDLCounterOpts, "SDL"), @@ -116,6 +146,10 @@ func (s *SDLClient) MStoreAndPublish(channelsAndEvents []string, pairs ...interf return s.db.SetAndPublish(channelsAndEvents, pairs...) } +func (s *SDLClient) Delete(keys []string) (err error) { + return s.db.Remove(keys) +} + func (s *SDLClient) Clear() { s.db.RemoveAll() } @@ -134,39 +168,55 @@ func (c *SDLClient) GetStat() (t SDLStatistics) { return } -// To be removed ... -func NewRNIBClient(ns string) *RNIBClient { +func NewRNIBClient() *RNIBClient { + s := sdl.NewSdlInstance("e2Manager", sdl.NewDatabase()) return &RNIBClient{ - db: sdl.NewSdlInstance(ns, sdl.NewDatabase()), + db: s, + reader: nil, + writer: nil, } } -func (r *RNIBClient) GetgNBList() (values map[string]interface{}, err error) { - keys, err := r.db.GetAll() - if err == nil { - values = make(map[string]interface{}) - for _, key := range keys { - v, err := r.db.Get([]string{key}) - if err == nil { - values[key] = v[key] - } - } - } - return +func (r *RNIBClient) Subscribe(cb func(string, ...string), channel string) error { + return r.db.SubscribeChannel(cb, channel) +} + +func (r *RNIBClient) StoreAndPublish(channel string, event string, pairs ...interface{}) error { + return r.db.SetAndPublish([]string{channel, event}, pairs...) +} + +func (r *RNIBClient) GetNodeb(invName string) (*RNIBNodebInfo, RNIBIRNibError) { + return rnibreader.GetRNibReader(r.db).GetNodeb(invName) +} + +func (r *RNIBClient) GetNodebByGlobalNbId(t RNIBNodeType, gid *RNIBGlobalNbId) (*RNIBNodebInfo, RNIBIRNibError) { + return rnibreader.GetRNibReader(r.db).GetNodebByGlobalNbId(t, gid) +} + +func (r *RNIBClient) GetCellList(invName string) (*RNIBCells, RNIBIRNibError) { + return rnibreader.GetRNibReader(r.db).GetCellList(invName) +} + +func (r *RNIBClient) GetListGnbIds() ([]*RNIBNbIdentity, RNIBIRNibError) { + return rnibreader.GetRNibReader(r.db).GetListGnbIds() +} + +func (r *RNIBClient) GetListEnbIds() ([]*RNIBNbIdentity, RNIBIRNibError) { + return rnibreader.GetRNibReader(r.db).GetListEnbIds() } -func (r *RNIBClient) GetNRCellList(key string) (value map[string]interface{}, err error) { - return r.db.Get([]string{key}) +func (r *RNIBClient) GetCountGnbList() (int, RNIBIRNibError) { + return rnibreader.GetRNibReader(r.db).GetCountGnbList() } -func (r *RNIBClient) GetUE(key1, key2 string) (value map[string]interface{}, err error) { - return r.db.Get([]string{key1 + key2}) +func (r *RNIBClient) GetCell(invName string, pci uint32) (*RNIBCell, RNIBIRNibError) { + return rnibreader.GetRNibReader(r.db).GetCell(invName, pci) } -func (r *RNIBClient) Store(key string, value interface{}) (err error) { - return r.db.Set(key, value) +func (r *RNIBClient) GetCellById(cellType RNIBCellType, cellId string) (*RNIBCell, RNIBIRNibError) { + return rnibreader.GetRNibReader(r.db).GetCellById(cellType, cellId) } -func (r *RNIBClient) Clear() { - r.db.RemoveAll() +func (r *RNIBClient) SaveNodeb(nbIdentity *RNIBNbIdentity, entity *RNIBNodebInfo) RNIBIRNibError { + return rnibwriter.GetRNibWriter(r.db).SaveNodeb(nbIdentity, entity) }