diff --git a/a3m/client/clientScripts/a3m_store_aip.py b/a3m/client/clientScripts/a3m_store_aip.py index beb00591..5a1f24a3 100644 --- a/a3m/client/clientScripts/a3m_store_aip.py +++ b/a3m/client/clientScripts/a3m_store_aip.py @@ -8,6 +8,7 @@ from a3m.client import metrics +from pathlib import Path logger = logging.getLogger(__name__) @@ -36,7 +37,13 @@ def _upload_file(path, bucket, key): boto_args.update(config=config) s3 = boto3.resource(**boto_args) - s3.meta.client.upload_file(path, bucket, key) + + # TODO: The S3 path should include a pre-defined directory path for the AIP + # We could use a predefined variable in the configuration file for a global A3M Storage such as predefined/global/path// + # Alternatively, we could use a predefined variable specifically for the AIP location such as predefined/aip/location/ + # In any case, the S3 path must be structured in a way that makes it easy to locate and manage the AIP. + s3_path = key + path.suffix + s3.meta.client.upload_file(str(path), bucket, s3_path) def _store_aip(job, sip_id, aip_path): @@ -51,7 +58,7 @@ def _store_aip(job, sip_id, aip_path): raise Exception("AIP is a directory") logger.info("Uploading AIP...") - _upload_file(str(aip_path), settings.S3_BUCKET, sip_id) + _upload_file(aip_path, settings.S3_BUCKET, sip_id) def call(jobs): @@ -59,5 +66,5 @@ def call(jobs): with transaction.atomic(): with job.JobContext(): sip_id = job.args[1] - aip_path = job.args[2] + aip_path = Path(job.args[2]) job.set_status(_store_aip(job, sip_id, aip_path)) diff --git a/a3m/client/clientScripts/verify_aip.py b/a3m/client/clientScripts/verify_aip.py index b568cb1a..10b46058 100644 --- a/a3m/client/clientScripts/verify_aip.py +++ b/a3m/client/clientScripts/verify_aip.py @@ -226,10 +226,12 @@ def verify_aip(job): file=sys.stderr, ) - aip_path = Path(aip_path) - completed_dir = Path(mcpclient_settings.SHARED_DIRECTORY, "completed") - shutil.move(str(aip_path), str(completed_dir)) - logger.info("AIP generated: %s", aip_path.name) + # Don't move to completed if S3 enabled + if not mcpclient_settings.S3_ENABLED: + aip_path = Path(aip_path) + completed_dir = Path(mcpclient_settings.SHARED_DIRECTORY, "completed") + shutil.move(str(aip_path), str(completed_dir)) + logger.info("AIP generated: %s", aip_path.name) return return_code