|
|
|
@@ -34,12 +34,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
@Resource |
|
|
|
private ExperimentDao experimentDao; |
|
|
|
@Resource |
|
|
|
private WorkflowService |
|
|
|
|
|
|
|
|
|
|
|
workflowService; |
|
|
|
|
|
|
|
|
|
|
|
private WorkflowService workflowService; |
|
|
|
@Value("${argo.url}") |
|
|
|
private String argoUrl; |
|
|
|
@Value("${argo.convert}") |
|
|
|
@@ -67,11 +62,10 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
|
|
|
|
// 检查是否需要调用接口查询状态:当原本状态为null或非终止态时调用argo接口 |
|
|
|
if (StringUtils.isEmpty(currentStatus) || !isTerminatedState(currentStatus)) { |
|
|
|
String newStatus = this.queryStatusFromArgo(experimentIns.getArgoInsNs(), experimentIns.getArgoInsName(), id ); |
|
|
|
experimentIns = this.queryStatusFromArgo(experimentIns); |
|
|
|
|
|
|
|
// 如果新状态不是null,并且与旧状态不同,则更新状态 |
|
|
|
if(!StringUtils.isEmpty(newStatus) && !StringUtils.equals(newStatus, currentStatus)){ |
|
|
|
experimentIns.setStatus(newStatus); |
|
|
|
if(!StringUtils.isEmpty(experimentIns.getStatus()) && !StringUtils.equals(experimentIns.getStatus(), currentStatus)){ |
|
|
|
this.update(experimentIns); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -90,14 +84,17 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
@Override |
|
|
|
public List<ExperimentIns> getByExperimentId(Integer experimentId) { |
|
|
|
List<ExperimentIns> experimentInsList = experimentInsDao.getByExperimentId(experimentId); |
|
|
|
for (ExperimentIns experimentIns: experimentInsList) { |
|
|
|
//当原本状态为null或非终止态时才调用argo接口 |
|
|
|
if ( experimentIns!=null && (StringUtils.isEmpty(experimentIns.getStatus())) || !isTerminatedState(experimentIns.getStatus())) { |
|
|
|
String newStatus = this.queryStatusFromArgo(experimentIns.getArgoInsNs(), experimentIns.getArgoInsName(),experimentIns.getId()); |
|
|
|
experimentIns.setStatus(newStatus); |
|
|
|
//只有当新状态是终止态时才更新数据库 |
|
|
|
if (isTerminatedState(newStatus)) { |
|
|
|
this.update(experimentIns); |
|
|
|
if (experimentInsList!=null&&experimentInsList.size()>0) { |
|
|
|
for (ExperimentIns experimentIns : experimentInsList) { |
|
|
|
//当原本状态为null或非终止态时才调用argo接口 |
|
|
|
if (experimentIns != null && (StringUtils.isEmpty(experimentIns.getStatus())) || !isTerminatedState(experimentIns.getStatus())) { |
|
|
|
experimentIns = this.queryStatusFromArgo(experimentIns); |
|
|
|
//只有当新状态是终止态时才更新数据库 |
|
|
|
if (isTerminatedState(experimentIns.getStatus())) { |
|
|
|
//同时更新各个节点 |
|
|
|
|
|
|
|
this.update(experimentIns); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -121,9 +118,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
for (ExperimentIns ins : experimentInsList) { |
|
|
|
//如果实验实例不为空或者 |
|
|
|
if (ins != null && StringUtils.isEmpty(ins.getStatus())) { |
|
|
|
Integer experimentInsId = ins.getId(); |
|
|
|
String status = this.queryStatusFromArgo(ins.getArgoInsNs(), ins.getArgoInsName(), experimentInsId); |
|
|
|
ins.setStatus(status); |
|
|
|
ins = this.queryStatusFromArgo(ins); |
|
|
|
this.update(ins); |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -183,7 +178,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(experimentIns.getStatus())){ |
|
|
|
experimentIns.setStatus(queryStatusFromArgo(experimentIns.getArgoInsNs(), experimentIns.getArgoInsName(), id)); |
|
|
|
experimentIns = queryStatusFromArgo(experimentIns); |
|
|
|
} |
|
|
|
if (StringUtils.equals(experimentIns.getStatus(),"Running")){ |
|
|
|
return "实验实例正在运行,不可删除"; |
|
|
|
@@ -214,7 +209,11 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String queryStatusFromArgo(String namespace, String name, Integer id) { |
|
|
|
public ExperimentIns queryStatusFromArgo(ExperimentIns ins) { |
|
|
|
|
|
|
|
String namespace = ins.getArgoInsNs(); |
|
|
|
String name = ins.getArgoInsName(); |
|
|
|
Integer id = ins.getId(); |
|
|
|
ExperimentIns experimentIns = this.experimentInsDao.queryById(id); |
|
|
|
// 创建请求数据map |
|
|
|
Map<String,Object> requestData = new HashMap<>(); |
|
|
|
@@ -273,9 +272,9 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
|
|
|
|
String nodeStatusJson = JsonUtils.mapToJson(modifiedNodes); |
|
|
|
experimentIns.setNodesStatus(nodeStatusJson); |
|
|
|
this.experimentInsDao.update(experimentIns); |
|
|
|
experimentIns.setStatus((String) status.get("phase")); |
|
|
|
|
|
|
|
return (String) status.get("phase"); |
|
|
|
return experimentIns; |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
throw new RuntimeException("查询状态失败: " + e.getMessage(), e); |
|
|
|
@@ -303,7 +302,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
String namespace = experimentIns.getArgoInsNs(); |
|
|
|
// 获取当前状态,如果为空,则从Argo查询 |
|
|
|
if (StringUtils.isEmpty(currentStatus)) { |
|
|
|
currentStatus = queryStatusFromArgo(namespace, name, id ); |
|
|
|
currentStatus = queryStatusFromArgo(experimentIns).getStatus(); |
|
|
|
} |
|
|
|
|
|
|
|
// 只有状态是"Running"时才能终止实例 |
|
|
|
|