From 1973461321ec1acdb2dc7cff7a4b26b64b433a40 Mon Sep 17 00:00:00 2001 From: Kirill Izotov Date: Mon, 23 Jun 2014 15:20:49 +0700 Subject: [PATCH] Modify API to make use of /executions endpoint Change-Id: If034adebe4bcf39fef0e26b48023a6f8d215896f --- mistralclient/api/executions.py | 39 +++++++++++++------- mistralclient/api/tasks.py | 50 ++++++++++++++++---------- mistralclient/tests/test_executions.py | 2 -- mistralclient/tests/test_tasks.py | 3 -- 4 files changed, 57 insertions(+), 37 deletions(-) diff --git a/mistralclient/api/executions.py b/mistralclient/api/executions.py index 81634d35..dd1762a4 100644 --- a/mistralclient/api/executions.py +++ b/mistralclient/api/executions.py @@ -54,30 +54,43 @@ class ExecutionManager(base.ResourceManager): return self._create('/workbooks/%s/executions' % workbook_name, data) def update(self, workbook_name, id, state): - self._ensure_not_empty(workbook_name=workbook_name, id=id, - state=state) + self._ensure_not_empty(id=id, state=state) data = { - 'workbook_name': workbook_name, - 'id': id, 'state': state } - return self._update('/workbooks/%s/executions/%s' % - (workbook_name, id), data) + if workbook_name: + uri = '/workbooks/%s/executions/%s' % (workbook_name, id) + else: + uri = '/executions/%s' % id + + return self._update(uri, data) def list(self, workbook_name): - self._ensure_not_empty(workbook_name=workbook_name) + if workbook_name: + uri = '/workbooks/%s/executions' % workbook_name + else: + uri = '/executions' - return self._list('/workbooks/%s/executions' % workbook_name, - 'executions') + return self._list(uri, 'executions') def get(self, workbook_name, id): - self._ensure_not_empty(workbook_name=workbook_name, id=id) + self._ensure_not_empty(id=id) - return self._get('/workbooks/%s/executions/%s' % (workbook_name, id)) + if workbook_name: + uri = '/workbooks/%s/executions/%s' % (workbook_name, id) + else: + uri = '/executions/%s' % id + + return self._get(uri) def delete(self, workbook_name, id): - self._ensure_not_empty(workbook_name=workbook_name, id=id) + self._ensure_not_empty(id=id) - self._delete('/workbooks/%s/executions/%s' % (workbook_name, id)) + if workbook_name: + uri = '/workbooks/%s/executions/%s' % (workbook_name, id) + else: + uri = '/executions/%s' % id + + self._delete(uri) diff --git a/mistralclient/api/tasks.py b/mistralclient/api/tasks.py index af7ec49b..48850800 100644 --- a/mistralclient/api/tasks.py +++ b/mistralclient/api/tasks.py @@ -25,33 +25,45 @@ class TaskManager(base.ResourceManager): resource_class = Task def update(self, workbook_name, execution_id, id, state): - self._ensure_not_empty(workbook_name=workbook_name, - execution_id=execution_id, - id=id, - state=state) + self._ensure_not_empty(id=id, state=state) data = { - 'workbook_name': workbook_name, - 'execution_id': execution_id, - 'id': id, 'state': state } - return self._update('/workbooks/%s/executions/%s/tasks/%s' % - (workbook_name, execution_id, id), data) + if execution_id: + if workbook_name: + uri = '/workbooks/%s/executions/%s/tasks/%s' % \ + (workbook_name, execution_id, id) + else: + uri = '/executions/%s/tasks/%s' % (execution_id, id) + else: + uri = '/tasks/%s' % id + + return self._update(uri, data) def list(self, workbook_name, execution_id): - self._ensure_not_empty(workbook_name=workbook_name, - execution_id=execution_id) + if execution_id: + if workbook_name: + uri = '/workbooks/%s/executions/%s/tasks' % \ + (workbook_name, execution_id) + else: + uri = '/executions/%s/tasks' % execution_id + else: + uri = '/tasks' - return self._list('/workbooks/%s/executions/%s/tasks' % - (workbook_name, execution_id), - 'tasks') + return self._list(uri, 'tasks') def get(self, workbook_name, execution_id, id): - self._ensure_not_empty(workbook_name=workbook_name, - execution_id=execution_id, - id=id) + self._ensure_not_empty(id=id) - return self._get('/workbooks/%s/executions/%s/tasks/%s' % - (workbook_name, execution_id, id)) + if execution_id: + if workbook_name: + uri = '/workbooks/%s/executions/%s/tasks/%s' % \ + (workbook_name, execution_id, id) + else: + uri = '/executions/%s/tasks/%s' % (execution_id, id) + else: + uri = '/tasks/%s' % id + + return self._get(uri) diff --git a/mistralclient/tests/test_executions.py b/mistralclient/tests/test_executions.py index 18052a81..df958b11 100644 --- a/mistralclient/tests/test_executions.py +++ b/mistralclient/tests/test_executions.py @@ -94,8 +94,6 @@ class TestExecutions(base.BaseClientTest): def test_update(self): mock = self.mock_http_put(content=EXECS[0]) body = { - 'workbook_name': EXECS[0]['workbook_name'], - 'id': EXECS[0]['id'], 'state': EXECS[0]['state'] } diff --git a/mistralclient/tests/test_tasks.py b/mistralclient/tests/test_tasks.py index 7b4367e0..a4f191ac 100644 --- a/mistralclient/tests/test_tasks.py +++ b/mistralclient/tests/test_tasks.py @@ -42,9 +42,6 @@ class TestTasks(base.BaseClientTest): def test_update(self): mock = self.mock_http_put(content=TASKS[0]) body = { - 'workbook_name': TASKS[0]['workbook_name'], - 'execution_id': TASKS[0]['execution_id'], - 'id': TASKS[0]['id'], 'state': TASKS[0]['state'] }