Ejemplo n.º 1
0
def do_cluster_extend(args):
    state = load_state()

    node_controller = get_node_controller(state, args)
    node_command_generator = SimpleNodeCommandGenerator()
    vnm = ValidatorNetworkManager(
        node_controller=node_controller,
        node_command_generator=node_command_generator)

    existing_nodes = state["Nodes"]

    desired_stated = state["DesiredState"]

    if desired_stated != "Running":
        raise CliException(
            "You must have a running network.\n" +
            "Use the cluster start command to start a validator network.")

    print("Extending network by {} nodes.".format(args.count))

    index_offset = len(existing_nodes)

    for i in xrange(0, args.count):
        j = i + index_offset
        node_name = "validator-{:0>3}".format(j)

        if node_name in existing_nodes and vnm.is_running(node_name):
            print("Already running: {}".format(node_name))
            continue

        # genesis is true for the first node
        genesis = (j == 0)
        gossip_port = 5500 + j
        http_port = 8800 + j

        node_args = NodeArguments(node_name,
                                  http_port=http_port,
                                  gossip_port=gossip_port,
                                  genesis=genesis)
        node_command_generator.start(node_args)

        state["Nodes"][node_name] = {
            "Status": "Running",
            "Index": i,
            "HttpPort": str(http_port),
            "GossipPort": str(gossip_port)
        }

    save_state(state)

    try:
        vnm.update()
    except ManagementError as e:
        raise CliException(str(e))
Ejemplo n.º 2
0
def do_cluster_extend(args):
    state = load_state()

    node_controller = get_node_controller(state, args)
    node_command_generator = SimpleNodeCommandGenerator()
    vnm = ValidatorNetworkManager(
        node_controller=node_controller,
        node_command_generator=node_command_generator)

    existing_nodes = state["Nodes"]

    desired_stated = state["DesiredState"]

    if desired_stated != "Running":
        raise CliException(
            "You must have a running network.\n" +
            "Use the cluster start command to start a validator network.")

    print("Extending network by {} nodes.".format(args.count))

    index_offset = len(existing_nodes)

    for i in xrange(0, args.count):
        j = i + index_offset
        node_name = "validator-{:0>3}".format(j)

        if node_name in existing_nodes and vnm.is_running(node_name):
            print("Already running: {}".format(node_name))
            continue

        # genesis is true for the first node
        genesis = (j == 0)
        gossip_port = 5500 + j
        http_port = 8800 + j

        node_args = NodeArguments(node_name, http_port=http_port,
                                  gossip_port=gossip_port, genesis=genesis)
        node_command_generator.start(node_args)

        state["Nodes"][node_name] = {
            "Status": "Running", "Index": i,
            "HttpPort": str(http_port), "GossipPort": str(gossip_port)}

    save_state(state)

    try:
        vnm.update()
    except ManagementError as e:
        raise CliException(str(e))
Ejemplo n.º 3
0
def do_cluster_start(args):
    # pylint: disable=redefined-variable-type
    file_name = \
        os.path.join(os.path.expanduser("~"), '.sawtooth', 'cluster',
                     "state.yaml")

    # Check for existing state.yaml and get state. If not create state dict.
    if os.path.isfile(file_name):
        with open(file_name, 'r') as state_file:
            state = yaml.load(state_file)
    else:
        state = dict()
        state["DesiredState"] = "Stopped"

    # Check State for Running validators, if stopped clear out nodes.
    if state["DesiredState"] == "Stopped":
        state["Nodes"] = {}

    if "Manage" not in state or state["DesiredState"] == "Stopped":
        if args.manage == "docker" or args.manage is None:
            state["Manage"] = "docker"
        elif args.manage == "daemon":
            state["Manage"] = "daemon"
    elif args.manage is not None and state['Manage'] != args.manage\
            and state["DesiredState"] == "Running":
        raise CliException('Cannot use two different Manage types.'
                           ' Already running {}'.format(state["Manage"]))

    state["DesiredState"] = "Running"

    if state["Manage"] == 'docker':
        node_controller = DockerNodeController()

    elif state["Manage"] == 'daemon':
        node_controller = DaemonNodeController()
    else:
        raise CliException('invalid management type:'
                           ' {}'.format(state["Manage"]))

    node_command_generator = SimpleNodeCommandGenerator()

    vnm = ValidatorNetworkManager(
        node_controller=node_controller,
        node_command_generator=node_command_generator)

    try:
        existing_nodes = vnm.get_node_names()
    except ManagementError as e:
        raise CliException(str(e))

    for i in xrange(0, args.count):
        node_name = "validator-{:0>3}".format(i)

        if node_name in existing_nodes and vnm.is_running(node_name):
            print "Already running: {}".format(node_name)
            continue

        # genesis is true for the first node
        genesis = (i == 0)
        gossip_port = 5500 + i
        http_port = 8800 + i

        print "Starting: {}".format(node_name)
        node_command_generator.start(node_name,
                                     http_port=http_port,
                                     gossip_port=gossip_port,
                                     genesis=genesis)

        state["Nodes"][node_name] = {"Status": "Running", "Index": i}

    # Write file to default directory with current state Nodes
    with open(file_name, 'w') as state_file:
        yaml.dump(state, state_file, default_flow_style=False)

    try:
        vnm.update()
    except ManagementError as e:
        raise CliException(str(e))
Ejemplo n.º 4
0
def do_cluster_start(args):
    # pylint: disable=redefined-variable-type
    file_name = \
        os.path.join(os.path.expanduser("~"), '.sawtooth', 'cluster',
                     "state.yaml")

    # Check for existing state.yaml and get state. If not create state dict.
    if os.path.isfile(file_name):
        with open(file_name, 'r') as state_file:
            state = yaml.load(state_file)
    else:
        state = dict()
        state["DesiredState"] = "Stopped"

    # Check State for Running validators, if stopped clear out nodes.
    if state["DesiredState"] == "Stopped":
        state["Nodes"] = {}

    if "Manage" not in state or state["DesiredState"] == "Stopped":
        if args.manage == "docker" or args.manage is None:
            state["Manage"] = "docker"
        elif args.manage == "daemon":
            state["Manage"] = "daemon"
    elif args.manage is not None and state['Manage'] != args.manage\
            and state["DesiredState"] == "Running":
        raise CliException('Cannot use two different Manage types.'
                           ' Already running {}'.format(state["Manage"]))

    state["DesiredState"] = "Running"

    if state["Manage"] == 'docker':
        node_controller = DockerNodeController()

    elif state["Manage"] == 'daemon':
        node_controller = DaemonNodeController()
    else:
        raise CliException('invalid management type:'
                           ' {}'.format(state["Manage"]))

    node_command_generator = SimpleNodeCommandGenerator()

    vnm = ValidatorNetworkManager(
        node_controller=node_controller,
        node_command_generator=node_command_generator)

    try:
        existing_nodes = vnm.get_node_names()
    except ManagementError as e:
        raise CliException(str(e))

    for i in xrange(0, args.count):
        node_name = "validator-{:0>3}".format(i)

        if node_name in existing_nodes and vnm.is_running(node_name):
            print "Already running: {}".format(node_name)
            continue

        # genesis is true for the first node
        genesis = (i == 0)
        gossip_port = 5500 + i
        http_port = 8800 + i

        print "Starting: {}".format(node_name)
        node_command_generator.start(
            node_name,
            http_port=gossip_port,
            gossip_port=http_port,
            genesis=genesis)

        state["Nodes"][node_name] = {"Status": "Running", "Index": i}

    # Write file to default directory with current state Nodes
    with open(file_name, 'w') as state_file:
        yaml.dump(state, state_file, default_flow_style=False)

    try:
        vnm.update()
    except ManagementError as e:
        raise CliException(str(e))
Ejemplo n.º 5
0
def do_cluster_extend(args):
    # pylint: disable=redefined-variable-type
    file_name = \
        os.path.join(os.path.expanduser("~"), '.sawtooth', 'cluster',
                     "state.yaml")
    # Get current state of Nodes
    if os.path.isfile(file_name):
        with open(file_name, 'r') as state_file:
            state = yaml.load(state_file)
    else:
        raise CliException("Missing state file")

    if state['Manage'] is None or state['Manage'] == 'docker':
        node_controller = DockerNodeController()
    elif state['Manage'] == 'daemon':
        node_controller = DaemonNodeController()
    else:
        raise CliException('invalid management'
                           ' type: {}'.format(state['Manage']))

    node_command_generator = SimpleNodeCommandGenerator()

    vnm = ValidatorNetworkManager(
        node_controller=node_controller,
        node_command_generator=node_command_generator)

    existing_nodes = state["Nodes"]

    desired_stated = state["DesiredState"]

    if desired_stated != "Running":
        raise CliException(
            "You must have a running network.\n" +
            "Use the cluster start command to start a validator network.")

    print "Extending network by {} nodes.".format(args.count)

    index_offset = len(existing_nodes)

    for i in xrange(0, args.count):
        j = i + index_offset
        node_name = "validator-{:0>3}".format(j)

        if node_name in existing_nodes and vnm.is_running(node_name):
            print "Already running: {}".format(node_name)
            continue

        # genesis is true for the first node
        genesis = (j == 0)
        gossip_port = 5500 + j
        http_port = 8800 + j

        print "Starting: {}".format(node_name)
        node_config = NodeConfig(node_name, http_port=http_port,
                                 gossip_port=gossip_port, genesis=genesis)
        node_command_generator.start(node_config)

        state["Nodes"][node_name] = {"Status": "Running", "Index": j}

    # Write file to default directory with current state Nodes
    with open(file_name, 'w') as state_file:
        yaml.dump(state, state_file, default_flow_style=False)

    try:
        vnm.update()
    except ManagementError as e:
        raise CliException(str(e))
Ejemplo n.º 6
0
def do_cluster_start(args):
    state = load_state(start=True)

    # Check State for Running validators, if stopped clear out nodes.
    if state["DesiredState"] == "Stopped":
        state["Nodes"] = {}

    manage_type = DEFAULT_MANAGE if args.manage is None else args.manage

    if "Manage" not in state or state["DesiredState"] == "Stopped":
        state['Manage'] = manage_type
    elif args.manage is not None and state['Manage'] != args.manage\
            and state["DesiredState"] == "Running":
        raise CliException('Cannot use two different Manage types.'
                           ' Already running {}'.format(state["Manage"]))

    state["DesiredState"] = "Running"

    if state["Manage"] in TNG_MANAGE:
        if args.processors is None:
            raise CliException("Use -P to specify one or more processors")
        state['Processors'] = args.processors

    node_controller = get_node_controller(state, args)
    node_command_generator = SimpleNodeCommandGenerator()
    vnm = ValidatorNetworkManager(
        node_controller=node_controller,
        node_command_generator=node_command_generator)

    try:
        existing_nodes = vnm.get_node_names()
    except ManagementError as e:
        raise CliException(str(e))

    # Check for runnings nodes. If found, raise exception with message to use
    # sawtooth cluster extend command to add nodes to running network.
    for i in xrange(0, args.count):
        node_name = "validator-{:0>3}".format(i)
        if node_name in existing_nodes and vnm.is_running(node_name):
            print("Already running: {}".format(node_name))
            raise CliException("Please use 'sawtooth cluster extend'\
             to add more nodes.")

    for i in xrange(0, args.count):
        node_name = "validator-{:0>3}".format(i)

        if node_name in existing_nodes and vnm.is_running(node_name):
            print("Already running: {}".format(node_name))
            continue

        # genesis is true for the first node
        genesis = (i == 0)
        gossip_port = 5500 + i
        http_port = 8800 + i

        node_args = NodeArguments(node_name,
                                  http_port=http_port,
                                  gossip_port=gossip_port,
                                  genesis=genesis)

        if node_args.genesis is True:
            node_controller.create_genesis_block(node_args)

        print("Starting: {}".format(node_name))
        node_command_generator.start(node_args)

        state["Nodes"][node_name] = {
            "Status": "Running",
            "Index": i,
            "HttpPort": str(http_port),
            "GossipPort": str(gossip_port)
        }

    save_state(state)

    try:
        vnm.update()
    except ManagementError as e:
        raise CliException(str(e))

    node_names = state['Nodes'].keys()

    if state["Manage"] in SUBPROCESS_MANAGE:
        try:
            while True:
                time.sleep(128)
        except KeyboardInterrupt:
            print()
            ns = Namespace(cluster_command='stop',
                           command='cluster',
                           node_names=node_names,
                           verbose=None)
            do_cluster_stop(ns)
Ejemplo n.º 7
0
def do_cluster_start(args):
    state = load_state(start=True)

    # Check State for Running validators, if stopped clear out nodes.
    if state["DesiredState"] == "Stopped":
        state["Nodes"] = {}

    manage_type = DEFAULT_MANAGE if args.manage is None else args.manage

    if "Manage" not in state or state["DesiredState"] == "Stopped":
        state['Manage'] = manage_type
    elif args.manage is not None and state['Manage'] != args.manage\
            and state["DesiredState"] == "Running":
        raise CliException('Cannot use two different Manage types.'
                           ' Already running {}'.format(state["Manage"]))

    state["DesiredState"] = "Running"

    if state["Manage"] not in LEGACY_MANAGE:
        if args.processors is None:
            raise CliException("Use -P to specify one or more processors")
        state['Processors'] = args.processors

    node_controller = get_node_controller(state, args)
    node_command_generator = SimpleNodeCommandGenerator()
    vnm = ValidatorNetworkManager(
        node_controller=node_controller,
        node_command_generator=node_command_generator)

    try:
        existing_nodes = vnm.get_node_names()
    except ManagementError as e:
        raise CliException(str(e))

    # Check for runnings nodes. If found, raise exception with message to use
    # sawtooth cluster extend command to add nodes to running network.
    for i in xrange(0, args.count):
        node_name = "validator-{:0>3}".format(i)
        if node_name in existing_nodes and vnm.is_running(node_name):
            print("Already running: {}".format(node_name))
            raise CliException("Please use 'sawtooth cluster extend'\
             to add more nodes.")

    for i in xrange(0, args.count):
        node_name = "validator-{:0>3}".format(i)

        if node_name in existing_nodes and vnm.is_running(node_name):
            print("Already running: {}".format(node_name))
            continue

        # genesis is true for the first node
        genesis = (i == 0)
        gossip_port = 5500 + i
        http_port = 8800 + i

        node_args = NodeArguments(node_name, http_port=http_port,
                                  gossip_port=gossip_port, genesis=genesis)

        if node_args.genesis is True:
            node_controller.create_genesis_block(node_args)

        print("Starting: {}".format(node_name))
        node_command_generator.start(node_args)

        state["Nodes"][node_name] = {
            "Status": "Running", "Index": i,
            "HttpPort": str(http_port), "GossipPort": str(gossip_port)}

    save_state(state)

    try:
        vnm.update()
    except ManagementError as e:
        raise CliException(str(e))

    node_names = state['Nodes'].keys()

    subprocess_manage = 'subprocess', 'subprocess-legacy'
    if state["Manage"] in subprocess_manage:
        try:
            while True:
                time.sleep(128)
        except KeyboardInterrupt:
            print()
            ns = Namespace(cluster_command='stop', command='cluster',
                           node_names=node_names, verbose=None)
            do_cluster_stop(ns)
Ejemplo n.º 8
0
def do_cluster_start(args):
    state = load_state(start=True)

    # Check State for Running validators, if stopped clear out nodes.
    if state["DesiredState"] == "Stopped":
        state["Nodes"] = {}

    if "Manage" not in state or state["DesiredState"] == "Stopped":
        if args.manage == "subprocess" or args.manage is None:
            state["Manage"] = "subprocess"
        elif args.manage == "docker":
            state["Manage"] = "docker"
        elif args.manage == "daemon":
            state["Manage"] = "daemon"
        elif args.manage == "docker-tng":
            state["Manage"] = "docker-tng"
    elif args.manage is not None and state['Manage'] != args.manage\
            and state["DesiredState"] == "Running":
        raise CliException('Cannot use two different Manage types.'
                           ' Already running {}'.format(state["Manage"]))

    state["DesiredState"] = "Running"

    if state["Manage"] == 'docker-tng':
        state['Processors'] = args.processors

    node_controller = get_node_controller(state, args)
    node_command_generator = SimpleNodeCommandGenerator()
    vnm = ValidatorNetworkManager(
        node_controller=node_controller,
        node_command_generator=node_command_generator)

    try:
        existing_nodes = vnm.get_node_names()
    except ManagementError as e:
        raise CliException(str(e))

    for i in xrange(0, args.count):
        node_name = "validator-{:0>3}".format(i)

        if node_name in existing_nodes and vnm.is_running(node_name):
            print "Already running: {}".format(node_name)
            continue

        # genesis is true for the first node
        genesis = (i == 0)
        gossip_port = 5500 + i
        http_port = 8800 + i

        node_args = NodeArguments(node_name,
                                  http_port=http_port,
                                  gossip_port=gossip_port,
                                  genesis=genesis)
        if node_args.genesis is True:
            node_controller.create_genesis_block(node_args)
        print "Starting: {}".format(node_name)
        node_command_generator.start(node_args)

        state["Nodes"][node_name] = {"Status": "Running", "Index": i}

    save_state(state)

    try:
        vnm.update()
    except ManagementError as e:
        raise CliException(str(e))

    if state["Manage"] == 'subprocess':
        try:
            while True:
                time.sleep(128)
        except KeyboardInterrupt:
            print
            ns = Namespace(cluster_command='stop',
                           command='cluster',
                           node_names=[],
                           verbose=None)
            do_cluster_stop(ns)