|
@@ -15,6 +15,7 @@ import com.css.simulation.resource.scheduler.pojo.po.UserPO;
|
|
|
import com.css.simulation.resource.scheduler.pojo.to.PrefixTO;
|
|
|
import com.css.simulation.resource.scheduler.service.TaskService;
|
|
|
import com.css.simulation.resource.scheduler.util.ProjectUtil;
|
|
|
+import com.css.simulation.resource.scheduler.util.RedisUtil;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -127,18 +128,18 @@ public class ProjectScheduler {
|
|
|
}
|
|
|
int simulationLicenseNumber = clusterPO.getNumSimulationLicense();
|
|
|
// 获取该用户正在运行的项目数量
|
|
|
- Set<String> clusterRunningKeySet = stringRedisTemplate.keys(redisPrefix.getClusterRunningPrefix() + "*");
|
|
|
- List<String> runningProjectSet = null;
|
|
|
+ Set<String> keySetOfAllProjectOfCluster = RedisUtil.getKeySetByPrefix(stringRedisTemplate, redisPrefix.getClusterRunningPrefix());
|
|
|
+ List<String> keyListOfRunningProject = null;
|
|
|
// cluster:${clusterId}:running:${projectId}
|
|
|
- if (CollectionUtil.isNotEmpty(clusterRunningKeySet)) {
|
|
|
- runningProjectSet = projectUtil.getRunningProjectList(clusterRunningKeySet);
|
|
|
- if (CollectionUtil.isNotEmpty(runningProjectSet)) {
|
|
|
- log.info("ProjectScheduler--dispatchProject 运行中的项目的 key 有:" + runningProjectSet);
|
|
|
+ if (CollectionUtil.isNotEmpty(keySetOfAllProjectOfCluster)) {
|
|
|
+ keyListOfRunningProject = projectUtil.getRunningProjectList(keySetOfAllProjectOfCluster); // 筛选出运行中的项目信息 (key 为 cluster:${cluster}:running:${projectId})
|
|
|
+ if (CollectionUtil.isNotEmpty(keyListOfRunningProject)) {
|
|
|
+ log.info("ProjectScheduler--dispatchProject 运行中的项目的 key 有:" + keyListOfRunningProject);
|
|
|
long parallelismSum = 0;
|
|
|
- for (String runningProjectKey : runningProjectSet) {
|
|
|
- parallelismSum += JsonUtil.jsonToBean(stringRedisTemplate.opsForValue().get(runningProjectKey), ProjectMessageDTO.class).getParallelism();
|
|
|
+ for (String keyOfRunningProject : keyListOfRunningProject) {
|
|
|
+ parallelismSum += JsonUtil.jsonToBean(RedisUtil.getStringByKey(stringRedisTemplate, keyOfRunningProject), ProjectMessageDTO.class).getParallelism();
|
|
|
}
|
|
|
- if (parallelismSum < simulationLicenseNumber) {
|
|
|
+ if (parallelismSum < simulationLicenseNumber) { // 已经运行的项目小于集群允许运行的项目则,运行新的项目
|
|
|
if (parallelismSum + parallelism < simulationLicenseNumber) {
|
|
|
run(clusterId, projectId, redisPrefix.getProjectWaitingKey(), redisPrefix.getProjectRunningKey(), parallelism);
|
|
|
return;
|
|
@@ -146,7 +147,7 @@ public class ProjectScheduler {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if ((CollectionUtil.isEmpty(clusterRunningKeySet) || CollectionUtil.isEmpty(runningProjectSet)) && parallelism < simulationLicenseNumber) {
|
|
|
+ if ((CollectionUtil.isEmpty(keySetOfAllProjectOfCluster) || CollectionUtil.isEmpty(keyListOfRunningProject)) && parallelism < simulationLicenseNumber) {
|
|
|
run(clusterId, projectId, redisPrefix.getProjectWaitingKey(), redisPrefix.getProjectRunningKey(), parallelism);
|
|
|
}
|
|
|
}
|
|
@@ -157,7 +158,7 @@ public class ProjectScheduler {
|
|
|
public void run(String clusterId, String projectId, String projectWaitingKey, String projectRunningKey, int parallelism) {
|
|
|
ProjectMessageDTO projectMessageDTO;
|
|
|
try {
|
|
|
- projectMessageDTO = JsonUtil.jsonToBean(stringRedisTemplate.opsForValue().get(projectWaitingKey), ProjectMessageDTO.class);
|
|
|
+ projectMessageDTO = JsonUtil.jsonToBean(RedisUtil.getStringByKey(stringRedisTemplate, projectWaitingKey), ProjectMessageDTO.class);
|
|
|
} catch (Exception e) {
|
|
|
log.error("ProjectScheduler--run 等待执行的项目信息已经从 redis 删除。");
|
|
|
return;
|
|
@@ -175,7 +176,7 @@ public class ProjectScheduler {
|
|
|
if (parallelismSum > 0L) {
|
|
|
log.info("ProjectScheduler--run 集群 " + clusterId + " 将项目 " + projectId + "在节点 " + nodeMap + " 上执行。");
|
|
|
projectMessageDTO.setCurrentParallelism(parallelismSum); // 设置实际的并行度
|
|
|
- projectConsumer.parseProject(nodeMap, projectMessageDTO, "cluster:" + clusterId, projectRunningKey);
|
|
|
+ projectConsumer.parseProject(nodeMap, projectMessageDTO, projectWaitingKey, projectRunningKey);
|
|
|
}
|
|
|
}
|
|
|
|