|
@@ -11,6 +11,9 @@ import com.css.simulation.resource.scheduler.mapper.*;
|
|
|
import com.css.simulation.resource.scheduler.pojo.po.*;
|
|
|
import com.css.simulation.resource.scheduler.pojo.to.*;
|
|
|
import io.kubernetes.client.openapi.ApiClient;
|
|
|
+import io.kubernetes.client.openapi.apis.BatchV1Api;
|
|
|
+import io.kubernetes.client.openapi.models.V1Job;
|
|
|
+import io.kubernetes.client.util.Yaml;
|
|
|
import io.minio.MinioClient;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -22,6 +25,7 @@ import org.springframework.kafka.annotation.KafkaListener;
|
|
|
import org.springframework.kafka.core.KafkaTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
@@ -59,6 +63,10 @@ public class ManualProjectConsumer {
|
|
|
ApiClient apiClient;
|
|
|
@Value("${scheduler.manual-project.topic}")
|
|
|
String manualProjectTopic;
|
|
|
+ @Value("${scheduler.manual-project.result-path-minio}")
|
|
|
+ String resultPathMinio;
|
|
|
+ @Value("${scheduler.manual-project.job-template-yaml}")
|
|
|
+ String jobTemplateYaml;
|
|
|
@Value("${scheduler.linux-temp-path}")
|
|
|
String linuxTempPath;
|
|
|
|
|
@@ -71,7 +79,7 @@ public class ManualProjectConsumer {
|
|
|
@KafkaListener(groupId = "simulation-resource-scheduler", topics = "${scheduler.manual-project.topic}")
|
|
|
@SneakyThrows
|
|
|
public void parseProject(ConsumerRecord<String, String> projectRecord) {
|
|
|
- log.info("------- parseProject 接收到消息为:" + projectRecord);
|
|
|
+ log.info("------- ManualProjectConsumer 接收到消息为:" + projectRecord);
|
|
|
|
|
|
|
|
|
{
|
|
@@ -114,13 +122,13 @@ public class ManualProjectConsumer {
|
|
|
}
|
|
|
}
|
|
|
List<ScenePO> sceneList = new ArrayList<>();
|
|
|
- if (CollectionUtil.isNotEmpty(naturalIdList)){
|
|
|
+ if (CollectionUtil.isNotEmpty(naturalIdList)) {
|
|
|
sceneList.addAll(sceneMapper.selectNaturalByIdList(naturalIdList));
|
|
|
}
|
|
|
- if (CollectionUtil.isNotEmpty(standardIdList)){
|
|
|
+ if (CollectionUtil.isNotEmpty(standardIdList)) {
|
|
|
sceneList.addAll(sceneMapper.selectStandardByIdList(standardIdList));
|
|
|
}
|
|
|
- if (CollectionUtil.isNotEmpty(accidentIdList)){
|
|
|
+ if (CollectionUtil.isNotEmpty(accidentIdList)) {
|
|
|
sceneList.addAll(sceneMapper.selectAccidentByIdList(accidentIdList));
|
|
|
}
|
|
|
projectMapper.updateTaskNumber(projectId, sceneList.size());
|
|
@@ -137,7 +145,7 @@ public class ManualProjectConsumer {
|
|
|
|
|
|
for (ScenePO scenePO : sceneList) {
|
|
|
String taskId = StringUtil.getRandomUUID();
|
|
|
- String resultPath = linuxTempPath + projectId + "/" + taskId;
|
|
|
+ String resultPath = resultPathMinio + projectId + "/" + taskId;
|
|
|
|
|
|
TaskPO taskPO = TaskPO.builder()
|
|
|
.id(taskId)
|
|
@@ -202,15 +210,14 @@ public class ManualProjectConsumer {
|
|
|
|
|
|
String taskJson = JsonUtil.beanToJson(taskTO);
|
|
|
|
|
|
-
|
|
|
- kafkaTemplate.send("test", taskJson).addCallback(success -> {
|
|
|
+ kafkaTemplate.send(projectId, taskJson).addCallback(success -> {
|
|
|
|
|
|
String topic = success.getRecordMetadata().topic();
|
|
|
|
|
|
int partition = success.getRecordMetadata().partition();
|
|
|
|
|
|
long offset = success.getRecordMetadata().offset();
|
|
|
- log.info("------- 发送消息成功:\n"
|
|
|
+ log.info("------- ManualProjectConsumer 发送消息成功:\n"
|
|
|
+ "主题 topic 为:" + topic + "\n"
|
|
|
+ "分区 partition 为:" + partition + "\n"
|
|
|
+ "偏移量为:" + offset + "\n"
|
|
@@ -221,10 +228,10 @@ public class ManualProjectConsumer {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- String algorithmId = projectMessageDTO.getAlgorithmId();
|
|
|
-
|
|
|
- AlgorithmPO algorithmPO = algorithmMapper.selectById(algorithmId);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -240,10 +247,12 @@ public class ManualProjectConsumer {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ int completions = sceneList.size();
|
|
|
+ int parallelism = projectMessageDTO.getParallelism();
|
|
|
+ log.info("------- ManualProjectConsumer 项目 " + projectId + " 的完成度为:" + completions);
|
|
|
+ log.info("------- ManualProjectConsumer 项目 " + projectId + " 的并行度为:" + parallelism);
|
|
|
+ BatchV1Api batchV1Api = new BatchV1Api(apiClient);
|
|
|
+ V1Job yaml = (V1Job) Yaml.load(new File("/opt/simulation-cloud/simulation-resource-scheduler/conf/job-template.yaml"));
|
|
|
|
|
|
|
|
|
|
|
@@ -271,7 +280,8 @@ public class ManualProjectConsumer {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+ log.info("------- ManualProjectConsumer 创建 job:" + yaml);
|
|
|
+ batchV1Api.createNamespacedJob("simulation-cloud", yaml, null, null, null);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -322,13 +332,13 @@ public class ManualProjectConsumer {
|
|
|
}
|
|
|
}
|
|
|
List<ScenePO> sceneList = new ArrayList<>();
|
|
|
- if (CollectionUtil.isNotEmpty(naturalIdList)){
|
|
|
+ if (CollectionUtil.isNotEmpty(naturalIdList)) {
|
|
|
sceneList.addAll(sceneMapper.selectNaturalByIdList(naturalIdList));
|
|
|
}
|
|
|
- if (CollectionUtil.isNotEmpty(standardIdList)){
|
|
|
+ if (CollectionUtil.isNotEmpty(standardIdList)) {
|
|
|
sceneList.addAll(sceneMapper.selectStandardByIdList(standardIdList));
|
|
|
}
|
|
|
- if (CollectionUtil.isNotEmpty(accidentIdList)){
|
|
|
+ if (CollectionUtil.isNotEmpty(accidentIdList)) {
|
|
|
sceneList.addAll(sceneMapper.selectAccidentByIdList(accidentIdList));
|
|
|
}
|
|
|
projectMapper.updateTaskNumber(projectId, sceneList.size());
|