def should_wait_for_node(self, task_id, node_id) -> bool: """ Check if the node has too many tasks assigned already """ if not self.is_my_task(task_id): logger.debug( "Not my task. task_id=%s, node=%s", task_id, short_node_id(node_id), ) return False task = self.tasks[task_id] verdict = task.should_accept_client(node_id) logger.debug( "Should accept client verdict. verdict=%s, task=%s, node=%s", verdict, task_id, short_node_id(node_id), ) if verdict == AcceptClientVerdict.SHOULD_WAIT: logger.warning("Waiting for results from %s on %s", short_node_id(node_id), task_id) return True elif verdict == AcceptClientVerdict.REJECTED: logger.warning( "Client has failed on subtask within this task" " and is banned from it. node_id=%s, task_id=%s", short_node_id(node_id), task_id) return False
def _handshake_error(self, key_id, error): logger.info("Resource handshake error (%r): %r", short_node_id(key_id), error) self._block_peer(key_id) self._finalize_handshake(key_id) self.task_server.task_computer.session_closed() self.dropped()
def _nonce_shared(self, key_id, result, options): handshake = self._get_handshake(key_id) if not handshake: logger.debug( 'Resource handshake: nonce shared after ' 'handshake failure with peer %r', short_node_id(key_id)) return handshake.hash, _ = result logger.debug( "Resource handshake: sending resource hash: " "%r to peer %r", handshake.hash, short_node_id(key_id)) os.remove(handshake.file) self.send( message.resources.ResourceHandshakeStart(resource=handshake.hash, options=options.__dict__))
def _finalize_handshake(self, key_id): handshake = self._get_handshake(key_id) if not handshake: return if handshake.finished(): logger.info('Finished resource handshake with %r', short_node_id(key_id)) if handshake.success() and handshake.message: self.send(message.tasks.WantToComputeTask(**handshake.message))
def should_accept_requestor(self, node_id): allowed, reason = self.acl.is_allowed(node_id) if not allowed: short_id = short_node_id(node_id) logger.info('requestor %s. node=%s', reason, short_id) return SupportStatus.err({UnsupportReason.DENY_LIST: node_id}) trust = self.client.get_requesting_trust(node_id) logger.debug("Requesting trust level: %r", trust) if trust >= self.config_desc.requesting_trust: return SupportStatus.ok() else: return SupportStatus.err({UnsupportReason.REQUESTOR_TRUST: trust})
def _nonce_downloaded(self, key_id, files): handshake = self._get_handshake(key_id) if not handshake: logger.debug( 'Resource handshake: nonce downloaded after ' 'handshake failure with peer %r', short_node_id(key_id)) return try: path = files[0] nonce = handshake.read_nonce(path) except Exception as err: self._handshake_error( key_id, 'reading nonce from file "{}": {}'.format(files, err)) else: os.remove(path) self.send(message.resources.ResourceHandshakeNonce(nonce=nonce))
def _start_handshake(self, key_id): logger.info('Starting resource handshake with %r', short_node_id(key_id)) handshake = ResourceHandshake(self._task_request_message) directory = self.resource_manager.storage.get_dir(self.NONCE_TASK) try: handshake.start(directory) except Exception as err: self._handshake_error( key_id, 'writing nonce to dir "{}": {}'.format(directory, err)) return self._set_handshake(key_id, handshake) self._start_handshake_timer() self._share_handshake_nonce(key_id)
def query_extra_data(self, perf_index: float, num_cores: int = 0, node_id: Optional[str] = None, node_name: Optional[str] = None) \ -> FrameRenderingTask.ExtraData: start_task, end_task = self._get_next_task() scene_file = self._get_scene_file_rel_path() if self.use_frames: frames, parts = self._choose_frames(self.frames, start_task, self.total_tasks) else: frames = self.frames or [1] parts = 1 if not self.use_frames: min_y, max_y = self._get_min_max_y(start_task) elif parts > 1: min_y = (parts - self._count_part(start_task, parts)) * (1.0 / parts) max_y = (parts - self._count_part(start_task, parts) + 1) * (1.0 / parts) else: min_y = 0.0 max_y = 1.0 # Blender is using single precision math, we use numpy to emulate this. # Send already converted values to blender. min_y = numpy.float32(min_y) max_y = numpy.float32(max_y) script_src = generate_blender_crop_file( resolution=(self.res_x, self.res_y), borders_x=(0.0, 1.0), borders_y=(min_y, max_y), use_compositing=self.compositing, samples=self.samples) extra_data = { "path_root": self.main_scene_dir, "start_task": start_task, "end_task": end_task, "total_tasks": self.total_tasks, "outfilebasename": self.outfilebasename, "scene_file": scene_file, "script_src": script_src, "frames": frames, "output_format": self.output_format, } subtask_id = self.create_subtask_id() logger.debug( 'Created new subtask for task. ' 'task_id=%s, subtask_id=%s, node_id=%s', self.header.task_id, subtask_id, short_node_id(node_id or '')) self.subtasks_given[subtask_id] = copy(extra_data) self.subtasks_given[subtask_id]['subtask_id'] = subtask_id self.subtasks_given[subtask_id]['status'] = SubtaskStatus.starting self.subtasks_given[subtask_id]['node_id'] = node_id self.subtasks_given[subtask_id]['parts'] = parts self.subtasks_given[subtask_id]['res_x'] = self.res_x self.subtasks_given[subtask_id]['res_y'] = self.res_y self.subtasks_given[subtask_id]['samples'] = self.samples self.subtasks_given[subtask_id]['use_frames'] = self.use_frames self.subtasks_given[subtask_id]['all_frames'] = self.frames self.subtasks_given[subtask_id]['crop_window'] = (0.0, 1.0, min_y, max_y) self.subtasks_given[subtask_id]['subtask_timeout'] = \ self.header.subtask_timeout self.subtasks_given[subtask_id]['tmp_dir'] = self.tmp_dir # FIXME issue #1955 part = self._count_part(start_task, parts) for frame in frames: frame_key = to_unicode(frame) state = self.frames_state[frame_key] state.status = TaskStatus.computing state.started = state.started or time.time() self.frames_subtasks[frame_key][part - 1] = subtask_id if not self.use_frames: self._update_task_preview() else: self._update_frame_task_preview() ctd = self._new_compute_task_def(subtask_id, extra_data, perf_index=perf_index) self.subtasks_given[subtask_id]['ctd'] = ctd return self.ExtraData(ctd=ctd)