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 httpmsghandlers
23 "e2mgr/e2managererrors"
27 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
28 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
29 "github.com/pkg/errors"
32 const VALIDATION_FAILURE_MESSAGE = "#UpdateGnbRequestHandler.Handle - validation failure: %s is a mandatory field"
34 type UpdateGnbRequestHandler struct {
36 rNibDataService services.RNibDataService
39 func NewUpdateGnbRequestHandler(logger *logger.Logger, rNibDataService services.RNibDataService) *UpdateGnbRequestHandler {
40 return &UpdateGnbRequestHandler{
42 rNibDataService: rNibDataService,
46 func (h *UpdateGnbRequestHandler) Handle(request models.Request) (models.IResponse, error) {
48 updateGnbRequest := request.(models.UpdateGnbRequest)
50 h.logger.Infof("#UpdateGnbRequestHandler.Handle - Ran name: %s", updateGnbRequest.RanName)
52 err := h.validateRequestBody(updateGnbRequest)
58 nodebInfo, err := h.rNibDataService.GetNodeb(updateGnbRequest.RanName)
61 _, ok := err.(*common.ResourceNotFoundError)
63 h.logger.Errorf("#UpdateGnbRequestHandler.Handle - RAN name: %s - failed to get nodeb entity from RNIB. Error: %s", updateGnbRequest.RanName, err)
64 return nil, e2managererrors.NewRnibDbError()
67 h.logger.Errorf("#UpdateGnbRequestHandler.Handle - RAN name: %s - RAN not found on RNIB. Error: %s", updateGnbRequest.RanName, err)
68 return nil, e2managererrors.NewResourceNotFoundError()
71 err = h.updateGnbCells(nodebInfo, updateGnbRequest)
77 return models.NewUpdateGnbResponse(nodebInfo), nil
80 func (h *UpdateGnbRequestHandler) updateGnbCells(nodebInfo *entities.NodebInfo, updateGnbRequest models.UpdateGnbRequest) error {
82 ranName := nodebInfo.RanName
83 gnb := nodebInfo.GetGnb()
86 h.logger.Errorf("#UpdateGnbRequestHandler.updateGnbCells - RAN name: %s - nodeb missing gnb configuration", ranName)
87 return e2managererrors.NewInternalError()
90 if len(gnb.ServedNrCells) != 0 {
91 err := h.rNibDataService.RemoveServedNrCells(ranName, gnb.ServedNrCells)
94 h.logger.Errorf("#UpdateGnbRequestHandler.updateGnbCells - RAN name: %s - Failed removing served nr cells", ranName)
95 return e2managererrors.NewRnibDbError()
99 gnb.ServedNrCells = updateGnbRequest.ServedNrCells
101 err := h.rNibDataService.UpdateGnbCells(nodebInfo, updateGnbRequest.ServedNrCells)
104 h.logger.Errorf("#UpdateGnbRequestHandler.updateGnbCells - RAN name: %s - Failed updating GNB cells. Error: %s", ranName, err)
105 return e2managererrors.NewRnibDbError()
108 h.logger.Infof("#UpdateGnbRequestHandler.updateGnbCells - RAN name: %s - Successfully updated GNB cells", ranName)
112 func (h *UpdateGnbRequestHandler) validateRequestBody(updateGnbRequest models.UpdateGnbRequest) error {
114 if len(updateGnbRequest.ServedNrCells) == 0 {
115 h.logger.Errorf(VALIDATION_FAILURE_MESSAGE+" and cannot be empty", "servedCells")
116 return e2managererrors.NewRequestValidationError()
119 for _, servedNrCell := range updateGnbRequest.ServedNrCells {
120 if servedNrCell.ServedNrCellInformation == nil {
121 h.logger.Errorf(VALIDATION_FAILURE_MESSAGE+" and cannot be empty", "servedNrCellInformation")
122 return e2managererrors.NewRequestValidationError()
125 err := isServedNrCellInformationValid(servedNrCell.ServedNrCellInformation)
128 h.logger.Errorf(VALIDATION_FAILURE_MESSAGE, err)
129 return e2managererrors.NewRequestValidationError()
132 if len(servedNrCell.NrNeighbourInfos) == 0 {
136 for _, nrNeighbourInformation := range servedNrCell.NrNeighbourInfos {
138 err := isNrNeighbourInformationValid(nrNeighbourInformation)
141 h.logger.Errorf(VALIDATION_FAILURE_MESSAGE, err)
142 return e2managererrors.NewRequestValidationError()
151 func isServedNrCellInformationValid(servedNrCellInformation *entities.ServedNRCellInformation) error {
152 if servedNrCellInformation.CellId == "" {
153 return errors.New("cellId")
156 if servedNrCellInformation.ChoiceNrMode == nil {
157 return errors.New("choiceNrMode")
160 if servedNrCellInformation.NrMode == entities.Nr_UNKNOWN {
161 return errors.New("nrMode")
164 if servedNrCellInformation.NrPci == 0 {
165 return errors.New("nrPci")
168 if len(servedNrCellInformation.ServedPlmns) == 0 {
169 return errors.New("servedPlmns")
172 return isServedNrCellInfoChoiceNrModeValid(servedNrCellInformation.ChoiceNrMode)
175 func isServedNrCellInfoChoiceNrModeValid(choiceNrMode *entities.ServedNRCellInformation_ChoiceNRMode) error {
176 if choiceNrMode.Fdd != nil {
177 return isServedNrCellInfoFddValid(choiceNrMode.Fdd)
180 if choiceNrMode.Tdd != nil {
181 return isServedNrCellInfoTddValid(choiceNrMode.Tdd)
184 return errors.New("served nr cell fdd / tdd")
187 func isServedNrCellInfoTddValid(tdd *entities.ServedNRCellInformation_ChoiceNRMode_TddInfo) error {
191 func isServedNrCellInfoFddValid(fdd *entities.ServedNRCellInformation_ChoiceNRMode_FddInfo) error {
195 func isNrNeighbourInformationValid(nrNeighbourInformation *entities.NrNeighbourInformation) error {
196 if nrNeighbourInformation.NrCgi == "" {
197 return errors.New("nrCgi")
200 if nrNeighbourInformation.ChoiceNrMode == nil {
201 return errors.New("choiceNrMode")
204 if nrNeighbourInformation.NrMode == entities.Nr_UNKNOWN {
205 return errors.New("nrMode")
208 if nrNeighbourInformation.NrPci == 0 {
209 return errors.New("nrPci")
212 return isNrNeighbourInfoChoiceNrModeValid(nrNeighbourInformation.ChoiceNrMode)
215 func isNrNeighbourInfoChoiceNrModeValid(choiceNrMode *entities.NrNeighbourInformation_ChoiceNRMode) error {
216 if choiceNrMode.Fdd != nil {
217 return isNrNeighbourInfoFddValid(choiceNrMode.Fdd)
220 if choiceNrMode.Tdd != nil {
221 return isNrNeighbourInfoTddValid(choiceNrMode.Tdd)
224 return errors.New("nr neighbour fdd / tdd")
227 func isNrNeighbourInfoTddValid(tdd *entities.NrNeighbourInformation_ChoiceNRMode_TddInfo) error {
231 func isNrNeighbourInfoFddValid(fdd *entities.NrNeighbourInformation_ChoiceNRMode_FddInfo) error {