X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fmanagers%2Fe2t_instances_manager.go;h=1e129430a7fba5feced5d27c5b3273097b4aea2d;hb=63249264955a37429a64ebfec7028c6a487bdf1e;hp=74f6a5188345eef4657762594783d3955853ae84;hpb=efcb4528362460aa2249d319c9752b63bb720fe2;p=ric-plt%2Fe2mgr.git diff --git a/E2Manager/managers/e2t_instances_manager.go b/E2Manager/managers/e2t_instances_manager.go index 74f6a51..1e12943 100644 --- a/E2Manager/managers/e2t_instances_manager.go +++ b/E2Manager/managers/e2t_instances_manager.go @@ -15,6 +15,9 @@ // limitations under the License. // +// This source code is part of the near-RT RIC (RAN Intelligent Controller) +// platform project (RICP). + package managers import ( @@ -35,16 +38,18 @@ type E2TInstancesManager struct { } type IE2TInstancesManager interface { + GetE2TAddresses() ([]string, error) GetE2TInstance(e2tAddress string) (*entities.E2TInstance, error) GetE2TInstances() ([]*entities.E2TInstance, error) GetE2TInstancesNoLogs() ([]*entities.E2TInstance, error) AddE2TInstance(e2tAddress string) error RemoveE2TInstance(e2tInstance *entities.E2TInstance) error SelectE2TInstance() (string, error) - AssociateRan(ranName string, e2tAddress string) error - DissociateRan(ranName string, e2tAddress string) error + AddRanToInstance(ranName string, e2tAddress string) error + RemoveRanFromInstance(ranName string, e2tAddress string) error ActivateE2TInstance(e2tInstance *entities.E2TInstance) error ResetKeepAliveTimestamp(e2tAddress string) error + ClearRansOfAllE2TInstances() error } func NewE2TInstancesManager(rnibDataService services.RNibDataService, logger *logger.Logger) *E2TInstancesManager { @@ -103,7 +108,7 @@ func (m *E2TInstancesManager) GetE2TInstancesNoLogs() ([]*entities.E2TInstance, return e2tInstances, nil } -func (m *E2TInstancesManager) GetE2TInstances() ([]*entities.E2TInstance, error) { +func (m *E2TInstancesManager) GetE2TAddresses() ([]string, error) { e2tAddresses, err := m.rnibDataService.GetE2TAddresses() if err != nil { @@ -111,12 +116,20 @@ func (m *E2TInstancesManager) GetE2TInstances() ([]*entities.E2TInstance, error) _, ok := err.(*common.ResourceNotFoundError) if !ok { - m.logger.Errorf("#E2TInstancesManager.GetE2TInstances - Failed retrieving E2T addresses. error: %s", err) + m.logger.Errorf("#E2TInstancesManager.GetE2TAddresses - Failed retrieving E2T addresses. error: %s", err) return nil, e2managererrors.NewRnibDbError() } - m.logger.Infof("#E2TInstancesManager.GetE2TInstances - Empty E2T addresses list") - return []*entities.E2TInstance{}, nil + } + + return e2tAddresses, nil +} + +func (m *E2TInstancesManager) GetE2TInstances() ([]*entities.E2TInstance, error) { + e2tAddresses, err := m.GetE2TAddresses() + + if err != nil { + return nil, e2managererrors.NewRnibDbError() } if len(e2tAddresses) == 0 { @@ -223,7 +236,7 @@ func (m *E2TInstancesManager) AddE2TInstance(e2tAddress string) error { return nil } -func (m *E2TInstancesManager) DissociateRan(ranName string, e2tAddress string) error { +func (m *E2TInstancesManager) RemoveRanFromInstance(ranName string, e2tAddress string) error { m.mux.Lock() defer m.mux.Unlock() @@ -231,8 +244,8 @@ func (m *E2TInstancesManager) DissociateRan(ranName string, e2tAddress string) e e2tInstance, err := m.rnibDataService.GetE2TInstance(e2tAddress) if err != nil { - m.logger.Errorf("#E2TInstancesManager.DissociateRan - E2T Instance address: %s - Failed retrieving E2TInstance. error: %s", e2tAddress, err) - return err + m.logger.Errorf("#E2TInstancesManager.RemoveRanFromInstance - E2T Instance address: %s - Failed retrieving E2TInstance. error: %s", e2tAddress, err) + return e2managererrors.NewRnibDbError() } i := 0 // output index @@ -249,11 +262,11 @@ func (m *E2TInstancesManager) DissociateRan(ranName string, e2tAddress string) e err = m.rnibDataService.SaveE2TInstance(e2tInstance) if err != nil { - m.logger.Errorf("#E2TInstancesManager.DissociateRan - E2T Instance address: %s - Failed saving E2TInstance. error: %s", e2tAddress, err) - return err + m.logger.Errorf("#E2TInstancesManager.RemoveRanFromInstance - E2T Instance address: %s - Failed saving E2TInstance. error: %s", e2tAddress, err) + return e2managererrors.NewRnibDbError() } - m.logger.Infof("#E2TInstancesManager.DissociateRan - successfully dissociated RAN %s from E2T %s", ranName, e2tInstance.Address) + m.logger.Infof("#E2TInstancesManager.RemoveRanFromInstance - successfully dissociated RAN %s from E2T %s", ranName, e2tInstance.Address) return nil } @@ -284,7 +297,7 @@ func (m *E2TInstancesManager) SelectE2TInstance() (string, error) { return min.Address, nil } -func (m *E2TInstancesManager) AssociateRan(ranName string, e2tAddress string) error { +func (m *E2TInstancesManager) AddRanToInstance(ranName string, e2tAddress string) error { m.mux.Lock() defer m.mux.Unlock() @@ -292,7 +305,7 @@ func (m *E2TInstancesManager) AssociateRan(ranName string, e2tAddress string) er e2tInstance, err := m.rnibDataService.GetE2TInstance(e2tAddress) if err != nil { - m.logger.Errorf("#E2TInstancesManager.AssociateRan - E2T Instance address: %s - Failed retrieving E2TInstance. error: %s", e2tAddress, err) + m.logger.Errorf("#E2TInstancesManager.AddRanToInstance - E2T Instance address: %s - Failed retrieving E2TInstance. error: %s", e2tAddress, err) return e2managererrors.NewRnibDbError() } @@ -301,29 +314,29 @@ func (m *E2TInstancesManager) AssociateRan(ranName string, e2tAddress string) er err = m.rnibDataService.SaveE2TInstance(e2tInstance) if err != nil { - m.logger.Errorf("#E2TInstancesManager.AssociateRan - E2T Instance address: %s - Failed saving E2TInstance. error: %s", e2tAddress, err) + m.logger.Errorf("#E2TInstancesManager.AddRanToInstance - E2T Instance address: %s - Failed saving E2TInstance. error: %s", e2tAddress, err) return e2managererrors.NewRnibDbError() } - m.logger.Infof("#E2TInstancesManager.AssociateRan - successfully associated RAN %s with E2T %s", ranName, e2tInstance.Address) + m.logger.Infof("#E2TInstancesManager.AddRanToInstance - RAN %s was added successfully to E2T %s", ranName, e2tInstance.Address) return nil } -func (h E2TInstancesManager) ActivateE2TInstance(e2tInstance *entities.E2TInstance) error{ +func (m E2TInstancesManager) ActivateE2TInstance(e2tInstance *entities.E2TInstance) error { if e2tInstance == nil { - h.logger.Errorf("#E2TInstancesManager.ActivateE2TInstance - e2tInstance empty") + m.logger.Errorf("#E2TInstancesManager.ActivateE2TInstance - e2tInstance empty") return e2managererrors.NewInternalError() } - h.logger.Infof("#E2TInstancesManager.ActivateE2TInstance - E2T Address: %s - activate E2T instance", e2tInstance.Address) + m.logger.Infof("#E2TInstancesManager.ActivateE2TInstance - E2T Address: %s - activate E2T instance", e2tInstance.Address) e2tInstance.State = entities.Active e2tInstance.KeepAliveTimestamp = time.Now().UnixNano() - err := h.rnibDataService.SaveE2TInstance(e2tInstance) + err := m.rnibDataService.SaveE2TInstance(e2tInstance) if err != nil { - h.logger.Errorf("#E2TInstancesManager.ActivateE2TInstance - E2T Instance address: %s - Failed saving E2TInstance. error: %s", e2tInstance.Address, err) + m.logger.Errorf("#E2TInstancesManager.ActivateE2TInstance - E2T Instance address: %s - Failed saving E2TInstance. error: %s", e2tInstance.Address, err) return err } return nil @@ -357,3 +370,31 @@ func (m *E2TInstancesManager) ResetKeepAliveTimestamp(e2tAddress string) error { return nil } + +func (m *E2TInstancesManager) ClearRansOfAllE2TInstances() error { + m.logger.Infof("#E2TInstancesManager.ClearRansOfAllE2TInstances - Going to clear associated RANs from E2T instances") + m.mux.Lock() + defer m.mux.Unlock() + + e2tInstances, err := m.GetE2TInstances() + + if err != nil { + return err + } + + if len(e2tInstances) == 0 { + m.logger.Errorf("#E2TInstancesManager.ClearRansOfAllE2TInstances - No E2T instances to clear associated RANs from") + return nil + } + + for _, v := range e2tInstances { + v.AssociatedRanList = []string{} + err := m.rnibDataService.SaveE2TInstance(v) + + if err != nil { + m.logger.Errorf("#E2TInstancesManager.ClearRansOfAllE2TInstances - e2t address: %s - failed saving e2t instance. error: %s", v.Address, err) + } + } + + return nil +}