Fix for subscription fail handling
[ric-plt/submgr.git] / pkg / control / sdl.go
index ecf6a85..ac8b8fb 100644 (file)
@@ -35,7 +35,6 @@ type SubscriptionInfo struct {
        EpList      xapp.RmrEndpointList
        SubReqMsg   e2ap.E2APSubscriptionRequest
        SubRespMsg  e2ap.E2APSubscriptionResponse
-       SubFailMsg  e2ap.E2APSubscriptionFailure
        SubRespRcvd string
 }
 
@@ -55,9 +54,6 @@ func (c *Control) WriteSubscriptionToSdl(subId uint32, subs *Subscription) error
        if typeofSubsMessage(subs.SubRFMsg) == "SubResp" {
                subscriptionInfo.SubRespRcvd = "SubResp"
                subscriptionInfo.SubRespMsg = *subs.SubRFMsg.(*e2ap.E2APSubscriptionResponse)
-       } else if typeofSubsMessage(subs.SubRFMsg) == "SubFail" {
-               subscriptionInfo.SubRespRcvd = "SubFail"
-               subscriptionInfo.SubFailMsg = *subs.SubRFMsg.(*e2ap.E2APSubscriptionFailure)
        } else {
                subscriptionInfo.SubRespRcvd = ""
        }
@@ -68,6 +64,7 @@ func (c *Control) WriteSubscriptionToSdl(subId uint32, subs *Subscription) error
        }
 
        if err = c.db.Set(strconv.FormatUint(uint64(subId), 10), jsonData); err != nil {
+               c.UpdateCounter(cSDLWriteFailure)
                return fmt.Errorf("SDL: WriteSubscriptionToSdl(): %s", err.Error())
        } else {
                xapp.Logger.Debug("SDL: Subscription written in db. subId = %v", subId)
@@ -81,6 +78,7 @@ func (c *Control) ReadSubscriptionFromSdl(subId uint32) (*Subscription, error) {
        key := strconv.FormatUint(uint64(subId), 10)
        retMap, err := c.db.Get([]string{key})
        if err != nil {
+               c.UpdateCounter(cSDLReadFailure)
                return nil, fmt.Errorf("SDL: ReadSubscriptionFromSdl(): %s", err.Error())
        } else {
                xapp.Logger.Debug("SDL: Subscription read from db.  subId = %v", subId)
@@ -125,11 +123,6 @@ func (c *Control) CreateSubscription(subscriptionInfo *SubscriptionInfo, jsonSub
                subResp := e2ap.E2APSubscriptionResponse{}
                subResp = subscriptionInfo.SubRespMsg
                subs.SubRFMsg = &subResp
-       } else if subscriptionInfo.SubRespRcvd == "SubFail" {
-               subs.SubRespRcvd = false
-               subFail := e2ap.E2APSubscriptionFailure{}
-               subFail = subscriptionInfo.SubFailMsg
-               subs.SubRFMsg = &subFail
        } else {
                subs.SubRespRcvd = false
                subs.SubRFMsg = nil
@@ -162,6 +155,7 @@ func (c *Control) ReadAllSubscriptionsFromSdl() ([]uint32, map[uint32]*Subscript
        // Get all keys
        keys, err := c.db.GetAll()
        if err != nil {
+               c.UpdateCounter(cSDLReadFailure)
                return nil, nil, fmt.Errorf("SDL: ReadAllSubscriptionsFromSdl(), GetAll(). Error while reading keys from DBAAS %s\n", err.Error())
        }
 
@@ -172,6 +166,7 @@ func (c *Control) ReadAllSubscriptionsFromSdl() ([]uint32, map[uint32]*Subscript
        // Get all subscriptionInfos
        iSubscriptionMap, err := c.db.Get(keys)
        if err != nil {
+               c.UpdateCounter(cSDLReadFailure)
                return nil, nil, fmt.Errorf("SDL: ReadAllSubscriptionsFromSdl(), Get():  Error while reading subscriptions from DBAAS %s\n", err.Error())
        }
 
@@ -196,8 +191,7 @@ func (c *Control) ReadAllSubscriptionsFromSdl() ([]uint32, map[uint32]*Subscript
                retMap[subscriptionInfo.ReqId.InstanceId] = subs
 
                // Remove subId from free subIds. Original slice is modified here!
-               subIds, err = removeNumber(subIds, subscriptionInfo.ReqId.InstanceId)
-               if err != nil {
+               if subIds, err = removeNumber(subIds, subscriptionInfo.ReqId.InstanceId); err != nil {
                        return nil, nil, fmt.Errorf("SDL: ReadAllSubscriptionsFromSdl() error: %s\n", err.Error())
                }
        }
@@ -216,6 +210,7 @@ func removeNumber(s []uint32, removedNum uint32) ([]uint32, error) {
 func (c *Control) RemoveAllSubscriptionsFromSdl() error {
 
        if err := c.db.RemoveAll(); err != nil {
+               c.UpdateCounter(cSDLRemoveFailure)
                return fmt.Errorf("SDL: RemoveAllSubscriptionsFromSdl(): %s\n", err.Error())
        } else {
                xapp.Logger.Debug("SDL: All subscriptions removed from db")