1 # ############################################################################
2 # Copyright (c) 2017 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 # ############################################################################
12 from api.utils.common import result_handler
13 from api.database.v1.handlers import AsyncTaskHandler
14 from yardstick.common import constants as consts
16 LOG = logging.getLogger(__name__)
17 LOG.setLevel(logging.DEBUG)
21 return _get_status(args)
24 def _get_status(args):
26 task_id = args['task_id']
28 return result_handler(consts.API_ERROR, 'task_id must be provided')
33 return result_handler(consts.API_ERROR, 'invalid task_id')
35 asynctask_handler = AsyncTaskHandler()
37 asynctask = asynctask_handler.get_task_by_taskid(task_id)
39 return result_handler(consts.API_ERROR, 'invalid task_id')
42 return result_handler(consts.TASK_NOT_DONE, {})
45 return result_handler(consts.TASK_DONE, {})
48 return result_handler(consts.TASK_FAILED, asynctask.error)
50 status = asynctask.status
51 LOG.debug('Task status is: %s', status)
53 if status not in [consts.TASK_NOT_DONE,
56 return result_handler(consts.API_ERROR, 'internal server error')
59 consts.TASK_NOT_DONE: _unfinished,
60 consts.TASK_DONE: _finished,
61 consts.TASK_FAILED: _error
64 return switcher.get(status)()