From 80ca856083c10545ec208533200aa24ca659bdf6 Mon Sep 17 00:00:00 2001 From: Marek Franciszkiewicz Date: Tue, 23 May 2017 18:28:30 +0200 Subject: [PATCH 1/3] Simple task and subtask representations with unicode keys and values --- golem/task/taskmanager.py | 61 +++++++++++++++------------- tests/golem/task/test_taskmanager.py | 3 ++ 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/golem/task/taskmanager.py b/golem/task/taskmanager.py index 5b2a0afce9..5bd1111969 100644 --- a/golem/task/taskmanager.py +++ b/golem/task/taskmanager.py @@ -7,7 +7,7 @@ from twisted.internet.defer import inlineCallbacks from golem.core.common import HandleKeyError, get_timestamp_utc, \ - timeout_to_deadline + timeout_to_deadline, to_unicode from golem.core.hostaddress import get_external_address from golem.manager.nodestatesnapshot import LocalTaskStateSnapshot from golem.network.transport.tcpnetwork import SocketAddress @@ -512,7 +512,8 @@ def get_subtasks(self, task_id): """ if task_id not in self.tasks_states: return None - return [sub.subtask_id for sub in self.tasks_states[task_id].subtask_states.values()] + return [sub.subtask_id for sub in + self.tasks_states[task_id].subtask_states.values()] def change_config(self, root_path, use_distributed_resource_management): self.dir_manager = DirManager(root_path) @@ -533,11 +534,13 @@ def get_dict_task(self, task_id): return self._simple_task_repr(self.tasks_states, self.tasks[task_id]) def get_dict_tasks(self): - return [self._simple_task_repr(self.tasks_states, t) for task_id, t in self.tasks.iteritems()] + return [self._simple_task_repr(self.tasks_states, t) + for task_id, t in self.tasks.iteritems()] def get_dict_subtasks(self, task_id): task_state = self.tasks_states[task_id] - return [self._simple_subtask_repr(subtask) for subtask_id, subtask in task_state.subtask_states.iteritems()] + return [self._simple_subtask_repr(subtask) for subtask_id, subtask + in task_state.subtask_states.iteritems()] def get_dict_subtask(self, subtask_id): task_id = self.subtask2task_mapping[subtask_id] @@ -546,35 +549,35 @@ def get_dict_subtask(self, subtask_id): return self._simple_subtask_repr(subtask) @staticmethod - def _simple_task_repr(_states, _task): - if _task: - state = _states.get(_task.header.task_id,) - return dict( - id=_task.header.task_id, - time_remaining=state.remaining_time, - subtasks=_task.get_total_tasks(), - status=state.status, - progress=_task.get_progress() - ) + def _simple_task_repr(states, task): + if task: + state = states.get(task.header.task_id) + return { + u'id': to_unicode(task.header.task_id), + u'time_remaining': state.remaining_time, + u'subtasks': task.get_total_tasks(), + u'status': to_unicode(state.status), + u'progress': task.get_progress() + } @staticmethod def _simple_subtask_repr(subtask): if subtask: - return dict( - subtask_id=subtask.subtask_id, - node_name=subtask.computer.node_name, - node_id=subtask.computer.node_id, - node_performance=subtask.computer.performance, - node_ip_address=subtask.computer.ip_address, - node_port=subtask.computer.port, - status=subtask.subtask_status, - progress=subtask.subtask_progress, - time_started=subtask.time_started, - time_remaining=subtask.subtask_rem_time, - results=subtask.results, - stderr=subtask.stderr, - stdout=subtask.stdout - ) + return { + u'subtask_id': to_unicode(subtask.subtask_id), + u'node_name': to_unicode(subtask.computer.node_name), + u'node_id': to_unicode(subtask.computer.node_id), + u'node_performance': subtask.computer.performance, + u'node_ip_address': to_unicode(subtask.computer.ip_address), + u'node_port': subtask.computer.port, + u'status': to_unicode(subtask.subtask_status), + u'progress': subtask.subtask_progress, + u'time_started': subtask.time_started, + u'time_remaining': subtask.subtask_rem_time, + u'results': [to_unicode(r) for r in subtask.results], + u'stderr': to_unicode(subtask.stderr), + u'stdout': to_unicode(subtask.stdout) + } @handle_subtask_key_error def set_computation_time(self, subtask_id, computation_time): diff --git a/tests/golem/task/test_taskmanager.py b/tests/golem/task/test_taskmanager.py index 992d2b287b..9adc13786f 100644 --- a/tests/golem/task/test_taskmanager.py +++ b/tests/golem/task/test_taskmanager.py @@ -636,6 +636,9 @@ def __build_subtasks(n): subtask.computer = ComputerState() subtask.computer.node_name = 'node_{}'.format(i) subtask.computer.node_id = 'deadbeef0{}'.format(i) + subtask.results = [] + subtask.stderr = 'error_{}'.format(i) + subtask.stdout = 'output_{}'.format(i) subtask_id = subtask.subtask_id subtasks[subtask.subtask_id] = subtask From 309cd556f4549763d456eb7518aa20cf7e74329e Mon Sep 17 00:00:00 2001 From: Marek Franciszkiewicz Date: Tue, 23 May 2017 19:18:55 +0200 Subject: [PATCH 2/3] Extend simple task representation with name, type and duration --- golem/task/taskmanager.py | 4 ++++ tests/golem/task/test_taskmanager.py | 1 + 2 files changed, 5 insertions(+) diff --git a/golem/task/taskmanager.py b/golem/task/taskmanager.py index 5bd1111969..b15894a6a0 100644 --- a/golem/task/taskmanager.py +++ b/golem/task/taskmanager.py @@ -554,6 +554,10 @@ def _simple_task_repr(states, task): state = states.get(task.header.task_id) return { u'id': to_unicode(task.header.task_id), + u'name': to_unicode(task.task_definition.name), + u'type': to_unicode(task.task_definition.type), + u'duration': max(task.task_definition.full_task_timeout - + state.remaining_time, 0), u'time_remaining': state.remaining_time, u'subtasks': task.get_total_tasks(), u'status': to_unicode(state.status), diff --git a/tests/golem/task/test_taskmanager.py b/tests/golem/task/test_taskmanager.py index 9adc13786f..f4065adb61 100644 --- a/tests/golem/task/test_taskmanager.py +++ b/tests/golem/task/test_taskmanager.py @@ -603,6 +603,7 @@ def __build_tasks(cls, n): for i in xrange(0, n): task = Mock() + task.task_definition.full_task_timeout = 100 task.header.task_id = str(uuid.uuid4()) task.get_total_tasks.return_value = i + 2 task.get_progress.return_value = i * 10 From 530c12bd6dc5a697785cca619723bd47c770218f Mon Sep 17 00:00:00 2001 From: Marek Franciszkiewicz Date: Tue, 23 May 2017 19:41:15 +0200 Subject: [PATCH 3/3] Fixed property names --- golem/task/taskmanager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/golem/task/taskmanager.py b/golem/task/taskmanager.py index b15894a6a0..3085c1faa7 100644 --- a/golem/task/taskmanager.py +++ b/golem/task/taskmanager.py @@ -554,8 +554,8 @@ def _simple_task_repr(states, task): state = states.get(task.header.task_id) return { u'id': to_unicode(task.header.task_id), - u'name': to_unicode(task.task_definition.name), - u'type': to_unicode(task.task_definition.type), + u'name': to_unicode(task.task_definition.task_name), + u'type': to_unicode(task.task_definition.task_type), u'duration': max(task.task_definition.full_task_timeout - state.remaining_time, 0), u'time_remaining': state.remaining_time,