|
|
|
@@ -36,13 +36,13 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
@Resource |
|
|
|
private WorkflowService workflowService; |
|
|
|
@Value("${argo.url}") |
|
|
|
private String argoUrl; |
|
|
|
private String argoUrl; |
|
|
|
@Value("${argo.convert}") |
|
|
|
private String argoConvert; |
|
|
|
private String argoConvert; |
|
|
|
@Value("${argo.workflowRun}") |
|
|
|
private String argoWorkflowRun; |
|
|
|
private String argoWorkflowRun; |
|
|
|
@Value("${argo.workflowStatus}") |
|
|
|
private String argoWorkflowStatus; |
|
|
|
private String argoWorkflowStatus; |
|
|
|
@Value("${argo.workflowTermination}") |
|
|
|
private String argoWorkflowTermination; |
|
|
|
@Value("${argo.workflowLog}") |
|
|
|
@@ -60,6 +60,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
@Resource |
|
|
|
private K8sClientUtil k8sClientUtil; |
|
|
|
private final MinioUtil minioUtil; |
|
|
|
|
|
|
|
public ExperimentInsServiceImpl(MinioUtil minioUtil) { |
|
|
|
this.minioUtil = minioUtil; |
|
|
|
} |
|
|
|
@@ -97,8 +98,6 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* |
|
|
|
* 根据实验ID查找所有具有相同ID的实例,并将它们添加到实验列表中 |
|
|
|
* |
|
|
|
* @param experimentId 实验ID |
|
|
|
@@ -187,8 +186,6 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 修改数据 |
|
|
|
* |
|
|
|
@@ -207,7 +204,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
@Override |
|
|
|
public String removeById(Integer id) { |
|
|
|
ExperimentIns experimentIns = experimentInsDao.queryById(id); |
|
|
|
if (experimentIns == null){ |
|
|
|
if (experimentIns == null) { |
|
|
|
return "实验实例不存在"; |
|
|
|
} |
|
|
|
|
|
|
|
@@ -215,21 +212,31 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser(); |
|
|
|
String username = loginUser.getUsername(); |
|
|
|
String createdBy = experimentIns.getCreateBy(); |
|
|
|
if (!(StringUtils.equals(username,"admin") || StringUtils.equals(username,createdBy))){ |
|
|
|
if (!(StringUtils.equals(username, "admin") || StringUtils.equals(username, createdBy))) { |
|
|
|
return "无权限删除该流水线"; |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(experimentIns.getStatus())){ |
|
|
|
if (StringUtils.isEmpty(experimentIns.getStatus())) { |
|
|
|
experimentIns = queryStatusFromArgo(experimentIns); |
|
|
|
} |
|
|
|
if (StringUtils.equals(experimentIns.getStatus(),"Running")){ |
|
|
|
if (StringUtils.equals(experimentIns.getStatus(), "Running")) { |
|
|
|
return "实验实例正在运行,不可删除"; |
|
|
|
} |
|
|
|
experimentIns.setState(0); |
|
|
|
return this.experimentInsDao.update(experimentIns)>0?"删除成功":"删除失败"; |
|
|
|
return this.experimentInsDao.update(experimentIns) > 0 ? "删除成功" : "删除失败"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String batchDelete(List<Integer> ids) { |
|
|
|
for (Integer id : ids) { |
|
|
|
String result = removeById(id); |
|
|
|
if (!"删除成功".equals(result)) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
return "删除成功"; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@@ -256,16 +263,16 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
Integer id = ins.getId(); |
|
|
|
// 创建请求数据map |
|
|
|
ExperimentIns experimentIns = this.experimentInsDao.queryById(id); |
|
|
|
Map<String,Object> requestData = new HashMap<>(); |
|
|
|
Map<String, Object> requestData = new HashMap<>(); |
|
|
|
requestData.put("namespace", namespace); |
|
|
|
requestData.put("name", name); |
|
|
|
// 创建发送数据map,将请求数据作为"data"键的值 |
|
|
|
Map<String,Object> res = new HashMap<>(); |
|
|
|
Map<String, Object> res = new HashMap<>(); |
|
|
|
res.put("data", requestData); |
|
|
|
|
|
|
|
try { |
|
|
|
// 发送POST请求到Argo工作流状态查询接口,并将请求数据转换为JSON |
|
|
|
String req = httpUtils.sendPost(argoUrl + argoWorkflowStatus,null, JsonUtils.mapToJson(res)); |
|
|
|
String req = httpUtils.sendPost(argoUrl + argoWorkflowStatus, null, JsonUtils.mapToJson(res)); |
|
|
|
// 检查响应是否为空或无内容 |
|
|
|
if (req == null || StringUtils.isEmpty(req)) { |
|
|
|
throw new RuntimeException("工作流状态响应为空。"); |
|
|
|
@@ -293,10 +300,10 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
|
|
|
|
// 解析nodes字段,提取节点状态并转换为JSON字符串 |
|
|
|
Map<String, Object> nodes = (Map<String, Object>) status.get("nodes"); |
|
|
|
Map<String, Object> modifiedNodes = new LinkedHashMap<>(); |
|
|
|
if (nodes != null ) { |
|
|
|
Map<String, Object> modifiedNodes = new LinkedHashMap<>(); |
|
|
|
if (nodes != null) { |
|
|
|
for (Map.Entry<String, Object> nodeEntry : nodes.entrySet()) { |
|
|
|
Map<String,Object> nodeDetails = (Map<String, Object>) nodeEntry.getValue(); |
|
|
|
Map<String, Object> nodeDetails = (Map<String, Object>) nodeEntry.getValue(); |
|
|
|
String templateName = (String) nodeDetails.get("displayName"); |
|
|
|
modifiedNodes.put(templateName, nodeDetails); |
|
|
|
} |
|
|
|
@@ -306,10 +313,10 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
experimentIns.setNodesStatus(nodeStatusJson); |
|
|
|
|
|
|
|
//终止态为终止不改 |
|
|
|
if (!StringUtils.equals(experimentIns.getStatus(),"Terminated")) { |
|
|
|
experimentIns.setStatus(StringUtils.isNotEmpty((String) status.get("phase"))?(String) status.get("phase"):"Pending"); |
|
|
|
if (!StringUtils.equals(experimentIns.getStatus(), "Terminated")) { |
|
|
|
experimentIns.setStatus(StringUtils.isNotEmpty((String) status.get("phase")) ? (String) status.get("phase") : "Pending"); |
|
|
|
} |
|
|
|
if (StringUtils.equals(experimentIns.getStatus(),"Error")) { |
|
|
|
if (StringUtils.equals(experimentIns.getStatus(), "Error")) { |
|
|
|
experimentIns.setStatus("Failed"); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -350,16 +357,16 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
} |
|
|
|
|
|
|
|
// 创建请求数据map |
|
|
|
Map<String,Object> requestData = new HashMap<>(); |
|
|
|
Map<String, Object> requestData = new HashMap<>(); |
|
|
|
requestData.put("namespace", namespace); |
|
|
|
requestData.put("name", name); |
|
|
|
// 创建发送数据map,将请求数据作为"data"键的值 |
|
|
|
Map<String,Object> res = new HashMap<>(); |
|
|
|
Map<String, Object> res = new HashMap<>(); |
|
|
|
res.put("data", requestData); |
|
|
|
|
|
|
|
try { |
|
|
|
// 发送POST请求到Argo工作流状态查询接口,并将请求数据转换为JSON |
|
|
|
String req = httpUtils.sendPost(argoUrl + argoWorkflowTermination,null, JsonUtils.mapToJson(res)); |
|
|
|
String req = httpUtils.sendPost(argoUrl + argoWorkflowTermination, null, JsonUtils.mapToJson(res)); |
|
|
|
// 检查响应是否为空或无内容 |
|
|
|
if (StringUtils.isEmpty(req)) { |
|
|
|
throw new RuntimeException("终止响应内容为空。"); |
|
|
|
@@ -423,20 +430,20 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
String namespace = experimentIns.getArgoInsNs(); |
|
|
|
|
|
|
|
// 创建请求数据的Json(map) |
|
|
|
Map<String,Object> requestData = new HashMap<>(); |
|
|
|
Map<String, Object> requestData = new HashMap<>(); |
|
|
|
requestData.put("namespace", namespace); |
|
|
|
requestData.put("name", name); |
|
|
|
//先写死这两个数据项 |
|
|
|
requestData.put("workflow-type","workflows"); |
|
|
|
requestData.put("artifact-name","main-logs"); |
|
|
|
requestData.put("component-id",componentId); |
|
|
|
requestData.put("workflow-type", "workflows"); |
|
|
|
requestData.put("artifact-name", "main-logs"); |
|
|
|
requestData.put("component-id", componentId); |
|
|
|
// 创建发送数据map,将请求数据作为"data"键的值 |
|
|
|
Map<String,Object> res = new HashMap<>(); |
|
|
|
Map<String, Object> res = new HashMap<>(); |
|
|
|
res.put("data", requestData); |
|
|
|
|
|
|
|
try { |
|
|
|
// 发送POST请求到Argo工作流日志查询接口,并将请求数据转换为JSON |
|
|
|
String req = httpUtils.sendPost(argoUrl + argoWorkflowLog, null,JsonUtils.mapToJson(res)); |
|
|
|
String req = httpUtils.sendPost(argoUrl + argoWorkflowLog, null, JsonUtils.mapToJson(res)); |
|
|
|
// 检查响应是否为空或无内容 |
|
|
|
if (StringUtils.isEmpty(req)) { |
|
|
|
throw new RuntimeException("响应内容为空"); |
|
|
|
@@ -445,7 +452,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
Map<String, Object> runResMap = JsonUtils.jsonToMap(req); |
|
|
|
// 从响应Map中获取"data"的值,也就是日志的值 |
|
|
|
String experimentInsLog = (String) runResMap.get("data"); |
|
|
|
if (experimentInsLog == null){ |
|
|
|
if (experimentInsLog == null) { |
|
|
|
throw new RuntimeException("日志为空。"); |
|
|
|
} |
|
|
|
//返回日志内容 |
|
|
|
@@ -463,28 +470,28 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
//查询 实例 |
|
|
|
ExperimentIns experimentIns = this.experimentInsDao.queryById(id); |
|
|
|
if (experimentIns == null) { |
|
|
|
throw new Exception("实验实例未查询到,id:" + id); |
|
|
|
throw new Exception("实验实例未查询到,id:" + id); |
|
|
|
} |
|
|
|
//找到 节点 节点结果 |
|
|
|
String nodesResultString = experimentIns.getNodesResult(); |
|
|
|
if (StringUtils.isEmpty(nodesResultString)) { |
|
|
|
throw new Exception("实验实例未查询到节点结果,id:" + id); |
|
|
|
throw new Exception("实验实例未查询到节点结果,id:" + id); |
|
|
|
} |
|
|
|
Map<String, Object> nodesResult = JsonUtils.jsonToMap(nodesResultString); |
|
|
|
Map<String, Object> paramOutput = (Map<String, Object>) nodesResult.get("param_output"); |
|
|
|
List<Map<String,Object>> nodeList = (List<Map<String,Object>>) paramOutput.get(nodeId); |
|
|
|
List<Map<String, Object>> nodeList = (List<Map<String, Object>>) paramOutput.get(nodeId); |
|
|
|
//遍历 查询minio |
|
|
|
for (int i = 0; i < nodeList.size(); i++) { |
|
|
|
Map<String, Object> map = nodeList.get(i); |
|
|
|
String path = (String) map.get("path"); |
|
|
|
String bucketName = path.substring(0, path.indexOf("/")); |
|
|
|
String prefix = path.substring(path.indexOf("/")+1,path.length())+"/"; |
|
|
|
if (StringUtils.equals( (String)map.get("type"),"file")){ |
|
|
|
String prefix = path.substring(path.indexOf("/") + 1, path.length()) + "/"; |
|
|
|
if (StringUtils.equals((String) map.get("type"), "file")) { |
|
|
|
List<Map> fileInfo = minioUtil.listFilesInDirectory(bucketName, prefix); |
|
|
|
map.put("value",fileInfo); |
|
|
|
}else if (StringUtils.equals( (String)map.get("type"),"string")){ |
|
|
|
map.put("value", fileInfo); |
|
|
|
} else if (StringUtils.equals((String) map.get("type"), "string")) { |
|
|
|
String resultInfo = minioUtil.readObjectAsString(bucketName, prefix); |
|
|
|
map.put("value",resultInfo); |
|
|
|
map.put("value", resultInfo); |
|
|
|
} |
|
|
|
results.add(map); |
|
|
|
//组装 |
|
|
|
@@ -501,14 +508,14 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
String taskId = logRequest.getTaskId(); |
|
|
|
String startTime = logRequest.getStartTime(); |
|
|
|
// 创建请求数据的Json(map) |
|
|
|
Map<String,Object> requestData = new HashMap<>(); |
|
|
|
Map<String, Object> requestData = new HashMap<>(); |
|
|
|
requestData.put("component_id", componentId); |
|
|
|
requestData.put("namespace", nameSpace); |
|
|
|
requestData.put("name", name); |
|
|
|
requestData.put("task_id",taskId); |
|
|
|
requestData.put("start_time",startTime); |
|
|
|
requestData.put("task_id", taskId); |
|
|
|
requestData.put("start_time", startTime); |
|
|
|
// 创建发送数据map,将请求数据作为"data"键的值 |
|
|
|
Map<String,Object> res = new HashMap<>(); |
|
|
|
Map<String, Object> res = new HashMap<>(); |
|
|
|
res.put("data", requestData); |
|
|
|
|
|
|
|
try { |
|
|
|
@@ -531,9 +538,9 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> getRealtimePodLog(String podName, String startTime) { |
|
|
|
Map<String,Object> requestData = new HashMap<>(); |
|
|
|
requestData.put("pod_name",podName); |
|
|
|
requestData.put("start_time",startTime); |
|
|
|
Map<String, Object> requestData = new HashMap<>(); |
|
|
|
requestData.put("pod_name", podName); |
|
|
|
requestData.put("start_time", startTime); |
|
|
|
try { |
|
|
|
// 将Map转换为JSON字符串 |
|
|
|
String req = HttpUtils.sendPost(argoUrl + argoWorkflowPodLog, JsonUtils.mapToJson(requestData)); |
|
|
|
@@ -554,7 +561,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getRealtimePodLogFromPod(PodLogVo podLogVo) { |
|
|
|
return k8sClientUtil.getPodLogs(podLogVo.getPodName(), podLogVo.getNamespace(),podLogVo.getContainerName(), logsLines); |
|
|
|
return k8sClientUtil.getPodLogs(podLogVo.getPodName(), podLogVo.getNamespace(), podLogVo.getContainerName(), logsLines); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@@ -573,7 +580,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
experimentIns.setStatus(status.toString()); // 设置实例的状态为枚举中的状态 |
|
|
|
|
|
|
|
// 查询具有相同状态的实例数量 |
|
|
|
Long count = experimentInsDao.count(experimentIns); |
|
|
|
Long count = experimentInsDao.count(experimentIns); |
|
|
|
|
|
|
|
// 将状态及其对应的实例数量放入map中 |
|
|
|
statusCountMap.put(status.toString(), count); |
|
|
|
@@ -588,7 +595,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
boolean flag = true; |
|
|
|
List<String> terminatedStates = Arrays.asList("Succeeded", "Failed"); |
|
|
|
flag = terminatedStates.contains(status); |
|
|
|
if (StringUtils.equals(status, "Terminated")){ |
|
|
|
if (StringUtils.equals(status, "Terminated")) { |
|
|
|
//如果跟node_status里面不一样,就要去更新node_status的信息 |
|
|
|
String nodesStatus = ins.getNodesStatus(); |
|
|
|
Map<String, Object> nodeMap = JsonUtils.jsonToMap(nodesStatus); |
|
|
|
@@ -597,7 +604,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { |
|
|
|
.findFirst() |
|
|
|
.orElse(null); |
|
|
|
Map workflowMap = (Map) nodeMap.get(keyStartsWithWorkflow); |
|
|
|
if (workflowMap != null){ |
|
|
|
if (workflowMap != null) { |
|
|
|
flag = StringUtils.equals("Terminated", (String) workflowMap.get("phase")); |
|
|
|
} |
|
|
|
} |
|
|
|
|