X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fsdl_e2SubsDb.go;h=d1830dee9df6f11ac43ff1e648dd0285a9da6a0e;hb=483bd162c10ee2f0ef348b5c25c2987aea80b7c8;hp=2afa36e306e9a8e78b4f561b8c46dc6d34787c96;hpb=f682ace08a827bd260e4905b5ee1bddacf01c6e0;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/sdl_e2SubsDb.go b/pkg/control/sdl_e2SubsDb.go index 2afa36e..d1830de 100644 --- a/pkg/control/sdl_e2SubsDb.go +++ b/pkg/control/sdl_e2SubsDb.go @@ -29,6 +29,8 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" ) +const e2SubSdlNs = "submgr_e2SubsDb" + type SubscriptionInfo struct { Valid bool ReqId RequestId @@ -41,7 +43,7 @@ type SubscriptionInfo struct { } func CreateSdl() Sdlnterface { - return sdl.NewSdlInstance("submgr_e2SubsDb", sdl.NewDatabase()) + return sdl.NewSyncStorage() } func (c *Control) WriteSubscriptionToSdl(subId uint32, subs *Subscription) error { @@ -66,7 +68,7 @@ func (c *Control) WriteSubscriptionToSdl(subId uint32, subs *Subscription) error return fmt.Errorf("SDL: WriteSubscriptionToSdl() json.Marshal error: %s", err.Error()) } - if err = c.e2SubsDb.Set(strconv.FormatUint(uint64(subId), 10), jsonData); err != nil { + if err = c.e2SubsDb.Set(e2SubSdlNs, strconv.FormatUint(uint64(subId), 10), jsonData); err != nil { c.UpdateCounter(cSDLWriteFailure) return fmt.Errorf("SDL: WriteSubscriptionToSdl(): %s", err.Error()) } else { @@ -79,7 +81,7 @@ func (c *Control) ReadSubscriptionFromSdl(subId uint32) (*Subscription, error) { // This function is now just for testing purpose key := strconv.FormatUint(uint64(subId), 10) - retMap, err := c.e2SubsDb.Get([]string{key}) + retMap, err := c.e2SubsDb.Get(e2SubSdlNs, []string{key}) if err != nil { c.UpdateCounter(cSDLReadFailure) return nil, fmt.Errorf("SDL: ReadSubscriptionFromSdl(): %s", err.Error()) @@ -138,7 +140,7 @@ func (c *Control) CreateSubscription(subscriptionInfo *SubscriptionInfo, jsonSub func (c *Control) RemoveSubscriptionFromSdl(subId uint32) error { key := strconv.FormatUint(uint64(subId), 10) - if err := c.e2SubsDb.Remove([]string{key}); err != nil { + if err := c.e2SubsDb.Remove(e2SubSdlNs, []string{key}); err != nil { return fmt.Errorf("SDL: RemoveSubscriptionfromSdl(): %s\n", err.Error()) } else { xapp.Logger.Debug("SDL: Subscription removed from e2SubsDb. subId = %v", subId) @@ -157,7 +159,7 @@ func (c *Control) ReadAllSubscriptionsFromSdl() ([]uint32, map[uint32]*Subscript retMap := make(map[uint32]*Subscription) // Get all keys - keys, err := c.e2SubsDb.GetAll() + keys, err := c.e2SubsDb.GetAll(e2SubSdlNs) if err != nil { c.UpdateCounter(cSDLReadFailure) return nil, nil, fmt.Errorf("SDL: ReadAllSubscriptionsFromSdl(), GetAll(). Error while reading E2 subscriptions keys from DBAAS %s\n", err.Error()) @@ -168,7 +170,7 @@ func (c *Control) ReadAllSubscriptionsFromSdl() ([]uint32, map[uint32]*Subscript } // Get all subscriptionInfos - iSubscriptionMap, err := c.e2SubsDb.Get(keys) + iSubscriptionMap, err := c.e2SubsDb.Get(e2SubSdlNs, keys) if err != nil { c.UpdateCounter(cSDLReadFailure) return nil, nil, fmt.Errorf("SDL: ReadAllSubscriptionsFromSdl(), Get(): Error while reading E2 subscriptions from DBAAS %s\n", err.Error()) @@ -213,7 +215,7 @@ func removeNumber(s []uint32, removedNum uint32) ([]uint32, error) { } func (c *Control) RemoveAllSubscriptionsFromSdl() error { - if err := c.e2SubsDb.RemoveAll(); err != nil { + if err := c.e2SubsDb.RemoveAll(e2SubSdlNs); err != nil { c.UpdateCounter(cSDLRemoveFailure) return fmt.Errorf("SDL: RemoveAllSubscriptionsFromSdl(): %s\n", err.Error()) } else { @@ -221,3 +223,14 @@ func (c *Control) RemoveAllSubscriptionsFromSdl() error { } return nil } + +func (c *Control) GetE2KeyCount() (int, error) { + + // Get all keys + keys, err := c.e2SubsDb.GetAll(e2SubSdlNs) + if err != nil { + c.UpdateCounter(cSDLReadFailure) + return 0, fmt.Errorf("SDL: GetE2KeyCount(), GetAll(). Error while reading E2 subscriptions keys from DBAAS %s\n", err.Error()) + } + return len(keys), nil +}