|
@@ -5,10 +5,8 @@ import api.common.pojo.constants.DictConstants;
|
|
import api.common.pojo.dto.ProjectMessageDTO;
|
|
import api.common.pojo.dto.ProjectMessageDTO;
|
|
import api.common.pojo.param.KafkaParameter;
|
|
import api.common.pojo.param.KafkaParameter;
|
|
import api.common.pojo.param.MinioParameter;
|
|
import api.common.pojo.param.MinioParameter;
|
|
-import api.common.util.FileUtil;
|
|
|
|
-import api.common.util.JsonUtil;
|
|
|
|
-import api.common.util.LinuxUtil;
|
|
|
|
-import api.common.util.StringUtil;
|
|
|
|
|
|
+import api.common.pojo.param.RedisParameter;
|
|
|
|
+import api.common.util.*;
|
|
import com.css.simulation.resource.scheduler.feign.CommonService;
|
|
import com.css.simulation.resource.scheduler.feign.CommonService;
|
|
import com.css.simulation.resource.scheduler.mapper.*;
|
|
import com.css.simulation.resource.scheduler.mapper.*;
|
|
import com.css.simulation.resource.scheduler.pojo.dto.*;
|
|
import com.css.simulation.resource.scheduler.pojo.dto.*;
|
|
@@ -22,9 +20,11 @@ import io.kubernetes.client.util.Yaml;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.kafka.annotation.KafkaListener;
|
|
import org.springframework.kafka.annotation.KafkaListener;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.util.ResourceUtils;
|
|
import org.springframework.util.ResourceUtils;
|
|
|
|
+
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -38,6 +38,8 @@ public class ManualProjectConsumer {
|
|
@Autowired
|
|
@Autowired
|
|
ProjectMapper projectMapper;
|
|
ProjectMapper projectMapper;
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ TaskMapper taskMapper;
|
|
|
|
+ @Autowired
|
|
IndexMapper indexMapper;
|
|
IndexMapper indexMapper;
|
|
@Autowired
|
|
@Autowired
|
|
SceneMapper sceneMapper;
|
|
SceneMapper sceneMapper;
|
|
@@ -53,8 +55,12 @@ public class ManualProjectConsumer {
|
|
private AlgorithmMapper algorithmMapper;
|
|
private AlgorithmMapper algorithmMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private ApiClient apiClient;
|
|
private ApiClient apiClient;
|
|
|
|
+ @Value("${spring.kafka.consumer.topic.manual-project}")
|
|
|
|
+ private String manualProjectTopic;
|
|
|
|
+ @Value("${scheduler.manual-project.result-path}")
|
|
|
|
+ private String manualProjectResultPath;
|
|
|
|
|
|
- @KafkaListener(groupId = "simulation-resource-scheduler", topics = "test")
|
|
|
|
|
|
+ @KafkaListener(groupId = "simulation-resource-scheduler", topics = "${spring.kafka.consumer.topic.manual-project}")
|
|
public void testConsumer(ConsumerRecord<String, String> projectRecord) {
|
|
public void testConsumer(ConsumerRecord<String, String> projectRecord) {
|
|
System.out.println("------- 消费成功:" + projectRecord.value());
|
|
System.out.println("------- 消费成功:" + projectRecord.value());
|
|
}
|
|
}
|
|
@@ -96,7 +102,7 @@ public class ManualProjectConsumer {
|
|
sceneList.addAll(sceneMapper.selectNaturalByIdList(naturalIdList));
|
|
sceneList.addAll(sceneMapper.selectNaturalByIdList(naturalIdList));
|
|
sceneList.addAll(sceneMapper.selectStandardByIdList(standardIdList));
|
|
sceneList.addAll(sceneMapper.selectStandardByIdList(standardIdList));
|
|
sceneList.addAll(sceneMapper.selectAccidentByIdList(accidentIdList));
|
|
sceneList.addAll(sceneMapper.selectAccidentByIdList(accidentIdList));
|
|
- projectMapper.updateTaskNumber(projectId,sceneList.size()); // 有多少场景就有多少任务
|
|
|
|
|
|
+ projectMapper.updateTaskNumber(projectId, sceneList.size()); // 有多少场景就有多少任务
|
|
// -------------------------------- 2 模型 --------------------------------
|
|
// -------------------------------- 2 模型 --------------------------------
|
|
// 根据 vehicleId, 获取 模型信息和传感器信息
|
|
// 根据 vehicleId, 获取 模型信息和传感器信息
|
|
String vehicleId = projectMessageDTO.getVehicleId(); // 模型 id
|
|
String vehicleId = projectMessageDTO.getVehicleId(); // 模型 id
|
|
@@ -110,8 +116,9 @@ public class ManualProjectConsumer {
|
|
|
|
|
|
for (ScenePO scenePO : sceneList) {
|
|
for (ScenePO scenePO : sceneList) {
|
|
String taskId = StringUtil.getRandomUUID();
|
|
String taskId = StringUtil.getRandomUUID();
|
|
- String resultPath = "/project/manual-project/" + projectId + "/" + taskId;
|
|
|
|
- TaskPO taskPO = TaskPO.builder()
|
|
|
|
|
|
+ String resultPath = manualProjectResultPath + projectId + "/" + taskId;
|
|
|
|
+ // 保存任务信息
|
|
|
|
+ TaskPO taskPO = TaskPO.builder() // run_start_time 和 run_end_time 不填
|
|
.id(taskId)
|
|
.id(taskId)
|
|
.pId(projectId)
|
|
.pId(projectId)
|
|
.sceneId(scenePO.getId())
|
|
.sceneId(scenePO.getId())
|
|
@@ -120,16 +127,16 @@ public class ManualProjectConsumer {
|
|
.runState(DictConstants.TASK_PENDING)
|
|
.runState(DictConstants.TASK_PENDING)
|
|
.runResult(resultPath)
|
|
.runResult(resultPath)
|
|
.build();
|
|
.build();
|
|
-// MonitorTaskPO taskPO = TaskPO.builder()
|
|
|
|
-// .id(taskId)
|
|
|
|
-// .pId(projectId)
|
|
|
|
-// .sceneId(scenePO.getId())
|
|
|
|
-// .sceneName(scenePO.getName())
|
|
|
|
-// .sceneType(scenePO.getType())
|
|
|
|
-// .runState(DictConstants.TASK_PENDING)
|
|
|
|
-// .runResult(resultPath)
|
|
|
|
-// .build();
|
|
|
|
- //4-1 组装 task 消息
|
|
|
|
|
|
+ taskPO.setCreateTime(TimeUtil.getNowForMysql());
|
|
|
|
+ taskPO.setCreateUserId("simulation-resource-scheduler");
|
|
|
|
+ taskPO.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
|
+ taskPO.setModifyUserId("simulation-resource-scheduler");
|
|
|
|
+ taskPO.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
|
+ taskPO.setIsDeleted("0");
|
|
|
|
+ taskMapper.insert(taskPO);
|
|
|
|
+ // 心跳信息存在緩存中
|
|
|
|
+ commonService.set(new RedisParameter(manualProjectTopic + ":" + projectId + ":" + taskId, TimeUtil.getNow() + "", 0));
|
|
|
|
+ // 组装 task 消息
|
|
TaskDTO taskDTO = TaskDTO.builder()
|
|
TaskDTO taskDTO = TaskDTO.builder()
|
|
.info(InfoDTO.builder()
|
|
.info(InfoDTO.builder()
|
|
.project_id(projectId)
|
|
.project_id(projectId)
|
|
@@ -186,12 +193,11 @@ public class ManualProjectConsumer {
|
|
// 下载算法文件到本地( 2 到仓库服务器)
|
|
// 下载算法文件到本地( 2 到仓库服务器)
|
|
Response response = commonService.download(new MinioParameter(minioPath));
|
|
Response response = commonService.download(new MinioParameter(minioPath));
|
|
InputStream inputStream = response.body().asInputStream();
|
|
InputStream inputStream = response.body().asInputStream();
|
|
- FileUtil.writeInputStreamToLocalFile(inputStream,localPath);
|
|
|
|
|
|
+ FileUtil.writeInputStreamToLocalFile(inputStream, localPath);
|
|
//4-2 本地执行 docker load 算法文件成镜像( 2 创建 ssh 连接)
|
|
//4-2 本地执行 docker load 算法文件成镜像( 2 创建 ssh 连接)
|
|
LinuxUtil.execute("docker load");
|
|
LinuxUtil.execute("docker load");
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
// -------------------------------- 5 创建 pod 开始执行 --------------------------------
|
|
// -------------------------------- 5 创建 pod 开始执行 --------------------------------
|
|
int completions = sceneList.size();
|
|
int completions = sceneList.size();
|
|
int parallelism = projectMessageDTO.getParallelism(); // 并行度
|
|
int parallelism = projectMessageDTO.getParallelism(); // 并行度
|
|
@@ -233,6 +239,4 @@ public class ManualProjectConsumer {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|