2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
20 package rmrmsghandlers
25 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
32 type ResourceStatusInitiateNotificationHandler struct {
34 rnibDataService services.RNibDataService
35 resourceStatusService services.IResourceStatusService
39 func NewResourceStatusInitiateNotificationHandler(logger *logger.Logger, rnibDataService services.RNibDataService, resourceStatusService services.IResourceStatusService, requestName string) ResourceStatusInitiateNotificationHandler {
40 return ResourceStatusInitiateNotificationHandler{
42 rnibDataService: rnibDataService,
43 resourceStatusService: resourceStatusService,
44 requestName: requestName,
48 func (h ResourceStatusInitiateNotificationHandler) UnmarshalResourceStatusPayload(inventoryName string, payload []byte) (*models.ResourceStatusPayload, error) {
49 unmarshalledPayload := models.ResourceStatusPayload{}
50 err := json.Unmarshal(payload, &unmarshalledPayload)
53 h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.UnmarshalResourceStatusPayload - RAN name: %s - Error unmarshaling RMR request payload: %v", inventoryName, err)
57 if unmarshalledPayload.NodeType == entities.Node_UNKNOWN {
58 h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.UnmarshalResourceStatusPayload - RAN name: %s - Unknown Node Type", inventoryName)
59 return nil, fmt.Errorf("unknown node type for RAN %s", inventoryName)
62 h.logger.Infof("#ResourceStatusInitiateNotificationHandler.UnmarshalResourceStatusPayload - Unmarshaled payload successfully: %+v", unmarshalledPayload)
63 return &unmarshalledPayload, nil
67 func (h ResourceStatusInitiateNotificationHandler) SaveRsmRanInfoStopTrue(inventoryName string) {
68 rsmRanInfo := models.NewRsmRanInfo(inventoryName, 0, 0, enums.Stop, true)
69 _ = h.rnibDataService.SaveRsmRanInfo(rsmRanInfo)
72 func (h ResourceStatusInitiateNotificationHandler) Handle(request *models.RmrRequest) {
73 inventoryName := request.RanName
74 h.logger.Infof("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - Received %s notification", inventoryName, h.requestName)
76 payload, err := h.UnmarshalResourceStatusPayload(inventoryName, request.Payload)
82 if payload.NodeType != entities.Node_ENB {
83 h.logger.Debugf("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s, Node type isn't ENB", inventoryName)
87 config, err := h.rnibDataService.GetRsmGeneralConfiguration()
93 if !config.EnableResourceStatus {
94 h.SaveRsmRanInfoStopTrue(inventoryName)
98 nodeb, err := h.rnibDataService.GetNodeb(inventoryName)
104 nodebConnectionStatus := nodeb.GetConnectionStatus()
106 h.logger.Infof("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - successfully fetched RAN from db. RAN's connection status: %s", inventoryName, nodebConnectionStatus)
108 if nodebConnectionStatus != entities.ConnectionStatus_CONNECTED {
109 h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - RAN's connection status isn't CONNECTED", inventoryName)
110 h.SaveRsmRanInfoStopTrue(inventoryName)
114 rsmRanInfo := models.NewRsmRanInfo(inventoryName, enums.Enb1MeasurementId, 0, enums.Start, false)
115 err = h.rnibDataService.SaveRsmRanInfo(rsmRanInfo)
121 err = h.resourceStatusService.BuildAndSendInitiateRequest(nodeb, config, rsmRanInfo.Enb1MeasurementId)
124 h.SaveRsmRanInfoStopTrue(inventoryName)