Ejemplo n.º 1
0
def get_network_node(src: typing.Union[ExecutionContext, NodeIdentifier],
                     node_index=None) -> typing.Tuple[Network, Node]:
    """Returns the network and node to which deploy(s) will be dispatched.

    :param src: Source from which targets will be derived.

    :returns: 2 member tuple -> (network, node).
    
    """
    if isinstance(src, ExecutionContext):
        network_id = factory.create_network_id(src.network)
        network = cache.infra.get_network(network_id)
        if node_index is not None:
            node_id = factory.create_node_id(network_id, node_index)
            node = cache.infra.get_node(node_id)
        elif src.node_index != 0:
            node_id = factory.create_node_id(network_id, src.node_index)
            node = cache.infra.get_node(node_id)
        else:
            node = cache.infra.get_node_by_network(network)

    elif isinstance(src, NodeIdentifier):
        network = cache.infra.get_network(src.network_id)
        node = cache.infra.get_node(src)

    else:
        raise ValueError("Cannot derive network & node from source")

    return network, node
Ejemplo n.º 2
0
def main(args):
    """Entry point.
    
    :param args: Parsed CLI arguments.

    """
    # Unpack.
    network_id = factory.create_network_id(args.network)
    node_id = factory.create_node_id(network_id, int(args.node))

    # Pull.
    node = cache.infra.get_node(node_id)
    if node is None:
        raise ValueError("Unregistered node.")

    # Update.
    node.status = NodeStatus[args.status.upper()]

    # Push.
    cache.infra.set_node(node)

    # Notify.
    utils.log(
        f"Node {args.network}:{args.node} status was updated --> {node.status}"
    )
Ejemplo n.º 3
0
def start_generator(meta: typing.Any):
    """Entry point.

    :param meta: Generator meta-data.

    """
    # Parse cli args.
    args = meta.ARGS.parse_args()

    # Import worker to setup upstream services / actors.
    _import_actors()

    # Import dramatiq actor used to ping message to broker.
    from stests.core.orchestration.run import do_run

    # Unpack args.
    network_id = factory.create_network_id(args.network_name)
    node_id = factory.create_node_id(network_id, args.node_index)

    # Start generator(s).
    ctx_list = _get_context_list(meta, args, network_id, node_id)
    for ctx in ctx_list:
        do_run.send(ctx)

    # Notify.
    if len(ctx_list) == 1:
        log_event(EventType.WFLOW_GENERATOR_LAUNCHED,
                  f"{ctx.run_type} :: run {ctx.run_index}", ctx)
    else:
        log_event(
            EventType.WFLOW_GENERATORS_LAUNCHED,
            f"{ctx.run_type} :: runs {ctx_list[0].run_index} -> {ctx_list[-1].run_index}",
            ctx)
Ejemplo n.º 4
0
def do_start_monitoring():
    """Starts monitoring of registered networks.
    
    """
    for network in cache.infra.get_networks():
        network_id = factory.create_network_id(network.name)
        for node in cache.infra.get_nodes_for_monitoring(network, _MAX_NODES):
            do_monitor_node.send(
                factory.create_node_id(network_id, node.index), )
            time.sleep(float(1))
Ejemplo n.º 5
0
 def __init__(self, info: NodeEventInfo):
     self.block = None
     self.block_hash = info.block_hash
     self.deploy = None
     self.deploy_hash = None
     self.info = info
     self.network_id = factory.create_network_id(info.network)
     self.network = cache.infra.get_network(self.network_id)
     self.node_id = factory.create_node_id(self.network_id, info.node_index)
     self.node = cache.infra.get_node(self.node_id)
     self.on_chain_block = None
     self.on_chain_deploy = None
Ejemplo n.º 6
0
def get_network_node(args) -> typing.Tuple[Network, Node]:
    """Maps input args to a target network node.
    
    """
    network_id = factory.create_network_id(args.network)
    network = cache.infra.get_network(network_id)
    if network is None:
        raise ValueError("Unregistered network.")

    node_id = factory.create_node_id(network_id, int(args.node))
    node = cache.infra.get_node(node_id)
    if node is None:
        raise ValueError("Unregistered node.")

    return network, node
Ejemplo n.º 7
0
def main(args):
    """Entry point.
    
    :param args: Parsed CLI arguments.

    """
    # Unpack.
    network_id = factory.create_network_id(args.network)
    node_id = factory.create_node_id(network_id, int(args.node))

    # Pull.
    node = cache.infra.get_node(node_id)
    if node is None:
        raise ValueError("Unregistered node.")

    # Set key pair.
    pvk, pbk = crypto.get_key_pair_from_pvk_pem_file(
        args.pem_path,
        algo=crypto.KeyAlgorithm.ED25519,
        encoding=crypto.KeyEncoding.HEX)

    # Set bonding account.
    node.account = factory.create_account(
        network=network_id.name,
        typeof=AccountType.VALIDATOR_BOND,
        index=-node_id.index,
        key_algo=crypto.KeyAlgorithm.ED25519,
        private_key=pvk,
        public_key=pbk,
    )

    # Push.
    cache.infra.set_node(node)

    # Inform.
    utils.log(
        f"Node {args.network}:{args.node} bonding key was successfully registered"
    )
Ejemplo n.º 8
0
def create_node_id() -> types.infra.NodeIdentifier:
    return factory.create_node_id(create_network_id(), 1)