Skip to content

Commit

Permalink
WIP commit on the util for generating ORCA Input JSON #387
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Stanton committed Dec 4, 2024
1 parent 8ac4951 commit 44ff1ef
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions utils/orca_input_generator/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv.3_10_8_validate_orca_backups
38 changes: 38 additions & 0 deletions utils/orca_input_generator/config.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
77 changes: 77 additions & 0 deletions utils/orca_input_generator/generate_orca_input.py
Original file line number Diff line number Diff line change
@@ -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!')

0 comments on commit 44ff1ef

Please sign in to comment.