Fix for subscription fail handling
[ric-plt/submgr.git] / pkg / control / control.go
index eff14ee..ac142eb 100755 (executable)
@@ -231,11 +231,12 @@ func (c *Control) SubscriptionDeleteHandler(s string) error {
 }
 
 func (c *Control) QueryHandler() (models.SubscriptionList, error) {
+       xapp.Logger.Info("QueryHandler() called")
+
        return c.registry.QueryHandler()
 }
 
 func (c *Control) TestRestHandler(w http.ResponseWriter, r *http.Request) {
-
        xapp.Logger.Info("TestRestHandler() called")
 
        pathParams := mux.Vars(r)
@@ -352,15 +353,14 @@ func (c *Control) handleXAPPSubscriptionRequest(params *xapp.RMRParams) {
                return
        }
 
-       trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subReqMsg.RequestId.InstanceId, params.Meid)
+       trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subReqMsg.RequestId, params.Meid)
        if trans == nil {
                xapp.Logger.Error("XAPP-SubReq: %s", idstring(fmt.Errorf("transaction not created"), params))
                return
        }
        defer trans.Release()
 
-       err = c.tracker.Track(trans)
-       if err != nil {
+       if err = c.tracker.Track(trans); err != nil {
                xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans))
                return
        }
@@ -372,15 +372,21 @@ func (c *Control) handleXAPPSubscriptionRequest(params *xapp.RMRParams) {
                return
        }
 
-       //
-       // Wake subs request
-       //
+       c.wakeSubscriptionRequest(subs, trans)
+}
+
+//-------------------------------------------------------------------
+// Wake Subscription Request to E2node
+//------------------------------------------------------------------
+func (c *Control) wakeSubscriptionRequest(subs *Subscription, trans *TransactionXapp) {
+
        go c.handleSubscriptionCreate(subs, trans)
        event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
-       err = nil
+       var err error
        if event != nil {
                switch themsg := event.(type) {
                case *e2ap.E2APSubscriptionResponse:
+                       themsg.RequestId.Id = trans.RequestId.Id
                        trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionResponse(themsg)
                        if err == nil {
                                trans.Release()
@@ -389,6 +395,7 @@ func (c *Control) handleXAPPSubscriptionRequest(params *xapp.RMRParams) {
                                return
                        }
                case *e2ap.E2APSubscriptionFailure:
+                       themsg.RequestId.Id = trans.RequestId.Id
                        trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionFailure(themsg)
                        if err == nil {
                                c.UpdateCounter(cSubFailToXapp)
@@ -415,7 +422,7 @@ func (c *Control) handleXAPPSubscriptionDeleteRequest(params *xapp.RMRParams) {
                return
        }
 
-       trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subDelReqMsg.RequestId.InstanceId, params.Meid)
+       trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subDelReqMsg.RequestId, params.Meid)
        if trans == nil {
                xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(fmt.Errorf("transaction not created"), params))
                return
@@ -449,7 +456,8 @@ func (c *Control) handleXAPPSubscriptionDeleteRequest(params *xapp.RMRParams) {
 
        // Whatever is received success, fail or timeout, send successful delete response
        subDelRespMsg := &e2ap.E2APSubscriptionDeleteResponse{}
-       subDelRespMsg.RequestId = subs.GetReqId().RequestId
+       subDelRespMsg.RequestId.Id = trans.RequestId.Id
+       subDelRespMsg.RequestId.InstanceId = subs.GetReqId().RequestId.InstanceId
        subDelRespMsg.FunctionId = subs.SubReqMsg.FunctionId
        trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(subDelRespMsg)
        if err == nil {
@@ -484,8 +492,7 @@ func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *Tran
                case *e2ap.E2APSubscriptionFailure:
                        removeSubscriptionFromDb = true
                        subRfMsg, valid = subs.SetCachedResponse(event, false)
-                       xapp.Logger.Info("SUBS-SubReq: internal delete  due event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
-                       c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
+                       xapp.Logger.Info("SUBS-SubReq: internal delete due event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
                case *SubmgrRestartTestEvent:
                        // This simulates that no response has been received and after restart subscriptions are restored from db
                        xapp.Logger.Debug("Test restart flag is active. Dropping this transaction to test restart case")