Skip to content

Commit

Permalink
Merge pull request #112 from andy89923/fix/chf-service
Browse files Browse the repository at this point in the history
fix: SMF Crash when no CHF running
  • Loading branch information
ianchen0119 authored Jul 27, 2024
2 parents acf1e31 + 9a3fa72 commit 85c084a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
19 changes: 16 additions & 3 deletions internal/sbi/consumer/chf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ func (s *nchfService) buildConvergedChargingRequest(smContext *smf_context.SMCon
return req
}

func (s *nchfService) SendConvergedChargingRequest(smContext *smf_context.SMContext,
requestType smf_context.RequestType, multipleUnitUsage []models.MultipleUnitUsage,
) (*models.ChargingDataResponse, *models.ProblemDetails, error) {
func (s *nchfService) SendConvergedChargingRequest(
smContext *smf_context.SMContext,
requestType smf_context.RequestType,
multipleUnitUsage []models.MultipleUnitUsage,
) (
*models.ChargingDataResponse, *models.ProblemDetails, error,
) {
logger.ChargingLog.Info("Handle SendConvergedChargingRequest")

req := s.buildConvergedChargingRequest(smContext, multipleUnitUsage)
Expand All @@ -119,13 +123,22 @@ func (s *nchfService) SendConvergedChargingRequest(smContext *smf_context.SMCont
return nil, pd, err
}

if smContext.SelectedCHFProfile.NfServices == nil {
errMsg := "No CHF found"
return nil, openapi.ProblemDetailsDataNotFound(errMsg), fmt.Errorf(errMsg)
}

var client *Nchf_ConvergedCharging.APIClient
// Create Converged Charging Client for this SM Context
for _, service := range *smContext.SelectedCHFProfile.NfServices {
if service.ServiceName == models.ServiceName_NCHF_CONVERGEDCHARGING {
client = s.getConvergedChargingClient(service.ApiPrefix)
}
}
if client == nil {
errMsg := "No CONVERGEDCHARGING-CHF found"
return nil, openapi.ProblemDetailsDataNotFound(errMsg), fmt.Errorf(errMsg)
}

// select the appropriate converged charging service based on trigger type
switch requestType {
Expand Down
8 changes: 5 additions & 3 deletions internal/sbi/consumer/nrf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,11 @@ func (s *nnrfService) CHFSelection(smContext *smf_context.SMContext) error {
}

// Select CHF from available CHF
smContext.SelectedCHFProfile = rsp.NfInstances[0]

return nil
if len(rsp.NfInstances) > 0 {
smContext.SelectedCHFProfile = rsp.NfInstances[0]
return nil
}
return fmt.Errorf("No CHF found in CHFSelection")
}

// PCFSelection will select PCF for this SM Context
Expand Down

0 comments on commit 85c084a

Please sign in to comment.