Skip to content

Commit

Permalink
fix: rename and organize a method
Browse files Browse the repository at this point in the history
Signed-off-by: gatici <[email protected]>
  • Loading branch information
gatici committed Oct 22, 2024
1 parent 6c1e012 commit 4fa3dfc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
33 changes: 18 additions & 15 deletions factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
"github.com/omec-project/udr/logger"
"go.uber.org/zap"
"google.golang.org/grpc/connectivity"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -69,7 +70,7 @@ func InitConfigFactory(f string) error {
initLog.Infoln("MANAGED_BY_CONFIG_POD is true")
client, err := grpcClient.ConnectToConfigServer(UdrConfig.Configuration.WebuiUri)
if err != nil {
go updateConfig(client)
go manageGrpcClient(client)
}
return err
} else {
Expand All @@ -83,38 +84,40 @@ func InitConfigFactory(f string) error {
return nil
}

// updateConfig connects the config pod GRPC server and subscribes the config changes
// manageGrpcClient connects the config pod GRPC server and subscribes the config changes
// then updates UDR configuration
func updateConfig(client grpcClient.ConfClient) {
func manageGrpcClient(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 {
initLog.Errorf("%v", err)
if stream != nil {
time.Sleep(time.Second * 30)
continue
} else {
err = client.GetConfigClientConn().Close()
if err != nil {
initLog.Debugf("failing ConfigClient is not closed properly: %+v", err)
}
client = nil
continue
logger.InitLog.Errorf("%v", err)
}
if stream == nil {
time.Sleep(time.Second * 30)
continue
}
if client.GetConfigClientConn().GetState() != connectivity.Ready {
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)
ConfigUpdateDbTrigger = make(chan *UpdateDb, 10)
go UdrConfig.updateConfig(configChannel, ConfigUpdateDbTrigger)
}

} else {
client, err = grpcClient.ConnectToConfigServer(UdrConfig.Configuration.WebuiUri)
if err != nil {
initLog.Errorf("%+v", err)
logger.InitLog.Errorf("%+v", err)
}
continue
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/urfave/cli v1.22.16
go.mongodb.org/mongo-driver v1.17.1
go.uber.org/zap v1.27.0
google.golang.org/grpc v1.67.1
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -69,7 +70,6 @@ require (
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/h2non/gock.v1 v1.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down

0 comments on commit 4fa3dfc

Please sign in to comment.