Skip to content

Commit

Permalink
fix: nrf_deregistration error type assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
a3828162 committed Aug 9, 2024
1 parent 4d35c61 commit 81bc721
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
20 changes: 6 additions & 14 deletions internal/sbi/consumer/nrf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,22 @@ func (s *nnrfService) SendNFIntancesUDR(id string, types int) string {
return ""
}

func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) {
func (s *nnrfService) SendDeregisterNFInstance() (err error) {
logger.ConsumerLog.Infof("Send Deregister NFInstance")

ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF)
ctx, _, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF)
if err != nil {
return pd, err
return err
}

udmContext := s.consumer.Context()
client := s.getNFManagementClient(udmContext.NrfUri)

var derigisterNfInstanceRequest Nnrf_NFManagement.DeregisterNFInstanceRequest
derigisterNfInstanceRequest.NfInstanceID = &udmContext.NfId
res, err := client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, &derigisterNfInstanceRequest)

if err == nil {
return problemDetails, err
} else if res != nil {
problem := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
problemDetails = &problem
} else {
err = openapi.ReportError("server no response")
}
return problemDetails, err
_, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, &derigisterNfInstanceRequest)

return err
}

func (s *nnrfService) RegisterNFInstance(ctx context.Context) (
Expand Down
26 changes: 19 additions & 7 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/sirupsen/logrus"

"github.com/free5gc/openapi"
"github.com/free5gc/openapi/nrf/NFManagement"
udm_context "github.com/free5gc/udm/internal/context"
"github.com/free5gc/udm/internal/logger"
"github.com/free5gc/udm/internal/sbi"
Expand Down Expand Up @@ -147,14 +149,24 @@ func (a *UdmApp) terminateProcedure() {
a.CallServerStop()

// deregister with NRF
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")
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)
}
}

logger.InitLog.Infof("Deregister from NRF successfully")

logger.MainLog.Infof("UDM SBI Server terminated")
}

Expand Down

0 comments on commit 81bc721

Please sign in to comment.