Skip to content

Commit

Permalink
Merge pull request #251 from ASFHyP3/develop
Browse files Browse the repository at this point in the history
Release: v0.6.1
  • Loading branch information
asjohnston-asf authored Sep 9, 2020
2 parents 3c33664 + 7584df3 commit 78ff4f1
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 80 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ 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.6.1]
### Added
- `GET /user` response now includes a `job_names` list including all distinct job names previously submitted for the current user

### Changed
- API is now deployed using Api Gateway V2 resources, resulting in lower response latency.

## [0.6.0]
### Added
- Added a new `INSAR_GAMMA` job type for producing an interferogram from a pair of Sentinel-1 SLC IW scenes using [GAMMA](https://www.gamma-rs.ch/software). For details, refer to the [hyp3-insar-gamma](https://github.com/ASFHyP3/hyp3-insar-gamma) plugin repository.
Expand Down
90 changes: 23 additions & 67 deletions api/cloudformation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,92 +24,48 @@ Parameters:
Outputs:

Url:
Value: !Sub "https://${DomainName}/ui"
Value: !Sub "https://${CustomDomainName}/ui"

Resources:

RestApi:
Type: AWS::ApiGateway::RestApi
Api:
Type: AWS::ApiGatewayV2::Api
Properties:
Name: !Ref AWS::StackName
EndpointConfiguration:
Types:
- REGIONAL
ProtocolType: HTTP
Target: !GetAtt Lambda.Arn
CredentialsArn: !GetAtt ApiRole.Arn

Resource:
Type: AWS::ApiGateway::Resource
ApiOverrides:
Type: AWS::ApiGatewayV2::ApiGatewayManagedOverrides
Properties:
RestApiId: !Ref RestApi
ParentId: !GetAtt RestApi.RootResourceId
PathPart: "{proxy+}"

RootMethod:
Type: AWS::ApiGateway::Method
Properties:
RestApiId: !Ref RestApi
ResourceId: !GetAtt RestApi.RootResourceId
HttpMethod: ANY
AuthorizationType: NONE
ApiId: !Ref Api
Integration:
Type: AWS_PROXY
Uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Lambda.Arn}/invocations"
IntegrationHttpMethod: POST
Credentials: !GetAtt ApiRole.Arn
PassthroughBehavior: NEVER

ResourceMethod:
Type: AWS::ApiGateway::Method
Properties:
RestApiId: !Ref RestApi
ResourceId: !Ref Resource
HttpMethod: ANY
AuthorizationType: NONE
Integration:
Type: AWS_PROXY
Uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Lambda.Arn}/invocations"
IntegrationHttpMethod: POST
Credentials: !GetAtt ApiRole.Arn
PassthroughBehavior: NEVER
PayloadFormatVersion: "1.0"
Stage:
AccessLogSettings:
DestinationArn: !GetAtt ApiLogGroup.Arn
Format: $context.identity.sourceIp - - [$context.requestTime] "$context.httpMethod $context.path $context.protocol" $context.status $context.responseLength $context.requestId

ApiLogGroup:
Type: AWS::Logs::LogGroup
Properties:
RetentionInDays: 180

Deployment:
Type: AWS::ApiGateway::Deployment
DependsOn:
- RootMethod
- ResourceMethod
Properties:
RestApiId: !Ref RestApi

Stage:
Type: AWS::ApiGateway::Stage
Properties:
StageName: api
RestApiId: !Ref RestApi
DeploymentId: !Ref Deployment
AccessLogSetting:
DestinationArn: !GetAtt ApiLogGroup.Arn
Format: $context.identity.sourceIp $context.identity.caller $context.identity.user [$context.requestTime] "$context.httpMethod $context.path $context.protocol" $context.status $context.responseLength $context.requestId

CustomDomainName:
Type: AWS::ApiGateway::DomainName
Type: AWS::ApiGatewayV2::DomainName
Properties:
DomainName: !Ref DomainName
EndpointConfiguration:
Types:
- REGIONAL
RegionalCertificateArn: !Ref CertificateArn
SecurityPolicy: TLS_1_2

BasePathMapping:
Type: AWS::ApiGateway::BasePathMapping
DomainNameConfigurations:
- CertificateArn: !Ref CertificateArn
EndpointType: REGIONAL

ApiMapping:
Type: AWS::ApiGatewayV2::ApiMapping
Properties:
ApiId: !Ref Api
DomainName: !Ref CustomDomainName
RestApiId: !Ref RestApi
Stage: !Ref Stage
Stage: $default

ApiRole:
Type: AWS::IAM::Role
Expand Down
12 changes: 12 additions & 0 deletions api/src/hyp3_api/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,25 @@ def get_jobs(user, start=None, end=None, status_code=None, name=None):
return {'jobs': response['Items']}


def get_names_for_user(user):
table = DYNAMODB_RESOURCE.Table(environ['TABLE_NAME'])
key_expression = Key('user_id').eq(user)
response = table.query(
IndexName='user_id',
KeyConditionExpression=key_expression,
)
names = {record['name'] for record in response['Items'] if 'name' in record}
return sorted(list(names))


def get_user(user):
return {
'user_id': user,
'quota': {
'limit': int(environ['MONTHLY_JOB_QUOTA_PER_USER']),
'remaining': get_remaining_jobs_for_user(user),
},
'job_names': get_names_for_user(user)
}


Expand Down
9 changes: 9 additions & 0 deletions api/src/hyp3_api/openapi-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,22 @@ components:
required:
- user_id
- quota
additionalProperties: false
properties:
user_id:
$ref: "#/components/schemas/user_id"
quota:
$ref: "#/components/schemas/quota"
job_names:
$ref: "#components/schemas/job_names_list"

quota:
description: Containes the limit of jobs per month and the amount remaining for a user.
type: object
required:
- limit
- remaining
additionalProperties: false
properties:
limit:
type: integer
Expand All @@ -121,6 +125,11 @@ components:
type: integer
minimum: 0

job_names_list:
type: array
items:
$ref: "#/components/schemas/name"

list_of_new_jobs:
description: Contains a list of new job objects.
type: array
Expand Down
12 changes: 8 additions & 4 deletions api/tests/test_get_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def test_get_user(client, table, monkeypatch):
request_time = format_time(datetime.now(timezone.utc))
user = 'user_with_jobs'
items = [
make_db_record('job1', user_id=user, request_time=request_time, status_code='PENDING'),
make_db_record('job2', user_id=user, request_time=request_time, status_code='RUNNING'),
make_db_record('job3', user_id=user, request_time=request_time, status_code='FAILED'),
make_db_record('job4', user_id=user, request_time=request_time, status_code='SUCCEEDED')
make_db_record('job1', user_id=user, request_time=request_time, status_code='PENDING', name='job1'),
make_db_record('job2', user_id=user, request_time=request_time, status_code='RUNNING', name='job1'),
make_db_record('job3', user_id=user, request_time=request_time, status_code='FAILED', name='job2'),
make_db_record('job4', user_id=user, request_time=request_time, status_code='SUCCEEDED', name=None)
]
for item in items:
table.put_item(Item=item)
Expand All @@ -28,6 +28,10 @@ def test_get_user(client, table, monkeypatch):
'limit': 25,
'remaining': 21,
},
'job_names': [
'job1',
'job2',
],
}


Expand Down
8 changes: 0 additions & 8 deletions batch-cluster/cloudformation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,6 @@ Resources:
Effect: Allow
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role
Policies:
- PolicyName: policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: batch:DescribeComputeEnvironments
Resource: "*"

InstanceProfile:
Type: AWS::IAM::InstanceProfile
Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r api/requirements.txt
boto3
moto
moto==1.3.14
pytest
PyYAML
responses

0 comments on commit 78ff4f1

Please sign in to comment.