Modify API to make use of /executions endpoint

Change-Id: If034adebe4bcf39fef0e26b48023a6f8d215896f
This commit is contained in:
Kirill Izotov 2014-06-23 15:20:49 +07:00
parent c1e9442fd9
commit 1973461321
4 changed files with 57 additions and 37 deletions

View File

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

View File

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

View File

@ -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']
}

View File

@ -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']
}