Add new interfaces
[ric-plt/xapp-frame.git] / pkg / xapp / db.go
index 0ab0b1f..542c755 100755 (executable)
@@ -21,9 +21,6 @@ package xapp
 
 import (
        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"
        "sync"
        "time"
 )
@@ -37,14 +34,10 @@ 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
 }
 
 type RNIBClient struct {
@@ -54,7 +47,9 @@ type RNIBClient struct {
 // 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 +62,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 +80,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 {
@@ -121,21 +134,6 @@ func (c *SDLClient) GetStat() (t SDLStatistics) {
        return
 }
 
-func NewUENIBClient() *UENIBClient {
-       return &UENIBClient{
-               reader: uenibreader.NewReader(),
-               writer: uenibwriter.NewWriter(),
-       }
-}
-
-func (u *UENIBClient) StoreUeMeasurement(gNbId string, gNbUeX2ApId string, data *api.MeasResults) error {
-       return u.writer.UpdateUeMeasurement(gNbId, gNbUeX2ApId, data)
-}
-
-func (u *UENIBClient) ReadUeMeasurement(gNbId string, gNbUeX2ApId string) (*api.MeasResults, error) {
-       return u.reader.GetUeMeasurement(gNbId, gNbUeX2ApId)
-}
-
 // To be removed ...
 func NewRNIBClient(ns string) *RNIBClient {
        return &RNIBClient{