martin преди 3 години
родител
ревизия
ecf63bbc29

+ 12 - 4
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/scheduler/TickScheduler.java

@@ -39,7 +39,10 @@ public class TickScheduler {
     String jobYaml;
 
     @Scheduled(fixedDelay = 60 * 1000)
-    public void tick() {
+    public void tick() throws IOException {
+
+        SshClient client = SshUtil.getClient();
+        ClientSession session = SshUtil.getSession(client, "182.92.203.182", "root", "CICV2022test");
 
         ArrayList<TaskPO> executingTaskList = taskMapper.selectExecuting();
         if (CollectionUtil.isEmpty(executingTaskList)) {
@@ -57,15 +60,20 @@ public class TickScheduler {
                 long difference = now - tickTime;
 //                log.info("------- TickScheduler 任务" + taskId + "心跳时间为:" + tickTime + "最大仿真时间为:" + tickTime + "时间差为:" + difference);
                 if (difference > timeout) {
-                    log.info("------- TickScheduler 任务" + taskId + "已超时,状态修改为:" + DictConstants.TASK_ABORTED);
                     String podName = redisTemplate.opsForValue().get("podName:" + taskId);
+                    String podDeleteCommand = "kubectl delete pod " + podName;
                     if (podName != null) {
-                        taskService.taskState(taskId, DictConstants.TASK_ABORTED, podName);
+                        log.info("TickScheduler--tick 修改任务 " + taskId + "已超时,状态修改为 Aborted,pod 名称为:" + podName + ",并执行删除 pod 命令:" + podDeleteCommand);
+                        SshUtil.execute(session, podDeleteCommand);
+//            taskManager.updateFailStateWithStopTime(taskId, state, TimeUtil.getNowForMysql()); // 如果任务 abort 代表项目失败
+                        taskMapper.updateFailStateWithStopTime(taskId, DictConstants.TASK_ABORTED, TimeUtil.getNowForMysql());
+                        redisTemplate.delete("podName:" + taskId);
                     }
                 }
             }
         }
-
+        session.close();
+        client.stop();
     }
 
 

+ 21 - 16
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/TaskService.java

@@ -122,22 +122,22 @@ public class TaskService {
             taskMapper.updateFailStateWithStopTime(taskId, state, TimeUtil.getNowForMysql());
             redisTemplate.delete("podName:" + taskId);
             //result-path-minio: /project/manual-project/
-            String projectId = taskMapper.selectProjectIdById(taskId);
-            String minioPathOfErrorLog = resultPathMinio + projectId + "/" + taskId + "error.log";
-            String errorString = MinioUtil.downloadToString(minioClient, bucketName, minioPathOfErrorLog);
-            String[] lines = errorString.split("\n");
-            AtomicReference<String> errorMessage = new AtomicReference<>("");
-            for (String line : lines) {
-                if (line.startsWith("Original Error")) {
-                    errorMessage.set(errorMessage.get() + line + "\n");
-                }
-
-                if (line.startsWith("Possible Cause")) {
-                    errorMessage.set(errorMessage.get() + line);
-                    break;
-                }
-            }
-            String errorMessageString = errorMessage.get();
+//            String projectId = taskMapper.selectProjectIdById(taskId);
+//            String minioPathOfErrorLog = resultPathMinio + projectId + "/" + taskId + "error.log";
+//            String errorString = MinioUtil.downloadToString(minioClient, bucketName, minioPathOfErrorLog);
+//            String[] lines = errorString.split("\n");
+//            AtomicReference<String> errorMessage = new AtomicReference<>("");
+//            for (String line : lines) {
+//                if (line.startsWith("Original Error")) {
+//                    errorMessage.set(errorMessage.get() + line + "\n");
+//                }
+//
+//                if (line.startsWith("Possible Cause")) {
+//                    errorMessage.set(errorMessage.get() + line);
+//                    break;
+//                }
+//            }
+//            String errorMessageString = errorMessage.get();
             return;
         } else if ("Terminated".equals(state)) {
             log.info("TaskService--state 修改任务 " + taskId + "的状态为 Terminated,pod 名称为:" + podName
@@ -157,6 +157,11 @@ public class TaskService {
             redisTemplate.delete("podName:" + taskId);
         }
         ProjectPO projectPO = projectMapper.selectById(taskId);
+        if (projectPO == null) {
+            session.close();
+            client.stop();
+            return;
+        }
         String projectId = projectPO.getId();
         Set<String> keys = redisTemplate.keys("manualProject:" + projectId + "*");
         assert keys != null;