+func (r *Registry) RemoveFromSubscription(subs *Subscription, trans *TransactionXapp, waitRouteClean time.Duration, c *Control) error {
+
+ xapp.Logger.Debug("RemoveFromSubscription %s", idstring(nil, trans, subs, trans))
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
+ subs.mutex.Lock()
+ defer subs.mutex.Unlock()
+
+ delStatus := subs.EpList.DelEndpoint(trans.GetEndpoint())
+ epamount := subs.EpList.Size()
+
+ subId := subs.ReqId.InstanceId
+ if delStatus == false {
+ return nil
+ }
+
+ 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)
+ time.Sleep(waitRouteClean)
+ }
+
+ xapp.Logger.Debug("CLEAN %s", subs.String())
+
+ if epamount == 0 {
+ //
+ // Subscription route delete
+ //
+ if subs.RMRRouteCreated == true {
+ r.RouteDelete(subs, trans, c)
+ }
+
+ // Not merged subscription is being deleted
+ xapp.Logger.Debug("Subscription route delete RemoveSubscriptionFromDb")
+ c.RemoveSubscriptionFromDb(subs)
+
+ //
+ // Subscription release
+ //
+
+ if _, ok := r.register[subId]; ok {
+ xapp.Logger.Debug("RELEASE %s", subs.String())
+ delete(r.register, subId)
+ xapp.Logger.Debug("Registry: substable=%v", r.register)
+ }
+ r.subIds = append(r.subIds, subId)
+ } else if subs.EpList.Size() > 0 {
+ //
+ // Subscription route update
+ //
+ if subs.RMRRouteCreated == true {
+ r.RouteDeleteUpdate(subs, c)
+ }
+
+ // Endpoint of merged subscription is being deleted
+ xapp.Logger.Debug("Subscription route update WriteSubscriptionToDb")
+ c.WriteSubscriptionToDb(subs)
+ c.UpdateCounter(cUnmergedSubscriptions)
+ }
+ return nil
+}
+
+func (r *Registry) RouteDelete(subs *Subscription, trans *TransactionXapp, c *Control) {
+ tmpList := xapp.RmrEndpointList{}
+ tmpList.AddEndpoint(trans.GetEndpoint())
+ subRouteAction := SubRouteInfo{tmpList, uint16(subs.ReqId.InstanceId)}
+ if err := r.rtmgrClient.SubscriptionRequestDelete(subRouteAction); err != nil {
+ c.UpdateCounter(cRouteDeleteFail)
+ }
+}
+
+func (r *Registry) RouteDeleteUpdate(subs *Subscription, c *Control) {
+ subRouteAction := SubRouteInfo{subs.EpList, uint16(subs.ReqId.InstanceId)}
+ if err := r.rtmgrClient.SubscriptionRequestUpdate(subRouteAction); err != nil {
+ c.UpdateCounter(cRouteDeleteUpdateFail)
+ }
+}
+
+func (r *Registry) GetSubscription(subId uint32) *Subscription {
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
+ if _, ok := r.register[subId]; ok {
+ return r.register[subId]
+ }
+ return nil
+}
+
+func (r *Registry) GetSubscriptionFirstMatch(subIds []uint32) (*Subscription, error) {
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
+ for _, subId := range subIds {
+ if _, ok := r.register[subId]; ok {
+ return r.register[subId], nil
+ }
+ }
+ return nil, fmt.Errorf("No valid subscription found with subIds %v", subIds)
+}
+
+func (r *Registry) SetResetTestFlag(resetTestFlag bool, subs *Subscription) {
+ if resetTestFlag == true {
+ // This is used in submgr restart unit tests
+ xapp.Logger.Debug("resetTestFlag == true")
+ subs.DoNotWaitSubResp = true
+ } else {
+ xapp.Logger.Debug("resetTestFlag == false")
+ }
+}
+
+func (r *Registry) DeleteAllE2Subscriptions(ranName string, c *Control) {
+
+ xapp.Logger.Debug("Registry: DeleteAllE2Subscriptions()")
+ for subId, subs := range r.register {
+ if subs.Meid.RanName == ranName {
+ if subs.OngoingReqCount != 0 || subs.OngoingDelCount != 0 {
+ // 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: E2 subscription under prosessing ongoing cannot delete it yet. subId=%v, OngoingReqCount=%v, OngoingDelCount=%v", subId, subs.OngoingReqCount, subs.OngoingDelCount)
+ continue
+ } else {
+ // Delete route
+ if subs.RMRRouteCreated == true {
+ for _, ep := range subs.EpList.Endpoints {
+ tmpList := xapp.RmrEndpointList{}
+ tmpList.AddEndpoint(&ep)
+ subRouteAction := SubRouteInfo{tmpList, uint16(subs.ReqId.InstanceId)}
+ if err := r.rtmgrClient.SubscriptionRequestDelete(subRouteAction); err != nil {
+ c.UpdateCounter(cRouteDeleteFail)
+ }
+ }
+ }
+ // Delete E2 subscription from registry and db
+ xapp.Logger.Debug("Registry: Subscription delete. subId=%v", subId)
+ delete(r.register, subId)
+ r.subIds = append(r.subIds, subId)
+ c.RemoveSubscriptionFromDb(subs)
+ }
+ }
+ }
+
+ // 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)
+ }
+ }
+}