From 5d1aedd2e44513c346f786643e3cc0c8cbb9fe78 Mon Sep 17 00:00:00 2001 From: Christophe Taton Date: Wed, 1 Nov 2017 15:51:25 -0700 Subject: [PATCH] Update protoc commands to match documentation. - Use long flags for better readability. - Change API descriptor file from `out.pb` to `api_descriptor.pb`. - Use same protoc command everywhere for consistency and simplicity. --- endpoints/bookstore-grpc/README.md | 10 +- endpoints/getting-started-grpc/README.md | 29 +-- .../container-engine.yaml | 8 +- .../getting-started-grpc/helloworld_pb2.py | 182 +++--------------- .../helloworld_pb2_grpc.py | 2 - .../getting-started/container-engine.yaml | 8 +- endpoints/kubernetes/grpc-bookstore.yaml | 8 +- 7 files changed, 67 insertions(+), 180 deletions(-) diff --git a/endpoints/bookstore-grpc/README.md b/endpoints/bookstore-grpc/README.md index 0e3009af3a8..2f413a2a9ee 100644 --- a/endpoints/bookstore-grpc/README.md +++ b/endpoints/bookstore-grpc/README.md @@ -46,8 +46,14 @@ code in the sample distribution. To modify the sample or create your own gRPC API definition, you'll need to update the generated code. To do this, once the gRPC libraries and tools are installed, run: - python -m grpc.tools.protoc --python_out=generated_pb2 \ - --grpc_python_out=generated_pb2 --proto_path=. bookstore.proto + python -m grpc.tools.protoc \ + --include_imports \ + --include_source_info \ + --proto_path=. \ + --python_out=generated_pb2 \ + --grpc_python_out=generated_pb2 \ + --descriptor_set_out=api_descriptor.pb \ + bookstore.proto ## Running the server with gRPC <-> HTTP/JSON Transcoding diff --git a/endpoints/getting-started-grpc/README.md b/endpoints/getting-started-grpc/README.md index ee1fae8e3d2..eca0b476725 100644 --- a/endpoints/getting-started-grpc/README.md +++ b/endpoints/getting-started-grpc/README.md @@ -28,13 +28,14 @@ Cloud account and [SDK](https://cloud.google.com/sdk/) configured. just wish to regenerate these files, run: ```bash - python -m grpc_tools.protoc -I protos --python_out=. --grpc_python_out=. protos/helloworld.proto - ``` - -1. Generate the `out.pb` from the proto file: - - ```bash - python -m grpc_tools.protoc --include_imports --include_source_info -I protos protos/helloworld.proto --descriptor_set_out out.pb + python -m grpc.tools.protoc \ + --include_imports \ + --include_source_info \ + --proto_path=protos \ + --python_out=. \ + --grpc_python_out=. \ + --descriptor_set_out=api_descriptor.pb \ + helloworld.proto ``` 1. Edit, `api_config.yaml`. Replace `MY_PROJECT_ID` with your project id. @@ -42,7 +43,7 @@ Cloud account and [SDK](https://cloud.google.com/sdk/) configured. 1. Deploy your service config to Service Management: ```bash - gcloud endpoints services deploy out.pb api_config.yaml + gcloud endpoints services deploy api_descriptor.pb api_config.yaml # The Config ID should be printed out, looks like: 2017-02-01r0, remember this # Set your project ID as a variable to make commands easier: @@ -97,20 +98,20 @@ Cloud account and [SDK](https://cloud.google.com/sdk/) configured. ```bash /usr/share/google/dockercfg_update.sh - docker run -d --name=grpc-hello gcr.io/${GCLOUD_PROJECT}/python-grpc-hello:1.0 + docker run --detach --name=grpc-hello gcr.io/${GCLOUD_PROJECT}/python-grpc-hello:1.0 ``` 1. Run the Endpoints proxy: ```bash docker run --detach --name=esp \ - -p 80:9000 \ + --publish=80:9000 \ --link=grpc-hello:grpc-hello \ gcr.io/endpoints-release/endpoints-runtime:1 \ - -s ${SERVICE_NAME} \ - -v ${SERVICE_CONFIG_ID} \ - -P 9000 \ - -a grpc://grpc-hello:50051 + --service=${SERVICE_NAME} \ + --version=${SERVICE_CONFIG_ID} \ + --http2_port=9000 \ + --backend=grpc://grpc-hello:50051 ``` 1. Back on your local machine, get the external IP of your GCE instance: diff --git a/endpoints/getting-started-grpc/container-engine.yaml b/endpoints/getting-started-grpc/container-engine.yaml index 20c0d7eb7f7..a778302343a 100644 --- a/endpoints/getting-started-grpc/container-engine.yaml +++ b/endpoints/getting-started-grpc/container-engine.yaml @@ -41,10 +41,10 @@ spec: - name: esp image: gcr.io/endpoints-release/endpoints-runtime:1 args: [ - "-P", "9000", - "-a", "grpc://127.0.0.1:50051", - "-s", "SERVICE_NAME", - "-v", "SERVICE_CONFIG_ID", + "--http2_port=9000", + "--backend=grpc://127.0.0.1:50051", + "--service=SERVICE_NAME", + "--version=SERVICE_CONFIG_ID", ] ports: - containerPort: 9000 diff --git a/endpoints/getting-started-grpc/helloworld_pb2.py b/endpoints/getting-started-grpc/helloworld_pb2.py index 9a133df46e8..4d22db1f756 100644 --- a/endpoints/getting-started-grpc/helloworld_pb2.py +++ b/endpoints/getting-started-grpc/helloworld_pb2.py @@ -21,7 +21,6 @@ syntax='proto3', serialized_pb=_b('\n\x10helloworld.proto\x12\nhelloworld\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t2\x8e\x01\n\x07Greeter\x12>\n\x08SayHello\x12\x18.helloworld.HelloRequest\x1a\x16.helloworld.HelloReply\"\x00\x12\x43\n\rSayHelloAgain\x12\x18.helloworld.HelloRequest\x1a\x16.helloworld.HelloReply\"\x00\x62\x06proto3') ) -_sym_db.RegisterFileDescriptor(DESCRIPTOR) @@ -89,6 +88,7 @@ DESCRIPTOR.message_types_by_name['HelloRequest'] = _HELLOREQUEST DESCRIPTOR.message_types_by_name['HelloReply'] = _HELLOREPLY +_sym_db.RegisterFileDescriptor(DESCRIPTOR) HelloRequest = _reflection.GeneratedProtocolMessageType('HelloRequest', (_message.Message,), dict( DESCRIPTOR = _HELLOREQUEST, @@ -105,155 +105,37 @@ _sym_db.RegisterMessage(HelloReply) -try: - # THESE ELEMENTS WILL BE DEPRECATED. - # Please use the generated *_pb2_grpc.py files instead. - import grpc - from grpc.framework.common import cardinality - from grpc.framework.interfaces.face import utilities as face_utilities - from grpc.beta import implementations as beta_implementations - from grpc.beta import interfaces as beta_interfaces - - - class GreeterStub(object): - """The greeting service definition. - """ - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.SayHello = channel.unary_unary( - '/helloworld.Greeter/SayHello', - request_serializer=HelloRequest.SerializeToString, - response_deserializer=HelloReply.FromString, - ) - self.SayHelloAgain = channel.unary_unary( - '/helloworld.Greeter/SayHelloAgain', - request_serializer=HelloRequest.SerializeToString, - response_deserializer=HelloReply.FromString, - ) - - - class GreeterServicer(object): - """The greeting service definition. - """ - - def SayHello(self, request, context): - """Sends a greeting - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def SayHelloAgain(self, request, context): - """Sends another greeting - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - - def add_GreeterServicer_to_server(servicer, server): - rpc_method_handlers = { - 'SayHello': grpc.unary_unary_rpc_method_handler( - servicer.SayHello, - request_deserializer=HelloRequest.FromString, - response_serializer=HelloReply.SerializeToString, - ), - 'SayHelloAgain': grpc.unary_unary_rpc_method_handler( - servicer.SayHelloAgain, - request_deserializer=HelloRequest.FromString, - response_serializer=HelloReply.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'helloworld.Greeter', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) +_GREETER = _descriptor.ServiceDescriptor( + name='Greeter', + full_name='helloworld.Greeter', + file=DESCRIPTOR, + index=0, + options=None, + serialized_start=94, + serialized_end=236, + methods=[ + _descriptor.MethodDescriptor( + name='SayHello', + full_name='helloworld.Greeter.SayHello', + index=0, + containing_service=None, + input_type=_HELLOREQUEST, + output_type=_HELLOREPLY, + options=None, + ), + _descriptor.MethodDescriptor( + name='SayHelloAgain', + full_name='helloworld.Greeter.SayHelloAgain', + index=1, + containing_service=None, + input_type=_HELLOREQUEST, + output_type=_HELLOREPLY, + options=None, + ), +]) +_sym_db.RegisterServiceDescriptor(_GREETER) + +DESCRIPTOR.services_by_name['Greeter'] = _GREETER - class BetaGreeterServicer(object): - """The Beta API is deprecated for 0.15.0 and later. - - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This class was generated - only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.""" - """The greeting service definition. - """ - def SayHello(self, request, context): - """Sends a greeting - """ - context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) - def SayHelloAgain(self, request, context): - """Sends another greeting - """ - context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) - - - class BetaGreeterStub(object): - """The Beta API is deprecated for 0.15.0 and later. - - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This class was generated - only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.""" - """The greeting service definition. - """ - def SayHello(self, request, timeout, metadata=None, with_call=False, protocol_options=None): - """Sends a greeting - """ - raise NotImplementedError() - SayHello.future = None - def SayHelloAgain(self, request, timeout, metadata=None, with_call=False, protocol_options=None): - """Sends another greeting - """ - raise NotImplementedError() - SayHelloAgain.future = None - - - def beta_create_Greeter_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None): - """The Beta API is deprecated for 0.15.0 and later. - - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This function was - generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" - request_deserializers = { - ('helloworld.Greeter', 'SayHello'): HelloRequest.FromString, - ('helloworld.Greeter', 'SayHelloAgain'): HelloRequest.FromString, - } - response_serializers = { - ('helloworld.Greeter', 'SayHello'): HelloReply.SerializeToString, - ('helloworld.Greeter', 'SayHelloAgain'): HelloReply.SerializeToString, - } - method_implementations = { - ('helloworld.Greeter', 'SayHello'): face_utilities.unary_unary_inline(servicer.SayHello), - ('helloworld.Greeter', 'SayHelloAgain'): face_utilities.unary_unary_inline(servicer.SayHelloAgain), - } - server_options = beta_implementations.server_options(request_deserializers=request_deserializers, response_serializers=response_serializers, thread_pool=pool, thread_pool_size=pool_size, default_timeout=default_timeout, maximum_timeout=maximum_timeout) - return beta_implementations.server(method_implementations, options=server_options) - - - def beta_create_Greeter_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None): - """The Beta API is deprecated for 0.15.0 and later. - - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This function was - generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" - request_serializers = { - ('helloworld.Greeter', 'SayHello'): HelloRequest.SerializeToString, - ('helloworld.Greeter', 'SayHelloAgain'): HelloRequest.SerializeToString, - } - response_deserializers = { - ('helloworld.Greeter', 'SayHello'): HelloReply.FromString, - ('helloworld.Greeter', 'SayHelloAgain'): HelloReply.FromString, - } - cardinalities = { - 'SayHello': cardinality.Cardinality.UNARY_UNARY, - 'SayHelloAgain': cardinality.Cardinality.UNARY_UNARY, - } - stub_options = beta_implementations.stub_options(host=host, metadata_transformer=metadata_transformer, request_serializers=request_serializers, response_deserializers=response_deserializers, thread_pool=pool, thread_pool_size=pool_size) - return beta_implementations.dynamic_stub(channel, 'helloworld.Greeter', cardinalities, options=stub_options) -except ImportError: - pass # @@protoc_insertion_point(module_scope) diff --git a/endpoints/getting-started-grpc/helloworld_pb2_grpc.py b/endpoints/getting-started-grpc/helloworld_pb2_grpc.py index 58ab0c27dae..d4375701a33 100644 --- a/endpoints/getting-started-grpc/helloworld_pb2_grpc.py +++ b/endpoints/getting-started-grpc/helloworld_pb2_grpc.py @@ -1,7 +1,5 @@ # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! import grpc -from grpc.framework.common import cardinality -from grpc.framework.interfaces.face import utilities as face_utilities import helloworld_pb2 as helloworld__pb2 diff --git a/endpoints/getting-started/container-engine.yaml b/endpoints/getting-started/container-engine.yaml index 781623adb8e..8f40dfe25eb 100644 --- a/endpoints/getting-started/container-engine.yaml +++ b/endpoints/getting-started/container-engine.yaml @@ -42,10 +42,10 @@ spec: - name: esp image: gcr.io/endpoints-release/endpoints-runtime:1 args: [ - "-p", "8081", - "-a", "127.0.0.1:8080", - "-s", "SERVICE_NAME", - "-v", "SERVICE_CONFIG_ID", + "--http_port=8081", + "--backend=127.0.0.1:8080", + "--service=SERVICE_NAME", + "--version=SERVICE_CONFIG_ID", ] # [END esp] ports: diff --git a/endpoints/kubernetes/grpc-bookstore.yaml b/endpoints/kubernetes/grpc-bookstore.yaml index d8d73d4ff02..04b71346587 100644 --- a/endpoints/kubernetes/grpc-bookstore.yaml +++ b/endpoints/kubernetes/grpc-bookstore.yaml @@ -42,10 +42,10 @@ spec: - name: esp image: gcr.io/endpoints-release/endpoints-runtime:1 args: [ - "-P", "9000", - "-s", "SERVICE_NAME", - "-v", "SERVICE_CONFIG_ID", - "-a", "grpc://127.0.0.1:8000" + "--http2_port=9000", + "--service=SERVICE_NAME", + "--version=SERVICE_CONFIG_ID", + "--backend=grpc://127.0.0.1:8000" ] ports: - containerPort: 9000