From 4bf33f15da284dd195371b4cffe59a9b46a75d8d Mon Sep 17 00:00:00 2001 From: Ray Liu Date: Wed, 11 Dec 2024 11:32:00 +1100 Subject: [PATCH] add api for rerun/deprecated vlidation --- .../workflow_manager/serializers/workflow_run.py | 2 +- .../serializers/workflow_run_action.py | 5 ++++- .../workflow_manager/urls/base.py | 3 +-- .../workflow_manager/viewsets/state.py | 9 ++++++++- .../viewsets/workflow_run_action.py | 15 +++++++++++++-- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/workload/stateless/stacks/workflow-manager/workflow_manager/serializers/workflow_run.py b/lib/workload/stateless/stacks/workflow-manager/workflow_manager/serializers/workflow_run.py index c1592a8bf..a8fce4aa2 100644 --- a/lib/workload/stateless/stacks/workflow-manager/workflow_manager/serializers/workflow_run.py +++ b/lib/workload/stateless/stacks/workflow-manager/workflow_manager/serializers/workflow_run.py @@ -19,7 +19,7 @@ def get_current_state(self, obj) -> dict: class WorkflowRunListParamSerializer(OptionalFieldsMixin, WorkflowRunBaseSerializer): class Meta: model = WorkflowRun - fields = "__all__" + fields = ["orcabus_id", "workflow", "analysis_run", "workflow_run_name", "portal_run_id", "execution_id", "comment",] class WorkflowRunSerializer(WorkflowRunBaseSerializer): from .workflow import WorkflowMinSerializer diff --git a/lib/workload/stateless/stacks/workflow-manager/workflow_manager/serializers/workflow_run_action.py b/lib/workload/stateless/stacks/workflow-manager/workflow_manager/serializers/workflow_run_action.py index 568904a9a..d57f7cc66 100644 --- a/lib/workload/stateless/stacks/workflow-manager/workflow_manager/serializers/workflow_run_action.py +++ b/lib/workload/stateless/stacks/workflow-manager/workflow_manager/serializers/workflow_run_action.py @@ -6,7 +6,10 @@ class AllowedRerunWorkflow(StrEnum): RNASUM = "rnasum" - + +class AllowedRerunWorkflowSerializer(serializers.Serializer): + is_valid = serializers.BooleanField() + valid_workflows = serializers.ListField(child=serializers.CharField()) class BaseRerunInputSerializer(serializers.Serializer): diff --git a/lib/workload/stateless/stacks/workflow-manager/workflow_manager/urls/base.py b/lib/workload/stateless/stacks/workflow-manager/workflow_manager/urls/base.py index da1315d52..c83584485 100644 --- a/lib/workload/stateless/stacks/workflow-manager/workflow_manager/urls/base.py +++ b/lib/workload/stateless/stacks/workflow-manager/workflow_manager/urls/base.py @@ -20,7 +20,7 @@ router = OptionalSlashDefaultRouter() -router.register("workflowrun/stats", WorkflowRunStatsViewSet, basename="workflowrun_list_all") # put it before workflowrun, as it will match the workflowrun/list_all/ url +router.register(r"workflowrun/stats", WorkflowRunStatsViewSet, basename="workflowrun_list_all") # put it before workflowrun, as it will match the workflowrun/list_all/ url router.register(r"analysis", AnalysisViewSet, basename="analysis") router.register(r"analysisrun", AnalysisRunViewSet, basename="analysisrun") router.register(r"analysiscontext", AnalysisContextViewSet, basename="analysiscontext") @@ -29,7 +29,6 @@ router.register(r"workflowrun", WorkflowRunActionViewSet, basename="workflowrun-action") router.register(r"payload", PayloadViewSet, basename="payload") -# may no longer need this as it's currently included in the detail response for an individual WorkflowRun record router.register( "workflowrun/(?P[^/.]+)/state", StateViewSet, diff --git a/lib/workload/stateless/stacks/workflow-manager/workflow_manager/viewsets/state.py b/lib/workload/stateless/stacks/workflow-manager/workflow_manager/viewsets/state.py index b208bae52..93bd9d631 100644 --- a/lib/workload/stateless/stacks/workflow-manager/workflow_manager/viewsets/state.py +++ b/lib/workload/stateless/stacks/workflow-manager/workflow_manager/viewsets/state.py @@ -1,4 +1,6 @@ - +from drf_spectacular.types import OpenApiTypes +from drf_spectacular.utils import extend_schema, PolymorphicProxySerializer +from rest_framework.decorators import action from rest_framework import mixins, status from rest_framework.response import Response from rest_framework.viewsets import GenericViewSet @@ -29,6 +31,11 @@ class StateViewSet(mixins.CreateModelMixin, mixins.UpdateModelMixin, mixins.List def get_queryset(self): return State.objects.filter(workflow_run=self.kwargs["orcabus_id"]) + @extend_schema(responses=OpenApiTypes.OBJECT, description="Valid states map for new state creation, update") + @action(detail=False, methods=['get'], url_name='valid_states_map', url_path='valid_states_map') + def get_valid_states_map(self, request, **kwargs): + return Response(self.valid_states_map) + def create(self, request, *args, **kwargs): """ Create a customed new state for a workflow run. diff --git a/lib/workload/stateless/stacks/workflow-manager/workflow_manager/viewsets/workflow_run_action.py b/lib/workload/stateless/stacks/workflow-manager/workflow_manager/viewsets/workflow_run_action.py index d05e47c32..9440cd705 100644 --- a/lib/workload/stateless/stacks/workflow-manager/workflow_manager/viewsets/workflow_run_action.py +++ b/lib/workload/stateless/stacks/workflow-manager/workflow_manager/viewsets/workflow_run_action.py @@ -15,7 +15,7 @@ from workflow_manager.models.utils import create_portal_run_id from workflow_manager.serializers.library import LibrarySerializer from workflow_manager.serializers.payload import PayloadSerializer -from workflow_manager.serializers.workflow_run_action import AllowedRerunWorkflow, RERUN_INPUT_SERIALIZERS +from workflow_manager.serializers.workflow_run_action import AllowedRerunWorkflow, RERUN_INPUT_SERIALIZERS, AllowedRerunWorkflowSerializer from workflow_manager.models import ( WorkflowRun, State, @@ -27,6 +27,17 @@ class WorkflowRunActionViewSet(ViewSet): queryset = WorkflowRun.objects.prefetch_related('states').all() orcabus_id_prefix = WorkflowRun.orcabus_id_prefix + @extend_schema(responses=AllowedRerunWorkflowSerializer, description="Allowed rerun workflows") + @action(detail=True, methods=['get'], url_name='validate_rerun_workflows', url_path='validate_rerun_workflows') + def validate_rerun_workflows(self, request, *args, **kwargs): + wfl_run = get_object_or_404(self.queryset, pk=kwargs.get('pk')) + is_valid = wfl_run.workflow.workflow_name in AllowedRerunWorkflow + reponse = { + 'is_valid': is_valid, + 'valid_workflows': AllowedRerunWorkflow + } + return Response(reponse, status=status.HTTP_200_OK) + @extend_schema( request=PolymorphicProxySerializer( component_name='WorkflowRunRerun', @@ -63,7 +74,7 @@ def rerun(self, request, *args, **kwargs): status=status.HTTP_400_BAD_REQUEST) detail = construct_rerun_eb_detail(wfl_run, serializer.data) - emit_wrsc_api_event(detail) + # emit_wrsc_api_event(detail) return Response(detail, status=status.HTTP_200_OK)