From 4de4e8a350d9ae8c884968d117be85db06fd1988 Mon Sep 17 00:00:00 2001 From: Jason Chua <91486739+jchua99@users.noreply.github.com> Date: Mon, 4 Mar 2024 10:09:07 +0800 Subject: [PATCH] fix spright-parking protos Signed-off-by: lrq619 --- grpcclient/getclient.go | 7 + grpcclient/parking_client.go | 55 ++++++++ proto/parking/parking.pb.go | 214 ++++++++++++++++++++++++++++++ proto/parking/parking.proto | 17 +++ proto/parking/parking_grpc.pb.go | 109 +++++++++++++++ proto/parking/parking_pb2.py | 31 +++++ proto/parking/parking_pb2_grpc.py | 66 +++++++++ 7 files changed, 499 insertions(+) create mode 100644 grpcclient/parking_client.go create mode 100644 proto/parking/parking.pb.go create mode 100644 proto/parking/parking.proto create mode 100644 proto/parking/parking_grpc.pb.go create mode 100644 proto/parking/parking_pb2.py create mode 100644 proto/parking/parking_pb2_grpc.py diff --git a/grpcclient/getclient.go b/grpcclient/getclient.go index 48c026c..088dcdf 100644 --- a/grpcclient/getclient.go +++ b/grpcclient/getclient.go @@ -14,6 +14,8 @@ func FindServiceName(functionName string) string { return "fibonacci" case "gptj-python": return "gptj" + case "spright-parking-python": + return "spright-parking" default: return functionName } @@ -91,6 +93,11 @@ func FindGrpcClient(service_name string) GrpcClient { log.Debug("Found Shipping client for online shop") return new(ShopShippingServiceClient) + // Spright parking --- + case "spright": + log.Debug("Found Spright client for spright parking") + return new(ParkingClient) + // Default --------- default: log.Warnf("Did not find a matching client for %s... Will use the default Hello world client. \n", service_name) diff --git a/grpcclient/parking_client.go b/grpcclient/parking_client.go new file mode 100644 index 0000000..1be2b24 --- /dev/null +++ b/grpcclient/parking_client.go @@ -0,0 +1,55 @@ +package grpcclient + +import ( + "context" + "log" + + pb "github.com/vhive-serverless/vSwarm-proto/proto/parking" +) + +type ParkingGenerator struct { + GeneratorBase +} + +func (g *ParkingGenerator) Next() Input { + var pkt = g.defaultInput + switch g.GeneratorBase.generator { + case Unique: + pkt.Value = "A unique message" + case Linear: + // g.count = g.count + 1 + // pkt.Value = fmt.Sprintf("%d", g.count) + pkt.Value = "A linear message" + case Random: + pkt.Value = "Let's do spright parking" + } + return pkt +} + +func (c *ParkingClient) GetGenerator() Generator { + return new(ParkingGenerator) +} + +type ParkingClient struct { + ClientBase + client pb.ParkingClient +} + +func (c *ParkingClient) Init(ctx context.Context, ip, port string) error { + log.Printf("Connect to: %s:%s\n", ip, port) + err := c.Connect(ctx, ip, port) + if err != nil { + return err + } + c.client = pb.NewParkingClient(c.conn) + return nil +} + +func (c *ParkingClient) Request(ctx context.Context, req Input) (string, error) { + + r, err := c.client.DoParking(ctx, &pb.ParkingRequest{Name: req.Value}) + if err != nil { + return "", err + } + return r.GetResult(), nil +} diff --git a/proto/parking/parking.pb.go b/proto/parking/parking.pb.go new file mode 100644 index 0000000..17ad268 --- /dev/null +++ b/proto/parking/parking.pb.go @@ -0,0 +1,214 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.1 +// protoc v3.6.1 +// source: proto/parking/parking.proto + +package parking + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ParkingRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *ParkingRequest) Reset() { + *x = ParkingRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_parking_parking_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ParkingRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ParkingRequest) ProtoMessage() {} + +func (x *ParkingRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_parking_parking_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ParkingRequest.ProtoReflect.Descriptor instead. +func (*ParkingRequest) Descriptor() ([]byte, []int) { + return file_proto_parking_parking_proto_rawDescGZIP(), []int{0} +} + +func (x *ParkingRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +type ParkingReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Result string `protobuf:"bytes,1,opt,name=result,proto3" json:"result,omitempty"` +} + +func (x *ParkingReply) Reset() { + *x = ParkingReply{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_parking_parking_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ParkingReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ParkingReply) ProtoMessage() {} + +func (x *ParkingReply) ProtoReflect() protoreflect.Message { + mi := &file_proto_parking_parking_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ParkingReply.ProtoReflect.Descriptor instead. +func (*ParkingReply) Descriptor() ([]byte, []int) { + return file_proto_parking_parking_proto_rawDescGZIP(), []int{1} +} + +func (x *ParkingReply) GetResult() string { + if x != nil { + return x.Result + } + return "" +} + +var File_proto_parking_parking_proto protoreflect.FileDescriptor + +var file_proto_parking_parking_proto_rawDesc = []byte{ + 0x0a, 0x1b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x61, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x2f, + 0x70, 0x61, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x70, + 0x61, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x22, 0x24, 0x0a, 0x0e, 0x50, 0x61, 0x72, 0x6b, 0x69, 0x6e, + 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x26, 0x0a, 0x0c, + 0x50, 0x61, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x16, 0x0a, 0x06, + 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x32, 0x48, 0x0a, 0x07, 0x50, 0x61, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x12, + 0x3d, 0x0a, 0x09, 0x44, 0x6f, 0x50, 0x61, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x12, 0x17, 0x2e, 0x70, + 0x61, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x50, 0x61, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x70, 0x61, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x50, 0x61, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x38, + 0x5a, 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, 0x68, 0x69, + 0x76, 0x65, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x6c, 0x65, 0x73, 0x73, 0x2f, 0x76, 0x53, + 0x77, 0x61, 0x72, 0x6d, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2f, 0x70, 0x61, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_proto_parking_parking_proto_rawDescOnce sync.Once + file_proto_parking_parking_proto_rawDescData = file_proto_parking_parking_proto_rawDesc +) + +func file_proto_parking_parking_proto_rawDescGZIP() []byte { + file_proto_parking_parking_proto_rawDescOnce.Do(func() { + file_proto_parking_parking_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_parking_parking_proto_rawDescData) + }) + return file_proto_parking_parking_proto_rawDescData +} + +var file_proto_parking_parking_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_proto_parking_parking_proto_goTypes = []interface{}{ + (*ParkingRequest)(nil), // 0: parking.ParkingRequest + (*ParkingReply)(nil), // 1: parking.ParkingReply +} +var file_proto_parking_parking_proto_depIdxs = []int32{ + 0, // 0: parking.Parking.DoParking:input_type -> parking.ParkingRequest + 1, // 1: parking.Parking.DoParking:output_type -> parking.ParkingReply + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_proto_parking_parking_proto_init() } +func file_proto_parking_parking_proto_init() { + if File_proto_parking_parking_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_parking_parking_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ParkingRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_parking_parking_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ParkingReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_proto_parking_parking_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_proto_parking_parking_proto_goTypes, + DependencyIndexes: file_proto_parking_parking_proto_depIdxs, + MessageInfos: file_proto_parking_parking_proto_msgTypes, + }.Build() + File_proto_parking_parking_proto = out.File + file_proto_parking_parking_proto_rawDesc = nil + file_proto_parking_parking_proto_goTypes = nil + file_proto_parking_parking_proto_depIdxs = nil +} diff --git a/proto/parking/parking.proto b/proto/parking/parking.proto new file mode 100644 index 0000000..a1c2edf --- /dev/null +++ b/proto/parking/parking.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +option go_package = "github.com/vhive-serverless/vSwarm-proto/proto/parking"; + +package parking; + +service Parking { + rpc DoParking(ParkingRequest) returns (ParkingReply) {} +} + +message ParkingRequest { + string name = 1; +} + +message ParkingReply { + string result = 1; +} diff --git a/proto/parking/parking_grpc.pb.go b/proto/parking/parking_grpc.pb.go new file mode 100644 index 0000000..b2901b8 --- /dev/null +++ b/proto/parking/parking_grpc.pb.go @@ -0,0 +1,109 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v3.6.1 +// source: proto/parking/parking.proto + +package parking + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + Parking_DoParking_FullMethodName = "/parking.Parking/DoParking" +) + +// ParkingClient is the client API for Parking service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ParkingClient interface { + DoParking(ctx context.Context, in *ParkingRequest, opts ...grpc.CallOption) (*ParkingReply, error) +} + +type parkingClient struct { + cc grpc.ClientConnInterface +} + +func NewParkingClient(cc grpc.ClientConnInterface) ParkingClient { + return &parkingClient{cc} +} + +func (c *parkingClient) DoParking(ctx context.Context, in *ParkingRequest, opts ...grpc.CallOption) (*ParkingReply, error) { + out := new(ParkingReply) + err := c.cc.Invoke(ctx, Parking_DoParking_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ParkingServer is the server API for Parking service. +// All implementations must embed UnimplementedParkingServer +// for forward compatibility +type ParkingServer interface { + DoParking(context.Context, *ParkingRequest) (*ParkingReply, error) + mustEmbedUnimplementedParkingServer() +} + +// UnimplementedParkingServer must be embedded to have forward compatible implementations. +type UnimplementedParkingServer struct { +} + +func (UnimplementedParkingServer) DoParking(context.Context, *ParkingRequest) (*ParkingReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method DoParking not implemented") +} +func (UnimplementedParkingServer) mustEmbedUnimplementedParkingServer() {} + +// UnsafeParkingServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ParkingServer will +// result in compilation errors. +type UnsafeParkingServer interface { + mustEmbedUnimplementedParkingServer() +} + +func RegisterParkingServer(s grpc.ServiceRegistrar, srv ParkingServer) { + s.RegisterService(&Parking_ServiceDesc, srv) +} + +func _Parking_DoParking_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ParkingRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ParkingServer).DoParking(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Parking_DoParking_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ParkingServer).DoParking(ctx, req.(*ParkingRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Parking_ServiceDesc is the grpc.ServiceDesc for Parking service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Parking_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "parking.Parking", + HandlerType: (*ParkingServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "DoParking", + Handler: _Parking_DoParking_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "proto/parking/parking.proto", +} diff --git a/proto/parking/parking_pb2.py b/proto/parking/parking_pb2.py new file mode 100644 index 0000000..5705f74 --- /dev/null +++ b/proto/parking/parking_pb2.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: proto/parking/parking.proto +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bproto/parking/parking.proto\x12\x07parking\"\x1e\n\x0eParkingRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1e\n\x0cParkingReply\x12\x0e\n\x06result\x18\x01 \x01(\t2H\n\x07Parking\x12=\n\tDoParking\x12\x17.parking.ParkingRequest\x1a\x15.parking.ParkingReply\"\x00\x42\x38Z6github.com/vhive-serverless/vSwarm-proto/proto/parkingb\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'proto.parking.parking_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = b'Z6github.com/vhive-serverless/vSwarm-proto/proto/parking' + _globals['_PARKINGREQUEST']._serialized_start=40 + _globals['_PARKINGREQUEST']._serialized_end=70 + _globals['_PARKINGREPLY']._serialized_start=72 + _globals['_PARKINGREPLY']._serialized_end=102 + _globals['_PARKING']._serialized_start=104 + _globals['_PARKING']._serialized_end=176 +# @@protoc_insertion_point(module_scope) diff --git a/proto/parking/parking_pb2_grpc.py b/proto/parking/parking_pb2_grpc.py new file mode 100644 index 0000000..7a41f08 --- /dev/null +++ b/proto/parking/parking_pb2_grpc.py @@ -0,0 +1,66 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + +from proto.parking import parking_pb2 as proto_dot_parking_dot_parking__pb2 + + +class ParkingStub(object): + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.DoParking = channel.unary_unary( + '/parking.Parking/DoParking', + request_serializer=proto_dot_parking_dot_parking__pb2.ParkingRequest.SerializeToString, + response_deserializer=proto_dot_parking_dot_parking__pb2.ParkingReply.FromString, + ) + + +class ParkingServicer(object): + """Missing associated documentation comment in .proto file.""" + + def DoParking(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_ParkingServicer_to_server(servicer, server): + rpc_method_handlers = { + 'DoParking': grpc.unary_unary_rpc_method_handler( + servicer.DoParking, + request_deserializer=proto_dot_parking_dot_parking__pb2.ParkingRequest.FromString, + response_serializer=proto_dot_parking_dot_parking__pb2.ParkingReply.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'parking.Parking', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + + + # This class is part of an EXPERIMENTAL API. +class Parking(object): + """Missing associated documentation comment in .proto file.""" + + @staticmethod + def DoParking(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/parking.Parking/DoParking', + proto_dot_parking_dot_parking__pb2.ParkingRequest.SerializeToString, + proto_dot_parking_dot_parking__pb2.ParkingReply.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata)