Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Comply with new App Interface #31

Merged
merged 4 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading