X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fdb.go;h=6591e04699c98f2c7cafb50933b6a7bf3193f687;hb=refs%2Fchanges%2F58%2F4558%2F1;hp=0ab0b1f6b30f5aaf225ed5e801770a7a0d141f71;hpb=2e78e42c5896b61b77ab3a97e45704f6749161b2;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/db.go b/pkg/xapp/db.go index 0ab0b1f..6591e04 100755 --- a/pkg/xapp/db.go +++ b/pkg/xapp/db.go @@ -20,10 +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" - "gitlabe1.ext.net.nokia.com/ric_dev/ue-nib/api" - "gitlabe1.ext.net.nokia.com/ric_dev/ue-nib/pkg/uenibreader" - "gitlabe1.ext.net.nokia.com/ric_dev/ue-nib/pkg/uenibwriter" + rnibwriter "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/rnib" "sync" "time" ) @@ -37,24 +37,46 @@ var SDLCounterOpts = []CounterOpts{ } type SDLClient struct { - db *sdl.SdlInstance - stat map[string]Counter - mux sync.Mutex -} - -type UENIBClient struct { - reader *uenibreader.Reader - writer *uenibwriter.Writer -} + db *sdl.SdlInstance + stat map[string]Counter + mux sync.Mutex + 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 { return &SDLClient{ - db: sdl.NewSdlInstance(ns, sdl.NewDatabase()), + db: sdl.NewSdlInstance(ns, sdl.NewDatabase()), + stat: Metric.RegisterCounterGroup(SDLCounterOpts, "SDL"), + ready: false, } } @@ -67,13 +89,16 @@ func (s *SDLClient) TestConnection() { Logger.Warn("Database connection not ready, waiting ...") time.Sleep(time.Duration(5 * time.Second)) } + s.ready = true Logger.Info("Connection to database established!") +} - s.RegisterMetrics() +func (s *SDLClient) IsReady() bool { + return s.ready } -func (s *SDLClient) Store(key string, value interface{}) (err error) { - err = s.db.Set(key, value) +func (s *SDLClient) doSet(pairs ...interface{}) (err error) { + err = s.db.Set(pairs) if err != nil { s.UpdateStatCounter("StoreError") } else { @@ -82,9 +107,24 @@ func (s *SDLClient) Store(key string, value interface{}) (err error) { return } +func (s *SDLClient) Store(key string, value interface{}) (err error) { + return s.doSet(key, value) +} + +func (s *SDLClient) MStore(pairs ...interface{}) (err error) { + return s.doSet(pairs) +} + func (s *SDLClient) Read(key string) (value map[string]interface{}, err error) { - value, err = s.db.Get([]string{key}) - return + return s.db.Get([]string{key}) +} + +func (s *SDLClient) MRead(key []string) (value map[string]interface{}, err error) { + return s.db.Get(key) +} + +func (s *SDLClient) ReadAllKeys(key string) (value []string, err error) { + return s.db.GetAll() } func (s *SDLClient) Subscribe(cb func(string, ...string), channel string) error { @@ -103,6 +143,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() } @@ -121,54 +165,55 @@ func (c *SDLClient) GetStat() (t SDLStatistics) { return } -func NewUENIBClient() *UENIBClient { - return &UENIBClient{ - reader: uenibreader.NewReader(), - writer: uenibwriter.NewWriter(), +func NewRNIBClient(ns string) *RNIBClient { + s := sdl.NewSdlInstance("e2Manager", sdl.NewDatabase()) + return &RNIBClient{ + db: s, + reader: nil, + writer: nil, } } -func (u *UENIBClient) StoreUeMeasurement(gNbId string, gNbUeX2ApId string, data *api.MeasResults) error { - return u.writer.UpdateUeMeasurement(gNbId, gNbUeX2ApId, data) +func (r *RNIBClient) Subscribe(cb func(string, ...string), channel string) error { + return r.db.SubscribeChannel(cb, channel) } -func (u *UENIBClient) ReadUeMeasurement(gNbId string, gNbUeX2ApId string) (*api.MeasResults, error) { - return u.reader.GetUeMeasurement(gNbId, gNbUeX2ApId) +func (r *RNIBClient) StoreAndPublish(channel string, event string, pairs ...interface{}) error { + return r.db.SetAndPublish([]string{channel, event}, pairs...) } -// To be removed ... -func NewRNIBClient(ns string) *RNIBClient { - return &RNIBClient{ - db: sdl.NewSdlInstance(ns, sdl.NewDatabase()), - } +func (r *RNIBClient) GetNodeb(invName string) (*RNIBNodebInfo, RNIBIRNibError) { + return rnibreader.GetRNibReader(r.db).GetNodeb(invName) } -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) 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) }