class UnixClientServer:
    temp = None
    sock = None
    server = None
    channel = None

    async def __aenter__(self):
        self.temp = tempfile.mkdtemp()
        self.sock = os.path.join(self.temp, 'grpclib.sock')

        dummy_service = DummyService()

        self.server = Server([dummy_service])
        await self.server.start(path=self.sock)

        self.channel = Channel(path=self.sock)
        dummy_stub = DummyServiceStub(self.channel)
        return dummy_service, dummy_stub

    async def __aexit__(self, *exc_info):
        self.server.close()
        await self.server.wait_closed()
        self.channel.close()
        if os.path.exists(self.sock):
            os.unlink(self.sock)
        if os.path.exists(self.temp):
            os.rmdir(self.temp)
Esempio n. 2
0
class ClientServer:
    server = None
    channel = None

    def __init__(self, *, loop):
        self.loop = loop

    async def __aenter__(self):
        host = '127.0.0.1'
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.bind(('127.0.0.1', 0))
            _, port = s.getsockname()

        dummy_service = DummyService()

        self.server = Server([dummy_service], loop=self.loop)
        await self.server.start(host, port)

        self.channel = Channel(host=host, port=port, loop=self.loop)
        dummy_stub = DummyServiceStub(self.channel)
        return dummy_service, dummy_stub

    async def __aexit__(self, *exc_info):
        self.server.close()
        await self.server.wait_closed()
        self.channel.close()
Esempio n. 3
0
def serve():
    print("grpcs-hello:", GRPC_LISTEN_ADDR)
    loop = asyncio.get_event_loop()
    server = Server([Hello()], loop=loop)
    loop.run_until_complete(
        server.start(
            GRPC_LISTEN_ADDR.split(":")[0],
            int(GRPC_LISTEN_ADDR.split(":")[1])))
    async def __aenter__(self):
        self.temp = tempfile.mkdtemp()
        self.sock = os.path.join(self.temp, 'grpclib.sock')

        dummy_service = DummyService()

        self.server = Server([dummy_service])
        await self.server.start(path=self.sock)

        self.channel = Channel(path=self.sock)
        dummy_stub = DummyServiceStub(self.channel)
        return dummy_service, dummy_stub
Esempio n. 5
0
    def configure(self, value: grpc_pb2.Server):
        assert isinstance(value, grpc_pb2.Server), type(value)
        self._config = value

        handlers = list(self.handlers)
        if not any(isinstance(h, Health) for h in handlers):
            handlers.append(Health())
        handlers = ServerReflection.extend(handlers)

        self.server = Server(handlers)
        listen(self.server, RecvRequest, _recv_request)
        listen(self.server, SendTrailingMetadata, _send_trailing_metadata)
Esempio n. 6
0
    async def __aenter__(self):
        host = '127.0.0.1'
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.bind(('127.0.0.1', 0))
            _, port = s.getsockname()

        bombed = Bombed()

        self.server = Server([bombed], loop=self.loop)
        await self.server.start(host, port)

        channel = Channel(host=host, port=port, loop=self.loop)
        stub = BombedStub(channel)
        return bombed, stub
    async def __aenter__(self):
        host = '127.0.0.1'
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.bind(('127.0.0.1', 0))
            _, port = s.getsockname()

        dummy_service = DummyService()

        self.server = Server([dummy_service])
        await self.server.start(host, port)

        self.channel = Channel(host=host, port=port)
        dummy_stub = DummyServiceStub(self.channel)
        return dummy_service, dummy_stub
async def start_server() -> NoReturn:
    HOST = "127.0.0.1"
    PORT = 50051
    server = Server([RecommendationService()])

    await server.start(HOST, PORT)
    await server.wait_closed()
Esempio n. 9
0
async def main(*, host: str = '127.0.0.1', port: int = 50051) -> None:
    server = Server([Greeter()])
    listen(server, RecvRequest, on_recv_request)
    with graceful_exit([server]):
        await server.start(host, port)
        print(f'Serving on {host}:{port}')
        await server.wait_closed()
Esempio n. 10
0
async def main(*, host: str = '127.0.0.1', port: int = 50051) -> None:
    server = Server([Greeter()])
    # Note: graceful_exit isn't supported in Windows
    with graceful_exit([server]):
        await server.start(host, port)
        print(f'Serving on {host}:{port}')
        await server.wait_closed()
Esempio n. 11
0
async def main(*, host='0.0.0.0', port=50051):
    # only one possible neo4j db at a time, will need to share for prod and test
    config.DATABASE_URL = f"bolt://*****:*****@graph-neo4j:7687"

    # USE THIS FOR INTEGRATION TEST
    #config.DATABASE_URL = f"bolt://*****:*****@graph:7687"

    if os.getenv("PROD") is None:
        db_name = "kic-friends-test"
        users_service_url = "test.api.keeping-it-casual.com"
        logging.basicConfig(
            level=logging.DEBUG,
            format='%(asctime)s %(name)s %(lineno)d %(levelname)s:%(message)s')
    else:
        db_name = "kic-friends-prod"
        users_service_url = "api.keeping-it-casual.com"
        logging.basicConfig(
            level=logging.INFO,
            format='%(asctime)s %(name)s %(lineno)d %(levelname)s:%(message)s')
    logger = logging.getLogger(__name__)
    db = MongoRepository(db_name)
    rep = Neo4jRepository()

    logger.info("Starting server")
    friends_service = FriendsService(db, rep, users_service_url)
    server = Server([friends_service])
    await server.start(host, port)
    await server.wait_closed()
Esempio n. 12
0
async def main(*, host: str = '127.0.0.1', port: int = 50051) -> None:
    with ProcessPoolExecutor(max_workers=4) as executor:
        server = Server([Primes(executor)])
        with graceful_exit([server]):
            await server.start(host, port)
            print(f'Serving on {host}:{port}')
            await server.wait_closed()
Esempio n. 13
0
async def start_server() -> NoReturn:
    HOST = "127.0.0.1"
    PORT = 50052
    server = Server([GreenService()])

    await server.start(HOST, PORT)
    await server.wait_closed()
Esempio n. 14
0
async def main():
  server = Server([LEDService()])

  with graceful_exit([server]):
    await server.start(sys.argv[1], "5001")
    print(f"Server running on {sys.argv[1]}")
    await server.wait_closed()
Esempio n. 15
0
    async def start():
        server = Server(handlers)

        with graceful_exit([server]):
            await server.start(host, port)
            print(f"Serving on {host}:{port}")
            await server.wait_closed()
Esempio n. 16
0
async def main(*, host='127.0.0.1', port=50051):
    loop = asyncio.get_running_loop()
    server = Server([Greeter()], loop=loop)
    with graceful_exit([server], loop=loop):
        await server.start(host, port)
        print(f'Serving on {host}:{port}')
        await server.wait_closed()
Esempio n. 17
0
async def main(*, host='127.0.0.1', port=50051):
    await db.set_bind('postgresql://*****:*****@localhost/book_shop')
    await db.gino.create_all()
    server = Server([BookService()])
    with graceful_exit([server]):
        await server.start(host, port)
        print(f'Serving on {host}:{port}')
        await server.wait_closed()
Esempio n. 18
0
async def main(*, host='127.0.0.1', port=50051):
    await cf.initialize()
    services = ServerReflection.extend([APIService()])
    server = Server(services)
    with graceful_exit([server]):
        await server.start(host, port)
        print(f'Serving on {host}:{port}')
        await server.wait_closed()
Esempio n. 19
0
class ServerWire(Wire):
    """

    .. wire:: harness.wires.grpclib.server.ServerWire
      :type: output
      :runtime: python
      :config: harness.grpc.Server
      :requirements:
        grpclib
        protobuf

    """

    _config: grpc_pb2.Server
    server: Server

    def __init__(self, handlers: List["_Servable"]):
        self.handlers = handlers

    def configure(self, value: grpc_pb2.Server):
        assert isinstance(value, grpc_pb2.Server), type(value)
        self._config = value

        handlers = list(self.handlers)
        if not any(isinstance(h, Health) for h in handlers):
            handlers.append(Health())
        handlers = ServerReflection.extend(handlers)

        self.server = Server(handlers)
        listen(self.server, RecvRequest, _recv_request)
        listen(self.server, SendTrailingMetadata, _send_trailing_metadata)

    async def __aenter__(self):
        await self.server.start(self._config.bind.host, self._config.bind.port)
        _log.info(
            "%s started: addr=%s:%d",
            self.__class__.__name__,
            self._config.bind.host,
            self._config.bind.port,
        )

    def close(self):
        self.server.close()

    async def wait_closed(self):
        await self.server.wait_closed()
Esempio n. 20
0
async def main(*, host: str = '127.0.0.1', port: int = 50051) -> None:
    services = ServerReflection.extend([Greeter()])

    server = Server(services)
    with graceful_exit([server]):
        await server.start(host, port)
        print(f'Serving on {host}:{port}')
        await server.wait_closed()
Esempio n. 21
0
async def start_server(socket, *a, **k):
    "Coroutine to bring up the rpc server"
    server = Server([PoreRefinerDispatchServer()])
    with graceful_exit([server]):
        await server.start(path=str(socket))
        log.info(f"RPC server listening on {socket}...")
        await server.wait_closed()
        log.warning(f"RPC server shutting down.")
Esempio n. 22
0
async def serve(bind_address='0.0.0.0', port=57850):

    logger.debug('Create gRPC server')
    server = Server([TelemetryReceiver()])

    with graceful_exit([server]):
        await server.start(bind_address, port)
        logger.debug('serving on %s:%d', bind_address, port)
        await server.wait_closed()
Esempio n. 23
0
 async def start(cls, backend: BackendInterface,
                 config: IMAPConfig) -> AdminService:
     config = backend.config
     path: Optional[str] = config.args.admin_sock
     handlers = AdminHandlers(backend)
     server = Server([handlers], loop=asyncio.get_event_loop())
     path = await cls._start(path, server)
     cls._chown(path, config.args)
     return cls(path, server)
Esempio n. 24
0
async def server(host="127.0.0.1", port=50051):
    services = [FilterVisualizer()]
    services = ServerReflection.extend(services)
    print(services)
    server = Server(services)
    with graceful_exit([server]):
        await server.start(host, port)
        print(f"Serving on {host}:{port}")
        await client()
Esempio n. 25
0
    async def main(self, app_cls, app_args):
        address = app_args.get("address")
        server = Server([app_cls(app_args)])

        host, port = address.split(":")
        logger.debug(f"Starting server on host {host} : port {port}")

        with graceful_exit([server]):
            await server.start(host, port)
            await server.wait_closed()
Esempio n. 26
0
async def main(options):
    ib = IB()
    ib.disconnectedEvent += onDisconnected
    await ib.connectAsync(options.ib_host, options.ib_port)
    server = Server([IbBridgeServer(ib)])
    with graceful_exit([server]):
        await server.start(options.http_host, options.http_port)
        print(f"Serving on {options.http_host}:{options.http_port}")
        await server.wait_closed()
        ib.disconnectedEvent -= onDisconnected
        ib.disconnect()
Esempio n. 27
0
async def main(*, host='0.0.0.0', port=Config['port']):
    # 起协程监听kafka消费
    # loop = asyncio.get_event_loop()
    # tasks = asyncio.gather(coroutine)
    # loop.run_until_complete(tasks)
    #
    server = Server(services.GeneralServices())
    with graceful_exit([server]):
        await server.start(host, port)
        print(f'grpcServer serving on {host}:{port}')
        await server.wait_closed()
Esempio n. 28
0
    async def serve(cls):
        loop = asyncio.get_running_loop()
        service = cls()

        host = get_service_host("reducer")
        port = get_service_port("reducer")

        service.setUp()
        server = Server([service], loop=loop)
        print(f'Server running at {host}:{port}')
        await server.start(host, port)
        await server.wait_closed()
Esempio n. 29
0
async def main(*, host: str = '0.0.0.0', port: int = 50051) -> None:
    server = Server([Health()])
    with graceful_exit([server]):
        await server.start(host,
                           port,
                           ssl=create_secure_context(
                               SERVER_CERT,
                               SERVER_KEY,
                               trusted=CLIENT_CERT,
                           ))
        print(f'Serving on {host}:{port}')
        await server.wait_closed()
Esempio n. 30
0
def main():
    # setup judge
    judgeenv.load_env(cli=True)
    executors.load_executors()
    print('Running grpc judge server ...')
    logging.basicConfig(
        filename=judgeenv.log_file,
        level=logging.INFO,
        format='%(levelname)s %(asctime)s %(module)s %(message)s')
    for warning in judgeenv.startup_warnings:
        print(ansi_style('#ansi[Warning: %s](yellow)' % warning))
    del judgeenv.startup_warnings
    print()

    judge = LocalJudge()

    loop = asyncio.get_event_loop()

    server = Server([DmojService(judge)], loop=loop)

    host, port = '127.0.0.1', 5001
    loop.run_until_complete(server.start(host, port))
    print('Serving on {}:{}'.format(host, port))
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
    server.close()
    loop.run_until_complete(server.wait_closed())
    loop.close()