Ejemplo n.º 1
0
    def run(self, conn, event: multiprocessing.Event):
        logging.debug("Container run...")

        if self._type == ServerType.GRPC:
            logging.info(f'Container run grpc port {self._port}')

            setproctitle.setproctitle(f"{setproctitle.getproctitle()} {self._process_name}")

            server = grpc.server(futures.ThreadPoolExecutor(conf.MAX_WORKERS, "ContainerThread"))
            loopchain_pb2_grpc.add_ContainerServicer_to_server(self, server)
            GRPCHelper().add_server_port(server, '[::]:' + str(self._port), conf.SSLAuthType.none)

            logging.info(f'Container run complete grpc port {self._port}')
        elif self._type == ServerType.REST_PEER:
            args = ['python3', '-m', 'loopchain', 'rest', '-p', str(self._port)]
            args += command_arguments.get_raw_commands_by_filter(
                command_arguments.Type.AMQPTarget,
                command_arguments.Type.AMQPKey,
                command_arguments.Type.Develop,
                command_arguments.Type.ConfigurationFilePath,
                command_arguments.Type.RadioStationTarget
            )
            server = CommonSubprocess(args)
            api_port = self._port + conf.PORT_DIFF_REST_SERVICE_CONTAINER
            server.set_proctitle(f"{setproctitle.getproctitle()} RestServer api_port({api_port})")
        else:
            args = ['python3', '-m', 'loopchain', 'rest-rs', '-p', str(self._port)]
            args += command_arguments.get_raw_commands_by_filter(
                command_arguments.Type.Develop,
                command_arguments.Type.ConfigurationFilePath
            )

            api_port = self._port + conf.PORT_DIFF_REST_SERVICE_CONTAINER
            server = CommonSubprocess(args)
            server.set_proctitle(f"{setproctitle.getproctitle()} RestServerRS api_port({api_port})")

        logging.info(f'Container run complete port {self._port}')

        # complete init
        event.set()

        if self._type == ServerType.GRPC:
            self._append_monitor()

        command = None
        while command != "quit":
            try:
                command, param = conn.recv()  # Queue 에 내용이 들어올 때까지 여기서 대기 된다. 따라서 Sleep 이 필요 없다.
                logging.debug("Container got: " + str(param))
            except Exception as e:
                logging.warning("Container conn.recv() error: " + str(e))
            except KeyboardInterrupt:
                pass

        if self._type == ServerType.GRPC:
            server.stop(0)
        else:
            server.stop()

        logging.info("Server Container Ended.")
Ejemplo n.º 2
0
    def run(self, conn, event: multiprocessing.Event):
        logging.debug("RestService run...")

        args = ['python3', '-m', 'loopchain', 'rest', '-p', str(self._port)]
        args += command_arguments.get_raw_commands_by_filter(
            command_arguments.Type.AMQPKey,
            command_arguments.Type.RadioStationTarget
        )
        server = CommonSubprocess(args)
        api_port = self._port + conf.PORT_DIFF_REST_SERVICE_CONTAINER
        server.set_proctitle(f"{setproctitle.getproctitle()} RestServer api_port({api_port})")
        logging.info(f'RestService run complete port {api_port}')

        # complete init
        event.set()

        command = None
        while command != "quit":
            try:
                command, param = conn.recv()
                logging.debug(f"RestService got: {param}")
            except Exception as e:
                logging.warning(f"RestService conn.recv() error: {e}")
            except KeyboardInterrupt:
                pass

        server.stop()
        logging.info("RestService Ended.")
Ejemplo n.º 3
0
    async def __run_score_container(self):
        if not conf.USE_EXTERNAL_SCORE or conf.EXTERNAL_SCORE_RUN_IN_LAUNCHER:
            process_args = [
                'python3', '-m', 'loopchain', 'score', '--channel',
                ChannelProperty().name, '--score_package',
                ChannelProperty().score_package
            ]
            process_args += command_arguments.get_raw_commands_by_filter(
                command_arguments.Type.AMQPTarget,
                command_arguments.Type.AMQPKey, command_arguments.Type.Develop,
                command_arguments.Type.ConfigurationFilePath)
            self.__score_container = CommonSubprocess(process_args)

        if conf.USE_EXTERNAL_SCORE:
            await StubCollection().create_icon_score_stub(
                ChannelProperty().name)
            await StubCollection().icon_score_stubs[ChannelProperty().name
                                                    ].connect()
            await StubCollection().icon_score_stubs[ChannelProperty().name
                                                    ].async_task().hello()
            return None
        else:
            await StubCollection().create_score_stub(
                ChannelProperty().name,
                ChannelProperty().score_package)
            await StubCollection().score_stubs[ChannelProperty().name
                                               ].connect()
            await StubCollection().score_stubs[ChannelProperty().name
                                               ].async_task().hello()

            return await self.__load_score()
Ejemplo n.º 4
0
    def run(self, conn, event: multiprocessing.Event):
        logging.debug("Container run...")

        if self._type == ServerType.REST_PEER:
            args = ['python3', '-m', 'loopchain', 'rest', '-p', str(self._port)]
            args += command_arguments.get_raw_commands_by_filter(
                command_arguments.Type.AMQPTarget,
                command_arguments.Type.AMQPKey,
                command_arguments.Type.Develop,
                command_arguments.Type.ConfigurationFilePath,
                command_arguments.Type.RadioStationTarget
            )
            server = CommonSubprocess(args)
            api_port = self._port + conf.PORT_DIFF_REST_SERVICE_CONTAINER
            server.set_proctitle(f"{setproctitle.getproctitle()} RestServer api_port({api_port})")
        else:
            args = ['python3', '-m', 'loopchain', 'rest-rs', '-p', str(self._port)]
            args += command_arguments.get_raw_commands_by_filter(
                command_arguments.Type.Develop,
                command_arguments.Type.ConfigurationFilePath
            )

            api_port = self._port + conf.PORT_DIFF_REST_SERVICE_CONTAINER
            server = CommonSubprocess(args)
            server.set_proctitle(f"{setproctitle.getproctitle()} RestServerRS api_port({api_port})")

        logging.info(f'Container run complete port {self._port}')

        # complete init
        event.set()

        command = None
        while command != "quit":
            try:
                command, param = conn.recv()  # Queue 에 내용이 들어올 때까지 여기서 대기 된다. 따라서 Sleep 이 필요 없다.
                logging.debug("Container got: " + str(param))
            except Exception as e:
                logging.warning("Container conn.recv() error: " + str(e))
            except KeyboardInterrupt:
                pass

        server.stop()
        logging.info("Server Container Ended.")
Ejemplo n.º 5
0
    def run(self, event: threading.Event):
        # rest_proxy_port will be calculated in 'rest_proxy.py' again.
        # The reason passing peer_port to 'rest_proxy.py' is that rest_proxy should know which port it has to connect.
        args = ['python3', './rest_proxy.py', '-p', str(self.__peer_port)]
        args += command_arguments.get_raw_commands_by_filter(
            command_arguments.Type.Develop, command_arguments.Type.AMQPTarget,
            command_arguments.Type.AMQPKey,
            command_arguments.Type.ConfigurationFilePath)

        self.__subprocess = subprocess.Popen(args)

        logging.debug(
            f'Launch gunicorn proxy server. Port = {self.__rest_proxy_port}')
        event.set()

        self.__subprocess.wait()
Ejemplo n.º 6
0
    async def __run_score_container(self):
        if conf.RUN_ICON_IN_LAUNCHER:
            process_args = ['python3', '-m', 'loopchain', 'score',
                            '--channel', ChannelProperty().name]
            process_args += command_arguments.get_raw_commands_by_filter(
                command_arguments.Type.AMQPTarget,
                command_arguments.Type.AMQPKey,
                command_arguments.Type.Develop,
                command_arguments.Type.ConfigurationFilePath,
                command_arguments.Type.RadioStationTarget
            )
            self.__score_container = CommonSubprocess(process_args)

        await StubCollection().create_icon_score_stub(ChannelProperty().name)
        await StubCollection().icon_score_stubs[ChannelProperty().name].connect()
        await StubCollection().icon_score_stubs[ChannelProperty().name].async_task().hello()
        return None
Ejemplo n.º 7
0
    async def serve_channels(self):
        for i, channel_name in enumerate(self.__channel_infos.keys()):
            score_port = self.__peer_port + conf.PORT_DIFF_SCORE_CONTAINER + conf.PORT_DIFF_BETWEEN_SCORE_CONTAINER * i

            args = ['python3', '-m', 'loopchain', 'channel']
            args += ['-p', str(score_port)]
            args += ['--channel', str(channel_name)]
            args += command_arguments.get_raw_commands_by_filter(
                command_arguments.Type.Develop,
                command_arguments.Type.AMQPTarget,
                command_arguments.Type.AMQPKey,
                command_arguments.Type.ConfigurationFilePath)

            service = CommonSubprocess(args)

            channel_stub = StubCollection().channel_stubs[channel_name]
            await channel_stub.async_task().hello()

            self.__channel_services[channel_name] = service