|
@@ -3,7 +3,6 @@ package com.css.simulation.resource.scheduler.consumer;
|
|
|
|
|
|
import api.common.pojo.constants.DictConstants;
|
|
|
import api.common.pojo.dto.ProjectMessageDTO;
|
|
|
-import api.common.util.CollectionUtil;
|
|
|
import api.common.util.JsonUtil;
|
|
|
import api.common.util.StringUtil;
|
|
|
import com.css.simulation.resource.scheduler.mapper.*;
|
|
@@ -22,10 +21,7 @@ import org.springframework.kafka.annotation.KafkaListener;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Component
|
|
|
@Slf4j
|
|
@@ -66,8 +62,6 @@ public class ProjectConsumer {
|
|
|
ProjectUtil projectUtil;
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
|
|
|
* 任务运行前首先判断用户是否拥有可分配资源
|
|
|
*
|
|
@@ -149,19 +143,14 @@ public class ProjectConsumer {
|
|
|
|
|
|
String projectId = projectMessageDTO.getProjectId();
|
|
|
int parallelism = projectMessageDTO.getParallelism();
|
|
|
- int parallelismSum;
|
|
|
-
|
|
|
- Map<String, Integer> nodeMap = projectUtil.getNodeMapToUse(parallelism);
|
|
|
- if (CollectionUtil.isEmpty(nodeMap)) {
|
|
|
- parallelismSum = 0;
|
|
|
- } else {
|
|
|
- parallelismSum = nodeMap.keySet().stream().mapToInt(nodeMap::get).sum();
|
|
|
- }
|
|
|
+
|
|
|
+ int restParallelism = projectUtil.getRestParallelism();
|
|
|
|
|
|
- if (parallelismSum > 0L) {
|
|
|
- log.info("ProjectConsumer--run 集群 " + clusterId + " 将项目 " + projectId + "在节点 " + nodeMap + " 上执行!");
|
|
|
- projectMessageDTO.setCurrentParallelism(parallelismSum);
|
|
|
- parseProject(nodeMap, projectMessageDTO, projectWaitingKey, projectRunningKey);
|
|
|
+ if (restParallelism > 0L) {
|
|
|
+ log.info("ProjectConsumer--run 集群 " + clusterId + " 执行项目 " + projectId);
|
|
|
+
|
|
|
+ projectMessageDTO.setCurrentParallelism(Math.min(restParallelism, parallelism));
|
|
|
+ parseProject(projectMessageDTO, projectWaitingKey, projectRunningKey);
|
|
|
} else {
|
|
|
log.info("ProjectConsumer--cacheManualProject 服务器资源不够,项目 " + projectId + " 暂时加入等待队列。");
|
|
|
wait(projectWaitingKey, projectMessageDTO);
|
|
@@ -179,21 +168,21 @@ public class ProjectConsumer {
|
|
|
|
|
|
|
|
|
|
|
|
- * @param nodeMap 节点列表以及剩余可用并行度
|
|
|
* @param projectMessageDTO 初始接收到的项目启动信息
|
|
|
* @param projectWaitingKey projectWaitingKey
|
|
|
* @param projectRunningKey projectRunningKey
|
|
|
*/
|
|
|
@SneakyThrows
|
|
|
- public void parseProject(Map<String, Integer> nodeMap, ProjectMessageDTO projectMessageDTO, String projectWaitingKey, String projectRunningKey) {
|
|
|
+ public void parseProject(ProjectMessageDTO projectMessageDTO, String projectWaitingKey, String projectRunningKey) {
|
|
|
String projectId = projectMessageDTO.getProjectId();
|
|
|
String projectType = projectMessageDTO.getType();
|
|
|
+ int currentParallelism = projectMessageDTO.getCurrentParallelism();
|
|
|
String packageId = projectMessageDTO.getScenePackageId();
|
|
|
long videoTime = projectMessageDTO.getMaxSimulationTime();
|
|
|
String vehicleConfigId = projectMessageDTO.getVehicleConfigId();
|
|
|
String algorithmId = projectMessageDTO.getAlgorithmId();
|
|
|
|
|
|
- projectService.prepare(nodeMap, projectMessageDTO, projectWaitingKey, projectRunningKey);
|
|
|
+ projectService.prepare(projectMessageDTO, projectWaitingKey, projectRunningKey);
|
|
|
String userId = null;
|
|
|
if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
|
|
|
userId = manualProjectMapper.selectCreateUserById(projectId);
|
|
@@ -206,8 +195,25 @@ public class ProjectConsumer {
|
|
|
int taskTotal = scenePOList.size();
|
|
|
projectMessageDTO.setTaskTotal(taskTotal);
|
|
|
projectMessageDTO.setTaskCompleted(0);
|
|
|
-
|
|
|
+
|
|
|
+ Map<String, Integer> nodeMap;
|
|
|
+ if (currentParallelism < taskTotal) {
|
|
|
+ nodeMap = projectUtil.getNodeMapToUse(currentParallelism);
|
|
|
+ } else {
|
|
|
+ nodeMap = projectUtil.getNodeMapToUse(taskTotal);
|
|
|
+ }
|
|
|
+
|
|
|
+ nodeMap.keySet().forEach(nodeName -> {
|
|
|
+ int parallelismToUse = nodeMap.get(nodeName);
|
|
|
+ String restParallelismKey = "node:" + nodeName + ":parallelism";
|
|
|
+ int restParallelism = Integer.parseInt(Objects.requireNonNull(stringRedisTemplate.opsForValue().get(restParallelismKey)));
|
|
|
+ stringRedisTemplate.opsForValue().set(restParallelismKey, (restParallelism - parallelismToUse) + "");
|
|
|
+ });
|
|
|
+
|
|
|
+ projectMessageDTO.setCurrentParallelism(nodeMap.values().stream().mapToInt(parallelism -> parallelism).sum());
|
|
|
+ log.info("ProjectConsume--parseProject 项目 " + projectId + " 运行在:" + nodeMap);
|
|
|
stringRedisTemplate.opsForValue().set(projectRunningKey, JsonUtil.beanToJson(projectMessageDTO));
|
|
|
+
|
|
|
Set<ScenePO> scenePOSet = new HashSet<>(scenePOList);
|
|
|
|
|
|
|