2 // Copyright 2023 Nokia
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
16 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
17 // platform project (RICP).
30 type IRicServiceUpdateManager interface {
31 RevertRanFunctions(ranName string) error
32 StoreExistingRanFunctions(ranName string) error
36 type RicServiceUpdateManager struct {
38 rNibDataService services.RNibDataService
41 func NewRicServiceUpdateManager(logger *logger.Logger, rNibDataService services.RNibDataService) *RicServiceUpdateManager {
42 return &RicServiceUpdateManager{
44 rNibDataService: rNibDataService,
49 func (h *RicServiceUpdateManager) StoreExistingRanFunctions(ranName string) error {
50 nodebInfo, err := h.rNibDataService.GetNodeb(ranName)
52 h.logger.Errorf("#RicServiceUpdateManager.revertRanFunctions - failed to get nodeB entity for ran name: %v due to RNIB Error: %s", ranName, err)
54 if nodebInfo.GetGnb() == nil {
55 h.logger.Errorf("#RicServiceUpdateManager.revertRanFunctions - GNB is nil for RAN name: %s", ranName)
56 return errors.New("There is empty gnb nodebInfo")
58 models.ExistingRanFunctiuonsMap[ranName] = nodebInfo.GetGnb().RanFunctions
59 h.logger.Errorf("#RicServiceUpdateManager.revertRanFunctions - Updated ranFunctions for reverting the changes are %v:", models.ExistingRanFunctiuonsMap[ranName])
63 func (h *RicServiceUpdateManager) RevertRanFunctions(ranName string) error {
64 nodebInfo, err := h.rNibDataService.GetNodeb(ranName)
66 h.logger.Errorf("#RicServiceUpdateManager.revertRanFunctions - failed to get nodeB entity for ran name: %v due to RNIB Error: %s", ranName, err)
69 if nodebInfo.GetGnb() != nil && nodebInfo.GetGnb().RanFunctions != nil {
70 nodebInfo.GetGnb().RanFunctions = models.ExistingRanFunctiuonsMap[ranName]
72 h.logger.Errorf("#RicServiceUpdateManager.revertRanFunctions returned nil")
74 err = h.rNibDataService.UpdateNodebInfoAndPublish(nodebInfo)
76 h.logger.Errorf("#RicServiceUpdateManager.revertRanFunctions - RAN name: %s - Failed at UpdateNodebInfoAndPublish. error: %s", nodebInfo.RanName, err)
80 h.logger.Infof("#RicServiceUpdateManager.revertRanFunctions - Revert ranFunctions for RAN name: %s", ranName)