Exemplo n.º 1
0
    def test_post(self):
        workflowrun_obj = {
            'creator': 'http://localhost:8000/user/1/',
            'workflow': 'http://localhost:8000/workflow/df78a1aa79554abcb5f1b0ac7bba2bad/',
        }

        response = self.client.post("/workflowruns/", workflowrun_obj, format='json')
        wfr = {
            'creator': User.objects.get(pk=1),
            'workflow': Workflow.objects.get(pk='df78a1aa79554abcb5f1b0ac7bba2bad')
        }
        workflow_run = WorkflowRun(**wfr)
        workflow_run.save()
        self.assertEqual(workflow_run.workflow, wfr['workflow'])
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Exemplo n.º 2
0
    def test_post(self):
        workflowrun_obj = {
            'creator':
            'http://localhost:8000/user/1/',
            'workflow':
            'http://localhost:8000/workflow/df78a1aa79554abcb5f1b0ac7bba2bad/',
        }

        response = self.client.post("/workflowruns/",
                                    workflowrun_obj,
                                    format='json')
        wfr = {
            'creator': User.objects.get(pk=1),
            'workflow':
            Workflow.objects.get(pk='df78a1aa79554abcb5f1b0ac7bba2bad')
        }
        workflow_run = WorkflowRun(**wfr)
        workflow_run.save()
        self.assertEqual(workflow_run.workflow, wfr['workflow'])
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Exemplo n.º 3
0
    def post(self, request, *args, **kwargs):
        """
            In the Rodan RESTful architecture, "running" a workflow is accomplished by creating a new
            WorkflowRun object.
        """
        # workflow = request.QUERY_PARAMS.get('workflow', None)
        workflow = request.DATA.get('workflow', None)
        test_status = request.QUERY_PARAMS.get('test', None)
        page_id = request.QUERY_PARAMS.get('page_id', None)

        if not workflow:
            return Response({"message": "You must specify a workflow ID"},
                            status=status.HTTP_400_BAD_REQUEST)

        value = urlparse.urlparse(workflow).path
        try:
            w = resolve(value)
        except:
            return Response(
                {"message": "Could not resolve ID to workflow object"},
                status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        try:
            workflow_obj = Workflow.objects.get(pk=w.kwargs.get('pk'))
        except:
            return Response(
                {"message": "You must specify an existing workflow"},
                status=status.HTTP_404_NOT_FOUND)

        workflow_jobs = WorkflowJob.objects.filter(
            workflow=workflow_obj).order_by('sequence')

        if not workflow_jobs.exists():
            return Response(
                {
                    "message":
                    "No jobs for workflow {0} were specified".format(workflow)
                },
                status=status.HTTP_400_BAD_REQUEST)

        if test_status:
            # running in test mode. This runs the workflow on a single page.
            if not page_id:
                return Response(
                    {
                        "message":
                        "You must specify a page ID if you are running in test mode."
                    },
                    status=status.HTTP_400_BAD_REQUEST)

            value = urlparse.urlparse(page_id).path
            try:
                p = resolve(value)
            except:
                return Response({}, status=status.HTTP_400_BAD_REQUEST)

            pages = Page.objects.filter(pk=p.kwargs.get('pk'))
            run_num = None
            test_status = True

            if not pages.exists():
                return Response(
                    {
                        "message":
                        "No pages for page ID {0} were found".format(page_id)
                    },
                    status=status.HTTP_400_BAD_REQUEST)
        else:
            pages = workflow_obj.pages.filter(processed=True)
            run_num = workflow_obj.runs + 1
            test_status = False

            if not pages:
                return Response(
                    {
                        "message":
                        "No pages were assigned to workflow ID {0}".format(
                            workflow)
                    },
                    status=status.HTTP_400_BAD_REQUEST)

        workflow_run = WorkflowRun(workflow=workflow_obj,
                                   run=run_num,
                                   test_run=test_status,
                                   creator=request.user)

        workflow_run.save()

        return_objects = []
        for page in pages:
            workflow_chain = []
            for workflow_job in workflow_jobs:
                is_interactive = False if workflow_job.job_type == 0 else True
                runjob = RunJob(
                    workflow_run=workflow_run,
                    workflow_job=workflow_job,
                    job_settings=workflow_job.
                    job_settings,  # copy the most recent settings from the workflow job (these may be modified if the job is interactive)
                    needs_input=
                    is_interactive,  # by default this is set to be True if the job is interactive
                    page=page,
                    sequence=workflow_job.sequence)
                runjob.save()

                rodan_task = registry.tasks[str(workflow_job.job_name)]
                workflow_chain.append((rodan_task, str(runjob.uuid)))
            first_job = workflow_chain[0]
            res = chain([first_job[0].si(None, first_job[1])] +
                        [job[0].s(job[1]) for job in workflow_chain[1:]])
            res.apply_async()
            return_objects.append(res)

        if not test_status:
            # If we're not doing a test run, update the run count on the workflow
            workflow_obj.runs = run_num

        return Response({"message": workflow_run.get_absolute_url()},
                        status=status.HTTP_201_CREATED)
Exemplo n.º 4
0
    def post(self, request, *args, **kwargs):
        """
            In the Rodan RESTful architecture, "running" a workflow is accomplished by creating a new
            WorkflowRun object.
        """
        # workflow = request.QUERY_PARAMS.get('workflow', None)
        workflow = request.DATA.get("workflow", None)
        test_status = request.QUERY_PARAMS.get("test", None)
        page_id = request.QUERY_PARAMS.get("page_id", None)

        if not workflow:
            return Response({"message": "You must specify a workflow ID"}, status=status.HTTP_400_BAD_REQUEST)

        value = urlparse.urlparse(workflow).path
        try:
            w = resolve(value)
        except:
            return Response(
                {"message": "Could not resolve ID to workflow object"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR
            )

        try:
            workflow_obj = Workflow.objects.get(pk=w.kwargs.get("pk"))
        except:
            return Response({"message": "You must specify an existing workflow"}, status=status.HTTP_404_NOT_FOUND)

        workflow_jobs = WorkflowJob.objects.filter(workflow=workflow_obj).order_by("sequence")

        if not workflow_jobs.exists():
            return Response(
                {"message": "No jobs for workflow {0} were specified".format(workflow)},
                status=status.HTTP_400_BAD_REQUEST,
            )

        if test_status:
            # running in test mode. This runs the workflow on a single page.
            if not page_id:
                return Response(
                    {"message": "You must specify a page ID if you are running in test mode."},
                    status=status.HTTP_400_BAD_REQUEST,
                )

            value = urlparse.urlparse(page_id).path
            try:
                p = resolve(value)
            except:
                return Response({}, status=status.HTTP_400_BAD_REQUEST)

            pages = Page.objects.filter(pk=p.kwargs.get("pk"))
            run_num = None
            test_status = True

            if not pages.exists():
                return Response(
                    {"message": "No pages for page ID {0} were found".format(page_id)},
                    status=status.HTTP_400_BAD_REQUEST,
                )
        else:
            pages = workflow_obj.pages.filter(processed=True)
            run_num = workflow_obj.runs + 1
            test_status = False

            if not pages:
                return Response(
                    {"message": "No pages were assigned to workflow ID {0}".format(workflow)},
                    status=status.HTTP_400_BAD_REQUEST,
                )

        workflow_run = WorkflowRun(workflow=workflow_obj, run=run_num, test_run=test_status, creator=request.user)

        workflow_run.save()

        return_objects = []
        for page in pages:
            workflow_chain = []
            for workflow_job in workflow_jobs:
                is_interactive = False if workflow_job.job_type == 0 else True
                runjob = RunJob(
                    workflow_run=workflow_run,
                    workflow_job=workflow_job,
                    job_settings=workflow_job.job_settings,  # copy the most recent settings from the workflow job (these may be modified if the job is interactive)
                    needs_input=is_interactive,  # by default this is set to be True if the job is interactive
                    page=page,
                    sequence=workflow_job.sequence,
                )
                runjob.save()

                rodan_task = registry.tasks[str(workflow_job.job_name)]
                workflow_chain.append((rodan_task, str(runjob.uuid)))
            first_job = workflow_chain[0]
            res = chain([first_job[0].si(None, first_job[1])] + [job[0].s(job[1]) for job in workflow_chain[1:]])
            res.apply_async()
            return_objects.append(res)

        if not test_status:
            # If we're not doing a test run, update the run count on the workflow
            workflow_obj.runs = run_num

        return Response({"message": workflow_run.get_absolute_url()}, status=status.HTTP_201_CREATED)