def _get_task_border(as_path=False): offsets = generate_expected_offsets(30, 800, 600) subtask = SubtaskState() definition = RenderingTaskDefinition() definition.options = BlenderRendererOptions() definition.options.use_frames = False definition.resolution = [800, 600] for k in range(1, 31): subtask.extra_data = {'start_task': k, 'end_task': k} border = BlenderTaskTypeInfo.get_task_border(subtask, definition, 30, as_path=as_path) assert min(border) == (0, offsets[k]) assert max(border) == (797, offsets[k + 1] - 1) definition.options.use_frames = True definition.options.frames = list(range(2)) offsets = generate_expected_offsets(15, 800, 600) for k in range(1, 31): subtask.extra_data = {'start_task': k, 'end_task': k} border = BlenderTaskTypeInfo.get_task_border(subtask, definition, 30, as_path=as_path) i = (k - 1) % 15 + 1 assert min(border) == (0, offsets[i]) assert max(border) == (798, offsets[i + 1] - 1) subtask.extra_data = {'start_task': 2, 'end_task': 2} definition.options.use_frames = True definition.options.frames = list(range(30)) if as_path: assert BlenderTaskTypeInfo.get_task_border( subtask, definition, 30, as_path=as_path) == \ [(0, 600), (800, 600), (800, 0), (0, 0)] else: assert BlenderTaskTypeInfo.get_task_border(subtask, definition, 30, as_path=as_path) == [] definition.options.use_frames = False definition.resolution = (0, 0) assert BlenderTaskTypeInfo.get_task_border(subtask, definition, 30, as_path=as_path) == []
def __add_subtask_to_tasks_states(self, node_name, node_id, price, ctd, address): if ctd.task_id not in self.tasks_states: raise RuntimeError("Should never be here!") logger.debug('add_subtask_to_tasks_states(%r, %r, %r, %r, %r)', node_name, node_id, price, ctd, address) ss = SubtaskState() ss.computer.node_id = node_id ss.computer.node_name = node_name ss.computer.performance = ctd.performance ss.computer.ip_address = address ss.computer.price = price ss.time_started = time.time() ss.deadline = ctd.deadline # TODO: read node ip address ss.subtask_definition = ctd.short_description ss.subtask_id = ctd.subtask_id ss.extra_data = ctd.extra_data ss.subtask_status = TaskStatus.starting ss.value = 0 self.tasks_states[ctd.task_id].subtask_states[ctd.subtask_id] = ss
def get_subtasks(self, frame): if self.task_definition.options.use_frames: subtask_ids = self.frames_subtasks.get(to_unicode(frame), []) subtask_ids = filter(None, subtask_ids) else: subtask_ids = self.subtasks_given.keys() subtasks = dict() # Convert to SubtaskState in order to match parent's return type for subtask_id in subtask_ids: state = SubtaskState() state.extra_data = self.subtasks_given[subtask_id] subtasks[subtask_id] = state return subtasks
def __add_subtask_to_tasks_states(self, node_name, node_id, ctd, address): logger.debug('add_subtask_to_tasks_states(%r, %r, %r, %r)', node_name, node_id, ctd, address) ss = SubtaskState() ss.time_started = time.time() ss.node_id = node_id ss.node_name = node_name ss.deadline = ctd['deadline'] ss.subtask_definition = ctd['short_description'] ss.subtask_id = ctd['subtask_id'] ss.extra_data = ctd['extra_data'] ss.subtask_status = SubtaskStatus.starting (self.tasks_states[ctd['task_id']].subtask_states[ctd['subtask_id']] ) = ss
def __build_subtasks(n): subtasks = dict() subtask_id = None for i in xrange(0, n): subtask = SubtaskState() subtask.subtask_id = str(uuid.uuid4()) 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.extra_data = {'start_task': i, 'end_task': i} subtask_id = subtask.subtask_id subtasks[subtask.subtask_id] = subtask return subtasks, subtask_id
def test_to_dictionary(): ss = SubtaskState() ss.subtask_definition = "My long task definition" ss.subtask_id = "ABCDEF" ss.subtask_progress = 0.92 ss.time_started = get_timestamp_utc() ss.deadline = timeout_to_deadline(ss.time_started + 5) ss.extra_data = {"param1": 1323, "param2": "myparam"} ss.subtask_rem_time = deadline_to_timeout( ss.deadline) - ss.time_started ss.subtask_status = SubtaskStatus.starting ss.value = 138 ss.stdout = "path/to/file" ss.stderr = "path/to/file2" ss.results = ["path/to/file3", "path/to/file4"] ss.computation_time = 130 ss.node_id = "NODE1" ss_dict = ss.to_dictionary() assert ss_dict['description'] == "My long task definition" assert ss_dict['subtask_id'] == "ABCDEF" assert ss_dict['progress'] == 0.92 assert ss_dict['time_started'] == get_timestamp_utc() assert ss_dict.get('deadline') is None assert ss_dict.get('extra_data') is None assert ss_dict['time_remaining'] == 5 assert ss_dict['status'] == SubtaskStatus.starting.value assert ss_dict.get('value') is None assert ss_dict['stdout'] == "path/to/file" assert ss_dict['stderr'] == "path/to/file2" assert ss_dict['results'] == ["path/to/file3", "path/to/file4"] assert ss_dict.get('computation_time') is None assert ss_dict['node_id'] == "NODE1"