def refresh_one(self, server): """Refresh the informations of a server. *To check error recovery in unittests, *server* can take a special value *"unittest"*, that simulates an *OSError* exception.* Arguments: server (str): Server name. Returns: bool: *True* if it succeeded, *False* otherwise. """ _unittest = server == 'unittest' server = 'localhost' if _unittest else server rcdef = self._set_rcdef(server) if not rcdef: raise ValueError(translate("Runner", "Server {0!r} is not available.") .format(server)) try: hostname = 'localhost' if server == 'localhost' else rcdef.hostname if _unittest: raise OSError output = remote_exec(rcdef.username, hostname, "{} shell -- as_run --info" .format(osp.join(rcdef.applipath, 'salome'))) except OSError: return False cfg = self.server_config(server) cfg.update(parse_server_config(output)) debug_message2("Server configuration for {0!r}: {1}" .format(server, cfg)) return True
def check_parameters(self, params): """Check parameters before starting.""" self._params = params required = set(['server', 'version', 'mode', 'memory', 'time']) missing = required.difference(params.keys()) if missing: raise RunnerError(translate('Runner', 'Missing parameters: {}') .format(missing)) debug_message2("Parameters:", params)
def resource_parameters(params): """Create ResourceParameters from the job parameters""" debug_message2("ResourceParameters from:", params) use_batch = params.get('mode') == Job.BatchText res = salome.ResourceParameters() res.name = to_str(params['server']) res.can_launch_batch_jobs = use_batch # setting mem_mb raises: ulimit: error setting limit (Invalid argument) res.mem_mb = int(params['memory']) res.nb_proc = params.get('mpicpu', 1) res.nb_node = params.get('nodes', 1) return res
def cleanup(self): """Cleanup function, called when a RunCase is removed.""" # Warning: it should be "when a RunCase is deleted" # Currently "removed" means "not follow by the dashboard", no? # That's why it is currently limited to unittests. debug_message2("cleanup execution") if self._unittest: for result in self._results: if not result.job.jobid: continue hdlr = self._build_new_hanfler(result) hdlr.kill()
def stop_current(self): """Stop the current calculation process.""" if not self.current or self.current.state & SO.Finished: return False self.current.state = SO.Error job = self.current.job if not job.jobid_int: return True self.hdlr.stopJob(job.jobid_int) self.get_job_results(job) self.save_jobs() debug_message2('Job {0} stopped'.format(job.jobid)) return True
def result_state(self, result): """Gets a result state. Returns: StateOptions: Current state of `result`. """ state = result.state if state & SO.Finished: return state self.refresh() state = result.state debug_message2("State of", result, ":", SO.name(state)) return state
def _build_new_hanfler(self, result): """Create a handler to manage a result.""" from asrun import create_calcul_handler job = result.job server = self._params.get('server') or job.server if server not in self._infos.available_servers: raise RunnerError( translate('Runner', 'Unknown server: {0!r}').format(server)) prof = self._infos.init_profil(server) if job.jobid: prof['jobid'] = job.jobid prof['nomjob'] = job.name prof['mode'] = text_to_asrun(Job.mode_to_text(job.mode)) debug_message2("Create handler with:\n", prof) return create_calcul_handler(prof)
def check_parameters(self, params): """Check parameters before starting.""" self._params = params # forced states in debug_mode calcstates = {} for stage, res in self._params.get('forced_states', {}).viewitems(): pcase = stage.parent_case assert pcase, "no parent case for {}".format(stage) calcstates[pcase.stages.index(stage)] = res for i in self._queue: stage = self._case.result_stage(i) index = stage.parent_case.stages.index(stage) if stage is not None and index in calcstates: self._forced[i] = calcstates[index] debug_message2("forced results:", self._forced) self._fstop = self._params.get('forced_stop', []) debug_message2("forced stops:", self._fstop)
def refresh(self): """Refresh state of currently processed (calculated) result.""" if self.is_finished() or not self.is_started(): return res = self.hdlr.tail(nbline=self._nbline) self.current.state = convert_asrun_state(res.state, res.diag) debug_message2('Job status is', res, ':', self.current.state) if self.current.state & SO.Finished: self.current.job.end_time = current_time() self.hdlr.get_results() self._update_result() # refresh next if any self.refresh() else: self.console("\nLast {0} lines at {1}...".format( self._nbline, current_time())) self.console(res.output) # on partial output self.current.add_messages(extract_messages(res.output))
def refresh(self): """Refresh state of currently processed (calculated) result.""" if self.is_finished() or not self.is_started(): return job = self.current.job res = self.hdlr.getJobState(job.jobid_int) self.current.state = convert_launcher_state(res) debug_message2('Job {0}: status is {1}: {2}' .format(job.jobid, res, SO.name(self.current.state))) if self.current.state & SO.Finished: job.end_time = current_time() self.get_job_results(job) # parse message file if it exists stage = self.current_stage output = glob(osp.join(stage.folder, "logs", "command_*.log")) if output: self.current.state = convert_state_from_message(res, output[0]) with open(output[0], 'rb') as fileout: text = to_unicode(fileout.read()) self.current.add_messages(extract_messages(text)) self.save_jobs() self._update_result() # refresh next if any self.refresh() else: self.console("\nLast {0} lines at {1}..." .format(self._nbline, current_time())) salome_job = self.hdlr.getJobParameters(job.jobid_int) text = remote_tail(self._infos.server_username(job.server), self._infos.server_hostname(job.server), osp.join(salome_job.work_directory, "logs", "command_*.log"), self._nbline) self.current.add_messages(extract_messages(text)) self.console(text)
def cleanup(self): """Cleanup function, called when a RunCase is removed.""" # Warning: it should be "when a RunCase is deleted" # Currently "removed" means "not follow by the dashboard", no? # That's why it is currently limited to unittests. debug_message2("cleanup execution")