root 2 سال پیش
والد
کامیت
aefb568f80

+ 3 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/common/util/ProjectUtil.java

@@ -109,7 +109,6 @@ public class ProjectUtil {
             String key = "pod:" + podName + ":node";
             // 先删除 redis key
             RedisUtil.deleteByKey(stringRedisTemplate, "pod:" + podName + ":node");
-            RedisUtil.deleteByKey(stringRedisTemplate, "pod:" + podName + ":cpu");
             KubernetesUtil.deletePod(apiClient, kubernetesConfiguration.getNamespace(), podName);
 
             log.info("deletePod() 等待 pod " + podName + " 的资源释放完成。");
@@ -176,7 +175,9 @@ public class ProjectUtil {
     @SneakyThrows
     public void createNextPod3(String projectId, String nodeName, String lastPodName) {
         //1 删除上一个 pod 和 redis 键值对 和 旧的 yaml 文件
+        String cpuOrderString = stringRedisTemplate.opsForValue().get("pod:" + lastPodName + ":cpu");
         deletePod(lastPodName);
+        RedisUtil.deleteByKey(stringRedisTemplate, "pod:" + lastPodName + ":cpu");
         //2 获取新的 yaml 信息
         final Set<String> yamlPathCacheKeySet = RedisUtil.getKeySetByPrefix(stringRedisTemplate, "project:" + projectId + ":node:" + nodeName + ":yaml");
         if (CollectionUtil.isEmpty(yamlPathCacheKeySet)) {
@@ -187,7 +188,7 @@ public class ProjectUtil {
             final String yamlPathCacheKey = new ArrayList<>(yamlPathCacheKeySet).get(0);
             final String absolutePath = stringRedisTemplate.opsForValue().get(yamlPathCacheKey);
             // 修改 cpu 编号
-            String cpuOrderString = stringRedisTemplate.opsForValue().get("pod:" + lastPodName + ":cpu");
+
             Optional.ofNullable(cpuOrderString).orElseThrow(() -> new RuntimeException("createNextPod2() pod " + lastPodName + " 缓存的 cpu 编号为空。"));
             final String read = FileUtil.read(absolutePath);
             final String replace = read.replace("cpu-order", "\"" + cpuOrderString + "\"");

+ 1 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/dao/manager/TaskManager.java

@@ -114,7 +114,7 @@ public class TaskManager {
             // 将运行中的任务的 pod 名称放入 redis
             stringRedisTemplate.opsForValue().set(redisPrefix.getTaskPodKey(), podName);
             taskTick(taskId); // 刷新一下心跳
-            log.info("TaskManager--state 修改任务 " + taskId + " 的状态为 " + state + ",pod 名称为:" + podName);
+            log.info("state() 修改任务 " + taskId + " 的状态为 " + state + ",pod 名称为:" + podName);
             taskMapper.updateStateWithStartTime(taskId, state, TimeUtil.getNowForMysql());
             return false;
         } else { // 结束的 pod 都直接删除,并判断项目是否完成

+ 2 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/ProjectService.java

@@ -307,7 +307,7 @@ public class ProjectService {
         taskMapper.deleteByProject(projectId);
 
         //4 根据 pod 前缀删除所有 pod
-        if (isRunning){
+        if (isRunning) {
             String podPrefix = "project-" + projectId;
             Set<String> nodeOfPodKeySet = RedisUtil.getKeySetByPrefix(stringRedisTemplate, "pod:" + podPrefix);
             for (String nodeOfPodKey : nodeOfPodKeySet) {
@@ -321,7 +321,7 @@ public class ProjectService {
         }
 
         //5 其他 redis key
-        RedisUtil.deleteByPrefix(stringRedisTemplate, "project:" + projectId + ":package:");
+        RedisUtil.deleteByPrefix(stringRedisTemplate, "project:" + projectId);
         RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getProjectRunningKey());
         RedisUtil.deleteByPrefix(stringRedisTemplate, redisPrefix.getProjectWaitingKey());