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)
def list(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_status = rest_util.parse_string(request, 'status', 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, ended, ingest_status, file_name, order) page = self.paginate_queryset(ingests) serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data)
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_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) order = rest_util.parse_string_list(request, 'order', required=False) jobs = Job.objects.get_job_updates(started, ended, job_statuses, 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)
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)
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)
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)
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)
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)
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)
def list(self, request, source_id=None): """Retrieves the products 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) batch_ids = rest_util.parse_int_list(request, 'batch_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) is_operational = rest_util.parse_bool(request, 'is_operational', required=False) is_published = rest_util.parse_bool(request, 'is_published', required=False) file_name = rest_util.parse_string(request, 'file_name', required=False) order = rest_util.parse_string_list(request, 'order', required=False) products = SourceFile.objects.get_source_products( source_id, started=started, ended=ended, batch_ids=batch_ids, job_type_ids=job_type_ids, job_type_names=job_type_names, job_type_categories=job_type_categories, is_operational=is_operational, is_published=is_published, file_name=file_name, order=order) page = self.paginate_queryset(products) serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data)
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)
def list_v6(self, request): """Retrieves the list of all datasets 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 options: # started, ended, dataset_id, keywords 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) dataset_ids = rest_util.parse_int_list(request, 'id', required=False) keywords = rest_util.parse_string_list(request, 'keyword', required=False) order = rest_util.parse_string_list(request, 'order', required=False) data_sets = DataSet.objects.get_datasets_v6(started=started, ended=ended, dataset_ids=dataset_ids, keywords=keywords, order=order) page = self.paginate_queryset(data_sets) serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data)
def _list_v5(self, request): """The v5 version for retrieving batches :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_v5( 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)
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)
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)
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)
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)
def get(self, request, job_id): """Retrieve detailed information about the input files for a job :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 """ 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) file_name = rest_util.parse_string(request, 'file_name', required=False) job_input = rest_util.parse_string(request, 'job_input', required=False) files = JobInputFile.objects.get_job_input_files(job_id, started=started, ended=ended, time_field=time_field, file_name=file_name, job_input=job_input) page = self.paginate_queryset(files) serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data)
def list_impl(self, request): """Retrieves the ingest status information 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', 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)) use_ingest_time = rest_util.parse_bool(request, 'use_ingest_time', default_value=False) ingests = Ingest.objects.get_status(started, ended, use_ingest_time) page = self.paginate_queryset(ingests) serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data)
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)
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)
def list_impl(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)
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) order = rest_util.parse_string_list(request, 'order', ['name', 'version']) job_types = JobType.objects.get_job_types(started, ended, names, categories, order) page = self.paginate_queryset(job_types) serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data)
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)
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)
def _list_v6(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=True) ended = rest_util.parse_timestamp(request, 'ended', required=False) rest_util.check_time_range(started, ended) type_ids = rest_util.parse_int_list(request, 'id', required=False) type_names = rest_util.parse_string_list(request, 'name', required=False) type_versions = rest_util.parse_string_list(request, 'version', required=False) if not started: return Response('Invalid parameter: started is required', status=status.HTTP_400_BAD_REQUEST) results = JobType.objects.get_timeline_jobs_json(started=started, ended=ended, type_ids=type_ids, type_names=type_names, type_versions=type_versions) data = { 'count': len(results), 'results': results } return JsonResponse(data)
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, '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=SourceFile.VALID_TIME_FIELDS) is_parsed = rest_util.parse_bool(request, 'is_parsed', required=False) file_name = rest_util.parse_string(request, 'file_name', required=False) order = rest_util.parse_string_list(request, 'order', required=False) sources = SourceFile.objects.get_sources(started, ended, time_field, is_parsed, file_name, order) page = self.paginate_queryset(sources) serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data)
def test_check_time_range_partial(self): """Tests checking a partial time range is valid.""" self.assertTrue( rest_util.check_time_range( datetime.datetime(2015, 1, 1, tzinfo=utc), None)) self.assertTrue( rest_util.check_time_range( None, datetime.datetime(2015, 1, 30, tzinfo=utc)))
def _list_v5(self, request): """Retrieves a list of files based of filters and returns it in JSON form -*-*- parameters: - name: started in: query description: The start time of a start/end time range required: false example: 2016-01-01T00:00:00Z - name: ended in: query description: The end time of a start/end time range required: false example: 2016-01-02T00:00:00Z - name: time_field in: query description: 'The database time field to apply `started` and `ended` time filters [Valid fields: `source`, `data`, `last_modified`]' required: false example: source - name: file_name in: query description: The name of a specific file in Scale required: false example: some_file_i_need_to_find.zip responses: '200': description: A JSON list of files with metadata -*-*- :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) file_name = rest_util.parse_string(request, 'file_name', required=False) files = ScaleFile.objects.filter_files_v5(started=started, ended=ended, time_field=time_field, file_name=file_name) page = self.paginate_queryset(files) serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data)
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 """ if request.version == 'v6': 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) 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) # Attempt to queue all jobs matching the filters requested_job_ids = {job.id for job in jobs} if requested_job_ids: 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 = JobSerializerV5(page, many=True) return self.get_paginated_response(serializer.data)
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)
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 """ countries = rest_util.parse_string_list(request, 'countries', required=False) 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) created_started = rest_util.parse_timestamp(request, 'created_started', required=False) created_ended = rest_util.parse_timestamp(request, 'created_ended', required=False) rest_util.check_time_range(created_started, created_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, created_started=created_started, created_ended=created_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, countries=countries ) page = self.paginate_queryset(files) serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data)
def get(self, request): '''Retrieves the queue depth 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') ended = rest_util.parse_timestamp(request, 'ended') rest_util.check_time_range(started, ended) duration = ended - started if datetime.timedelta(days=0) > duration or datetime.timedelta(days=31) < duration: raise BadParameter('Time range must be between 0 and 31 days') results = Queue.objects.get_historical_queue_depth(started, ended) return Response(results)
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)
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)
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 = rest_util.perform_paging(request, recipe_types) serializer = RecipeTypeListSerializer(page, context={'request': request}) return Response(serializer.data, status=status.HTTP_200_OK)
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)
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) order = rest_util.parse_string_list(request, 'order', required=False) errors = Error.objects.get_errors(started, ended, order) page = self.paginate_queryset(errors) serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data)
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)
def list(self, request): """Retrieves the ingest status information 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', 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)) use_ingest_time = rest_util.parse_bool(request, 'use_ingest_time', default_value=False) ingests = Ingest.objects.get_status(started, ended, use_ingest_time) page = self.paginate_queryset(ingests) serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data)
def get(self, request): '''Retrieves the ingest status information 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', 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)) use_ingest_time = rest_util.parse_bool(request, 'use_ingest_time', default_value=False) ingests = Ingest.objects.get_status(started, ended, use_ingest_time) page = rest_util.perform_paging(request, ingests) serializer = IngestStatusListSerializer(page, context={'request': request}) return Response(serializer.data, status=status.HTTP_200_OK)
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)
def get(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 = rest_util.perform_paging(request, sources) serializer = SourceFileUpdateListSerializer(page, context={'request': request}) return Response(serializer.data, status=status.HTTP_200_OK)
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)
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)
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, 'started', required=False) ended = rest_util.parse_timestamp(request, 'ended', required=False) rest_util.check_time_range(started, ended) is_parsed = rest_util.parse_bool(request, 'is_parsed', required=False) file_name = rest_util.parse_string(request, 'file_name', required=False) order = rest_util.parse_string_list(request, '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)
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)
def list(self, request, product_id=None): """Retrieves the source files for a given product id 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 """ try: ScaleFile.objects.get(id=product_id, file_type='PRODUCT') 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) time_field = rest_util.parse_string( request, 'time_field', required=False, accepted_values=SourceFile.VALID_TIME_FIELDS) is_parsed = rest_util.parse_bool(request, 'is_parsed', required=False) file_name = rest_util.parse_string(request, 'file_name', required=False) order = rest_util.parse_string_list(request, 'order', required=False) sources = ProductFile.objects.get_product_sources( product_id, started, ended, time_field, is_parsed, file_name, order) page = self.paginate_queryset(sources) serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data)
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)
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)
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)
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) batch_ids = rest_util.parse_int_list(request, 'batch_id', 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, batch_ids=batch_ids, 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)
def test_check_time_range(self): '''Tests checking a time range is valid.''' self.assertTrue(rest_util.check_time_range(datetime.datetime(2015, 1, 1), datetime.datetime(2015, 1, 30)))
def test_check_time_range(self): """Tests checking a time range is valid.""" self.assertTrue( rest_util.check_time_range( datetime.datetime(2015, 1, 1, tzinfo=utc), datetime.datetime(2015, 1, 30, tzinfo=utc)))
def test_check_time_range_partial(self): '''Tests checking a partial time range is valid.''' self.assertTrue(rest_util.check_time_range(datetime.datetime(2015, 1, 1), None)) self.assertTrue(rest_util.check_time_range(None, datetime.datetime(2015, 1, 30)))