Skip to content

Commit

Permalink
chore: use manageGrpcClient method in Service/init.go (#145)
Browse files Browse the repository at this point in the history
* Use manageGrpcClient method in Service/init.go

Signed-off-by: gatici <[email protected]>

* chore: update config5g version

Signed-off-by: gatici <[email protected]>

* removing spots in the logs

Signed-off-by: gatici <[email protected]>

* remove MANAGED_BY_CONFIG_POD check if clause in factory

Signed-off-by: gatici <[email protected]>

---------

Signed-off-by: gatici <[email protected]>
  • Loading branch information
gatici authored Oct 28, 2024
1 parent 9e7e361 commit a4fa310
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 55 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.2-dev
1.5.2
2 changes: 1 addition & 1 deletion factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (c *Config) GetSbiUri() string {
return c.GetSbiScheme() + "://" + c.GetSbiRegisterAddr()
}

func (c *Config) updateConfig(commChannel chan *protos.NetworkSliceResponse) bool {
func (c *Config) UpdateConfig(commChannel chan *protos.NetworkSliceResponse) bool {
for rsp := range commChannel {
logger.GrpcLog.Infoln("Received updateConfig in the nrf app : ", rsp)
for _, ns := range rsp.NetworkSlice {
Expand Down
50 changes: 0 additions & 50 deletions factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ package factory
import (
"fmt"
"os"
"time"

grpcClient "github.com/omec-project/config5g/proto/client"
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
"github.com/omec-project/nrf/logger"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -43,57 +40,10 @@ func InitConfigFactory(f string) error {
NrfConfig.Configuration.WebuiUri = "webui:9876"
}
logger.InitLog.Infof("DefaultPlmnId Mnc %v, Mcc %v", NrfConfig.Configuration.DefaultPlmnId.Mnc, NrfConfig.Configuration.DefaultPlmnId.Mcc)
if os.Getenv("MANAGED_BY_CONFIG_POD") == "true" {
logger.InitLog.Infoln("MANAGED_BY_CONFIG_POD is true")
client, err := grpcClient.ConnectToConfigServer(NrfConfig.Configuration.WebuiUri)
if err != nil {
go updateConfig(client)
}
return err
}
}
return nil
}

// updateConfig connects the config pod GRPC server and subscribes the config changes
// then updates NRF configuration
func updateConfig(client grpcClient.ConfClient) {
var stream protos.ConfigService_NetworkSliceSubscribeClient
var err error
var configChannel chan *protos.NetworkSliceResponse
for {
if client != nil {
stream, err = client.CheckGrpcConnectivity()
if err != nil {
logger.InitLog.Errorf("%v", err)
if stream != nil {
time.Sleep(time.Second * 30)
continue
} else {
err = client.GetConfigClientConn().Close()
if err != nil {
logger.InitLog.Debugf("failing ConfigClient is not closed properly: %+v", err)
}
client = nil
continue
}
}
if configChannel == nil {
configChannel = client.PublishOnConfigChange(true, stream)
ManagedByConfigPod = true
go NrfConfig.updateConfig(configChannel)
}

} else {
client, err = grpcClient.ConnectToConfigServer(NrfConfig.Configuration.WebuiUri)
if err != nil {
logger.InitLog.Errorf("%+v", err)
}
continue
}
}
}

func CheckConfigVersion() error {
currentVersion := NrfConfig.GetVersion()

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/google/uuid v1.6.0
github.com/mitchellh/mapstructure v1.5.0
github.com/omec-project/config5g v1.5.3
github.com/omec-project/config5g v1.5.4
github.com/omec-project/openapi v1.3.1
github.com/omec-project/util v1.2.3
github.com/prometheus/client_golang v1.20.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/omec-project/config5g v1.5.3 h1:FPetMFU1/BXGzihcoRHJm0q1vU1AnYyR4Tq1T1gyvUQ=
github.com/omec-project/config5g v1.5.3/go.mod h1:HOvQtmi79f8cw35AiFHWHDoCTuZbXfMjeFJWgtPbwaI=
github.com/omec-project/config5g v1.5.4 h1:5JMw5Fsr5qyLZpQi3IZQaQPj78QJMFQXDVS3QDMOY9Y=
github.com/omec-project/config5g v1.5.4/go.mod h1:HOvQtmi79f8cw35AiFHWHDoCTuZbXfMjeFJWgtPbwaI=
github.com/omec-project/openapi v1.3.1 h1:NCteMRdMtWnMhf1CXYduuLgeu8fEhc/7XO1CiE7fN3Y=
github.com/omec-project/openapi v1.3.1/go.mod h1:cR6Iharp2TLOzEmskQ/EdCVFZnpKh0zTvUSSuyXAYLE=
github.com/omec-project/util v1.2.3 h1:h32ZYFT99+fB9VPp1CQUIKwrSP6RtX+PbFDcqmEHmn0=
Expand Down
59 changes: 59 additions & 0 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"syscall"
"time"

grpcClient "github.com/omec-project/config5g/proto/client"
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
"github.com/urfave/cli"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -88,9 +90,66 @@ func (nrf *NRF) Initialize(c *cli.Context) error {
return err
}

if os.Getenv("MANAGED_BY_CONFIG_POD") == "true" {
logger.InitLog.Infoln("MANAGED_BY_CONFIG_POD is true")
go manageGrpcClient(factory.NrfConfig.Configuration.WebuiUri)
}

return nil
}

// manageGrpcClient connects the config pod GRPC server and subscribes the config changes.
// Then it updates NRF configuration.
func manageGrpcClient(webuiUri string) {
var configChannel chan *protos.NetworkSliceResponse
var client grpcClient.ConfClient
var stream protos.ConfigService_NetworkSliceSubscribeClient
var err error
count := 0
for {
if client != nil {
if client.CheckGrpcConnectivity() != "ready" {
time.Sleep(time.Second * 30)
count++
if count > 5 {
err = client.GetConfigClientConn().Close()
if err != nil {
logger.InitLog.Infof("failing ConfigClient is not closed properly: %+v", err)
}
client = nil
count = 0
}
logger.InitLog.Infoln("checking the connectivity readiness")
continue
}

if stream == nil {
stream, err = client.SubscribeToConfigServer()
if err != nil {
logger.InitLog.Infof("failing SubscribeToConfigServer: %+v", err)
continue
}
}

if configChannel == nil {
configChannel = client.PublishOnConfigChange(true, stream)
logger.InitLog.Infoln("PublishOnConfigChange is triggered")
go factory.NrfConfig.UpdateConfig(configChannel)
logger.InitLog.Infoln("NRF updateConfig is triggered")
}
} else {
client, err = grpcClient.ConnectToConfigServer(webuiUri)
stream = nil
configChannel = nil
logger.InitLog.Infoln("connecting to config server")
if err != nil {
logger.InitLog.Errorf("%+v", err)
}
continue
}
}
}

func (nrf *NRF) setLogLevel() {
if factory.NrfConfig.Logger == nil {
initLog.Warnln("NRF config without log level setting!!!")
Expand Down

0 comments on commit a4fa310

Please sign in to comment.