This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch mft-integration
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal-sdk.git
The following commit(s) were added to refs/heads/mft-integration by this push:
new 1e4970c AIRAVATA-3420 Adding resource id to UserFiles model
1e4970c is described below
commit 1e4970cd4fecab1e36b63c5fba44d14e67f46762
Author: Marcus Christie <[email protected]>
AuthorDate: Tue Apr 27 12:57:59 2021 -0400
AIRAVATA-3420 Adding resource id to UserFiles model
---
.../migrations/0002_userfiles_file_resource_id.py | 29 ++++++++++++++++++++++
airavata_django_portal_sdk/models.py | 4 +++
airavata_django_portal_sdk/user_storage/api.py | 19 +++++++-------
3 files changed, 43 insertions(+), 9 deletions(-)
diff --git
a/airavata_django_portal_sdk/migrations/0002_userfiles_file_resource_id.py
b/airavata_django_portal_sdk/migrations/0002_userfiles_file_resource_id.py
new file mode 100644
index 0000000..57c1244
--- /dev/null
+++ b/airavata_django_portal_sdk/migrations/0002_userfiles_file_resource_id.py
@@ -0,0 +1,29 @@
+# Generated by Django 2.2.17 on 2021-04-27 11:42
+
+from django.db import migrations, models
+
+
+def delete_user_file_entries(apps, schema_editor):
+ # UserFiles table is just a cache of generated Data Product URIs for files
+ # in directory listings. We can wipe it out safely. The existing entries
+ # need to be deleted because this migration adds a new non-nullable field,
+ # file_resource_id, and there's no good default for existing entries.
+ UserFiles = apps.get_model('airavata_django_portal_sdk', 'UserFiles')
+ UserFiles.objects.all().delete()
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('airavata_django_portal_sdk', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.RunPython(delete_user_file_entries,
migrations.RunPython.noop),
+ migrations.AddField(
+ model_name='userfiles',
+ name='file_resource_id',
+ field=models.CharField(default='default', max_length=255),
+ preserve_default=False,
+ ),
+ ]
diff --git a/airavata_django_portal_sdk/models.py
b/airavata_django_portal_sdk/models.py
index a39f5dd..f294343 100644
--- a/airavata_django_portal_sdk/models.py
+++ b/airavata_django_portal_sdk/models.py
@@ -6,6 +6,10 @@ class UserFiles(models.Model):
username = models.CharField(max_length=64)
file_path = models.TextField()
file_dpu = models.CharField(max_length=255, primary_key=True)
+ # resource id is either the (legacy) storage resource id that has an
+ # associated storage preference in the Gateway Resource Profile, or a
+ # resource id to a resource defined in MFT
+ file_resource_id = models.CharField(max_length=255)
class Meta:
indexes = [
diff --git a/airavata_django_portal_sdk/user_storage/api.py
b/airavata_django_portal_sdk/user_storage/api.py
index 16e0786..6ca2324 100644
--- a/airavata_django_portal_sdk/user_storage/api.py
+++ b/airavata_django_portal_sdk/user_storage/api.py
@@ -177,7 +177,7 @@ def move(request, data_product=None, path=None,
data_product_uri=None, storage_r
data_product_copy = _save_copy_of_data_product(request, full_path,
data_product, storage_resource_id)
# Remove the source file and data product metadata
source_backend.delete(source_path)
- _delete_data_product(data_product.ownerName, source_path)
+ _delete_data_product(data_product.ownerName, source_path,
storage_resource_id=source_storage_resource_id)
return data_product_copy
@@ -415,7 +415,7 @@ def delete(request, data_product=None,
data_product_uri=None):
backend = get_user_storage_provider(request,
storage_resource_id=storage_resource_id)
try:
backend.delete(path)
- _delete_data_product(data_product.ownerName, path)
+ _delete_data_product(data_product.ownerName, path,
storage_resource_id)
except Exception:
logger.exception(
"Unable to delete file {} for data product uri {}".format(
@@ -612,7 +612,7 @@ def _get_data_product_uri(request, full_path,
storage_resource_id, owner=None, b
if owner is None:
owner = request.user.username
user_file = models.UserFiles.objects.filter(
- username=owner, file_path=full_path)
+ username=owner, file_path=full_path,
file_resource_id=storage_resource_id)
if user_file.exists():
product_uri = user_file[0].file_dpu
else:
@@ -633,12 +633,12 @@ def _save_data_product(request, full_path,
storage_resource_id, name=None, conte
data_product = _create_data_product(
owner, full_path, storage_resource_id, name=name,
content_type=content_type, backend=backend
)
- product_uri = _register_data_product(request, full_path, data_product,
owner=owner)
+ product_uri = _register_data_product(request, full_path, data_product,
storage_resource_id, owner=owner)
data_product.productUri = product_uri
return data_product
-def _register_data_product(request, full_path, data_product, owner=None):
+def _register_data_product(request, full_path, data_product,
storage_resource_id, owner=None):
if owner is None:
owner = request.user.username
product_uri = request.airavata_client.registerDataProduct(
@@ -648,7 +648,8 @@ def _register_data_product(request, full_path,
data_product, owner=None):
user_file_instance = models.UserFiles(
username=owner,
file_path=full_path,
- file_dpu=product_uri)
+ file_dpu=product_uri,
+ file_resource_id=storage_resource_id)
user_file_instance.save()
return product_uri
@@ -656,7 +657,7 @@ def _register_data_product(request, full_path,
data_product, owner=None):
def _save_copy_of_data_product(request, full_path, data_product,
storage_resource_id):
"""Save copy of a data product with a different path."""
data_product_copy = _copy_data_product(request, data_product, full_path,
storage_resource_id)
- product_uri = _register_data_product(request, full_path, data_product_copy)
+ product_uri = _register_data_product(request, full_path,
data_product_copy, storage_resource_id)
data_product_copy.productUri = product_uri
return data_product_copy
@@ -673,12 +674,12 @@ def _copy_data_product(request, data_product, full_path,
storage_resource_id):
return data_product_copy
-def _delete_data_product(username, full_path):
+def _delete_data_product(username, full_path, storage_resource_id):
# TODO: call API to delete data product from replica catalog when it is
# available (not currently implemented)
from airavata_django_portal_sdk import models
user_file = models.UserFiles.objects.filter(
- username=username, file_path=full_path)
+ username=username, file_path=full_path,
file_resource_id=storage_resource_id)
if user_file.exists():
user_file.delete()