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 2021/01/25 21:00:09 UTC
[airavata-django-portal] branch develop updated: Adding support for
URI_COLLECTION to output view providers
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git
The following commit(s) were added to refs/heads/develop by this push:
new e5f170c Adding support for URI_COLLECTION to output view providers
e5f170c is described below
commit e5f170c1bb005c796246100124f13c0e3d488ae8
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Jan 25 15:59:35 2021 -0500
Adding support for URI_COLLECTION to output view providers
---
django_airavata/apps/api/output_views.py | 40 ++++++++++++++++++--------------
docs/dev/custom_output_view_provider.md | 14 +++++++++++
docs/tutorial/gateways_tutorial.md | 6 ++---
3 files changed, 40 insertions(+), 20 deletions(-)
diff --git a/django_airavata/apps/api/output_views.py b/django_airavata/apps/api/output_views.py
index 4d3eb55..3ba70b1 100644
--- a/django_airavata/apps/api/output_views.py
+++ b/django_airavata/apps/api/output_views.py
@@ -3,6 +3,7 @@ import inspect
import json
import logging
import os
+from functools import partial
import nbformat
import papermill as pm
@@ -26,7 +27,8 @@ class DefaultViewProvider:
request,
experiment_output,
experiment,
- output_file=None):
+ output_file=None,
+ **kwargs):
return {
}
@@ -191,28 +193,32 @@ def _generate_data(request,
**kwargs):
# TODO: handle URI_COLLECTION also
logger.debug("getting data product for {}".format(experiment_output.value))
- output_file = None
- test_output_file = getattr(output_view_provider,
- 'test_output_file',
- None)
+ output_files = []
if (experiment_output.value and
experiment_output.type in (DataType.URI,
+ DataType.URI_COLLECTION,
DataType.STDOUT,
DataType.STDERR) and
experiment_output.value.startswith("airavata-dp")):
- data_product = request.airavata_client.getDataProduct(
- request.authz_token, experiment_output.value)
- if user_storage.exists(request, data_product):
- output_file = user_storage.open_file(request, data_product)
- elif settings.DEBUG and test_output_file is not None:
- output_file = open(test_output_file, 'rb')
- # TODO: change interface to provide output_file as a path
+ data_product_uris = experiment_output.value.split(",")
+ data_products = map(lambda dpid:
+ request.airavata_client.getDataProduct(request.authz_token,
+ dpid),
+ data_product_uris)
+ for data_product in data_products:
+ if user_storage.exists(request, data_product):
+ output_file = user_storage.open_file(request, data_product)
+ output_files.append(output_file)
+ generate_data_func = output_view_provider.generate_data
+ method_sig = inspect.signature(generate_data_func)
+ if 'output_files' in method_sig.parameters:
+ generate_data_func = partial(generate_data_func, output_files=output_files)
# TODO: convert experiment and experiment_output to dict/JSON
- data = output_view_provider.generate_data(request,
- experiment_output,
- experiment,
- output_file=output_file,
- **kwargs)
+ data = generate_data_func(request,
+ experiment_output,
+ experiment,
+ output_file=output_files[0] if len(output_files) > 0 else None,
+ **kwargs)
_process_interactive_params(data)
return data
diff --git a/docs/dev/custom_output_view_provider.md b/docs/dev/custom_output_view_provider.md
index c1b396a..63bea39 100644
--- a/docs/dev/custom_output_view_provider.md
+++ b/docs/dev/custom_output_view_provider.md
@@ -89,6 +89,20 @@ def generate_data(self, request, experiment_output, experiment, output_file=None
}
```
+For the output view provider to work with experiment outputs of type
+URI_COLLECTION, add `output_files=None` to the function signature and get the
+output as a list of file objects.
+
+```python
+# For URI_COLLECTION, add output_files=None to signature
+def generate_data(self, request, experiment_output, experiment, output_files=None, **kwargs):
+
+ # Return a dictionary
+ return {
+ #...
+ }
+```
+
The required contents of the dictionary varies based on the _display type_.
#### Display type link
diff --git a/docs/tutorial/gateways_tutorial.md b/docs/tutorial/gateways_tutorial.md
index 2cde8d1..65e2b72 100644
--- a/docs/tutorial/gateways_tutorial.md
+++ b/docs/tutorial/gateways_tutorial.md
@@ -444,7 +444,7 @@ class GaussianEigenvaluesViewProvider:
which should be the image's mime type. Here's the `generate_data` function:
```python
- def generate_data(self, request, experiment_output, experiment, output_file=None):
+ def generate_data(self, request, experiment_output, experiment, output_file=None, **kwargs):
# Parse output_file
output_text = io.TextIOWrapper(output_file)
gaussian = ccopen(output_text)
@@ -512,7 +512,7 @@ class GaussianEigenvaluesViewProvider:
display_type = 'image'
name = "Gaussian Eigenvalues"
- def generate_data(self, request, experiment_output, experiment, output_file=None):
+ def generate_data(self, request, experiment_output, experiment, output_file=None, **kwargs):
# Parse output_file
output_text = io.TextIOWrapper(output_file)
@@ -636,7 +636,7 @@ grid as an example.
parameter with a default value of `False`:
```python
- def generate_data(self, request, experiment_output, experiment, output_file=None, show_grid=False):
+ def generate_data(self, request, experiment_output, experiment, output_file=None, show_grid=False, **kwargs):
```
2. Add the following `.grid()` lines to the matplotlib code: