aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources
diff options
context:
space:
mode:
Diffstat (limited to 'api/resources')
-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: