コード例 #1
0
    def patch(self, request, job_id):
        """Modify job info with a subset of fields

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param job_id: The ID for the job.
        :type job_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        # Validate that no extra fields are included
        rest_util.check_update(request, ['status'])

        # Validate JSON
        status_code = rest_util.parse_string(request, 'status')
        if status_code != 'CANCELED':
            raise rest_util.BadParameter(
                'Invalid or read-only status. Allowed values: CANCELED')

        try:
            Queue.objects.handle_job_cancellation(job_id, datetime.utcnow())
            job = Job.objects.get_details(job_id)
        except (Job.DoesNotExist, JobExecution.DoesNotExist):
            raise Http404

        serializer = self.get_serializer(job)
        return Response(serializer.data)
コード例 #2
0
ファイル: views.py プロジェクト: cuulee/scale
    def patch(self, request, job_id):
        """Modify job info with a subset of fields

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param job_id: The ID for the job.
        :type job_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        # Validate that no extra fields are included
        rest_util.check_update(request, ['status'])

        # Validate JSON
        status_code = rest_util.parse_string(request, 'status')
        if status_code != 'CANCELED':
            raise rest_util.BadParameter('Invalid or read-only status. Allowed values: CANCELED')

        try:
            Queue.objects.handle_job_cancellation(job_id, datetime.utcnow())
            job = Job.objects.get_details(job_id)
        except (Job.DoesNotExist, JobExecution.DoesNotExist):
            raise Http404

        serializer = self.get_serializer(job)
        return Response(serializer.data)
コード例 #3
0
ファイル: views.py プロジェクト: Carl4/scale
    def patch(self, request, job_type_id):
        '''Modify job type info with a subset of fields

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param job_type_id: The ID for the job type.
        :type job_type_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        '''

        # Validate that no extra fields are included
        rest_util.check_update(request, [u'error_mapping', u'is_paused'])

        # Validate JSON
        error_mapping = rest_util.parse_dict(request, u'error_mapping', required=False)
        is_paused = rest_util.parse_bool(request, u'is_paused', required=False)
        if error_mapping is not None:
            try:
                ErrorInterface(error_mapping)
            except InvalidInterfaceDefinition:
                return Response(u'Input failed schema validation.', status=status.HTTP_400_BAD_REQUEST)

        try:
            if error_mapping is not None:
                JobType.objects.update_error_mapping(error_mapping, job_type_id)
            if is_paused is not None:
                Queue.objects.update_job_type_pause(job_type_id, is_paused)
            job_type = JobType.objects.get_details(job_type_id)
            serializer = JobTypeDetailsSerializer(job_type)
            return Response(serializer.data, status=status.HTTP_200_OK)
        except JobType.DoesNotExist:
            raise Http404
コード例 #4
0
ファイル: test_rest.py プロジェクト: ctc-oss/scale
 def test_check_update(self):
     """Tests checking a white-list of parameters allowed to be updated during a POST."""
     request = MagicMock(Request)
     request.data = QueryDict('', mutable=True)
     request.data.update({
         'test': 'value1',
     })
     self.assertTrue(rest_util.check_update(request, ['test']))
コード例 #5
0
ファイル: test_rest.py プロジェクト: dev-geo/scale
 def test_check_update(self):
     '''Tests checking a white-list of parameters allowed to be updated during a POST.'''
     request = MagicMock(Request)
     request.DATA = QueryDict('', mutable=True)
     request.DATA.update({
         'test': 'value1',
     })
     self.assertTrue(rest_util.check_update(request, ['test']))