Merge "Add filters to all collections listing functions (tags included)"

This commit is contained in:
Jenkins 2016-07-06 12:21:49 +00:00 committed by Gerrit Code Review
commit 5437ad417f
10 changed files with 481 additions and 53 deletions

View File

@ -184,9 +184,14 @@ class ActionsController(rest.RestController, hooks.HookController):
db_api.delete_action_definition(name) db_api.delete_action_definition(name)
@wsme_pecan.wsexpose(Actions, types.uuid, int, types.uniquelist, @wsme_pecan.wsexpose(Actions, types.uuid, int, types.uniquelist,
types.list, types.uniquelist, types.jsontype) types.list, types.uniquelist, wtypes.text,
wtypes.text, SCOPE_TYPES, wtypes.text,
types.uniquelist, wtypes.text, wtypes.text,
wtypes.text, bool, wtypes.text)
def get_all(self, marker=None, limit=None, sort_keys='name', def get_all(self, marker=None, limit=None, sort_keys='name',
sort_dirs='asc', fields='', **filters): sort_dirs='asc', fields='', created_at=None, name=None,
scope=None, tag=None, tags=None, updated_at=None,
description=None, definition=None, is_system=None, input=None):
"""Return all actions. """Return all actions.
:param marker: Optional. Pagination marker for large data sets. :param marker: Optional. Pagination marker for large data sets.
@ -196,18 +201,53 @@ class ActionsController(rest.RestController, hooks.HookController):
:param sort_keys: Optional. Columns to sort results by. :param sort_keys: Optional. Columns to sort results by.
Default: name. Default: name.
:param sort_dirs: Optional. Directions to sort corresponding to :param sort_dirs: Optional. Directions to sort corresponding to
sort_keys, "asc" or "desc" can be choosed. sort_keys, "asc" or "desc" can be chosen.
Default: asc. Default: asc.
:param fields: Optional. A specified list of fields of the resource to :param fields: Optional. A specified list of fields of the resource to
be returned. 'id' will be included automatically in be returned. 'id' will be included automatically in
fields if it's provided, since it will be used when fields if it's provided, since it will be used when
constructing 'next' link. constructing 'next' link.
:param filters: Optional. A list of filters to apply to the result. :param name: Optional. Keep only resources with a specific name.
:param scope: Optional. Keep only resources with a specific scope.
:param definition: Optional. Keep only resources with a specific
definition.
:param is_system: Optional. Keep only system actions or ad-hoc
actions (if False).
:param input: Optional. Keep only resources with a specific input.
:param description: Optional. Keep only resources with a specific
description.
:param tag: Optional. Keep only resources with a specific tag. If it is
used with 'tags', it will be appended to the list of
matching tags.
:param tags: Optional. Keep only resources containing specific tags.
:param created_at: Optional. Keep only resources created at a specific
time and date.
:param updated_at: Optional. Keep only resources with specific latest
update time and date.
Where project_id is the same as the requester or Where project_id is the same as the requester or
project_id is different but the scope is public. project_id is different but the scope is public.
""" """
acl.enforce('actions:list', context.ctx()) acl.enforce('actions:list', context.ctx())
if tag is not None:
if tags is None:
tags = [tag]
else:
tags.append(tag)
filters = rest_utils.filters_to_dict(
created_at=created_at,
name=name,
scope=scope,
tags=tags,
updated_at=updated_at,
description=description,
definition=definition,
is_system=is_system,
input=input
)
LOG.info("Fetch actions. marker=%s, limit=%s, sort_keys=%s, " LOG.info("Fetch actions. marker=%s, limit=%s, sort_keys=%s, "
"sort_dirs=%s, filters=%s", marker, limit, sort_keys, "sort_dirs=%s, filters=%s", marker, limit, sort_keys,
sort_dirs, filters) sort_dirs, filters)

View File

@ -125,7 +125,7 @@ def _get_action_executions(task_execution_id=None, marker=None, limit=None,
fields='', **filters): fields='', **filters):
"""Return all action executions. """Return all action executions.
Where project_id is the same as the requestor or Where project_id is the same as the requester or
project_id is different but the scope is public. project_id is different but the scope is public.
:param marker: Optional. Pagination marker for large data sets. :param marker: Optional. Pagination marker for large data sets.
@ -230,12 +230,20 @@ class ActionExecutionsController(rest.RestController):
return ActionExecution.from_dict(values) return ActionExecution.from_dict(values)
@wsme_pecan.wsexpose(ActionExecutions, types.uuid, int, types.uniquelist, @wsme_pecan.wsexpose(ActionExecutions, types.uuid, int, types.uniquelist,
types.list, types.uniquelist, types.jsontype) types.list, types.uniquelist, wtypes.text,
wtypes.text, wtypes.text, types.uniquelist,
wtypes.text, wtypes.text, wtypes.text, types.uuid,
wtypes.text, wtypes.text, bool, types.jsontype,
types.jsontype, types.jsontype, wtypes.text)
def get_all(self, marker=None, limit=None, sort_keys='created_at', def get_all(self, marker=None, limit=None, sort_keys='created_at',
sort_dirs='asc', fields='', **filters): sort_dirs='asc', fields='', created_at=None, name=None,
tag=None, tags=None, updated_at=None, workflow_name=None,
task_name=None, task_execution_id=None, state=None,
state_info=None, accepted=None, input=None, output=None,
params=None, description=None):
"""Return all tasks within the execution. """Return all tasks within the execution.
Where project_id is the same as the requestor or Where project_id is the same as the requester or
project_id is different but the scope is public. project_id is different but the scope is public.
:param marker: Optional. Pagination marker for large data sets. :param marker: Optional. Pagination marker for large data sets.
@ -252,10 +260,57 @@ class ActionExecutionsController(rest.RestController):
be returned. 'id' will be included automatically in be returned. 'id' will be included automatically in
fields if it's provided, since it will be used when fields if it's provided, since it will be used when
constructing 'next' link. constructing 'next' link.
:param filters: Optional. A list of filters to apply to the result. :param name: Optional. Keep only resources with a specific name.
:param workflow_name: Optional. Keep only resources with a specific
workflow name.
:param task_name: Optional. Keep only resources with a specific
task name.
:param task_execution_id: Optional. Keep only resources within a
specific task execution.
:param state: Optional. Keep only resources with a specific state.
:param state_info: Optional. Keep only resources with specific state
information.
:param accepted: Optional. Keep only resources which have been accepted
or not.
:param input: Optional. Keep only resources with a specific input.
:param output: Optional. Keep only resources with a specific output.
:param params: Optional. Keep only resources with specific parameters.
:param description: Optional. Keep only resources with a specific
description.
:param tag: Optional. Keep only resources with a specific tag. If it is
used with 'tags', it will be appended to the list of
matching tags.
:param tags: Optional. Keep only resources containing specific tags.
:param created_at: Optional. Keep only resources created at a specific
time and date.
:param updated_at: Optional. Keep only resources with specific latest
update time and date.
""" """
acl.enforce('action_executions:list', context.ctx()) acl.enforce('action_executions:list', context.ctx())
if tag is not None:
if tags is None:
tags = [tag]
else:
tags.append(tag)
filters = rest_utils.filters_to_dict(
created_at=created_at,
name=name,
tags=tags,
updated_at=updated_at,
workflow_name=workflow_name,
task_name=task_name,
task_execution_id=task_execution_id,
state=state,
state_info=state_info,
accepted=accepted,
input=input,
output=output,
params=params,
description=description
)
LOG.info("Fetch action_executions. marker=%s, limit=%s, " LOG.info("Fetch action_executions. marker=%s, limit=%s, "
"sort_keys=%s, sort_dirs=%s, filters=%s", "sort_keys=%s, sort_dirs=%s, filters=%s",
marker, limit, sort_keys, sort_dirs, filters) marker, limit, sort_keys, sort_dirs, filters)
@ -297,14 +352,23 @@ class ActionExecutionsController(rest.RestController):
class TasksActionExecutionController(rest.RestController): class TasksActionExecutionController(rest.RestController):
@wsme_pecan.wsexpose(ActionExecutions, types.uuid, types.uuid, int, @wsme_pecan.wsexpose(ActionExecutions, types.uuid, types.uuid, int,
types.uniquelist, types.list, types.uniquelist, types.uniquelist, types.list, types.uniquelist,
types.jsontype) wtypes.text, wtypes.text, types.uniquelist,
wtypes.text, wtypes.text, wtypes.text, wtypes.text,
wtypes.text, wtypes.text, bool, types.jsontype,
types.jsontype, types.jsontype, wtypes.text)
def get_all(self, task_execution_id, marker=None, limit=None, def get_all(self, task_execution_id, marker=None, limit=None,
sort_keys='created_at', sort_dirs='asc', fields='', **filters): sort_keys='created_at', sort_dirs='asc', fields='',
created_at=None, name=None, tag=None, tags=None,
updated_at=None, workflow_name=None, task_name=None,
state=None, state_info=None, accepted=None, input=None,
output=None, params=None, description=None):
"""Return all tasks within the execution. """Return all tasks within the execution.
Where project_id is the same as the requestor or Where project_id is the same as the requester or
project_id is different but the scope is public. project_id is different but the scope is public.
:param task_execution_id: Keep only resources within a specific task
execution.
:param marker: Optional. Pagination marker for large data sets. :param marker: Optional. Pagination marker for large data sets.
:param limit: Optional. Maximum number of resources to return in a :param limit: Optional. Maximum number of resources to return in a
single result. Default value is None for backward single result. Default value is None for backward
@ -319,15 +383,59 @@ class TasksActionExecutionController(rest.RestController):
be returned. 'id' will be included automatically in be returned. 'id' will be included automatically in
fields if it's provided, since it will be used when fields if it's provided, since it will be used when
constructing 'next' link. constructing 'next' link.
:param filters: Optional. A list of filters to apply to the result. :param name: Optional. Keep only resources with a specific name.
:param workflow_name: Optional. Keep only resources with a specific
workflow name.
:param task_name: Optional. Keep only resources with a specific
task name.
:param state: Optional. Keep only resources with a specific state.
:param state_info: Optional. Keep only resources with specific state
information.
:param accepted: Optional. Keep only resources which have been accepted
or not.
:param input: Optional. Keep only resources with a specific input.
:param output: Optional. Keep only resources with a specific output.
:param params: Optional. Keep only resources with specific parameters.
:param description: Optional. Keep only resources with a specific
description.
:param tag: Optional. Keep only resources with a specific tag. If it is
used with 'tags', it will be appended to the list of
matching tags.
:param tags: Optional. Keep only resources containing specific tags.
:param created_at: Optional. Keep only resources created at a specific
time and date.
:param updated_at: Optional. Keep only resources with specific latest
update time and date.
""" """
acl.enforce('action_executions:list', context.ctx()) acl.enforce('action_executions:list', context.ctx())
if tag is not None:
if tags is None:
tags = [tag]
else:
tags.append(tag)
filters = rest_utils.filters_to_dict(
created_at=created_at,
name=name,
tags=tags,
updated_at=updated_at,
workflow_name=workflow_name,
task_name=task_name,
task_execution_id=task_execution_id,
state=state,
state_info=state_info,
accepted=accepted,
input=input,
output=output,
params=params,
description=description
)
LOG.info("Fetch action_executions. marker=%s, limit=%s, " LOG.info("Fetch action_executions. marker=%s, limit=%s, "
"sort_keys=%s, sort_dirs=%s, filters=%s", "sort_keys=%s, sort_dirs=%s, filters=%s",
marker, limit, sort_keys, sort_dirs, filters) marker, limit, sort_keys, sort_dirs, filters)
return _get_action_executions( return _get_action_executions(
task_execution_id=task_execution_id,
marker=marker, marker=marker,
limit=limit, limit=limit,
sort_keys=sort_keys, sort_keys=sort_keys,

View File

@ -125,9 +125,17 @@ class CronTriggersController(rest.RestController):
db_api.delete_cron_trigger(name) db_api.delete_cron_trigger(name)
@wsme_pecan.wsexpose(CronTriggers, types.uuid, int, types.uniquelist, @wsme_pecan.wsexpose(CronTriggers, types.uuid, int, types.uniquelist,
types.list, types.uniquelist, types.jsontype) types.list, types.uniquelist, wtypes.text,
wtypes.text, types.uuid, types.jsontype,
types.jsontype, SCOPE_TYPES, wtypes.text,
wtypes.IntegerType(minimum=1), wtypes.text,
wtypes.text, wtypes.text, wtypes.text)
def get_all(self, marker=None, limit=None, sort_keys='created_at', def get_all(self, marker=None, limit=None, sort_keys='created_at',
sort_dirs='asc', fields='', **filters): sort_dirs='asc', fields='', name=None, workflow_name=None,
workflow_id=None, workflow_input=None, workflow_params=None,
scope=None, pattern=None, remaining_executions=None,
first_execution_time=None, next_execution_time=None,
created_at=None, updated_at=None):
"""Return all cron triggers. """Return all cron triggers.
:param marker: Optional. Pagination marker for large data sets. :param marker: Optional. Pagination marker for large data sets.
@ -144,10 +152,45 @@ class CronTriggersController(rest.RestController):
be returned. 'id' will be included automatically in be returned. 'id' will be included automatically in
fields if it's provided, since it will be used when fields if it's provided, since it will be used when
constructing 'next' link. constructing 'next' link.
:param filters: Optional. A list of filters to apply to the result. :param name: Optional. Keep only resources with a specific name.
:param workflow_name: Optional. Keep only resources with a specific
workflow name.
:param workflow_id: Optional. Keep only resources with a specific
workflow ID.
:param workflow_input: Optional. Keep only resources with a specific
workflow input.
:param workflow_params: Optional. Keep only resources with specific
workflow parameters.
:param scope: Optional. Keep only resources with a specific scope.
:param pattern: Optional. Keep only resources with a specific pattern.
:param remaining_executions: Optional. Keep only resources with a
specific number of remaining executions.
:param first_execution_time: Optional. Keep only resources with a
specific time and date of first execution.
:param next_execution_time: Optional. Keep only resources with a
specific time and date of next execution.
:param created_at: Optional. Keep only resources created at a specific
time and date.
:param updated_at: Optional. Keep only resources with specific latest
update time and date.
""" """
acl.enforce('cron_triggers:list', context.ctx()) acl.enforce('cron_triggers:list', context.ctx())
filters = rest_utils.filters_to_dict(
created_at=created_at,
name=name,
updated_at=updated_at,
workflow_name=workflow_name,
workflow_id=workflow_id,
workflow_input=workflow_input,
workflow_params=workflow_params,
scope=scope,
pattern=pattern,
remaining_executions=remaining_executions,
first_execution_time=first_execution_time,
next_execution_time=next_execution_time
)
LOG.info("Fetch cron triggers. marker=%s, limit=%s, sort_keys=%s, " LOG.info("Fetch cron triggers. marker=%s, limit=%s, sort_keys=%s, "
"sort_dirs=%s, filters=%s", marker, limit, sort_keys, "sort_dirs=%s, filters=%s", marker, limit, sort_keys,
sort_dirs, filters) sort_dirs, filters)

View File

@ -30,6 +30,7 @@ from mistral.utils import rest_utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
SCOPE_TYPES = wtypes.Enum(str, 'private', 'public')
SAMPLE = { SAMPLE = {
'server': 'localhost', 'server': 'localhost',
@ -46,7 +47,7 @@ class Environment(resource.Resource):
name = wtypes.text name = wtypes.text
description = wtypes.text description = wtypes.text
variables = types.jsontype variables = types.jsontype
scope = wtypes.Enum(str, 'private', 'public') scope = SCOPE_TYPES
created_at = wtypes.text created_at = wtypes.text
updated_at = wtypes.text updated_at = wtypes.text
@ -78,12 +79,15 @@ class Environments(resource.ResourceList):
class EnvironmentController(rest.RestController): class EnvironmentController(rest.RestController):
@wsme_pecan.wsexpose(Environments, types.uuid, int, types.uniquelist, @wsme_pecan.wsexpose(Environments, types.uuid, int, types.uniquelist,
types.list, types.uniquelist, types.jsontype) types.list, types.uniquelist, wtypes.text,
wtypes.text, types.jsontype, SCOPE_TYPES, wtypes.text,
wtypes.text)
def get_all(self, marker=None, limit=None, sort_keys='created_at', def get_all(self, marker=None, limit=None, sort_keys='created_at',
sort_dirs='asc', fields='', **filters): sort_dirs='asc', fields='', name=None, description=None,
variables=None, scope=None, created_at=None, updated_at=None):
"""Return all environments. """Return all environments.
Where project_id is the same as the requestor or Where project_id is the same as the requester or
project_id is different but the scope is public. project_id is different but the scope is public.
:param marker: Optional. Pagination marker for large data sets. :param marker: Optional. Pagination marker for large data sets.
@ -100,10 +104,28 @@ class EnvironmentController(rest.RestController):
be returned. 'id' will be included automatically in be returned. 'id' will be included automatically in
fields if it's provided, since it will be used when fields if it's provided, since it will be used when
constructing 'next' link. constructing 'next' link.
:param filters: Optional. A list of filters to apply to the result. :param name: Optional. Keep only resources with a specific name.
:param description: Optional. Keep only resources with a specific
description.
:param variables: Optional. Keep only resources with specific
variables.
:param scope: Optional. Keep only resources with a specific scope.
:param created_at: Optional. Keep only resources created at a specific
time and date.
:param updated_at: Optional. Keep only resources with specific latest
update time and date.
""" """
acl.enforce('environments:list', context.ctx()) acl.enforce('environments:list', context.ctx())
filters = rest_utils.filters_to_dict(
created_at=created_at,
name=name,
updated_at=updated_at,
description=description,
variables=variables,
scope=scope
)
LOG.info("Fetch environments. marker=%s, limit=%s, sort_keys=%s, " LOG.info("Fetch environments. marker=%s, limit=%s, sort_keys=%s, "
"sort_dirs=%s, filters=%s", marker, limit, sort_keys, "sort_dirs=%s, filters=%s", marker, limit, sort_keys,
sort_dirs, filters) sort_dirs, filters)

View File

@ -33,6 +33,8 @@ from mistral.workflow import states
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
STATE_TYPES = wtypes.Enum(str, states.IDLE, states.RUNNING, states.SUCCESS,
states.ERROR, states.PAUSED)
# TODO(rakhmerov): Make sure to make all needed renaming on public API. # TODO(rakhmerov): Make sure to make all needed renaming on public API.
@ -254,9 +256,15 @@ class ExecutionsController(rest.RestController):
return db_api.delete_workflow_execution(id) return db_api.delete_workflow_execution(id)
@wsme_pecan.wsexpose(Executions, types.uuid, int, types.uniquelist, @wsme_pecan.wsexpose(Executions, types.uuid, int, types.uniquelist,
types.list, types.uniquelist, types.jsontype) types.list, types.uniquelist, wtypes.text,
types.uuid, wtypes.text, types.jsontype, types.uuid,
STATE_TYPES, wtypes.text, types.jsontype,
types.jsontype, wtypes.text, wtypes.text)
def get_all(self, marker=None, limit=None, sort_keys='created_at', def get_all(self, marker=None, limit=None, sort_keys='created_at',
sort_dirs='asc', fields='', **filters): sort_dirs='asc', fields='', workflow_name=None,
workflow_id=None, description=None, params=None,
task_execution_id=None, state=None, state_info=None,
input=None, output=None, created_at=None, updated_at=None):
"""Return all Executions. """Return all Executions.
:param marker: Optional. Pagination marker for large data sets. :param marker: Optional. Pagination marker for large data sets.
@ -273,10 +281,41 @@ class ExecutionsController(rest.RestController):
be returned. 'id' will be included automatically in be returned. 'id' will be included automatically in
fields if it's provided, since it will be used when fields if it's provided, since it will be used when
constructing 'next' link. constructing 'next' link.
:param filters: Optional. A list of filters to apply to the result. :param workflow_name: Optional. Keep only resources with a specific
workflow name.
:param workflow_id: Optional. Keep only resources with a specific
workflow ID.
:param description: Optional. Keep only resources with a specific
description.
:param params: Optional. Keep only resources with specific parameters.
:param task_execution_id: Optional. Keep only resources with a
specific task execution ID.
:param state: Optional. Keep only resources with a specific state.
:param state_info: Optional. Keep only resources with specific
state information.
:param input: Optional. Keep only resources with a specific input.
:param output: Optional. Keep only resources with a specific output.
:param created_at: Optional. Keep only resources created at a specific
time and date.
:param updated_at: Optional. Keep only resources with specific latest
update time and date.
""" """
acl.enforce('executions:list', context.ctx()) acl.enforce('executions:list', context.ctx())
filters = rest_utils.filters_to_dict(
created_at=created_at,
workflow_name=workflow_name,
workflow_id=workflow_id,
params=params,
task_execution_id=task_execution_id,
state=state,
state_info=state_info,
input=input,
output=output,
updated_at=updated_at,
description=description
)
LOG.info( LOG.info(
"Fetch executions. marker=%s, limit=%s, sort_keys=%s, " "Fetch executions. marker=%s, limit=%s, sort_keys=%s, "
"sort_dirs=%s, filters=%s", marker, limit, sort_keys, sort_dirs, "sort_dirs=%s, filters=%s", marker, limit, sort_keys, sort_dirs,

View File

@ -36,6 +36,8 @@ from mistral.workflow import states
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
STATE_TYPES = wtypes.Enum(str, states.IDLE, states.RUNNING, states.SUCCESS,
states.ERROR, states.RUNNING_DELAYED)
class Task(resource.Resource): class Task(resource.Resource):
@ -112,7 +114,7 @@ def _get_task_resources_with_results(wf_ex_id=None, marker=None, limit=None,
fields='', **filters): fields='', **filters):
"""Return all tasks within the execution. """Return all tasks within the execution.
Where project_id is the same as the requestor or Where project_id is the same as the requester or
project_id is different but the scope is public. project_id is different but the scope is public.
:param marker: Optional. Pagination marker for large data sets. :param marker: Optional. Pagination marker for large data sets.
@ -164,12 +166,18 @@ class TasksController(rest.RestController):
return _get_task_resource_with_result(task_ex) return _get_task_resource_with_result(task_ex)
@wsme_pecan.wsexpose(Tasks, types.uuid, int, types.uniquelist, @wsme_pecan.wsexpose(Tasks, types.uuid, int, types.uniquelist,
types.list, types.uniquelist, types.jsontype) types.list, types.uniquelist, wtypes.text,
wtypes.text, types.uuid, types.uuid, STATE_TYPES,
wtypes.text, wtypes.text, types.jsontype, bool,
wtypes.text, wtypes.text, bool, types.jsontype)
def get_all(self, marker=None, limit=None, sort_keys='created_at', def get_all(self, marker=None, limit=None, sort_keys='created_at',
sort_dirs='asc', fields='', **filters): sort_dirs='asc', fields='', name=None, workflow_name=None,
workflow_id=None, workflow_execution_id=None, state=None,
state_info=None, result=None, published=None, processed=None,
created_at=None, updated_at=None, reset=None, env=None):
"""Return all tasks. """Return all tasks.
Where project_id is the same as the requestor or Where project_id is the same as the requester or
project_id is different but the scope is public. project_id is different but the scope is public.
:param marker: Optional. Pagination marker for large data sets. :param marker: Optional. Pagination marker for large data sets.
@ -186,10 +194,47 @@ class TasksController(rest.RestController):
be returned. 'id' will be included automatically in be returned. 'id' will be included automatically in
fields if it's provided, since it will be used when fields if it's provided, since it will be used when
constructing 'next' link. constructing 'next' link.
:param filters: Optional. A list of filters to apply to the result. :param name: Optional. Keep only resources with a specific name.
:param workflow_name: Optional. Keep only resources with a specific
workflow name.
:param workflow_id: Optional. Keep only resources with a specific
workflow ID.
:param workflow_execution_id: Optional. Keep only resources with a
specific workflow execution ID.
:param state: Optional. Keep only resources with a specific state.
:param state_info: Optional. Keep only resources with specific
state information.
:param result: Optional. Keep only resources with a specific result.
:param published: Optional. Keep only resources with specific
published content.
:param processed: Optional. Keep only resources which have been
processed or not.
:param reset: Optional. Keep only resources which have been reset or
not.
:param env: Optional. Keep only resources with a specific environment.
:param created_at: Optional. Keep only resources created at a specific
time and date.
:param updated_at: Optional. Keep only resources with specific latest
update time and date.
""" """
acl.enforce('tasks:list', context.ctx()) acl.enforce('tasks:list', context.ctx())
filters = rest_utils.filters_to_dict(
created_at=created_at,
workflow_name=workflow_name,
workflow_id=workflow_id,
state=state,
state_info=state_info,
updated_at=updated_at,
name=name,
workflow_execution_id=workflow_execution_id,
result=result,
published=published,
processed=processed,
reset=reset,
env=env
)
LOG.info("Fetch tasks. marker=%s, limit=%s, sort_keys=%s, " LOG.info("Fetch tasks. marker=%s, limit=%s, sort_keys=%s, "
"sort_dirs=%s, filters=%s", marker, limit, sort_keys, "sort_dirs=%s, filters=%s", marker, limit, sort_keys,
sort_dirs, filters) sort_dirs, filters)
@ -257,14 +302,19 @@ class TasksController(rest.RestController):
class ExecutionTasksController(rest.RestController): class ExecutionTasksController(rest.RestController):
@wsme_pecan.wsexpose(Tasks, types.uuid, types.uuid, int, types.uniquelist, @wsme_pecan.wsexpose(Tasks, types.uuid, types.uuid, int, types.uniquelist,
types.list, types.uniquelist) types.list, types.uniquelist, wtypes.text,
wtypes.text, types.uuid, STATE_TYPES, wtypes.text,
wtypes.text, types.jsontype, bool, wtypes.text,
wtypes.text, bool, types.jsontype)
def get_all(self, workflow_execution_id, marker=None, limit=None, def get_all(self, workflow_execution_id, marker=None, limit=None,
sort_keys='created_at', sort_dirs='asc', fields='', **filters): sort_keys='created_at', sort_dirs='asc', fields='', name=None,
workflow_name=None, workflow_id=None, state=None,
state_info=None, result=None, published=None, processed=None,
created_at=None, updated_at=None, reset=None, env=None):
"""Return all tasks within the execution. """Return all tasks within the execution.
Where project_id is the same as the requestor or Where project_id is the same as the requester or
project_id is different but the scope is public. project_id is different but the scope is public.
:param marker: Optional. Pagination marker for large data sets. :param marker: Optional. Pagination marker for large data sets.
@ -281,9 +331,48 @@ class ExecutionTasksController(rest.RestController):
be returned. 'id' will be included automatically in be returned. 'id' will be included automatically in
fields if it's provided, since it will be used when fields if it's provided, since it will be used when
constructing 'next' link. constructing 'next' link.
:param filters: Optional. A list of filters to apply to the result. :param name: Optional. Keep only resources with a specific name.
:param workflow_name: Optional. Keep only resources with a specific
workflow name.
:param workflow_id: Optional. Keep only resources with a specific
workflow ID.
:param workflow_execution_id: Optional. Keep only resources with a
specific workflow execution ID.
:param state: Optional. Keep only resources with a specific state.
:param state_info: Optional. Keep only resources with specific
state information.
:param result: Optional. Keep only resources with a specific result.
:param published: Optional. Keep only resources with specific
published content.
:param processed: Optional. Keep only resources which have been
processed or not.
:param reset: Optional. Keep only resources which have been reset or
not.
:param env: Optional. Keep only resources with a specific environment.
:param created_at: Optional. Keep only resources created at a specific
time and date.
:param updated_at: Optional. Keep only resources with specific latest
update time and date.
""" """
acl.enforce('tasks:list', context.ctx()) acl.enforce('tasks:list', context.ctx())
filters = rest_utils.filters_to_dict(
wf_ex_id=workflow_execution_id,
created_at=created_at,
id=id,
workflow_name=workflow_name,
workflow_id=workflow_id,
state=state,
state_info=state_info,
updated_at=updated_at,
name=name,
result=result,
published=published,
processed=processed,
reset=reset,
env=env
)
LOG.info("Fetch tasks. workflow_execution_id=%s, marker=%s, limit=%s, " LOG.info("Fetch tasks. workflow_execution_id=%s, marker=%s, limit=%s, "
"sort_keys=%s, sort_dirs=%s, filters=%s", "sort_keys=%s, sort_dirs=%s, filters=%s",
workflow_execution_id, marker, limit, sort_keys, sort_dirs, workflow_execution_id, marker, limit, sort_keys, sort_dirs,

View File

@ -130,9 +130,13 @@ class WorkbooksController(rest.RestController, hooks.HookController):
db_api.delete_workbook(name) db_api.delete_workbook(name)
@wsme_pecan.wsexpose(Workbooks, types.uuid, int, types.uniquelist, @wsme_pecan.wsexpose(Workbooks, types.uuid, int, types.uniquelist,
types.list, types.uniquelist, types.jsontype) types.list, types.uniquelist, wtypes.text,
wtypes.text, wtypes.text, SCOPE_TYPES, wtypes.text,
types.uniquelist, wtypes.text)
def get_all(self, marker=None, limit=None, sort_keys='created_at', def get_all(self, marker=None, limit=None, sort_keys='created_at',
sort_dirs='asc', fields='', **filters): sort_dirs='asc', fields='', created_at=None,
definition=None, name=None, scope=None, tag=None, tags=None,
updated_at=None):
"""Return a list of workbooks. """Return a list of workbooks.
:param marker: Optional. Pagination marker for large data sets. :param marker: Optional. Pagination marker for large data sets.
@ -142,18 +146,45 @@ class WorkbooksController(rest.RestController, hooks.HookController):
:param sort_keys: Optional. Columns to sort results by. :param sort_keys: Optional. Columns to sort results by.
Default: created_at. Default: created_at.
:param sort_dirs: Optional. Directions to sort corresponding to :param sort_dirs: Optional. Directions to sort corresponding to
sort_keys, "asc" or "desc" can be choosed. sort_keys, "asc" or "desc" can be chosen.
Default: asc. Default: asc.
:param fields: Optional. A specified list of fields of the resource to :param fields: Optional. A specified list of fields of the resource to
be returned. 'id' will be included automatically in be returned. 'id' will be included automatically in
fields if it's provided, since it will be used when fields if it's provided, since it will be used when
constructing 'next' link. constructing 'next' link.
:param filters: Optional. A list of filters to apply to the result. :param name: Optional. Keep only resources with a specific name.
:param definition: Optional. Keep only resources with a specific
definition.
:param tag: Optional. Keep only resources with a specific tag. If it is
used with 'tags', it will be appended to the list of
matching tags.
:param tags: Optional. Keep only resources containing specific tags.
:param scope: Optional. Keep only resources with a specific scope.
:param created_at: Optional. Keep only resources created at a specific
time and date.
:param updated_at: Optional. Keep only resources with specific latest
update time and date.
Where project_id is the same as the requestor or Where project_id is the same as the requester or
project_id is different but the scope is public. project_id is different but the scope is public.
""" """
acl.enforce('workbooks:list', context.ctx()) acl.enforce('workbooks:list', context.ctx())
if tag is not None:
if tags is None:
tags = [tag]
else:
tags.append(tag)
filters = rest_utils.filters_to_dict(
created_at=created_at,
definition=definition,
name=name,
scope=scope,
tags=tags,
updated_at=updated_at
)
LOG.info("Fetch workbooks. marker=%s, limit=%s, sort_keys=%s, " LOG.info("Fetch workbooks. marker=%s, limit=%s, sort_keys=%s, "
"sort_dirs=%s, fields=%s, filters=%s", marker, limit, "sort_dirs=%s, fields=%s, filters=%s", marker, limit,
sort_keys, sort_dirs, fields, filters) sort_keys, sort_dirs, fields, filters)

View File

@ -236,9 +236,14 @@ class WorkflowsController(rest.RestController, hooks.HookController):
@rest_utils.wrap_wsme_controller_exception @rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(Workflows, types.uuid, int, types.uniquelist, @wsme_pecan.wsexpose(Workflows, types.uuid, int, types.uniquelist,
types.list, types.uniquelist, types.jsontype) types.list, types.uniquelist, wtypes.text,
wtypes.text, wtypes.text, wtypes.text,
types.uniquelist, SCOPE_TYPES, types.uuid,
wtypes.text, wtypes.text)
def get_all(self, marker=None, limit=None, sort_keys='created_at', def get_all(self, marker=None, limit=None, sort_keys='created_at',
sort_dirs='asc', fields='', **filters): sort_dirs='asc', fields='', name=None, input=None,
definition=None, tag=None, tags=None, scope=None,
project_id=None, created_at=None, updated_at=None):
"""Return a list of workflows. """Return a list of workflows.
:param marker: Optional. Pagination marker for large data sets. :param marker: Optional. Pagination marker for large data sets.
@ -248,18 +253,47 @@ class WorkflowsController(rest.RestController, hooks.HookController):
:param sort_keys: Optional. Columns to sort results by. :param sort_keys: Optional. Columns to sort results by.
Default: created_at. Default: created_at.
:param sort_dirs: Optional. Directions to sort corresponding to :param sort_dirs: Optional. Directions to sort corresponding to
sort_keys, "asc" or "desc" can be choosed. sort_keys, "asc" or "desc" can be chosen.
Default: asc. Default: asc.
:param fields: Optional. A specified list of fields of the resource to :param fields: Optional. A specified list of fields of the resource to
be returned. 'id' will be included automatically in be returned. 'id' will be included automatically in
fields if it's provided, since it will be used when fields if it's provided, since it will be used when
constructing 'next' link. constructing 'next' link.
:param filters: Optional. A list of filters to apply to the result. :param name: Optional. Keep only resources with a specific name.
:param input: Optional. Keep only resources with a specific input.
Where project_id is the same as the requester or :param definition: Optional. Keep only resources with a specific
project_id is different but the scope is public. definition.
:param tag: Optional. Keep only resources with a specific tag. If it is
used with 'tags', it will be appended to the list of
matching tags.
:param tags: Optional. Keep only resources containing specific tags.
:param scope: Optional. Keep only resources with a specific scope.
:param project_id: Optional. The same as the requester project_id
or different if the scope is public.
:param created_at: Optional. Keep only resources created at a specific
time and date.
:param updated_at: Optional. Keep only resources with specific latest
update time and date.
""" """
acl.enforce('workflows:list', context.ctx()) acl.enforce('workflows:list', context.ctx())
if tag is not None:
if tags is None:
tags = [tag]
else:
tags.append(tag)
filters = rest_utils.filters_to_dict(
created_at=created_at,
name=name,
scope=scope,
tags=tags,
updated_at=updated_at,
input=input,
definition=definition,
project_id=project_id
)
LOG.info("Fetch workflows. marker=%s, limit=%s, sort_keys=%s, " LOG.info("Fetch workflows. marker=%s, limit=%s, sort_keys=%s, "
"sort_dirs=%s, fields=%s, filters=%s", marker, limit, "sort_dirs=%s, fields=%s, filters=%s", marker, limit,
sort_keys, sort_dirs, fields, filters) sort_keys, sort_dirs, fields, filters)

View File

@ -161,8 +161,19 @@ def _get_collection(model, limit=None, marker=None, sort_keys=None,
) )
if query is None: if query is None:
tags = kwargs.pop('tags', None)
query = _secure_query(model, *columns).filter_by(**kwargs) query = _secure_query(model, *columns).filter_by(**kwargs)
# To match the tag list, a resource must contain at least all of the
# tags present in the filter parameter.
if tags:
tag_attr = getattr(model, 'tags')
if len(tags) == 1:
expr = tag_attr.contains(tags)
else:
expr = sa.and_(*[tag_attr.contains(tag) for tag in tags])
query = query.filter(expr)
try: try:
return _paginate_query( return _paginate_query(
model, model,

View File

@ -108,6 +108,17 @@ def validate_fields(fields, object_fields):
) )
def filters_to_dict(**kwargs):
"""Return only non-null values
:param kwargs: All possible filters
:type kwargs: dict
:return: Actual filters
:rtype: dict
"""
return {k: v for k, v in kwargs.items() if v is not None}
def get_all(list_cls, cls, get_all_function, get_function, def get_all(list_cls, cls, get_all_function, get_function,
resource_function=None, marker=None, limit=None, resource_function=None, marker=None, limit=None,
sort_keys='created_at', sort_dirs='asc', fields='', **filters): sort_keys='created_at', sort_dirs='asc', fields='', **filters):
@ -127,7 +138,7 @@ def get_all(list_cls, cls, get_all_function, get_function,
:param sort_keys: Optional. Columns to sort results by. :param sort_keys: Optional. Columns to sort results by.
Default: created_at. Default: created_at.
:param sort_dirs: Optional. Directions to sort corresponding to :param sort_dirs: Optional. Directions to sort corresponding to
sort_keys, "asc" or "desc" can be choosed. sort_keys, "asc" or "desc" can be chosen.
Default: asc. Default: asc.
:param fields: Optional. A specified list of fields of the resource to :param fields: Optional. A specified list of fields of the resource to
be returned. 'id' will be included automatically in be returned. 'id' will be included automatically in