You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2019/05/28 13:22:34 UTC
[airavata-django-portal] 04/06: AIRAVATA-3032 Copy cloned input
files to tmp input file dir
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch airavata-3016
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git
commit a63fd110934186914b22d3dc2778832e0bdff371
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon May 27 17:24:38 2019 -0400
AIRAVATA-3032 Copy cloned input files to tmp input file dir
---
django_airavata/apps/api/data_products_helper.py | 10 +++++
django_airavata/apps/api/datastore.py | 8 ++--
django_airavata/apps/api/views.py | 56 +++++++++++-------------
3 files changed, 39 insertions(+), 35 deletions(-)
diff --git a/django_airavata/apps/api/data_products_helper.py b/django_airavata/apps/api/data_products_helper.py
index b085e87..08ce7e0 100644
--- a/django_airavata/apps/api/data_products_helper.py
+++ b/django_airavata/apps/api/data_products_helper.py
@@ -36,6 +36,16 @@ def save_input_file_upload(request, file):
return data_product
+def copy_input_file_upload(request, data_product):
+ path = _get_replica_filepath(data_product)
+ name = data_product.productName
+ full_path = datastore.copy(request.user.username,
+ path,
+ TMP_INPUT_FILE_UPLOAD_DIR,
+ name=name)
+ return _save_data_product(request, full_path, name=name)
+
+
def is_input_file_upload(request, data_product):
path = _get_replica_filepath(data_product)
rel_path = datastore.rel_path(request.user.username, path)
diff --git a/django_airavata/apps/api/datastore.py b/django_airavata/apps/api/datastore.py
index 2fc0965..6369d22 100644
--- a/django_airavata/apps/api/datastore.py
+++ b/django_airavata/apps/api/datastore.py
@@ -29,10 +29,10 @@ def open(username, path):
raise ObjectDoesNotExist("File path does not exist: {}".format(path))
-def save(username, path, file):
+def save(username, path, file, name=None):
"""Save file to username/path in data store."""
# file.name may be full path, so get just the name of the file
- file_name = os.path.basename(file.name)
+ file_name = name if name is not None else os.path.basename(file.name)
user_data_storage = _user_data_storage(username)
file_path = os.path.join(
path, user_data_storage.get_valid_name(file_name))
@@ -57,10 +57,10 @@ def create_user_dir(username, path):
"Directory {} already exists".format(path))
-def copy(username, source_path, target_path):
+def copy(username, source_path, target_path, name=None):
"""Copy a user file into target_path dir."""
f = open(username, source_path)
- return save(username, target_path, f)
+ return save(username, target_path, f, name=name)
def delete(username, path):
diff --git a/django_airavata/apps/api/views.py b/django_airavata/apps/api/views.py
index 4ec398e..c3e652c 100644
--- a/django_airavata/apps/api/views.py
+++ b/django_airavata/apps/api/views.py
@@ -287,7 +287,9 @@ class ExperimentViewSet(APIBackedViewSet):
# Create a copy of the experiment input files
self._copy_cloned_experiment_input_uris(cloned_experiment)
- self._set_storage_id_and_data_dir(cloned_experiment)
+ # Null out experimentDataDir so a new one will get created at launch
+ # time
+ cloned_experiment.userConfigurationData.experimentDataDir = None
request.airavata_client.updateExperiment(
self.authz_token, cloned_experiment.experimentId, cloned_experiment
)
@@ -322,54 +324,46 @@ class ExperimentViewSet(APIBackedViewSet):
self.authz_token, entity_id, ResourcePermissionType.WRITE)
def _copy_cloned_experiment_input_uris(self, cloned_experiment):
- # update the experimentInputs of type URI, copying files in data store
- request = self.request
- # TODO: create experiment data directory and copy inputs into it
- target_project = request.airavata_client.getProject(
- self.authz_token, cloned_experiment.projectId)
+ # update the experimentInputs of type URI, copying input files into the
+ # tmp input files directory of the data store
for experiment_input in cloned_experiment.experimentInputs:
+ # skip inputs without values
+ if not experiment_input.value:
+ continue
if experiment_input.type == DataType.URI:
- data_product_uri = self._copy_experiment_input_uri(
- experiment_input.value, target_project, cloned_experiment)
- if data_product_uri is None:
+ cloned_data_product = self._copy_experiment_input_uri(
+ experiment_input.value)
+ if cloned_data_product is None:
log.warning("Setting cloned input {} to null".format(
experiment_input.name))
- experiment_input.value = data_product_uri
+ experiment_input.value = None
+ else:
+ experiment_input.value = cloned_data_product.productUri
elif experiment_input.type == DataType.URI_COLLECTION:
data_product_uris = experiment_input.value.split(
",") if experiment_input.value else []
cloned_data_product_uris = []
for data_product_uri in data_product_uris:
- cloned_data_product_uri = self._copy_experiment_input_uri(
- data_product_uri, target_project, cloned_experiment)
- if cloned_data_product_uri is None:
+ cloned_data_product = self._copy_experiment_input_uri(
+ data_product_uri)
+ if cloned_data_product.productUri is None:
log.warning(
"Omitting a cloned input value for {}".format(
experiment_input.name))
else:
cloned_data_product_uris.append(
- cloned_data_product_uri)
+ cloned_data_product.productUri)
experiment_input.value = ",".join(cloned_data_product_uris)
def _copy_experiment_input_uri(
self,
- source_data_product_uri,
- project,
- experiment):
- request = self.request
- source_data_product = request.airavata_client.getDataProduct(
- self.authz_token, source_data_product_uri)
- try:
- copied_data_product = datastore.copy(
- self.username,
- project.name,
- experiment.experimentName,
- source_data_product)
- data_product_uri = \
- request.airavata_client.registerDataProduct(
- self.authz_token, copied_data_product)
- return data_product_uri
- except ObjectDoesNotExist as odne:
+ data_product_uri):
+ source_data_product = self.request.airavata_client.getDataProduct(
+ self.authz_token, data_product_uri)
+ if data_products_helper.exists(self.request, source_data_product):
+ return data_products_helper.copy_input_file_upload(
+ self.request, source_data_product)
+ else:
log.warning("Could not find file for source data "
"product {}".format(source_data_product))
return None