diff options
author | Rex Lee <limingjiang@huawei.com> | 2017-07-21 01:07:34 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-07-21 01:07:34 +0000 |
commit | 1cff540d812ace29fa45bc789ad3a329435aa3ba (patch) | |
tree | 2c3e7cff2a51a898d266dbc9adc8493193f09795 | |
parent | edec11f71207d6df007460cd19ccab08201d60c6 (diff) | |
parent | dccdca6743b797bc6bda5aa7560120b094eb8e17 (diff) |
Merge "Add API(v2) to get certain task info"
-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: |