This commit is contained in:
Timothee Guerin 2017-07-13 13:56:52 -07:00
Родитель 27b14e6adc
Коммит 8f5757cea3
2 изменённых файлов: 21 добавлений и 13 удалений

Просмотреть файл

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
from dtde import clusterlib, util from dtde import clusterlib, util
import argparse import argparse
import os import os
if __name__ == '__main__': if __name__ == '__main__':
@ -18,13 +18,13 @@ if __name__ == '__main__':
parser.add_argument('--id', dest="cluster_id", required=True, parser.add_argument('--id', dest="cluster_id", required=True,
help='The unique id of your spark cluster') help='The unique id of your spark cluster')
parser.add_argument('--masterui', parser.add_argument('--masterui',
help='Local port to port spark\'s master UI to') help='Local port to port spark\'s master UI to')
parser.add_argument('--webui', parser.add_argument('--webui',
help='Local port to port spark\'s webui to') help='Local port to port spark\'s webui to')
parser.add_argument('--jupyter', parser.add_argument('--jupyter',
help='Local port to port jupyter to') help='Local port to port jupyter to')
parser.add_argument('-u', '--username', parser.add_argument('-u', '--username',
help='Username to spark cluster') help='Username to spark cluster')
parser.add_argument('--no-connect', parser.add_argument('--no-connect',
action='store_false', action='store_false',
@ -33,7 +33,7 @@ if __name__ == '__main__':
the command to run.') the command to run.')
args = parser.parse_args() args = parser.parse_args()
if (args.no_connect is True and args.username is None): if (args.no_connect is True and args.username is None):
print('You must specify a username in order to connect automatically.') print('You must specify a username in order to connect automatically.')
exit() exit()
@ -70,7 +70,7 @@ if __name__ == '__main__':
# get ssh command # get ssh command
clusterlib.ssh( clusterlib.ssh(
pool_id = pool_id, cluster_id = pool_id,
masterui = masterui, masterui = masterui,
webui = webui, webui = webui,
jupyter = jupyter, jupyter = jupyter,

Просмотреть файл

@ -81,13 +81,13 @@ def generate_cluster_start_task(
def create_cluster( def create_cluster(
custom_script:str, custom_script: str,
cluster_id:str, cluster_id: str,
vm_count, vm_count,
vm_low_pri_count, vm_low_pri_count,
vm_size, vm_size,
username:str, username: str,
password:str, password: str,
wait=True): wait=True):
""" """
Create a spark cluster Create a spark cluster
@ -257,7 +257,13 @@ def delete_cluster(cluster_id: str):
# job id is equal to pool id # job id is equal to pool id
job_id = pool_id job_id = pool_id
job_exists = batch_client.job.exists(job_id) job_exists = True
try:
batch_client.job.get(job_id)
except:
job_exists = False
pool_exists = batch_client.pool.exists(pool_id) pool_exists = batch_client.pool.exists(pool_id)
if job_exists: if job_exists:
@ -269,6 +275,7 @@ def delete_cluster(cluster_id: str):
if job_exists or pool_exists: if job_exists or pool_exists:
print("Deleting cluster {0}".format(cluster_id)) print("Deleting cluster {0}".format(cluster_id))
def ssh( def ssh(
cluster_id: str, cluster_id: str,
username: str=None, username: str=None,
@ -296,6 +303,7 @@ def ssh(
remote_login_settings = batch_client.compute_node.get_remote_login_settings( remote_login_settings = batch_client.compute_node.get_remote_login_settings(
cluster_id, master_node_id) cluster_id, master_node_id)
master_node_ip = remote_login_settings.remote_login_ip_address
master_node_port = remote_login_settings.remote_login_port master_node_port = remote_login_settings.remote_login_port
ssh_command = CommandBuilder('ssh') ssh_command = CommandBuilder('ssh')
@ -308,7 +316,7 @@ def ssh(
ssh_command.add_option("-L", "{0}:localhost:{1}".format(port[0], port[1])) ssh_command.add_option("-L", "{0}:localhost:{1}".format(port[0], port[1]))
user = username if username is not None else '<username>' user = username if username is not None else '<username>'
ssh_command.add_argument("{0}@{1} -p {2}".format(user, master_node_id, master_node_port)) ssh_command.add_argument("{0}@{1} -p {2}".format(user, master_node_ip, master_node_port))
command = ssh_command.to_str() command = ssh_command.to_str()
ssh_command_array = command.split() ssh_command_array = command.split()