Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create and use constants for landing zone status types #1729

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion irodsadmin/management/commands/irodsorphans.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from projectroles.plugins import get_backend_api

# Landingzones dependency
from landingzones.constants import ZONE_STATUS_MOVED, ZONE_STATUS_DELETED
from landingzones.models import LandingZone

# Samplesheets dependency
Expand Down Expand Up @@ -84,7 +85,7 @@ def get_zone_collections(irods_backend):
return [
irods_backend.get_path(lz)
for lz in LandingZone.objects.filter(
~(Q(status='MOVED') & Q(status='DELETED'))
~(Q(status=ZONE_STATUS_MOVED) & Q(status=ZONE_STATUS_DELETED))
)
]

Expand Down
91 changes: 91 additions & 0 deletions landingzones/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""Constants for the landingzones app"""

# Status types for landing zones
ZONE_STATUS_OK = 'OK'
ZONE_STATUS_CREATING = 'CREATING'
ZONE_STATUS_NOT_CREATED = 'NOT CREATED'
ZONE_STATUS_ACTIVE = 'ACTIVE'
ZONE_STATUS_PREPARING = 'PREPARING'
ZONE_STATUS_VALIDATING = 'VALIDATING'
ZONE_STATUS_MOVING = 'MOVING'
ZONE_STATUS_MOVED = 'MOVED'
ZONE_STATUS_FAILED = 'FAILED'
ZONE_STATUS_DELETING = 'DELETING'
ZONE_STATUS_DELETED = 'DELETED'

ZONE_STATUS_TYPES = [
ZONE_STATUS_CREATING,
ZONE_STATUS_NOT_CREATED,
ZONE_STATUS_ACTIVE,
ZONE_STATUS_PREPARING,
ZONE_STATUS_VALIDATING,
ZONE_STATUS_MOVING,
ZONE_STATUS_MOVED,
ZONE_STATUS_FAILED,
ZONE_STATUS_DELETING,
ZONE_STATUS_DELETED,
]

DEFAULT_STATUS_INFO = {
ZONE_STATUS_CREATING: 'Creating landing zone in iRODS',
ZONE_STATUS_NOT_CREATED: 'Creating landing zone in iRODS failed (unknown problem)',
ZONE_STATUS_ACTIVE: 'Available with write access for user',
ZONE_STATUS_PREPARING: 'Preparing transaction for validation and moving',
ZONE_STATUS_VALIDATING: 'Validation in progress, write access disabled',
ZONE_STATUS_MOVING: 'Validation OK, moving files into sample data repository',
ZONE_STATUS_MOVED: 'Files moved successfully, landing zone removed',
ZONE_STATUS_FAILED: 'Validation/moving failed (unknown problem)',
ZONE_STATUS_DELETING: 'Deleting landing zone',
ZONE_STATUS_DELETED: 'Landing zone deleted',
}
STATUS_INFO_DELETE_NO_COLL = (
'No iRODS collection for zone found, marked as deleted'
)

STATUS_STYLES = {
ZONE_STATUS_CREATING: 'bg-warning',
ZONE_STATUS_NOT_CREATED: 'bg-danger',
ZONE_STATUS_ACTIVE: 'bg-info',
ZONE_STATUS_PREPARING: 'bg-warning',
ZONE_STATUS_VALIDATING: 'bg-warning',
ZONE_STATUS_MOVING: 'bg-warning',
ZONE_STATUS_MOVED: 'bg-success',
ZONE_STATUS_FAILED: 'bg-danger',
ZONE_STATUS_DELETING: 'bg-warning',
ZONE_STATUS_DELETED: 'bg-secondary',
}

# Status types for which zone validation, moving and deletion are allowed
STATUS_ALLOW_UPDATE = [ZONE_STATUS_ACTIVE, ZONE_STATUS_FAILED]

# Status types for zones for which activities have finished
STATUS_FINISHED = [
ZONE_STATUS_MOVED,
ZONE_STATUS_NOT_CREATED,
ZONE_STATUS_DELETED,
]

# Status types which lock the project in Taskflow
STATUS_LOCKING = [
ZONE_STATUS_PREPARING,
ZONE_STATUS_VALIDATING,
ZONE_STATUS_MOVING,
]

# Status types for busy landing zones
STATUS_BUSY = [
ZONE_STATUS_CREATING,
ZONE_STATUS_PREPARING,
ZONE_STATUS_VALIDATING,
ZONE_STATUS_MOVING,
ZONE_STATUS_DELETING,
]

# Status types during which file lists and stats should be displayed
STATUS_DISPLAY_FILES = [
ZONE_STATUS_ACTIVE,
ZONE_STATUS_PREPARING,
ZONE_STATUS_VALIDATING,
ZONE_STATUS_MOVING,
ZONE_STATUS_FAILED,
]
3 changes: 2 additions & 1 deletion landingzones/management/commands/busyzones.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
# Projectroles dependency
from projectroles.management.logging import ManagementCommandLogger

from landingzones.models import LandingZone, STATUS_BUSY
from landingzones.constants import STATUS_BUSY
from landingzones.models import LandingZone


logger = ManagementCommandLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion landingzones/management/commands/inactivezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from projectroles.management.logging import ManagementCommandLogger
from projectroles.plugins import get_backend_api

from landingzones.constants import ZONE_STATUS_MOVED, ZONE_STATUS_DELETED
from landingzones.models import LandingZone


Expand All @@ -20,7 +21,7 @@ def get_inactive_zones(weeks=2):
"""Return landing zones last modified over n weeks ago"""
return LandingZone.objects.filter(
date_modified__lte=localtime() - timedelta(weeks=weeks)
).exclude(status__in=('DELETED', 'MOVED'))
).exclude(status__in=(ZONE_STATUS_MOVED, ZONE_STATUS_DELETED))


def get_output(zones, irods_backend, irods):
Expand Down
72 changes: 8 additions & 64 deletions landingzones/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,12 @@
# Samplesheets dependency
from samplesheets.models import Assay

import landingzones.constants as lc

# Access Django user model
AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')


ZONE_STATUS_TYPES = [
'CREATING',
'NOT CREATED',
'ACTIVE',
'PREPARING',
'VALIDATING',
'MOVING',
'FAILED',
'MOVED',
'DELETING',
'DELETED',
]

DEFAULT_STATUS_INFO = {
'CREATING': 'Creating landing zone in iRODS',
'NOT CREATED': 'Creating landing zone in iRODS failed (unknown problem)',
'ACTIVE': 'Available with write access for user',
'PREPARING': 'Preparing transaction for validation and moving',
'VALIDATING': 'Validation in progress, write access disabled',
'MOVING': 'Validation OK, moving files into sample data repository',
'MOVED': 'Files moved successfully, landing zone removed',
'FAILED': 'Validation/moving failed (unknown problem)',
'DELETING': 'Deleting landing zone',
'DELETED': 'Landing zone deleted',
}
STATUS_INFO_DELETE_NO_COLL = (
'No iRODS collection for zone found, marked as deleted'
)

STATUS_STYLES = {
'CREATING': 'bg-warning',
'NOT CREATED': 'bg-danger',
'ACTIVE': 'bg-info',
'PREPARING': 'bg-warning',
'VALIDATING': 'bg-warning',
'MOVING': 'bg-warning',
'MOVED': 'bg-success',
'FAILED': 'bg-danger',
'DELETING': 'bg-warning',
'DELETED': 'bg-secondary',
}

# Status types for which zone validation, moving and deletion are allowed
STATUS_ALLOW_UPDATE = ['ACTIVE', 'FAILED']

# Status types for zones for which activities have finished
STATUS_FINISHED = ['MOVED', 'NOT CREATED', 'DELETED']

# Status types which lock the project in Taskflow
STATUS_LOCKING = ['PREPARING', 'VALIDATING', 'MOVING']

# Status types for busy landing zones
STATUS_BUSY = ['CREATING', 'PREPARING', 'VALIDATING', 'MOVING', 'DELETING']

# Status types during which file lists and stats should be displayed
STATUS_DISPLAY_FILES = ['ACTIVE', 'PREPARING', 'VALIDATING', 'MOVING', 'FAILED']


class LandingZone(models.Model):
"""Class representing an user's iRODS landing zone for an assay"""

Expand Down Expand Up @@ -108,7 +52,7 @@ class LandingZone(models.Model):
max_length=64,
null=False,
blank=False,
default='CREATING',
default=lc.ZONE_STATUS_CREATING,
help_text='Status of landing zone',
)

Expand All @@ -117,7 +61,7 @@ class LandingZone(models.Model):
max_length=1024,
null=True,
blank=True,
default=DEFAULT_STATUS_INFO['CREATING'],
default=lc.DEFAULT_STATUS_INFO[lc.ZONE_STATUS_CREATING],
help_text='Additional status information',
)

Expand Down Expand Up @@ -185,24 +129,24 @@ def get_project(self):

def set_status(self, status, status_info=None):
"""Set zone status"""
if status not in ZONE_STATUS_TYPES:
if status not in lc.ZONE_STATUS_TYPES:
raise TypeError('Unknown status "{}"'.format(status))
self.status = status
if status_info:
self.status_info = status_info
else:
self.status_info = DEFAULT_STATUS_INFO[status][:1024]
self.status_info = lc.DEFAULT_STATUS_INFO[status][:1024]
self.save()

def is_locked(self):
"""
Return True/False depending whether write access to zone is currently
locked.
"""
return self.status in STATUS_LOCKING
return self.status in lc.STATUS_LOCKING

def can_display_files(self):
"""
Return True/False depending whether file info should be displayed.
"""
return self.status in STATUS_DISPLAY_FILES
return self.status in lc.STATUS_DISPLAY_FILES
13 changes: 10 additions & 3 deletions landingzones/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
# Samplesheets dependency
from samplesheets.models import Investigation, Assay

from landingzones.models import LandingZone, STATUS_ALLOW_UPDATE
from landingzones.constants import (
STATUS_ALLOW_UPDATE,
ZONE_STATUS_MOVED,
ZONE_STATUS_DELETED,
)
from landingzones.models import LandingZone
from landingzones.urls import urlpatterns
from landingzones.views import ZoneModifyMixin

Expand Down Expand Up @@ -125,7 +130,7 @@ def get_object_link(self, model_str, uuid):
obj = self.get_object(eval(model_str), uuid)
if not obj:
return None
if obj.__class__ == LandingZone and obj.status != 'MOVED':
if obj.__class__ == LandingZone and obj.status != ZONE_STATUS_MOVED:
return {
'url': reverse(
'landingzones:list',
Expand Down Expand Up @@ -166,7 +171,9 @@ def get_project_list_value(self, column_id, project, user):
zones = LandingZone.objects.filter(project=project)
else:
zones = LandingZone.objects.filter(project=project, user=user)
active_count = zones.exclude(status__in=['MOVED', 'DELETED']).count()
active_count = zones.exclude(
status__in=[ZONE_STATUS_MOVED, ZONE_STATUS_DELETED]
).count()

if investigation and investigation.irods_status and active_count > 0:
return (
Expand Down
11 changes: 8 additions & 3 deletions landingzones/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
# Samplesheets dependency
from samplesheets.models import Assay

from landingzones.constants import (
ZONE_STATUS_OK,
ZONE_STATUS_DELETED,
ZONE_STATUS_NOT_CREATED,
)
from landingzones.models import LandingZone
from landingzones.utils import get_zone_title

Expand Down Expand Up @@ -56,9 +61,9 @@ def get_status_locked(self, obj):
def get_irods_path(self, obj):
irods_backend = get_backend_api('omics_irods')
if irods_backend and obj.status not in [
'MOVED',
'DELETED',
'NOT CREATED',
ZONE_STATUS_OK,
ZONE_STATUS_DELETED,
ZONE_STATUS_NOT_CREATED,
]:
return irods_backend.get_path(obj)

Expand Down
3 changes: 2 additions & 1 deletion landingzones/tasks_celery.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Celery tasks for the landingzones app"""

import logging

from django.conf import settings
Expand All @@ -10,7 +11,7 @@
from projectroles.models import Project
from projectroles.plugins import get_backend_api

from landingzones.models import STATUS_ALLOW_UPDATE, STATUS_LOCKING
from landingzones.constants import STATUS_ALLOW_UPDATE, STATUS_LOCKING
from landingzones.views import ZoneMoveMixin

logger = logging.getLogger(__name__)
Expand Down
Loading
Loading