This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git
The following commit(s) were added to refs/heads/master by this push:
new 5d67f01 Allow views that generate input files to pass them to create
experiment
5d67f01 is described below
commit 5d67f01d4c904659e294b9bf3d6ec6ed84bb1624
Author: Marcus Christie <[email protected]>
AuthorDate: Mon Apr 22 16:50:15 2019 -0400
Allow views that generate input files to pass them to create experiment
---
django_airavata/apps/api/datastore.py | 64 ++++++++++++++++------
.../js/containers/CreateExperimentContainer.vue | 10 +++-
.../js/entry-create-experiment.js | 9 ++-
.../create_experiment.html | 2 +-
django_airavata/apps/workspace/views.py | 23 +++++++-
5 files changed, 85 insertions(+), 23 deletions(-)
diff --git a/django_airavata/apps/api/datastore.py
b/django_airavata/apps/api/datastore.py
index e14a154..b1cde6c 100644
--- a/django_airavata/apps/api/datastore.py
+++ b/django_airavata/apps/api/datastore.py
@@ -53,24 +53,7 @@ def save(username, project_name, experiment_name, file):
input_file_name = experiment_data_storage.save(file_path, file)
input_file_fullpath = experiment_data_storage.path(input_file_name)
# Create DataProductModel instance with DataReplicaLocationModel
- data_product = DataProductModel()
- data_product.gatewayId = settings.GATEWAY_ID
- data_product.ownerName = username
- data_product.productName = file_name
- data_product.dataProductType = DataProductType.FILE
- data_replica_location = DataReplicaLocationModel()
- data_replica_location.storageResourceId = \
- settings.GATEWAY_DATA_STORE_RESOURCE_ID
- data_replica_location.replicaName = \
- "{} gateway data store copy".format(file_name)
- data_replica_location.replicaLocationCategory = \
- ReplicaLocationCategory.GATEWAY_DATA_STORE
- data_replica_location.replicaPersistentType = \
- ReplicaPersistentType.TRANSIENT
- data_replica_location.filePath = \
- "file://{}:{}".format(settings.GATEWAY_DATA_STORE_HOSTNAME,
- input_file_fullpath)
- data_product.replicaLocations = [data_replica_location]
+ data_product = _create_data_product(username, input_file_fullpath)
return data_product
@@ -110,6 +93,28 @@ def get_experiment_dir(username, project_name,
experiment_name):
return experiment_dir
+def user_file_exists(username, file_path):
+ """Check if file path exists in user's data storage space."""
+ try:
+ return experiment_data_storage.exists(
+ os.path.join(username, file_path))
+ except SuspiciousFileOperation as e:
+ logger.warning(
+ "File does not exist for user {} at file path {}".format(
+ username, file_path))
+ return False
+
+
+def get_data_product(username, file_path):
+ """Get a DataProduct instance for file in user's data storage space."""
+ if user_file_exists(username, file_path):
+ full_path = experiment_data_storage.path(
+ os.path.join(username, file_path))
+ return _create_data_product(username, full_path)
+ else:
+ raise ObjectDoesNotExist("User file does not exist")
+
+
def _get_replica_filepath(data_product):
replica_filepaths = [rep.filePath
for rep in data_product.replicaLocations
@@ -120,3 +125,26 @@ def _get_replica_filepath(data_product):
if replica_filepath:
return urlparse(replica_filepath).path
return None
+
+
+def _create_data_product(username, full_path):
+ data_product = DataProductModel()
+ data_product.gatewayId = settings.GATEWAY_ID
+ data_product.ownerName = username
+ file_name = os.path.basename(full_path)
+ data_product.productName = file_name
+ data_product.dataProductType = DataProductType.FILE
+ data_replica_location = DataReplicaLocationModel()
+ data_replica_location.storageResourceId = \
+ settings.GATEWAY_DATA_STORE_RESOURCE_ID
+ data_replica_location.replicaName = \
+ "{} gateway data store copy".format(file_name)
+ data_replica_location.replicaLocationCategory = \
+ ReplicaLocationCategory.GATEWAY_DATA_STORE
+ data_replica_location.replicaPersistentType = \
+ ReplicaPersistentType.TRANSIENT
+ data_replica_location.filePath = \
+ "file://{}:{}".format(settings.GATEWAY_DATA_STORE_HOSTNAME,
+ full_path)
+ data_product.replicaLocations = [data_replica_location]
+ return data_product
diff --git
a/django_airavata/apps/workspace/static/django_airavata_workspace/js/containers/CreateExperimentContainer.vue
b/django_airavata/apps/workspace/static/django_airavata_workspace/js/containers/CreateExperimentContainer.vue
index 9666f90..c7f7d0b 100644
---
a/django_airavata/apps/workspace/static/django_airavata_workspace/js/containers/CreateExperimentContainer.vue
+++
b/django_airavata/apps/workspace/static/django_airavata_workspace/js/containers/CreateExperimentContainer.vue
@@ -20,7 +20,7 @@ import moment from "moment";
export default {
name: "create-experiment-container",
- props: ["app-module-id"],
+ props: ["app-module-id", "user-input-files"],
data() {
return {
experiment: null,
@@ -56,6 +56,14 @@ export default {
{ ignoreErrors: true }
).then(appInterface => {
experiment.populateInputsOutputsFromApplicationInterface(appInterface);
+ if (this.userInputFiles) {
+ Object.keys(this.userInputFiles).forEach(k => {
+ const experimentInput = experiment.experimentInputs.find(inp =>
inp.name === k);
+ if (experimentInput) {
+ experimentInput.value = this.userInputFiles[k];
+ }
+ })
+ }
experiment.executionId = appInterface.applicationInterfaceId;
});
Promise.all([loadAppModule, loadAppInterface])
diff --git
a/django_airavata/apps/workspace/static/django_airavata_workspace/js/entry-create-experiment.js
b/django_airavata/apps/workspace/static/django_airavata_workspace/js/entry-create-experiment.js
index 82099a1..386d665 100644
---
a/django_airavata/apps/workspace/static/django_airavata_workspace/js/entry-create-experiment.js
+++
b/django_airavata/apps/workspace/static/django_airavata_workspace/js/entry-create-experiment.js
@@ -7,20 +7,25 @@ entry(Vue => {
return h(components.MainLayout, [
h(CreateExperimentContainer, {
props: {
- appModuleId: this.appModuleId
+ appModuleId: this.appModuleId,
+ userInputFiles: this.userInputFiles
}
})
]);
},
data() {
return {
- appModuleId: null
+ appModuleId: null,
+ userInputFiles: null
};
},
beforeMount() {
if (this.$el.dataset.appModuleId) {
this.appModuleId = this.$el.dataset.appModuleId;
}
+ if (this.$el.dataset.userInputFiles) {
+ this.userInputFiles = JSON.parse(this.$el.dataset.userInputFiles);
+ }
}
}).$mount("#create-experiment");
});
diff --git
a/django_airavata/apps/workspace/templates/django_airavata_workspace/create_experiment.html
b/django_airavata/apps/workspace/templates/django_airavata_workspace/create_experiment.html
index b316f03..327d5a3 100644
---
a/django_airavata/apps/workspace/templates/django_airavata_workspace/create_experiment.html
+++
b/django_airavata/apps/workspace/templates/django_airavata_workspace/create_experiment.html
@@ -2,6 +2,6 @@
{% block content %}
-<div id="{{ bundle_name }}" data-app-module-id="{{ app_module_id }}"></div>
+<div id="{{ bundle_name }}" data-app-module-id="{{ app_module_id }}"
data-user-input-files="{{ user_input_files }}"></div>
{% endblock content %}
diff --git a/django_airavata/apps/workspace/views.py
b/django_airavata/apps/workspace/views.py
index a1c8c7a..5a8f0fb 100644
--- a/django_airavata/apps/workspace/views.py
+++ b/django_airavata/apps/workspace/views.py
@@ -11,6 +11,7 @@ from django.http import JsonResponse
from django.shortcuts import render
from rest_framework.renderers import JSONRenderer
+from airavata.model.application.io.ttypes import DataType
from airavata.model.data.replica.ttypes import (
DataProductModel,
DataProductType,
@@ -18,7 +19,9 @@ from airavata.model.data.replica.ttypes import (
ReplicaLocationCategory,
ReplicaPersistentType
)
+from django_airavata.apps.api import datastore
from django_airavata.apps.api.views import (
+ ApplicationModuleViewSet,
ExperimentSearchViewSet,
FullExperimentViewSet,
ProjectViewSet
@@ -65,10 +68,28 @@ def projects_list(request):
def create_experiment(request, app_module_id):
request.active_nav_item = 'dashboard'
+ # User input files can be passed as query parameters
+ # <input name>=<path/to/user_file>
+ app_interface = ApplicationModuleViewSet.as_view(
+ {'get': 'application_interface'})(request, app_module_id=app_module_id)
+ user_input_files = {}
+ for app_input in app_interface.data['applicationInputs']:
+ if (app_input['type'] ==
+ DataType.URI and app_input['name'] in request.GET):
+ user_file_path = request.GET[app_input['name']]
+ if datastore.user_file_exists(
+ request.user.username, user_file_path):
+ data_product = datastore.get_data_product(
+ request.user.username, user_file_path)
+ data_product_uri = request.airavata_client.registerDataProduct(
+ request.authz_token, data_product)
+ user_input_files[app_input['name']] = data_product_uri
+
return render(request,
'django_airavata_workspace/create_experiment.html',
{'bundle_name': 'create-experiment',
- 'app_module_id': app_module_id})
+ 'app_module_id': app_module_id,
+ 'user_input_files': json.dumps(user_input_files)})
@login_required