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 //gnb := nodebInfo.GetGnb()
74 // // TODO: log and return appropriate error
75 // return nil, e2managererrors.NewRnibDbError()
78 //gnb.ServedNrCells = updateGnbRequest.ServedNrCells
80 //err = h.rNibDataService.UpdateGnbCells(nodebInfo, updateGnbRequest.ServedNrCells)
83 // // TODO: handle error
87 return models.NewUpdateGnbResponse(nodebInfo), nil
90 func (h *UpdateGnbRequestHandler) validateRequestBody(updateGnbRequest models.UpdateGnbRequest) (error) {
92 if len(updateGnbRequest.ServedNrCells) == 0 {
93 h.logger.Errorf(VALIDATION_FAILURE_MESSAGE+" and cannot be empty", "servedCells")
94 return e2managererrors.NewRequestValidationError()
97 for _, servedNrCell := range updateGnbRequest.ServedNrCells {
98 if servedNrCell.ServedNrCellInformation == nil {
99 h.logger.Errorf(VALIDATION_FAILURE_MESSAGE+" and cannot be empty", "servedNrCellInformation")
100 return e2managererrors.NewRequestValidationError()
103 err := isServedNrCellInformationValid(servedNrCell.ServedNrCellInformation)
106 h.logger.Errorf(VALIDATION_FAILURE_MESSAGE, err)
107 return e2managererrors.NewRequestValidationError()
110 if len(servedNrCell.NrNeighbourInfos) == 0 {
114 for _, nrNeighbourInformation := range servedNrCell.NrNeighbourInfos {
116 err := isNrNeighbourInformationValid(nrNeighbourInformation)
119 h.logger.Errorf(VALIDATION_FAILURE_MESSAGE, err)
120 return e2managererrors.NewRequestValidationError()
129 func isServedNrCellInformationValid(servedNrCellInformation *entities.ServedNRCellInformation) error {
130 if servedNrCellInformation.CellId == "" {
131 return errors.New("cellId");
134 if servedNrCellInformation.ChoiceNrMode == nil {
135 return errors.New("choiceNrMode");
138 if servedNrCellInformation.NrMode == entities.Nr_UNKNOWN {
139 return errors.New("nrMode");
142 if servedNrCellInformation.NrPci == 0 {
143 return errors.New("nrPci");
146 if len(servedNrCellInformation.ServedPlmns) == 0 {
147 return errors.New("servedPlmns");
150 return isServedNrCellInfoChoiceNrModeValid(servedNrCellInformation.ChoiceNrMode)
153 func isServedNrCellInfoChoiceNrModeValid(choiceNrMode *entities.ServedNRCellInformation_ChoiceNRMode) error {
154 if choiceNrMode.Fdd != nil {
155 return isServedNrCellInfoFddValid(choiceNrMode.Fdd)
158 if choiceNrMode.Tdd != nil {
159 return isServedNrCellInfoTddValid(choiceNrMode.Tdd)
162 return errors.New("served nr cell fdd / tdd")
165 func isServedNrCellInfoTddValid(tdd *entities.ServedNRCellInformation_ChoiceNRMode_TddInfo) error {
169 func isServedNrCellInfoFddValid(fdd *entities.ServedNRCellInformation_ChoiceNRMode_FddInfo) error {
173 func isNrNeighbourInformationValid(nrNeighbourInformation *entities.NrNeighbourInformation) error {
174 if nrNeighbourInformation.NrCgi == "" {
175 return errors.New("nrCgi")
178 if nrNeighbourInformation.ChoiceNrMode == nil {
179 return errors.New("choiceNrMode")
182 if nrNeighbourInformation.NrMode == entities.Nr_UNKNOWN {
183 return errors.New("nrMode")
186 if nrNeighbourInformation.NrPci == 0 {
187 return errors.New("nrPci")
190 return isNrNeighbourInfoChoiceNrModeValid(nrNeighbourInformation.ChoiceNrMode)
193 func isNrNeighbourInfoChoiceNrModeValid(choiceNrMode *entities.NrNeighbourInformation_ChoiceNRMode) error {
194 if choiceNrMode.Fdd != nil {
195 return isNrNeighbourInfoFddValid(choiceNrMode.Fdd)
198 if choiceNrMode.Tdd != nil {
199 return isNrNeighbourInfoTddValid(choiceNrMode.Tdd)
202 return errors.New("nr neighbour fdd / tdd")
205 func isNrNeighbourInfoTddValid(tdd *entities.NrNeighbourInformation_ChoiceNRMode_TddInfo) error {
209 func isNrNeighbourInfoFddValid(fdd *entities.NrNeighbourInformation_ChoiceNRMode_FddInfo) error {