X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fmanagers%2Fran_reconnection_manager.go;h=87a656ec3041b2cff9907be763c08498cb91c4e7;hb=88b31d518e6f4c0513962d6fa373f76c5e8c1306;hp=f4a3c3568a9929b8a2424fd38da925dcab56e5c5;hpb=19e72a51b5edbf108d230093fdf85b42fe5ab470;p=ric-plt%2Fe2mgr.git diff --git a/E2Manager/managers/ran_reconnection_manager.go b/E2Manager/managers/ran_reconnection_manager.go index f4a3c35..87a656e 100644 --- a/E2Manager/managers/ran_reconnection_manager.go +++ b/E2Manager/managers/ran_reconnection_manager.go @@ -1,14 +1,36 @@ +// +// Copyright 2019 AT&T Intellectual Property +// Copyright 2019 Nokia +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + package managers import ( "e2mgr/configuration" "e2mgr/logger" "e2mgr/rNibWriter" + "e2mgr/services" "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader" ) +type IRanReconnectionManager interface { + ReconnectRan(inventoryName string) error +} + type RanReconnectionManager struct { logger *logger.Logger config *configuration.Configuration @@ -17,13 +39,13 @@ type RanReconnectionManager struct { ranSetupManager *RanSetupManager } -func NewRanReconnectionManager(logger *logger.Logger, config *configuration.Configuration, rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter, ranSetupManager *RanSetupManager) *RanReconnectionManager { +func NewRanReconnectionManager(logger *logger.Logger, config *configuration.Configuration, rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter, rmrService *services.RmrService) *RanReconnectionManager { return &RanReconnectionManager{ logger: logger, config: config, rnibReaderProvider: rnibReaderProvider, rnibWriterProvider: rnibWriterProvider, - ranSetupManager: ranSetupManager, + ranSetupManager: NewRanSetupManager(logger,rmrService,rnibWriterProvider), } } @@ -31,23 +53,24 @@ func (m *RanReconnectionManager) ReconnectRan(inventoryName string) error { nodebInfo, rnibErr := m.rnibReaderProvider().GetNodeb(inventoryName) if rnibErr != nil { - m.logger.Errorf("#ReconnectRan - RAN name: %s - Failed fetching RAN from rNib. Error: %v", inventoryName, rnibErr) + m.logger.Errorf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Failed fetching RAN from rNib. Error: %v", inventoryName, rnibErr) return rnibErr } + m.logger.Infof("#RanReconnectionManager.ReconnectRan - RAN name: %s - RAN's connection status: %s, RAN's connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionStatus, nodebInfo.ConnectionAttempts) + if !m.canReconnectRan(nodebInfo) { - m.logger.Warnf("#ReconnectRan - RAN name: %s - Cannot reconnect RAN", inventoryName) return m.setConnectionStatusOfUnconnectableRan(nodebInfo) } + err := m.ranSetupManager.ExecuteSetup(nodebInfo) if err != nil { - m.logger.Errorf("#ReconnectRan - RAN name: %s - Failed executing setup. Error: %v", inventoryName, err) + m.logger.Errorf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Failed executing setup. Error: %v", inventoryName, err) return err } - m.logger.Infof("#ReconnectRan - RAN name: %s - Successfully done executing setup", inventoryName) return nil } @@ -58,28 +81,37 @@ func (m *RanReconnectionManager) canReconnectRan(nodebInfo *entities.NodebInfo) } func (m *RanReconnectionManager) updateNodebInfoStatus(nodebInfo *entities.NodebInfo, connectionStatus entities.ConnectionStatus) common.IRNibError { + if nodebInfo.ConnectionStatus == connectionStatus { + return nil + } + nodebInfo.ConnectionStatus = connectionStatus; err := m.rnibWriterProvider().UpdateNodebInfo(nodebInfo) if err != nil { - m.logger.Errorf("#updateNodebInfoStatus - RAN name: %s - Failed updating RAN's connection status to %s in rNib. Error: %v", nodebInfo.RanName, connectionStatus, err) + m.logger.Errorf("#RanReconnectionManager.updateNodebInfoStatus - RAN name: %s - Failed updating RAN's connection status to %s in rNib. Error: %v", nodebInfo.RanName, connectionStatus, err) return err } - m.logger.Infof("#updateNodebInfoStatus - RAN name: %s - Successfully updated RAN's connection status to %s in rNib", nodebInfo.RanName, connectionStatus) + m.logger.Infof("#RanReconnectionManager.updateNodebInfoStatus - RAN name: %s - Successfully updated rNib. RAN's current connection status: %s", nodebInfo.RanName, nodebInfo.ConnectionStatus) return nil } func (m *RanReconnectionManager) setConnectionStatusOfUnconnectableRan(nodebInfo *entities.NodebInfo) common.IRNibError { connectionStatus := nodebInfo.GetConnectionStatus() - m.logger.Warnf("#setConnectionStatusOfUnconnectableRan - RAN name: %s, RAN's connection status: %s, RAN's connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionStatus, nodebInfo.ConnectionAttempts) + + if connectionStatus == entities.ConnectionStatus_SHUT_DOWN { + m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: connection status is SHUT_DOWN", nodebInfo.RanName) + return nil + } if connectionStatus == entities.ConnectionStatus_SHUTTING_DOWN { + m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: connection status is SHUTTING_DOWN", nodebInfo.RanName) return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_SHUT_DOWN) } if int(nodebInfo.GetConnectionAttempts()) >= m.config.MaxConnectionAttempts { - m.logger.Warnf("#setConnectionStatusOfUnconnectableRan - RAN name: %s - RAN's connection attempts are greater than %d", nodebInfo.RanName, m.config.MaxConnectionAttempts) + m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: RAN's connection attempts exceeded the limit (%d)", nodebInfo.RanName, m.config.MaxConnectionAttempts) return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_DISCONNECTED) }