}
type Registry struct {
- mutex sync.Mutex
+ mutex *sync.Mutex
register map[uint32]*Subscription
subIds []uint32
rtmgrClient *RtmgrClient
}
func (r *Registry) Initialize() {
+ r.mutex = new(sync.Mutex)
r.register = make(map[uint32]*Subscription)
r.restSubscriptions = make(map[string]*RESTSubscription)
Meid: trans.Meid,
RMRRouteCreated: rmrRoutecreated,
SubReqMsg: subReqMsg,
+ OngoingReqCount: 0,
+ OngoingDelCount: 0,
valid: true,
PolicyUpdate: false,
RetryFromXapp: false,
return e2ap.E2AP_ActionTypeInvalid, fmt.Errorf("Invalid action type in RICactions-ToBeSetup-List")
}
-// TODO: Works with concurrent calls, but check if can be improved
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()
delStatus := subs.EpList.DelEndpoint(trans.GetEndpoint())
epamount := subs.EpList.Size()
- subId := subs.ReqId.InstanceId
+ subId := subs.ReqId.InstanceId
if delStatus == false {
return nil
}
- go func() {
- if waitRouteClean > 0 {
- xapp.Logger.Debug("Pending %v in order to wait route cleanup", waitRouteClean)
- time.Sleep(waitRouteClean)
- }
+ 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)
+ }
- subs.mutex.Lock()
- defer subs.mutex.Unlock()
- xapp.Logger.Debug("CLEAN %s", subs.String())
+ xapp.Logger.Debug("CLEAN %s", subs.String())
- if epamount == 0 {
- //
- // Subscription route delete
- //
- if subs.RMRRouteCreated == true {
- r.RouteDelete(subs, trans, c)
- }
+ if epamount == 0 {
+ //
+ // Subscription route delete
+ //
+ if subs.RMRRouteCreated == true {
+ r.RouteDelete(subs, trans, c)
+ }
- //
- // Subscription release
- //
- r.mutex.Lock()
- defer r.mutex.Unlock()
+ // Not merged subscription is being deleted
+ xapp.Logger.Debug("Subscription route delete RemoveSubscriptionFromDb")
+ c.RemoveSubscriptionFromDb(subs)
- 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)
- }
+ //
+ // 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) UpdateSubscriptionToDb(subs *Subscription, c *Control) {
- r.mutex.Lock()
- defer r.mutex.Unlock()
- subs.mutex.Lock()
- defer subs.mutex.Unlock()
-
- epamount := subs.EpList.Size()
- if epamount == 0 {
- if _, ok := r.register[subs.ReqId.InstanceId]; ok {
- // Not merged subscription is being deleted
- c.RemoveSubscriptionFromDb(subs)
-
- }
- } else if subs.EpList.Size() > 0 {
- // Endpoint of merged subscription is being deleted
- c.WriteSubscriptionToDb(subs)
- c.UpdateCounter(cUnmergedSubscriptions)
- }
-}
-
func (r *Registry) GetSubscription(subId uint32) *Subscription {
r.mutex.Lock()
defer r.mutex.Unlock()
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)
+ }
+ }
+}