1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from __future__ import absolute_import
15 from flasgger.utils import swag_from
17 from api import ApiResource
18 from api.database.v1.handlers import TasksHandler
19 from yardstick.common import constants as consts
20 from yardstick.common.utils import result_handler
21 from api.swagger import models
23 LOG = logging.getLogger(__name__)
24 LOG.setLevel(logging.DEBUG)
27 ResultModel = models.ResultModel
30 class V1Result(ApiResource):
32 @swag_from(os.path.join(consts.REPOS_DIR, 'api/swagger/docs/results.yaml'))
34 args = self._get_args()
37 task_id = args['task_id']
39 return result_handler(consts.API_ERROR, 'task_id must be provided')
44 return result_handler(consts.API_ERROR, 'invalid task_id')
46 task_handler = TasksHandler()
48 task = task_handler.get_task_by_taskid(task_id)
50 return result_handler(consts.API_ERROR, 'invalid task_id')
53 return result_handler(consts.TASK_NOT_DONE, {})
57 return result_handler(consts.TASK_DONE, json.loads(task.result))
59 return result_handler(consts.TASK_DONE, {})
62 return result_handler(consts.TASK_FAILED, task.error)
65 LOG.debug('Task status is: %s', status)
67 if status not in [consts.TASK_NOT_DONE,
70 return result_handler(consts.API_ERROR, 'internal server error')
73 consts.TASK_NOT_DONE: _unfinished,
74 consts.TASK_DONE: _finished,
75 consts.TASK_FAILED: _error
78 return switcher.get(status)()