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
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)
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)
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, )
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
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
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)
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
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
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)
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)
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)
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
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
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
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
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
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
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
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
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)
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
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)
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
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
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
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
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)
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)
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)