Newer
Older
"""
This file contains the database models
"""
Jörn Künsemöller
committed
from django.db.models import ForeignKey, CharField, DateTimeField, BooleanField, IntegerField, BigIntegerField, \
ManyToManyField, CASCADE, SET_NULL, PROTECT
from django.contrib.postgres.fields import ArrayField, JSONField
from .specification import AbstractChoice, BasicCommon, Template, NamedCommon # , WorkRequestBlueprint
from enum import Enum
Jörn Künsemöller
committed
from rest_framework.serializers import HyperlinkedRelatedField
#
# I/O
#
Jörn Künsemöller
committed
class SubtaskConnector(BasicCommon):
Jörn Künsemöller
committed
role = ForeignKey('RoleChoice', null=False, on_delete=PROTECT)
datatype = ForeignKey('DatatypeChoice', null=False, on_delete=PROTECT)
Jörn Künsemöller
committed
dataformats = ManyToManyField('DataformatChoice', blank=True)
Jörn Künsemöller
committed
output_of = ForeignKey('SubtaskTemplate', related_name='inputs', blank=True, on_delete=PROTECT)
input_of = ForeignKey('SubtaskTemplate', related_name='outputs', blank=True, on_delete=PROTECT)
#
# Choices
#
Jörn Künsemöller
committed
class SubtaskStateChoice(AbstractChoice):
"""Defines the model and predefined list of possible SubtaskStatusChoice's for Subtask.
The items in the Choices class below are automagically populated into the database via a data migration."""
class Choices(Enum):
Jörn Künsemöller
committed
DEFINING = "defining"
DEFINED = "defined"
SCHEDULING = "scheduling"
SCHEDULED = "scheduled"
QUEUEING = "queueing"
QUEUED = "queued"
STARTING = "starting"
STARTED = "started"
FINISHING = "finishing"
FINISHED = "finished"
CANCELLING = "cancelling"
CANCELLED = "cancelled"
ERROR = "error"
Jörn Künsemöller
committed
class SubtaskTypeChoice(AbstractChoice):
"""Defines the model and predefined list of possible SubtaskTypeChoice's for Subtask.
The items in the Choices class below are automagically populated into the database via a data migration."""
class Choices(Enum):
OBSERVATION = "observation"
PIPELINE = "pipeline"
INSPECTION = "inspection"
DELETION = "deletion"
Jörn Künsemöller
committed
MANUAL = 'manual'
OTHER = 'other'
class StationTypeChoice(AbstractChoice):
"""Defines the model and predefined list of possible StationTypeChoice's for AntennaSet.
Jörn Künsemöller
committed
The items in the Choices class below are automagically populated into the database via a data migration."""
class Choices(Enum):
CORE = "core"
REMOTE = "remote"
INTERNATIONAL = "international"
Jörn Künsemöller
committed
class Algorithm(AbstractChoice):
"""Defines the model and predefined list of possible Algorithm's for DataproductHash.
The items in the Choices class below are automagically populated into the database via a data migration."""
class Choices(Enum):
MD5 = 'md5'
AES256 = 'aes256'
class ScheduleMethod(AbstractChoice):
"""Defines the model and predefined list of possible Algorithm's for DataproductHash.
The items in the Choices class below are automagically populated into the database via a data migration."""
class Choices(Enum):
MANUAL = 'manual'
BATCH = 'batch'
DYNAMIC = 'dynamic'
#
# Templates
#
Jörn Künsemöller
committed
class SubtaskTemplate(Template):
queue = BooleanField(default=False)
realtime = BooleanField(default=False)
Jörn Künsemöller
committed
class DefaultSubtaskTemplate(BasicCommon):
name = CharField(max_length=30, unique=True)
Jörn Künsemöller
committed
template = ForeignKey('SubtaskTemplate', on_delete=PROTECT)
class DataproductSpecificationsTemplate(Template):
pass
class DefaultDataproductSpecificationsTemplate(BasicCommon):
name = CharField(max_length=30, unique=True)
template = ForeignKey('DataproductSpecificationsTemplate', on_delete=PROTECT)
Jörn Künsemöller
committed
class SubtaskInputSelectionTemplate(Template):
pass
# todo: so we need to specify a default?
Jörn Künsemöller
committed
class DataproductFeedbackTemplate(Template):
pass
# todo: do we need to specify a default?
Jörn Künsemöller
committed
#
# Instance Objects
#
Jörn Künsemöller
committed
class Subtask(BasicCommon):
type = ForeignKey('SubtaskTypeChoice', null=False, on_delete=PROTECT)
start_time = DateTimeField()
stop_time = DateTimeField()
Jörn Künsemöller
committed
state = ForeignKey('SubtaskStateChoice', null=False, on_delete=PROTECT, related_name='task_states')
specifications_doc = JSONField()
work_request_blueprint = ForeignKey('WorkRequestBlueprint', null=True, on_delete=SET_NULL)
Jörn Künsemöller
committed
specifications_template = ForeignKey('SubtaskTemplate', null=False, on_delete=PROTECT)
do_cancel = DateTimeField()
priority = IntegerField()
schedule_method = ForeignKey('ScheduleMethod', null=False, on_delete=PROTECT)
cluster = ForeignKey('Cluster', null=False, on_delete=PROTECT)
scheduler_input_doc = JSONField()
Jörn Künsemöller
committed
# resource_claim = ForeignKey("ResourceClaim", null=False, on_delete=PROTECT) # todo <-- how is this external reference supposed to work?
Jörn Künsemöller
committed
class SubtaskInput(BasicCommon):
subtask = ForeignKey('Subtask', null=False, on_delete=CASCADE)
task_relation_blueprint = ForeignKey('TaskRelationBlueprint', null=True, on_delete=SET_NULL)
connector = ForeignKey('SubtaskConnector', null=True, on_delete=SET_NULL)
producer = ForeignKey('SubtaskOutput', on_delete=PROTECT)
dataproducts = ManyToManyField('Dataproduct')
selection_doc = JSONField()
selection_template = ForeignKey('SubtaskInputSelectionTemplate', on_delete=PROTECT)
class SubtaskOutput(BasicCommon):
subtask = ForeignKey('Subtask', null=False, on_delete=CASCADE)
connector = ForeignKey('SubtaskConnector', null=True, on_delete=SET_NULL)
class Dataproduct(BasicCommon):
filename = CharField(max_length=128)
directory = CharField(max_length=1024)
Jörn Künsemöller
committed
dataformat = ForeignKey('DataformatChoice', null=False, on_delete=PROTECT)
deleted_since = DateTimeField(null=True)
pinned_since = DateTimeField(null=True)
Jörn Künsemöller
committed
specifications_doc = JSONField()
specifications_template = ForeignKey('DataproductSpecificationsTemplate', null=False, on_delete=CASCADE)
Jörn Künsemöller
committed
producer = ForeignKey('SubtaskOutput', on_delete=PROTECT)
do_cancel = DateTimeField() # BooleanField() <- after consulting JDM, we opt for datetimefield for consistency
expected_size = BigIntegerField()
size = BigIntegerField()
feedback_doc = JSONField()
Jörn Künsemöller
committed
feedback_template = ForeignKey('DataproductFeedbackTemplate', on_delete=PROTECT)
class AntennaSet(NamedCommon):
Jörn Künsemöller
committed
station_type = ForeignKey('StationTypeChoice', null=False, on_delete=PROTECT)
rcus = ArrayField(IntegerField(), size=128, blank=False)
inputs = ArrayField(CharField(max_length=30), size=128, blank=True)
Jörn Künsemöller
committed
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
class DataproductTransform(BasicCommon):
input = ForeignKey('Dataproduct', related_name='inputs', on_delete=PROTECT)
output = ForeignKey('Dataproduct', related_name='outputs', on_delete=PROTECT)
identity = BooleanField()
class Filesystem(NamedCommon):
capacity = BigIntegerField()
cluster = ForeignKey('Cluster', on_delete=PROTECT)
class Cluster(NamedCommon):
location = CharField(max_length=128)
class DataproductArchiveInfo(BasicCommon):
dataproduct = ForeignKey('Dataproduct', on_delete=PROTECT)
storage_ticket = CharField(max_length=128)
public_since = DateTimeField()
corrupted_since = DateTimeField()
class DataproductHash(BasicCommon):
dataproduct = ForeignKey('Dataproduct', on_delete=PROTECT)
algorithm = ForeignKey('Algorithm', null=False, on_delete=PROTECT)
hash = CharField(max_length=128)
class TaskRelationBlueprint(BasicCommon):
# dummy, this will eventually come from the renaming of the WorkRelationBlueprint in LEI-86...
pass