예제 #1
0
파일: views.py 프로젝트: cuulee/scale
    def list(self, request):
        """Gets job executions and their associated job_type id, name, and version

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_status = rest_util.parse_string(request, 'status', required=False)
        job_type_ids = rest_util.parse_int_list(request, 'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
        job_type_categories = rest_util.parse_string_list(request, 'job_type_category', required=False)

        node_ids = rest_util.parse_int_list(request, 'node_id', required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        job_exes = JobExecution.objects.get_exes(started, ended, job_status, job_type_ids, job_type_names,
                                                 job_type_categories, node_ids, order)

        page = self.paginate_queryset(job_exes)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #2
0
파일: views.py 프로젝트: cshamis/scale
    def get(self, request):
        '''Retrieves the product updates for a given time range and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        '''
        started = rest_util.parse_timestamp(request, u'started', required=False)
        ended = rest_util.parse_timestamp(request, u'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_type_ids = rest_util.parse_int_list(request, u'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, u'job_type_name', required=False)
        job_type_categories = rest_util.parse_string_list(request, u'job_type_category', required=False)
        is_operational = rest_util.parse_bool(request, u'is_operational', required=False)
        file_name = rest_util.parse_string(request, u'file_name', required=False)

        order = rest_util.parse_string_list(request, u'order', required=False)

        products = ProductFile.objects.get_products(started, ended, job_type_ids, job_type_names, job_type_categories,
                                                    is_operational, file_name, order)
        page = rest_util.perform_paging(request, products)
        ProductFile.objects.populate_source_ancestors(page)
        serializer = ProductFileUpdateListSerializer(page, context={'request': request})
        return Response(serializer.data, status=status.HTTP_200_OK)
예제 #3
0
파일: views.py 프로젝트: cshamis/scale
    def get(self, request, name):
        '''Retrieves the plot values for metrics and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        '''
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        choice_ids = rest_util.parse_string_list(request, 'choice_id', required=False)
        column_names = rest_util.parse_string_list(request, 'column', required=False)
        group_names = rest_util.parse_string_list(request, 'group', required=False)

        try:
            provider = registry.get_provider(name)
            metrics_type = provider.get_metrics_type(include_choices=False)
        except MetricsTypeError:
            raise Http404

        # Build a unique set of column names from groups
        columns = metrics_type.get_column_set(column_names, group_names)

        # Get the actual plot values
        metrics_values = provider.get_plot_data(started, ended, choice_ids, columns)

        page = rest_util.perform_paging(request, metrics_values)

        if len(choice_ids) > 1:
            serializer = MetricsPlotMultiListSerializer(page, context={'request': request})
        else:
            serializer = MetricsPlotListSerializer(page, context={'request': request})
        return Response(serializer.data, status=status.HTTP_200_OK)
예제 #4
0
파일: views.py 프로젝트: droessne/scale
    def list(self, request):
        """Retrieves jobs and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        statuses = rest_util.parse_string_list(request, 'status', required=False)
        job_ids = rest_util.parse_int_list(request, 'job_id', required=False)
        job_type_ids = rest_util.parse_int_list(request, 'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
        job_type_categories = rest_util.parse_string_list(request, 'job_type_category', required=False)
        error_categories = rest_util.parse_string_list(request, 'error_category', required=False)
        include_superseded = rest_util.parse_bool(request, 'include_superseded', required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        jobs = Job.objects.get_jobs(started=started, ended=ended, statuses=statuses, job_ids=job_ids,
                                    job_type_ids=job_type_ids, job_type_names=job_type_names,
                                    job_type_categories=job_type_categories, error_categories=error_categories,
                                    include_superseded=include_superseded, order=order)

        page = self.paginate_queryset(jobs)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #5
0
파일: views.py 프로젝트: ngageoint/scale
    def list(self, request):
        """Retrieves the list of all job types and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        names = rest_util.parse_string_list(request, 'name', required=False)
        categories = rest_util.parse_string_list(request, 'category', required=False)
        is_active = rest_util.parse_bool(request, 'is_active', default_value=True)
        is_operational = rest_util.parse_bool(request, 'is_operational', required=False)
        order = rest_util.parse_string_list(request, 'order', ['name', 'version'])

        job_types = JobType.objects.get_job_types(started=started, ended=ended, names=names, categories=categories,
                                                  is_active=is_active, is_operational=is_operational, order=order)

        page = self.paginate_queryset(job_types)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #6
0
파일: views.py 프로젝트: cuulee/scale
    def list(self, request):
        """Retrieves the product updates for a given time range and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, u'started', required=False)
        ended = rest_util.parse_timestamp(request, u'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_type_ids = rest_util.parse_int_list(request, u'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, u'job_type_name', required=False)
        job_type_categories = rest_util.parse_string_list(request, u'job_type_category', required=False)
        is_operational = rest_util.parse_bool(request, u'is_operational', required=False)
        file_name = rest_util.parse_string(request, u'file_name', required=False)

        order = rest_util.parse_string_list(request, u'order', required=False)

        products = ProductFile.objects.get_products(started, ended, job_type_ids, job_type_names, job_type_categories,
                                                    is_operational, file_name, order)

        page = self.paginate_queryset(products)
        ProductFile.objects.populate_source_ancestors(page)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #7
0
파일: views.py 프로젝트: Carl4/scale
    def get(self, request):
        '''Gets job executions and their associated job_type id, name, and version

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        '''
        started = rest_util.parse_timestamp(request, u'started', required=False)
        ended = rest_util.parse_timestamp(request, u'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_status = rest_util.parse_string(request, u'status', required=False)
        job_type_ids = rest_util.parse_int_list(request, u'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, u'job_type_name', required=False)
        job_type_categories = rest_util.parse_string_list(request, u'job_type_category', required=False)

        node_ids = rest_util.parse_int_list(request, u'node_id', required=False)

        order = rest_util.parse_string_list(request, u'order', required=False)

        job_exes = JobExecution.objects.get_exes(started, ended, job_status, job_type_ids, job_type_names,
                                                 job_type_categories, node_ids, order)
        page = rest_util.perform_paging(request, job_exes)

        serializer = JobExecutionListSerializer(page, context={u'request': request})
        return Response(serializer.data, status=status.HTTP_200_OK)
예제 #8
0
파일: views.py 프로젝트: cuulee/scale
    def get(self, request):
        """Retrieves the job updates for a given time range and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_status = rest_util.parse_string(request, 'status', required=False)
        job_type_ids = rest_util.parse_int_list(request, 'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
        job_type_categories = rest_util.parse_string_list(request, 'job_type_category', required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        jobs = Job.objects.get_job_updates(started, ended, job_status, job_type_ids, job_type_names,
                                           job_type_categories, order)

        page = self.paginate_queryset(jobs)
        Job.objects.populate_input_files(page)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #9
0
파일: views.py 프로젝트: Carl4/scale
    def get(self, request):
        '''Retrieves the job updates for a given time range and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        '''
        started = rest_util.parse_timestamp(request, u'started', required=False)
        ended = rest_util.parse_timestamp(request, u'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_status = rest_util.parse_string(request, u'status', required=False)
        job_type_ids = rest_util.parse_int_list(request, u'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, u'job_type_name', required=False)
        job_type_categories = rest_util.parse_string_list(request, u'job_type_category', required=False)

        order = rest_util.parse_string_list(request, u'order', required=False)

        jobs = Job.objects.get_job_updates(started, ended, job_status, job_type_ids, job_type_names,
                                           job_type_categories, order)

        page = rest_util.perform_paging(request, jobs)
        Job.objects.populate_input_files(page)
        serializer = JobUpdateListSerializer(page, context={'request': request})
        return Response(serializer.data, status=status.HTTP_200_OK)
예제 #10
0
파일: views.py 프로젝트: Carl4/scale
    def get(self, request):
        '''Gets jobs and their associated latest execution

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        '''
        started = rest_util.parse_timestamp(request, u'started', required=False)
        ended = rest_util.parse_timestamp(request, u'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_status = rest_util.parse_string(request, u'status', required=False)
        job_type_ids = rest_util.parse_int_list(request, u'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, u'job_type_name', required=False)
        job_type_categories = rest_util.parse_string_list(request, u'job_type_category', required=False)

        order = rest_util.parse_string_list(request, u'order', required=False)

        jobs = Job.objects.get_jobs(started, ended, job_status, job_type_ids, job_type_names, job_type_categories,
                                    order)
        page = rest_util.perform_paging(request, jobs)

        # Add the latest execution for each matching job
        paged_jobs = list(page.object_list)
        job_exes_dict = JobExecution.objects.get_latest(page.object_list)
        for job in paged_jobs:
            job.latest_job_exe = job_exes_dict[job.id] if job.id in job_exes_dict else None
        page.object_list = paged_jobs

        serializer = JobWithExecutionListSerializer(page, context={u'request': request})
        return Response(serializer.data, status=status.HTTP_200_OK)
예제 #11
0
파일: views.py 프로젝트: ngageoint/scale
    def list(self, request):
        """Retrieves the batches and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        statuses = rest_util.parse_string_list(request, 'status', required=False)
        recipe_type_ids = rest_util.parse_int_list(request, 'recipe_type_id', required=False)
        recipe_type_names = rest_util.parse_string_list(request, 'recipe_type_name', required=False)
        order = rest_util.parse_string_list(request, 'order', required=False)

        batches = Batch.objects.get_batches(started=started, ended=ended, statuses=statuses,
                                            recipe_type_ids=recipe_type_ids, recipe_type_names=recipe_type_names,
                                            order=order)

        page = self.paginate_queryset(batches)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #12
0
파일: views.py 프로젝트: cuulee/scale
    def list(self, request):
        """Gets jobs and their associated latest execution

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_status = rest_util.parse_string(request, 'status', required=False)
        job_ids = rest_util.parse_int_list(request, 'job_id', required=False)
        job_type_ids = rest_util.parse_int_list(request, 'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
        job_type_categories = rest_util.parse_string_list(request, 'job_type_category', required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        jobs = Job.objects.get_jobs(started, ended, job_status, job_ids, job_type_ids, job_type_names,
                                    job_type_categories, order)

        # Add the latest execution for each matching job
        page = self.paginate_queryset(jobs)
        job_exes_dict = JobExecution.objects.get_latest(page)
        for job in page:
            job.latest_job_exe = job_exes_dict[job.id] if job.id in job_exes_dict else None
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #13
0
파일: test_rest.py 프로젝트: dev-geo/scale
    def test_parse_string_list_optional(self):
        '''Tests parsing an optional list of string parameters that are missing.'''
        request = MagicMock(Request)
        request.QUERY_PARAMS = QueryDict('', mutable=True)
        request.QUERY_PARAMS.setlist('test', ['value1'])

        self.assertListEqual(rest_util.parse_string_list(request, 'test2', required=False), [])
예제 #14
0
파일: views.py 프로젝트: sau29/scale
    def _get_v6(self, request):
        """Retrieves the list of all errors and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)
        is_builtin = rest_util.parse_bool(request, 'is_builtin', required=False)
        job_type_name = rest_util.parse_string(request, 'job_type_name', required=False)
        name = rest_util.parse_string(request, 'name', required=False)
        category = rest_util.parse_string(request, 'category', required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        errors = Error.objects.get_errors(started=started, ended=ended, order=order, is_builtin=is_builtin,
                                          job_type_name=job_type_name, name=name, category=category)

        page = self.paginate_queryset(errors)
        serializer = self.serializer_class(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #15
0
파일: views.py 프로젝트: kaydoh/scale
    def _list_v6(self, request):
        """Retrieves the job load for a given time range and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(
            request, 'started', default_value=rest_util.get_relative_days(7))
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started,
                                   ended,
                                   max_duration=datetime.timedelta(days=31))

        job_type_ids = rest_util.parse_int_list(request,
                                                'job_type_id',
                                                required=False)
        job_type_names = rest_util.parse_string_list(request,
                                                     'job_type_name',
                                                     required=False)

        job_loads = JobLoad.objects.get_job_loads(started, ended, job_type_ids,
                                                  job_type_names)
        job_loads_grouped = JobLoad.objects.group_by_time(job_loads)

        page = self.paginate_queryset(job_loads_grouped)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #16
0
파일: test_rest.py 프로젝트: dev-geo/scale
    def test_parse_string_list_default(self):
        '''Tests parsing a required list of string parameters that are provided via default value.'''
        request = MagicMock(Request)
        request.QUERY_PARAMS = QueryDict('', mutable=True)
        request.QUERY_PARAMS.setlist('test', ['value1'])

        self.assertEqual(rest_util.parse_string_list(request, 'test2', ['value2', 'value3']), ['value2', 'value3'])
예제 #17
0
    def test_parse_string_list(self):
        """Tests parsing a required list of string parameters that is provided via GET."""
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['value1', 'value2'])

        self.assertListEqual(rest_util.parse_string_list(request, 'test'), ['value1', 'value2'])
예제 #18
0
파일: test_rest.py 프로젝트: cshamis/scale
    def test_parse_string_list_post(self):
        '''Tests parsing a required list of string parameters that are provided via POST.'''
        request = MagicMock(Request)
        request.DATA = QueryDict('', mutable=True)
        request.DATA.setlist('test', ['value1', 'value2'])

        self.assertEqual(rest_util.parse_string_list(request, 'test'), ['value1', 'value2'])
예제 #19
0
    def post(self, request, recipe_id):
        """Schedules a recipe for reprocessing and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param recipe_id: The id of the recipe
        :type recipe_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        job_names = rest_util.parse_string_list(request, 'job_names', required=False)
        all_jobs = rest_util.parse_bool(request, 'all_jobs', required=False)

        try:
            handler = Recipe.objects.reprocess_recipe(recipe_id, job_names, all_jobs)
        except Recipe.DoesNotExist:
            raise Http404
        except ReprocessError as err:
            raise BadParameter(unicode(err))

        try:
            new_recipe = Recipe.objects.get_details(handler.recipe.id)
        except Recipe.DoesNotExist:
            raise Http404

        url = urlresolvers.reverse('recipe_details_view', args=[new_recipe.id])
        serializer = self.get_serializer(new_recipe)
        return Response(serializer.data, status=status.HTTP_201_CREATED, headers=dict(location=url))
예제 #20
0
    def list(self, request):
        """Retrieves the source file updates for a given time range and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request,
                                            u'started',
                                            required=False)
        ended = rest_util.parse_timestamp(request, u'ended', required=False)
        rest_util.check_time_range(started, ended)

        is_parsed = rest_util.parse_bool(request, u'is_parsed', required=False)
        file_name = rest_util.parse_string(request,
                                           u'file_name',
                                           required=False)

        order = rest_util.parse_string_list(request, u'order', required=False)

        sources = SourceFile.objects.get_sources(started, ended, is_parsed,
                                                 file_name, order)

        page = self.paginate_queryset(sources)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #21
0
    def list_v6(self, request):
        """Retrieves the list of all recipe types returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        keywords = rest_util.parse_string_list(request,
                                               'keyword',
                                               required=False)
        is_active = rest_util.parse_bool(request, 'is_active', required=False)
        is_system = rest_util.parse_bool(request, 'is_system', required=False)
        order = ['name']

        recipe_types = RecipeType.objects.get_recipe_types_v6(
            keywords=keywords,
            is_active=is_active,
            is_system=is_system,
            order=order)

        page = self.paginate_queryset(recipe_types)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #22
0
파일: views.py 프로젝트: ctc-oss/scale
    def _list_v6(self, request):
        """Retrieves a list of files based on filters and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        data_started = rest_util.parse_timestamp(request, 'data_started', required=False)
        data_ended = rest_util.parse_timestamp(request, 'data_ended', required=False)
        rest_util.check_time_range(data_started, data_ended)

        source_started = rest_util.parse_timestamp(request, 'source_started', required=False)
        source_ended = rest_util.parse_timestamp(request, 'source_ended', required=False)
        rest_util.check_time_range(source_started, source_ended)

        source_sensor_classes = rest_util.parse_string_list(request, 'source_sensor_class', required=False)
        source_sensors = rest_util.parse_string_list(request, 'source_sensor', required=False)
        source_collections = rest_util.parse_string_list(request, 'source_collection', required=False)
        source_tasks = rest_util.parse_string_list(request, 'source_task', required=False)

        mod_started = rest_util.parse_timestamp(request, 'modified_started', required=False)
        mod_ended = rest_util.parse_timestamp(request, 'modified_ended', required=False)
        rest_util.check_time_range(mod_started, mod_ended)

        job_type_ids = rest_util.parse_int_list(request, 'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
        job_ids = rest_util.parse_int_list(request, 'job_id', required=False)
        file_names = rest_util.parse_string_list(request, 'file_name', required=False)
        job_outputs = rest_util.parse_string_list(request, 'job_output', required=False)
        recipe_ids = rest_util.parse_int_list(request, 'recipe_id', required=False)
        recipe_type_ids = rest_util.parse_int_list(request, 'recipe_type_id', required=False)
        recipe_nodes = rest_util.parse_string_list(request, 'recipe_node', required=False)
        batch_ids = rest_util.parse_int_list(request, 'batch_id', required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        files = ScaleFile.objects.filter_files(
            data_started=data_started, data_ended=data_ended,
            source_started=source_started, source_ended=source_ended,
            source_sensor_classes=source_sensor_classes, source_sensors=source_sensors,
            source_collections=source_collections, source_tasks=source_tasks,
            mod_started=mod_started, mod_ended=mod_ended, job_type_ids=job_type_ids,
            job_type_names=job_type_names, job_ids=job_ids,
            file_names=file_names, job_outputs=job_outputs, recipe_ids=recipe_ids,
            recipe_type_ids=recipe_type_ids, recipe_nodes=recipe_nodes, batch_ids=batch_ids,
            order=order,
        )

        page = self.paginate_queryset(files)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #23
0
파일: test_rest.py 프로젝트: ctc-oss/scale
    def test_parse_string_list_optional(self):
        """Tests parsing an optional list of string parameters that are missing."""
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['value1'])

        self.assertListEqual(
            rest_util.parse_string_list(request, 'test2', required=False), [])
예제 #24
0
파일: test_rest.py 프로젝트: ctc-oss/scale
    def test_parse_string_list(self):
        """Tests parsing a required list of string parameters that is provided via GET."""
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['value1', 'value2'])

        self.assertListEqual(rest_util.parse_string_list(request, 'test'),
                             ['value1', 'value2'])
예제 #25
0
파일: test_rest.py 프로젝트: dev-geo/scale
    def test_parse_string_list_accepted_all(self):
        '''Tests parsing a list of string parameters where all values are acceptable.'''
        request = MagicMock(Request)
        request.QUERY_PARAMS = QueryDict('', mutable=True)
        request.QUERY_PARAMS.setlist('test', ['value1', 'value2'])

        self.assertListEqual(rest_util.parse_string_list(request, 'test', accepted_values=['value1', 'value2']),
                             ['value1', 'value2'])
예제 #26
0
파일: test_rest.py 프로젝트: ctc-oss/scale
    def test_parse_string_list_post(self):
        """Tests parsing a required list of string parameters that are provided via POST."""
        request = MagicMock(Request)
        request.data = QueryDict('', mutable=True)
        request.data.update({'test': ['value1', 'value2']})

        self.assertEqual(rest_util.parse_string_list(request, 'test'),
                         ['value1', 'value2'])
예제 #27
0
    def test_parse_string_list_post(self):
        """Tests parsing a required list of string parameters that are provided via POST."""
        request = MagicMock(Request)
        request.data = QueryDict('', mutable=True)
        request.data.update({
            'test': ['value1', 'value2']
        })

        self.assertEqual(rest_util.parse_string_list(request, 'test'), ['value1', 'value2'])
예제 #28
0
파일: views.py 프로젝트: GRSEB9S/scale
    def list(self, request):
        """Retrieves the product updates for a given time range and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_type_ids = rest_util.parse_int_list(request,
                                                'job_type_id',
                                                required=False)
        job_type_names = rest_util.parse_string_list(request,
                                                     'job_type_name',
                                                     required=False)
        job_type_categories = rest_util.parse_string_list(request,
                                                          'job_type_category',
                                                          required=False)
        is_operational = rest_util.parse_bool(request,
                                              'is_operational',
                                              required=False)
        file_name = rest_util.parse_string(request,
                                           'file_name',
                                           required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        products = ProductFile.objects.get_products(
            started=started,
            ended=ended,
            job_type_ids=job_type_ids,
            job_type_names=job_type_names,
            job_type_categories=job_type_categories,
            is_operational=is_operational,
            file_name=file_name,
            order=order)

        page = self.paginate_queryset(products)
        ProductFile.objects.populate_source_ancestors(page)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #29
0
파일: views.py 프로젝트: GRSEB9S/scale
    def get(self, request):
        """Retrieves the job updates for a given time range and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        statuses = rest_util.parse_string_list(request,
                                               'status',
                                               required=False)
        job_type_ids = rest_util.parse_int_list(request,
                                                'job_type_id',
                                                required=False)
        job_type_names = rest_util.parse_string_list(request,
                                                     'job_type_name',
                                                     required=False)
        job_type_categories = rest_util.parse_string_list(request,
                                                          'job_type_category',
                                                          required=False)
        include_superseded = rest_util.parse_bool(request,
                                                  'include_superseded',
                                                  required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        jobs = Job.objects.get_job_updates(
            started=started,
            ended=ended,
            statuses=statuses,
            job_type_ids=job_type_ids,
            job_type_names=job_type_names,
            job_type_categories=job_type_categories,
            include_superseded=include_superseded,
            order=order)

        page = self.paginate_queryset(jobs)
        Job.objects.populate_input_files(page)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #30
0
파일: views.py 프로젝트: marketboy/scale
    def list_impl(self, request, name):
        """Retrieves the plot values for metrics and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param name: the name of the metrics detail to retrieve.
        :type name: string
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        choice_ids = rest_util.parse_string_list(request,
                                                 'choice_id',
                                                 required=False)
        column_names = rest_util.parse_string_list(request,
                                                   'column',
                                                   required=False)
        group_names = rest_util.parse_string_list(request,
                                                  'group',
                                                  required=False)

        try:
            provider = registry.get_provider(name)
            metrics_type = provider.get_metrics_type(include_choices=False)
        except MetricsTypeError:
            raise Http404

        # Build a unique set of column names from groups
        columns = metrics_type.get_column_set(column_names, group_names)

        # Get the actual plot values
        metrics_values = provider.get_plot_data(started, ended, choice_ids,
                                                columns)

        page = self.paginate_queryset(metrics_values)
        if len(choice_ids) > 1:
            serializer = MetricsPlotMultiSerializer(page, many=True)
        else:
            serializer = MetricsPlotSerializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #31
0
    def list(self, request):
        """Gets jobs and their associated latest execution

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_statuses = rest_util.parse_string_list(request,
                                                   'status',
                                                   required=False)
        job_ids = rest_util.parse_int_list(request, 'job_id', required=False)
        job_type_ids = rest_util.parse_int_list(request,
                                                'job_type_id',
                                                required=False)
        job_type_names = rest_util.parse_string_list(request,
                                                     'job_type_name',
                                                     required=False)
        job_type_categories = rest_util.parse_string_list(request,
                                                          'job_type_category',
                                                          required=False)
        error_categories = rest_util.parse_string_list(request,
                                                       'error_category',
                                                       required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        jobs = Job.objects.get_jobs(started, ended, job_statuses, job_ids,
                                    job_type_ids, job_type_names,
                                    job_type_categories, error_categories,
                                    order)

        # Add the latest execution for each matching job
        page = self.paginate_queryset(jobs)
        job_exes_dict = JobExecution.objects.get_latest(page)
        for job in page:
            job.latest_job_exe = job_exes_dict[
                job.id] if job.id in job_exes_dict else None
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #32
0
파일: test_rest.py 프로젝트: wong-j/scale
    def test_parse_string_list_default(self):
        '''Tests parsing a required list of string parameters that are provided via default value.'''
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['value1'])

        self.assertEqual(
            rest_util.parse_string_list(request, 'test2',
                                        ['value2', 'value3']),
            ['value2', 'value3'])
예제 #33
0
    def post(self, request):
        """Submit command message to re-queue jobs that fit the given filter criteria

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        error_categories = rest_util.parse_string_list(request, 'error_categories', required=False)
        error_ids = rest_util.parse_int_list(request, 'error_ids', required=False)
        job_ids = rest_util.parse_int_list(request, 'job_ids', required=False)
        job_status = rest_util.parse_string(request, 'status', required=False)
        job_type_ids = rest_util.parse_int_list(request, 'job_type_ids', required=False)
        priority = rest_util.parse_int(request, 'priority', required=False)

        job_type_names = rest_util.parse_string_list(request, 'job_type_names', required=False)
        batch_ids = rest_util.parse_int_list(request, 'batch_ids', required=False)
        recipe_ids = rest_util.parse_int_list(request, 'recipe_ids', required=False)
        is_superseded = rest_util.parse_bool(request, 'is_superseded', required=False)

        job_types = rest_util.parse_dict_list(request, 'job_types', required=False)

        for jt in job_types:
            if 'name' not in jt or 'version' not in jt:
                raise BadParameter('Job types argument invalid: %s' % job_types)
            existing_job_type = JobType.objects.filter(name=jt['name'], version=jt['version']).first()
            if not existing_job_type:
                raise BadParameter(
                    'Job Type with name: %s and version: %s does not exist' % (jt['name'], jt['version']))
            job_type_ids.append(existing_job_type.id)

        # Create and send message
        msg = create_requeue_jobs_bulk_message(started=started, ended=ended, error_categories=error_categories,
                                               error_ids=error_ids, job_ids=job_ids, job_type_ids=job_type_ids,
                                               priority=priority, status=job_status, job_type_names=job_type_names,
                                               batch_ids=batch_ids, recipe_ids=recipe_ids, is_superseded=is_superseded)
        CommandMessageManager().send_messages([msg])

        return Response(status=status.HTTP_202_ACCEPTED)
예제 #34
0
    def post(self, request):
        """Increase max_tries, place it on the queue, and returns the new job information in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_status = rest_util.parse_string(request, 'status', required=False)
        job_ids = rest_util.parse_int_list(request, 'job_ids', required=False)
        job_type_ids = rest_util.parse_int_list(request,
                                                'job_type_ids',
                                                required=False)
        job_type_names = rest_util.parse_string_list(request,
                                                     'job_type_names',
                                                     required=False)
        job_type_categories = rest_util.parse_string_list(
            request, 'job_type_categories', required=False)

        priority = rest_util.parse_int(request, 'priority', required=False)

        # Fetch all the jobs matching the filters
        jobs = Job.objects.get_jobs(started, ended, job_status, job_ids,
                                    job_type_ids, job_type_names,
                                    job_type_categories)
        if not jobs:
            raise Http404

        # Attempt to queue all jobs matching the filters
        requested_job_ids = {job.id for job in jobs}
        Queue.objects.requeue_jobs(requested_job_ids, priority)

        # Refresh models to get the new status information for all originally requested jobs
        jobs = Job.objects.get_jobs(job_ids=requested_job_ids)

        page = self.paginate_queryset(jobs)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #35
0
파일: test_rest.py 프로젝트: ctc-oss/scale
    def test_parse_string_list_accepted_all(self):
        """Tests parsing a list of string parameters where all values are acceptable."""
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['value1', 'value2'])

        self.assertListEqual(
            rest_util.parse_string_list(request,
                                        'test',
                                        accepted_values=['value1', 'value2']),
            ['value1', 'value2'])
예제 #36
0
    def list_v6(self, request, job_id):
        """Gets job executions and their associated job_type id, name, and version

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        statuses = rest_util.parse_string_list(request, 'status', required=False)
        node_ids = rest_util.parse_int_list(request, 'node_id', required=False)
        error_ids = rest_util.parse_int_list(request, 'error_id', required=False)
        error_cats = rest_util.parse_string_list(request, 'error_category', required=False)

        job_exes = JobExecution.objects.get_job_exes(job_id=job_id, statuses=statuses, node_ids=node_ids,
                                                     error_ids=error_ids, error_categories=error_cats)

        page = self.paginate_queryset(job_exes)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #37
0
파일: views.py 프로젝트: chedda7/scale
    def list_impl(self, request, source_id=None):
        """Retrieves the jobs for a given source file ID and returns them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param source_id: The id of the source
        :type source_id: int encoded as a string
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            ScaleFile.objects.get(id=source_id, file_type='SOURCE')
        except ScaleFile.DoesNotExist:
            raise Http404

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        statuses = rest_util.parse_string_list(request, 'status', required=False)
        job_ids = rest_util.parse_int_list(request, 'job_id', required=False)
        job_type_ids = rest_util.parse_int_list(request, 'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
        job_type_categories = rest_util.parse_string_list(request, 'job_type_category', required=False)
        batch_ids = rest_util.parse_int_list(request, 'batch_id', required=False)
        error_categories = rest_util.parse_string_list(request, 'error_category', required=False)
        include_superseded = rest_util.parse_bool(request, 'include_superseded', required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        jobs = SourceFile.objects.get_source_jobs(source_id, started=started, ended=ended, statuses=statuses,
                                                  job_ids=job_ids, job_type_ids=job_type_ids,
                                                  job_type_names=job_type_names,
                                                  job_type_categories=job_type_categories, batch_ids=batch_ids,
                                                  error_categories=error_categories,
                                                  include_superseded=include_superseded, order=order)

        page = self.paginate_queryset(jobs)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #38
0
    def list(self, request):
        """Retrieves jobs and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        source_started = rest_util.parse_timestamp(request, 'source_started', required=False)
        source_ended = rest_util.parse_timestamp(request, 'source_ended', required=False)
        rest_util.check_time_range(source_started, source_ended)

        source_sensor_classes = rest_util.parse_string_list(request, 'source_sensor_class', required=False)
        source_sensors = rest_util.parse_string_list(request, 'source_sensor', required=False)
        source_collections = rest_util.parse_string_list(request, 'source_collection', required=False)
        source_tasks = rest_util.parse_string_list(request, 'source_task', required=False)

        statuses = rest_util.parse_string_list(request, 'status', required=False)
        job_ids = rest_util.parse_int_list(request, 'job_id', required=False)
        job_type_ids = rest_util.parse_int_list(request, 'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
        batch_ids = rest_util.parse_int_list(request, 'batch_id', required=False)
        recipe_ids = rest_util.parse_int_list(request, 'recipe_id', required=False)
        error_categories = rest_util.parse_string_list(request, 'error_category', required=False)
        error_ids = rest_util.parse_int_list(request, 'error_id', required=False)
        is_superseded = rest_util.parse_bool(request, 'is_superseded', required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        jobs = Job.objects.get_jobs_v6(started=started, ended=ended,
                                       source_started=source_started, source_ended=source_ended,
                                       source_sensor_classes=source_sensor_classes, source_sensors=source_sensors,
                                       source_collections=source_collections, source_tasks=source_tasks,
                                       statuses=statuses, job_ids=job_ids,
                                       job_type_ids=job_type_ids, job_type_names=job_type_names,
                                       batch_ids=batch_ids, recipe_ids=recipe_ids,
                                       error_categories=error_categories, error_ids=error_ids,
                                       is_superseded=is_superseded, order=order)

        # additional optimizations not being captured by the existing ones in the manager
        # see issue #1717
        jobs = jobs.select_related('job_type_rev__job_type').defer(None)
        page = self.paginate_queryset(jobs)
        serializer = self.get_serializer(page, many=True)

        return self.get_paginated_response(serializer.data)
예제 #39
0
    def list(self, request, source_id=None):
        """Retrieves the ingests for a given source file ID and returns them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param source_id: The id of the source
        :type source_id: int encoded as a string
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            ScaleFile.objects.get(id=source_id, file_type='SOURCE')
        except ScaleFile.DoesNotExist:
            raise Http404

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        ingest_statuses = rest_util.parse_string_list(request,
                                                      'status',
                                                      required=False)
        strike_ids = rest_util.parse_int_list(request,
                                              'strike_id',
                                              required=False)
        scan_ids = rest_util.parse_int_list(request, 'scan_id', required=False)
        order = rest_util.parse_string_list(request, 'order', required=False)

        ingests = SourceFile.objects.get_source_ingests(
            source_id,
            started=started,
            ended=ended,
            statuses=ingest_statuses,
            scan_ids=scan_ids,
            strike_ids=strike_ids,
            order=order)

        page = self.paginate_queryset(ingests)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #40
0
파일: views.py 프로젝트: cshamis/scale
    def get(self, request):
        '''Retrieves the list of all recipes and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        '''
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        type_ids = rest_util.parse_int_list(request, 'type_id', required=False)
        type_names = rest_util.parse_string_list(request, 'type_name', required=False)
        order = rest_util.parse_string_list(request, 'order', required=False)

        recipes = Recipe.objects.get_recipes(started, ended, type_ids, type_names, order)

        page = rest_util.perform_paging(request, recipes)
        serializer = RecipeListSerializer(page, context={'request': request})
        return Response(serializer.data, status=status.HTTP_200_OK)
예제 #41
0
파일: views.py 프로젝트: ngageoint/scale
    def list(self, request):
        """Retrieves the list of all workspaces and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, "started", required=False)
        ended = rest_util.parse_timestamp(request, "ended", required=False)
        rest_util.check_time_range(started, ended)

        names = rest_util.parse_string_list(request, "name", required=False)
        order = rest_util.parse_string_list(request, "order", ["name"])

        workspaces = Workspace.objects.get_workspaces(started, ended, names, order)

        page = self.paginate_queryset(workspaces)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #42
0
    def get(self, request):
        """Retrieves the list of all workspaces and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        names = rest_util.parse_string_list(request, 'name', required=False)
        order = rest_util.parse_string_list(request, 'order', ['name'])

        workspaces = Workspace.objects.get_workspaces(started, ended, names, order)

        page = self.paginate_queryset(workspaces)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #43
0
    def list(self, request):
        """Retrieves jobs and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_statuses = rest_util.parse_string_list(request,
                                                   'status',
                                                   required=False)
        job_ids = rest_util.parse_int_list(request, 'job_id', required=False)
        job_type_ids = rest_util.parse_int_list(request,
                                                'job_type_id',
                                                required=False)
        job_type_names = rest_util.parse_string_list(request,
                                                     'job_type_name',
                                                     required=False)
        job_type_categories = rest_util.parse_string_list(request,
                                                          'job_type_category',
                                                          required=False)
        error_categories = rest_util.parse_string_list(request,
                                                       'error_category',
                                                       required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        jobs = Job.objects.get_jobs(started, ended, job_statuses, job_ids,
                                    job_type_ids, job_type_names,
                                    job_type_categories, error_categories,
                                    order)

        page = self.paginate_queryset(jobs)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #44
0
파일: views.py 프로젝트: droessne/scale
    def post(self, request):
        """Increase max_tries, place it on the queue, and returns the new job information in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_status = rest_util.parse_string(request, 'status', required=False)
        job_ids = rest_util.parse_int_list(request, 'job_ids', required=False)
        job_type_ids = rest_util.parse_int_list(request, 'job_type_ids', required=False)
        job_type_names = rest_util.parse_string_list(request, 'job_type_names', required=False)
        job_type_categories = rest_util.parse_string_list(request, 'job_type_categories', required=False)
        error_categories = rest_util.parse_string_list(request, 'error_categories', required=False)

        priority = rest_util.parse_int(request, 'priority', required=False)

        # Fetch all the jobs matching the filters
        job_status = [job_status] if job_status else job_status
        jobs = Job.objects.get_jobs(started=started, ended=ended, statuses=job_status, job_ids=job_ids,
                                    job_type_ids=job_type_ids, job_type_names=job_type_names,
                                    job_type_categories=job_type_categories, error_categories=error_categories)
        if not jobs:
            raise Http404

        # Attempt to queue all jobs matching the filters
        requested_job_ids = {job.id for job in jobs}
        Queue.objects.requeue_jobs(requested_job_ids, priority)

        # Refresh models to get the new status information for all originally requested jobs
        jobs = Job.objects.get_jobs(job_ids=requested_job_ids)

        page = self.paginate_queryset(jobs)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #45
0
파일: views.py 프로젝트: Carl4/scale
    def get(self, request):
        '''Retrieves the list of all job types and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        '''

        started = rest_util.parse_timestamp(request, u'started', required=False)
        ended = rest_util.parse_timestamp(request, u'ended', required=False)
        rest_util.check_time_range(started, ended)

        names = rest_util.parse_string_list(request, u'name', required=False)
        categories = rest_util.parse_string_list(request, u'category', required=False)
        order = rest_util.parse_string_list(request, u'order', [u'name', u'version'])

        job_types = JobType.objects.get_job_types(started, ended, names, categories, order)

        page = rest_util.perform_paging(request, job_types)
        serializer = JobTypeListSerializer(page, context={u'request': request})
        return Response(serializer.data, status=status.HTTP_200_OK)
예제 #46
0
파일: views.py 프로젝트: GRSEB9S/scale
    def list(self, request):
        """Retrieves the list of all job types and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        names = rest_util.parse_string_list(request, 'name', required=False)
        categories = rest_util.parse_string_list(request,
                                                 'category',
                                                 required=False)
        is_active = rest_util.parse_bool(request,
                                         'is_active',
                                         default_value=True)
        is_operational = rest_util.parse_bool(request,
                                              'is_operational',
                                              required=False)
        order = rest_util.parse_string_list(request, 'order',
                                            ['name', 'version'])

        job_types = JobType.objects.get_job_types(
            started=started,
            ended=ended,
            names=names,
            categories=categories,
            is_active=is_active,
            is_operational=is_operational,
            order=order)

        page = self.paginate_queryset(job_types)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #47
0
    def list(self, request):
        """Retrieves the list of all recipes and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        type_ids = rest_util.parse_int_list(request, 'type_id', required=False)
        type_names = rest_util.parse_string_list(request, 'type_name', required=False)
        include_superseded = rest_util.parse_bool(request, 'include_superseded', required=False)
        order = rest_util.parse_string_list(request, 'order', required=False)

        recipes = Recipe.objects.get_recipes(started=started, ended=ended, type_ids=type_ids, type_names=type_names,
                                             include_superseded=include_superseded, order=order)

        page = self.paginate_queryset(recipes)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #48
0
    def list(self, request):
        """Gets job executions and their associated job_type id, name, and version

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_statuses = rest_util.parse_string_list(request,
                                                   'status',
                                                   required=False)
        job_type_ids = rest_util.parse_int_list(request,
                                                'job_type_id',
                                                required=False)
        job_type_names = rest_util.parse_string_list(request,
                                                     'job_type_name',
                                                     required=False)
        job_type_categories = rest_util.parse_string_list(request,
                                                          'job_type_category',
                                                          required=False)

        node_ids = rest_util.parse_int_list(request, 'node_id', required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        job_exes = JobExecution.objects.get_exes(started, ended, job_statuses,
                                                 job_type_ids, job_type_names,
                                                 job_type_categories, node_ids,
                                                 order)

        page = self.paginate_queryset(job_exes)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #49
0
파일: views.py 프로젝트: AppliedIS/scale
    def list(self, request, name):
        """Retrieves the plot values for metrics and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param name: the name of the metrics detail to retrieve.
        :type name: string
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        choice_ids = rest_util.parse_string_list(request, 'choice_id', required=False)
        column_names = rest_util.parse_string_list(request, 'column', required=False)
        group_names = rest_util.parse_string_list(request, 'group', required=False)

        try:
            provider = registry.get_provider(name)
            metrics_type = provider.get_metrics_type(include_choices=False)
        except MetricsTypeError:
            raise Http404

        # Build a unique set of column names from groups
        columns = metrics_type.get_column_set(column_names, group_names)

        # Get the actual plot values
        metrics_values = provider.get_plot_data(started, ended, choice_ids, columns)

        page = self.paginate_queryset(metrics_values)
        if len(choice_ids) > 1:
            serializer = MetricsPlotMultiSerializer(page, many=True)
        else:
            serializer = MetricsPlotSerializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #50
0
    def list_v6(self, request):
        """Retrieves a list of files based on filters and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)
        time_field = rest_util.parse_string(request, 'time_field', required=False,
                                            accepted_values=ScaleFile.VALID_TIME_FIELDS)

        job_type_ids = rest_util.parse_int_list(request, 'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
        job_ids = rest_util.parse_int_list(request, 'job_id', required=False)
        file_names = rest_util.parse_string_list(request, 'file_name', required=False)
        job_outputs = rest_util.parse_string_list(request, 'job_output', required=False)
        recipe_ids = rest_util.parse_int_list(request, 'recipe_id', required=False)
        recipe_type_ids = rest_util.parse_int_list(request, 'recipe_type_id', required=False)
        recipe_nodes = rest_util.parse_string_list(request, 'recipe_node', required=False)
        batch_ids = rest_util.parse_int_list(request, 'batch_id', required=False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        files = ScaleFile.objects.filter_files(
            started=started, ended=ended, time_field=time_field, job_type_ids=job_type_ids,
            job_type_names=job_type_names, job_ids=job_ids, 
            file_names=file_names, job_outputs=job_outputs, recipe_ids=recipe_ids,
            recipe_type_ids=recipe_type_ids, recipe_nodes=recipe_nodes, batch_ids=batch_ids, order=order,
        )

        page = self.paginate_queryset(files)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #51
0
파일: views.py 프로젝트: ctc-oss/scale
    def list_impl(self, request):
        """Retrieves the list of all ingests and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        ingest_statuses = rest_util.parse_string_list(request,
                                                      'status',
                                                      required=False)
        strike_ids = rest_util.parse_int_list(request,
                                              'strike_id',
                                              required=False)
        scan_ids = rest_util.parse_int_list(request, 'scan_id', required=False)
        file_name = rest_util.parse_string(request,
                                           'file_name',
                                           required=False)
        order = rest_util.parse_string_list(request, 'order', required=False)

        ingests = Ingest.objects.get_ingests(started=started,
                                             ended=ended,
                                             statuses=ingest_statuses,
                                             scan_ids=scan_ids,
                                             strike_ids=strike_ids,
                                             file_name=file_name,
                                             order=order)

        page = self.paginate_queryset(ingests)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #52
0
파일: views.py 프로젝트: dev-geo/scale
    def get(self, request):
        """Retrieves the job load for a given time range and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, 'started', default_value=rest_util.get_relative_days(7))
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended, max_duration=datetime.timedelta(days=31))

        job_type_ids = rest_util.parse_int_list(request, 'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
        job_type_categories = rest_util.parse_string_list(request, 'job_type_category', required=False)
        job_type_priorities = rest_util.parse_string_list(request, 'job_type_priority', required=False)

        job_loads = JobLoad.objects.get_job_loads(started, ended, job_type_ids, job_type_names, job_type_categories,
                                                  job_type_priorities)
        job_loads_grouped = JobLoad.objects.group_by_time(job_loads)

        page = rest_util.perform_paging(request, job_loads_grouped)
        serializer = JobLoadGroupListSerializer(page, context={'request': request})
        return Response(serializer.data, status=status.HTTP_200_OK)
예제 #53
0
파일: views.py 프로젝트: kaydoh/scale
    def create_v6(self, request):
        """Creates or edits a dataset and returns a link to the detail URL

        :param request: the HTTP POST request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        title = rest_util.parse_string(request, 'title', required=False)
        description = rest_util.parse_string(request,
                                             'description',
                                             required=False)
        definition = rest_util.parse_dict(request, 'definition', required=True)
        media_type = rest_util.parse_string_list(request,
                                                 'media_type',
                                                 required=False)

        # validate the definition
        try:
            dataset_def = DataSetDefinitionV6(
                definition=definition, do_validate=True).get_definition()
        except InvalidDataSetDefinition as ex:
            message = 'DataSet definition is invalid'
            logger.exception(message)
            raise BadParameter('%s: %s' % (message, unicode(ex)))

        try:
            dataset = DataSet.objects.create_dataset_v6(
                dataset_def, title=title, description=description)
        except Exception as ex:
            message = 'Unable to create new dataset'
            logger.exception(message)
            raise BadParameter('%s: %s' % (message, unicode(ex)))

        try:
            dataset = DataSet.objects.get_details_v6(dataset.id)
        except DataSet.DoesNotExist:
            raise Http404

        url = reverse('dataset_details_view',
                      args=[dataset.id],
                      request=request)
        serializer = DataSetDetailsSerializerV6(dataset)

        return Response(serializer.data,
                        status=status.HTTP_201_CREATED,
                        headers=dict(location=url))
예제 #54
0
파일: views.py 프로젝트: AppliedIS/scale
    def get(self, request):
        """Retrieves the list of all recipe types returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        order = rest_util.parse_string_list(request, 'order', ['name', 'version'])

        recipe_types = RecipeType.objects.get_recipe_types(started, ended, order)

        page = self.paginate_queryset(recipe_types)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #55
0
파일: views.py 프로젝트: cshamis/scale
    def get(self, request):
        '''Retrieves the list of all nodes and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        '''
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)
        include_inactive = rest_util.parse_bool(request, 'include_inactive', False, False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        nodes = Node.objects.get_nodes(started, ended, order, include_inactive=include_inactive)

        page = rest_util.perform_paging(request, nodes)
        serializer = NodeListSerializer(page, context={'request': request})
        return Response(serializer.data, status=status.HTTP_200_OK)
예제 #56
0
파일: views.py 프로젝트: droessne/scale
    def list(self, request):
        """Retrieves the list of all nodes and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)
        include_inactive = rest_util.parse_bool(request, 'include_inactive', False, False)

        order = rest_util.parse_string_list(request, 'order', required=False)

        nodes = Node.objects.get_nodes(started, ended, order, include_inactive=include_inactive)

        page = self.paginate_queryset(nodes)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
예제 #57
0
    def get(self, request):
        """Exports the job and recipe configuration and returns it in JSON form.

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        # Filter and export recipe types
        recipe_type_ids = rest_util.parse_string_list(request, 'recipe_type_id', required=False)
        recipe_type_names = rest_util.parse_string_list(request, 'recipe_type_name', required=False)
        recipe_filter = recipe_type_ids or recipe_type_names
        recipe_types = exporter.get_recipe_types(recipe_type_ids, recipe_type_names)

        # Filter and export job types
        job_type_ids = rest_util.parse_string_list(request, 'job_type_id', required=False)
        job_type_names = rest_util.parse_string_list(request, 'job_type_name', required=False)
        job_type_categories = rest_util.parse_string_list(request, 'job_type_category', required=False)
        job_filter = job_type_ids or job_type_names or job_type_categories
        job_types = exporter.get_job_types(recipe_types if recipe_filter else None, job_type_ids, job_type_names,
                                           job_type_categories)

        # Filter and export errors
        error_ids = rest_util.parse_string_list(request, 'error_id', required=False)
        error_names = rest_util.parse_string_list(request, 'error_name', required=False)
        errors = exporter.get_errors(job_types if job_filter or recipe_filter else None, error_ids, error_names)

        # Includes are handled at the very end so that the cascaded filtering works as expected
        includes = rest_util.parse_string_list(
            request, 'include', default_value=['recipe_types', 'job_types', 'errors'], required=False,
            accepted_values=['recipe_types', 'job_types', 'errors']
        )
        recipe_types = recipe_types if 'recipe_types' in includes else None
        job_types = job_types if 'job_types' in includes else None
        errors = errors if 'errors' in includes else None

        export_config = exporter.export_config(recipe_types, job_types, errors)
        return Response(export_config.get_dict())
예제 #58
0
파일: views.py 프로젝트: Carl4/scale
    def get(self, request):
        '''Retrieves the list of all errors and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        '''

        started = rest_util.parse_timestamp(request, u'started', required=False)
        ended = rest_util.parse_timestamp(request, u'ended', required=False)
        rest_util.check_time_range(started, ended)

        order = rest_util.parse_string_list(request, u'order', required=False)

        errors = Error.objects.get_errors(started, ended, order)

        page = rest_util.perform_paging(request, errors)
        serializer = ErrorListSerializer(page, context={u'request': request})
        return Response(serializer.data, status=status.HTTP_200_OK)