Example #1
0
def update_resource_member(resource_id,
                           res_type,
                           member_id,
                           values,
                           session=None):
    # Only member who is not the owner of the resource can update the
    # membership status.
    if member_id != security.get_project_id():
        raise exc.DBEntityNotFoundError(
            "Resource member not found [resource_id=%s, member_id=%s]" %
            (resource_id, member_id))

    query = _secure_query(
        models.ResourceMember).filter_by(resource_type=res_type)

    res_member = query.filter(
        _get_criterion(resource_id, member_id, is_owner=False)).first()

    if not res_member:
        raise exc.DBEntityNotFoundError(
            "Resource member not found [resource_id=%s, member_id=%s]" %
            (resource_id, member_id))

    res_member.update(values.copy())

    return res_member
Example #2
0
def update_cron_trigger(name, values, session=None, query_filter=None):
    cron_trigger = _get_cron_trigger(name)

    if not cron_trigger:
        raise exc.DBEntityNotFoundError(
            "Cron trigger not found [name=%s]" % name
        )

    if query_filter:
        try:
            # Execute the UPDATE statement with the query_filter as the WHERE.
            specimen = models.CronTrigger(id=cron_trigger.id, **query_filter)

            query = b.model_query(models.CronTrigger)

            cron_trigger = query.update_on_match(
                specimen=specimen,
                surrogate_key='id',
                values=values
            )

            return cron_trigger, 1

        except oslo_sqlalchemy.update_match.NoRowsMatched:
            LOG.debug(
                "No rows matched for cron update call"
                "[id=%s, values=%s, query_filter=%s", id, values, query_filter
            )

            return cron_trigger, 0

    else:
        cron_trigger.update(values.copy())

        return cron_trigger, len(session.dirty)
Example #3
0
def delete_task_execution(id, session=None):
    count = _secure_query(
        models.TaskExecution).filter(models.TaskExecution.id == id).delete()

    if count == 0:
        raise exc.DBEntityNotFoundError("Task execution not found [id=%s]" %
                                        id)
Example #4
0
 def test_nf_with_no_message(self):
     exc = exceptions.DBEntityNotFoundError()
     self.assertIn("Object not found", six.text_type(exc))
     self.assertEqual(
         404,
         exc.http_code,
     )
Example #5
0
def get_workflow_definition(identifier, namespace='', fields=(), session=None):
    """Gets workflow definition by name or uuid.

    :param identifier: Identifier could be in the format of plain string or
                       uuid.
    :param namespace: The namespace the workflow is in. Optional.
    :param fields: Fields that need to be loaded. For example,
        (WorkflowDefinition.name,)
    :return: Workflow definition.
    """
    ctx = context.ctx()

    wf_def = _get_db_object_by_name_and_namespace_or_id(
        models.WorkflowDefinition,
        identifier,
        namespace=namespace,
        insecure=ctx.is_admin,
        columns=fields)

    if not wf_def:
        raise exc.DBEntityNotFoundError(
            "Workflow not found [workflow_identifier=%s, namespace=%s]" %
            (identifier, namespace))

    return wf_def
Example #6
0
def get_scheduled_job(id, session=None):
    job = _get_db_object_by_id(models.ScheduledJob, id)

    if not job:
        raise exc.DBEntityNotFoundError("Scheduled job not found [id=%s]" % id)

    return job
Example #7
0
def delete_workbook(name, session=None):
    count = _secure_query(
        models.Workbook).filter(models.Workbook.name == name).delete()

    if count == 0:
        raise exc.DBEntityNotFoundError(
            "Workbook not found [workbook_name=%s]" % name)
Example #8
0
def get_action_definition_by_id(id, session=None):
    action_def = _get_db_object_by_id(models.ActionDefinition, id)

    if not action_def:
        raise exc.DBEntityNotFoundError("Action not found [action_id=%s]" % id)

    return action_def
Example #9
0
def get_delayed_call(id, session=None):
    delayed_call = _get_db_object_by_id(models.DelayedCall, id)

    if not delayed_call:
        raise exc.DBEntityNotFoundError("Delayed Call not found [id=%s]" % id)

    return delayed_call
Example #10
0
def delete_environment(name, session=None):
    count = _secure_query(
        models.Environment).filter(models.Environment.name == name).delete()

    if count == 0:
        raise exc.DBEntityNotFoundError("Environment not found [name=%s]" %
                                        name)
Example #11
0
    def get(self, identifier, namespace=''):
        """Return the named action.

        :param identifier: ID or name of the Action to get.
        :param namespace: The namespace of the action.
        """

        acl.enforce('actions:get', context.ctx())

        LOG.debug("Fetch action [identifier=%s]", identifier)

        action_provider = action_service.get_system_action_provider()

        # Here we assume that the action search might involve DB operations
        # so we need to apply the regular retrying logic as everywhere else.
        action_desc = rest_utils.rest_retry_on_db_error(action_provider.find)(
            identifier, namespace=namespace)

        if action_desc is None:
            # TODO(rakhmerov): We need to change exception class so that
            # it's not DB specific. But it should be associated with the
            # same HTTP code.
            raise exc.DBEntityNotFoundError(
                'Action not found [name=%s, namespace=%s]' %
                (identifier, namespace))

        return _action_descriptor_to_resource(action_desc)
Example #12
0
def delete_scheduled_job(id, session=None):
    # It's safe to use insecure query here because users can't access
    # scheduled job.
    count = b.model_query(
        models.ScheduledJob).filter(models.ScheduledJob.id == id).delete()

    if count == 0:
        raise exc.DBEntityNotFoundError("Scheduled job not found [id=%s]" % id)
Example #13
0
def get_cron_trigger(name, session=None):
    cron_trigger = _get_db_object_by_name(models.CronTrigger, name)

    if not cron_trigger:
        raise exc.DBEntityNotFoundError("Cron trigger not found [name=%s]" %
                                        name)

    return cron_trigger
Example #14
0
def get_workflow_execution(id, session=None):
    wf_ex = _get_db_object_by_id(models.WorkflowExecution, id)

    if not wf_ex:
        raise exc.DBEntityNotFoundError("WorkflowExecution not found [id=%s]" %
                                        id)

    return wf_ex
Example #15
0
def get_task_execution(id, session=None):
    task_ex = _get_db_object_by_id(models.TaskExecution, id)

    if not task_ex:
        raise exc.DBEntityNotFoundError("Task execution not found [id=%s]" %
                                        id)

    return task_ex
Example #16
0
def get_action_definition(identifier, session=None):
    a_def = _get_db_object_by_name_or_id(models.ActionDefinition, identifier)

    if not a_def:
        raise exc.DBEntityNotFoundError(
            "Action definition not found [action_name=%s]" % identifier)

    return a_def
Example #17
0
def get_action_execution(id, session=None):
    a_ex = _get_db_object_by_id(models.ActionExecution, id)

    if not a_ex:
        raise exc.DBEntityNotFoundError("ActionExecution not found [id=%s]" %
                                        id)

    return a_ex
Example #18
0
def get_workflow_definition_by_id(id, session=None):
    wf_def = _get_db_object_by_id(models.WorkflowDefinition, id)

    if not wf_def:
        raise exc.DBEntityNotFoundError("Workflow not found [workflow_id=%s]" %
                                        id)

    return wf_def
Example #19
0
def get_event_trigger(id, insecure=False, session=None):
    event_trigger = _get_event_trigger(id, insecure)

    if not event_trigger:
        raise exc.DBEntityNotFoundError("Event trigger not found [id=%s]." %
                                        id)

    return event_trigger
Example #20
0
def get_environment(name, session=None):
    env = _get_db_object_by_name(models.Environment, name)

    if not env:
        raise exc.DBEntityNotFoundError("Environment not found [name=%s]" %
                                        name)

    return env
Example #21
0
def delete_delayed_call(id, session=None):
    # It's safe to use insecure query here because users can't access
    # delayed calls.
    count = b.model_query(
        models.DelayedCall).filter(models.DelayedCall.id == id).delete()

    if count == 0:
        raise exc.DBEntityNotFoundError("Delayed Call not found [id=%s]" % id)
Example #22
0
def get_workbook(name, session=None):
    wb = _get_db_object_by_name(models.Workbook, name)

    if not wb:
        raise exc.DBEntityNotFoundError(
            "Workbook not found [workbook_name=%s]" % name)

    return wb
Example #23
0
def delete_delayed_call(id, session=None):
    delayed_call = _get_delayed_call(id)

    if not delayed_call:
        raise exc.DBEntityNotFoundError(
            "DelayedCall not found [id=%s]" % id
        )

    session.delete(delayed_call)
Example #24
0
def get_cron_trigger_by_id(id, session=None):
    ctx = context.ctx()
    cron_trigger = _get_db_object_by_id(models.CronTrigger,
                                        id,
                                        insecure=ctx.is_admin)
    if not cron_trigger:
        raise exc.DBEntityNotFoundError("Cron trigger not found [id=%s]" % id)

    return cron_trigger
Example #25
0
def get_workflow_execution(id):
    wf_ex = _get_workflow_execution(id)

    if not wf_ex:
        raise exc.DBEntityNotFoundError(
            "WorkflowExecution not found [id=%s]" % id
        )

    return wf_ex
Example #26
0
def get_task_execution(id):
    task_ex = _get_task_execution(id)

    if not task_ex:
        raise exc.DBEntityNotFoundError(
            "Task execution not found [id=%s]" % id
        )

    return task_ex
Example #27
0
def get_delayed_call(id, session=None):
    delayed_call = _get_delayed_call(id=id, session=session)

    if not delayed_call:
        raise exc.DBEntityNotFoundError(
            "Delayed Call not found [id=%s]" % id
        )

    return delayed_call
Example #28
0
def delete_task_execution(id, session=None):
    task_ex = _get_task_execution(id)

    if not task_ex:
        raise exc.DBEntityNotFoundError(
            "TaskExecution not found [id=%s]" % id
        )

    session.delete(task_ex)
Example #29
0
def delete_workflow_execution(id, session=None):
    wf_ex = _get_workflow_execution(id)

    if not wf_ex:
        raise exc.DBEntityNotFoundError(
            "WorkflowExecution not found [id=%s]" % id
        )

    session.delete(wf_ex)
Example #30
0
def delete_event_trigger(id, session=None):
    # It's safe to use insecure query here because users can't access
    # delayed calls.
    count = b.model_query(
        models.EventTrigger).filter(models.EventTrigger.id == id).delete()

    if count == 0:
        raise exc.DBEntityNotFoundError("Event trigger not found [id=%s]." %
                                        id)