|
@@ -17,8 +17,10 @@ import java.io.File;
|
|
@Slf4j
|
|
@Slf4j
|
|
public class ProjectManager {
|
|
public class ProjectManager {
|
|
|
|
|
|
- @Value("${scheduler.linux-path.pod-template-yaml}")
|
|
|
|
- String podTemplateYaml;
|
|
|
|
|
|
+ @Value("${scheduler.linux-path.vtd-pod-template-yaml}")
|
|
|
|
+ String vtdPodTemplateYaml;
|
|
|
|
+ @Value("${scheduler.linux-path.carsim-pod-template-yaml}")
|
|
|
|
+ String carsimPodTemplateYaml;
|
|
@Value("${scheduler.linux-path.pod-yaml-directory}")
|
|
@Value("${scheduler.linux-path.pod-yaml-directory}")
|
|
String podYamlDirectory;
|
|
String podYamlDirectory;
|
|
@Value("${spring.kafka.bootstrap-servers}")
|
|
@Value("${spring.kafka.bootstrap-servers}")
|
|
@@ -33,12 +35,10 @@ public class ProjectManager {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 创建一个临时 yaml,node 在最后用 # 号隔开
|
|
* 创建一个临时 yaml,node 在最后用 # 号隔开
|
|
- *
|
|
|
|
- * @param projectId
|
|
|
|
- * @param algorithmDockerImage
|
|
|
|
*/
|
|
*/
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
public String createTempYaml(String projectId,
|
|
public String createTempYaml(String projectId,
|
|
|
|
+ String modelType,
|
|
String algorithmDockerImage,
|
|
String algorithmDockerImage,
|
|
String nodeName,
|
|
String nodeName,
|
|
int kafkaPartition,
|
|
int kafkaPartition,
|
|
@@ -48,39 +48,70 @@ public class ProjectManager {
|
|
) {
|
|
) {
|
|
String podName = projectUtil.getRandomPodName(projectId); // 生成 podName
|
|
String podName = projectUtil.getRandomPodName(projectId); // 生成 podName
|
|
String podYaml = projectUtil.getPodYamlName(nodeName, podName); // 模板文件名称
|
|
String podYaml = projectUtil.getPodYamlName(nodeName, podName); // 模板文件名称
|
|
- String podString = FileUtil.read(new File(podTemplateYaml));
|
|
|
|
- String replace0 = podString.replace("vtd-container", "vtd-" + projectId);
|
|
|
|
- String replace1 = replace0.replace("algorithm-container", "algorithm-" + projectId);
|
|
|
|
- String replace2 = replace1.replace("algorithm-image", algorithmDockerImage);
|
|
|
|
- String replace3 = replace2.replace("kafka-topic", projectId); // 消息主题名称为 projectId
|
|
|
|
- String replace4 = replace3.replace("kafka-ip", kafkaIp);
|
|
|
|
- String replace5 = replace4.replace("kafka-partition", "\"" + kafkaPartition + "\"");
|
|
|
|
- String replace6 = replace5.replace("kafka-offset", "\"" + kafkaOffset + "\"");
|
|
|
|
- String replace7 = replace6.replace("minio-ip", minioConfiguration.getEndpointWithoutHttp());
|
|
|
|
- String replace8 = replace7.replace("minio-access-key", minioConfiguration.getAccessKey());
|
|
|
|
- String replace9 = replace8.replace("minio-secret-key", minioConfiguration.getSecretKey());
|
|
|
|
- String replace10 = replace9.replace("pod-name", podName); // pod 名称包括 projectId 和 随机字符串
|
|
|
|
- String replace11 = replace10.replace("namespace-name", kubernetesConfiguration.getNamespace()); // pod 名称包括 projectId 和 随机字符串
|
|
|
|
- String replace12 = replace11.replace("node-name", nodeName); // 指定 pod 运行节点
|
|
|
|
|
|
+ if ("1".equals(modelType)) {
|
|
|
|
+ String podString = FileUtil.read(new File(vtdPodTemplateYaml));
|
|
|
|
+ String replace0 = podString.replace("vtd-container", "vtd-" + projectId);
|
|
|
|
+ String replace1 = replace0.replace("algorithm-container", "algorithm-" + projectId);
|
|
|
|
+ String replace2 = replace1.replace("algorithm-image", algorithmDockerImage);
|
|
|
|
+ String replace3 = replace2.replace("kafka-topic", projectId); // 消息主题名称为 projectId
|
|
|
|
+ String replace4 = replace3.replace("kafka-ip", kafkaIp);
|
|
|
|
+ String replace5 = replace4.replace("kafka-partition", "\"" + kafkaPartition + "\"");
|
|
|
|
+ String replace6 = replace5.replace("kafka-offset", "\"" + kafkaOffset + "\"");
|
|
|
|
+ String replace7 = replace6.replace("minio-ip", minioConfiguration.getEndpointWithoutHttp());
|
|
|
|
+ String replace8 = replace7.replace("minio-access-key", minioConfiguration.getAccessKey());
|
|
|
|
+ String replace9 = replace8.replace("minio-secret-key", minioConfiguration.getSecretKey());
|
|
|
|
+ String replace10 = replace9.replace("pod-name", podName); // pod 名称包括 projectId 和 随机字符串
|
|
|
|
+ String replace11 = replace10.replace("namespace-name", kubernetesConfiguration.getNamespace()); // pod 名称包括 projectId 和 随机字符串
|
|
|
|
+ String replace12 = replace11.replace("node-name", nodeName); // 指定 pod 运行节点
|
|
|
|
|
|
- String finalYaml = null;
|
|
|
|
- if (DictConstants.USE_GPU.equals(isChoiceGpu)) {
|
|
|
|
- log.info("项目 " + projectId + " 使用 gpu 生成视频");
|
|
|
|
- String replace13 = replace12.replace("vtd-image", kubernetesConfiguration.getVtdImageUseGpu());
|
|
|
|
- finalYaml = replace13.replace("vtd-command", kubernetesConfiguration.getVtdCommandUseGpu());
|
|
|
|
- }
|
|
|
|
- if (DictConstants.NOT_USE_GPU.equals(isChoiceGpu)) {
|
|
|
|
- log.info("项目 " + projectId + " 不使用 gpu 生成视频");
|
|
|
|
- String replace13 = replace12.replace("vtd-image", kubernetesConfiguration.getVtdImageNotUseGpu());
|
|
|
|
- finalYaml = replace13.replace("vtd-command", kubernetesConfiguration.getVtdCommandNotUseGpu());
|
|
|
|
|
|
+ String finalYaml = null;
|
|
|
|
+ if (DictConstants.USE_GPU.equals(isChoiceGpu)) {
|
|
|
|
+ log.info("项目 " + projectId + " 使用 gpu 生成视频");
|
|
|
|
+ String replace13 = replace12.replace("vtd-image", kubernetesConfiguration.getVtdImageUseGpu());
|
|
|
|
+ finalYaml = replace13.replace("vtd-command", kubernetesConfiguration.getVtdCommandUseGpu());
|
|
|
|
+ }
|
|
|
|
+ if (DictConstants.NOT_USE_GPU.equals(isChoiceGpu)) {
|
|
|
|
+ log.info("项目 " + projectId + " 不使用 gpu 生成视频");
|
|
|
|
+ String replace13 = replace12.replace("vtd-image", kubernetesConfiguration.getVtdImageNotUseGpu());
|
|
|
|
+ finalYaml = replace13.replace("vtd-command", kubernetesConfiguration.getVtdCommandNotUseGpu());
|
|
|
|
+ }
|
|
|
|
+ log.info("保存项目 " + projectId + " 的 yaml 文件:" + finalYaml);
|
|
|
|
+ FileUtil.writeStringToLocalFile(finalYaml, podYamlDirectory + podYaml);
|
|
|
|
+ return podYamlDirectory + podYaml;
|
|
|
|
+ } else if ("2".equals(modelType)) {
|
|
|
|
+ String podString = FileUtil.read(new File(carsimPodTemplateYaml));
|
|
|
|
+ String replace0 = podString.replace("vtd-container", "vtd-" + projectId);
|
|
|
|
+ String replace1 = replace0.replace("algorithm-container", "algorithm-" + projectId);
|
|
|
|
+ String replace2 = replace1.replace("algorithm-image", algorithmDockerImage);
|
|
|
|
+ String replace3 = replace2.replace("kafka-topic", projectId); // 消息主题名称为 projectId
|
|
|
|
+ String replace4 = replace3.replace("kafka-ip", kafkaIp);
|
|
|
|
+ String replace5 = replace4.replace("kafka-partition", "\"" + kafkaPartition + "\"");
|
|
|
|
+ String replace6 = replace5.replace("kafka-offset", "\"" + kafkaOffset + "\"");
|
|
|
|
+ String replace7 = replace6.replace("minio-ip", minioConfiguration.getEndpointWithoutHttp());
|
|
|
|
+ String replace8 = replace7.replace("minio-access-key", minioConfiguration.getAccessKey());
|
|
|
|
+ String replace9 = replace8.replace("minio-secret-key", minioConfiguration.getSecretKey());
|
|
|
|
+ String replace10 = replace9.replace("pod-name", podName); // pod 名称包括 projectId 和 随机字符串
|
|
|
|
+ String replace11 = replace10.replace("namespace-name", kubernetesConfiguration.getNamespace()); // pod 名称包括 projectId 和 随机字符串
|
|
|
|
+ String replace12 = replace11.replace("node-name", nodeName); // 指定 pod 运行节点
|
|
|
|
+
|
|
|
|
+ String finalYaml = null;
|
|
|
|
+ if (DictConstants.USE_GPU.equals(isChoiceGpu)) {
|
|
|
|
+ log.info("项目 " + projectId + " 使用 gpu 生成视频");
|
|
|
|
+ String replace13 = replace12.replace("vtd-image", kubernetesConfiguration.getVtdImageUseGpu());
|
|
|
|
+ finalYaml = replace13.replace("vtd-command", kubernetesConfiguration.getVtdCommandUseGpu());
|
|
|
|
+ }
|
|
|
|
+ if (DictConstants.NOT_USE_GPU.equals(isChoiceGpu)) {
|
|
|
|
+ log.info("项目 " + projectId + " 不使用 gpu 生成视频");
|
|
|
|
+ String replace13 = replace12.replace("vtd-image", kubernetesConfiguration.getVtdImageNotUseGpu());
|
|
|
|
+ finalYaml = replace13.replace("vtd-command", kubernetesConfiguration.getVtdCommandNotUseGpu());
|
|
|
|
+ }
|
|
|
|
+ log.info("保存项目 " + projectId + " 的 yaml 文件:" + finalYaml);
|
|
|
|
+ FileUtil.writeStringToLocalFile(finalYaml, podYamlDirectory + podYaml);
|
|
|
|
+ return podYamlDirectory + podYaml;
|
|
|
|
+ } else {
|
|
|
|
+ throw new RuntimeException("createTempYaml() 模型类型错误:" + modelType);
|
|
}
|
|
}
|
|
- log.info("保存项目 " + projectId + " 的 yaml 文件:" + finalYaml);
|
|
|
|
- FileUtil.writeStringToLocalFile(finalYaml, podYamlDirectory + podYaml);
|
|
|
|
-// log.info("ProjectService--createPod 在节点 " + nodeName + " 开始执行 pod。");
|
|
|
|
-// projectUtil.createPod(nodeName, podName, tempPodString);
|
|
|
|
- return podYamlDirectory + podYaml;
|
|
|
|
-// if (count == 0) {
|
|
|
|
-// projectUtil.createPod2(podYamlDirectory + podYaml);
|
|
|
|
-// }
|
|
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|