|
| 1 | +# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 | +# may not use this file except in compliance with the License. A copy of |
| 5 | +# the License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "license" file accompanying this file. This file is |
| 10 | +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 | +# ANY KIND, either express or implied. See the License for the specific |
| 12 | +# language governing permissions and limitations under the License. |
| 13 | +from datetime import datetime |
| 14 | + |
| 15 | +from sagemaker.s3 import S3Downloader, S3Uploader |
| 16 | +from sagemaker.spark.processing import PySparkProcessor |
| 17 | + |
| 18 | + |
| 19 | +def test_sagemaker_spark_processor_default_tag(spark_version, role, sagemaker_session, sagemaker_client): |
| 20 | + """Test that spark processor works with default tag""" |
| 21 | + spark = PySparkProcessor( |
| 22 | + base_job_name="sm-spark-py", |
| 23 | + framework_version=spark_version, |
| 24 | + role=role, |
| 25 | + instance_count=1, |
| 26 | + instance_type="ml.c5.xlarge", |
| 27 | + max_runtime_in_seconds=1200, |
| 28 | + sagemaker_session=sagemaker_session, |
| 29 | + ) |
| 30 | + bucket = spark.sagemaker_session.default_bucket() |
| 31 | + timestamp = datetime.now().isoformat() |
| 32 | + output_data_uri = "s3://{}/spark/output/sales/{}".format(bucket, timestamp) |
| 33 | + spark_event_logs_key_prefix = "spark/spark-events/{}".format(timestamp) |
| 34 | + spark_event_logs_s3_uri = "s3://{}/{}".format(bucket, spark_event_logs_key_prefix) |
| 35 | + |
| 36 | + with open("test/resources/data/files/data.jsonl") as data: |
| 37 | + body = data.read() |
| 38 | + input_data_uri = "s3://{}/spark/input/data.jsonl".format(bucket) |
| 39 | + S3Uploader.upload_string_as_file_body( |
| 40 | + body=body, desired_s3_uri=input_data_uri, sagemaker_session=sagemaker_session |
| 41 | + ) |
| 42 | + |
| 43 | + spark.run( |
| 44 | + submit_app="test/resources/code/python/hello_py_spark/hello_py_spark_app.py", |
| 45 | + submit_py_files=["test/resources/code/python/hello_py_spark/hello_py_spark_udfs.py"], |
| 46 | + arguments=["--input", input_data_uri, "--output", output_data_uri], |
| 47 | + spark_event_logs_s3_uri=spark_event_logs_s3_uri, |
| 48 | + wait=True, |
| 49 | + ) |
| 50 | + |
| 51 | + processing_job = spark.latest_job |
| 52 | + waiter = sagemaker_client.get_waiter("processing_job_completed_or_stopped") |
| 53 | + waiter.wait( |
| 54 | + ProcessingJobName=processing_job.job_name, |
| 55 | + # poll every 15 seconds. timeout after 15 minutes. |
| 56 | + WaiterConfig={"Delay": 15, "MaxAttempts": 60}, |
| 57 | + ) |
| 58 | + |
| 59 | + output_contents = S3Downloader.list(output_data_uri, sagemaker_session=sagemaker_session) |
| 60 | + assert len(output_contents) != 0 |
0 commit comments