From 44ff1efb1850ee5c903c44629d2d87e026b659c5 Mon Sep 17 00:00:00 2001 From: Kris Stanton Date: Wed, 4 Dec 2024 11:23:28 -0600 Subject: [PATCH] WIP commit on the util for generating ORCA Input JSON #387 --- utils/orca_input_generator/.python-version | 1 + utils/orca_input_generator/config.json | 38 +++++++++ .../generate_orca_input.py | 77 +++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 utils/orca_input_generator/.python-version create mode 100644 utils/orca_input_generator/config.json create mode 100644 utils/orca_input_generator/generate_orca_input.py diff --git a/utils/orca_input_generator/.python-version b/utils/orca_input_generator/.python-version new file mode 100644 index 0000000..c6fa069 --- /dev/null +++ b/utils/orca_input_generator/.python-version @@ -0,0 +1 @@ +venv.3_10_8_validate_orca_backups diff --git a/utils/orca_input_generator/config.json b/utils/orca_input_generator/config.json new file mode 100644 index 0000000..df61eb9 --- /dev/null +++ b/utils/orca_input_generator/config.json @@ -0,0 +1,38 @@ +{ + "restore_to__bucket_name":"csda-cumulus-kris-sbx7894-protected-7894", + + "config": { + "buckets": { + "protected": { + "name": "csda-cumulus-kris-sbx7894-protected-7894", + "type": "protected" + }, + "internal": { + "name": "csda-cumulus-kris-sbx7894-internal-7894", + "type": "internal" + }, + "private": { + "name": "csda-cumulus-kris-sbx7894-private-7894", + "type": "private" + }, + "public": { + "name": "csda-cumulus-kris-sbx7894-public-7894", + "type": "public" + }, + "orca_default": { + "name": "csda-cumulus-cba-uat-orca-archive", + "type": "orca" + } + }, + "fileBucketMaps": [ + { + "regex": "^(\\d{8}_\\d{6}_.+)(?:_\\dB_.+|_thumb.*|_cmr[.]json|_metadata[.]json)$", + "sampleFileName": "20160628_204526_1_0c74_3B_Analytic_DN_metadata.xml", + "bucket": "protected" + } + ], + "s3MultipartChunksizeMb": 200, + "excludedFileExtensions": [], + "asyncOperationId": "e3d8b981-0da4-4cad-84c5-c12d2f1094bc" + } +} \ No newline at end of file diff --git a/utils/orca_input_generator/generate_orca_input.py b/utils/orca_input_generator/generate_orca_input.py new file mode 100644 index 0000000..4499d3a --- /dev/null +++ b/utils/orca_input_generator/generate_orca_input.py @@ -0,0 +1,77 @@ +import sys +import json +from pprint import pprint + +# Resources: +# https://github.com/NASA-IMPACT/csdap-cumulus/issues/387 +# https://github.com/NASA-IMPACT/csdap-cumulus/issues/279#issuecomment-1800344062 + +# Settings +SETTINGS__default_config_json = "config.json" + +print(f'generate_orca_input.py: STARTED') + +# JSON Loader +def load_json_to_dict(file_path): + """ + Loads a JSON file at the given path into a Python dictionary. + + Args: + file_path (str): The path to the JSON file. + + Returns: + dict: The loaded data as a dictionary. + """ + with open(file_path, 'r') as f: + data = json.load(f) + return data + + + +# Code to Actually Generate JSON Input for recovery Granules +def generate_orca_recovery_json__v1(config_dict={}): + print(f' generate_orca_recovery_json__v1: Started') + ret_dict = {} + + ret_dict['payload'] = "TODO: Make an Object that goes here, it is a list of granules - May have to make this specific to the dataset or collection type" + ret_dict['config'] = config_dict['config'] + + print(f' generate_orca_recovery_json__v1: Reached the End') + return ret_dict + + + +# Main Entry Point +def main(): + + if len(sys.argv) > 1: + input_config_json_file = sys.argv[1] + else: + input_config_json_file = SETTINGS__default_config_json + + print(f'') + print(f'input_config_json_file: {input_config_json_file}') + print(f'') + # + # Load the Config Dictionary + print(f'Loading the Config Dictionary') + config_dict = load_json_to_dict(input_config_json_file) + print(f'config_dict: {config_dict}') + print(f'') + + # Generate ORCA Recovery Input JSON from Config Dictonary + print(f'Generating the ORCA Recovery JSON') + orca_recoveery_json__v1 = generate_orca_recovery_json__v1(config_dict=config_dict) + print(f'orca_recoveery_json__v1: (Next Lines)') + pprint(orca_recoveery_json__v1) + print(f'') + + + +main() + +# Example usage: +#data = load_json_to_dict("config.json") +#print(data) + +print(f'generate_orca_input.py: Reached the End!') \ No newline at end of file