Skip to content

Commit 3fcc15f

Browse files
Merge pull request #228 from ASFHyP3/develop
Release: new datatypes for api job parameters
2 parents b5910d2 + da04eb1 commit 3fcc15f

File tree

4 files changed

+95
-24
lines changed

4 files changed

+95
-24
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.5.0]
8+
### Changed
9+
- The `dem_matching`, `speckle_filter`, `include_dem`, and `include_inc_map` api parameters are now booleans instead of strings.
10+
- The `resolution` api parameter is now a number instead of a string, and the `10.0` option has been removed.
11+
712
## [0.4.0]
813
### Changed
914
- Implemented 0.15° buffer and 20% threshold in DEM coverage checks when submitting new jobs. As a result slightly more granules will be rejected as having insufficient coverage.

api/src/hyp3_api/openapi-spec.yml

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,9 @@ components:
240240

241241
resolution:
242242
description: Desired output resolution in meters.
243-
type: string
243+
type: number
244244
enum:
245-
- "30.0"
246-
- "10.0"
245+
- 30.0
247246

248247
radiometry:
249248
description: Backscatter coefficient normalization, either by ground area (sigma0) or illuminated area projected into the look direction (gamma0)
@@ -261,31 +260,23 @@ components:
261260

262261
speckle_filter:
263262
description: Apply an enhanced lee speckle filter
264-
type: string
265-
enum:
266-
- "false"
267-
- "true"
263+
default: false
264+
type: boolean
268265

269266
dem_matching:
270-
description: Attempt to match the DEMs otherwise use dead reconing
271-
type: string
272-
enum:
273-
- "false"
274-
- "true"
267+
description: Attempt to match the DEMs otherwise use dead-reckoning
268+
default: false
269+
type: boolean
275270

276271
include_dem:
277272
description: Include the DEM files in the product package
278-
type: string
279-
enum:
280-
- "false"
281-
- "true"
273+
default: false
274+
type: boolean
282275

283276
include_inc_map:
284277
description: Include the incident angle map in the product package
285-
type: string
286-
enum:
287-
- "false"
288-
- "true"
278+
default: false
279+
type: boolean
289280

290281
datetime:
291282
description: Date and time object formatted according to ISO 8601

step-function/start-execution/src/main.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,20 @@ def get_pending_jobs():
2727
return response['Items']
2828

2929

30-
def lambda_handler(event, context):
31-
pending_jobs = get_pending_jobs()
32-
for job in pending_jobs:
30+
def convert_parameters_to_strings(parameters):
31+
return {key: str(value) for key, value in parameters.items()}
32+
33+
34+
def submit_jobs(jobs):
35+
for job in jobs:
36+
job['job_parameters'] = convert_parameters_to_strings(job['job_parameters'])
3337
STEP_FUNCTION.start_execution(
3438
stateMachineArn=environ['STEP_FUNCTION_ARN'],
35-
input=json.dumps(job, cls=DecimalEncoder),
39+
input=json.dumps(job, cls=DecimalEncoder, sort_keys=True),
3640
name=job['job_id']
3741
)
42+
43+
44+
def lambda_handler(event, context):
45+
pending_jobs = get_pending_jobs()
46+
submit_jobs(pending_jobs)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from decimal import Decimal
2+
from json import dumps
3+
4+
import pytest
5+
from botocore.stub import Stubber
6+
from src.main import STEP_FUNCTION, submit_jobs
7+
8+
9+
@pytest.fixture(autouse=True)
10+
def setup_env(monkeypatch):
11+
monkeypatch.setenv('AWS_REGION', 'myRegion')
12+
monkeypatch.setenv('STEP_FUNCTION_ARN', 'myStepFunctionArn')
13+
14+
15+
@pytest.fixture
16+
def states_stubber():
17+
with Stubber(STEP_FUNCTION) as stubber:
18+
yield stubber
19+
stubber.assert_no_pending_responses()
20+
21+
22+
def test_lambda_handler(states_stubber):
23+
jobs = [
24+
{
25+
'job_id': 'myJobId',
26+
'string_field': 'value1',
27+
'boolean_field': True,
28+
'decimal_float_field': Decimal('10.1'),
29+
'decimal_integer_field': Decimal('10'),
30+
'job_parameters': {
31+
'string_field': 'value1',
32+
'boolean_field': True,
33+
'decimal_float_field': Decimal('10.1'),
34+
'decimal_integer_field': Decimal('10'),
35+
},
36+
},
37+
]
38+
39+
states_input = {
40+
'job_id': 'myJobId',
41+
'string_field': 'value1',
42+
'boolean_field': True,
43+
'decimal_float_field': 10.1,
44+
'decimal_integer_field': 10,
45+
'job_parameters': {
46+
'string_field': 'value1',
47+
'boolean_field': 'True',
48+
'decimal_float_field': '10.1',
49+
'decimal_integer_field': '10',
50+
},
51+
}
52+
53+
states_stubber.add_response(
54+
method='start_execution',
55+
expected_params={
56+
'stateMachineArn': 'myStepFunctionArn',
57+
'name': 'myJobId',
58+
'input': dumps(states_input, sort_keys=True),
59+
},
60+
service_response={
61+
'executionArn': 'myExecutionArn',
62+
'startDate': '2020-01-01',
63+
},
64+
)
65+
66+
submit_jobs(jobs)

0 commit comments

Comments
 (0)