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 import ApiResource
13 from api.database.v1.handlers import AsyncTaskHandler
14 from yardstick.common import constants as consts
15 from yardstick.common.utils import result_handler
17 LOG = logging.getLogger(__name__)
18 LOG.setLevel(logging.DEBUG)
21 class V1AsyncTask(ApiResource):
24 args = self._get_args()
27 task_id = args['task_id']
29 return result_handler(consts.API_ERROR, 'task_id must be provided')
34 return result_handler(consts.API_ERROR, 'invalid task_id')
36 asynctask_handler = AsyncTaskHandler()
38 asynctask = asynctask_handler.get_task_by_taskid(task_id)
40 return result_handler(consts.API_ERROR, 'invalid task_id')
43 return result_handler(consts.TASK_NOT_DONE, {})
46 return result_handler(consts.TASK_DONE, {})
49 return result_handler(consts.TASK_FAILED, asynctask.error)
51 status = asynctask.status
52 LOG.debug('Task status is: %s', status)
54 if status not in [consts.TASK_NOT_DONE,
57 return result_handler(consts.API_ERROR, 'internal server error')
60 consts.TASK_NOT_DONE: _unfinished,
61 consts.TASK_DONE: _finished,
62 consts.TASK_FAILED: _error
65 return switcher.get(status)()