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).
23 "e2mgr/e2managererrors"
27 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
30 type UpdateGnbManager struct {
32 rnibDataService services.RNibDataService
33 nodebValidator *NodebValidator
36 func NewUpdateGnbManager(logger *logger.Logger, rnibDataService services.RNibDataService, nodebValidator *NodebValidator) *UpdateGnbManager {
37 return &UpdateGnbManager{
39 rnibDataService: rnibDataService,
40 nodebValidator: nodebValidator,
44 func (h *UpdateGnbManager) Validate(request models.Request) error {
46 updateGnbRequest := request.(*models.UpdateGnbRequest)
48 if err := h.nodebValidator.IsGnbValid(updateGnbRequest.Gnb); err != nil {
49 h.logger.Errorf("#UpdateGnbManager.Validate - RAN name: %s - validation failure: %s is a mandatory field and cannot be empty", updateGnbRequest.RanName, err)
56 func (h *UpdateGnbManager) RemoveNodebCells(nodeb *entities.NodebInfo) error {
58 if nodeb.NodeType != entities.Node_GNB {
59 h.logger.Errorf("#UpdateGnbManager.RemoveNodebCells - RAN name: %s - node type isn't gNB", nodeb.GetRanName())
60 return e2managererrors.NewRequestValidationError()
63 servedNrCells := nodeb.GetGnb().GetServedNrCells()
65 if len(servedNrCells) == 0 {
66 h.logger.Infof("#UpdateGnbManager.RemoveNodebCells - RAN name: %s - gNB cells are nil or empty - no cells to remove", nodeb.GetRanName())
70 err := h.rnibDataService.RemoveServedNrCells(nodeb.GetRanName(), servedNrCells)
72 h.logger.Errorf("#UpdateGnbManager.RemoveNodebCells - RAN name: %s - Failed removing gNB cells", nodeb.GetRanName())
73 return e2managererrors.NewRnibDbError()
76 h.logger.Infof("#UpdateGnbManager.RemoveNodebCells - RAN name: %s - Successfully removed gNB cells", nodeb.GetRanName())
80 func (h *UpdateGnbManager) SetNodeb(nodeb *entities.NodebInfo, request models.Request) {
82 updateGnbRequest := request.(*models.UpdateGnbRequest)
83 nodeb.GetGnb().ServedNrCells = updateGnbRequest.ServedNrCells
86 func (h *UpdateGnbManager) UpdateNodeb(nodeb *entities.NodebInfo) error {
88 err := h.rnibDataService.UpdateGnbCells(nodeb, nodeb.GetGnb().GetServedNrCells())
90 h.logger.Errorf("#UpdateGnbManager.UpdateNodeb - RAN name: %s - Failed updating gNB cells. Error: %s", nodeb.GetRanName(), err)
91 return e2managererrors.NewRnibDbError()
93 h.logger.Infof("#UpdateGnbManager.UpdateNodeb - RAN name: %s - Successfully updated gNB cells", nodeb.GetRanName())