summaryrefslogtreecommitdiffstats
path: root/api/resources/v2
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2017-07-21 01:07:34 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-21 01:07:34 +0000
commit1cff540d812ace29fa45bc789ad3a329435aa3ba (patch)
tree2c3e7cff2a51a898d266dbc9adc8493193f09795 /api/resources/v2
parentedec11f71207d6df007460cd19ccab08201d60c6 (diff)
parentdccdca6743b797bc6bda5aa7560120b094eb8e17 (diff)
Merge "Add API(v2) to get certain task info"
Diffstat (limited to 'api/resources/v2')
-rw-r--r--api/resources/v2/tasks.py21
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: