Commit 0d15a116 authored by Kunal Taitkar's avatar Kunal Taitkar
Browse files

Merge branch 'devbranch' into kunal_DownloadManager

parents 2aa47da5 1cb61f1a
Branches
Tags
2 merge requests!10220Aug Merge Dev to Stg,!100downloadhelpermdl: Export struct and check for "Last-Modified" header
Showing with 73 additions and 92 deletions
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: grpcbuildermdl/grpcbuildermdl.proto
// source: grpcbuildermdl.proto
package grpcbuildermdl
......@@ -39,7 +39,7 @@ func (m *GRPCMessage) Reset() { *m = GRPCMessage{} }
func (m *GRPCMessage) String() string { return proto.CompactTextString(m) }
func (*GRPCMessage) ProtoMessage() {}
func (*GRPCMessage) Descriptor() ([]byte, []int) {
return fileDescriptor_e620ca3a5f127fa1, []int{0}
return fileDescriptor_8d80590c423530f2, []int{0}
}
func (m *GRPCMessage) XXX_Unmarshal(b []byte) error {
......@@ -106,7 +106,7 @@ func (m *GRPCRequest) Reset() { *m = GRPCRequest{} }
func (m *GRPCRequest) String() string { return proto.CompactTextString(m) }
func (*GRPCRequest) ProtoMessage() {}
func (*GRPCRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_e620ca3a5f127fa1, []int{1}
return fileDescriptor_8d80590c423530f2, []int{1}
}
func (m *GRPCRequest) XXX_Unmarshal(b []byte) error {
......@@ -145,7 +145,7 @@ func (m *GRPCResponse) Reset() { *m = GRPCResponse{} }
func (m *GRPCResponse) String() string { return proto.CompactTextString(m) }
func (*GRPCResponse) ProtoMessage() {}
func (*GRPCResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_e620ca3a5f127fa1, []int{2}
return fileDescriptor_8d80590c423530f2, []int{2}
}
func (m *GRPCResponse) XXX_Unmarshal(b []byte) error {
......@@ -175,6 +175,8 @@ func (m *GRPCResponse) GetData() string {
type GRPCByteResponse struct {
Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
ErrorCode int32 `protobuf:"varint,2,opt,name=errorCode,proto3" json:"errorCode,omitempty"`
Error string `protobuf:"bytes,3,opt,name=error,proto3" json:"error,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
......@@ -184,7 +186,7 @@ func (m *GRPCByteResponse) Reset() { *m = GRPCByteResponse{} }
func (m *GRPCByteResponse) String() string { return proto.CompactTextString(m) }
func (*GRPCByteResponse) ProtoMessage() {}
func (*GRPCByteResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_e620ca3a5f127fa1, []int{3}
return fileDescriptor_8d80590c423530f2, []int{3}
}
func (m *GRPCByteResponse) XXX_Unmarshal(b []byte) error {
......@@ -212,6 +214,20 @@ func (m *GRPCByteResponse) GetData() []byte {
return nil
}
func (m *GRPCByteResponse) GetErrorCode() int32 {
if m != nil {
return m.ErrorCode
}
return 0
}
func (m *GRPCByteResponse) GetError() string {
if m != nil {
return m.Error
}
return ""
}
func init() {
proto.RegisterType((*GRPCMessage)(nil), "grpcbuildermdl.GRPCMessage")
proto.RegisterType((*GRPCRequest)(nil), "grpcbuildermdl.GRPCRequest")
......@@ -219,30 +235,30 @@ func init() {
proto.RegisterType((*GRPCByteResponse)(nil), "grpcbuildermdl.GRPCByteResponse")
}
func init() {
proto.RegisterFile("grpcbuildermdl/grpcbuildermdl.proto", fileDescriptor_e620ca3a5f127fa1)
}
var fileDescriptor_e620ca3a5f127fa1 = []byte{
// 288 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0xc1, 0x4a, 0xc3, 0x40,
0x10, 0x35, 0xda, 0x8a, 0x9d, 0x04, 0x29, 0x83, 0x87, 0xa0, 0x1e, 0xc2, 0x0a, 0x92, 0x53, 0x85,
0x78, 0xf6, 0x92, 0x1e, 0xec, 0x41, 0x45, 0x56, 0xbc, 0x08, 0x1e, 0xb6, 0xd9, 0xa1, 0x86, 0xa6,
0x49, 0xdc, 0xdd, 0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xe1, 0x60, 0xa6, 0xae, 0xc5, 0x79,
0x34, 0xb4, 0x74, 0x0f, 0xb2, 0x83, 0xe4, 0x15, 0x26, 0x0d, 0x3b, 0xff, 0xa0, 0x6c, 0x8d, 0x0b,
0x17, 0xec, 0xb5, 0xbe, 0x1c, 0x5e, 0xfe, 0xd9, 0xa6, 0xd3, 0xb7, 0x9d, 0x57, 0x5f, 0x1e, 0xdb,
0xcf, 0x70, 0xfb, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x59, 0x6b, 0xff, 0x89, 0x33, 0x02, 0x00, 0x00,
func init() { proto.RegisterFile("grpcbuildermdl.proto", fileDescriptor_8d80590c423530f2) }
var fileDescriptor_8d80590c423530f2 = []byte{
// 308 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xb1, 0x4e, 0xf3, 0x30,
0x14, 0x85, 0xff, 0xfc, 0xb4, 0x88, 0xdc, 0x54, 0xa8, 0xb2, 0x3a, 0x44, 0xd0, 0x21, 0xf2, 0x94,
0xa9, 0x43, 0x98, 0x59, 0x92, 0x81, 0x0e, 0x80, 0x90, 0x11, 0x4b, 0x25, 0x06, 0x37, 0xbe, 0x2a,
0x51, 0xd3, 0x38, 0xd8, 0x2e, 0x12, 0x8f, 0xc1, 0x1b, 0x23, 0xdb, 0xa9, 0x9a, 0x56, 0x11, 0xdb,
0x3d, 0xc7, 0x47, 0xd7, 0xe7, 0xb3, 0x0c, 0xb3, 0x8d, 0x6a, 0xcb, 0xf5, 0xbe, 0xaa, 0x05, 0xaa,
0x9d, 0xa8, 0x17, 0xad, 0x92, 0x46, 0x92, 0xeb, 0x53, 0x97, 0xfe, 0x04, 0x10, 0x3d, 0xb0, 0x97,
0xe2, 0x09, 0xb5, 0xe6, 0x1b, 0x24, 0x04, 0x46, 0x0d, 0xdf, 0x61, 0x1c, 0x24, 0x41, 0x1a, 0x32,
0x37, 0x5b, 0x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ff, 0xff, 0xce, 0x75, 0x30, 0xf3,
0x58, 0x02, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
......@@ -322,7 +338,7 @@ var _GRPCService_serviceDesc = grpc.ServiceDesc{
},
},
Streams: []grpc.StreamDesc{},
Metadata: "grpcbuildermdl/grpcbuildermdl.proto",
Metadata: "grpcbuildermdl.proto",
}
// GRPCCheckClient is the client API for GRPCCheck service.
......@@ -394,5 +410,5 @@ var _GRPCCheck_serviceDesc = grpc.ServiceDesc{
},
},
Streams: []grpc.StreamDesc{},
Metadata: "grpcbuildermdl/grpcbuildermdl.proto",
Metadata: "grpcbuildermdl.proto",
}
......@@ -24,6 +24,8 @@ message GRPCResponse {
message GRPCByteResponse {
bytes data = 1;
int32 errorCode = 2;
string error = 3;
}
service GRPCService {
......
......@@ -11,33 +11,6 @@ import (
"google.golang.org/grpc"
)
// type GRPCHost struct {
// Host string `json:"host"`
// Port string `json:"port"`
// }
// var clientConns map[string]*grpc.ClientConn
// var mutex sync.Mutex
// var once sync.Once
// // GetGRPCClientConnection GetGRPCClientConnection
// func GetGRPCClientConnection(hostName string) (*grpc.ClientConn, error) {
// defer mutex.Unlock()
// mutex.Lock()
// if clientConns == nil {
// return nil, errormdl.Wrap("GRPC_NOT_DONE")
// }
// if hostName == "" {
// if instance, ok := clientConns[hostName]; ok {
// return instance, nil
// }
// }
// if instance, ok := clientConns[hostName]; ok {
// return instance, nil
// }
// return nil, errormdl.Wrap("GRPC not found for instance: " + hostName)
// }
// TotalCheck TotalCheck
func TotalCheck() (string, error) {
// TODO: review
......@@ -54,17 +27,11 @@ func TotalCheck() (string, error) {
return res.GetData(), nil
}
type Employee struct {
Name string `json:"empname"`
Number int `json:"empid"`
}
var instances map[string]*grpcpool.Pool
var instancesList map[string]map[string]*grpcpool.Pool
// Init init
func Init(grpcServerURLList []string, grpcClients []string) {
instances = make(map[string]*grpcpool.Pool)
loggermdl.LogError("Length of grpcServerURLList", len(grpcServerURLList))
......@@ -75,42 +42,37 @@ func Init(grpcServerURLList []string, grpcClients []string) {
}
//ByteHandler ByteHandler
func ByteHandler(req *grpcbuildermdl.GRPCRequest, grpcServerURL string) ([]byte, error) {
loggermdl.LogError("grpcServer instances", instances[grpcServerURL], grpcServerURL)
func ByteHandler(req *grpcbuildermdl.GRPCRequest, grpcServerURL string) ([]byte, int32, string, error) {
if instances[grpcServerURL] != nil {
conn, err := instances[grpcServerURL].Get(context.Background())
if err != nil {
loggermdl.LogError("Failed to create gRPC pool: %v", err)
return nil, err
return nil, 0, "", err
}
client := grpcbuildermdl.NewGRPCServiceClient(conn.ClientConn)
loggermdl.LogError("request Data send", req)
res, err := client.GRPCHandler(context.Background(), req)
if err != nil {
loggermdl.LogError("GRPCHandler err:", err)
return nil, err
loggermdl.LogError("GRPCHandler err:", res.GetError())
return res.GetData(), res.GetErrorCode(), res.GetError(), err
}
return res.GetData(), nil
loggermdl.LogError("response Data received", res)
return res.GetData(), res.GetErrorCode(), res.GetError(), nil
}
return []byte{}, errors.New("no grpc connection found")
return nil, 0, "", errors.New("no grpc connection found")
}
// CreateConnection method
func CreateConnection(serverURL string, grpcClientName string) {
var factory grpcpool.Factory
// serverURL := grpcServerURLList[index]
factory = func() (*grpc.ClientConn, error) {
conn, err := grpc.Dial(serverURL, grpc.WithInsecure())
if err != nil {
loggermdl.LogError("Failed to start gRPC connection: %v", err)
}
loggermdl.LogError("Connected to server")
return conn, err
}
pool, err := grpcpool.New(factory, 5, 5, time.Second)
if err != nil {
loggermdl.LogError("Failed to create gRPC pool: %v", err)
}
......
......@@ -19,31 +19,27 @@ import (
type Server struct{}
// GRPCInit init
func GRPCInit(GRPCPort net.Listener /* , serverStatus chan string */) {
loggermdl.LogInfo("GRPC init called")
func GRPCInit(GRPCPort net.Listener) {
loggermdl.LogInfo("In GRPCInit")
s := grpc.NewServer()
grpcbuildermdl.RegisterGRPCCheckServer(s, &Server{})
grpcbuildermdl.RegisterGRPCServiceServer(s, &Server{})
if err := s.Serve(GRPCPort); err != nil {
loggermdl.LogError("Unable to start GRPC server: %v", err)
}
}
//Employee ... Employee
type Employee struct {
Name string `json:"empname"`
Number int `json:"empid"`
loggermdl.LogError("GRPC server started on :", GRPCPort.Addr().String())
}
// GRPCHandler GRPCHandler
func (*Server) GRPCHandler(ctx context.Context, req *grpcbuildermdl.GRPCRequest) (*grpcbuildermdl.GRPCByteResponse, error) {
loggermdl.LogError("GRPC Handler inoked: ", req)
loggermdl.LogError("GRPC Handler inoked:")
principal := servicebuildermdl.Principal{}
errExecutingActivity := ""
if req.GetGrpcMessage().GetIsRestricted() {
claim, _ := jwtmdl.GeneratePricipleObjUsingToken(req.GetGrpcMessage().GetToken(), jwtmdl.GlobalJWTKey)
groups, grperr := roleenforcemdl.GetGroupNames(claim, "groups")
if errormdl.CheckErr(grperr) != nil {
loggermdl.LogError(grperr)
loggermdl.LogError("Error accessing group", grperr)
return nil, errormdl.CheckErr(grperr)
}
userID, ok := claim["userId"].(string)
......@@ -66,22 +62,27 @@ func (*Server) GRPCHandler(ctx context.Context, req *grpcbuildermdl.GRPCRequest)
principal.Token = req.GetGrpcMessage().GetToken()
}
loggermdl.LogError("<Request Message>", req)
loggermdl.LogError("Request Data send to activity", req)
result, nextDynamicPage, ab, isCompressed, errorCode, err := executeService(
req.GetGrpcMessage().GetName(),
req.GetGrpcMessage().GetData(), req.GetGrpcMessage().GetIsRestricted(),
req.GetGrpcMessage().GetIsRoleBased(), false, principal)
loggermdl.LogError("Response after execution of activity", result, nextDynamicPage, ab, isCompressed, errorCode, err)
e, _ := json.Marshal(result)
if err != nil {
errExecutingActivity = err.Error()
}
res := &grpcbuildermdl.GRPCByteResponse{
Data: e,
Data: e,
ErrorCode: int32(errorCode),
Error: errExecutingActivity,
}
loggermdl.LogError(result, string(e), nextDynamicPage, ab, isCompressed, errorCode, err)
return res, err
return res, nil
}
// GRPCCheck GRPCCheck
func (*Server) GRPCCheck(ctx context.Context, req *grpcbuildermdl.GRPCRequest) (*grpcbuildermdl.GRPCResponse, error) {
loggermdl.LogError("GRPC Check Invoked: ", req)
loggermdl.LogError("GRPC Check Invoked: ")
claim, _ := jwtmdl.GeneratePricipleObjUsingToken(req.GetGrpcMessage().GetToken(), jwtmdl.GlobalJWTKey)
principal := servicebuildermdl.Principal{}
groups, grperr := roleenforcemdl.GetGroupNames(claim, "groups")
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment