|
@@ -0,0 +1,52 @@
|
|
|
|
+package com.css.simulation.resource.scheduler.manager;
|
|
|
|
+
|
|
|
|
+import api.common.util.FileUtil;
|
|
|
|
+import com.css.simulation.resource.scheduler.configuration.kubernetes.KubernetesConfiguration;
|
|
|
|
+import com.css.simulation.resource.scheduler.util.ProjectUtil;
|
|
|
|
+import lombok.SneakyThrows;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.io.File;
|
|
|
|
+
|
|
|
|
+@Component
|
|
|
|
+@Slf4j
|
|
|
|
+public class ProjectManager {
|
|
|
|
+
|
|
|
|
+ @Value("${scheduler.linux-path.pod-template-yaml}")
|
|
|
|
+ String podTemplateYaml;
|
|
|
|
+ @Value("${scheduler.linux-path.pod-yaml-directory}")
|
|
|
|
+ String podYamlDirectory;
|
|
|
|
+ @Resource
|
|
|
|
+ KubernetesConfiguration kubernetesConfiguration;
|
|
|
|
+ @Resource
|
|
|
|
+ ProjectUtil projectUtil;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建一个临时 yaml,node 在最后用 # 号隔开
|
|
|
|
+ *
|
|
|
|
+ * @param projectId
|
|
|
|
+ * @param algorithmDockerImage
|
|
|
|
+ */
|
|
|
|
+ @SneakyThrows
|
|
|
|
+ public void createTempYaml(String projectId, String algorithmDockerImage, String nodeName) {
|
|
|
|
+ String podName = projectUtil.getRandomPodName(projectId); // 生成 podName
|
|
|
|
+ String podTemplateFileNameOfProject = projectUtil.getPodYamlName(podName, nodeName); // 模板文件名称
|
|
|
|
+ String podString = FileUtil.read(new File(podTemplateYaml));
|
|
|
|
+ String replace0 = podString.replace("vtd-container", "vtd-" + projectId);
|
|
|
|
+ String replace1 = replace0.replace("vtd-image", kubernetesConfiguration.getVtdImage());
|
|
|
|
+ String replace2 = replace1.replace("algorithm-container", "algorithm-" + projectId);
|
|
|
|
+ String replace3 = replace2.replace("algorithm-image", algorithmDockerImage);
|
|
|
|
+ String replace4 = replace3.replace("kafkaTopic", projectId); // 消息主题名称为 projectId
|
|
|
|
+ String replace5 = replace4.replace("pod-name", podName); // pod 名称包括 projectId 和 随机字符串
|
|
|
|
+ String replace6 = replace5.replace("namespace-name", kubernetesConfiguration.getNamespace()); // pod 名称包括 projectId 和 随机字符串
|
|
|
|
+ String replace7 = replace6.replace("node-name", nodeName); // 指定 pod 运行节点
|
|
|
|
+// log.info("ProjectService--createPod 在节点 " + nodeName + " 开始执行 pod:" + tempPodString);
|
|
|
|
+ FileUtil.writeStringToLocalFile(replace7, podYamlDirectory + podTemplateFileNameOfProject);
|
|
|
|
+// log.info("ProjectService--createPod 在节点 " + nodeName + " 开始执行 pod。");
|
|
|
|
+// projectUtil.createPod(nodeName, podName, tempPodString);
|
|
|
|
+ }
|
|
|
|
+}
|