|
@@ -9,12 +9,11 @@ import com.css.simulation.resource.scheduler.pojo.to.*;
|
|
|
import com.css.simulation.resource.scheduler.util.GitUtil;
|
|
|
import com.css.simulation.resource.scheduler.util.KubernetesUtil;
|
|
|
import com.css.simulation.resource.scheduler.util.MinioUtil;
|
|
|
+import com.css.simulation.resource.scheduler.util.ProjectUtil;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import io.kubernetes.client.openapi.ApiClient;
|
|
|
-import io.kubernetes.client.openapi.models.V1Pod;
|
|
|
-import io.kubernetes.client.util.Yaml;
|
|
|
import io.minio.MinioClient;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -28,7 +27,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -77,6 +75,8 @@ public class ProjectService {
|
|
|
AlgorithmMapper algorithmMapper;
|
|
|
@Resource
|
|
|
ApiClient apiClient;
|
|
|
+ @Resource
|
|
|
+ ProjectUtil projectUtil;
|
|
|
|
|
|
|
|
|
// -------------------------------- Comment --------------------------------
|
|
@@ -107,13 +107,6 @@ public class ProjectService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// //4 将项目状态修改为执行中(页面上已经改成了执行中,这里应该不需要)
|
|
|
-// if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
|
|
|
-// manualProjectMapper.updateNowRunStateById(DictConstants.PROJECT_RUNNING, projectId);
|
|
|
-// } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
|
|
|
-// autoSubProjectMapper.updateNowRunStateById(DictConstants.PROJECT_RUNNING, projectId);
|
|
|
-// }
|
|
|
-
|
|
|
//5 将该 project 下所有旧的任务和指标得分删除。
|
|
|
taskMapper.deleteByProject(projectId);
|
|
|
indexMapper.deleteFirstTargetScoreByProjectId(projectId);
|
|
@@ -285,9 +278,9 @@ public class ProjectService {
|
|
|
/**
|
|
|
* 将 master 节点设置成镜像仓库,导入镜像的同时 commit 到仓库当中,供其他节点 pull
|
|
|
*
|
|
|
- * @param projectId
|
|
|
- * @param algorithmId
|
|
|
- * @return
|
|
|
+ * @param projectId 项目 id
|
|
|
+ * @param algorithmId 算法 id
|
|
|
+ * @return 镜像名称
|
|
|
*/
|
|
|
@SneakyThrows
|
|
|
@Transactional
|
|
@@ -379,32 +372,6 @@ public class ProjectService {
|
|
|
return dockerImage;
|
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
-// * 运行
|
|
|
-// *
|
|
|
-// * @param projectId 项目id
|
|
|
-// * @param nodeMap 并行度
|
|
|
-// * @param algorithmDockerImage 算法镜像
|
|
|
-// */
|
|
|
-// @SneakyThrows
|
|
|
-// public void transferAndRunYaml(String projectId, Map<String, Integer> nodeMap, String algorithmDockerImage) {
|
|
|
-// String podTemplate = FileUtil.read(podTemplateYaml);
|
|
|
-// String replace0 = podTemplate.replace("vtd-container", "vtd-" + projectId);
|
|
|
-// String replace1 = replace0.replace("algorithm-container", "algorithm-" + projectId);
|
|
|
-// String replace2 = replace1.replace("algorithm-image", algorithmDockerImage);
|
|
|
-// String replace3 = replace2.replace("kafkaTopic", projectId); // 消息主题名称为 projectId
|
|
|
-// nodeMap.forEach((nodeName, parallelism) -> {
|
|
|
-// String tempPodNameSuffix = projectId + StringUtil.getRandomUUID();
|
|
|
-// String tempReplace4 = replace3.replace("pod-name", "project-" + tempPodNameSuffix); // pod 名称包括 projectId 和 随机字符串
|
|
|
-// String tempFinalYaml = tempReplace4.replace("node-name", nodeName); // 指定 pod 运行节点
|
|
|
-// log.info("ProjectConsumer--parseManualProject 在节点 " + nodeName + " 开始执行 pod:" + finalYaml);
|
|
|
-// String tempFinalYamlTargetPath = podYamlDirectory + tempPodNameSuffix;
|
|
|
-// FileUtil.writeStringToLocalFile(tempFinalYaml, tempFinalYamlTargetPath);
|
|
|
-// // 启动
|
|
|
-// KubernetesUtil.applyYaml(hostname, username, password, jobTemplateYamlPathTarget);
|
|
|
-// });
|
|
|
-// }
|
|
|
-
|
|
|
/**
|
|
|
* 运行 pod
|
|
|
*
|
|
@@ -430,15 +397,17 @@ public class ProjectService {
|
|
|
String tempReplace4 = podTemplateStringOfProject.replace("pod-name", podName); // pod 名称包括 projectId 和 随机字符串
|
|
|
String tempPodString = tempReplace4.replace("node-name", nodeName); // 指定 pod 运行节点
|
|
|
log.info("ProjectService--createPod 在节点 " + nodeName + " 开始执行 pod:" + tempPodString);
|
|
|
- V1Pod v1Pod;
|
|
|
- try {
|
|
|
- FileUtil.writeStringToLocalFile(tempPodString, podYamlDirectory + tempPodFileNameOfProject);
|
|
|
- v1Pod = (V1Pod) Yaml.load(tempPodString);
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException("ProjectService--createPod 项目 " + projectId + " 创建 pod 失败,为:", e);
|
|
|
- }
|
|
|
- // 启动
|
|
|
- KubernetesUtil.createPod(apiClient, kubernetesNamespace, v1Pod);
|
|
|
+ projectUtil.createPod(tempPodString,tempPodFileNameOfProject);
|
|
|
+
|
|
|
+
|
|
|
+// V1Pod v1Pod;
|
|
|
+// try {
|
|
|
+// FileUtil.writeStringToLocalFile(tempPodString, podYamlDirectory + tempPodFileNameOfProject);
|
|
|
+// v1Pod = (V1Pod) Yaml.load(tempPodString);
|
|
|
+// } catch (IOException e) {
|
|
|
+// throw new RuntimeException("ProjectService--createPod 项目 " + projectId + " 创建 pod 失败:", e);
|
|
|
+// }
|
|
|
+// KubernetesUtil.createPod(apiClient, kubernetesNamespace, v1Pod);
|
|
|
});
|
|
|
}
|
|
|
|