Unut test counter check code fixed
[ric-plt/submgr.git] / pkg / control / control.go
index 87c81ff..7de724e 100755 (executable)
@@ -150,7 +150,7 @@ func NewControl() *Control {
                e2SubsDb:          CreateSdl(),
                restSubsDb:        CreateRESTSdl(),
                Counters:          xapp.Metric.RegisterCounterGroup(GetMetricsOpts(), "SUBMGR"),
-               LoggerLevel:       4,
+               LoggerLevel:       1,
        }
 
        e2IfState.Init(c)
@@ -161,16 +161,13 @@ func NewControl() *Control {
        xapp.Resource.InjectRoute("/ric/v1/restsubscriptions", c.GetAllRestSubscriptions, "GET")
        xapp.Resource.InjectRoute("/ric/v1/symptomdata", c.SymptomDataHandler, "GET")
 
-       if readSubsFromDb == "false" {
-               return c
+       if readSubsFromDb == "true" {
+               // Read subscriptions from db
+               c.ReadE2Subscriptions()
+               c.ReadRESTSubscriptions()
        }
 
-       // Read subscriptions from db
-       c.ReadE2Subscriptions()
-       c.ReadRESTSubscriptions()
-
        go xapp.Subscription.Listen(c.RESTSubscriptionHandler, c.RESTQueryHandler, c.RESTSubscriptionDeleteHandler)
-
        return c
 }
 
@@ -241,7 +238,8 @@ func (c *Control) ReadConfigParameters(f string) {
        xapp.Logger.Debug("ReadConfigParameters")
 
        c.LoggerLevel = int(xapp.Logger.GetLevel())
-       xapp.Logger.Debug("LoggerLevel= %v", c.LoggerLevel)
+       xapp.Logger.Info("LoggerLevel = %v", c.LoggerLevel)
+       c.e2ap.SetASN1DebugPrintStatus(c.LoggerLevel)
 
        // viper.GetDuration returns nanoseconds
        e2tSubReqTimeout = viper.GetDuration("controls.e2tSubReqTimeout_ms") * 1000000
@@ -635,6 +633,7 @@ func (c *Control) handleSubscriptionRequest(trans *TransactionXapp, subReqMsg *e
                        break
                }
        } else {
+               // Timer expiry
                err = fmt.Errorf("E2 subscription response timeout")
                errorInfo.SetInfo(err.Error(), "", models.SubscriptionInstanceTimeoutTypeE2Timeout)
                if subs.PolicyUpdate == true {
@@ -643,6 +642,7 @@ func (c *Control) handleSubscriptionRequest(trans *TransactionXapp, subReqMsg *e
        }
 
        xapp.Logger.Error("XAPP-SubReq E2 subscription failed %s", idstring(err, trans, subs))
+
        c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
        return nil, &errorInfo, err
 }
@@ -748,8 +748,8 @@ func (c *Control) RESTSubscriptionDeleteHandler(restSubId string) int {
                                return common.UnsubscribeBadRequestCode
                        } else if restSubscription.SubDelReqOngoing == true {
                                // Previous request for same restSubId still ongoing
-                               c.UpdateCounter(cRestSubDelFailToXapp)
-                               return common.UnsubscribeBadRequestCode
+                               c.UpdateCounter(cRestSubDelRespToXapp)
+                               return common.UnsubscribeNoContentCode
                        }
                }
        }
@@ -1112,13 +1112,13 @@ func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *Tran
                        removeSubscriptionFromDb = true
                        subRfMsg, valid = subs.SetCachedResponse(event, false)
                        xapp.Logger.Debug("SUBS-SubReq: internal delete due failure event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
-                       c.sendE2TSubscriptionDeleteRequest(subs, trans, 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")
                case *PackSubscriptionRequestErrortEvent, *SDLWriteErrortEvent:
                        subRfMsg, valid = subs.SetCachedResponse(event, false)
                default:
+                       // Timer expiry
                        if subs.PolicyUpdate == false {
                                xapp.Logger.Debug("SUBS-SubReq: internal delete due default event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
                                removeSubscriptionFromDb = true