Added timer & change status to connected state.
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / e2_reset_request_handler.go
index a800fef..76a0b1a 100644 (file)
 package rmrmsghandlers\r
 \r
 import (\r
+       "e2mgr/configuration"\r
        "e2mgr/logger"\r
        "e2mgr/models"\r
        "e2mgr/services"\r
        "e2mgr/utils"\r
+       "time"\r
+\r
        "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"\r
 )\r
 \r
@@ -31,12 +34,14 @@ const E2ResetRequestLogInfoElapsedTime = "#E2ResetRequestNotificationHandler.Han
 type E2ResetRequestNotificationHandler struct {\r
        logger          *logger.Logger\r
        rnibDataService services.RNibDataService\r
+       config          *configuration.Configuration\r
 }\r
 \r
-func NewE2ResetRequestNotificationHandler(logger *logger.Logger, rnibDataService services.RNibDataService) *E2ResetRequestNotificationHandler {\r
+func NewE2ResetRequestNotificationHandler(logger *logger.Logger, rnibDataService services.RNibDataService, config *configuration.Configuration) *E2ResetRequestNotificationHandler {\r
        return &E2ResetRequestNotificationHandler{\r
                logger:          logger,\r
                rnibDataService: rnibDataService,\r
+               config:          config,\r
        }\r
 }\r
 \r
@@ -66,6 +71,19 @@ func (e *E2ResetRequestNotificationHandler) Handle(request *models.NotificationR
        e.logger.Debugf("#E2ResetRequestNotificationHandler.Handle - nodeB entity under reset state. RanName %s, ConnectionStatus %s", nodebInfo.RanName, nodebInfo.ConnectionStatus)\r
 \r
        e.logger.Infof(E2ResetRequestLogInfoElapsedTime, utils.ElapsedTime(request.StartTime))\r
+\r
+       e.waitfortimertimeout(request)\r
+\r
+       nodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTED\r
+\r
+       err = e.rnibDataService.UpdateNodebInfoAndPublish(nodebInfo)\r
+\r
+       if err != nil {\r
+               e.logger.Errorf("#E2ResetRequestNotificationHandler.Handle - failed to update connection status of nodeB entity. RanName: %s. Error: %s", request.RanName, err.Error())\r
+       }\r
+\r
+       e.logger.Debugf("#E2ResetRequestNotificationHandler.Handle - nodeB entity connected state. RanName %s, ConnectionStatus %s", nodebInfo.RanName, nodebInfo.ConnectionStatus)\r
+\r
 }\r
 \r
 func (e *E2ResetRequestNotificationHandler) getNodebInfo(ranName string) (*entities.NodebInfo, error) {\r
@@ -77,3 +95,15 @@ func (e *E2ResetRequestNotificationHandler) getNodebInfo(ranName string) (*entit
        }\r
        return nodebInfo, err\r
 }\r
+\r
+func (e *E2ResetRequestNotificationHandler) waitfortimertimeout(request *models.NotificationRequest) {\r
+       timeout := e.config.E2ResetTimeOutSec\r
+       for {\r
+               timeElapsed := utils.ElapsedTime(request.StartTime)\r
+               e.logger.Infof(E2ResetRequestLogInfoElapsedTime, utils.ElapsedTime(request.StartTime))\r
+               if int(timeElapsed) > timeout {\r
+                       break\r
+               }\r
+               time.Sleep(time.Duration(timeout/100) * time.Millisecond)\r
+       }\r
+}\r