f07e8fdebabd5e53084cfe3e9bd747ab61b59e03
[ric-plt/e2mgr.git] / E2Manager / managers / ran_disconnection_manager.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 //
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
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16
17 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 //  platform project (RICP).
19
20 package managers
21
22 import (
23         "e2mgr/configuration"
24         "e2mgr/logger"
25         "e2mgr/services"
26         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
27 )
28
29 type IRanDisconnectionManager interface {
30         DisconnectRan(inventoryName string) error
31 }
32
33 type RanDisconnectionManager struct {
34         logger                        *logger.Logger
35         config                        *configuration.Configuration
36         rnibDataService               services.RNibDataService
37         e2tAssociationManager         *E2TAssociationManager
38         ranConnectStatusChangeManager IRanConnectStatusChangeManager
39 }
40
41 func NewRanDisconnectionManager(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, e2tAssociationManager *E2TAssociationManager, ranConnectStatusChangeManager IRanConnectStatusChangeManager) *RanDisconnectionManager {
42         return &RanDisconnectionManager{
43                 logger:                        logger,
44                 config:                        config,
45                 rnibDataService:               rnibDataService,
46                 e2tAssociationManager:         e2tAssociationManager,
47                 ranConnectStatusChangeManager: ranConnectStatusChangeManager,
48         }
49 }
50
51 func (m *RanDisconnectionManager) DisconnectRan(inventoryName string) error {
52         nodebInfo, err := m.rnibDataService.GetNodeb(inventoryName)
53
54         if err != nil {
55                 m.logger.Errorf("#RanDisconnectionManager.DisconnectRan - RAN name: %s - Failed fetching RAN from rNib. Error: %v", inventoryName, err)
56                 return err
57         }
58
59         connectionStatus := nodebInfo.GetConnectionStatus()
60         m.logger.Infof("#RanDisconnectionManager.DisconnectRan - RAN name: %s - RAN's connection status: %s", nodebInfo.RanName, connectionStatus)
61
62         if connectionStatus == entities.ConnectionStatus_SHUT_DOWN {
63                 m.logger.Warnf("#RanDisconnectionManager.DisconnectRan - RAN name: %s - quit. RAN's connection status is SHUT_DOWN", nodebInfo.RanName)
64                 return nil
65         }
66
67         if connectionStatus == entities.ConnectionStatus_SHUTTING_DOWN {
68                 return m.ranConnectStatusChangeManager.ChangeStatus(nodebInfo, entities.ConnectionStatus_SHUT_DOWN)
69         }
70
71         err = m.ranConnectStatusChangeManager.ChangeStatus(nodebInfo, entities.ConnectionStatus_DISCONNECTED)
72
73         if err != nil {
74                 return err
75         }
76
77         e2tAddress := nodebInfo.AssociatedE2TInstanceAddress
78         return m.e2tAssociationManager.DissociateRan(e2tAddress, nodebInfo.RanName)
79 }