コード例 #1
0
 def get(self, request, pk):
     try:
         run = Run.objects.get(id=pk)
     except Run.DoesNotExist:
         return Response({"details": "Run %s not found" % str(pk)},
                         status=status.HTTP_404_NOT_FOUND)
     try:
         resolved_dict = PipelineCache.get_pipeline(run.app)
     except Exception as e:
         return Response({"details": str(e)},
                         status=status.HTTP_400_BAD_REQUEST)
     app = "data:text/plain;base64,%s" % base64.b64encode(
         json.dumps(resolved_dict).encode("utf-8")).decode("utf-8")
     run_serializer = RunSerializerFull(run)
     inputs = {}
     for inp in run_serializer.data["inputs"]:
         if inp["value"]:
             inputs[inp["name"]] = inp["value"].get("inputs")
     data = {"app": app, "inputs": inputs, "config": {}}
     r = requests.post(
         url=settings.RABIX_URL + "/v0/engine/jobs/",
         headers={"content-type": "application/json"},
         data=json.dumps(data),
     )
     if r.status_code != 200:
         return Response(r.json(), status=r.status_code)
     data = r.json()
     execution_id = data["rootId"]
     run.execution_id = uuid.UUID(execution_id)
     run.status = RunStatus.RUNNING
     run.save()
     response = RunSerializerFull(run)
     return Response(response.data, status=status.HTTP_200_OK)
コード例 #2
0
 def create(self, request, *args, **kwargs):
     serializer = CreateRunSerializer(data=request.data,
                                      context={"request": request})
     if serializer.is_valid():
         run = serializer.save()
         response = RunSerializerFull(run)
         return Response(response.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #3
0
 def create(self, request, *args, **kwargs):
     serializer = APIRunCreateSerializer(data=request.data,
                                         context={'request': request})
     if serializer.is_valid():
         run = serializer.save()
         response = RunSerializerFull(run)
         create_run_task.delay(response.data['id'], request.data['inputs'])
         job_group_notifier_id = str(run.job_group_notifier_id)
         self._send_notifications(job_group_notifier_id, run)
         return Response(response.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #4
0
 def create(self, request, *args, **kwargs):
     run_creator = RunCreator(**request.data)
     if run_creator.is_valid():
         run = run_creator.create()
         response = RunSerializerFull(run)
         create_run_task.delay(response.data["id"], request.data["inputs"])
         job_group_notifier_id = str(run.job_group_notifier_id)
         if job_group_notifier_id:
             self._send_notifications(job_group_notifier_id, run)
         return Response(response.data, status=status.HTTP_201_CREATED)
     return Response("Error", status=status.HTTP_400_BAD_REQUEST)
コード例 #5
0
ファイル: run_view.py プロジェクト: utkarsh-stark/beagle
 def list(self, request, *args, **kwargs):
     queryset = time_filter(Run, request.query_params)
     status_param = request.query_params.get('status')
     if status_param:
         if status_param not in [s.name for s in RunStatus]:
             return Response(
                 {
                     'details':
                     'Invalid status value %s: expected values %s' %
                     (status_param, [s.name for s in Status])
                 },
                 status=status.HTTP_400_BAD_REQUEST)
         queryset = queryset.filter(status=RunStatus[status_param].value)
     page = self.paginate_queryset(queryset)
     if page is not None:
         serializer = RunSerializerFull(page, many=True)
         return self.get_paginated_response(serializer.data)
コード例 #6
0
ファイル: run_api_view.py プロジェクト: stevekm/beagle
 def post(self, request):
     run_id = request.data.get('run')
     run = RunObject.from_db(run_id)
     inputs = dict()
     for port in run.inputs:
         inputs[port.name] = port.db_value
     data = dict(app=str(run.run_obj.app.id),
                 inputs=inputs,
                 tags=run.tags,
                 job_group_id=run.job_group.id,
                 job_group_notifier_id=run.job_group_notifier.id,
                 resume=run_id)
     serializer = APIRunCreateSerializer(data=data,
                                         context={'request': request})
     if serializer.is_valid():
         new_run = serializer.save()
         response = RunSerializerFull(new_run)
         create_run_task.delay(response.data['id'], data['inputs'])
         job_group_notifier_id = str(new_run.job_group_notifier_id)
         self._send_notifications(job_group_notifier_id, new_run)
         return Response(response.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #7
0
 def list(self, request, *args, **kwargs):
     query_list_types = [
         'job_groups', 'request_ids', 'inputs', 'tags', 'jira_ids',
         'run_ids', 'apps', 'run', 'values_run', 'ports'
     ]
     fixed_query_params = fix_query_list(request.query_params,
                                         query_list_types)
     serializer = RunApiListSerializer(data=fixed_query_params)
     if serializer.is_valid():
         queryset = time_filter(Run, fixed_query_params)
         queryset = time_filter(Run,
                                request.query_params,
                                time_modal='modified_date',
                                previous_queryset=queryset)
         job_groups = fixed_query_params.get('job_groups')
         jira_ids = fixed_query_params.get('jira_ids')
         run_ids = fixed_query_params.get('run_ids')
         status_param = fixed_query_params.get('status')
         ports = fixed_query_params.get('ports')
         tags = fixed_query_params.get('tags')
         request_ids = fixed_query_params.get('request_ids')
         apps = fixed_query_params.get('apps')
         values_run = fixed_query_params.get('values_run')
         run = fixed_query_params.get('run')
         run_distribution = fixed_query_params.get('run_distribution')
         count = fixed_query_params.get('count')
         full = fixed_query_params.get('full')
         if full:
             full = bool(strtobool(full))
         if job_groups:
             queryset = queryset.filter(job_group__in=job_groups)
         if jira_ids:
             queryset = queryset.filter(job_group__jira_id__in=jira_ids)
         if run_ids:
             queryset = queryset.filter(id__in=run_ids)
         if status_param:
             queryset = queryset.filter(
                 status=RunStatus[status_param].value)
         if ports:
             queryset = self.query_from_dict("port__%s__exact", queryset,
                                             ports)
         if tags:
             queryset = self.query_from_dict("tags__%s__contains", queryset,
                                             tags)
         if request_ids:
             queryset = queryset.filter(tags__requestId__in=request_ids)
         if apps:
             queryset = queryset.filter(app__in=apps)
         if run:
             filter_query = dict()
             for single_run in run:
                 key, value = single_run.split(':')
                 if value == 'True' or value == 'true':
                     value = True
                 if value == 'False' or value == 'false':
                     value = False
                 filter_query[key] = value
             if filter_query:
                 queryset = queryset.filter(**filter_query)
         if values_run:
             if len(values_run) == 1:
                 ret_str = values_run[0]
                 queryset = queryset.values_list(
                     ret_str, flat=True).order_by(ret_str).distinct(ret_str)
             else:
                 values_run_query_list = [
                     single_run for single_run in values_run
                 ]
                 values_run_query_set = set(values_run_query_list)
                 sorted_query_list = sorted(values_run_query_set)
                 queryset = queryset.values_list(
                     *sorted_query_list).distinct()
         if run_distribution:
             distribution_dict = {}
             run_query = run_distribution
             run_ids = queryset.values_list('id', flat=True)
             queryset = Run.objects.all()
             queryset = queryset.filter(
                 id__in=run_ids).values(run_query).order_by().annotate(
                     Count(run_query))
             for single_arg in queryset:
                 single_arg_name = None
                 single_arg_count = 0
                 for single_key, single_value in single_arg.items():
                     if 'count' in single_key:
                         single_arg_count = single_value
                     else:
                         single_arg_name = single_value
                 if single_arg_name is not None:
                     distribution_dict[single_arg_name] = single_arg_count
             return Response(distribution_dict, status=status.HTTP_200_OK)
         if count:
             count = bool(strtobool(count))
             if count:
                 return Response(queryset.count(),
                                 status=status.HTTP_200_OK)
         try:
             page = self.paginate_queryset(queryset.all())
         except ValidationError as e:
             return Response(e, status=status.HTTP_400_BAD_REQUEST)
         if page is not None:
             if values_run:
                 return self.get_paginated_response(page)
             if full:
                 serializer = RunSerializerFull(page, many=True)
             else:
                 serializer = RunSerializerPartial(page, many=True)
             return self.get_paginated_response(serializer.data)
         return Response([], status=status.HTTP_200_OK)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)