Skip to content

Commit cfaab65

Browse files
Merge pull request #99 from ASFHyP3/develop
Release v0.1.8
2 parents ac7fa27 + bc5dc91 commit cfaab65

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
77
and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [0.1.8]
10+
11+
### Fixed
12+
- `upload_rtc.py` now deletes any pre-existing objects from S3 prior to uploading output files. Eliminates duplicate
13+
output files in the rare case where a HyP3 job attempt is terminated in the middle of uploading objects and then later
14+
retried.
15+
916
## [0.1.7]
1017

1118
### Fixed

src/hyp3_opera_rtc/upload_rtc.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from shutil import copyfile, make_archive
44
from xml.etree import ElementTree as et
55

6-
from hyp3lib.aws import upload_file_to_s3
6+
from hyp3lib import aws
77

88
import hyp3_opera_rtc
99

@@ -12,6 +12,12 @@ class FailedToFindLineageStatementError(Exception):
1212
pass
1313

1414

15+
def delete_prefix(bucket: str, bucket_prefix: str) -> None:
16+
response = aws.S3_CLIENT.list_objects_v2(Bucket=bucket, Prefix=bucket_prefix)
17+
for obj in response.get('Contents', []):
18+
aws.S3_CLIENT.delete_object(Bucket=bucket, Key=obj['Key'])
19+
20+
1521
def upload_rtc(bucket: str, bucket_prefix: str, output_dir: Path) -> None:
1622
output_files = [f for f in output_dir.iterdir() if not f.is_dir()]
1723

@@ -20,8 +26,9 @@ def upload_rtc(bucket: str, bucket_prefix: str, output_dir: Path) -> None:
2026
output_zip = make_zip(output_files, output_dir)
2127
output_files.append(output_zip)
2228

29+
delete_prefix(bucket, bucket_prefix)
2330
for output_file in output_files:
24-
upload_file_to_s3(output_file, bucket, bucket_prefix, chunk_size=100_000_000)
31+
aws.upload_file_to_s3(output_file, bucket, bucket_prefix, chunk_size=100_000_000)
2532

2633

2734
def make_zip(output_files: list[Path], output_dir: Path) -> Path:

tests/test_upload_rtc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ def test_upload_slc_rtc(rtc_slc_results_dir, s3_bucket):
6161
assert file_suffixs == {'.json': 1, '.log': 1, '.h5': 27, '.xml': 27, '.png': 27, '.tif': 27 * 3}
6262

6363

64+
def test_upload_slc_rtc_with_existing_objects(rtc_slc_results_dir, s3_bucket):
65+
prefix = 'myPrefix'
66+
aws.S3_CLIENT.put_object(Bucket=s3_bucket, Key=f'{prefix}/foo.txt')
67+
aws.S3_CLIENT.put_object(Bucket=s3_bucket, Key=f'{prefix}/bar.json')
68+
69+
upload_rtc.upload_rtc(s3_bucket, prefix, rtc_slc_results_dir)
70+
71+
resp = aws.S3_CLIENT.list_objects_v2(Bucket=s3_bucket, Prefix=prefix)
72+
file_suffixes = dict(Counter(Path(obj['Key']).suffix for obj in resp['Contents']))
73+
assert file_suffixes == {'.json': 1, '.log': 1, '.h5': 27, '.xml': 27, '.png': 27, '.tif': 27 * 3}
74+
75+
6476
def test_make_zip_name(rtc_burst_output_files):
6577
zip_filename = upload_rtc.make_zip_name([Path(f) for f in rtc_burst_output_files])
6678

0 commit comments

Comments
 (0)