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) ValidateNodeb(nodeb *entities.NodebInfo) error{
60 func (h *UpdateGnbManager) RemoveNodebCells(nodeb *entities.NodebInfo) error {
62 if nodeb.NodeType != entities.Node_GNB {
63 h.logger.Errorf("#UpdateGnbManager.RemoveNodebCells - RAN name: %s - node type isn't gNB", nodeb.GetRanName())
64 return e2managererrors.NewRequestValidationError()
67 servedNrCells := nodeb.GetGnb().GetServedNrCells()
69 if len(servedNrCells) == 0 {
70 h.logger.Infof("#UpdateGnbManager.RemoveNodebCells - RAN name: %s - gNB cells are nil or empty - no cells to remove", nodeb.GetRanName())
74 err := h.rnibDataService.RemoveServedNrCells(nodeb.GetRanName(), servedNrCells)
76 h.logger.Errorf("#UpdateGnbManager.RemoveNodebCells - RAN name: %s - Failed removing gNB cells", nodeb.GetRanName())
77 return e2managererrors.NewRnibDbError()
80 h.logger.Infof("#UpdateGnbManager.RemoveNodebCells - RAN name: %s - Successfully removed gNB cells", nodeb.GetRanName())
84 func (h *UpdateGnbManager) SetNodeb(nodeb *entities.NodebInfo, request models.Request) {
86 updateGnbRequest := request.(*models.UpdateGnbRequest)
87 nodeb.GetGnb().ServedNrCells = updateGnbRequest.ServedNrCells
90 func (h *UpdateGnbManager) UpdateNodeb(nodeb *entities.NodebInfo) error {
92 err := h.rnibDataService.UpdateGnbCells(nodeb, nodeb.GetGnb().GetServedNrCells())
94 h.logger.Errorf("#UpdateGnbManager.UpdateNodeb - RAN name: %s - Failed updating gNB cells. Error: %s", nodeb.GetRanName(), err)
95 return e2managererrors.NewRnibDbError()
97 h.logger.Infof("#UpdateGnbManager.UpdateNodeb - RAN name: %s - Successfully updated gNB cells", nodeb.GetRanName())