def is_started(self, url=None):
     if not url:
         url = self.url
     lwc = LedgerWebClient(url)
     sta = None
     try:
         sta = lwc.get_status(verbose=False, timeout=2)
     except MessageException as e:
         print e.message
         return False
     if sta is not None:
         return sta.get('Status', '') == 'started'
     return False
Ejemplo n.º 2
0
 def is_started(self, url=None):
     if not url:
         url = self.url
     lwc = LedgerWebClient(url)
     sta = None
     try:
         sta = lwc.get_status(verbose=False, timeout=2)
     except MessageException as e:
         print e.message
         return False
     if sta is not None:
         return sta.get('Status', '') == 'started'
     return False
Ejemplo n.º 3
0
def _get_quorum(gossiper, callback):
    """Attempts to connect gossiper to new available quorum nodes
    Args:
        gossiper (Node): The local node.
        callback (function): The function to call once the quorum topology
            update has completed.
    """
    # find out how many we have and how many nodes we still need need
    count = max(0, TargetConnectivity - len(gossiper.VotingQuorum.keys()))
    # we have all the nodes we need; do next operation (the callback)
    if count <= 0:
        logger.debug('sufficiently connected via %s',
                     [str(x.Name) for x in gossiper.VotingQuorum.itervalues()])
        callback()
        return
    # add nodes we don't have already, in random order
    candidates = [
        x for x in gossiper.quorum_list()
        if gossiper.VotingQuorum.get(x.Identifier, None) is None
    ]
    random.shuffle(candidates)
    logger.debug('trying to increase working quorum by %d from candidates %s',
                 count, [str(x.Name) for x in candidates])
    for nd in candidates:
        lwc = LedgerWebClient('http://{0}:{1}'.format(nd.NetHost, nd.HttpPort))
        try:
            status = lwc.get_status(verbose=False, timeout=2)
        except MessageException as e:
            logger.debug(e.message)
            continue
        status = status.get('Status', '')
        if status in [
                'started', "transferring ledger",
                "waiting for initial connections"
        ]:
            # candidate node is live; add it
            logger.debug('adding %s to quorum', nd.Name)
            gossiper.add_quorum_node(nd)
            if nd.Identifier not in gossiper.peer_id_list():
                send_connection_request(gossiper, nd)
            count -= 1
            if count == 0:
                logger.debug('now sufficiently connected')
                break
    # try again (or possibly execute the piggybacked callback)
    reactor.callLater(TimeBetweenProbes, _get_quorum, gossiper, callback)
Ejemplo n.º 4
0
def _get_quorum(gossiper, callback):
    """Attempts to connect gossiper to new available quorum nodes
    Args:
        gossiper (Node): The local node.
        callback (function): The function to call once the quorum topology
            update has completed.
    """
    # find out how many we have and how many nodes we still need need
    count = max(0, TargetConnectivity - len(gossiper.VotingQuorum.keys()))
    # we have all the nodes we need; do next operation (the callback)
    if count <= 0:
        logger.debug('sufficiently connected via %s',
                     [str(x.Name) for x in gossiper.VotingQuorum.itervalues()])
        callback()
        return
    # add nodes we don't have already, in random order
    candidates = [x for x in gossiper.quorum_list()
                  if gossiper.VotingQuorum.get(x.Identifier, None) is None]
    random.shuffle(candidates)
    logger.debug('trying to increase working quorum by %d from candidates %s',
                 count, [str(x.Name) for x in candidates])
    for nd in candidates:
        lwc = LedgerWebClient('http://{0}:{1}'.format(nd.NetHost,
                                                      nd.HttpPort))
        try:
            status = lwc.get_status(verbose=False, timeout=2)
        except MessageException as e:
            logger.debug(e.message)
            continue
        status = status.get('Status', '')
        if status in ['started', "transferring ledger",
                      "waiting for initial connections"]:
            # candidate node is live; add it
            logger.debug('adding %s to quorum', nd.Name)
            gossiper.add_quorum_node(nd)
            if nd.Identifier not in gossiper.peer_id_list():
                send_connection_request(gossiper, nd)
            count -= 1
            if count == 0:
                logger.debug('now sufficiently connected')
                break
    # try again (or possibly execute the piggybacked callback)
    reactor.callLater(TimeBetweenProbes, _get_quorum, gossiper, callback)