X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fhandlers%2Frmrmsghandlers%2Fe2_term_init_notification_handler.go;h=904e34b7d824d4c935ccd5e9bede6e3238eace13;hb=78f7c411678d2756ad076a71e6c093cd38cfca99;hp=783f714740e51d7d9da26b5d2820746bba716b06;hpb=e3623cf1310f8c8d2fd9b5842102516b9be3b441;p=ric-plt%2Fe2mgr.git diff --git a/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler.go index 783f714..904e34b 100644 --- a/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler.go @@ -22,40 +22,68 @@ import ( "e2mgr/managers" "e2mgr/models" "e2mgr/services" + "encoding/json" "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" ) type E2TermInitNotificationHandler struct { + logger *logger.Logger rnibDataService services.RNibDataService ranReconnectionManager *managers.RanReconnectionManager + e2tInstancesManager managers.IE2TInstancesManager } -func NewE2TermInitNotificationHandler(ranReconnectionManager *managers.RanReconnectionManager, rnibDataService services.RNibDataService) E2TermInitNotificationHandler { +func NewE2TermInitNotificationHandler(logger *logger.Logger, ranReconnectionManager *managers.RanReconnectionManager, rnibDataService services.RNibDataService, e2tInstancesManager managers.IE2TInstancesManager) E2TermInitNotificationHandler { return E2TermInitNotificationHandler{ + logger: logger, rnibDataService: rnibDataService, ranReconnectionManager: ranReconnectionManager, + e2tInstancesManager: e2tInstancesManager, } } -func (handler E2TermInitNotificationHandler) Handle(logger *logger.Logger, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { +func (h E2TermInitNotificationHandler) Handle(request *models.NotificationRequest) { - logger.Infof("#E2TermInitNotificationHandler.Handle - Handling E2_TERM_INIT") + h.logger.Infof("#E2TermInitNotificationHandler.Handle - Handling E2_TERM_INIT") + + unmarshalledPayload := models.E2TermInitPayload{} + err := json.Unmarshal(request.Payload, &unmarshalledPayload) - nbIdentityList, err := handler.rnibDataService.GetListNodebIds() if err != nil { - logger.Errorf("#E2TermInitNotificationHandler.Handle - Failed to get nodes list from RNIB. Error: %s", err.Error()) + h.logger.Errorf("#E2TermInitNotificationHandler - Error unmarshaling E2 Term Init payload: %s", err) + return + } + + e2tAddress := unmarshalledPayload.Address + + if len(e2tAddress) == 0 { + h.logger.Errorf("#E2TermInitNotificationHandler - Empty E2T address received") + return + } + + e2tInstance, err := h.e2tInstancesManager.GetE2TInstance(e2tAddress) + + if err != nil { + _, ok := err.(*common.ResourceNotFoundError) + + if !ok { + h.logger.Errorf("#E2TermInitNotificationHandler.Handle - Failed retrieving E2TInstance. error: %s", err) + return + } + + _ = h.e2tInstancesManager.AddE2TInstance(e2tAddress) return } - if len(nbIdentityList) == 0 { - logger.Warnf("#E2TermInitNotificationHandler.Handle - The Nodes list in RNIB is empty") + if len(e2tInstance.AssociatedRanList) == 0 { + h.logger.Infof("#E2TermInitNotificationHandler.Handle - E2T Address: %s - E2T instance has no associated RANs", e2tInstance.Address) return } - for _, nbIdentity := range nbIdentityList { + for _, ranName := range e2tInstance.AssociatedRanList { - if err := handler.ranReconnectionManager.ReconnectRan(nbIdentity.InventoryName); err != nil { - logger.Errorf("#E2TermInitNotificationHandler.Handle - Ran name: %s - connection attempt failure, error: %s", (*nbIdentity).GetInventoryName(), err.Error()) + if err := h.ranReconnectionManager.ReconnectRan(ranName); err != nil { + h.logger.Errorf("#E2TermInitNotificationHandler.Handle - Ran name: %s - connection attempt failure, error: %s", ranName, err) _, ok := err.(*common.ResourceNotFoundError) if !ok { break @@ -63,5 +91,5 @@ func (handler E2TermInitNotificationHandler) Handle(logger *logger.Logger, reque } } - logger.Infof("#E2TermInitNotificationHandler.Handle - Completed handling of E2_TERM_INIT") + h.logger.Infof("#E2TermInitNotificationHandler.Handle - Completed handling of E2_TERM_INIT") }