Handling e2 reset request & change status to reset
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / e2_reset_request_handler.go
1 //\r
2 // Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved.\r
3 //\r
4 // Licensed under the Apache License, Version 2.0 (the "License");\r
5 // you may not use this file except in compliance with the License.\r
6 // You may obtain a copy of the License at\r
7 //\r
8 //      http://www.apache.org/licenses/LICENSE-2.0\r
9 //\r
10 // Unless required by applicable law or agreed to in writing, software\r
11 // distributed under the License is distributed on an "AS IS" BASIS,\r
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13 // See the License for the specific language governing permissions and\r
14 // limitations under the License.\r
15 \r
16 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)\r
17 //  platform project (RICP).\r
18 \r
19 package rmrmsghandlers\r
20 \r
21 import (\r
22         "e2mgr/logger"\r
23         "e2mgr/models"\r
24         "e2mgr/services"\r
25         "e2mgr/utils"\r
26         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"\r
27 )\r
28 \r
29 const E2ResetRequestLogInfoElapsedTime = "#E2ResetRequestNotificationHandler.Handle - Summary: elapsed time for receiving and handling reset request message from E2 terminator: %f ms"\r
30 \r
31 type E2ResetRequestNotificationHandler struct {\r
32         logger          *logger.Logger\r
33         rnibDataService services.RNibDataService\r
34 }\r
35 \r
36 func NewE2ResetRequestNotificationHandler(logger *logger.Logger, rnibDataService services.RNibDataService) *E2ResetRequestNotificationHandler {\r
37         return &E2ResetRequestNotificationHandler{\r
38                 logger:          logger,\r
39                 rnibDataService: rnibDataService,\r
40         }\r
41 }\r
42 \r
43 func (e *E2ResetRequestNotificationHandler) Handle(request *models.NotificationRequest) {\r
44 \r
45         e.logger.Infof("#E2ResetRequestNotificationHandler.Handle - RAN name: %s - received E2_Reset. Payload: %x", request.RanName, request.Payload)\r
46 \r
47         e.logger.Debugf("#E2ResetRequestNotificationHandler.Handle - RIC_E2_Node_Reset parsed successfully ")\r
48 \r
49         nodebInfo, err := e.getNodebInfo(request.RanName)\r
50         if err != nil {\r
51                 e.logger.Errorf("#E2ResetRequestNotificationHandler.Handle - failed to retrieve nodeB entity. RanName: %s. Error: %s", request.RanName, err.Error())\r
52                 e.logger.Infof(E2ResetRequestLogInfoElapsedTime, utils.ElapsedTime(request.StartTime))\r
53                 return\r
54         }\r
55 \r
56         e.logger.Debugf("#E2ResetRequestNotificationHandler.Handle - nodeB entity retrieved. RanName %s, ConnectionStatus %s", nodebInfo.RanName, nodebInfo.ConnectionStatus)\r
57 \r
58         nodebInfo.ConnectionStatus = entities.ConnectionStatus_UNDER_RESET\r
59 \r
60         err = e.rnibDataService.UpdateNodebInfoAndPublish(nodebInfo)\r
61 \r
62         if err != nil {\r
63                 e.logger.Errorf("#E2ResetRequestNotificationHandler.Handle - failed to update connection status of nodeB entity. RanName: %s. Error: %s", request.RanName, err.Error())\r
64         }\r
65 \r
66         e.logger.Debugf("#E2ResetRequestNotificationHandler.Handle - nodeB entity under reset state. RanName %s, ConnectionStatus %s", nodebInfo.RanName, nodebInfo.ConnectionStatus)\r
67 \r
68         e.logger.Infof(E2ResetRequestLogInfoElapsedTime, utils.ElapsedTime(request.StartTime))\r
69 }\r
70 \r
71 func (e *E2ResetRequestNotificationHandler) getNodebInfo(ranName string) (*entities.NodebInfo, error) {\r
72 \r
73         nodebInfo, err := e.rnibDataService.GetNodeb(ranName)\r
74         if err != nil {\r
75                 e.logger.Errorf("#E2ResetRequestNotificationHandler.Handle - failed to retrieve nodeB entity. RanName: %s. Error: %s", ranName, err.Error())\r
76                 return nil, err\r
77         }\r
78         return nodebInfo, err\r
79 }\r