X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fsdl_restSubsDb.go;h=ac85d98ed8f393c17f049413a3fe659ab10e668b;hb=d13ba63c1c237882202fc975d70ed5ad21a48fcf;hp=23483036f4112326b9ee3d6addae0b3c2969ea38;hpb=3cdd2e0c0d042b816f6d35f68a93f97fbbe7efc1;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/sdl_restSubsDb.go b/pkg/control/sdl_restSubsDb.go index 2348303..ac85d98 100644 --- a/pkg/control/sdl_restSubsDb.go +++ b/pkg/control/sdl_restSubsDb.go @@ -27,7 +27,11 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" ) +const restSubSdlNs = "submgr_restSubsDb" + type RESTSubscriptionInfo struct { + Created string + XAppServiceName string XAppRmrEndPoint string Meid string InstanceIds []uint32 @@ -38,12 +42,14 @@ type RESTSubscriptionInfo struct { } func CreateRESTSdl() Sdlnterface { - return sdl.NewSdlInstance("submgr_restSubsDb", sdl.NewDatabase()) + return sdl.NewSyncStorage() } func (c *Control) WriteRESTSubscriptionToSdl(restSubId string, restSubs *RESTSubscription) error { var restSubscriptionInfo RESTSubscriptionInfo + restSubscriptionInfo.Created = restSubs.Created + restSubscriptionInfo.XAppServiceName = restSubs.xAppServiceName restSubscriptionInfo.XAppRmrEndPoint = restSubs.xAppRmrEndPoint restSubscriptionInfo.Meid = restSubs.Meid restSubscriptionInfo.InstanceIds = restSubs.InstanceIds @@ -57,7 +63,7 @@ func (c *Control) WriteRESTSubscriptionToSdl(restSubId string, restSubs *RESTSub return fmt.Errorf("SDL: WriteSubscriptionToSdl() json.Marshal error: %s", err.Error()) } - if err = c.restSubsDb.Set(restSubId, jsonData); err != nil { + if err = c.restSubsDb.Set(restSubSdlNs, restSubId, jsonData); err != nil { c.UpdateCounter(cSDLWriteFailure) return fmt.Errorf("SDL: WriteSubscriptionToSdl(): %s", err.Error()) } else { @@ -70,7 +76,7 @@ func (c *Control) ReadRESTSubscriptionFromSdl(restSubId string) (*RESTSubscripti // This function is now just for testing purpose key := restSubId - retMap, err := c.restSubsDb.Get([]string{key}) + retMap, err := c.restSubsDb.Get(restSubSdlNs, []string{key}) if err != nil { c.UpdateCounter(cSDLReadFailure) return nil, fmt.Errorf("SDL: ReadSubscriptionFromSdl(): %s", err.Error()) @@ -102,6 +108,8 @@ func (c *Control) ReadRESTSubscriptionFromSdl(restSubId string) (*RESTSubscripti func (c *Control) CreateRESTSubscription(restSubscriptionInfo *RESTSubscriptionInfo, jsonSubscriptionInfo *string) *RESTSubscription { restSubs := &RESTSubscription{} + restSubs.Created = restSubscriptionInfo.Created + restSubs.xAppServiceName = restSubscriptionInfo.XAppServiceName restSubs.xAppRmrEndPoint = restSubscriptionInfo.XAppRmrEndPoint restSubs.Meid = restSubscriptionInfo.Meid restSubs.InstanceIds = restSubscriptionInfo.InstanceIds @@ -116,7 +124,7 @@ func (c *Control) CreateRESTSubscription(restSubscriptionInfo *RESTSubscriptionI func (c *Control) RemoveRESTSubscriptionFromSdl(restSubId string) error { key := restSubId - if err := c.restSubsDb.Remove([]string{key}); err != nil { + if err := c.restSubsDb.Remove(restSubSdlNs, []string{key}); err != nil { return fmt.Errorf("SDL: RemoveSubscriptionfromSdl(): %s\n", err.Error()) } else { xapp.Logger.Debug("SDL: Subscription removed from restSubsDb. restSubId = %v", restSubId) @@ -128,7 +136,7 @@ func (c *Control) ReadAllRESTSubscriptionsFromSdl() (map[string]*RESTSubscriptio retMap := make(map[string]*RESTSubscription) // Get all keys - keys, err := c.restSubsDb.GetAll() + keys, err := c.restSubsDb.GetAll(restSubSdlNs) if err != nil { c.UpdateCounter(cSDLReadFailure) return nil, fmt.Errorf("SDL: ReadAllSubscriptionsFromSdl(), GetAll(). Error while reading REST subscriptions keys from DBAAS %s\n", err.Error()) @@ -139,7 +147,7 @@ func (c *Control) ReadAllRESTSubscriptionsFromSdl() (map[string]*RESTSubscriptio } // Get all subscriptionInfos - iRESTSubscriptionMap, err := c.restSubsDb.Get(keys) + iRESTSubscriptionMap, err := c.restSubsDb.Get(restSubSdlNs, keys) if err != nil { c.UpdateCounter(cSDLReadFailure) return nil, fmt.Errorf("SDL: ReadAllSubscriptionsFromSdl(), Get(): Error while reading REST subscriptions from DBAAS %s\n", err.Error()) @@ -166,11 +174,22 @@ func (c *Control) ReadAllRESTSubscriptionsFromSdl() (map[string]*RESTSubscriptio func (c *Control) RemoveAllRESTSubscriptionsFromSdl() error { - if err := c.restSubsDb.RemoveAll(); err != nil { + if err := c.restSubsDb.RemoveAll(restSubSdlNs); err != nil { c.UpdateCounter(cSDLRemoveFailure) return fmt.Errorf("SDL: RemoveAllSubscriptionsFromSdl(): %s\n", err.Error()) } else { - xapp.Logger.Debug("SDL: All subscriptions removed from e2SubsDb") + xapp.Logger.Debug("SDL: All subscriptions removed from restSubsDb") } return nil } + +func (c *Control) GetRESTKeyCount() (int, error) { + + // Get all keys + keys, err := c.restSubsDb.GetAll(restSubSdlNs) + if err != nil { + c.UpdateCounter(cSDLReadFailure) + return 0, fmt.Errorf("SDL: GetRESTKeyCount(), GetAll(). Error while reading E2 subscriptions keys from DBAAS %s\n", err.Error()) + } + return len(keys), nil +}