|
@@ -1,9 +1,14 @@
|
|
|
package com.css.simulation.resource.scheduler.scheduler;
|
|
|
|
|
|
+import api.common.pojo.constants.DictConstants;
|
|
|
import api.common.util.CollectionUtil;
|
|
|
import com.css.simulation.resource.scheduler.configuration.kubernetes.KubernetesConfiguration;
|
|
|
+import com.css.simulation.resource.scheduler.mapper.AutoSubProjectMapper;
|
|
|
+import com.css.simulation.resource.scheduler.mapper.ManualProjectMapper;
|
|
|
+import com.css.simulation.resource.scheduler.pojo.po.ProjectPO;
|
|
|
import com.css.simulation.resource.scheduler.pojo.to.KubernetesNodeTO;
|
|
|
import com.css.simulation.resource.scheduler.util.KubernetesUtil;
|
|
|
+import com.css.simulation.resource.scheduler.util.RedisUtil;
|
|
|
import io.kubernetes.client.openapi.ApiClient;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -25,7 +30,10 @@ public class ClusterScheduler {
|
|
|
ApiClient apiClient;
|
|
|
@Resource
|
|
|
StringRedisTemplate stringRedisTemplate;
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ ManualProjectMapper manualProjectMapper;
|
|
|
+ @Resource
|
|
|
+ AutoSubProjectMapper autoSubProjectMapper;
|
|
|
|
|
|
/**
|
|
|
* 闲时重置所有并行度
|
|
@@ -42,4 +50,20 @@ public class ClusterScheduler {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 闲时删除 cluster 所有遗留数据
|
|
|
+ */
|
|
|
+ @Scheduled(fixedDelay = 2 * 60 * 1000)
|
|
|
+ @SneakyThrows
|
|
|
+ public void removeCluster() {
|
|
|
+ //1 查询是否有正在运行的项目
|
|
|
+ List<ProjectPO> manual = manualProjectMapper.selectByNowRunState(DictConstants.PROJECT_RUNNING);
|
|
|
+ List<ProjectPO> autoSub = autoSubProjectMapper.selectByNowRunState(DictConstants.PROJECT_RUNNING);
|
|
|
+
|
|
|
+ //2 如果没有正在运行的项目,则删除redis
|
|
|
+ if (CollectionUtil.isEmpty(manual) && CollectionUtil.isEmpty(autoSub)) {
|
|
|
+ RedisUtil.deleteByPrefix(stringRedisTemplate, "cluster:");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|