diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 5beefe2..8382703 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -100,29 +100,35 @@ func (s *nnrfService) SendSearchNFInstances( return &result, err } -func (s *nnrfService) SendDeregisterNFInstance() (err error) { - logger.ConsumerLog.Infof("Send Deregister NFInstance") +func (s *nnrfService) SendDeregisterNFInstance() (*models.ProblemDetails, error) { + logger.ConsumerLog.Infof("[AUSF] Send Deregister NFInstance") - ctx, _, err := ausf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) + ctx, pd, err := ausf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) if err != nil { - return err + return pd, err } ausfContext := s.consumer.Context() client := s.getNFManagementClient(ausfContext.NrfUri) + request := &Nnrf_NFManagement.DeregisterNFInstanceRequest{ + NfInstanceID: &ausfContext.NfId, + } - var derigisterNfInstanceRequest Nnrf_NFManagement.DeregisterNFInstanceRequest - derigisterNfInstanceRequest.NfInstanceID = &ausfContext.NfId - _, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, &derigisterNfInstanceRequest) - - return err + _, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, request) + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + // API error + if deregNfError, okDeg := apiErr.Model().(Nnrf_NFManagement.DeregisterNFInstanceError); okDeg { + return &deregNfError.ProblemDetails, err + } + return nil, err + } + return nil, err } func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( resouceNrfUri string, retrieveNfInstanceID string, err error, ) { ausfContext := s.consumer.Context() - client := s.getNFManagementClient(ausfContext.NrfUri) nfProfile, err := s.buildNfProfile(ausfContext) if err != nil { @@ -136,6 +142,11 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( NrfNfManagementNfProfile: &nfProfile, } for { + select { + case <-ctx.Done(): + return "", "", errors.Errorf("Context Cancel before RegisterNFInstance") + default: + } res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, registerNFInstanceRequest) if err != nil || res == nil { logger.ConsumerLog.Errorf("AUSF register to NRF Error[%v]", err) @@ -204,14 +215,18 @@ func (s *nnrfService) buildNfProfile(ausfContext *ausf_context.AUSFContext) ( func (s *nnrfService) GetUdmUrl(nrfUri string) string { udmUrl := "https://localhost:29503" // default - nfDiscoverParam := &Nnrf_NFDiscovery.SearchNFInstancesRequest{ - ServiceNames: []models.ServiceName{models.ServiceName_NUDM_UEAU}, + targetNfType := models.NrfNfManagementNfType_UDM + requestNfType := models.NrfNfManagementNfType_AUSF + nfDiscoverParam := Nnrf_NFDiscovery.SearchNFInstancesRequest{ + RequesterNfType: &requestNfType, + TargetNfType: &targetNfType, + ServiceNames: []models.ServiceName{models.ServiceName_NUDM_UEAU}, } res, err := s.SendSearchNFInstances( nrfUri, models.NrfNfManagementNfType_UDM, models.NrfNfManagementNfType_AUSF, - *nfDiscoverParam, + nfDiscoverParam, ) if err != nil { logger.ConsumerLog.Errorln("[Search UDM UEAU] ", err.Error(), "use defalt udmUrl", udmUrl) diff --git a/pkg/service/init.go b/pkg/service/init.go index 13860de..0c93036 100644 --- a/pkg/service/init.go +++ b/pkg/service/init.go @@ -16,8 +16,6 @@ import ( "github.com/free5gc/ausf/internal/sbi/processor" "github.com/free5gc/ausf/pkg/app" "github.com/free5gc/ausf/pkg/factory" - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/nrf/NFManagement" ) var AUSF *AusfApp @@ -166,25 +164,15 @@ func (a *AusfApp) terminateProcedure() { a.CallServerStop() // deregister with NRF - err := a.Consumer().SendDeregisterNFInstance() - if err != nil { - switch apiErr := err.(type) { - case openapi.GenericOpenAPIError: - switch errModel := apiErr.Model().(type) { - case NFManagement.DeregisterNFInstanceError: - pd := &errModel.ProblemDetails - logger.InitLog.Errorf("Deregister NF instance Failed Problem[%+v]", pd) - case error: - logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err) - } - case error: - logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err) - } + problemDetails, err := a.Consumer().SendDeregisterNFInstance() + if problemDetails != nil { + logger.MainLog.Errorf("Deregister NF instance Failed Problem[%+v]", problemDetails) + } else if err != nil { + logger.MainLog.Errorf("Deregister NF instance Error[%+v]", err) + } else { + logger.MainLog.Infof("Deregister from NRF successfully") } - - logger.MainLog.Infof("Deregister from NRF successfully") - - logger.MainLog.Infof("AUSF SBI Server terminated") + logger.MainLog.Infof("CHF SBI Server terminated") } func (a *AusfApp) CallServerStop() {