diff --git a/SAS/TMSS/backend/services/scheduling/lib/constraints/__init__.py b/SAS/TMSS/backend/services/scheduling/lib/constraints/__init__.py index 783dd86c11c1187042cc3fa490753338f77aff1a..bfbd513759be5e4ba90d3ecfb6def111ed0bb9fc 100644 --- a/SAS/TMSS/backend/services/scheduling/lib/constraints/__init__.py +++ b/SAS/TMSS/backend/services/scheduling/lib/constraints/__init__.py @@ -86,7 +86,7 @@ def filter_scheduling_units_using_constraints(scheduling_units: [models.Scheduli # For example, the user can choose a different template, # or submit a feature request to implement constraint solvers for this new template. logger.warning(e) - for subtask in models.Subtask.independent_subtasks().filter(task_blueprints__scheduling_unit_blueprint_id=scheduling_unit.id).all(): + for subtask in models.Subtask.independent_subtasks().filter(task_blueprint__scheduling_unit_blueprint_id=scheduling_unit.id).all(): subtask.status = models.SubtaskState.objects.get(value=models.SubtaskState.Choices.UNSCHEDULABLE.value) subtask.save() @@ -151,7 +151,7 @@ def sort_scheduling_units_scored_by_constraints(scheduling_units: [models.Schedu # For example, the user can choose a different template, # or submit a feature request to implement constraint solvers for this new template. logger.warning(e) - for subtask in models.Subtask.independent_subtasks().filter(task_blueprints__scheduling_unit_blueprint_id=scheduling_unit.id).all(): + for subtask in models.Subtask.independent_subtasks().filter(task_blueprint__scheduling_unit_blueprint_id=scheduling_unit.id).all(): subtask.status = models.SubtaskState.objects.get(value=models.SubtaskState.Choices.UNSCHEDULABLE.value) subtask.save() diff --git a/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py b/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py index bbf6e5d542bfbbbf8aaf3ffd70eb0d79d9744a17..428bc37d3f0cc91fdefe6384d2ab6cd02875eb34 100644 --- a/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py +++ b/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py @@ -306,7 +306,7 @@ def get_scheduled_scheduling_units(lower:datetime=None, upper:datetime=None) -> scheduled_subtasks = scheduled_subtasks.filter(stop_time__gte=lower) if upper is not None: scheduled_subtasks = scheduled_subtasks.filter(start_time__lte=upper) - return list(models.SchedulingUnitBlueprint.objects.filter(id__in=scheduled_subtasks.values('task_blueprints__scheduling_unit_blueprint_id').distinct()).all()) + return list(models.SchedulingUnitBlueprint.objects.filter(id__in=scheduled_subtasks.values('task_blueprint__scheduling_unit_blueprint_id').distinct()).all()) def get_running_observation_subtasks(stopping_after:datetime=None) -> [models.Subtask]: diff --git a/SAS/TMSS/backend/services/scheduling/test/t_dynamic_scheduling.py b/SAS/TMSS/backend/services/scheduling/test/t_dynamic_scheduling.py index 3d2c663ccbe2711db8d84766d09df29507f5b782..552ce7d7280f6eb5e2a57afe16b073f40a3a24f1 100755 --- a/SAS/TMSS/backend/services/scheduling/test/t_dynamic_scheduling.py +++ b/SAS/TMSS/backend/services/scheduling/test/t_dynamic_scheduling.py @@ -260,7 +260,7 @@ class TestDynamicScheduling(TestCase): # Note: we use django.test.TestCase inst # check the scheduled subtask upcoming_scheduled_subtasks = models.Subtask.objects.filter(state__value='scheduled', - task_blueprints__scheduling_unit_blueprint__in=(scheduling_unit_blueprint_low, + task_blueprint__scheduling_unit_blueprint__in=(scheduling_unit_blueprint_low, scheduling_unit_blueprint_medium, scheduling_unit_blueprint_high)).all() self.assertEqual(1, upcoming_scheduled_subtasks.count()) diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py index 1d2d09b011ba812ccda109acc442a57ab16e28dc..47ab3ea87a3770eb9791360d081799be444a79b5 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py @@ -1004,6 +1004,16 @@ class TaskDraft(NamedCommon, TemplateSchemaMixin, ProjectPropertyMixin): class TaskBlueprint(ProjectPropertyMixin, TemplateSchemaMixin, NamedCommon): + class Status(Enum): + DEFINED = "defined" + FINISHED = "finished" + CANCELLED = "cancelled" + ERROR = "error" + OBSOLETE = "obsolete" + OBSERVED = "observed" + STARTED = "started" + SCHEDULED = "scheduled" + SCHEDULABLE = "schedulable" specifications_doc = JSONField(help_text='Schedulings for this task (IMMUTABLE).') specifications_template = ForeignKey('TaskTemplate', on_delete=CASCADE, help_text='Schema used for specifications_doc (IMMUTABLE).') @@ -1124,35 +1134,35 @@ class TaskBlueprint(ProjectPropertyMixin, TemplateSchemaMixin, NamedCommon): # simple python filtering counting by state and type. Saves many round-trip-db calls! nr_of_subtasks = len(subtasks) if nr_of_subtasks == 0: - return "defined" + return TaskBlueprint.Status.DEFINED.value if any(s for s in subtasks if s['state'] == 'defining'): - return "defined" + return TaskBlueprint.Status.DEFINED.value if len([s for s in subtasks if s['state'] == 'finished']) == nr_of_subtasks: - return "finished" + return TaskBlueprint.Status.FINISHED.value if any(s for s in subtasks if s['state'] in ('cancelling', 'cancelled')): - return "cancelled" + return TaskBlueprint.Status.CANCELLED.value if any(s for s in subtasks if s['state'] == 'error'): - return "error" + return TaskBlueprint.Status.ERROR.value # TODO: in TMSS-850 implement the various conditional aggregations for the 'obsolete' vs 'finished' states if any(s for s in subtasks if s['state'] == 'obsolete'): - return "obsolete" + return TaskBlueprint.Status.OBSOLETE.value observations = [s for s in subtasks if s['specifications_template__type_id'] == 'observation'] if observations and all(obs and obs['state'] in ('finishing', 'finished') for obs in observations): - return "observed" + return TaskBlueprint.Status.OBSERVED.value if any(s for s in subtasks if s['state'] in ('starting','started','queueing','queued','finishing','finished')): - return "started" + return TaskBlueprint.Status.STARTED.value if any(s for s in subtasks if s['state'] == 'scheduled'): - return "scheduled" + return TaskBlueprint.Status.SCHEDULED.value - return "schedulable" + return TaskBlueprint.Status.SCHEDULABLE.value class TaskRelationDraft(BasicCommon, TemplateSchemaMixin, ProjectPropertyMixin): diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py b/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py index ab02a13dbce5b07442337d8b569e6defffd9a11b..718a8a1ecaf3233ce1db01345be5bae360fa8ce3 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py @@ -1941,7 +1941,7 @@ def create_and_schedule_subtasks_from_task_blueprint(task_blueprint: TaskBluepri def schedule_independent_subtasks_in_task_blueprint(task_blueprint: TaskBlueprint, start_time: datetime=None) -> [Subtask]: '''Convenience method: Schedule (and return) the subtasks in the task_blueprint that are not dependend on any predecessors''' - independent_subtasks = list(Subtask.independent_subtasks().filter(task_blueprints__id=task_blueprint.id, state__value=SubtaskState.Choices.DEFINED.value).all()) + independent_subtasks = list(Subtask.independent_subtasks().filter(task_blueprint__id=task_blueprint.id, state__value=SubtaskState.Choices.DEFINED.value).all()) for subtask in independent_subtasks: if start_time is not None: diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/scheduling.py b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/scheduling.py index 037eb1269cc88e11e3b973172704588788ae21b1..25b4d7b9aa591f1e028b4d9ecbb2e1ae47c710fa 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/scheduling.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/scheduling.py @@ -136,7 +136,7 @@ class SubTaskFilter(filters.FilterSet): id_min = filters.NumberFilter(field_name='id', lookup_expr='gte') id_max = filters.NumberFilter(field_name='id', lookup_expr='lte') state = filters.ModelMultipleChoiceFilter(field_name='state', queryset=models.SubtaskState.objects.all()) - name = filters.CharFilter(field_name='task_blueprints__scheduling_unit_blueprint__name', lookup_expr='icontains') # todo: correct name? + name = filters.CharFilter(field_name='task_blueprint__scheduling_unit_blueprint__name', lookup_expr='icontains') # todo: correct name? class Meta: model = Subtask diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py index d52d77d92abc9d2bb4de6520324950d8e7372ff8..9b2b9b82f44fdbf21d0581448e07d873300a4f40 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py @@ -1029,7 +1029,7 @@ class SchedulingUnitBlueprintViewSet(LOFARViewSet): operation_description="Get the subtask logging urls of this schedulingunit blueprint.") @action(methods=['get'], detail=True, url_name='get_all_subtasks_log_urls') def get_all_subtasks_log_urls(self, request, pk=None): - subtasks = models.Subtask.objects.filter(task_blueprints__scheduling_unit_blueprint_id=pk) + subtasks = models.Subtask.objects.filter(task_blueprint__scheduling_unit_blueprint_id=pk) result = [] for subtask in subtasks: if subtask.log_url != "": @@ -1069,7 +1069,7 @@ class SchedulingUnitBlueprintViewSet(LOFARViewSet): operation_description="Get all subtasks for this scheduling_unit") @action(methods=['get'], detail=True, url_name="subtasks", name="all subtasks in this scheduling_unit") def subtasks(self, request, pk=None): - subtasks = models.Subtask.objects.all().filter(task_blueprints__scheduling_unit_blueprint_id=pk). \ + subtasks = models.Subtask.objects.all().filter(task_blueprint__scheduling_unit_blueprint_id=pk). \ select_related('state', 'specifications_template', 'specifications_template__type', 'cluster', 'created_or_updated_by_user').all() # return a response with the new serialized scheduling_unit_blueprint (with references to the created task_blueprint(s) and (scheduled) subtasks) @@ -1279,7 +1279,7 @@ class TaskBlueprintPropertyFilter(property_filters.PropertyFilterSet): relative_stop_time_max = property_filters.PropertyDurationFilter(field_name='relative_stop_time', lookup_expr='lte') start_time = property_filters.PropertyIsoDateTimeFromToRangeFilter(field_name='start_time') stop_time = property_filters.PropertyIsoDateTimeFromToRangeFilter(field_name='stop_time') - status = property_filters.PropertyMultipleChoiceFilter(field_name='status', choices=tuple((i.value, i.value) for i in models.SubtaskState.Choices), lookup_expr='iexact') + status = property_filters.PropertyMultipleChoiceFilter(field_name='status', choices=tuple((i.value, i.value) for i in models.TaskBlueprint.Status), lookup_expr='iexact') subtasks = filters.ModelMultipleChoiceFilter(field_name='subtasks', queryset=models.Subtask.objects.all()) subtasks_min = filters.NumberFilter(field_name='subtasks__id', lookup_expr='gte') subtasks_max = filters.NumberFilter(field_name='subtasks__id', lookup_expr='lte') diff --git a/SAS/TMSS/backend/src/tmss/workflowapp/tests/t_workflow_qaworkflow.py b/SAS/TMSS/backend/src/tmss/workflowapp/tests/t_workflow_qaworkflow.py index 332c5b04d13e5d6b6f03482d5bd0b362fca49b46..502313a5b45c4542df939ae2838e0b781333ffde 100755 --- a/SAS/TMSS/backend/src/tmss/workflowapp/tests/t_workflow_qaworkflow.py +++ b/SAS/TMSS/backend/src/tmss/workflowapp/tests/t_workflow_qaworkflow.py @@ -106,7 +106,7 @@ class SchedulingUnitFlowTest(unittest.TestCase): scheduling_set=models.SchedulingSet.objects.create(**SchedulingSet_test_data())) scheduling_unit_blueprint = create_task_blueprints_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft) - #ingest_subtask = models.Subtask.objects.get(task_blueprints__scheduling_unit_blueprint__id=scheduling_unit_blueprint.id, + #ingest_subtask = models.Subtask.objects.get(task_blueprint__scheduling_unit_blueprint__id=scheduling_unit_blueprint.id, # specifications_template__type__value=TaskType.Choices.INGEST.value) scheduling_unit_draft.refresh_from_db() @@ -402,7 +402,7 @@ class SchedulingUnitFlowTest(unittest.TestCase): scheduling_set=models.SchedulingSet.objects.create(**SchedulingSet_test_data())) scheduling_unit_blueprint = create_task_blueprints_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft) - #ingest_subtask = models.Subtask.objects.get(task_blueprints__scheduling_unit_blueprint__id=scheduling_unit_blueprint.id, + #ingest_subtask = models.Subtask.objects.get(task_blueprint__scheduling_unit_blueprint__id=scheduling_unit_blueprint.id, # specifications_template__type__value=TaskType.Choices.INGEST.value) scheduling_unit_draft.refresh_from_db() @@ -598,7 +598,7 @@ class SchedulingUnitFlowTest(unittest.TestCase): scheduling_set=models.SchedulingSet.objects.create(**SchedulingSet_test_data())) scheduling_unit_blueprint = create_task_blueprints_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft) - #ingest_subtask = models.Subtask.objects.get(task_blueprints__scheduling_unit_blueprint__id=scheduling_unit_blueprint.id, + #ingest_subtask = models.Subtask.objects.get(task_blueprint__scheduling_unit_blueprint__id=scheduling_unit_blueprint.id, # specifications_template__type__value=TaskType.Choices.INGEST.value) scheduling_unit_draft.refresh_from_db() @@ -821,7 +821,7 @@ class SchedulingUnitFlowTest(unittest.TestCase): scheduling_set=models.SchedulingSet.objects.create(**SchedulingSet_test_data())) scheduling_unit_blueprint = create_task_blueprints_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft) - #ingest_subtask = models.Subtask.objects.get(task_blueprints__scheduling_unit_blueprint__id=scheduling_unit_blueprint.id, + #ingest_subtask = models.Subtask.objects.get(task_blueprint__scheduling_unit_blueprint__id=scheduling_unit_blueprint.id, # specifications_template__type__value=TaskType.Choices.INGEST.value) scheduling_unit_draft.refresh_from_db() @@ -1103,7 +1103,7 @@ class SchedulingUnitFlowTest(unittest.TestCase): scheduling_set=models.SchedulingSet.objects.create(**SchedulingSet_test_data())) scheduling_unit_blueprint = create_task_blueprints_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft) - #ingest_subtask = models.Subtask.objects.get(task_blueprints__scheduling_unit_blueprint__id=scheduling_unit_blueprint.id, + #ingest_subtask = models.Subtask.objects.get(task_blueprint__scheduling_unit_blueprint__id=scheduling_unit_blueprint.id, # specifications_template__type__value=TaskType.Choices.INGEST.value) scheduling_unit_draft.refresh_from_db() @@ -1377,7 +1377,7 @@ class SchedulingUnitFlowTest(unittest.TestCase): scheduling_unit_blueprint = create_task_blueprints_and_subtasks_from_scheduling_unit_draft( scheduling_unit_draft) - # ingest_subtask = models.Subtask.objects.get(task_blueprints__scheduling_unit_blueprint__id=scheduling_unit_blueprint.id, + # ingest_subtask = models.Subtask.objects.get(task_blueprint__scheduling_unit_blueprint__id=scheduling_unit_blueprint.id, # specifications_template__type__value=TaskType.Choices.INGEST.value) scheduling_unit_draft.refresh_from_db()