Exemple #1
0
def serve():
  parser = argparse.ArgumentParser()
  parser.add_argument(
      '--port', help='the port on which to serve', type=int)
  parser.add_argument(
      '--use_tls', help='require a secure connection',
      default=False, type=resources.parse_bool)
  args = parser.parse_args()

  server = test_pb2.beta_create_TestService_server(methods.TestService())
  if args.use_tls:
    private_key = resources.private_key()
    certificate_chain = resources.certificate_chain()
    credentials = implementations.ssl_server_credentials(
        [(private_key, certificate_chain)])
    server.add_secure_port('[::]:{}'.format(args.port), credentials)
  else:
    server.add_insecure_port('[::]:{}'.format(args.port))

  server.start()
  logging.info('Server serving.')
  try:
    while True:
      time.sleep(_ONE_DAY_IN_SECONDS)
  except BaseException as e:
    logging.info('Caught exception "%s"; stopping server...', e)
    server.stop(0)
    logging.info('Server stopped; exiting.')
Exemple #2
0
def serve(config):
    d_config = default_config()
    if config is not None:
        d_config.update(config)
    config = d_config

    server = message_pb2.beta_create_Communication_server(
        servicer.MessageServicer())
    if args.ssl:
        if config['private_key'] == '' or config['certificate_chain'] == '':
            raise RuntimeError(
                'To enable SSL private_key and certificate_chain must be set')
        creds = implementations.ssl_server_credentials([(
            utils.resource_string(config['private_key']),
            utils.resource_string(config['certificate_chain']))])
        port = server.add_secure_port('[::]:{0}'.format(config['port']), creds)
    else:
        port = server.add_insecure_port('[::]:{0}'.format(config['port']))
    logging.info('Listening on {0}'.format(port))
    server.start()
    try:
        while True:
            time.sleep(config['time_to_sleep'])
    except KeyboardInterrupt:
        server.stop(0)
  def setUp(self):
    self._servicer = _Servicer()
    self._method_implementations = {
        (_GROUP, _UNARY_UNARY):
            utilities.unary_unary_inline(self._servicer.unary_unary),
        (_GROUP, _UNARY_STREAM):
            utilities.unary_stream_inline(self._servicer.unary_stream),
        (_GROUP, _STREAM_UNARY):
            utilities.stream_unary_inline(self._servicer.stream_unary),
        (_GROUP, _STREAM_STREAM):
            utilities.stream_stream_inline(self._servicer.stream_stream),
    }

    self._cardinalities = {
        _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY,
        _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM,
        _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY,
        _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM,
    }

    self._server_options = implementations.server_options(
        thread_pool_size=test_constants.POOL_SIZE)
    self._server_credentials = implementations.ssl_server_credentials(
        [(resources.private_key(), resources.certificate_chain(),),])
    self._client_credentials = implementations.ssl_client_credentials(
        resources.test_root_certificates(), None, None)
    self._stub_options = implementations.stub_options(
        thread_pool_size=test_constants.POOL_SIZE)
Exemple #4
0
def serve():
    parser = argparse.ArgumentParser()
    parser.add_argument('--port', help='the port on which to serve', type=int)
    parser.add_argument('--use_tls',
                        help='require a secure connection',
                        default=False,
                        type=resources.parse_bool)
    args = parser.parse_args()

    server = test_pb2.beta_create_TestService_server(methods.TestService())
    if args.use_tls:
        private_key = resources.private_key()
        certificate_chain = resources.certificate_chain()
        credentials = implementations.ssl_server_credentials([
            (private_key, certificate_chain)
        ])
        server.add_secure_port('[::]:{}'.format(args.port), credentials)
    else:
        server.add_insecure_port('[::]:{}'.format(args.port))

    server.start()
    logging.info('Server serving.')
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except BaseException as e:
        logging.info('Caught exception "%s"; stopping server...', e)
        server.stop(0)
        logging.info('Server stopped; exiting.')
  def _create_server(self, config):
    if config.server_type == control_pb2.SYNC_SERVER:
      servicer = benchmark_server.BenchmarkServer()
      server = services_pb2.beta_create_BenchmarkService_server(servicer)
    elif config.server_type == control_pb2.ASYNC_GENERIC_SERVER:
      resp_size = config.payload_config.bytebuf_params.resp_size
      servicer = benchmark_server.GenericBenchmarkServer(resp_size)
      method_implementations = {
          ('grpc.testing.BenchmarkService', 'StreamingCall'):
          utilities.stream_stream_inline(servicer.StreamingCall),
          ('grpc.testing.BenchmarkService', 'UnaryCall'):
          utilities.unary_unary_inline(servicer.UnaryCall),
      }
      server = implementations.server(method_implementations)
    else:
      raise Exception('Unsupported server type {}'.format(config.server_type))

    if config.HasField('security_params'):  # Use SSL
      server_creds = implementations.ssl_server_credentials([(
          resources.private_key(), resources.certificate_chain())])
      port = server.add_secure_port('[::]:{}'.format(config.port), server_creds)
    else:
      port = server.add_insecure_port('[::]:{}'.format(config.port))

    return (server, port)
  def instantiate(
      self, methods, method_implementations, multi_method_implementation):
    serialization_behaviors = _serialization_behaviors_from_test_methods(
        methods)
    # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest.
    service = next(iter(methods))[0]
    # TODO(nathaniel): Add a "cardinalities_by_group" attribute to
    # _digest.TestServiceDigest.
    cardinalities = {
        method: method_object.cardinality()
        for (group, method), method_object in six.iteritems(methods)}

    server_options = implementations.server_options(
        request_deserializers=serialization_behaviors.request_deserializers,
        response_serializers=serialization_behaviors.response_serializers,
        thread_pool_size=test_constants.POOL_SIZE)
    server = implementations.server(
        method_implementations, options=server_options)
    server_credentials = implementations.ssl_server_credentials(
        [(resources.private_key(), resources.certificate_chain(),),])
    port = server.add_secure_port('[::]:0', server_credentials)
    server.start()
    channel_credentials = implementations.ssl_channel_credentials(
        resources.test_root_certificates())
    channel = test_utilities.not_really_secure_channel(
        'localhost', port, channel_credentials, _SERVER_HOST_OVERRIDE)
    stub_options = implementations.stub_options(
        request_serializers=serialization_behaviors.request_serializers,
        response_deserializers=serialization_behaviors.response_deserializers,
        thread_pool_size=test_constants.POOL_SIZE)
    generic_stub = implementations.generic_stub(channel, options=stub_options)
    dynamic_stub = implementations.dynamic_stub(
        channel, service, cardinalities, options=stub_options)
    return generic_stub, {service: dynamic_stub}, server
Exemple #7
0
    def setUp(self):
        self._servicer = _Servicer()
        self._method_implementations = {
            (_GROUP, _UNARY_UNARY):
            utilities.unary_unary_inline(self._servicer.unary_unary),
            (_GROUP, _UNARY_STREAM):
            utilities.unary_stream_inline(self._servicer.unary_stream),
            (_GROUP, _STREAM_UNARY):
            utilities.stream_unary_inline(self._servicer.stream_unary),
            (_GROUP, _STREAM_STREAM):
            utilities.stream_stream_inline(self._servicer.stream_stream),
        }

        self._cardinalities = {
            _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY,
            _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM,
            _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY,
            _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM,
        }

        self._server_options = implementations.server_options(
            thread_pool_size=test_constants.POOL_SIZE)
        self._server_credentials = implementations.ssl_server_credentials([
            (
                resources.private_key(),
                resources.certificate_chain(),
            ),
        ])
        self._channel_credentials = implementations.ssl_channel_credentials(
            resources.test_root_certificates())
        self._stub_options = implementations.stub_options(
            thread_pool_size=test_constants.POOL_SIZE)
  def instantiate(
      self, methods, method_implementations, multi_method_implementation):
    serialization_behaviors = _serialization_behaviors_from_test_methods(
        methods)
    # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest.
    service = next(iter(methods))[0]
    # TODO(nathaniel): Add a "cardinalities_by_group" attribute to
    # _digest.TestServiceDigest.
    cardinalities = {
        method: method_object.cardinality()
        for (group, method), method_object in methods.iteritems()}

    server_options = implementations.server_options(
        request_deserializers=serialization_behaviors.request_deserializers,
        response_serializers=serialization_behaviors.response_serializers,
        thread_pool_size=test_constants.POOL_SIZE)
    server = implementations.server(
        method_implementations, options=server_options)
    server_credentials = implementations.ssl_server_credentials(
        [(resources.private_key(), resources.certificate_chain(),),])
    port = server.add_secure_port('[::]:0', server_credentials)
    server.start()
    channel_credentials = implementations.ssl_channel_credentials(
        resources.test_root_certificates(), None, None)
    channel = test_utilities.not_really_secure_channel(
        'localhost', port, channel_credentials, _SERVER_HOST_OVERRIDE)
    stub_options = implementations.stub_options(
        request_serializers=serialization_behaviors.request_serializers,
        response_deserializers=serialization_behaviors.response_deserializers,
        thread_pool_size=test_constants.POOL_SIZE)
    generic_stub = implementations.generic_stub(channel, options=stub_options)
    dynamic_stub = implementations.dynamic_stub(
        channel, service, cardinalities, options=stub_options)
    return generic_stub, {service: dynamic_stub}, server
    def _create_server(self, config):
        if config.server_type == control_pb2.SYNC_SERVER:
            servicer = benchmark_server.BenchmarkServer()
            server = services_pb2.beta_create_BenchmarkService_server(servicer)
        elif config.server_type == control_pb2.ASYNC_GENERIC_SERVER:
            resp_size = config.payload_config.bytebuf_params.resp_size
            servicer = benchmark_server.GenericBenchmarkServer(resp_size)
            method_implementations = {
                ('grpc.testing.BenchmarkService', 'StreamingCall'):
                utilities.stream_stream_inline(servicer.StreamingCall),
                ('grpc.testing.BenchmarkService', 'UnaryCall'):
                utilities.unary_unary_inline(servicer.UnaryCall),
            }
            server = implementations.server(method_implementations)
        else:
            raise Exception('Unsupported server type {}'.format(
                config.server_type))

        if config.HasField('security_params'):  # Use SSL
            server_creds = implementations.ssl_server_credentials([
                (resources.private_key(), resources.certificate_chain())
            ])
            port = server.add_secure_port('[::]:{}'.format(config.port),
                                          server_creds)
        else:
            port = server.add_insecure_port('[::]:{}'.format(config.port))

        return (server, port)
Exemple #10
0
 def setUp(self):
   self.server = test_pb2.beta_create_TestService_server(methods.TestService())
   port = self.server.add_secure_port(
       '[::]:0', implementations.ssl_server_credentials(
           [(resources.private_key(), resources.certificate_chain())]))
   self.server.start()
   self.stub = test_pb2.beta_create_TestService_stub(
       test_utilities.not_really_secure_channel(
           '[::]', port, implementations.ssl_channel_credentials(
               resources.test_root_certificates()),
               _SERVER_HOST_OVERRIDE))
Exemple #11
0
 def setUp(self):
   self.server = test_pb2.beta_create_TestService_server(methods.TestService())
   port = self.server.add_secure_port(
       '[::]:0', implementations.ssl_server_credentials(
           [(resources.private_key(), resources.certificate_chain())]))
   self.server.start()
   self.stub = test_pb2.beta_create_TestService_stub(
       test_utilities.not_really_secure_channel(
           '[::]', port, implementations.ssl_client_credentials(
               resources.test_root_certificates(), None, None),
               _SERVER_HOST_OVERRIDE))
def serve():
  key_cert = [(open('../../../key.pem').read(), open('../../../cert.pem'
                                                     ).read())]
  creds = implementations.ssl_server_credentials(key_cert, None, False)
  server = crawl_pb2.beta_create_Crawl_server(Crawl())
  server.add_secure_port('[::]:8000', creds)
  server.start()
  try:
  	while True:
  	  time.sleep(_ONE_DAY_IN_SECONDS)
  except KeyboardInterrupt:
  	server.stop(0)
def serve():
  key_cert = [(open('../../../key.pem').read(),
              open('../../../cert.pem').read())]
  creds = implementations.ssl_server_credentials(key_cert, None,
                                                 False)
  server = search_pb2.beta_create_Google_server(GoogleServicer())
  server.add_secure_port('[::]:8000', creds)
  server.start()
  try:
    while True:
      time.sleep(86400)
  except KeyboardInterrupt:
    server.stop(0)
def serve():
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    helloworld_pb2.add_GreeterServicer_to_server(Greeter(), server)
    key_cert = [(open('/etc/nginx/server.key').read(),
                 open('/etc/nginx/server.crt').read())]
    creds = implementations.ssl_server_credentials(key_cert, None, False)
    server.add_insecure_port('[::]:50051')
    server.add_secure_port('[::]:50052', creds)
    server.start()
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        server.stop(0)
Exemple #15
0
    def setUp(self):
        self._servicer = _Servicer()
        method_implementations = {
            (_GROUP, _UNARY_UNARY):
            utilities.unary_unary_inline(self._servicer.unary_unary),
            (_GROUP, _UNARY_STREAM):
            utilities.unary_stream_inline(self._servicer.unary_stream),
            (_GROUP, _STREAM_UNARY):
            utilities.stream_unary_inline(self._servicer.stream_unary),
            (_GROUP, _STREAM_STREAM):
            utilities.stream_stream_inline(self._servicer.stream_stream),
        }

        cardinalities = {
            _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY,
            _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM,
            _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY,
            _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM,
        }

        server_options = implementations.server_options(
            thread_pool_size=test_constants.POOL_SIZE)
        self._server = implementations.server(method_implementations,
                                              options=server_options)
        server_credentials = implementations.ssl_server_credentials([
            (
                resources.private_key(),
                resources.certificate_chain(),
            ),
        ])
        port = self._server.add_secure_port('[::]:0', server_credentials)
        self._server.start()
        self._channel_credentials = implementations.ssl_channel_credentials(
            resources.test_root_certificates())
        self._call_credentials = implementations.metadata_call_credentials(
            _metadata_plugin)
        channel = test_utilities.not_really_secure_channel(
            'localhost', port, self._channel_credentials,
            _SERVER_HOST_OVERRIDE)
        stub_options = implementations.stub_options(
            thread_pool_size=test_constants.POOL_SIZE)
        self._dynamic_stub = implementations.dynamic_stub(channel,
                                                          _GROUP,
                                                          cardinalities,
                                                          options=stub_options)
    def setUp(self):
        self._servicer = _Servicer()
        method_implementations = {
            (_GROUP, _UNARY_UNARY):
            utilities.unary_unary_inline(self._servicer.unary_unary),
            (_GROUP, _UNARY_STREAM):
            utilities.unary_stream_inline(self._servicer.unary_stream),
            (_GROUP, _STREAM_UNARY):
            utilities.stream_unary_inline(self._servicer.stream_unary),
            (_GROUP, _STREAM_STREAM):
            utilities.stream_stream_inline(self._servicer.stream_stream),
        }

        cardinalities = {
            _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY,
            _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM,
            _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY,
            _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM,
        }

        server_options = implementations.server_options(
            thread_pool_size=test_constants.POOL_SIZE)
        self._server = implementations.server(
            method_implementations, options=server_options)
        server_credentials = implementations.ssl_server_credentials([
            (
                resources.private_key(),
                resources.certificate_chain(),
            ),
        ])
        port = self._server.add_secure_port('[::]:0', server_credentials)
        self._server.start()
        self._channel_credentials = implementations.ssl_channel_credentials(
            resources.test_root_certificates())
        self._call_credentials = implementations.metadata_call_credentials(
            _metadata_plugin)
        channel = test_utilities.not_really_secure_channel(
            'localhost', port, self._channel_credentials, _SERVER_HOST_OVERRIDE)
        stub_options = implementations.stub_options(
            thread_pool_size=test_constants.POOL_SIZE)
        self._dynamic_stub = implementations.dynamic_stub(
            channel, _GROUP, cardinalities, options=stub_options)
Exemple #17
0
    def SayHello(self, request, context):
        meta = dict(context.invocation_metadata())
        print 'Got RPC with message:  \n' + str(request)
        return echo_pb2.EchoReply(message='Hello, %s %s!' %
                                  (request.firstname, request.lastname))

    def SayHelloStream(self, request, context):
        meta = dict(context.invocation_metadata())
        print 'Got RPC with message for Streaming :  \n' + str(request)
        yield echo_pb2.EchoReply(message='Streaming Hello 1, %s %s!' %
                                 (request.firstname, request.lastname))
        yield echo_pb2.EchoReply(message='Streaming Hello 2, %s %s!' %
                                 (request.firstname, request.lastname))
        return


keypairs = [(open('server_key.pem').read(), open('server_crt.pem').read())]
sc = implementations.ssl_server_credentials(keypairs,
                                            open('CA_crt.pem').read(), False)
server = echo_pb2.beta_create_EchoServer_server(Greeter())

#server.add_insecure_port('[::]:50051')
server.add_secure_port('[::]:50051', server_credentials=sc)
server.start()
try:
    print 'Started gRPC server on port 50051'
    while True:
        time.sleep(_ONE_HOUR_IN_SECONDS)
except KeyboardInterrupt:
    server.stop()