a30770ee14fb668217801b0df68f7c95798f8ef0
[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/scp/ric-app/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         "net"
10 )
11
12 // RCControlServer represents the grpc server
13 type RCControlServer struct {
14 }
15
16 //Start gRPC Server For receiving Control   Messages from dataingestion
17 func StartgRPCRCControlCommServerRoutine() error {
18
19         //log.Println("Starting Go Routine for Handling gRPC Server for handling gRPC RCControl Handling")
20         xapp.Logger.Info("Starting Go Routine for Handling gRPC Server for handling gRPC RCControl Handling ")
21         port := xapp.Config.GetString("controls.ricHOControlgRpcServerPort")
22         xapp.Logger.Info("GrpcServer started listening on Port port =  %v", port)
23         lConnStr := ":" + port
24
25         // create a listener on TCP port Configured
26         lLis, lErr := net.Listen("tcp", lConnStr)
27         if lErr != nil {
28                 //log.Printf("GrpcServer Listen failed with error", lErr)
29                 xapp.Logger.Info("GrpcServer Listen failed with error = %v", lErr)
30                 return lErr
31         }
32
33         xapp.Logger.Info("GrpcServer started listening on Connection: %v", lConnStr)
34         // create a server instance
35         lRCControlSrv := RCControlServer{}
36
37         // create a grpc server object
38         lgRPCServer := grpc.NewServer()
39
40         // attach the Ping service to the server
41         rc.RegisterMsgCommServer(lgRPCServer, &lRCControlSrv)
42
43         //Register to health service
44         grpc_health_v1.RegisterHealthServer(lgRPCServer, health.NewServer())
45
46         xapp.Logger.Debug("GrpcServer Serve start with port = %v and lConnStr = %v and lgRPCServer = %v ", lLis, lConnStr, lgRPCServer)
47
48         // start the server
49         if lErr := lgRPCServer.Serve(lLis); lErr != nil {
50                 xapp.Logger.Info("GrpcServer Serve failed with error", lErr)
51                 return lErr
52         }
53
54         return nil
55 }