3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
11 Resources to retrieve the task results
19 from flask import jsonify
21 from functest.api.base import ApiResource
22 from functest.api.common import api_utils
23 from functest.api.database.v1.handlers import TasksHandler
26 LOGGER = logging.getLogger(__name__)
29 class V1Tasks(ApiResource):
30 """ V1Tasks Resource class"""
32 def get(self, task_id): # pylint: disable=no-self-use
33 """ GET the result of the task id """
37 return api_utils.result_handler(status=1, data='Invalid task id')
39 task_handler = TasksHandler()
41 task = task_handler.get_task_by_taskid(task_id)
43 return api_utils.result_handler(status=1, data='No such task id')
46 LOGGER.debug('Task status is: %s', status)
48 if status not in ['IN PROGRESS', 'FAIL', 'FINISHED']:
49 return api_utils.result_handler(status=1,
50 data='internal server error')
51 if status == 'IN PROGRESS':
52 result = {'status': status, 'result': ''}
53 elif status == 'FAIL':
54 result = {'status': status, 'error': task.error}
56 result = {'status': status, 'result': json.loads(task.result)}
58 return jsonify(result)