ConfigMap parameter handling change
[ric-plt/submgr.git] / pkg / control / control.go
index 6111c63..59a840e 100755 (executable)
@@ -51,7 +51,6 @@ func idstring(err error, entries ...fmt.Stringer) string {
        if err != nil {
                retval += filler + "err(" + err.Error() + ")"
                filler = " "
-
        }
        return retval
 }
@@ -97,7 +96,6 @@ func init() {
 
 func NewControl() *Control {
 
-       ReadConfigParameters()
        transport := httptransport.New(viper.GetString("rtmgr.HostAddr")+":"+viper.GetString("rtmgr.port"), viper.GetString("rtmgr.baseUrl"), []string{"http"})
        rtmgrClient := RtmgrClient{rtClient: rtmgrclient.New(transport, strfmt.Default)}
 
@@ -108,8 +106,6 @@ func NewControl() *Control {
        tracker := new(Tracker)
        tracker.Init()
 
-       //subscriber := xapp.NewSubscriber(viper.GetString("subscription.host"), viper.GetInt("subscription.timeout"))
-
        c := &Control{e2ap: new(E2ap),
                registry: registry,
                tracker:  tracker,
@@ -117,12 +113,12 @@ func NewControl() *Control {
                //subscriber: subscriber,
                Counters: xapp.Metric.RegisterCounterGroup(GetMetricsOpts(), "SUBMGR"),
        }
+       c.ReadConfigParameters("")
 
        // Register REST handler for testing support
        xapp.Resource.InjectRoute("/ric/v1/test/{testId}", c.TestRestHandler, "POST")
 
        go xapp.Subscription.Listen(c.SubscriptionHandler, c.QueryHandler, c.SubscriptionDeleteHandler)
-       //go c.subscriber.Listen(c.SubscriptionHandler, c.QueryHandler)
 
        if readSubsFromDb == "false" {
                return c
@@ -144,7 +140,7 @@ func NewControl() *Control {
 //-------------------------------------------------------------------
 //
 //-------------------------------------------------------------------
-func ReadConfigParameters() {
+func (c *Control) ReadConfigParameters(f string) {
 
        // viper.GetDuration returns nanoseconds
        e2tSubReqTimeout = viper.GetDuration("controls.e2tSubReqTimeout_ms") * 1000000
@@ -203,6 +199,7 @@ func (c *Control) ReadyCB(data interface{}) {
 
 func (c *Control) Run() {
        xapp.SetReadyCB(c.ReadyCB, nil)
+       xapp.AddConfigChangeListener(c.ReadConfigParameters)
        xapp.Run(c)
 }
 
@@ -360,8 +357,7 @@ func (c *Control) handleXAPPSubscriptionRequest(params *xapp.RMRParams) {
        }
        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
        }
@@ -373,12 +369,17 @@ 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:
@@ -488,8 +489,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")