X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fsubscription.go;h=6a72f7423f64e3bda3ed34132dd72ccfb0770e5e;hb=refs%2Fchanges%2F22%2F2222%2F1;hp=9bbe3d47dd12675fad0c157683a82bd2d4c44abc;hpb=0388dd945789dae802aaa93c5062e3ae4c45ddf1;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/subscription.go b/pkg/control/subscription.go index 9bbe3d4..6a72f74 100644 --- a/pkg/control/subscription.go +++ b/pkg/control/subscription.go @@ -30,9 +30,10 @@ import ( // //----------------------------------------------------------------------------- type Subscription struct { - mutex sync.Mutex - Seq uint16 - Active bool + mutex sync.Mutex + registry *Registry + Seq uint16 + Active bool // Meid *xapp.RMRMeid RmrEndpoint // xapp endpoint. Now only one xapp can have relation to single subscription. To be changed in merge @@ -45,6 +46,21 @@ func (s *Subscription) String() string { return strconv.FormatUint(uint64(s.Seq), 10) + "/" + s.RmrEndpoint.String() + "/" + s.Meid.RanName } +func (s *Subscription) GetSubId() uint16 { + s.mutex.Lock() + defer s.mutex.Unlock() + return s.Seq +} + +func (s *Subscription) GetMeid() *xapp.RMRMeid { + s.mutex.Lock() + defer s.mutex.Unlock() + if s.Meid != nil { + return s.Meid + } + return nil +} + func (s *Subscription) Confirmed() { s.mutex.Lock() defer s.mutex.Unlock() @@ -96,14 +112,29 @@ func (s *Subscription) GetTransaction() *Transaction { return s.Trans } -func (s *Subscription) UpdateRoute(act Action, rtmgrClient *RtmgrClient) error { - s.mutex.Lock() - defer s.mutex.Unlock() +func (s *Subscription) updateRouteImpl(act Action) error { xapp.Logger.Info("Subscription: Starting routing manager route add. SubId: %d, RmrEndpoint: %s", s.Seq, s.RmrEndpoint) subRouteAction := SubRouteInfo{act, s.RmrEndpoint.Addr, s.RmrEndpoint.Port, s.Seq} - err := rtmgrClient.SubscriptionRequestUpdate(subRouteAction) + err := s.registry.rtmgrClient.SubscriptionRequestUpdate(subRouteAction) if err != nil { return fmt.Errorf("Subscription: Failed to add route. SubId: %d, RmrEndpoint: %s", s.Seq, s.RmrEndpoint) } return nil } + +func (s *Subscription) UpdateRoute(act Action) error { + s.mutex.Lock() + defer s.mutex.Unlock() + return s.updateRouteImpl(act) +} + +func (s *Subscription) Release() { + xapp.Logger.Info("Subscription: Releasing %s", s) + s.mutex.Lock() + defer s.mutex.Unlock() + s.registry.DelSubscription(s.Seq) + err := s.updateRouteImpl(DELETE) + if err != nil { + xapp.Logger.Error("Registry: Failed to del route. SubId: %d, RmrEndpoint: %s", s.Seq, s.RmrEndpoint) + } +}