Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2339#discussion_r17381096
  
    --- Diff: ec2/spark_ec2.py ---
    @@ -618,6 +620,57 @@ def wait_for_cluster(conn, wait_secs, master_nodes, 
slave_nodes):
         time.sleep(wait_secs)
     
     
    +def is_ssh_available(host, opts):
    +    "Checks if SSH is available on the host."
    +    try:
    +        with open(os.devnull, 'w') as devnull:
    +            ret = subprocess.check_call(
    +                ssh_command(opts) +
    +                ['-t', '-t',
    +                 '-o', 'ConnectTimeout=3',
    +                 '%s@%s' % (opts.user, host),
    +                 stringify_command('true')],
    +                stdout=devnull,
    +                stderr=devnull
    +            )
    +        if ret == 0:
    +            return True
    +        else:
    +            return False
    +    except subprocess.CalledProcessError as e:
    +        return False
    +
    +
    +def wait_for_cluster_state(cluster_instances, cluster_state, opts):
    +    """
    +    cluster_instances: a list of boto.ec2.instance.Instance
    +    cluster_state: a string representing the desired state of all the 
instances in the cluster
    +           value can be 'ssh-ready' or a valid value from 
boto.ec2.instance.InstanceState such as
    +           'running', 'terminated', etc.
    +           (would be nice to replace this with a proper enum: 
http://stackoverflow.com/a/1695250)
    +    """
    +    sys.stdout.write(
    +        "Waiting for all instances in cluster to enter '{s}' 
state.".format(s=cluster_state)
    +    )
    +    sys.stdout.flush()
    +    while True:
    +        for i in cluster_instances:
    +            s = i.update()  # capture output to suppress print to screen 
in newer versions of boto
    +            # print "{instance}: {state}".format(instance=i.id, 
state=i.state)
    +        if cluster_state == 'ssh-ready':
    +            if all(i.state == 'running' for i in cluster_instances) and \
    +               all(is_ssh_available(host=i.ip_address, opts=opts) for i in 
cluster_instances):
    +                print ""  # so that next line of output starts on new line
    +                return
    --- End diff --
    
    The long comment sounds boring than 'sys.stdout.write("\n")'. With 'print 
""', you also need to flush manually. I think we do not need to flush here, 
because it has no visually changes until other loggings coming in.
    
    Either is fine to me. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to