-
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: Adding DAAC archive config (#396)
* chore: method to subscribe to sns from sqs * feat: adding infrastructure for archive daac * feat: adding percolator * feat: add method to migrate data * feat: add migration logic to the real code * chore: move granules index to correct location * feat: (in progress) adding daac config crud ops * feat: finished adding CRUDS for daac config * fix: need to authorizer if user is authorized for current collection + set tenant & venue for DB * fix: updating errors based on testcase * fix: adding log statement * fix: mistaken perc alias v. normal alias * fix: saved search are not in correct place in mapping * chore: adding log statement to see the problem * fix: add it at the correct place * fix: add test case + update errors based on those * fix: add missing columns for daac archiving * fix: file extension can be an array * fix: update testcase + fix bugs * fix: update test case
- Loading branch information
Showing
28 changed files
with
964 additions
and
10 deletions.
There are no files selected for viewing
Empty file.
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,13 @@ | ||
from cumulus_lambda_functions.lib.lambda_logger_generator import LambdaLoggerGenerator | ||
|
||
|
||
def lambda_handler(event, context): | ||
""" | ||
:param event: | ||
:param context: | ||
:return: | ||
{'Records': [{'messageId': '6ff7c6fd-4053-4ab4-bc12-c042be1ed275', 'receiptHandle': 'AQEBYASiFPjQT5JBI2KKCTF/uQhHfJt/tHhgucslQQdvkNVxcXCNi2E5Ux4U9N0eu7RfvlnvtycjUh0gdL7jIeoyH+VRKSF61uAJuT4p31BsNe0GYu49N9A6+kxjP/RrykR7ZofmQRdHToX1ugRc76SMRic4H/ZZ89YAHA2QeomJFMrYywIxlk8OAzYaBf2dQI7WexjY5u1CW00XNMbTGyTo4foVPxcSn6bdFpfgxW/L7yJMX/0YQvrA9ruiuQ+lrui+6fWYh5zEk3f5v1bYtUQ6DtyyfbtMHZQJTJpUlWAFRzzN+3melilH7FySyOGDXhPb0BOSzmdKq9wBbfLW/YPb7l99ejq4GfRfj8LyI4EtB96vTeUw4LCgUqbZcBrxbGBLUXMacweh+gCjHav9ylqr2SeOiqG3vWPq9pwFYQIDqNE=', 'body': '{\n "Type" : "Notification",\n "MessageId" : "33e1075a-435c-5217-a33d-59fae85e19b2",\n "TopicArn" : "arn:aws:sns:us-west-2:237868187491:uds-sbx-cumulus-granules_cnm_ingester",\n "Subject" : "Amazon S3 Notification",\n "Message" : "{\\"Service\\":\\"Amazon S3\\",\\"Event\\":\\"s3:TestEvent\\",\\"Time\\":\\"2024-04-22T18:13:22.416Z\\",\\"Bucket\\":\\"uds-sbx-cumulus-staging\\",\\"RequestId\\":\\"DQ4T0GRVFPSX45C9\\",\\"HostId\\":\\"gHBFnYNmfnGDZBmqoQwA3RScjtjBk5lr426moGxu8IDpe5UhWAqNTxHqilWBoPN1njzIrzNrf8c=\\"}",\n "Timestamp" : "2024-04-22T18:13:22.434Z",\n "SignatureVersion" : "1",\n "Signature" : "RvSxqpU7J7CCJXbin9cXqTxzjMjgAUFtk/n454mTMcOe5x3Ay1w4AHfzyeYQCFBdLHNBa8n3OdMDoDlJqyVQMb8k+nERaiZWN2oqFVDRqT9pqSr89b+4FwlhPv6TYy2pBa/bgjZ4cOSYsey1uSQ3hjl0idfssvuV5cCRxQScbA+yu8Gcv9K7Oqgy01mC0sDHiuPIifhFXxupG5ygbjqoHIB+1gdMEbBwyixoY5GOpHM/O2uHNF+dJDjax1WMxQ2FzVjiFeCa+tNcjovF059+tx2v1YmDq/kEAFrN6DAtP6R4zKag62P9jkvjU/wHYJ2jjXmZAqoG+nuzAo24HiZPSw==",\n "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-60eadc530605d63b8e62a523676ef735.pem",\n "UnsubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:237868187491:uds-sbx-cumulus-granules_cnm_ingester:76cbefa1-addf-45c2-97e1-ae16986b195b"\n}', 'attributes': {'ApproximateReceiveCount': '1', 'SentTimestamp': '1713809602474', 'SenderId': 'AIDAIYLAVTDLUXBIEIX46', 'ApproximateFirstReceiveTimestamp': '1713809602483'}, 'messageAttributes': {}, 'md5OfBody': 'c6d06d1b742ad5bd2cfe5f542640aad2', 'eventSource': 'aws:sqs', 'eventSourceARN': 'arn:aws:sqs:us-west-2:237868187491:uds-sbx-cumulus-granules_cnm_ingester', 'awsRegion': 'us-west-2'}]} | ||
""" | ||
LambdaLoggerGenerator.remove_default_handlers() | ||
print('To be implemented later') | ||
return |
24 changes: 24 additions & 0 deletions
24
cumulus_lambda_functions/granules_to_es/granules_index_mapping.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
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
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
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,95 @@ | ||
from cumulus_lambda_functions.lib.json_validator import JsonValidator | ||
|
||
from cumulus_lambda_functions.lib.uds_db.db_constants import DBConstants | ||
|
||
from cumulus_lambda_functions.lib.aws.es_abstract import ESAbstract | ||
|
||
from cumulus_lambda_functions.lib.aws.es_factory import ESFactory | ||
|
||
|
||
class UdsArchiveConfigIndex: | ||
basic_schema = { | ||
'type': 'object', | ||
'required': ['daac_collection_id', 'daac_sns_topic_arn', 'daac_data_version', 'collection', 'ss_username', 'archiving_types'], | ||
'properties': { | ||
'daac_collection_id': {'type': 'string'}, | ||
'daac_sns_topic_arn': {'type': 'string'}, | ||
'daac_data_version': {'type': 'string'}, | ||
'collection': {'type': 'string'}, | ||
'ss_username': {'type': 'string'}, | ||
'archiving_types': {'type': 'array', 'items': {'type': 'object'}}, | ||
} | ||
} | ||
def __init__(self, es_url, es_port=443): | ||
self.__es: ESAbstract = ESFactory().get_instance('AWS', | ||
index='TODO', | ||
base_url=es_url, | ||
port=es_port) | ||
self.__tenant, self.__venue = '', '' | ||
|
||
def set_tenant_venue(self, tenant, venue): | ||
self.__tenant, self.__venue = tenant, venue | ||
return self | ||
|
||
def get_config(self, collection_id, username=None): | ||
read_alias_name = f'{DBConstants.granules_read_alias_prefix}_{self.__tenant}_{self.__venue}_perc'.lower().strip() | ||
conditions = [{"term": {"collection": {"value": collection_id}}}] | ||
if username is not None: | ||
conditions.append({"term": {"ss_username": {"value": username}}}) | ||
result = self.__es.query({ | ||
'size': 9999, | ||
'query': { | ||
'bool': { | ||
'must': conditions | ||
} | ||
} | ||
}, read_alias_name) | ||
return [k['_source'] for k in result['hits']['hits']] | ||
|
||
def add_new_config(self, ingesting_dict: dict): | ||
result = JsonValidator(self.basic_schema).validate(ingesting_dict) | ||
if result is not None: | ||
raise ValueError(f'input ingesting_dict has basic_schema validation errors: {result}') | ||
write_alias_name = f'{DBConstants.granules_write_alias_prefix}_{self.__tenant}_{self.__venue}_perc'.lower().strip() | ||
ingesting_dict['daac_collection_name'] = ingesting_dict.pop('daac_collection_id') | ||
ingesting_dict['ss_query'] = { | ||
"bool": { | ||
"must": [{ | ||
"term": {"collection": {"value": ingesting_dict['collection']} } | ||
}] | ||
} | ||
} | ||
result = self.__es.index_one(ingesting_dict, f"{ingesting_dict['daac_collection_name']}__{ingesting_dict['collection']}", index=write_alias_name) | ||
return | ||
|
||
def delete_config(self, collection_id, daac_collection_id): | ||
write_alias_name = f'{DBConstants.granules_write_alias_prefix}_{self.__tenant}_{self.__venue}_perc'.lower().strip() | ||
self.__es.delete_by_query({ | ||
'size': 9999, | ||
'query': { | ||
'bool': { | ||
'must': [ | ||
{ "term": {"collection": {"value": collection_id}} }, | ||
{"term": {"daac_collection_name": {"value": daac_collection_id}}}, | ||
] | ||
} | ||
} | ||
}, write_alias_name) | ||
return | ||
|
||
def update_config(self, collection_id, daac_collection_id, daac_sns_topic_arn, username): | ||
write_alias_name = f'{DBConstants.granules_write_alias_prefix}_{self.__tenant}_{self.__venue}_perc'.lower().strip() | ||
result = self.__es.update_one({ | ||
"collection": collection_id, | ||
"daac_collection_name": daac_collection_id, | ||
"daac_sns_topic_arn": daac_sns_topic_arn, | ||
"ss_query": { | ||
"bool": { | ||
"must": [{ | ||
"term": {"collection": {"value": collection_id}} | ||
}] | ||
} | ||
}, | ||
"ss_username": username, | ||
}, f'{daac_collection_id}__{collection_id}', index=write_alias_name) | ||
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
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.
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,13 @@ | ||
from cumulus_lambda_functions.lib.lambda_logger_generator import LambdaLoggerGenerator | ||
|
||
|
||
def lambda_handler(event, context): | ||
""" | ||
:param event: | ||
:param context: | ||
:return: | ||
{'Records': [{'messageId': '6ff7c6fd-4053-4ab4-bc12-c042be1ed275', 'receiptHandle': 'AQEBYASiFPjQT5JBI2KKCTF/uQhHfJt/tHhgucslQQdvkNVxcXCNi2E5Ux4U9N0eu7RfvlnvtycjUh0gdL7jIeoyH+VRKSF61uAJuT4p31BsNe0GYu49N9A6+kxjP/RrykR7ZofmQRdHToX1ugRc76SMRic4H/ZZ89YAHA2QeomJFMrYywIxlk8OAzYaBf2dQI7WexjY5u1CW00XNMbTGyTo4foVPxcSn6bdFpfgxW/L7yJMX/0YQvrA9ruiuQ+lrui+6fWYh5zEk3f5v1bYtUQ6DtyyfbtMHZQJTJpUlWAFRzzN+3melilH7FySyOGDXhPb0BOSzmdKq9wBbfLW/YPb7l99ejq4GfRfj8LyI4EtB96vTeUw4LCgUqbZcBrxbGBLUXMacweh+gCjHav9ylqr2SeOiqG3vWPq9pwFYQIDqNE=', 'body': '{\n "Type" : "Notification",\n "MessageId" : "33e1075a-435c-5217-a33d-59fae85e19b2",\n "TopicArn" : "arn:aws:sns:us-west-2:237868187491:uds-sbx-cumulus-granules_cnm_ingester",\n "Subject" : "Amazon S3 Notification",\n "Message" : "{\\"Service\\":\\"Amazon S3\\",\\"Event\\":\\"s3:TestEvent\\",\\"Time\\":\\"2024-04-22T18:13:22.416Z\\",\\"Bucket\\":\\"uds-sbx-cumulus-staging\\",\\"RequestId\\":\\"DQ4T0GRVFPSX45C9\\",\\"HostId\\":\\"gHBFnYNmfnGDZBmqoQwA3RScjtjBk5lr426moGxu8IDpe5UhWAqNTxHqilWBoPN1njzIrzNrf8c=\\"}",\n "Timestamp" : "2024-04-22T18:13:22.434Z",\n "SignatureVersion" : "1",\n "Signature" : "RvSxqpU7J7CCJXbin9cXqTxzjMjgAUFtk/n454mTMcOe5x3Ay1w4AHfzyeYQCFBdLHNBa8n3OdMDoDlJqyVQMb8k+nERaiZWN2oqFVDRqT9pqSr89b+4FwlhPv6TYy2pBa/bgjZ4cOSYsey1uSQ3hjl0idfssvuV5cCRxQScbA+yu8Gcv9K7Oqgy01mC0sDHiuPIifhFXxupG5ygbjqoHIB+1gdMEbBwyixoY5GOpHM/O2uHNF+dJDjax1WMxQ2FzVjiFeCa+tNcjovF059+tx2v1YmDq/kEAFrN6DAtP6R4zKag62P9jkvjU/wHYJ2jjXmZAqoG+nuzAo24HiZPSw==",\n "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-60eadc530605d63b8e62a523676ef735.pem",\n "UnsubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:237868187491:uds-sbx-cumulus-granules_cnm_ingester:76cbefa1-addf-45c2-97e1-ae16986b195b"\n}', 'attributes': {'ApproximateReceiveCount': '1', 'SentTimestamp': '1713809602474', 'SenderId': 'AIDAIYLAVTDLUXBIEIX46', 'ApproximateFirstReceiveTimestamp': '1713809602483'}, 'messageAttributes': {}, 'md5OfBody': 'c6d06d1b742ad5bd2cfe5f542640aad2', 'eventSource': 'aws:sqs', 'eventSourceARN': 'arn:aws:sqs:us-west-2:237868187491:uds-sbx-cumulus-granules_cnm_ingester', 'awsRegion': 'us-west-2'}]} | ||
""" | ||
LambdaLoggerGenerator.remove_default_handlers() | ||
print('To be implemented later') | ||
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
Oops, something went wrong.