Skip to content

Commit

Permalink
Merge pull request #201 from ASFHyP3/develop
Browse files Browse the repository at this point in the history
RELEASE: job names
  • Loading branch information
Jlrine2 authored Aug 3, 2020
2 parents 678b89f + 7d628ab commit fa848e1
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.4]
### Added
- Name field to job parameter, set in the same way as description but with max length of 20

## [0.3.3]
### Added
- Administrators can now shut down Hyp3-api by setting SystemAvailable flag to false in CloudFormation Template and deploying
Expand Down
14 changes: 8 additions & 6 deletions api/src/hyp3_api/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def check_system_available():
if environ['SYSTEM_AVAILABLE'] != "true":
message = 'HyP3 is currently unavailable. Please try again later.'
error = {
'detail': message,
'status': 503,
'title': 'Service Unavailable',
'type': 'about:blank'
'detail': message,
'status': 503,
'title': 'Service Unavailable',
'type': 'about:blank'
}
return make_response(jsonify(error), 503)


def post_jobs(body, user, token_info):
def post_jobs(body, user):
print(body)

quota = get_user(user)['quota']
Expand Down Expand Up @@ -66,7 +66,7 @@ def post_jobs(body, user, token_info):
return body


def get_jobs(user, start=None, end=None, status_code=None):
def get_jobs(user, start=None, end=None, status_code=None, name=None):
table = DYNAMODB_RESOURCE.Table(environ['TABLE_NAME'])

key_expression = Key('user_id').eq(user)
Expand All @@ -76,6 +76,8 @@ def get_jobs(user, start=None, end=None, status_code=None):
filter_expression = Attr('job_id').exists()
if status_code is not None:
filter_expression &= Attr('status_code').eq(status_code)
if name is not None:
filter_expression &= Attr('name').eq(name)

response = table.query(
IndexName='user_id',
Expand Down
16 changes: 16 additions & 0 deletions api/src/hyp3_api/openapi-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ paths:
in: query
schema:
$ref: "#/components/schemas/datetime"
- name: name
in: query
schema:
$ref: "#/components/schemas/name"

responses:
"200":
description: 200 response
Expand Down Expand Up @@ -134,6 +139,8 @@ components:
$ref: "#/components/schemas/job_parameters"
description:
$ref: "#/components/schemas/description"
name:
$ref: "#/components/schemas/name"

list_of_jobs:
type: array
Expand Down Expand Up @@ -166,6 +173,8 @@ components:
$ref: "#/components/schemas/status_code"
description:
$ref: "#/components/schemas/description"
name:
$ref: "#/components/schemas/name"
files:
$ref: "#/components/schemas/list_of_files"
browse_images:
Expand Down Expand Up @@ -233,6 +242,13 @@ components:
minLength: 1
example: a description of the job

name:
description: User provided text to name the job
type: string
minLength: 1
maxLength: 20
example: Job Name

list_of_files:
description: List of downloadable files generated by the job.
type: array
Expand Down
25 changes: 16 additions & 9 deletions api/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def get_table_properties_from_template():

def make_job(granule='S1B_IW_SLC__1SDV_20200604T082207_20200604T082234_021881_029874_5E38',
description='someDescription',
name='someName',
job_type='RTC_GAMMA'):
job = {
'job_type': job_type,
Expand All @@ -56,6 +57,9 @@ def make_job(granule='S1B_IW_SLC__1SDV_20200604T082207_20200604T082234_021881_02
}
if description is not None:
job['description'] = description
if name is not None:
job['name'] = name

return job


Expand All @@ -72,6 +76,7 @@ def make_db_record(job_id,
request_time='2019-12-31T15:00:00+00:00',
status_code='RUNNING',
expiration_time='2019-12-31T15:00:00+00:00',
name=None,
files=None,
browse_images=None,
thumbnail_images=None):
Expand All @@ -85,6 +90,8 @@ def make_db_record(job_id,
'request_time': request_time,
'status_code': status_code,
}
if name is not None:
record['name'] = name
if files is not None:
record['files'] = files
if browse_images is not None:
Expand All @@ -100,15 +107,15 @@ def setup_requests_mock(batch):
granules = [job['job_parameters']['granule'] for job in batch]
cmr_response = {
'feed': {
'entry': [
{
'producer_granule_id': granule,
'polygons': [
['3.871941 -157.47052 62.278873 -156.62677 62.712959 -151.784653 64.318275 -152.353271 '
'63.871941 -157.47052']
],
} for granule in granules
]
'entry': [
{
'producer_granule_id': granule,
'polygons': [
['3.871941 -157.47052 62.278873 -156.62677 62.712959 -151.784653 64.318275 -152.353271 '
'63.871941 -157.47052']
],
} for granule in granules
]
}
}
responses.reset()
Expand Down
18 changes: 18 additions & 0 deletions api/tests/test_list_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ def test_list_jobs(client, table):
assert response.json == {'jobs': []}


def test_list_jobs_by_name(client, table):
items = [
make_db_record('0ddaeb98-7636-494d-9496-03ea4a7df266', name='item1'),
make_db_record('27836b79-e5b2-4d8f-932f-659724ea02c3', name='item2')
]
for item in items:
table.put_item(Item=item)

login(client)
response = client.get(JOBS_URI, query_string={'name': 'item1'})
assert response.status_code == status.HTTP_200_OK
assert response.json == {'jobs': [items[0]]}

response = client.get(JOBS_URI, query_string={'name': 'item does not exist'})
assert response.status_code == status.HTTP_200_OK
assert response.json == {'jobs': []}


def test_list_jobs_by_status(client, table):
items = [
make_db_record('0ddaeb98-7636-494d-9496-03ea4a7df266', status_code='RUNNING'),
Expand Down
31 changes: 31 additions & 0 deletions api/tests/test_submit_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,37 @@ def test_submit_job_with_empty_description(client):
assert response.status_code == status.HTTP_400_BAD_REQUEST


def test_submit_job_without_name(client, table):
login(client)
batch = [
make_job(name=None)
]
setup_requests_mock(batch)

response = submit_batch(client, batch)
assert response.status_code == status.HTTP_200_OK


def test_submit_job_with_empty_name(client):
login(client)
batch = [
make_job(name='')
]
setup_requests_mock(batch)
response = submit_batch(client, batch)
assert response.status_code == status.HTTP_400_BAD_REQUEST


def test_submit_job_with_long_name(client):
login(client)
batch = [
make_job(name='X' * 21)
]
setup_requests_mock(batch)
response = submit_batch(client, batch)
assert response.status_code == status.HTTP_400_BAD_REQUEST


def test_submit_job_granule_does_not_exist(client, table):
batch = [
make_job('S1B_IW_SLC__1SDV_20200604T082207_20200604T082234_021881_029874_5E38'),
Expand Down

0 comments on commit fa848e1

Please sign in to comment.