-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add CNM Response Archival lambda (#369)
* feat: add additional lambda * fix: urllib has some library clash in github actions * fix: still not working * fix: still not working * fix: still not working * fix: fixing github action * fix: undo setup.py * fix: forgot to call s3 url extraction * feat: add test case * feat: add diagrams * fix: remove extra arrow
- Loading branch information
Showing
13 changed files
with
265 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
90 changes: 90 additions & 0 deletions
90
cumulus_lambda_functions/granules_cnm_response_writer/cnm_result_writer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import json | ||
|
||
from cumulus_lambda_functions.lib.json_validator import JsonValidator | ||
from cumulus_lambda_functions.lib.lambda_logger_generator import LambdaLoggerGenerator | ||
from cumulus_lambda_functions.lib.aws.aws_message_transformers import AwsMessageTransformers | ||
from cumulus_lambda_functions.lib.aws.aws_s3 import AwsS3 | ||
|
||
LOGGER = LambdaLoggerGenerator.get_logger(__name__, LambdaLoggerGenerator.get_level_from_env()) | ||
|
||
|
||
class CnmResultWriter: | ||
def __init__(self): | ||
self.__s3 = AwsS3() | ||
self.__cnm_response_schema = { | ||
'type': 'object', | ||
'required': ['collection', 'product', 'submissionTime'], | ||
'properties': { | ||
'submissionTime': {'type': 'string'}, | ||
'collection': {'type': 'string'}, | ||
'product': { | ||
'type': 'object', | ||
'required': ['name', 'files'], | ||
'properties': { | ||
'name': {'type': 'string'}, | ||
'files': { | ||
'type': 'array', | ||
'minItems': 1, | ||
'items': { | ||
'type': 'object', | ||
'required': ['name', 'uri'], | ||
'properties': { | ||
'name': {'type': 'string'}, | ||
'uri': {'type': 'string'}, | ||
} | ||
}, | ||
} | ||
} | ||
} | ||
} | ||
} | ||
self.__cnm_response = {} | ||
self.__s3_url = None | ||
|
||
@property | ||
def s3_url(self): | ||
return self.__s3_url | ||
|
||
@s3_url.setter | ||
def s3_url(self, val): | ||
""" | ||
:param val: | ||
:return: None | ||
""" | ||
self.__s3_url = val | ||
return | ||
|
||
@property | ||
def cnm_response(self): | ||
return self.__cnm_response | ||
|
||
@cnm_response.setter | ||
def cnm_response(self, val): | ||
""" | ||
:param val: | ||
:return: None | ||
""" | ||
self.__cnm_response = val | ||
return | ||
|
||
def extract_s3_location(self): | ||
result = JsonValidator(self.__cnm_response_schema).validate(self.cnm_response) | ||
if result is not None: | ||
LOGGER.error(f'invalid JSON: {result}. request_body: {self.cnm_response}') | ||
raise ValueError(f'invalid JSON: {result}. request_body: {self.cnm_response}') | ||
response_filename = f'{self.cnm_response["product"]["name"]}.{self.cnm_response["submissionTime"]}.cnm.json' | ||
parsed_url = self.cnm_response['product']['files'][0]['uri'].split('//')[1] | ||
s3_url = parsed_url.split('/') | ||
s3_url[-1] = response_filename | ||
self.__s3_url = 's3://' + '/'.join(s3_url[1:]) | ||
LOGGER.debug(f'extracted s3_url: {self.__s3_url}') | ||
return self | ||
|
||
def start(self, event): | ||
LOGGER.debug(f'event: {event}') | ||
sns_msg = AwsMessageTransformers().sqs_sns(event) | ||
LOGGER.debug(f'sns_msg: {sns_msg}') | ||
self.cnm_response = sns_msg | ||
self.extract_s3_location() | ||
self.__s3.set_s3_url(self.s3_url).upload_bytes(json.dumps(self.cnm_response, indent=4).encode()) | ||
return |
15 changes: 15 additions & 0 deletions
15
cumulus_lambda_functions/granules_cnm_response_writer/lambda_function.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import json | ||
|
||
from cumulus_lambda_functions.granules_cnm_response_writer.cnm_result_writer import CnmResultWriter | ||
from cumulus_lambda_functions.lib.lambda_logger_generator import LambdaLoggerGenerator | ||
|
||
|
||
def lambda_handler(event, context): | ||
""" | ||
:param event: | ||
:param context: | ||
:return: | ||
""" | ||
LambdaLoggerGenerator.remove_default_handlers() | ||
CnmResultWriter().start(event) | ||
return |
Empty file.
54 changes: 54 additions & 0 deletions
54
tests/cumulus_lambda_functions/granules_cnm_response_writer/test_cnm_result_writer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from unittest import TestCase | ||
|
||
from cumulus_lambda_functions.granules_cnm_response_writer.cnm_result_writer import CnmResultWriter | ||
|
||
|
||
class TestCnmResultWriter(TestCase): | ||
def test_01(self): | ||
sample_msg = { | ||
"collection": "URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT", | ||
"identifier": "URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT___2403261440:abcd.1234.efgh.test_file05", | ||
"submissionTime": "2024-05-01T13:35:23.796366", | ||
"provider": "unity", | ||
"version": "1.6.0", | ||
"product": { | ||
"dataVersion": "2403261440", | ||
"files": [ | ||
{ | ||
"type": "data", | ||
"name": "abcd.1234.efgh.test_file05.nc", | ||
"uri": "https://uds-distribution-placeholder/uds-sbx-cumulus-staging/URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT___2403261440/URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT___2403261440:abcd.1234.efgh.test_file05/abcd.1234.efgh.test_file05.nc", | ||
"checksumType": "md5", | ||
"checksum": "unknown", | ||
"size": -1 | ||
}, | ||
{ | ||
"type": "metadata", | ||
"name": "abcd.1234.efgh.test_file05.nc.cas", | ||
"uri": "https://uds-distribution-placeholder/uds-sbx-cumulus-staging/URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT___2403261440/URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT___2403261440:abcd.1234.efgh.test_file05/abcd.1234.efgh.test_file05.nc.cas", | ||
"checksumType": "md5", | ||
"checksum": "unknown", | ||
"size": -1 | ||
}, | ||
{ | ||
"type": "metadata", | ||
"name": "URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT___2403261440:abcd.1234.efgh.test_file05.cmr.xml", | ||
"uri": "https://uds-distribution-placeholder/uds-sbx-cumulus-staging/URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT___2403261440/URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT___2403261440:abcd.1234.efgh.test_file05/URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT___2403261440:abcd.1234.efgh.test_file05.cmr.xml", | ||
"checksumType": "md5", | ||
"checksum": "63e0f7f9b76d56189267c854b67cd91b", | ||
"size": 1858 | ||
} | ||
], | ||
"name": "URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT___2403261440:abcd.1234.efgh.test_file05" | ||
}, | ||
"receivedTime": "2024-05-01T13:37:29.643Z", | ||
"response": { | ||
"status": "SUCCESS" | ||
}, | ||
"processCompleteTime": "2024-05-01T13:38:01.676Z" | ||
} | ||
test = CnmResultWriter() | ||
test.cnm_response = sample_msg | ||
test.extract_s3_location() | ||
self.assertEqual('s3://uds-sbx-cumulus-staging/URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT___2403261440/URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT___2403261440:abcd.1234.efgh.test_file05/URN:NASA:UNITY:UDS_LOCAL_TEST:DEV:SNDR-SNPP_ATMS@L1B$OUTPUT___2403261440:abcd.1234.efgh.test_file05.2024-05-01T13:35:23.796366.cnm.json', test.s3_url) | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Terraform Guide on what are being deployed as there are various components. | ||
|
||
### REST API | ||
- Source: https://www.figma.com/file/dRmKfOzPC2NKACc0NL29bT/DAPA-API-Infrastructure | ||
![DAPA API Infrastructure.png](DAPA%20API%20Infrastructure.png) | ||
### Auto Ingestion Workflow | ||
- Source: https://www.figma.com/file/5kI41JOXP1WPuC4veGCEgm/auto-ingestion-workflow-infrastructure | ||
![auto-ingestion workflow infrastructure.png](auto-ingestion%20workflow%20infrastructure.png) | ||
|
||
### CMR metadata generators | ||
- 3 Lambdas which are used in CNM Step function definitions stored in cumulus-template-deploy terraform. | ||
- Example: STAC [Metadata](https://github.jpl.nasa.gov/unity-uds/cumulus-template-deploy/blob/master/cumulus-tf/catalog_granule_workflow.asl.json#L216) Extraction | ||
### Custom Metadata Ingestion | ||
- Source: https://www.figma.com/file/mKxRrAlvKmrR5DULHD2yah/Custom-metadata-Ingestion-Infrastructure | ||
![Custom metadata Ingestion Infrastructure.png](Custom%20metadata%20Ingestion%20Infrastructure.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters