@@ -10,9 +10,11 @@ import com.sdm.common.common.SdmResponse;
import com.sdm.common.common.ThreadLocalContext ;
import com.sdm.common.entity.enums.MessageTemplateEnum ;
import com.sdm.common.entity.req.flowable.AsyncCallbackRequest ;
import com.sdm.common.entity.req.pbs.DelHpcJobsFileToolReq ;
import com.sdm.common.entity.req.pbs.DelHpcJobsReq ;
import com.sdm.common.entity.req.system.SendMsgReq ;
import com.sdm.common.entity.resp.PageDataResp ;
import com.sdm.common.entity.resp.pbs.hpc.DelHpcJobsResult ;
import com.sdm.common.entity.resp.pbs.hpc.FileNodeInfo ;
import com.sdm.common.feign.impl.system.MessageFeignClientImpl ;
import com.sdm.common.feign.inter.flowable.IFlowableFeignClient ;
@@ -55,6 +57,7 @@ import java.time.LocalDateTime;
import java.util.* ;
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
import java.util.stream.Collectors ;
@Slf4j
@Service
@@ -579,7 +582,7 @@ public class PbsServiceDecorator implements IPbsServiceDecorator {
List < SimulationJob > jobList = simulationJobService . lambdaQuery ( )
. in ( SimulationJob : : getJobId , req . getHpcJobIds ( ) )
. list ( ) ;
if ( jobList . isEmpty ( ) ) {
if ( CollectionUtils . isEmpty ( jobList ) ) {
throw new RuntimeException ( " 未查询到待删除的HPC任务 " ) ;
}
// 2. 校验任务状态(非进行中、文件非上传中)
@@ -589,20 +592,59 @@ public class PbsServiceDecorator implements IPbsServiceDecorator {
throw new RuntimeException ( " 删除的任务状态和文件状态不能是未完成 " ) ;
}
// 2 . 调用HPC批量删除接口 todo
// boolean hpcDelSuccess = batchDeleteHpcJobs(req.getHpcJobIds()) ;
// if (!hpcDelSuccess) {
// return SdmResponse.fail("调用HPC批量删除接口失败") ;
// }
// 5. 逻辑删除simulation_job表数据
boolean logicDelSuccess = logicDeleteSimulationJob ( jobList ) ;
if ( ! logicDelSuccess ) {
return SdmResponse . failed ( " 逻辑删除任务数据失败 " ) ;
// 3 . 调用HPC批量删除接口
SdmResponse < DelHpcJobsResult > response = batchDeleteHpcJobs ( jobList ) ;
if ( ! response . isSuccess ( ) ) {
return SdmResponse. failed ( " 调用HPC文件工具服务批量删除工作目录失败:{} " , JSONObject . toJSONString ( response ) ) ;
}
DelHpcJobsResult data = response . getData ( ) ;
if ( ! Objects . isNull ( data ) & & CollectionUtils . isNotEmpty ( data . getSuccJobIds ( ) ) ) {
List < String > succJobIds = data . getSuccJobIds ( ) ;
List < SimulationJob > newJobs = filterSuccessJobs ( jobList , succJobIds ) ;
// 5. 逻辑删除simulation_job表数据
boolean logicDelSuccess = logicDeleteSimulationJob ( newJobs ) ;
if ( ! logicDelSuccess ) {
return SdmResponse . failed ( " 逻辑删除任务数据失败 " ) ;
}
}
return SdmResponse . success ( " 批量删除HPC任务成功 " ) ;
}
/**
* 筛选出jobId在succJobIds中的SimulationJob集合
* @param jobList 原始任务集合
* @param succJobIds 成功的jobId集合
* @return 筛选后的新任务集合
*/
private List < SimulationJob > filterSuccessJobs ( List < SimulationJob > jobList , List < String > succJobIds ) {
// 2. 使用Stream流筛选: jobId存在于succJobIds中的元素
List < SimulationJob > newJobList = jobList . stream ( )
// 核心筛选逻辑: 判断当前job的jobId是否在succJobIds中
. filter ( job - > succJobIds . contains ( job . getJobId ( ) ) )
// 收集筛选结果到新集合
. collect ( Collectors . toList ( ) ) ;
return newJobList ;
}
private SdmResponse < DelHpcJobsResult > batchDeleteHpcJobs ( List < SimulationJob > jobList ) {
// 远程请求filetool工具
List < DelHpcJobsFileToolReq > reqs = new ArrayList < > ( ) ;
for ( SimulationJob job : jobList ) {
if ( StringUtils . isNotBlank ( job . getJobId ( ) ) & & StringUtils . isNotBlank ( job . getStdoutHpcFilePath ( ) ) ) {
DelHpcJobsFileToolReq req = new DelHpcJobsFileToolReq ( ) ;
req . setJobId ( job . getJobId ( ) ) ;
req . setStdoutHpcFilePath ( job . getStdoutHpcFilePath ( ) ) ;
reqs . add ( req ) ;
}
}
if ( CollectionUtils . isEmpty ( reqs ) ) {
log . error ( " batchDeleteHpcJobs get reqs null " ) ;
return SdmResponse . failed ( " 请求参数是null " ) ;
}
SdmResponse < DelHpcJobsResult > response = hpcCommandExcuteUtil . batchDeleteHpcJobs ( reqs , pbsWebClient ) ;
return response ;
}
private boolean logicDeleteSimulationJob ( List < SimulationJob > jobList ) {
for ( SimulationJob job : jobList ) {
job . setDelFlag ( " Y " ) ;