Skip to content

Commit

Permalink
DBMISVC-119 - Added async copy/move endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
b32147 committed Aug 19, 2022
1 parent 77b8eb7 commit 80c6dc7
Show file tree
Hide file tree
Showing 12 changed files with 444 additions and 35 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ RUN pip install --no-index \
# and Pip errors out on the mismatches.
-r /requirements.in

# Setup entry scripts
ADD docker-entrypoint-init.d/* /docker-entrypoint-init.d/

# Copy app source
COPY /fileservice /app

Expand Down
7 changes: 7 additions & 0 deletions docker-entrypoint-init.d/45-django-q.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -e

# Create the Django cache table as needed by Q
python ${DBMI_APP_ROOT}/manage.py createcachetable

# Start the Q cluster
python ${DBMI_APP_ROOT}/manage.py qcluster &
14 changes: 12 additions & 2 deletions fileservice/filemaster/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from filemaster.models import CustomUser
from filemaster.models import DownloadLog
from filemaster.models import FileLocation
from filemaster.models import FileOperation

from guardian.admin import GuardedModelAdmin

Expand All @@ -22,7 +23,7 @@ class CustomUserAdmin(admin.ModelAdmin):
admin.site.register(CustomUser, CustomUserAdmin)


class BucketAdmin(admin.ModelAdmin):
class BucketAdmin(GuardedModelAdmin):
list_display = ('name', )


Expand All @@ -34,7 +35,7 @@ class ArchiveFileAdmin(GuardedModelAdmin):
list_display = ('filename', 'uuid', 'creationdate', 'owner')
readonly_fields = ('uuid', 'creationdate')
sortable_by = ('owner', 'creationdate', 'modifydate')
search_fields = ('owner__email', 'owner__username', 'filename', 'metadata', )
search_fields = ('uuid', 'owner__email', 'owner__username', 'filename', 'metadata', )


admin.site.register(ArchiveFile, ArchiveFileAdmin)
Expand Down Expand Up @@ -62,6 +63,15 @@ class DownloadLogAdmin(admin.ModelAdmin):
admin.site.register(DownloadLog, DownloadLogAdmin)


class FileOperationAdmin(admin.ModelAdmin):
fields = ('uuid', 'archivefile', 'task_id', 'creationdate', 'modifydate', 'origin', 'destination', 'origin_location', 'destination_location')
readonly_fields = ('completed', 'task_id', 'uuid', 'creationdate', 'modifydate', 'archivefile', 'origin', 'destination', 'origin_location', 'destination_location')
list_display = ('uuid', 'operation', 'archivefile', 'origin', 'destination', 'completed', 'creationdate', 'modifydate', )
sortable_by = ('creationdate', 'modifydate', 'archivefile', 'origin', 'destination', )

admin.site.register(FileOperation, FileOperationAdmin)


def patch_admin(model, admin_site=None):
"""
Enables version control with full admin integration for a model that has
Expand Down
18 changes: 12 additions & 6 deletions fileservice/filemaster/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from boto.s3.connection import S3Connection
from django.conf import settings

from .models import FileLocation
from .models import ArchiveFile, FileLocation

import logging
log = logging.getLogger(__name__)
Expand Down Expand Up @@ -132,7 +132,10 @@ def signedUrlDownload(archiveFile=None, hours=24):
return False


def awsCopyFile(archive_file, destination, origin):
def awsCopyFile(archive_file_uuid, destination, origin):

# Fetch it
archive_file = ArchiveFile.objects.get(uuid=archive_file_uuid)

# Get the location
location = archive_file.get_location(origin)
Expand Down Expand Up @@ -167,7 +170,7 @@ def awsCopyFile(archive_file, destination, origin):
# Add it
archive_file.locations.add(new_location)

return new_location
return new_location.id


def awsRemoveFile(location):
Expand All @@ -188,7 +191,10 @@ def awsRemoveFile(location):
return True


def awsMoveFile(archive_file, destination, origin):
def awsMoveFile(archive_file_uuid, destination, origin):

# Fetch it
archive_file = ArchiveFile.objects.get(uuid=archive_file_uuid)

# Get the current location
location = archive_file.get_location(origin)
Expand All @@ -197,7 +203,7 @@ def awsMoveFile(archive_file, destination, origin):
return False

# Call other methods
new_location = awsCopyFile(archive_file, destination, origin)
new_location = awsCopyFile(archive_file.uuid, destination, origin)
if new_location:

# File was copied, remove from origin
Expand All @@ -210,7 +216,7 @@ def awsMoveFile(archive_file, destination, origin):
else:
log.error(f'Could not delete original file after move: {archive_file.uuid}')

return new_location
return new_location.id

return False

Expand Down
Loading

0 comments on commit 80c6dc7

Please sign in to comment.