Delete all subscriptions when Ran is under reset.
[ric-plt/submgr.git] / pkg / control / registry.go
index 3de549a..5e9d63e 100644 (file)
@@ -36,7 +36,7 @@ import (
 //-----------------------------------------------------------------------------
 
 type RESTSubscription struct {
-       Created          time.Time
+       Created          string
        xAppServiceName  string
        xAppRmrEndPoint  string
        Meid             string
@@ -233,7 +233,7 @@ func (r *Registry) CreateRESTSubscription(restSubId *string, xappServiceName *st
        r.mutex.Lock()
        defer r.mutex.Unlock()
        newRestSubscription := RESTSubscription{}
-       newRestSubscription.Created = time.Now()
+       newRestSubscription.Created = time.Now().Format("2006-01-02 15:04:05.000")
        newRestSubscription.xAppServiceName = *xappServiceName
        newRestSubscription.xAppRmrEndPoint = *xAppRmrEndPoint
        newRestSubscription.Meid = *maid
@@ -511,7 +511,7 @@ func (r *Registry) CheckActionTypes(subReqMsg *e2ap.E2APSubscriptionRequest) (ui
        return e2ap.E2AP_ActionTypeInvalid, fmt.Errorf("Invalid action type in RICactions-ToBeSetup-List")
 }
 
-func (r *Registry) RemoveFromSubscription(subs *Subscription, trans *TransactionXapp, waitRouteClean time.Duration, c *Control) error {
+func (r *Registry) RemoveFromSubscription(subs *Subscription, trans *TransactionXapp, waitRouteClean time.Duration, c *Control) {
 
        xapp.Logger.Debug("RemoveFromSubscription %s", idstring(nil, trans, subs, trans))
        r.mutex.Lock()
@@ -524,13 +524,15 @@ func (r *Registry) RemoveFromSubscription(subs *Subscription, trans *Transaction
 
        subId := subs.ReqId.InstanceId
        if delStatus == false {
-               return nil
+               return
        }
 
        if waitRouteClean > 0 {
                // Wait here that response is delivered to xApp via RMR before route is cleaned
                xapp.Logger.Debug("Pending %v in order to wait route cleanup", waitRouteClean)
+               r.mutex.Unlock()
                time.Sleep(waitRouteClean)
+               r.mutex.Lock()
        }
 
        xapp.Logger.Debug("CLEAN %s", subs.String())
@@ -567,10 +569,13 @@ func (r *Registry) RemoveFromSubscription(subs *Subscription, trans *Transaction
 
                // Endpoint of merged subscription is being deleted
                xapp.Logger.Debug("Subscription route update WriteSubscriptionToDb")
-               c.WriteSubscriptionToDb(subs)
+               err := c.WriteSubscriptionToDb(subs)
+               if err != nil {
+                       xapp.Logger.Error("tracker.UnTrackTransaction() failed:%s", err.Error())
+               }
                c.UpdateCounter(cUnmergedSubscriptions)
        }
-       return nil
+       return
 }
 
 func (r *Registry) RouteDelete(subs *Subscription, trans *TransactionXapp, c *Control) {
@@ -652,15 +657,17 @@ func (r *Registry) DeleteAllE2Subscriptions(ranName string, c *Control) {
 
        // Delete REST subscription from registry and db
        for restSubId, restSubs := range r.restSubscriptions {
-               if restSubs.Meid == ranName && restSubs.SubReqOngoing == true || restSubs.SubDelReqOngoing == true {
-                       // Subscription creation or deletion processes need to be processed gracefully till the end.
-                       // Subscription is deleted at end of the process in both cases.
-                       xapp.Logger.Debug("Registry: REST subscription under prosessing ongoing cannot delete it yet. RestSubId=%v, SubReqOngoing=%v, SubDelReqOngoing=%v", restSubId, restSubs.SubReqOngoing, restSubs.SubDelReqOngoing)
-                       continue
-               } else {
-                       xapp.Logger.Debug("Registry: REST subscription delete. subId=%v", restSubId)
-                       delete(r.restSubscriptions, restSubId)
-                       c.RemoveRESTSubscriptionFromDb(restSubId)
+               if restSubs.Meid == ranName {
+                       if restSubs.SubReqOngoing == true || restSubs.SubDelReqOngoing == true {
+                               // Subscription creation or deletion processes need to be processed gracefully till the end.
+                               // Subscription is deleted at end of the process in both cases.
+                               xapp.Logger.Debug("Registry: REST subscription under prosessing ongoing cannot delete it yet. RestSubId=%v, SubReqOngoing=%v, SubDelReqOngoing=%v", restSubId, restSubs.SubReqOngoing, restSubs.SubDelReqOngoing)
+                               continue
+                       } else {
+                               xapp.Logger.Debug("Registry: REST subscription delete. subId=%v", restSubId)
+                               delete(r.restSubscriptions, restSubId)
+                               c.RemoveRESTSubscriptionFromDb(restSubId)
+                       }
                }
        }
 }