Exemplo n.º 1
0
    def getLeader(self, wait=False, returnRawInstance=False):
        assert self._ctx
        instances = self._getNodesInCluster(nodeType=None, both=True)
        instances.sort(key=lambda x: x.launch_time)
        try:
            leader = instances[0]  # assume leader was launched first
        except IndexError:
            raise NoSuchClusterException(self.clusterName)
        if (leader.tags.get(_TOIL_NODE_TYPE_TAG_KEY) or 'leader') != 'leader':
            raise InvalidClusterStateException(
                'Invalid cluster state! The first launched instance appears not to be the leader '
                'as it is missing the "leader" tag. The safest recovery is to destroy the cluster '
                'and restart the job. Incorrect Leader ID: %s' % leader.id)
        leaderNode = Node(publicIP=leader.ip_address,
                          privateIP=leader.private_ip_address,
                          name=leader.id,
                          launchTime=leader.launch_time,
                          nodeType=None,
                          preemptable=False,
                          tags=leader.tags)
        if wait:
            logger.debug("Waiting for toil_leader to enter 'running' state...")
            wait_instances_running(self._ctx.ec2, [leader])
            logger.debug('... toil_leader is running')
            self._waitForIP(leader)
            leaderNode.waitForNode('toil_leader')

        return leader if returnRawInstance else leaderNode
Exemplo n.º 2
0
 def _getLeader(self):
     instances = self._getNodesInCluster()
     instances.sort(key=lambda x: x.created_at)
     try:
         leader = instances[0]  # assume leader was launched first
     except IndexError:
         raise NoSuchClusterException(self.clusterName)
     return leader
Exemplo n.º 3
0
 def getLeader(self):
     instances = self._getNodesInCluster()
     instances.sort(key=lambda x: x.created_at)
     try:
         leader = instances[0]  # assume leader was launched first
     except IndexError:
         raise NoSuchClusterException(self.clusterName)
     return Node(publicIP=leader.public_ips[0], privateIP=leader.private_ips[0],
                       name=leader.name, launchTime=leader.created_at, nodeType=leader.size,
                       preemptable=False, tags=None)
Exemplo n.º 4
0
 def _getLeader(cls, clusterName, wait=False, zone=None):
     ctx = cls._buildContext(clusterName=clusterName, zone=zone)
     instances = cls._getNodesInCluster(ctx, clusterName, nodeType=None, both=True)
     instances.sort(key=lambda x: x.launch_time)
     try:
         leader = instances[0]  # assume leader was launched first
     except IndexError:
         raise NoSuchClusterException(clusterName)
     if wait:
         logger.info("Waiting for toil_leader to enter 'running' state...")
         wait_instances_running(ctx.ec2, [leader])
         logger.info('... toil_leader is running')
         cls._waitForNode(leader, 'toil_leader')
     return leader
Exemplo n.º 5
0
    def getLeader(self, wait=False):
        assert self._ctx
        instances = self._getNodesInCluster(nodeType=None, both=True)
        instances.sort(key=lambda x: x.launch_time)
        try:
            leader = instances[0]  # assume leader was launched first
        except IndexError:
            raise NoSuchClusterException(self.clusterName)
        leaderNode = Node(publicIP=leader.ip_address, privateIP=leader.private_ip_address,
                          name=leader.id, launchTime=leader.launch_time, nodeType=None,
                          preemptable=False, tags=leader.tags)
        if wait:
            logger.debug("Waiting for toil_leader to enter 'running' state...")
            wait_instances_running(self._ctx.ec2, [leader])
            logger.debug('... toil_leader is running')
            self._waitForIP(leader)
            leaderNode.waitForNode('toil_leader')

        return leaderNode
Exemplo n.º 6
0
 def getLeader(self):
     try:
         leader = self._getNodes('leader')[0]
     except IndexError:
         raise NoSuchClusterException(self.clusterName)
     return leader