Skip to content

Commit

Permalink
update copyNotificationNfProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
danielh1204 committed Aug 13, 2023
1 parent 3e1ce4d commit c682695
Showing 1 changed file with 74 additions and 21 deletions.
95 changes: 74 additions & 21 deletions internal/sbi/producer/nf_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit c682695

Please sign in to comment.