diff options
author | chenjiankun <chenjiankun1@huawei.com> | 2017-08-09 03:23:58 +0000 |
---|---|---|
committer | chenjiankun <chenjiankun1@huawei.com> | 2017-08-11 09:29:58 +0000 |
commit | 43bf12d6ab7bcaea16dc75ed4ccbe3895cf51da3 (patch) | |
tree | 234d642e36564dab4e9d48cff09c0b93901c252f /api/resources | |
parent | 55234666785b0fdc81365da4dac5563e954f8a09 (diff) |
Add real time log view in GUI
JIRA: YARDSTICK-775
We have GUI now, but we can't see real time log in GUI view.
So I add real time log view in GUI.
Change-Id: Ie83f327ef0a94302afa6b3def764fec6ef5818d1
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api/resources')
-rw-r--r-- | api/resources/v2/tasks.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/api/resources/v2/tasks.py b/api/resources/v2/tasks.py index 885a190c6..25a9cf109 100644 --- a/api/resources/v2/tasks.py +++ b/api/resources/v2/tasks.py @@ -8,6 +8,8 @@ ############################################################################## import uuid import logging +import os +import errno from datetime import datetime from oslo_serialization import jsonutils @@ -252,3 +254,37 @@ class V2Task(ApiResource): task_thread.start() return result_handler(consts.API_SUCCESS, {'uuid': task_id}) + + +class V2TaskLog(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') + + index = int(self._get_args().get('index', 0)) + + try: + with open(os.path.join(consts.TASK_LOG_DIR, '{}.log'.format(task_id))) as f: + f.seek(index) + data = f.readlines() + index = f.tell() + except OSError as e: + if e.errno == errno.ENOENT: + return result_handler(consts.API_ERROR, 'log file does not exist') + return result_handler(consts.API_ERROR, 'error with log file') + + return_data = { + 'index': index, + 'data': data + } + + return result_handler(task.status, return_data) |