Skip to content

Commit 90773fc

Browse files
committed
chore: update from develop
2 parents 91582ac + d290bf9 commit 90773fc

File tree

5 files changed

+74
-22
lines changed

5 files changed

+74
-22
lines changed

CHANGELOG.md

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

8+
## [9.16.0] - 2025-10-07
9+
### Changed
10+
- [#608](https://github.com/unity-sds/unity-data-services/pull/608) feat:daac response fastapi
11+
812
## [9.15.1] - 2025-06-25
913
### Fixed
1014
- [#597](https://github.com/unity-sds/unity-data-services/pull/597) fix: collection deletion - adding cumulus execution deletions

cumulus_lambda_functions/daac_archiver/daac_archiver_logic.py

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from mdps_ds_lib.lib.aws.aws_message_transformers import AwsMessageTransformers
1212
from mdps_ds_lib.lib.utils.json_validator import JsonValidator
1313
from pystac import Item
14+
from mdps_ds_lib.stac_fast_api_client.sfa_client_factory import SFAClientFactory
1415

1516
from cumulus_lambda_functions.lib.uds_db.granules_db_index import GranulesDbIndex
1617
from mdps_ds_lib.lib.aws.aws_sns import AwsSns
@@ -228,25 +229,46 @@ def send_to_daac_maap(self, granules_json):
228229
}
229230
return
230231

231-
def receive_from_daac(self, event: dict):
232-
LOGGER.debug(f'receive_from_daac#event: {event}')
233-
sns_msg = AwsMessageTransformers().sqs_sns(event)
234-
LOGGER.debug(f'sns_msg: {sns_msg}')
235-
cnm_notification_msg = sns_msg
232+
def update_stac(self, cnm_notification_msg):
233+
update_type = os.getenv('ARCHIVAL_STATUS_MECHANISM', '')
234+
if not any([k for k in ['UDS', 'FAST_STAC'] if k == update_type]):
235+
raise ValueError(f"missing ARCHIVAL_STATUS_MECHANISM environment variable or value is not {['UDS', 'FAST_STAC']}")
236+
if update_type == 'UDS':
237+
return self.update_stac_uds(cnm_notification_msg)
238+
return self.update_stac_fast_api(cnm_notification_msg)
236239

237-
cnm_msg_schema = requests.get('https://raw.githubusercontent.com/podaac/cloud-notification-message-schema/v1.6.1/cumulus_sns_schema.json')
238-
cnm_msg_schema.raise_for_status()
239-
cnm_msg_schema = json.loads(cnm_msg_schema.text)
240-
result = JsonValidator(cnm_msg_schema).validate(cnm_notification_msg)
241-
if result is not None:
242-
raise ValueError(f'input cnm event has cnm_msg_schema validation errors: {result}')
243-
if 'response' not in cnm_notification_msg:
244-
raise ValueError(f'missing response in {cnm_notification_msg}')
240+
def update_stac_fast_api(self, cnm_notification_msg):
241+
sfa_client = SFAClientFactory().get_instance_from_env()
242+
collection_id, granule_id = ':'.join(cnm_notification_msg['identifier'].split(':')[:-1]), cnm_notification_msg['identifier']
243+
# TODO assuming granule ID is URN:NASA:VENUE:TENANT:VENUE:COLLECTION_ID:COLLECTION_ID
244+
existing_item = sfa_client.get_item(collection_id, granule_id)
245+
# TODO handle error when no existing_item. Currently, it is requests.HTTPError with 404
246+
if cnm_notification_msg['response']['status'] == 'SUCCESS':
247+
latest_daac_status = {
248+
'archive_status': 'cnm_r_success',
249+
'archive_error_message': '',
250+
'archive_error_code': '',
251+
}
252+
else:
253+
latest_daac_status = {
254+
'archive_status': 'cnm_r_failed',
255+
'archive_error_message': cnm_notification_msg['response']['errorMessage'] if 'errorMessage' in cnm_notification_msg['response'] else 'unknown',
256+
'archive_error_code': cnm_notification_msg['response']['errorCode'] if 'errorCode' in cnm_notification_msg['response'] else 'unknown',
257+
}
258+
latest_daac_status['event_time'] = TimeUtils.get_current_time()
259+
existing_item['properties']['archival_statuses'] = existing_item['properties']['archival_statuses'] + [latest_daac_status] if 'archival_statuses' in existing_item['properties'] else [latest_daac_status]
260+
updated_item = sfa_client.update_item(collection_id, granule_id, existing_item, update_whole=True) # TODO partial update via patch is not working at this moment.
261+
return
262+
263+
def update_stac_uds(self, cnm_notification_msg):
245264
granule_identifier = UdsCollections.decode_identifier(cnm_notification_msg['identifier']) # This is normally meant to be for collection. Since our granule ID also has collection id prefix. we can use this.
246265
try:
247-
existing_granule_object = self.__granules_index.get_entry(granule_identifier.tenant, granule_identifier.venue, cnm_notification_msg['identifier'])
266+
existing_granule_object = self.__granules_index.get_entry(granule_identifier.tenant,
267+
granule_identifier.venue,
268+
cnm_notification_msg['identifier'])
248269
except Exception as e:
249-
LOGGER.exception(f"error while attempting to retrieve existing record: {cnm_notification_msg['identifier']}, not continuing")
270+
LOGGER.exception(
271+
f"error while attempting to retrieve existing record: {cnm_notification_msg['identifier']}, not continuing")
250272
return
251273
LOGGER.debug(f'existing_granule_object: {existing_granule_object}')
252274
if cnm_notification_msg['response']['status'] == 'SUCCESS':
@@ -258,7 +280,27 @@ def receive_from_daac(self, event: dict):
258280
return
259281
self.__granules_index.update_entry(granule_identifier.tenant, granule_identifier.venue, {
260282
'archive_status': 'cnm_r_failed',
261-
'archive_error_message': cnm_notification_msg['response']['errorMessage'] if 'errorMessage' in cnm_notification_msg['response'] else 'unknown',
262-
'archive_error_code': cnm_notification_msg['response']['errorCode'] if 'errorCode' in cnm_notification_msg['response'] else 'unknown',
283+
'archive_error_message': cnm_notification_msg['response']['errorMessage'] if 'errorMessage' in
284+
cnm_notification_msg[
285+
'response'] else 'unknown',
286+
'archive_error_code': cnm_notification_msg['response']['errorCode'] if 'errorCode' in cnm_notification_msg[
287+
'response'] else 'unknown',
263288
}, cnm_notification_msg['identifier'])
264289
return
290+
291+
def receive_from_daac(self, event: dict):
292+
LOGGER.debug(f'receive_from_daac#event: {event}')
293+
sns_msg = AwsMessageTransformers().sqs_sns(event)
294+
LOGGER.debug(f'sns_msg: {sns_msg}')
295+
cnm_notification_msg = sns_msg
296+
297+
cnm_msg_schema = requests.get('https://raw.githubusercontent.com/podaac/cloud-notification-message-schema/v1.6.1/cumulus_sns_schema.json')
298+
cnm_msg_schema.raise_for_status()
299+
cnm_msg_schema = json.loads(cnm_msg_schema.text)
300+
result = JsonValidator(cnm_msg_schema).validate(cnm_notification_msg)
301+
if result is not None:
302+
raise ValueError(f'input cnm event has cnm_msg_schema validation errors: {result}')
303+
if 'response' not in cnm_notification_msg:
304+
raise ValueError(f'missing response in {cnm_notification_msg}')
305+
self.update_stac(cnm_notification_msg)
306+
return

requirements.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ certifi==2024.8.30
55
charset-normalizer==3.3.2
66
click==8.1.7
77
dateparser==1.2.0
8-
elasticsearch==7.13.4
98
exceptiongroup==1.2.2
109
fastapi==0.115.0
1110
fastjsonschema==2.20.0
@@ -15,7 +14,7 @@ jsonschema==4.23.0
1514
jsonschema-specifications==2023.12.1
1615
lark==0.12.0
1716
mangum==0.18.0
18-
mdps-ds-lib==1.1.1.dev800
17+
mdps-ds-lib==1.2.0.dev100
1918
pydantic==2.9.2
2019
pydantic_core==2.23.4
2120
pygeofilter==0.2.4
@@ -26,7 +25,7 @@ python-dotenv==1.0.1
2625
pytz==2024.2
2726
referencing==0.35.1
2827
regex==2024.9.11
29-
requests==2.31.0
28+
requests==2.32.5
3029
requests-aws4auth==1.2.3
3130
rpds-py==0.20.0
3231
six==1.16.0
@@ -35,6 +34,6 @@ starlette==0.38.6
3534
tenacity==8.2.3
3635
typing_extensions==4.12.2
3736
tzlocal==5.2
38-
urllib3==1.26.11
37+
urllib3==1.26.20
3938
uvicorn==0.30.6
4039
xmltodict==0.13.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name="cumulus_lambda_functions",
15-
version="9.15.1",
15+
version="9.16.0",
1616
packages=find_packages(),
1717
install_requires=install_requires,
1818
package_data={

tf-module/unity-cumulus/daac_archiver.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ resource "aws_lambda_function" "daac_archiver_response" {
4444
LOG_LEVEL = var.log_level
4545
ES_URL = aws_elasticsearch_domain.uds-es.endpoint
4646
ES_PORT = 443
47+
ARCHIVAL_STATUS_MECHANISM = "UDS" # UDS or FAST_STAC
48+
DS_URL = 'TODO'
49+
SFA_USERNAME = 'TODO'
50+
SFA_PASSWORD = 'TODO'
51+
SFA_AUTH_KEY = 'TODO'
52+
SFA_AUTH_VALUE = 'TODO'
53+
SFA_BEARER_TOKEN = 'TODO'
4754
}
4855
}
4956

0 commit comments

Comments
 (0)