|
| 1 | +from boto.s3.connection import S3Connection |
| 2 | +from boto.s3.key import Key |
| 3 | +import re |
| 4 | +import os |
| 5 | +import subprocess |
| 6 | +import shakedown |
| 7 | + |
| 8 | +def upload_jar(jar): |
| 9 | + conn = S3Connection(os.environ['AWS_ACCESS_KEY_ID'], os.environ['AWS_SECRET_ACCESS_KEY']) |
| 10 | + bucket = conn.get_bucket(os.environ['S3_BUCKET']) |
| 11 | + |
| 12 | + key = Key(bucket, 'S3_PREFIX') |
| 13 | + key.metadata = {'Content-Type': 'application/java-archive'} |
| 14 | + key.set_contents_from_filename(jar) |
| 15 | + key.make_public() |
| 16 | + |
| 17 | + basename = os.path.basename(jar) |
| 18 | + |
| 19 | + jar_url = "http://{0}.s3.amazonaws.com/{1}{2}".format( |
| 20 | + os.environ['S3_BUCKET'], |
| 21 | + os.environ['S3_PREFIX'], |
| 22 | + basename) |
| 23 | + |
| 24 | + return jar_url |
| 25 | + |
| 26 | + |
| 27 | +def submit_job(jar_url): |
| 28 | + spark_job_runner_args = 'http://leader.mesos:5050 dcos \\"*\\" spark:only 2' |
| 29 | + submit_args = "-Dspark.driver.memory=2g --class com.typesafe.spark.test.mesos.framework.runners.SparkJobRunner {0} {1}".format( |
| 30 | + jar_url, spark_job_runner_args) |
| 31 | + cmd = 'dcos --log-level=DEBUG spark --verbose run --submit-args="{0}"'.format(submit_args) |
| 32 | + print('Running {}'.format(cmd)) |
| 33 | + stdout = subprocess.check_output(cmd, shell=True).decode('utf-8') |
| 34 | + print(stdout) |
| 35 | + |
| 36 | + regex = r"Submission id: (\S+)" |
| 37 | + match = re.search(regex, stdout) |
| 38 | + return match.group(1) |
| 39 | + |
| 40 | +def task_log(task_id): |
| 41 | + cmd = "dcos task log --completed --lines=1000 {}".format(task_id) |
| 42 | + print('Running {}'.format(cmd)) |
| 43 | + stdout = subprocess.check_output(cmd, shell=True).decode('utf-8') |
| 44 | + return stdout |
| 45 | + |
| 46 | + |
| 47 | +def main(): |
| 48 | + jar_url = upload_jar(os.getenv('TEST_JAR_PATH')) |
| 49 | + task_id = submit_job(jar_url) |
| 50 | + print('Waiting for task id={} to complete'.format(task_id)) |
| 51 | + shakedown.wait_for_task_completion(task_id) |
| 52 | + log = task_log(task_id) |
| 53 | + print(log) |
| 54 | + assert "All tests passed" in log |
| 55 | + |
| 56 | +main() |
0 commit comments