Commit 4e1823bb authored by Joern jkuensem's avatar Joern jkuensem

Task LEI-30: Update datamodel, add views/serializers etc for new model items

parent 2d1310f4
......@@ -4247,7 +4247,7 @@ SAS/LSMR/src/lsmr/lsmrapp/__init__.py -text
SAS/LSMR/src/lsmr/lsmrapp/admin.py -text
SAS/LSMR/src/lsmr/lsmrapp/apps.py -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/0001_initial.py -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/0002_auto_20181015_1833.py -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/0002_auto_20190410_1621.py -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/0003_populate.py -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/CMakeLists.txt -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/__init__.py -text
......
......@@ -6,7 +6,7 @@ from ..populate import *
class Migration(migrations.Migration):
dependencies = [
('lsmrapp', '0002_auto_20181015_1833'),
('lsmrapp', '0002_auto_20190410_1621'),
]
operations = [ migrations.RunPython(populate_choices) ]
......@@ -16,7 +16,7 @@ class Migration(migrations.Migration):
"""
from .models.specification import RoleChoice, DatatypeChoice, DataformatChoice, CopyReasonChoice
from .models.scheduling import TaskStateChoice, TaskTypeChoice, StationTypeChoice
from .models.scheduling import SubtaskStateChoice, SubtaskTypeChoice, StationTypeChoice
def populate_choices(apps, schema_editor):
'''
......@@ -25,6 +25,6 @@ def populate_choices(apps, schema_editor):
:return: None
'''
for choice_class in [RoleChoice, DatatypeChoice, DataformatChoice, CopyReasonChoice,
TaskStateChoice, TaskTypeChoice, StationTypeChoice]:
SubtaskStateChoice, SubtaskTypeChoice, StationTypeChoice]:
choice_class.objects.bulk_create([choice_class(value=x.value) for x in choice_class.Choices])
......@@ -6,21 +6,21 @@ from rest_framework import serializers
from .. import models
class TaskIORoleSerializer(serializers.HyperlinkedModelSerializer):
class SubtaskConnectorSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.TaskIORole
model = models.SubtaskConnector
fields = '__all__'
class TaskStateChoiceSerializer(serializers.ModelSerializer):
class SubtaskStateChoiceSerializer(serializers.ModelSerializer):
class Meta:
model = models.TaskStateChoice
model = models.SubtaskStateChoice
fields = '__all__'
class TaskTypeChoiceSerializer(serializers.ModelSerializer):
class SubtaskTypeChoiceSerializer(serializers.ModelSerializer):
class Meta:
model = models.TaskTypeChoice
model = models.SubtaskTypeChoice
fields = '__all__'
......@@ -30,15 +30,15 @@ class StationTypeChoiceSerializer(serializers.ModelSerializer):
fields = '__all__'
class TaskTemplateSerializer(serializers.HyperlinkedModelSerializer):
class SubtaskTemplateSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.TaskTemplate
model = models.SubtaskTemplate
fields = '__all__'
class DefaultTaskTemplateSerializer(serializers.HyperlinkedModelSerializer):
class DefaultSubtaskTemplateSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.DefaultTaskTemplate
model = models.DefaultSubtaskTemplate
fields = '__all__'
......@@ -54,15 +54,26 @@ class DefaultDataproductSpecificationTemplateSerializer(serializers.HyperlinkedM
fields = '__all__'
class TaskSerializer(serializers.HyperlinkedModelSerializer):
class SubtaskSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.Task
model = models.Subtask
fields = '__all__'
class DataproductRelationSerializer(serializers.HyperlinkedModelSerializer):
# class DataproductRelationSerializer(serializers.HyperlinkedModelSerializer):
# class Meta:
# model = models.DataproductRelation
# fields = '__all__'
class SubtaskInputSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.DataproductRelation
model = models.SubtaskInput
fields = '__all__'
class SubtaskOutputSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.SubtaskOutput
fields = '__all__'
......@@ -76,3 +87,39 @@ class AntennaSetSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.AntennaSet
fields = '__all__'
class DataproductTransformSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.DataproductTransform
fields = '__all__'
class FilesystemSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.Filesystem
fields = '__all__'
class ClusterSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.Cluster
fields = '__all__'
class DataproductArchiveInfoSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.DataproductArchiveInfo
fields = '__all__'
class DataproductHashSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.DataproductHash
fields = '__all__'
class TaskRelationBlueprintSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.TaskRelationBlueprint
fields = '__all__'
\ No newline at end of file
......@@ -7,19 +7,19 @@ from .. import models
from .. import serializers
class TaskIORoleViewSet(viewsets.ModelViewSet):
queryset = models.TaskIORole.objects.all()
serializer_class = serializers.TaskIORoleSerializer
class SubtaskConnectorViewSet(viewsets.ModelViewSet):
queryset = models.SubtaskConnector.objects.all()
serializer_class = serializers.SubtaskConnectorSerializer
class TaskStateChoiceViewSet(viewsets.ModelViewSet):
queryset = models.TaskStateChoice.objects.all()
serializer_class = serializers.TaskStateChoiceSerializer
class SubtaskStateChoiceViewSet(viewsets.ModelViewSet):
queryset = models.SubtaskStateChoice.objects.all()
serializer_class = serializers.SubtaskStateChoiceSerializer
class TaskTypeChoiceViewSet(viewsets.ModelViewSet):
queryset = models.TaskTypeChoice.objects.all()
serializer_class = serializers.TaskTypeChoiceSerializer
class SubtaskTypeChoiceViewSet(viewsets.ModelViewSet):
queryset = models.SubtaskTypeChoice.objects.all()
serializer_class = serializers.SubtaskTypeChoiceSerializer
class StationTypeChoiceViewSet(viewsets.ModelViewSet):
......@@ -27,14 +27,14 @@ class StationTypeChoiceViewSet(viewsets.ModelViewSet):
serializer_class = serializers.StationTypeChoiceSerializer
class TaskTemplateViewSet(viewsets.ModelViewSet):
queryset = models.TaskTemplate.objects.all()
serializer_class = serializers.TaskTemplateSerializer
class SubtaskTemplateViewSet(viewsets.ModelViewSet):
queryset = models.SubtaskTemplate.objects.all()
serializer_class = serializers.SubtaskTemplateSerializer
class DefaultTaskTemplateViewSet(viewsets.ModelViewSet):
queryset = models.DefaultTaskTemplate.objects.all()
serializer_class = serializers.DefaultTaskTemplateSerializer
class DefaultSubtaskTemplateViewSet(viewsets.ModelViewSet):
queryset = models.DefaultSubtaskTemplate.objects.all()
serializer_class = serializers.DefaultSubtaskTemplateSerializer
class DataproductSpecificationTemplateViewSet(viewsets.ModelViewSet):
......@@ -47,14 +47,23 @@ class DefaultDataproductSpecificationTemplateViewSet(viewsets.ModelViewSet):
serializer_class = serializers.DefaultDataproductSpecificationTemplateSerializer
class TaskViewSet(viewsets.ModelViewSet):
queryset = models.Task.objects.all()
serializer_class = serializers.TaskSerializer
class SubtaskViewSet(viewsets.ModelViewSet):
queryset = models.Subtask.objects.all()
serializer_class = serializers.SubtaskSerializer
class DataproductRelationViewSet(viewsets.ModelViewSet):
queryset = models.DataproductRelation.objects.all()
serializer_class = serializers.DataproductRelationSerializer
# class DataproductRelationViewSet(viewsets.ModelViewSet):
# queryset = models.DataproductRelation.objects.all()
# serializer_class = serializers.DataproductRelationSerializer
class SubtaskInputViewSet(viewsets.ModelViewSet):
queryset = models.SubtaskInput.objects.all()
serializer_class = serializers.SubtaskInputSerializer
class SubtaskOutputViewSet(viewsets.ModelViewSet):
queryset = models.SubtaskOutput.objects.all()
serializer_class = serializers.SubtaskOutputSerializer
class DataproductViewSet(viewsets.ModelViewSet):
......@@ -67,3 +76,31 @@ class AntennaSetViewSet(viewsets.ModelViewSet):
serializer_class = serializers.AntennaSetSerializer
class DataproductTransformViewSet(viewsets.ModelViewSet):
queryset = models.DataproductTransform.objects.all()
serializer_class = serializers.DataproductTransformSerializer
class FilesystemViewSet(viewsets.ModelViewSet):
queryset = models.Filesystem.objects.all()
serializer_class = serializers.FilesystemSerializer
class ClusterViewSet(viewsets.ModelViewSet):
queryset = models.Cluster.objects.all()
serializer_class = serializers.ClusterSerializer
class DataproductArchiveInfoViewSet(viewsets.ModelViewSet):
queryset = models.DataproductArchiveInfo.objects.all()
serializer_class = serializers.DataproductArchiveInfoSerializer
class DataproductHashViewSet(viewsets.ModelViewSet):
queryset = models.DataproductHash.objects.all()
serializer_class = serializers.DataproductHashSerializer
class TaskRelationBlueprintViewSet(viewsets.ModelViewSet):
queryset = models.TaskRelationBlueprint.objects.all()
serializer_class = serializers.TaskRelationBlueprintSerializer
\ No newline at end of file
......@@ -75,22 +75,31 @@ router.register(r'work_request_relation_blueprint', viewsets.WorkRequestRelation
# SCHEDULING
# choices
router.register(r'task_state_choice', viewsets.TaskStateChoiceViewSet)
router.register(r'task_type_choice', viewsets.TaskTypeChoiceViewSet)
router.register(r'subtask_state_choice', viewsets.SubtaskStateChoiceViewSet)
router.register(r'subtask_type_choice', viewsets.SubtaskTypeChoiceViewSet)
router.register(r'station_type_choice', viewsets.StationTypeChoiceViewSet)
# templates
router.register(r'task_io_role', viewsets.TaskIORoleViewSet)
router.register(r'task_template', viewsets.TaskTemplateViewSet)
router.register(r'subtask_connector', viewsets.SubtaskConnectorViewSet)
router.register(r'subtask_template', viewsets.SubtaskTemplateViewSet)
router.register(r'dataproduct_specification_template', viewsets.DataproductSpecificationTemplateViewSet)
router.register(r'default_task_template', viewsets.DefaultTaskTemplateViewSet)
router.register(r'default_subtask_template', viewsets.DefaultSubtaskTemplateViewSet)
router.register(r'default_dataproduct_specification_template', viewsets.DefaultDataproductSpecificationTemplateViewSet)
# instances
router.register(r'task', viewsets.TaskViewSet)
router.register(r'subtask', viewsets.SubtaskViewSet)
router.register(r'dataproduct', viewsets.DataproductViewSet)
router.register(r'dataproduct_relation', viewsets.DataproductRelationViewSet)
#router.register(r'dataproduct_relation', viewsets.DataproductRelationViewSet)
router.register(r'subtask_input', viewsets.SubtaskInputViewSet)
router.register(r'subtask_output', viewsets.SubtaskOutputViewSet)
router.register(r'antenna_set', viewsets.AntennaSetViewSet)
router.register(r'dataproduct_transform', viewsets.DataproductTransformViewSet)
router.register(r'filesystem', viewsets.FilesystemViewSet)
router.register(r'cluster', viewsets.ClusterViewSet)
router.register(r'dataproduct_archive_info', viewsets.DataproductArchiveInfoViewSet)
router.register(r'dataproduct_hash', viewsets.DataproductHashViewSet)
router.register(r'task_relation_blueprint', viewsets.TaskRelationBlueprintViewSet)
# ---
......
......@@ -80,7 +80,7 @@ def get_project_details_from_momdb():
return results
def query_task_details_for_project_from_momdb(project_mom2id):
def query_subtask_details_for_project_from_momdb(project_mom2id):
logger.info("Querying MoM database for tasks of project %s" % project_mom2id)
# todo: double-check the correct use of ids. What refers to a mom2id and what refers to a database entry pk does not seem systematic and is very comfusing.
query = '''SELECT mom2object.mom2id, mom2object.name, mom2object.description, mom2object.mom2objecttype, status.code,
......@@ -104,9 +104,9 @@ def query_task_details_for_project_from_momdb(project_mom2id):
return results
def _dummy_task_template():
def _dummy_subtask_template():
try:
return models.TaskTemplate.objects.get(name='dummy')
return models.SubtaskTemplate.objects.get(name='dummy')
except:
dummy_template_details = {"name": "dummy",
"description": 'Dummy Template',
......@@ -116,7 +116,7 @@ def _dummy_task_template():
"queue": False,
"tags": ["DUMMY"]}
return models.TaskTemplate.objects.create(**dummy_template_details)
return models.SubtaskTemplate.objects.create(**dummy_template_details)
def _dummy_run_set(project):
......@@ -210,10 +210,10 @@ def _dummy_work_request_blueprint(draft, template, run_blueprint):
return models.WorkRequestBlueprint.objects.create(**dummy_work_request_blueprint_details)
def get_task_details_from_momdb(project_mom2id, project):
def get_subtask_details_from_momdb(project_mom2id, project):
logger.info("Getting task details from MoM database")
mom_results = query_task_details_for_project_from_momdb(project_mom2id)
logger.info("Getting subtask details from MoM database")
mom_results = query_subtask_details_for_project_from_momdb(project_mom2id)
results = {}
for mom_details in mom_results:
......@@ -223,12 +223,12 @@ def get_task_details_from_momdb(project_mom2id, project):
# (maybe we want to instead separate these into different queries instead or union them in SQL?)
if 'OBSERVATION' in mom_details['mom2objecttype']:
type = models.TaskTypeChoice.objects.get(value='observation')
type = models.SubtaskTypeChoice.objects.get(value='observation')
template_name = mom_details['default_template']
start_time = mom_details['obs_starttime']
end_time = mom_details['obs_endtime']
elif 'PIPELINE' in mom_details['mom2objecttype']:
type = models.TaskTypeChoice.objects.get(value='pipeline')
type = models.SubtaskTypeChoice.objects.get(value='pipeline')
template_name = mom_details['template']
start_time = mom_details['starttime']
end_time = mom_details['endtime']
......@@ -264,7 +264,7 @@ def get_task_details_from_momdb(project_mom2id, project):
# state
try:
state = models.TaskStateChoice.objects.get(value=mom_details['code'])
state = models.SubtaskStateChoice.objects.get(value=mom_details['code'])
details['state'] = state
details['requested_state'] = state
except Exception as e:
......@@ -276,13 +276,13 @@ def get_task_details_from_momdb(project_mom2id, project):
if template_name is not None:
try:
details['template'] = models.TaskTemplate.objects.get(name=template_name)
details['template'] = models.SubtaskTemplate.objects.get(name=template_name)
except Exception as e:
logger.warning("No task template matching '%s' in lsmr database! Using dummy instead! %s" % (template_name, e))
# todo: create a lot of templates to reflect what was used for the actual task?
# todo: raise Exception (or continue) once we have proper templates for everything.
details["template"] = _dummy_task_template()
details["template"] = _dummy_subtask_template()
else:
logger.warning('Missing template name in MoM details!')
......@@ -332,11 +332,11 @@ def main():
project = models.Project.objects.create(**p_details)
logger.info("...created new project with lsmr id %s" % project.id)
task_details = get_task_details_from_momdb(p_id, project)
task_details = get_subtask_details_from_momdb(p_id, project)
for t_id, t_details in task_details.items():
logger.info("...creating new task mom2id %s" % t_id)
task = models.Task.objects.create(**t_details)
task = models.Subtask.objects.create(**t_details)
logger.info("...created new task with lsmr id %s" % task.id)
logger.info("...done migrating project %s." % p_details['name'])
......
......@@ -5,6 +5,7 @@
<!--<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<!--<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>-->
<link rel="stylesheet" id="theme" href="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/5.24.7/jsoneditor.css">
<link rel="stylesheet" id="custom" href="custom.css">
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/5.24.7/img/jsoneditor-icons.svg"></script>-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/5.24.7/jsoneditor.js"></script>
......@@ -15,9 +16,9 @@
{% if field.label %}{{ field.label }}{% endif %}
</label>
<input id="helper_input" name="{{ field.name }}" type="hidden" class="form-control" {% if field.value != None %} value="{{ field.value|safe }}"{% endif %}">
<input id="helper_input" name="{{ field.name }}" type="hidden" {% if field.value != None %} value="{{ field.value|safe }}"{% endif %}">
<div class="col-sm-10">
<div class="col-sm-10 clearfix">
<div id="app"></div>
</div>
......
{% extends "rest_framework/base.html" %}
{% block bootstrap_theme %}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootswatch/3.3.7/yeti/bootstrap.min.css" type="text/css">
{% endblock %}
{% block bootstrap_navbar_variant %}{% endblock %}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment