Exemple #1
0
    def tasks(self, request):
        """Lists a given bot's tasks within the specified date range.

    In this case, the tasks are effectively TaskRunResult since it's individual
    task tries sent to this specific bot.

    It is impossible to search by both tags and bot id. If there's a need,
    TaskRunResult.tags will be added (via a copy from TaskRequest.tags).
    """
        logging.debug('%s', request)
        try:
            start = message_conversion.epoch_to_datetime(request.start)
            end = message_conversion.epoch_to_datetime(request.end)
            now = utils.utcnow()
            query = task_result.get_run_results_query(
                start, end, request.sort.name.lower(),
                request.state.name.lower(), request.bot_id)
            items, cursor = datastore_utils.fetch_page(query, request.limit,
                                                       request.cursor)
        except ValueError as e:
            raise endpoints.BadRequestException(
                'Inappropriate filter for bot.tasks: %s' % e)
        return swarming_rpcs.BotTasks(
            cursor=cursor,
            items=[
                message_conversion.task_result_to_rpc(
                    r, request.include_performance_stats) for r in items
            ],
            now=now)
Exemple #2
0
 def _query_from_request(self, request, sort=None):
     """Returns a TaskResultSummary query."""
     start = message_conversion.epoch_to_datetime(request.start)
     end = message_conversion.epoch_to_datetime(request.end)
     return task_result.get_result_summaries_query(
         start, end, sort or request.sort.name.lower(),
         request.state.name.lower(), request.tags)
Exemple #3
0
 def events(self, request):
     """Returns events that happened on a bot."""
     logging.debug('%s', request)
     try:
         now = utils.utcnow()
         start = message_conversion.epoch_to_datetime(request.start)
         end = message_conversion.epoch_to_datetime(request.end)
         order = not (start or end)
         query = bot_management.get_events_query(request.bot_id, order)
         if not order:
             query = query.order(-bot_management.BotEvent.ts,
                                 bot_management.BotEvent.key)
         if start:
             query = query.filter(bot_management.BotEvent.ts >= start)
         if end:
             query = query.filter(bot_management.BotEvent.ts < end)
         items, cursor = datastore_utils.fetch_page(query, request.limit,
                                                    request.cursor)
     except ValueError as e:
         raise endpoints.BadRequestException(
             'Inappropriate filter for bot.events: %s' % e)
     return swarming_rpcs.BotEvents(
         cursor=cursor,
         items=[message_conversion.bot_event_to_rpc(r) for r in items],
         now=now)
 def events(self, request):
   """Returns events that happened on a bot."""
   logging.info('%s', request)
   try:
     now = utils.utcnow()
     start = message_conversion.epoch_to_datetime(request.start)
     end = message_conversion.epoch_to_datetime(request.end)
     order = not (start or end)
     query = bot_management.get_events_query(request.bot_id, order)
     if not order:
       query = query.order(
           -bot_management.BotEvent.ts, bot_management.BotEvent.key)
     if start:
       query = query.filter(bot_management.BotEvent.ts >= start)
     if end:
       query = query.filter(bot_management.BotEvent.ts < end)
     items, cursor = datastore_utils.fetch_page(
         query, request.limit, request.cursor)
   except ValueError as e:
     raise endpoints.BadRequestException(
         'Inappropriate filter for bot.events: %s' % e)
   return swarming_rpcs.BotEvents(
       cursor=cursor,
       items=[message_conversion.bot_event_to_rpc(r) for r in items],
       now=now)
  def tasks(self, request):
    """Lists a given bot's tasks within the specified date range.

    In this case, the tasks are effectively TaskRunResult since it's individual
    task tries sent to this specific bot.

    It is impossible to search by both tags and bot id. If there's a need,
    TaskRunResult.tags will be added (via a copy from TaskRequest.tags).
    """
    logging.info('%s', request)
    try:
      start = message_conversion.epoch_to_datetime(request.start)
      end = message_conversion.epoch_to_datetime(request.end)
      now = utils.utcnow()
      query = task_result.get_run_results_query(
          start, end,
          request.sort.name.lower(),
          request.state.name.lower(),
          request.bot_id)
      items, cursor = datastore_utils.fetch_page(
          query, request.limit, request.cursor)
    except ValueError as e:
      raise endpoints.BadRequestException(
          'Inappropriate filter for bot.tasks: %s' % e)
    return swarming_rpcs.BotTasks(
        cursor=cursor,
        items=[message_conversion.task_result_to_rpc(r) for r in items],
        now=now)
 def list(self, request):
   """Provides a list of available tasks."""
   logging.info('%s', request)
   try:
     start = message_conversion.epoch_to_datetime(request.start)
     end = message_conversion.epoch_to_datetime(request.end)
     now = utils.utcnow()
     query = task_result.get_result_summaries_query(
         start, end,
         request.sort.name.lower(),
         request.state.name.lower(),
         request.tags)
     items, cursor = datastore_utils.fetch_page(
         query, request.limit, request.cursor)
   except ValueError as e:
     raise endpoints.BadRequestException(
         'Inappropriate filter for tasks/list: %s' % e)
   except datastore_errors.NeedIndexError as e:
     logging.error('%s', e)
     raise endpoints.BadRequestException(
         'Requires new index, ask admin to create one.')
   except datastore_errors.BadArgumentError as e:
     logging.error('%s', e)
     raise endpoints.BadRequestException(
         'This combination is unsupported, sorry.')
   return swarming_rpcs.TaskList(
       cursor=cursor,
       items=[message_conversion.task_result_to_rpc(i) for i in items],
       now=now)
  def list(self, request):
    """Provides a list of available tasks."""
    logging.info('%s', request)
    state = request.state.name.lower()
    uses = sum([bool(request.tags), state != 'all'])
    if state != 'all':
      raise endpoints.BadRequestException(
          'Querying by state is not yet supported. '
          'Received argument state=%s.' % state)
    if uses > 1:
      raise endpoints.BadRequestException(
          'Only one of tag (1 or many) or state can be used.')

    # get the tasks
    try:
      start = message_conversion.epoch_to_datetime(request.start)
      end = message_conversion.epoch_to_datetime(request.end)
      items, cursor_str, state = task_result.get_result_summaries(
          request.tags, request.cursor, start, end, state, request.limit)
      return swarming_rpcs.TaskList(
          cursor=cursor_str,
          items=[message_conversion.task_result_to_rpc(i) for i in items])
    except ValueError as e:
      raise endpoints.BadRequestException(
          'Inappropriate limit for tasks/list: %s' % e)
Exemple #8
0
 def list(self, request):
     """Provides a list of available tasks."""
     logging.info('%s', request)
     try:
         start = message_conversion.epoch_to_datetime(request.start)
         end = message_conversion.epoch_to_datetime(request.end)
         now = utils.utcnow()
         query = task_result.get_result_summaries_query(
             start, end, request.sort.name.lower(),
             request.state.name.lower(), request.tags)
         items, cursor = datastore_utils.fetch_page(query, request.limit,
                                                    request.cursor)
     except ValueError as e:
         raise endpoints.BadRequestException(
             'Inappropriate filter for tasks/list: %s' % e)
     except datastore_errors.NeedIndexError as e:
         logging.error('%s', e)
         raise endpoints.BadRequestException(
             'Requires new index, ask admin to create one.')
     except datastore_errors.BadArgumentError as e:
         logging.error('%s', e)
         raise endpoints.BadRequestException(
             'This combination is unsupported, sorry.')
     return swarming_rpcs.TaskList(
         cursor=cursor,
         items=[message_conversion.task_result_to_rpc(i) for i in items],
         now=now)
 def _query_from_request(self, request, sort=None):
   """Returns a TaskResultSummary query."""
   start = message_conversion.epoch_to_datetime(request.start)
   end = message_conversion.epoch_to_datetime(request.end)
   return task_result.get_result_summaries_query(
       start, end,
       sort or request.sort.name.lower(),
       request.state.name.lower(),
       request.tags)
 def tasks(self, request):
   """Lists a given bot's tasks within the specified date range."""
   logging.info('%s', request)
   try:
     start = message_conversion.epoch_to_datetime(request.start)
     end = message_conversion.epoch_to_datetime(request.end)
     run_results, cursor, more = task_result.get_run_results(
         request.cursor, request.bot_id, start, end, request.limit)
   except ValueError as e:
     raise endpoints.BadRequestException(
         'Inappropriate limit for bots/list: %s' % e)
   return swarming_rpcs.BotTasks(
       cursor=cursor.urlsafe() if cursor and more else None,
       items=[message_conversion.task_result_to_rpc(r) for r in run_results],
       now=utils.utcnow())
Exemple #11
0
 def count(self, request):
     """Counts number of tasks in a given state."""
     logging.info('%s', request)
     if not request.start:
         raise endpoints.BadRequestException('start (as epoch) is required')
     if not request.end:
         raise endpoints.BadRequestException('end (as epoch) is required')
     try:
         now = utils.utcnow()
         query = task_result.get_result_summaries_query(
             message_conversion.epoch_to_datetime(request.start),
             message_conversion.epoch_to_datetime(request.end),
             'created_ts', request.state.name.lower(), request.tags)
         count = query.count()
     except ValueError as e:
         raise endpoints.BadRequestException(
             'Inappropriate filter for tasks/count: %s' % e)
     return swarming_rpcs.TasksCount(count=count, now=now)
Exemple #12
0
 def count(self, request):
   """Counts number of tasks in a given state."""
   logging.info('%s', request)
   if not request.start:
     raise endpoints.BadRequestException('start (as epoch) is required')
   if not request.end:
     raise endpoints.BadRequestException('end (as epoch) is required')
   try:
     now = utils.utcnow()
     query = task_result.get_result_summaries_query(
         message_conversion.epoch_to_datetime(request.start),
         message_conversion.epoch_to_datetime(request.end),
         'created_ts',
         request.state.name.lower(),
         request.tags)
     count = query.count()
   except ValueError as e:
     raise endpoints.BadRequestException(
         'Inappropriate filter for tasks/count: %s' % e)
   return swarming_rpcs.TasksCount(count=count, now=now)