diff options
author | chenjiankun <chenjiankun1@huawei.com> | 2017-07-19 09:44:05 +0000 |
---|---|---|
committer | chenjiankun <chenjiankun1@huawei.com> | 2017-07-19 09:44:05 +0000 |
commit | dccdca6743b797bc6bda5aa7560120b094eb8e17 (patch) | |
tree | 38a469b5bdcb89cade457148ee5dedc2223e5b6f /api/resources | |
parent | d5a7303e3a1cf3b229ff505f5d0630360440106b (diff) |
Add API(v2) to get certain task info
JIRA: YARDSTICK-737
API: /api/v2/yardstick/tasks/<task_id>
METHOD: GET
Change-Id: Ia360f4bba05e196e07c9eb339061ccfbf5df8137
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api/resources')
-rw-r--r-- | api/resources/v2/tasks.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/api/resources/v2/tasks.py b/api/resources/v2/tasks.py index 550e43c2c..7cc4f5d14 100644 --- a/api/resources/v2/tasks.py +++ b/api/resources/v2/tasks.py @@ -2,11 +2,14 @@ import uuid import logging from datetime import datetime +from oslo_serialization import jsonutils + from api import ApiResource from api.database.v2.handlers import V2TaskHandler from api.database.v2.handlers import V2ProjectHandler from api.database.v2.handlers import V2EnvironmentHandler from yardstick.common.utils import result_handler +from yardstick.common.utils import change_obj_to_dict from yardstick.common import constants as consts LOG = logging.getLogger(__name__) @@ -52,6 +55,24 @@ class V2Tasks(ApiResource): class V2Task(ApiResource): + def get(self, task_id): + try: + uuid.UUID(task_id) + except ValueError: + return result_handler(consts.API_ERROR, 'invalid task id') + + task_handler = V2TaskHandler() + try: + task = task_handler.get_by_uuid(task_id) + except ValueError: + return result_handler(consts.API_ERROR, 'no such task id') + + task_info = change_obj_to_dict(task) + result = task_info['result'] + task_info['result'] = jsonutils.loads(result) if result else None + + return result_handler(consts.API_SUCCESS, {'task': task_info}) + def put(self, task_id): try: |