28a50e54649459aca1c43e114dda296f2102e7a4
[ric-plt/e2mgr.git] / E2Manager / handlers / x2_reset_request_notification_handler.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 package handlers
19
20 import (
21         "e2mgr/e2pdus"
22         "e2mgr/logger"
23         "e2mgr/models"
24         "e2mgr/rmrCgo"
25         "e2mgr/sessions"
26         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
27         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
28 )
29
30 type X2ResetRequestNotificationHandler struct {
31         rnibReaderProvider func() reader.RNibReader
32 }
33
34 func NewX2ResetRequestNotificationHandler(rnibReaderProvider func() reader.RNibReader) X2ResetRequestNotificationHandler {
35         return X2ResetRequestNotificationHandler{
36                 rnibReaderProvider: rnibReaderProvider,
37         }
38 }
39
40 func (src X2ResetRequestNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions,
41         request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) {
42
43         logger.Debugf("#X2ResetRequestNotificationHandler.Handle - Ran name: %s", request.RanName)
44
45         nb, rNibErr := src.rnibReaderProvider().GetNodeb(request.RanName)
46         if rNibErr != nil {
47                 logger.Errorf("#X2ResetRequestNotificationHandler.Handle - failed to retrieve nodeB entity. RanName: %s. Error: %s", request.RanName, rNibErr.Error())
48                 printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime)
49
50                 return
51         }
52         logger.Debugf("#X2ResetRequestNotificationHandler.Handle - nodeB entity retrieved. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus)
53
54         if nb.ConnectionStatus == entities.ConnectionStatus_SHUTTING_DOWN {
55                 logger.Warnf("#X2ResetRequestNotificationHandler.Handle - nodeB entity in incorrect state. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus)
56                 printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime)
57
58                 return
59         }
60
61         if nb.ConnectionStatus != entities.ConnectionStatus_CONNECTED {
62                 logger.Errorf("#X2ResetRequestNotificationHandler.Handle - nodeB entity in incorrect state. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus)
63                 printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime)
64
65                 return
66         }
67         response := models.NotificationResponse{RanName: request.RanName, Payload: e2pdus.PackedX2ResetResponse, MgsType: rmrCgo.RIC_X2_RESET_RESP}
68         messageChannel <- &response
69
70         //TODO change name of printHandlingSetupResponseElapsedTimeInMs (remove setup response) and move to utils?
71         printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime)
72 }