Fixed function id handling and improved ut fail handling
[ric-plt/submgr.git] / pkg / control / control.go
index a2c8b0d..c2b33b7 100755 (executable)
@@ -23,7 +23,6 @@ import (
        "fmt"
        "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
        rtmgrclient "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client"
-       rtmgrhandle "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client/handle"
        "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
        httptransport "github.com/go-openapi/runtime/client"
        "github.com/go-openapi/strfmt"
@@ -60,7 +59,7 @@ type RMRMeid struct {
 
 const (
        CREATE Action = 0
-       MERGE  Action = 1
+       UPDATE Action = 1
        NONE   Action = 2
        DELETE Action = 3
 )
@@ -75,10 +74,7 @@ func init() {
 func NewControl() *Control {
 
        transport := httptransport.New(viper.GetString("rtmgr.HostAddr")+":"+viper.GetString("rtmgr.port"), viper.GetString("rtmgr.baseUrl"), []string{"http"})
-       client := rtmgrclient.New(transport, strfmt.Default)
-       handle := rtmgrhandle.NewProvideXappSubscriptionHandleParamsWithTimeout(10 * time.Second)
-       deleteHandle := rtmgrhandle.NewDeleteXappSubscriptionHandleParamsWithTimeout(10 * time.Second)
-       rtmgrClient := RtmgrClient{client, handle, deleteHandle}
+       rtmgrClient := RtmgrClient{rtClient: rtmgrclient.New(transport, strfmt.Default)}
 
        registry := new(Registry)
        registry.Initialize()
@@ -335,7 +331,7 @@ func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *Tran
                parentTrans.SendEvent(nil, 0)
        }
 
-       subs.DelEndpoint(parentTrans.GetEndpoint())
+       go c.registry.RemoveFromSubscription(subs, parentTrans, 5*time.Second)
 }
 
 //-------------------------------------------------------------------
@@ -353,7 +349,7 @@ func (c *Control) handleSubscriptionDelete(subs *Subscription, parentTrans *Tran
        event := c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
 
        parentTrans.SendEvent(event, 0)
-       subs.DelEndpoint(parentTrans.GetEndpoint())
+       go c.registry.RemoveFromSubscription(subs, parentTrans, 5*time.Second)
 }
 
 //-------------------------------------------------------------------
@@ -398,7 +394,7 @@ func (c *Control) sendE2TSubscriptionDeleteRequest(subs *Subscription, trans *Tr
        subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{}
        subDelReqMsg.RequestId.Id = 123
        subDelReqMsg.RequestId.Seq = uint32(subs.GetSubId())
-       subDelReqMsg.FunctionId = 0
+       subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId
        trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg)
        if err != nil {
                xapp.Logger.Error("SUBS-SubDelReq: %s parent %s", idstring(trans, subs, err), parentTrans.String())