Skip to content

Commit

Permalink
Merge pull request #31 from andy89923/refactor/app
Browse files Browse the repository at this point in the history
Refactor: Comply with new App Interface
  • Loading branch information
ianchen0119 authored Jun 20, 2024
2 parents 30e0f20 + 67a76a4 commit 516f992
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
3 changes: 1 addition & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ func action(cliCtx *cli.Context) error {
}
CHF = chf

chf.Start("")
CHF.WaitRoutineStopped()
chf.Start()

return nil
}
Expand Down
9 changes: 5 additions & 4 deletions internal/sbi/consumer/nrf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"sync"
"time"

// "github.com/free5gc/openapi/nrf/NFManagement" // R17
chf_context "github.com/free5gc/chf/internal/context"
"github.com/free5gc/chf/internal/logger"
"github.com/free5gc/openapi"
Expand Down Expand Up @@ -73,8 +72,10 @@ func (s *nnrfService) getNFDiscClient(uri string) *Nnrf_NFDiscovery.APIClient {
}

func (s *nnrfService) SendSearchNFInstances(
nrfUri string, targetNfType, requestNfType models.NfType, param Nnrf_NFDiscovery.SearchNFInstancesParamOpts) (
*models.SearchResult, error) {
nrfUri string, targetNfType, requestNfType models.NfType, param Nnrf_NFDiscovery.SearchNFInstancesParamOpts,
) (
*models.SearchResult, error,
) {
// Set client and set url
chfContext := s.consumer.Context()

Expand Down Expand Up @@ -147,7 +148,7 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) (
var nf models.NfProfile
var res *http.Response
for {
nf, res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(context.TODO(), chfContext.NfId, nfProfile)
nf, res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, chfContext.NfId, nfProfile)
if err != nil || res == nil {
logger.ConsumerLog.Errorf("CHF register to NRF Error[%v]", err)
time.Sleep(2 * time.Second)
Expand Down
2 changes: 1 addition & 1 deletion internal/sbi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@ func (s *Server) startServer(wg *sync.WaitGroup) {
if err != nil && err != http.ErrServerClosed {
logger.SBILog.Errorf("SBI server error: %v", err)
}
logger.SBILog.Warnf("SBI server (listen on %s) stopped", s.httpServer.Addr)
logger.SBILog.Infof("SBI server (listen on %s) stopped", s.httpServer.Addr)
}
2 changes: 1 addition & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type App interface {
SetLogLevel(level string)
SetReportCaller(reportCaller bool)

Start(tlsKeyLogPath string)
Start()
Terminate()

Context() *chf_context.CHFContext
Expand Down
18 changes: 8 additions & 10 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ var CHF *ChfApp
var _ app.App = &ChfApp{}

type ChfApp struct {
app.App
consumer.ConsumerChf
processor.ProcessorChf
sbi.ServerChf

chfCtx *chf_context.CHFContext
cfg *factory.Config

Expand Down Expand Up @@ -134,13 +129,11 @@ func (c *ChfApp) SetReportCaller(reportCaller bool) {
if reportCaller == logger.Log.ReportCaller {
return
}

c.Config().SetLogReportCaller(reportCaller)
logger.Log.SetReportCaller(reportCaller)
}

// tlsKeyLogPath have to remove after all NFs are refactor
func (a *ChfApp) Start(tlsKeyLogPath string) {
func (a *ChfApp) Start() {
logger.InitLog.Infoln("Server started")

a.wg.Add(1)
Expand All @@ -158,6 +151,8 @@ func (a *ChfApp) Start(tlsKeyLogPath string) {
if err := a.sbiServer.Run(context.Background(), &a.wg); err != nil {
logger.MainLog.Fatalf("Run SBI server failed: %+v", err)
}

a.WaitRoutineStopped()
}

func (a *ChfApp) listenShutdownEvent() {
Expand All @@ -170,12 +165,15 @@ func (a *ChfApp) listenShutdownEvent() {
}()

<-a.ctx.Done()
a.Terminate()
a.terminateProcedure()
}

func (c *ChfApp) Terminate() {
logger.MainLog.Infof("Terminating CHF...")
c.cancel()
}

func (c *ChfApp) terminateProcedure() {
logger.MainLog.Infof("Terminating CHF...")
c.CallServerStop()

// deregister with NRF
Expand Down

0 comments on commit 516f992

Please sign in to comment.