diff --git a/internal/sbi/producer/nf_management.go b/internal/sbi/producer/nf_management.go index 614d1f8..9101c97 100644 --- a/internal/sbi/producer/nf_management.go +++ b/internal/sbi/producer/nf_management.go @@ -230,12 +230,14 @@ func RemoveSubscriptionProcedure(subscriptionID string) { } func GetNFInstancesProcedure(nfType string, limit int) (*nrf_context.UriList, *models.ProblemDetails) { - // nfType := c.Query("nf-type") - // limit, err := strconv.Atoi(c.Query("limit")) collName := "urilist" filter := bson.M{"nfType": nfType} + if nfType == "" { + // if the query parameter is not present, do not filter by nfType + filter = bson.M{} + } - UL, err := mongoapi.RestfulAPIGetOne(collName, filter) + ULs, err := mongoapi.RestfulAPIGetMany(collName, filter) if err != nil { logger.NfmLog.Errorf("GetNFInstancesProcedure err: %+v", err) problemDetail := &models.ProblemDetails{ @@ -246,21 +248,28 @@ func GetNFInstancesProcedure(nfType string, limit int) (*nrf_context.UriList, *m } return nil, problemDetail } - logger.NfmLog.Infoln("UL: ", UL) - originalUL := &nrf_context.UriList{} - if err := mapstructure.Decode(UL, originalUL); err != nil { - logger.NfmLog.Errorf("Decode error in GetNFInstancesProcedure: %+v", err) - problemDetail := &models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", + logger.NfmLog.Infoln("ULs: ", ULs) + rspUriList := &nrf_context.UriList{} + for _, UL := range ULs { + originalUL := &nrf_context.UriList{} + if err := mapstructure.Decode(UL, originalUL); err != nil { + logger.NfmLog.Errorf("Decode error in GetNFInstancesProcedure: %+v", err) + problemDetail := &models.ProblemDetails{ + Title: "System failure", + Status: http.StatusInternalServerError, + Detail: err.Error(), + Cause: "SYSTEM_FAILURE", + } + return nil, problemDetail + } + rspUriList.Link.Item = append(rspUriList.Link.Item, originalUL.Link.Item...) + if nfType != "" && rspUriList.NfType == "" { + rspUriList.NfType = originalUL.NfType } - return nil, problemDetail } - nrf_context.NnrfUriListLimit(originalUL, limit) - // c.JSON(http.StatusOK, originalUL) - return originalUL, nil + + nrf_context.NnrfUriListLimit(rspUriList, limit) + return rspUriList, nil } func NFDeregisterProcedure(nfInstanceID string) *models.ProblemDetails { @@ -320,7 +329,7 @@ func NFDeregisterProcedure(nfInstanceID string) *models.ProblemDetails { Notification_event := models.NotificationEventType_DEREGISTERED for _, uri := range uriList { - problemDetails := SendNFStatusNotify(Notification_event, nfInstanceUri, uri) + problemDetails := SendNFStatusNotify(Notification_event, nfInstanceUri, uri, nil) if problemDetails != nil { return problemDetails } @@ -379,7 +388,7 @@ func UpdateNFInstanceProcedure(nfInstanceID string, patchJSON []byte) map[string nfInstanceUri := nrf_context.GetNfInstanceURI(nfInstanceID) for _, uri := range uriList { - SendNFStatusNotify(Notification_event, nfInstanceUri, uri) + SendNFStatusNotify(Notification_event, nfInstanceUri, uri, &nfProfiles[0]) } return nf @@ -470,7 +479,7 @@ func NFRegisterProcedure( // receive the rsp from handler for _, uri := range uriList { - problemDetails := SendNFStatusNotify(Notification_event, nfInstanceUri, uri) + problemDetails := SendNFStatusNotify(Notification_event, nfInstanceUri, uri, &nfProfile) if problemDetails != nil { return nil, nil, true, problemDetails } @@ -487,7 +496,7 @@ func NFRegisterProcedure( nfInstanceUri := locationHeaderValue for _, uri := range uriList { - problemDetails := SendNFStatusNotify(Notification_event, nfInstanceUri, uri) + problemDetails := SendNFStatusNotify(Notification_event, nfInstanceUri, uri, nil) if problemDetails != nil { return nil, nil, false, problemDetails } @@ -508,8 +517,48 @@ func NFRegisterProcedure( } } +func copyNotificationNfProfile(notifProfile *models.NfProfileNotificationData, nfProfile *models.NfProfile) { + notifProfile.NfInstanceId = nfProfile.NfInstanceId + notifProfile.NfType = nfProfile.NfType + notifProfile.NfStatus = nfProfile.NfStatus + notifProfile.HeartBeatTimer = nfProfile.HeartBeatTimer + notifProfile.PlmnList = *nfProfile.PlmnList + notifProfile.SNssais = *nfProfile.SNssais + notifProfile.PerPlmnSnssaiList = nfProfile.PerPlmnSnssaiList + notifProfile.NsiList = nfProfile.NsiList + notifProfile.Fqdn = nfProfile.Fqdn + notifProfile.InterPlmnFqdn = nfProfile.InterPlmnFqdn + notifProfile.Ipv4Addresses = nfProfile.Ipv4Addresses + notifProfile.Ipv6Addresses = nfProfile.Ipv6Addresses + notifProfile.AllowedPlmns = *nfProfile.AllowedPlmns + notifProfile.AllowedNfTypes = nfProfile.AllowedNfTypes + notifProfile.AllowedNfDomains = nfProfile.AllowedNfDomains + notifProfile.AllowedNssais = *nfProfile.AllowedNssais + notifProfile.Priority = nfProfile.Priority + notifProfile.Capacity = nfProfile.Capacity + notifProfile.Load = nfProfile.Load + notifProfile.Locality = nfProfile.Locality + notifProfile.UdrInfo = nfProfile.UdrInfo + notifProfile.UdmInfo = nfProfile.UdmInfo + notifProfile.AusfInfo = nfProfile.AusfInfo + notifProfile.AmfInfo = nfProfile.AmfInfo + notifProfile.SmfInfo = nfProfile.SmfInfo + notifProfile.UpfInfo = nfProfile.UpfInfo + notifProfile.PcfInfo = nfProfile.PcfInfo + notifProfile.BsfInfo = nfProfile.BsfInfo + notifProfile.ChfInfo = nfProfile.ChfInfo + notifProfile.NrfInfo = nfProfile.NrfInfo + notifProfile.CustomInfo = nfProfile.CustomInfo + notifProfile.RecoveryTime = nfProfile.RecoveryTime + notifProfile.NfServicePersistence = nfProfile.NfServicePersistence + notifProfile.NfServices = *nfProfile.NfServices + notifProfile.NfProfileChangesSupportInd = nfProfile.NfProfileChangesSupportInd + notifProfile.NfProfileChangesInd = nfProfile.NfProfileChangesInd + notifProfile.DefaultNotificationSubscriptions = nfProfile.DefaultNotificationSubscriptions +} + func SendNFStatusNotify(Notification_event models.NotificationEventType, nfInstanceUri string, - url string, + url string, nfProfile *models.NfProfile, ) *models.ProblemDetails { // Set client and set url configuration := Nnrf_NFManagement.NewConfiguration() @@ -520,6 +569,10 @@ func SendNFStatusNotify(Notification_event models.NotificationEventType, nfInsta Event: Notification_event, NfInstanceUri: nfInstanceUri, } + if nfProfile != nil { + copyNotificationNfProfile(notifcationData.NfProfile, nfProfile) + } + client := Nnrf_NFManagement.NewAPIClient(configuration) res, err := client.NotificationApi.NotificationPost(context.TODO(), notifcationData)