Skip to content
Permalink
Browse files
AIRAVATA-3420 Adding resource id to UserFiles model
  • Loading branch information
machristie committed Apr 27, 2021
1 parent c19c2c6 commit 1e4970cd4fecab1e36b63c5fba44d14e67f46762
Showing 3 changed files with 43 additions and 9 deletions.
@@ -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,
),
]
@@ -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 = [
@@ -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,15 +648,16 @@ 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


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()

0 comments on commit 1e4970c

Please sign in to comment.