コード例 #1
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()
コード例 #2
0
def run_score_server_as_process(amqp_key):
    args = [
        'python3', 'loopchain.py', 'score', '--channel',
        conf.LOOPCHAIN_DEFAULT_CHANNEL, '--amqp_key', amqp_key,
        '--score_package', "score_package", '-d'
    ]
    logging.debug(f"run_score_server_as_process ({args})")
    return CommonSubprocess(args)
コード例 #3
0
def run_peer_server_as_process(port,
                               radiostation_port=conf.PORT_RADIOSTATION,
                               group_id=None,
                               score=None):
    args = [
        'python3', 'loopchain.py', 'peer', '-d', '-p',
        str(port), '-r', f"{util.get_private_ip()}:{radiostation_port}"
    ]
    logging.debug(f"run_peer_server_as_process ({args})")
    return CommonSubprocess(args)
コード例 #4
0
ファイル: container.py プロジェクト: braveheart12/ICON-Chain
    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.")
コード例 #5
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.")
コード例 #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
コード例 #7
0
ファイル: peer_service.py プロジェクト: ip-config/loopchain-1
    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
コード例 #8
0
def run_radio_station_as_process(port):
    args = ['python3', 'loopchain.py', 'rs', '-d', '-p', str(port)]
    logging.debug(f"run_radio_station_as_process ({args})")
    return CommonSubprocess(args)
コード例 #9
0
    def test_common_subprocess(self):
        # GIVEN
        process_args = ['ls']
        logging.debug(f"run common subprocess....")
        subprocess = CommonSubprocess(process_args)
        logging.debug(f"after run common subprocess....")
        subprocess.start()
        subprocess.start()
        subprocess.start()
        self.assertTrue(subprocess.is_run())

        # WHEN
        time.sleep(2)
        subprocess.stop()
        subprocess.wait()
        subprocess.wait()
        subprocess.stop()

        # THEN
        self.assertFalse(subprocess.is_run())
コード例 #10
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)
            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.")