|
@@ -1,7 +1,6 @@
|
|
|
package com.css.simulation.resource.scheduler.scheduler;
|
|
|
|
|
|
import api.common.pojo.constants.DictConstants;
|
|
|
-import api.common.util.CollectionUtil;
|
|
|
import api.common.util.SshUtil;
|
|
|
import api.common.util.StringUtil;
|
|
|
import api.common.util.TimeUtil;
|
|
@@ -59,7 +58,7 @@ public class ProjectScheduler {
|
|
|
* @throws IOException 超时时间
|
|
|
*/
|
|
|
@Scheduled(fixedDelay = 60 * 1000)
|
|
|
- public void timeout() throws IOException {
|
|
|
+ public void taskTimeout() throws IOException {
|
|
|
|
|
|
long timeout = 2 * 60 * 1000L;
|
|
|
|
|
@@ -67,9 +66,9 @@ public class ProjectScheduler {
|
|
|
ClientSession session = SshUtil.getSession(client, hostname, username, password);
|
|
|
List<TaskPO> executingTaskList = taskMapper.selectExecuting();
|
|
|
|
|
|
- log.info("ProjectScheduler--timeout 正在运行的任务有:" + executingTaskList);
|
|
|
- if (CollectionUtil.isEmpty(executingTaskList)) {
|
|
|
- executingTaskList.forEach(task -> {
|
|
|
+ log.info("ProjectScheduler--taskTimeout 正在运行的任务有:" + executingTaskList);
|
|
|
+ if (executingTaskList != null && executingTaskList.size() > 0) {
|
|
|
+ for (TaskPO task : executingTaskList) {
|
|
|
String taskId = task.getId();
|
|
|
String projectId = task.getPId();
|
|
|
long lastTickTime = Long.parseLong(Objects.requireNonNull(redisTemplate.opsForValue().get(manualProjectTopic + ":" + projectId + ":" + taskId + ":tick")));
|
|
@@ -77,8 +76,7 @@ public class ProjectScheduler {
|
|
|
String podName = redisTemplate.opsForValue().get(manualProjectTopic + ":" + projectId + ":" + taskId + ":pod");
|
|
|
taskService.taskState(taskId, DictConstants.TASK_ABORTED, podName);
|
|
|
}
|
|
|
- });
|
|
|
-
|
|
|
+ }
|
|
|
}
|
|
|
session.close();
|
|
|
client.stop();
|
|
@@ -89,13 +87,13 @@ public class ProjectScheduler {
|
|
|
* 检查如果有 job 在运行但是 pod 全部关闭的情况,此时需要重启一下 job
|
|
|
*/
|
|
|
@Scheduled(fixedDelay = 30 * 1000)
|
|
|
- public void checkProject() throws IOException {
|
|
|
+ public void projectCheck() throws IOException {
|
|
|
SshClient client = SshUtil.getClient();
|
|
|
ClientSession session = SshUtil.getSession(client, hostname, username, password);
|
|
|
|
|
|
//1 查询出正在运行中的 project
|
|
|
List<String> projectIdList = projectMapper.selectIdByState("20");
|
|
|
- log.info("ProjectScheduler-------checkProject 查询出正在运行中的 project" + projectIdList);
|
|
|
+ log.info("ProjectScheduler--projectCheck 查询出正在运行中的 project" + projectIdList);
|
|
|
//2 根据 projectId 获取 pod
|
|
|
projectIdList.forEach(projectId -> {
|
|
|
try {
|
|
@@ -103,7 +101,7 @@ public class ProjectScheduler {
|
|
|
String checkKey = manualProjectTopic + ":" + projectId + ":check";
|
|
|
String lastNowString = redisTemplate.opsForValue().get(checkKey);
|
|
|
String podList = SshUtil.execute(session, "kubectl get pod | grep project-" + projectId);
|
|
|
- log.info("ProjectScheduler-------checkProject 项目 " + projectId + " 正在运行的 pod 为:\n" + podList);
|
|
|
+ log.info("ProjectScheduler--projectCheck 项目 " + projectId + " 正在运行的 pod 为:\n" + podList);
|
|
|
int taskNumber = StringUtil.countSubString(podList, "project");
|
|
|
if (StringUtil.isEmpty(lastNowString) && taskNumber == 0) {
|
|
|
redisTemplate.opsForValue().set(checkKey, TimeUtil.getNowString());
|
|
@@ -119,16 +117,16 @@ public class ProjectScheduler {
|
|
|
SshUtil.execute(session, "kubectl delete job project-" + projectId);
|
|
|
Thread.sleep(15000);
|
|
|
while (true) {
|
|
|
- log.info("ProjectScheduler-------checkProject 准备重启项目 " + projectId);
|
|
|
+ log.info("ProjectScheduler--projectCheck 准备重启项目 " + projectId);
|
|
|
String podList2 = SshUtil.execute(session, "kubectl get pod | grep project-" + projectId);
|
|
|
- log.info("ProjectScheduler-------checkProject 项目 " + projectId + " 剩余的 pod 信息为:\n" + podList2);
|
|
|
+ log.info("ProjectScheduler--projectCheck 项目 " + projectId + " 剩余的 pod 信息为:\n" + podList2);
|
|
|
int taskNumber2 = StringUtil.countSubString(podList2, "project");
|
|
|
if (taskNumber2 == 0) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
Thread.sleep(15000);
|
|
|
- log.info("ProjectScheduler-------checkProject 重新执行项目" + projectId);
|
|
|
+ log.info("ProjectScheduler--projectCheck 重新执行项目" + projectId);
|
|
|
String jobTemplateYamlPathTarget = jobYaml + "project-" + projectId + ".yaml";
|
|
|
SshUtil.execute(session, "kubectl apply -f " + jobTemplateYamlPathTarget);
|
|
|
}
|