summaryrefslogtreecommitdiffstats
path: root/src/rsync/cmd
diff options
context:
space:
mode:
authorManjunath Ranganathaiah <manjunath.ranganathaiah@intel.com>2020-05-11 20:03:43 +0000
committerEric Multanen <eric.w.multanen@intel.com>2020-05-21 12:33:33 -0700
commit864c44c57473cbb10b55607cdd6e55fac592a43d (patch)
tree55eb95ace545b567d8742c4254b0286e25b3ba32 /src/rsync/cmd
parent10b401413dd722ef57de79ba3caaa873ed1093b8 (diff)
InstallApp Grpc proto and server for rsync
Add the InstallApp GRPC proto file server code to the resource synchronizer. Issue-ID: MULTICLOUD-1005 Signed-off-by: Manjunath Ranganathaiah <manjunath.ranganathaiah@intel.com> Change-Id: I8e586f1b878009fd4df53ef48aae6deded0f64ea
Diffstat (limited to 'src/rsync/cmd')
-rw-r--r--src/rsync/cmd/main.go60
1 files changed, 58 insertions, 2 deletions
diff --git a/src/rsync/cmd/main.go b/src/rsync/cmd/main.go
index 6e30b60b..ce98edd2 100644
--- a/src/rsync/cmd/main.go
+++ b/src/rsync/cmd/main.go
@@ -17,11 +17,63 @@ import (
"fmt"
"log"
"math/rand"
+ "net"
+ register "rsync/pkg/grpc"
+ installpb "rsync/pkg/grpc/installapp"
+ "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")
+ }
}