README updated
[ric-app/rc.git] / control / grpcserver.go
1 package control
2
3 import (
4         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
5         "gerrit.o-ran-sc.org/r/ric-app/rc/protocol/grpc/ricmsgcommrpc/rc"
6         "google.golang.org/grpc"
7         "google.golang.org/grpc/health"
8         "google.golang.org/grpc/health/grpc_health_v1"
9         "google.golang.org/grpc/reflection"
10         "net"
11 )
12
13 // RCControlServer represents the grpc server
14 type RCControlServer struct {
15 }
16
17 //Start gRPC Server For receiving Control   Messages from dataingestion
18 func StartgRPCRCControlCommServerRoutine() error {
19
20         //log.Println("Starting Go Routine for Handling gRPC Server for handling gRPC RCControl Handling")
21         xapp.Logger.Info("Starting Go Routine for Handling gRPC Server for handling gRPC RCControl Handling ")
22         port := xapp.Config.GetString("controls.ricHOControlgRpcServerPort")
23         xapp.Logger.Info("GrpcServer started listening on Port port =  %v", port)
24         lConnStr := ":" + port
25
26         // create a listener on TCP port Configured
27         lLis, lErr := net.Listen("tcp", lConnStr)
28         if lErr != nil {
29                 //log.Printf("GrpcServer Listen failed with error", lErr)
30                 xapp.Logger.Info("GrpcServer Listen failed with error = %v", lErr)
31                 return lErr
32         }
33
34         xapp.Logger.Info("GrpcServer started listening on Connection: %v", lConnStr)
35         // create a server instance
36         lRCControlSrv := RCControlServer{}
37
38         // create a grpc server object
39         lgRPCServer := grpc.NewServer()
40
41         // attach the Ping service to the server
42         rc.RegisterMsgCommServer(lgRPCServer, &lRCControlSrv)
43         reflection.Register(lgRPCServer)
44
45         //Register to health service
46         grpc_health_v1.RegisterHealthServer(lgRPCServer, health.NewServer())
47
48         xapp.Logger.Debug("GrpcServer Serve start with port = %v and lConnStr = %v and lgRPCServer = %v ", lLis, lConnStr, lgRPCServer)
49
50         // start the server
51         if lErr := lgRPCServer.Serve(lLis); lErr != nil {
52                 xapp.Logger.Info("GrpcServer Serve failed with error", lErr)
53                 return lErr
54         }
55
56         return nil
57 }