Ejemplo n.º 1
0
    def __init__(self, channel, score_package, amqp_target, amqp_key):
        """Score service init
        """
        loggers.get_preset().channel_name = channel
        loggers.get_preset().score_package = score_package
        loggers.get_preset().update_logger()
        loggers.update_other_loggers()

        self.score: PeerScore = None
        self.score_plugin = Plugins().load_score_plugin(channel)
        self.iiss_plugin = Plugins().load_iiss_plugin(channel)

        self.__peer_id: str = None
        self.__channel_name: str = channel

        StubCollection().amqp_key = amqp_key
        StubCollection().amqp_target = amqp_target

        score_queue_name = conf.SCORE_QUEUE_NAME_FORMAT.format(
            score_package_name=score_package,
            channel_name=channel,
            amqp_key=amqp_key)
        self.__inner_service = ScoreInnerService(amqp_target,
                                                 score_queue_name,
                                                 conf.AMQP_USERNAME,
                                                 conf.AMQP_PASSWORD,
                                                 score_service=self)

        setproctitle.setproctitle(f"{setproctitle.getproctitle()} {channel}")
Ejemplo n.º 2
0
def main(argv):
    parser = argparse.ArgumentParser()
    for cmd_arg_type in command_arguments.Type:
        cmd_arg_attr = command_arguments.attributes[cmd_arg_type]
        parser.add_argument(*cmd_arg_attr.names, **cmd_arg_attr.kwargs)

    args, unknowns = parse_args_include_unknowns(parser, argv)
    quick_command = get_quick_command(unknowns)

    if args.version:
        print(json.dumps(conf.ICON_VERSIONS, indent=2))
        parser.exit()

    command_arguments.set_raw_commands(args)

    if args.radio_station_target == 'testnet':
        args.radio_station_target = conf.URL_CITIZEN_TESTNET
        args.configure_file_path = conf.CONF_PATH_LOOPCHAIN_TESTNET
    elif args.radio_station_target == 'mainnet':
        args.radio_station_target = conf.URL_CITIZEN_MAINNET
        args.configure_file_path = conf.CONF_PATH_LOOPCHAIN_MAINNET

    if args.configure_file_path:
        conf.Configure().load_configure_json(args.configure_file_path)

    if args.key_convert:
        key_convert()
        parser.exit()

    if args.develop:
        loggers.set_preset_type(loggers.PresetType.develop)
    else:
        loggers.set_preset_type(loggers.PresetType.production)
    logger_preset = loggers.get_preset()
    logger_preset.service_type = args.service_type
    loggers.update_preset(False)
    loggers.update_other_loggers()

    grpc_patcher.monkey_patch()
    async_.thread_monkey_patch()
    async_.concurrent_future_monkey_patch()

    if args.service_type in ("peer", "citizen"):
        start_as_peer(args)
    elif args.service_type == "rest":
        start_as_rest_server(args)
    elif args.service_type == "score":
        start_as_score(args)
    elif args.service_type == "channel":
        start_as_channel(args)
    elif args.service_type == "tool":
        start_as_tool(args, quick_command)
    elif args.service_type == "admin":
        start_as_admin(args, quick_command)
    else:
        print(
            f"not supported service type {args.service_type}\ncheck loopchain help.\n"
        )
        parser.print_help()
Ejemplo n.º 3
0
def main(argv):
    parser = argparse.ArgumentParser()
    for cmd_arg_type in command_arguments.Type:
        cmd_arg_attr = command_arguments.attributes[cmd_arg_type]
        parser.add_argument(*cmd_arg_attr.names, **cmd_arg_attr.kwargs)

    args = parser.parse_args(argv)
    command_arguments.set_raw_commands(args)

    if args.radio_station_target == 'testnet':
        args.radio_station_target = conf.URL_CITIZEN_TESTNET
        args.configure_file_path = conf.CONF_PATH_LOOPCHAIN_TESTNET
    elif args.radio_station_target == 'mainnet':
        args.radio_station_target = conf.URL_CITIZEN_MAINNET
        args.configure_file_path = conf.CONF_PATH_LOOPCHAIN_MAINNET

    if args.configure_file_path:
        conf.Configure().load_configure_json(args.configure_file_path)

    if args.develop:
        loggers.set_preset_type(loggers.PresetType.develop)
    else:
        loggers.set_preset_type(loggers.PresetType.production)
    logger_preset = loggers.get_preset()
    logger_preset.service_type = args.service_type
    loggers.update_preset(False)
    loggers.update_other_loggers()

    grpc_patcher.monkey_patch()
    async .thread_monkey_patch()
    async .concurrent_future_monkey_patch()

    if args.service_type == "peer":
        start_as_peer(args, conf.NodeType.CommunityNode)
    elif args.service_type == "citizen":
        start_as_peer(args, conf.NodeType.CitizenNode)
    elif args.service_type == "rs" or args.service_type == "radiostation":
        start_as_rs(args)
    elif args.service_type == "rest":
        start_as_rest_server(args)
    elif args.service_type == "rest-rs":
        start_as_rest_server_rs(args)
    elif args.service_type == "score":
        start_as_score(args)
    elif args.service_type == "channel":
        start_as_channel(args)
    elif args.service_type == "tool":
        start_as_tool(args)
    elif args.service_type == "admin":
        start_as_admin(args)
    else:
        print(
            f"not supported service type {args.service_type}\ncheck loopchain help.\n"
        )
        os.system("python3 ./loopchain.py -h")
Ejemplo n.º 4
0
    def load_properties(properties: ModuleProcessProperties, module_name):
        conf.set_origin_type_configurations(properties.configurations)

        loggers.set_preset_type(properties.logger_preset_type)
        loggers.update_other_loggers()

        loggers.set_presets(properties.logger_presets)
        preset = loggers.get_preset()
        if preset.service_type:
            preset.service_type += f"-{module_name}"
        else:
            preset.service_type = module_name
        preset.update_logger()
Ejemplo n.º 5
0
        async def ready_tasks():
            from loopchain import loggers
            loggers.get_preset().update_logger()
            loggers.update_other_loggers()

            logging.debug('rest_server:initialize complete.')
Ejemplo n.º 6
0
import multiprocessing
import unittest

from aio_pika.exceptions import ChannelClosed
from earlgrey import MessageQueueStub, MessageQueueService, MessageQueueType, message_queue_task

from loopchain import configure as conf
from loopchain.channel.channel_inner_service import ChannelInnerService, ChannelInnerStub
from loopchain.peer import PeerInnerService, PeerInnerStub
from loopchain.utils import loggers
from loopchain.utils.message_queue import StubCollection
from tests.unit import test_util

loggers.set_preset_type(loggers.PresetType.develop)
loggers.update_preset()
loggers.update_other_loggers()


class TestMessageQueue(unittest.TestCase):
    def setUp(self):
        test_util.print_testname(self._testMethodName)

    def test_basic(self):
        class Task:
            @message_queue_task
            async def sum(self, x, y):
                return x + y

            @message_queue_task
            def multiply(self, x, y):
                return x * y