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.
18 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 // platform project (RICP).
21 package httpmsghandlers
24 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
32 type ResourceStatusRequestHandler struct {
33 rNibDataService services.RNibDataService
35 resourceStatusService services.IResourceStatusService
38 func NewResourceStatusRequestHandler(logger *logger.Logger, rNibDataService services.RNibDataService, resourceStatusService services.IResourceStatusService) *ResourceStatusRequestHandler {
39 return &ResourceStatusRequestHandler{
40 resourceStatusService: resourceStatusService,
41 rNibDataService: rNibDataService,
46 func (h ResourceStatusRequestHandler) Handle(request models.Request) error {
48 resourceStatusRequest := request.(models.ResourceStatusRequest)
49 config, err := h.rNibDataService.GetRsmGeneralConfiguration()
51 return rsmerrors.NewRnibDbError()
54 config.EnableResourceStatus = resourceStatusRequest.EnableResourceStatus
55 err = h.rNibDataService.SaveRsmGeneralConfiguration(config)
57 return rsmerrors.NewRnibDbError()
60 nbIdentityList, err := h.rNibDataService.GetListEnbIds()
62 return rsmerrors.NewRnibDbError()
66 for _, nbIdentity := range nbIdentityList {
68 ranName := (*nbIdentity).GetInventoryName()
70 nodeb, err := h.rNibDataService.GetNodeb(ranName)
72 h.logger.Errorf("#ResourceStatusRequestHandler.Handle - Couldn't find RAN %s in RSM DB", ranName)
77 h.logger.Infof("#ResourceStatusRequestHandler.Handle - handle RAN: %s started", nodeb.RanName)
79 if nodeb.ConnectionStatus != entities.ConnectionStatus_CONNECTED {
80 h.logger.Infof("#ResourceStatusRequestHandler.Handle - RAN name: %s - connection status not CONNECTED, ignore", nodeb.RanName)
81 h.logger.Infof("#ResourceStatusRequestHandler.Handle - handle RAN: %s completed", nodeb.RanName)
85 err = h.saveAndSendRsmRanInfo(nodeb, config)
89 h.logger.Infof("#ResourceStatusRequestHandler.Handle - handle RAN: %s completed", nodeb.RanName)
92 if numberOfFails > 0 {
93 return rsmerrors.NewRsmError(numberOfFails)
98 func (h ResourceStatusRequestHandler) saveAndSendRsmRanInfo(nodebInfo *entities.NodebInfo, config *models.RsmGeneralConfiguration) error {
100 rsmRanInfo, err := h.rNibDataService.GetRsmRanInfo(nodebInfo.RanName)
105 if config.EnableResourceStatus {
106 return h.handleNotStartedRsmRanInfo(nodebInfo, rsmRanInfo, config)
109 return h.handleNotStoppedRsmRanInfo(nodebInfo, rsmRanInfo, config)
112 func (h ResourceStatusRequestHandler) handleNotStoppedRsmRanInfo(nodebInfo *entities.NodebInfo, rsmRanInfo *models.RsmRanInfo, config *models.RsmGeneralConfiguration) error {
113 if rsmRanInfo.Action == enums.Stop && rsmRanInfo.ActionStatus {
117 if rsmRanInfo.Enb2MeasurementId == 0 {
118 h.logger.Errorf("#ResourceStatusRequestHandler.handleNotStoppedRsmRanInfo - RAN: %s Enb2MeasurementId is zero", nodebInfo.RanName)
119 return rsmerrors.NewInternalError()
122 if rsmRanInfo.Action != enums.Stop {
124 err := h.saveRsmRanInfoStopFalse(rsmRanInfo)
130 return h.resourceStatusService.BuildAndSendStopRequest(nodebInfo, config, rsmRanInfo.Enb1MeasurementId, rsmRanInfo.Enb2MeasurementId)
133 func (h ResourceStatusRequestHandler) handleNotStartedRsmRanInfo(nodebInfo *entities.NodebInfo, rsmRanInfo *models.RsmRanInfo, config *models.RsmGeneralConfiguration) error {
134 if rsmRanInfo.Action == enums.Start && rsmRanInfo.ActionStatus {
138 if rsmRanInfo.Action != enums.Start {
140 err := h.saveRsmRanInfoStartFalse(rsmRanInfo)
146 return h.resourceStatusService.BuildAndSendInitiateRequest(nodebInfo, config, rsmRanInfo.Enb1MeasurementId)
149 func (h ResourceStatusRequestHandler) saveRsmRanInfoStopFalse(rsmRanInfo *models.RsmRanInfo) error {
150 rsmRanInfo.Action = enums.Stop
151 rsmRanInfo.ActionStatus = false
153 return h.rNibDataService.SaveRsmRanInfo(rsmRanInfo)
156 func (h ResourceStatusRequestHandler) saveRsmRanInfoStartFalse(rsmRanInfo *models.RsmRanInfo) error {
157 rsmRanInfo.Action = enums.Start
158 rsmRanInfo.ActionStatus = false
159 rsmRanInfo.Enb2MeasurementId = 0
160 rsmRanInfo.Enb1MeasurementId = enums.Enb1MeasurementId
162 return h.rNibDataService.SaveRsmRanInfo(rsmRanInfo)