Пример #1
0
  def new(self, request):
    """Creates a new task.

    The task will be enqueued in the tasks list and will be executed at the
    earliest opportunity by a bot that has at least the dimensions as described
    in the task request.
    """
    logging.info('%s', request)
    try:
      request = message_conversion.new_task_request_from_rpc(
          request, utils.utcnow())
      posted_request = task_request.make_request(request, acl.is_bot_or_admin())
    except (datastore_errors.BadValueError, TypeError, ValueError) as e:
      raise endpoints.BadRequestException(e.message)

    result_summary = task_scheduler.schedule_request(posted_request)

    previous_result = None
    if result_summary.deduped_from:
      previous_result = message_conversion.task_result_to_rpc(result_summary)

    return swarming_rpcs.TaskRequestMetadata(
        request=message_conversion.task_request_to_rpc(posted_request),
        task_id=task_pack.pack_result_summary_key(result_summary.key),
        task_result=previous_result)
Пример #2
0
    def new(self, request):
        """Creates a new task.

    The task will be enqueued in the tasks list and will be executed at the
    earliest opportunity by a bot that has at least the dimensions as described
    in the task request.
    """
        logging.info('%s', request)
        try:
            request = message_conversion.new_task_request_from_rpc(
                request, utils.utcnow())
            posted_request = task_request.make_request(request,
                                                       acl.is_bot_or_admin())
        except (datastore_errors.BadValueError, TypeError, ValueError) as e:
            raise endpoints.BadRequestException(e.message)

        result_summary = task_scheduler.schedule_request(posted_request)

        previous_result = None
        if result_summary.deduped_from:
            previous_result = message_conversion.task_result_to_rpc(
                result_summary)

        return swarming_rpcs.TaskRequestMetadata(
            request=message_conversion.task_request_to_rpc(posted_request),
            task_id=task_pack.pack_result_summary_key(result_summary.key),
            task_result=previous_result)
Пример #3
0
    def post(self):
        logging.error('Unexpected old client')
        data = self.parse_body()
        msg = log_unexpected_subset_keys(self._EXPECTED_DATA_KEYS,
                                         self._REQUIRED_DATA_KEYS, data,
                                         self.request, 'client',
                                         'request keys')
        if msg:
            self.abort_with_error(400, error=msg)
        data_properties = data['properties']
        msg = log_unexpected_subset_keys(self._EXPECTED_PROPERTIES_KEYS,
                                         self._REQUIRED_PROPERTIES_KEYS,
                                         data_properties, self.request,
                                         'client', 'request properties keys')
        if msg:
            self.abort_with_error(400, error=msg)

        # Class TaskProperties takes care of making everything deterministic.
        properties = task_request.TaskProperties(
            commands=data_properties['commands'],
            data=data_properties['data'],
            dimensions=data_properties['dimensions'],
            env=data_properties['env'],
            execution_timeout_secs=data_properties['execution_timeout_secs'],
            grace_period_secs=data_properties.get('grace_period_secs', 30),
            idempotent=data_properties.get('idempotent', False),
            io_timeout_secs=data_properties['io_timeout_secs'])

        now = utils.utcnow()
        expiration_ts = now + datetime.timedelta(
            seconds=data['scheduling_expiration_secs'])
        request = task_request.TaskRequest(
            created_ts=now,
            expiration_ts=expiration_ts,
            name=data['name'],
            parent_task_id=data.get('parent_task_id'),
            priority=data['priority'],
            properties=properties,
            tags=data['tags'],
            user=data['user'] or '')

        try:
            request = task_request.make_request(request, acl.is_bot_or_admin())
        except (AttributeError, datastore_errors.BadValueError, TypeError,
                ValueError) as e:
            self.abort_with_error(400, error=str(e))

        result_summary = task_scheduler.schedule_request(request)
        data = {
            'request': request.to_dict(),
            'task_id': task_pack.pack_result_summary_key(result_summary.key),
        }
        self.send_response(utils.to_json_encodable(data))
Пример #4
0
  def post(self):
    logging.error('Unexpected old client')
    data = self.parse_body()
    msg = log_unexpected_subset_keys(
        self._EXPECTED_DATA_KEYS, self._REQUIRED_DATA_KEYS, data, self.request,
        'client', 'request keys')
    if msg:
      self.abort_with_error(400, error=msg)
    data_properties = data['properties']
    msg = log_unexpected_subset_keys(
        self._EXPECTED_PROPERTIES_KEYS, self._REQUIRED_PROPERTIES_KEYS,
        data_properties, self.request, 'client', 'request properties keys')
    if msg:
      self.abort_with_error(400, error=msg)

    # Class TaskProperties takes care of making everything deterministic.
    properties = task_request.TaskProperties(
        commands=data_properties['commands'],
        data=data_properties['data'],
        dimensions=data_properties['dimensions'],
        env=data_properties['env'],
        execution_timeout_secs=data_properties['execution_timeout_secs'],
        grace_period_secs=data_properties.get('grace_period_secs', 30),
        idempotent=data_properties.get('idempotent', False),
        io_timeout_secs=data_properties['io_timeout_secs'])

    now = utils.utcnow()
    expiration_ts = now + datetime.timedelta(
        seconds=data['scheduling_expiration_secs'])
    request = task_request.TaskRequest(
        created_ts=now,
        expiration_ts=expiration_ts,
        name=data['name'],
        parent_task_id=data.get('parent_task_id'),
        priority=data['priority'],
        properties=properties,
        tags=data['tags'],
        user=data['user'] or '')

    try:
      request = task_request.make_request(request, acl.is_bot_or_admin())
    except (
        AttributeError, datastore_errors.BadValueError, TypeError,
        ValueError) as e:
      self.abort_with_error(400, error=str(e))

    result_summary = task_scheduler.schedule_request(request)
    data = {
      'request': request.to_dict(),
      'task_id': task_pack.pack_result_summary_key(result_summary.key),
    }
    self.send_response(utils.to_json_encodable(data))
Пример #5
0
  def post(self):
    request_data = self.parse_body()
    # If the priority is below 100, make the the user has right to do so.
    if request_data.get('priority', 255) < 100 and not acl.is_bot_or_admin():
      # Silently drop the priority of normal users.
      request_data['priority'] = 100

    try:
      request = task_request.make_request(request_data)
    except (datastore_errors.BadValueError, TypeError, ValueError) as e:
      self.abort_with_error(400, error=str(e))

    result_summary = task_scheduler.schedule_request(request)
    data = {
      'request': request.to_dict(),
      'task_id': task_pack.pack_result_summary_key(result_summary.key),
    }
    self.send_response(utils.to_json_encodable(data))
Пример #6
0
  def post(self):
    request_data = self.parse_body()
    # If the priority is below 100, make the the user has right to do so.
    if request_data.get('priority', 255) < 100 and not acl.is_bot_or_admin():
      # Silently drop the priority of normal users.
      request_data['priority'] = 100

    try:
      request = task_request.make_request(request_data)
    except (datastore_errors.BadValueError, TypeError, ValueError) as e:
      self.abort_with_error(400, error=str(e))

    result_summary = task_scheduler.schedule_request(request)
    data = {
      'request': request.to_dict(),
      'task_id': task_pack.pack_result_summary_key(result_summary.key),
    }
    self.send_response(utils.to_json_encodable(data))
Пример #7
0
    def terminate(self, request):
        """Asks a bot to terminate itself gracefully.

    The bot will stay in the DB, use 'delete' to remove it from the DB
    afterward. This request returns a pseudo-taskid that can be waited for to
    wait for the bot to turn down.

    This command is particularly useful when a privileged user needs to safely
    debug a machine specific issue. The user can trigger a terminate for one of
    the bot exhibiting the issue, wait for the pseudo-task to run then access
    the machine with the guarantee that the bot is not running anymore.
    """
        # TODO(maruel): Disallow a terminate task when there's one currently
        # pending or if the bot is considered 'dead', e.g. no contact since 10
        # minutes.
        logging.info('%s', request)
        bot_key = bot_management.get_info_key(request.bot_id)
        get_or_raise(bot_key)  # raises 404 if there is no such bot
        try:
            # Craft a special priority 0 task to tell the bot to shutdown.
            properties = task_request.TaskProperties(
                dimensions={u'id': request.bot_id},
                execution_timeout_secs=0,
                grace_period_secs=0,
                io_timeout_secs=0)
            now = utils.utcnow()
            request = task_request.TaskRequest(
                created_ts=now,
                expiration_ts=now + datetime.timedelta(days=1),
                name='Terminate %s' % request.bot_id,
                priority=0,
                properties=properties,
                tags=['terminate:1'],
                user=auth.get_current_identity().to_bytes())
            assert request.properties.is_terminate
            posted_request = task_request.make_request(request,
                                                       acl.is_bot_or_admin())
        except (datastore_errors.BadValueError, TypeError, ValueError) as e:
            raise endpoints.BadRequestException(e.message)

        result_summary = task_scheduler.schedule_request(posted_request)
        return swarming_rpcs.TerminateResponse(
            task_id=task_pack.pack_result_summary_key(result_summary.key))
Пример #8
0
  def terminate(self, request):
    """Asks a bot to terminate itself gracefully.

    The bot will stay in the DB, use 'delete' to remove it from the DB
    afterward. This request returns a pseudo-taskid that can be waited for to
    wait for the bot to turn down.

    This command is particularly useful when a privileged user needs to safely
    debug a machine specific issue. The user can trigger a terminate for one of
    the bot exhibiting the issue, wait for the pseudo-task to run then access
    the machine with the guarantee that the bot is not running anymore.
    """
    # TODO(maruel): Disallow a terminate task when there's one currently
    # pending or if the bot is considered 'dead', e.g. no contact since 10
    # minutes.
    logging.info('%s', request)
    bot_key = bot_management.get_info_key(request.bot_id)
    get_or_raise(bot_key)  # raises 404 if there is no such bot
    try:
      # Craft a special priority 0 task to tell the bot to shutdown.
      properties = task_request.TaskProperties(
          dimensions={u'id': request.bot_id},
          execution_timeout_secs=0,
          grace_period_secs=0,
          io_timeout_secs=0)
      now = utils.utcnow()
      request = task_request.TaskRequest(
          created_ts=now,
          expiration_ts=now + datetime.timedelta(days=1),
          name='Terminate %s' % request.bot_id,
          priority=0,
          properties=properties,
          tags=['terminate:1'],
          user=auth.get_current_identity().to_bytes())
      assert request.properties.is_terminate
      posted_request = task_request.make_request(request, acl.is_bot_or_admin())
    except (datastore_errors.BadValueError, TypeError, ValueError) as e:
      raise endpoints.BadRequestException(e.message)

    result_summary = task_scheduler.schedule_request(posted_request)
    return swarming_rpcs.TerminateResponse(
        task_id=task_pack.pack_result_summary_key(result_summary.key))
Пример #9
0
  def new(self, request):
    """Provides a TaskRequest and receives its metadata."""
    request_dict = json.loads(remote.protojson.encode_message(request))
    _transform_request(request_dict)

    # If the priority is below 100, make the the user has right to do so.
    if request_dict.get('priority', 255) < 100 and not acl.is_bot_or_admin():
      # Silently drop the priority of normal users.
      request_dict['priority'] = 100

    try:
      posted_request = task_request.make_request(request_dict)
    except (datastore_errors.BadValueError, TypeError, ValueError) as e:
      raise endpoints.BadRequestException(e.message)

    result_summary = task_scheduler.schedule_request(posted_request)
    posted_dict = utils.to_json_encodable(posted_request)
    return swarming_rpcs.TaskRequestMetadata(
        request=message_conversion.task_request_from_dict(posted_dict),
        task_id=task_pack.pack_result_summary_key(result_summary.key))
Пример #10
0
    def new(self, request):
        """Provides a TaskRequest and receive its metadata."""
        request_dict = json.loads(remote.protojson.encode_message(request))
        _transform_request(request_dict)

        # If the priority is below 100, make the the user has right to do so.
        if request_dict.get('priority',
                            255) < 100 and not acl.is_bot_or_admin():
            # Silently drop the priority of normal users.
            request_dict['priority'] = 100

        try:
            posted_request = task_request.make_request(request_dict)
        except (datastore_errors.BadValueError, TypeError, ValueError) as e:
            raise endpoints.BadRequestException(e.message)

        result_summary = task_scheduler.schedule_request(posted_request)
        posted_dict = utils.to_json_encodable(posted_request)
        return swarming_rpcs.TaskRequestMetadata(
            request=message_conversion.task_request_from_dict(posted_dict),
            task_id=task_pack.pack_result_summary_key(result_summary.key))