def get_consumer_id(task):
    for tag in task.tags:
        if not tags.is_resource_tag(tag):
            continue
        resource_type, resource_id = tags.parse_resource_tag(tag)
        if tags.RESOURCE_CONSUMER_TYPE == resource_type:
            return resource_id
示例#2
0
    def parse_tags(task):
        """
        Uses the tags entry in the task to render a user-friendly display of
        the actions and resources involved in the task.

        @param task: object representation of the task
        @type  task: Task

        @return: tuple of list of actions and list of resources involved
        @rtype:  ([], [])
        """

        actions = []
        resources = []

        if task.tags is None:
            return actions, resources

        for t in task.tags:
            if tag_utils.is_resource_tag(t):
                resource_type, resource_id = tag_utils.parse_resource_tag(t)
                resources.append('%s (%s)' % (resource_id, resource_type))
            else:
                tag_value = tag_utils.parse_value(t)
                actions.append(tag_value)

        return actions, resources
示例#3
0
    def parse_tags(task):
        """
        Uses the tags entry in the task to render a user-friendly display of
        the actions and resources involved in the task.

        @param task: object representation of the task
        @type  task: Task

        @return: tuple of list of actions and list of resources involved
        @rtype:  ([], [])
        """

        actions = []
        resources = []

        if task.tags is None:
            return actions, resources

        for t in task.tags:
            if tag_utils.is_resource_tag(t):
                resource_type, resource_id = tag_utils.parse_resource_tag(t)
                resources.append('%s (%s)' % (resource_id, resource_type))
            else:
                tag_value = tag_utils.parse_value(t)
                actions.append(tag_value)

        return actions, resources
示例#4
0
def get_consumer_id(task):
    for tag in task.tags:
        if not tags.is_resource_tag(tag):
            continue
        resource_type, resource_id = tags.parse_resource_tag(tag)
        if tags.RESOURCE_CONSUMER_TYPE == resource_type:
            return resource_id
示例#5
0
def cancel(task_id, revoke_task=True):
    """
    Cancel the task that is represented by the given task_id. This method cancels only the task
    with given task_id, not the spawned tasks. This also updates task's state to 'canceled'.

    :param task_id: The ID of the task you wish to cancel
    :type  task_id: basestring

    :param revoke_task: Whether to perform a celery revoke() on the task in edition to cancelling
                        Works around issue #2835 (https://pulp.plan.io/issues/2835)
    :type  revoke_task: bool

    :raises MissingResource: if a task with given task_id does not exist
    :raises PulpCodedException: if given task is already in a complete state
    """
    try:
        task_status = TaskStatus.objects.get(task_id=task_id)
    except DoesNotExist:
        raise MissingResource(task_id)

    if task_status['state'] in constants.CALL_COMPLETE_STATES:
        # If the task is already done, just stop
        msg = _('Task [%(task_id)s] already in a completed state: %(state)s')
        _logger.info(msg % {'task_id': task_id, 'state': task_status['state']})
        return

    if task_status['worker_name'] == 'agent':
        tag_dict = dict([
            tags.parse_resource_tag(t) for t in task_status['tags']
            if tags.is_resource_tag(t)
        ])
        agent_manager = managers.consumer_agent_manager()
        consumer_id = tag_dict.get(tags.RESOURCE_CONSUMER_TYPE)
        agent_manager.cancel_request(consumer_id, task_id)
    else:
        if revoke_task:
            controller.revoke(task_id, terminate=True)

    qs = TaskStatus.objects(task_id=task_id,
                            state__nin=constants.CALL_COMPLETE_STATES)
    qs.update_one(set__state=constants.CALL_CANCELED_STATE)

    msg = _('Task canceled: %(task_id)s.')
    msg = msg % {'task_id': task_id}
    _logger.info(msg)
示例#6
0
文件: tasks.py 项目: alexxa/pulp
def cancel(task_id, revoke_task=True):
    """
    Cancel the task that is represented by the given task_id. This method cancels only the task
    with given task_id, not the spawned tasks. This also updates task's state to 'canceled'.

    :param task_id: The ID of the task you wish to cancel
    :type  task_id: basestring

    :param revoke_task: Whether to perform a celery revoke() on the task in edition to cancelling
                        Works around issue #2835 (https://pulp.plan.io/issues/2835)
    :type  revoke_task: bool

    :raises MissingResource: if a task with given task_id does not exist
    :raises PulpCodedException: if given task is already in a complete state
    """
    try:
        task_status = TaskStatus.objects.get(task_id=task_id)
    except DoesNotExist:
        raise MissingResource(task_id)

    if task_status['state'] in constants.CALL_COMPLETE_STATES:
        # If the task is already done, just stop
        msg = _('Task [%(task_id)s] already in a completed state: %(state)s')
        _logger.info(msg % {'task_id': task_id, 'state': task_status['state']})
        return

    if task_status['worker_name'] == 'agent':
        tag_dict = dict(
            [
                tags.parse_resource_tag(t) for t in task_status['tags'] if tags.is_resource_tag(t)
            ])
        agent_manager = managers.consumer_agent_manager()
        consumer_id = tag_dict.get(tags.RESOURCE_CONSUMER_TYPE)
        agent_manager.cancel_request(consumer_id, task_id)
    else:
        if revoke_task:
            controller.revoke(task_id, terminate=True)

    qs = TaskStatus.objects(task_id=task_id, state__nin=constants.CALL_COMPLETE_STATES)
    qs.update_one(set__state=constants.CALL_CANCELED_STATE)

    msg = _('Task canceled: %(task_id)s.')
    msg = msg % {'task_id': task_id}
    _logger.info(msg)
示例#7
0
文件: tasks.py 项目: maxamillion/pulp
def cancel(task_id):
    """
    Cancel the task that is represented by the given task_id. This method cancels only the task
    with given task_id, not the spawned tasks. This also updates task's state to 'canceled'.

    :param task_id: The ID of the task you wish to cancel
    :type  task_id: basestring

    :raises MissingResource: if a task with given task_id does not exist
    :raises PulpCodedException: if given task is already in a complete state
    """
    try:
        task_status = TaskStatus.objects.get(task_id=task_id)
    except DoesNotExist:
        raise MissingResource(task_id)

    if task_status["state"] in constants.CALL_COMPLETE_STATES:
        # If the task is already done, just stop
        msg = _("Task [%(task_id)s] already in a completed state: %(state)s")
        _logger.info(msg % {"task_id": task_id, "state": task_status["state"]})
        return

    if task_status["worker_name"] == "agent":
        tag_dict = dict([tags.parse_resource_tag(t) for t in task_status["tags"] if tags.is_resource_tag(t)])
        agent_manager = managers.consumer_agent_manager()
        consumer_id = tag_dict.get(tags.RESOURCE_CONSUMER_TYPE)
        agent_manager.cancel_request(consumer_id, task_id)
    else:
        controller.revoke(task_id, terminate=True)

    qs = TaskStatus.objects(task_id=task_id, state__nin=constants.CALL_COMPLETE_STATES)
    qs.update_one(set__state=constants.CALL_CANCELED_STATE)

    msg = _("Task canceled: %(task_id)s.")
    msg = msg % {"task_id": task_id}
    _logger.info(msg)