From dccdca6743b797bc6bda5aa7560120b094eb8e17 Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Wed, 19 Jul 2017 09:44:05 +0000 Subject: Add API(v2) to get certain task info JIRA: YARDSTICK-737 API: /api/v2/yardstick/tasks/ METHOD: GET Change-Id: Ia360f4bba05e196e07c9eb339061ccfbf5df8137 Signed-off-by: chenjiankun --- api/resources/v2/tasks.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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: -- cgit 1.2.3-korg