def update( self ): if self.selected: self.messagesNew = {} result = DB.execute( "SELECT `contact_group_id` FROM `contact` WHERE `name`=? LIMIT 1", self.name ) group_id = result and result[0]['contact_group_id'] or None if group_id: self.group = DB.execute( "SELECT `name` FROM `contact_group` WHERE `id`=?", group_id )[0]['name'] else: self.group = None if self.group: self.buttons.addButton.hide() self.buttons.removeButton.show() self.nameLabel.setStyleSheet( 'QLabel { color:#333; }' ) else: self.buttons.addButton.show() self.buttons.removeButton.hide() self.nameLabel.setStyleSheet( 'QLabel { color:#999; }' ) self.nameLabel.setText( '%s [%s]' % ( self.name, self.status ) ) self.statusLabel.setText( self.statusMessage ) if self.status == 'online': self.statusLabel.setStyleSheet( 'QLabel { color:green; }' ) elif self.status == 'offline': self.statusLabel.setStyleSheet( 'QLabel { color:gray; }' ) elif self.status == 'away': self.statusLabel.setStyleSheet( 'QLabel { color:orange; }' ) else: self.statusLabel.setStyleSheet( 'QLabel { color:red; }' ) self.messagesLabel.setText( ( len( self.messagesNew ) and '('+str( len( self.messagesNew ) )+')' or '' ) )
def addContactCallback( self, contact, group ): QHelper.log( '::CONNECT:QContact:addContact', contact ) if self.name == contact: self.group = group group_id = DB.execute( "SELECT `id` FROM `contact_group` WHERE `name`=?", self.group )[0]['id'] if not DB.execute( "INSERT OR IGNORE INTO `contact` ( `name`, `contact_group_id` ) VALUES ( ?, ? )", self.name, group_id ): DB.execute( "UPDATE `contact` SET `contact_group_id`=? WHERE `name`=? )", group_id, self.name ) self.update()
def _asyc_mesh(self, mesh_id): self._easily_parse() mo = MeshOpt(cad_file=self.cad_file_path, mesh_dir=self.work_path, mesh_config=self.mesh_config, mesh_app=self.mesh_app) mo.ready_mesh_dir() command_dict = mo.get_commands_dict() slurm = Slurm() slurm_id = slurm.send_job(self.work_path, launch_script=self.lanuch_script, username=self.username, total_core=self.num_proc, temp_file="cfmesh_batch_script.sh", job_name=self.mesh_name, **command_dict) log_file = str(Path(self.work_path).joinpath(f"{slurm_id}.out")) err_file = str(Path(self.work_path).joinpath(f"{slurm_id}.err")) DB.write_mesh_status(mesh_id, core_num=self.core_num, slurm_id=slurm_id, log_file=log_file, error_file=err_file) # 开启文件夹监控程序 core_logger.info(f"开始监控 | mesh_id: {mesh_id}") DIR_MONITOR.create_watcher_process( self.work_path, CFMeshResultHandler( mesh_id, (r'.*{slurm_id}\.out'.format(slurm_id=slurm_id), ))) # 阻塞住这个进程, 直到进行转换 while True: state = SlurmDB().query_job_status(slurm_id) if state == 3: break if state in (4, 5): # TODO 生成网格被中断保存 return None time.sleep(10) # TODO 添加异常处理 ori_file = str(Path(self.work_path).joinpath("case.foam")) try: cc = ConvertControler(ori_file=ori_file, des_file=self.des_path, vf_file=self.vf_path, thumb_path=self.thumb_path, convert_type=1) except Exception: core_logger.exception("创建ConvertControler失败") raise ValueError("创建ConvertControler失败") core_logger.info("SU2MeshControler开始进行转换") cv_id = cc.start_actions()[0] print(cv_id) DB.write_mesh_convert(mesh_id, cv_id) return mesh_id
def on_modified(self, event): res_file = event.src_path if self.offset == 0: self.su2p = SU2Parser(res_file) self.res_dict_tmp, self.keys, self.offset = self.su2p.parse_first_line( ) results, self.offset = self.su2p.res_parse(self.res_dict_tmp, self.keys, self.offset) curent_step = int( results[-1]["Iteration"]) if len(results) is not 0 else 0 if len(results) is not 0: DB.update_solve_current_step(self.solve_job_id, curent_step) # 更新数据库中仿真当前步数 for l_res in results: iter_step = l_res["Iteration"] DB.write_solve_chart(self.solve_job_id, iter_step, l_res)
def start_actions(self): core_logger.info(f"convert信息写入数据库! | {CONVERT_CLASSES[self.convert_type]}" f" |{self.ori_file} | {self.des_file} | {self.vf_file }") convert_id = DB.write_convert(self.ori_file, self.des_file, self.vf_file, self.convert_type, thumb_nail=self.thumb_path) if convert_id == -1: return -1, "数据库写入失败" core_logger.info(f"创建进程进行转换 | convert_id: {convert_id}") try: convert_pro = Process(target=self._asyc_convert, args=(convert_id,)) convert_pro.start() core_logger.info(f"异步转换进程开始 | pid: {convert_pro.pid} | convert_id: {convert_id}") return convert_id, "success!" except ProcessError: DB.update_convert(convert_id, 1, {}) core_logger.exception("开启转换进程失败") return 1, "开启转换进程失败"
def stop_actions(cls, mesh_id): ms = DB.query_mesh_status(mesh_id) if ms is None: pass slurm_id = ms["slurmId"] status = SlurmDB().query_job_status(slurm_id) if status is 0 or status is 1: mesh_dir = DB().query_mesh_dir(mesh_id) if mesh_dir is not None: DIR_MONITOR.kill_watcher(mesh_dir) Slurm.kill_job(slurm_id) core_logger.info( f"杀死网格作业 | slurm_id: {slurm_id} | mesh_id: {mesh_id}") return 0, "success" else: return 2, "查询网格错误" else: return 1, "mesh job has finished!"
def post(self): arg = dict(solve_chart.parse_args()) job_id = arg.get("jobId", None) if job_id is None: return create_resp(1, msg="we didn't get jobId!", result=None) begin = arg.get("iterationStep", 0) if begin is None: begin = 0 result = DB.query_solve_chart(solve_job_id=job_id, begin=begin) return create_resp(0, msg="success", result=result)
def on_modified(self, event): res_file = event.src_path save_offset = 0 line_matches = 0 for line, offset in offset_file(res_file, offset=self.offset): if re.search("Finished", line): line_matches += 1 if re.search("End", line): DB.compete_mesh_step(mesh_id=self.mesh_id) return save_offset = offset self.current_step += line_matches self.offset = save_offset if save_offset > 0 else self.offset res = DB.query_mesh_status(self.mesh_id) if res == {}: convert_logger.critical(f"mesh_status中没有对应的mesh | {self.mesh_id}") return else: DB.update_mesh_status(self.mesh_id, current_step=self.current_step)
def post(self): in_args = dict(compute_domain_status) domain_id = in_args.get("domain-id", None) if domain_id is None: return create_resp(1, msg="没有接收到domain-id", result=None) domain_status = DB.query_compute_domain(domain_id) if domain_status is None: return create_resp(1, msg=f"未查询到domain状态 | domain-id: {domain_id}", result=None) else: return create_resp(0, msg="success", result=domain_status)
def post(self): in_arg = dict(convert_status.parse_args()) convert_id = in_arg.get("convertId", None) if convert_id is not None: res = DB.query_convert(convert_id) if res: return create_resp(0, msg="success!", result=res) else: return create_resp(1, msg=f"不存在该转换任务 | {convert_id}", result=None) else: return create_resp(1, msg=f"没有接收到convertId", result=None)
def __init__( self, parent ): super( self.__class__, self ).__init__( parent ) self.radioList = {} self.contactListItems = {} self.layout = QtGui.QVBoxLayout() self.layout.addStretch( 1 ) #self.layout.setAlignment( QtCore.Qt.AlignTop ) self.setLayout( self.layout ) self.contact = None #self.master.View.contactItem( contact, status ) self.connect( QHelper.master(), QtCore.SIGNAL( 'receiveMessage' ), self.receiveMessageCallback ) self.connect( QHelper.master(), QtCore.SIGNAL( 'contactStatus' ), self.contactStatusCallback ) self.connect( QHelper.master(), QtCore.SIGNAL( 'pickedContact' ), self.pickedContactCallback ) for row in DB.execute( "SELECT `contact`.*, `contact_group`.`name` FROM `contact`, `contact_group` WHERE `contact`.`contact_group_id`=`contact_group`.`id`" ): self.radioList[row['name']] = QContact( row['name'], 'offline', '', self ) self.layout.addWidget( self.radioList[row['name']] )
def post(self): in_arg = dict(mesh_status_parser.parse_args()) mesh_id = in_arg.get("meshId", None) if mesh_id is None: return create_resp(1, msg="we didn't get meshId", result=None) result = DB.query_mesh_status(mesh_id) if result is None: return create_resp(1, msg="没有该网格作业的状态", result=None) slurm_id = result["slurmId"] status = SlurmDB().query_job_status(slurm_id) if status == -2: return create_resp(1, msg="slurm中没有对应的作业", result=None) result["slurmStatus"] = status result["currentStep"] = result["totalStep"] - 1 if \ result["currentStep"] > result["totalStep"] else result["currentStep"] return create_resp(0, msg="success", result=result)
def start_actions(self): core_logger.info(f"构建计算域数据库信息 | cad_file_path: {self.cad_file_path}" f" | visual_file_path: {self.visual_file_path}") domain_id = DB.write_compute_domain(self.cad_file_path, self.visual_file_path) core_logger.info(f"异步开始构建计算域 | domain_id: {domain_id}") try: dom_crt_process = Process(target=self.asyc_domain_create, args=(domain_id, )) dom_crt_process.start() core_logger.exception( f"异步进行计算域的生成 | pid: {dom_crt_process.pid} | domain_id: {domain_id}" ) return domain_id, "success" except ProcessError: core_logger.exception(f"开启计算域构建进程失败 | domain_id: {domain_id}") return -1, f"开启计算域构建进程失败 | domain_id: {domain_id}"
def post(self): arg = dict(results_parser.parse_args()) job_id = arg.get("jobId", None) if job_id is None: return create_resp(1, msg="we didn't get jobId!", result=None) result = DB.query_solve_status(solve_id=job_id) if result is None or result == {}: return create_resp(1, msg="没有该仿真作业的状态", result=None) slurm_id = result["slurmId"] status = SlurmDB().query_job_status(slurm_id) if status == -2: return create_resp(1, msg="slurm中没有对应的作业", result=None) result["currentStep"] = result["currentStep"] + 1 if result[ "currentStep"] > 0 else 0 result["slurmStatus"] = status return create_resp(0, msg="success", result=result)
def post(self): in_args = su2mesh_status_parser.parse_args() mesh_id = in_args.get("meshId", None) if mesh_id is None: return create_resp(2, msg=f"未接收到参数meshId", result=None) result = DB.query_mesh_convert(mesh_id) slurm_id = result["slurmId"] status = SlurmDB().query_job_status(slurm_id) if status == -2: return create_resp(1, msg="slurm中没有对应的作业", result=None) result["slurmStatus"] = status if result["slurmStatus"] == 3 and result["convertStatus"] is None: result["convertStatus"] = 1 if result["slurmStatus"] >= 4: result["convertStatus"] = 2 if result["slurmStatus"] <= 1: result["convertStatus"] = 1 if result["convertStatus"] == 0: result["convertStatus"] = 3 else: result["convertStatus"] = 1 return create_resp(0, msg="success", result=result)
def start_actions(self): core_logger.info( f"划分网格信息写入数据库 | mesh_app: {self.mesh_app}" f" | work_path: {self.work_path} | cad:name: {self.cad_file_path}" f" | mesh_name: {self.mesh_name}") mesh_id = DB.write_mesh(meshing_path=self.work_path, cad_path=self.cad_file_path, username=self.username, mesh_app=self.mesh_app, mesh_config=self.mesh_config, launch_script=str(self.lanuch_script)) core_logger.info(f"异步进行网格的划分 | mesh_id: {mesh_id}") try: mc_process = Process(target=self._asyc_mesh, args=(mesh_id, )) mc_process.start() core_logger.info( f"异步mesh_convert进程开始 | pid: {mc_process.pid} | mesh_id: {mesh_id}" ) # self._asyc_mesh(mesh_id) except ProcessError: # TODO 更新数据库 core_logger.exception(f"开启转换进程失败 | mesh_id: {mesh_id}") return -1, "开启网格进程失败" return mesh_id, "success!"
def _asyc_convert(self, convert_id): core_logger.info(f"异步进行转换 | {convert_id}") try: status, conver_info, msg = self.converter.start() except TypeError: DB.update_convert(convert_id, 2, {}) core_logger.exception(f"转换失败 | {convert_id}") return except ValueError: DB.update_convert(convert_id, 2, {}) core_logger.exception(f"转换失败 | {convert_id}") return DB.update_convert(convert_id, status, conver_info) core_logger.info(f"异步转换结束 | {convert_id} | {msg}") if self.thumb_path is not None: if Path(self.vf_file).exists(): res = SnipThumb(vf_file=self.vf_file, img_file=self.thumb_path).start() if res == 1: core_logger.info(f"图片转换失败 | 图片转换脚本出错") core_logger.info(f"转换图片失败 | 没有对应的vtm文件 | {self.vf_file}") return
def removeContactCallback( self, contact ): QHelper.log( '::CONNECT:QContact:removeContact', contact ) if self.name == contact: DB.execute( "DELETE FROM `contact` WHERE `name`=?", self.name ) self.update()