diff options
Diffstat (limited to 'src/rsync/cmd/main.go')
-rw-r--r-- | src/rsync/cmd/main.go | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/src/rsync/cmd/main.go b/src/rsync/cmd/main.go index 6e30b60b..e62e0542 100644 --- a/src/rsync/cmd/main.go +++ b/src/rsync/cmd/main.go @@ -17,11 +17,63 @@ import ( "fmt" "log" "math/rand" + "net" + register "github.com/onap/multicloud-k8s/src/rsync/pkg/grpc" + installpb "github.com/onap/multicloud-k8s/src/rsync/pkg/grpc/installapp" + "github.com/onap/multicloud-k8s/src/rsync/pkg/grpc/installappserver" + "strings" "time" + + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/config" contextDb "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/contextdb" "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/testdata" ) +func startGrpcServer() error { + var tls bool + + if strings.Contains(config.GetConfiguration().GrpcEnableTLS, "enable") { + tls = true + } else { + tls = false + } + certFile := config.GetConfiguration().GrpcServerCert + keyFile := config.GetConfiguration().GrpcServerKey + + host, port := register.GetServerHostPort() + + lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", host, port)) + if err != nil { + log.Fatalf("Could not listen to port: %v", err) + } + var opts []grpc.ServerOption + if tls { + if certFile == "" { + certFile = testdata.Path("server.pem") + } + if keyFile == "" { + keyFile = testdata.Path("server.key") + } + creds, err := credentials.NewServerTLSFromFile(certFile, keyFile) + if err != nil { + log.Fatalf("Could not generate credentials %v", err) + } + opts = []grpc.ServerOption{grpc.Creds(creds)} + } + grpcServer := grpc.NewServer(opts...) + installpb.RegisterInstallappServer(grpcServer, installappserver.NewInstallAppServer()) + + log.Println("Starting rsync gRPC Server") + err = grpcServer.Serve(lis) + if err != nil { + log.Fatalf("rsync grpc server is not serving %v", err) + } + return err +} + func main() { rand.Seed(time.Now().UnixNano()) @@ -44,6 +96,10 @@ func main() { log.Fatalln("Exiting...") } - // Initialize grpc - + // Start grpc + fmt.Println("starting rsync GRPC server..") + err = startGrpcServer() + if err != nil { + log.Fatalf("GRPC server failed to start") + } } |