X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fmanagers%2Fe2t_shutdown_manager.go;h=3c88dbd39c072d8b0b7e93dc96d6763e60d3ae69;hb=fb1e406498460f92ce4664ea060e43878a6c868e;hp=20e4554c70464f4fe3e9b99f55fe78b0659dbae8;hpb=f846c5987cd35da745534e26ac3a22bdcf8b030a;p=ric-plt%2Fe2mgr.git diff --git a/E2Manager/managers/e2t_shutdown_manager.go b/E2Manager/managers/e2t_shutdown_manager.go index 20e4554..3c88dbd 100644 --- a/E2Manager/managers/e2t_shutdown_manager.go +++ b/E2Manager/managers/e2t_shutdown_manager.go @@ -34,22 +34,22 @@ type IE2TShutdownManager interface { } type E2TShutdownManager struct { - logger *logger.Logger - config *configuration.Configuration - rnibDataService services.RNibDataService - e2TInstancesManager IE2TInstancesManager - e2tAssociationManager *E2TAssociationManager - ranSetupManager IRanSetupManager + logger *logger.Logger + config *configuration.Configuration + rnibDataService services.RNibDataService + e2TInstancesManager IE2TInstancesManager + e2tAssociationManager *E2TAssociationManager + ranConnectStatusChangeManager IRanConnectStatusChangeManager } -func NewE2TShutdownManager(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, e2TInstancesManager IE2TInstancesManager, e2tAssociationManager *E2TAssociationManager, ranSetupManager IRanSetupManager) E2TShutdownManager { - return E2TShutdownManager{ - logger: logger, - config: config, - rnibDataService: rnibDataService, - e2TInstancesManager: e2TInstancesManager, - e2tAssociationManager: e2tAssociationManager, - ranSetupManager: ranSetupManager, +func NewE2TShutdownManager(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, e2TInstancesManager IE2TInstancesManager, e2tAssociationManager *E2TAssociationManager, ranConnectStatusChangeManager IRanConnectStatusChangeManager) *E2TShutdownManager { + return &E2TShutdownManager{ + logger: logger, + config: config, + rnibDataService: rnibDataService, + e2TInstancesManager: e2TInstancesManager, + e2tAssociationManager: e2tAssociationManager, + ranConnectStatusChangeManager: ranConnectStatusChangeManager, } } @@ -68,56 +68,24 @@ func (m E2TShutdownManager) Shutdown(e2tInstance *entities.E2TInstance) error { return err } - ranNamesToBeDissociated := []string{} - ranNamesToBeAssociated := make(map[string][]string) // e2tAddress -> associatedRanList - - for _, ranName := range e2tInstance.AssociatedRanList { - err = m.reAssociateRanInMemory(ranName, ranNamesToBeAssociated, ranNamesToBeDissociated) - if err != nil { - m.logger.Errorf("#E2TShutdownManager.Shutdown - Failed to re-associate nodeb %s.", ranName) - return err - } - } - - err = m.e2tAssociationManager.RemoveE2tInstance(e2tInstance.Address, ranNamesToBeDissociated, ranNamesToBeAssociated) - if err != nil { - m.logger.Errorf("#E2TShutdownManager.Shutdown - Failed to remove E2T %s.", e2tInstance.Address) - return err - } - - err = m.clearNodebsAssociation(ranNamesToBeDissociated) + err = m.clearNodebsAssociation(e2tInstance.AssociatedRanList) if err != nil { m.logger.Errorf("#E2TShutdownManager.Shutdown - Failed to clear nodebs association to E2T %s.", e2tInstance.Address) return err } - err = m.reassociateNodebs(ranNamesToBeAssociated) + err = m.e2tAssociationManager.RemoveE2tInstance(e2tInstance) if err != nil { - m.logger.Errorf("#E2TShutdownManager.Shutdown - Failed to re-associate nodebs after killing E2T %s.", e2tInstance.Address) + m.logger.Errorf("#E2TShutdownManager.Shutdown - Failed to remove E2T %s.", e2tInstance.Address) return err } - return nil -} - -func (m E2TShutdownManager) reassociateNodebs(ranNamesToBeAssociated map[string][]string) error { - for e2tAddress, ranNames := range ranNamesToBeAssociated { - - err := m.associateAndSetupNodebs(ranNames, e2tAddress) - if err != nil { - return err - } - - } + m.logger.Infof("#E2TShutdownManager.Shutdown - E2T %s was shutdown successfully.", e2tInstance.Address) return nil } func (m E2TShutdownManager) clearNodebsAssociation(ranNamesToBeDissociated []string) error { - return m.associateAndSetupNodebs(ranNamesToBeDissociated, "") -} - -func (m E2TShutdownManager) associateAndSetupNodebs(ranNamesToBeUpdated []string, e2tAddress string) error { - for _, ranName := range ranNamesToBeUpdated { + for _, ranName := range ranNamesToBeDissociated { nodeb, err := m.rnibDataService.GetNodeb(ranName) if err != nil { m.logger.Warnf("#E2TShutdownManager.associateAndSetupNodebs - Failed to get nodeb %s from db.", ranName) @@ -127,55 +95,19 @@ func (m E2TShutdownManager) associateAndSetupNodebs(ranNamesToBeUpdated []string } return err } - nodeb.AssociatedE2TInstanceAddress = e2tAddress - err = m.rnibDataService.UpdateNodebInfo(nodeb) + + _, err = m.ranConnectStatusChangeManager.ChangeStatus(nodeb, entities.ConnectionStatus_DISCONNECTED) if err != nil { - m.logger.Errorf("#E2TShutdownManager.associateAndSetupNodebs - Failed to save nodeb %s from db.", ranName) return err } - shouldSendSetup := len(e2tAddress) > 0 - if shouldSendSetup { - err = m.ranSetupManager.ExecuteSetup(nodeb, entities.ConnectionStatus_CONNECTING) - if err != nil { - m.logger.Errorf("#E2TShutdownManager.associateAndSetupNodebs - Failed to execute Setup for nodeb %s.", ranName) - continue - } - } - } - return nil -} - -func (m E2TShutdownManager) reAssociateRanInMemory(ranName string, ranNamesToBeAssociated map[string][]string, ranNamesToBeDissociated []string) error { - nodeb, err := m.rnibDataService.GetNodeb(ranName) - if err != nil { - - _, ok := err.(*common.ResourceNotFoundError) - - if !ok { - m.logger.Errorf("#E2TShutdownManager.reAssociateRanInMemory - Failed to get nodeb %s from db.", ranName) + nodeb.AssociatedE2TInstanceAddress = "" + err = m.rnibDataService.UpdateNodebInfo(nodeb) + if err != nil { + m.logger.Errorf("#E2TShutdownManager.clearNodebsAssociation - Failed to save nodeb %s to db.", ranName) return err } - - m.logger.Errorf("#E2TShutdownManager.reAssociateRanInMemory - nodeb %s not found in db. dissociating it...", ranName) - ranNamesToBeDissociated = append(ranNamesToBeDissociated, ranName) - return nil - } - - if nodeb.ConnectionStatus == entities.ConnectionStatus_SHUTTING_DOWN || nodeb.ConnectionStatus == entities.ConnectionStatus_SHUT_DOWN { - m.logger.Errorf("#E2TShutdownManager.reAssociateRanInMemory - nodeb %s status is %s. dissociating it...", ranName, nodeb.ConnectionStatus) - ranNamesToBeDissociated = append(ranNamesToBeDissociated, ranName) - return nil } - - selectedE2tAddress, err := m.e2TInstancesManager.SelectE2TInstance() - if err != nil { - m.logger.Infof("#E2TShutdownManager.reAssociateRanInMemory - No selected E2T instance for nodeb %s found.", ranName) - ranNamesToBeDissociated = append(ranNamesToBeDissociated, ranName) - return nil - } - - ranNamesToBeAssociated[selectedE2tAddress] = append(ranNamesToBeAssociated[selectedE2tAddress], ranName) return nil } @@ -190,5 +122,5 @@ func (m E2TShutdownManager) isE2tInstanceAlreadyBeingDeleted(e2tInstance *entiti delta := time.Now().UnixNano() - e2tInstance.DeletionTimestamp timestampNanosec := int64(time.Duration(m.config.E2TInstanceDeletionTimeoutMs) * time.Millisecond) - return delta <= timestampNanosec + return e2tInstance.State == entities.ToBeDeleted && delta <= timestampNanosec }