diff --git a/mistral/api/controllers/v2/action.py b/mistral/api/controllers/v2/action.py index 646e6d6d..8f4c977b 100644 --- a/mistral/api/controllers/v2/action.py +++ b/mistral/api/controllers/v2/action.py @@ -184,9 +184,14 @@ class ActionsController(rest.RestController, hooks.HookController): db_api.delete_action_definition(name) @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', - 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. :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. Default: name. :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. :param fields: Optional. A specified list of fields of the resource to be returned. 'id' will be included automatically in fields if it's provided, since it will be used when 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 project_id is different but the scope is public. """ 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, " "sort_dirs=%s, filters=%s", marker, limit, sort_keys, sort_dirs, filters) diff --git a/mistral/api/controllers/v2/action_execution.py b/mistral/api/controllers/v2/action_execution.py index efe3d883..f4d32537 100644 --- a/mistral/api/controllers/v2/action_execution.py +++ b/mistral/api/controllers/v2/action_execution.py @@ -125,7 +125,7 @@ def _get_action_executions(task_execution_id=None, marker=None, limit=None, fields='', **filters): """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. :param marker: Optional. Pagination marker for large data sets. @@ -230,12 +230,20 @@ class ActionExecutionsController(rest.RestController): return ActionExecution.from_dict(values) @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', - 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. - 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. :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 fields if it's provided, since it will be used when 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()) + + 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, " "sort_keys=%s, sort_dirs=%s, filters=%s", marker, limit, sort_keys, sort_dirs, filters) @@ -297,14 +352,23 @@ class ActionExecutionsController(rest.RestController): class TasksActionExecutionController(rest.RestController): @wsme_pecan.wsexpose(ActionExecutions, types.uuid, types.uuid, int, 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, - 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. - 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. + :param task_execution_id: Keep only resources within a specific task + execution. :param marker: Optional. Pagination marker for large data sets. :param limit: Optional. Maximum number of resources to return in a single result. Default value is None for backward @@ -319,15 +383,59 @@ class TasksActionExecutionController(rest.RestController): be returned. 'id' will be included automatically in fields if it's provided, since it will be used when 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()) + 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, " "sort_keys=%s, sort_dirs=%s, filters=%s", marker, limit, sort_keys, sort_dirs, filters) return _get_action_executions( - task_execution_id=task_execution_id, marker=marker, limit=limit, sort_keys=sort_keys, diff --git a/mistral/api/controllers/v2/cron_trigger.py b/mistral/api/controllers/v2/cron_trigger.py index a5aa3f17..df3b4ee4 100644 --- a/mistral/api/controllers/v2/cron_trigger.py +++ b/mistral/api/controllers/v2/cron_trigger.py @@ -125,9 +125,17 @@ class CronTriggersController(rest.RestController): db_api.delete_cron_trigger(name) @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', - 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. :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 fields if it's provided, since it will be used when 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()) + + 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, " "sort_dirs=%s, filters=%s", marker, limit, sort_keys, sort_dirs, filters) diff --git a/mistral/api/controllers/v2/environment.py b/mistral/api/controllers/v2/environment.py index 900d784f..84d7eef7 100644 --- a/mistral/api/controllers/v2/environment.py +++ b/mistral/api/controllers/v2/environment.py @@ -30,6 +30,7 @@ from mistral.utils import rest_utils LOG = logging.getLogger(__name__) +SCOPE_TYPES = wtypes.Enum(str, 'private', 'public') SAMPLE = { 'server': 'localhost', @@ -46,7 +47,7 @@ class Environment(resource.Resource): name = wtypes.text description = wtypes.text variables = types.jsontype - scope = wtypes.Enum(str, 'private', 'public') + scope = SCOPE_TYPES created_at = wtypes.text updated_at = wtypes.text @@ -78,12 +79,15 @@ class Environments(resource.ResourceList): class EnvironmentController(rest.RestController): @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', - 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. - 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. :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 fields if it's provided, since it will be used when 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()) + + 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, " "sort_dirs=%s, filters=%s", marker, limit, sort_keys, sort_dirs, filters) diff --git a/mistral/api/controllers/v2/execution.py b/mistral/api/controllers/v2/execution.py index b5b04a47..84000df5 100644 --- a/mistral/api/controllers/v2/execution.py +++ b/mistral/api/controllers/v2/execution.py @@ -33,6 +33,8 @@ from mistral.workflow import states 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. @@ -254,9 +256,15 @@ class ExecutionsController(rest.RestController): return db_api.delete_workflow_execution(id) @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', - 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. :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 fields if it's provided, since it will be used when 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()) + + 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( "Fetch executions. marker=%s, limit=%s, sort_keys=%s, " "sort_dirs=%s, filters=%s", marker, limit, sort_keys, sort_dirs, diff --git a/mistral/api/controllers/v2/task.py b/mistral/api/controllers/v2/task.py index 382ebc46..9e648b9c 100644 --- a/mistral/api/controllers/v2/task.py +++ b/mistral/api/controllers/v2/task.py @@ -36,6 +36,8 @@ from mistral.workflow import states LOG = logging.getLogger(__name__) +STATE_TYPES = wtypes.Enum(str, states.IDLE, states.RUNNING, states.SUCCESS, + states.ERROR, states.RUNNING_DELAYED) class Task(resource.Resource): @@ -112,7 +114,7 @@ def _get_task_resources_with_results(wf_ex_id=None, marker=None, limit=None, fields='', **filters): """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. :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) @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', - 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. - 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. :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 fields if it's provided, since it will be used when 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()) + + 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, " "sort_dirs=%s, filters=%s", marker, limit, sort_keys, sort_dirs, filters) @@ -257,14 +302,19 @@ class TasksController(rest.RestController): class ExecutionTasksController(rest.RestController): - @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, - 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. - 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. :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 fields if it's provided, since it will be used when 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()) + + 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, " "sort_keys=%s, sort_dirs=%s, filters=%s", workflow_execution_id, marker, limit, sort_keys, sort_dirs, diff --git a/mistral/api/controllers/v2/workbook.py b/mistral/api/controllers/v2/workbook.py index d7d1dd4e..53dfc3e0 100644 --- a/mistral/api/controllers/v2/workbook.py +++ b/mistral/api/controllers/v2/workbook.py @@ -130,9 +130,13 @@ class WorkbooksController(rest.RestController, hooks.HookController): db_api.delete_workbook(name) @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', - 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. :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. Default: created_at. :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. :param fields: Optional. A specified list of fields of the resource to be returned. 'id' will be included automatically in fields if it's provided, since it will be used when 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. """ 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, " "sort_dirs=%s, fields=%s, filters=%s", marker, limit, sort_keys, sort_dirs, fields, filters) diff --git a/mistral/api/controllers/v2/workflow.py b/mistral/api/controllers/v2/workflow.py index 8ac99f95..9b8281cb 100644 --- a/mistral/api/controllers/v2/workflow.py +++ b/mistral/api/controllers/v2/workflow.py @@ -236,9 +236,14 @@ class WorkflowsController(rest.RestController, hooks.HookController): @rest_utils.wrap_wsme_controller_exception @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', - 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. :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. Default: created_at. :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. :param fields: Optional. A specified list of fields of the resource to be returned. 'id' will be included automatically in fields if it's provided, since it will be used when constructing 'next' link. - :param filters: Optional. A list of filters to apply to the result. - - Where project_id is the same as the requester or - project_id is different but the scope is public. + :param name: Optional. Keep only resources with a specific name. + :param input: Optional. Keep only resources with a specific input. + :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 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()) + + 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, " "sort_dirs=%s, fields=%s, filters=%s", marker, limit, sort_keys, sort_dirs, fields, filters) diff --git a/mistral/db/v2/sqlalchemy/api.py b/mistral/db/v2/sqlalchemy/api.py index 5cd549e5..864e5d09 100644 --- a/mistral/db/v2/sqlalchemy/api.py +++ b/mistral/db/v2/sqlalchemy/api.py @@ -161,8 +161,19 @@ def _get_collection(model, limit=None, marker=None, sort_keys=None, ) if query is None: + tags = kwargs.pop('tags', None) 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: return _paginate_query( model, diff --git a/mistral/utils/rest_utils.py b/mistral/utils/rest_utils.py index cad074e0..6c2da812 100644 --- a/mistral/utils/rest_utils.py +++ b/mistral/utils/rest_utils.py @@ -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, resource_function=None, marker=None, limit=None, 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. Default: created_at. :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. :param fields: Optional. A specified list of fields of the resource to be returned. 'id' will be included automatically in