martin 3 年 前
コミット
4b901fa513

+ 0 - 28
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/manager/TaskManager.java

@@ -1,28 +0,0 @@
-package com.css.simulation.resource.scheduler.manager;
-
-import api.common.pojo.constants.DictConstants;
-import com.css.simulation.resource.scheduler.mapper.TaskMapper;
-import org.apache.ibatis.session.ExecutorType;
-import org.apache.ibatis.session.SqlSession;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.sql.Timestamp;
-
-@Component
-public class TaskManager {
-
-    @Autowired
-    private SqlSessionFactory sqlSessionFactory;
-
-    public void updateFailStateWithStopTime(String taskId, String runState, Timestamp runStopTime) {
-
-        try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
-            TaskMapper taskMapper = sqlSession.getMapper(TaskMapper.class);
-            taskMapper.updateFailStateWithStopTime(taskId, runState, runStopTime,DictConstants.TASK_ERROR_REASON_2);
-            taskMapper.updateProjectStateByTaskId(DictConstants.PROJECT_TERMINATED, taskId);
-            sqlSession.commit();
-        }
-    }
-}

+ 2 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/IndexTemplateMapper.java

@@ -40,7 +40,8 @@ public interface IndexTemplateMapper {
             "       sps.package_and_rules,\n" +
             "       sr.rule_details\n" +
             "from scene_package_sublist sps left join scoring_rules sr on sps.package_and_rules = sr.rules_id\n" +
-            "where sps.root_id = #{packageId}")
+            "where sps.root_id = #{packageId}\n" +
+            "and sps.is_deleted = '0'")
     List<IndexTemplatePO> selectByPackageIdIncludeDeleted(@Param("packageId") String packageId);
 
 

+ 1 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/TaskMapper.java

@@ -24,7 +24,7 @@ public interface TaskMapper {
             @Result(column = "run_result_file_path", property = "runResultFilePath", jdbcType = JdbcType.VARCHAR),
             @Result(column = "max_simulation_time", property = "maxSimulationTime", jdbcType = JdbcType.VARCHAR),
             @Result(column = "last_targer_id", property = "lastTargetId", jdbcType = JdbcType.VARCHAR),
-            @Result(column = "create_user_id", property = "lastTargetId", jdbcType = JdbcType.VARCHAR)
+            @Result(column = "create_user_id", property = "createUserId", jdbcType = JdbcType.VARCHAR)
     })
     @Select("select id,\n" +
             "       p_id,\n" +

+ 6 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/scheduler/ProjectScheduler.java

@@ -22,7 +22,6 @@ import org.springframework.stereotype.Component;
 
 import java.io.IOException;
 import java.util.List;
-import java.util.Objects;
 
 @Component
 @Slf4j
@@ -105,7 +104,12 @@ public class ProjectScheduler {
                 String taskId = task.getId();
                 String projectId = task.getPId();
                 String userId = task.getCreateUserId();
-                long lastTickTime = Long.parseLong(Objects.requireNonNull(redisTemplate.opsForValue().get(manualProjectTopic + ":" + userId + ":" + projectId + ":task:" + taskId + ":tick")));
+                String tickTime = redisTemplate.opsForValue().get(manualProjectTopic + ":" + userId + ":" + projectId + ":task:" + taskId + ":tick");
+                if (StringUtil.isEmpty(tickTime)) {
+                    log.error(manualProjectTopic + ":" + userId + ":" + projectId + ":task:" + taskId + ":tick" + ",该 key 的心跳时间为空!");
+                    continue;
+                }
+                long lastTickTime = Long.parseLong(tickTime);
                 if (TimeUtil.getNow() - lastTickTime > timeout) {
                     String podName = redisTemplate.opsForValue().get(manualProjectTopic + ":" + userId + ":" + projectId + ":task:" + taskId + ":pod");
                     taskService.taskState(taskId, DictConstants.TASK_ABORTED, podName);

+ 1 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/ManualProjectService.java

@@ -89,7 +89,7 @@ public class ManualProjectService {
     @Transactional
     public List<ScenePO> handlePackage(String manualProjectTopic, String userId, String projectId, String packageId) {
 
-        //1 查询该场景包的所有指标列表存入 redis
+        //1 查询该场景包的所有指标列表存入 redis,包删了无所谓,但要过滤删掉的指标
         List<IndexTemplatePO> allIndexList = indexTemplateMapper.selectByPackageIdIncludeDeleted(packageId);
         stringRedisTemplate.opsForValue().set(manualProjectTopic + ":" + userId + ":" + projectId + ":package:" + packageId + ":all", JsonUtil.listToJson(allIndexList));
 

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

@@ -3,7 +3,6 @@ package com.css.simulation.resource.scheduler.service;
 import api.common.pojo.constants.DictConstants;
 import api.common.util.*;
 import com.css.simulation.resource.scheduler.manager.TaskIndexManager;
-import com.css.simulation.resource.scheduler.manager.TaskManager;
 import com.css.simulation.resource.scheduler.mapper.IndexMapper;
 import com.css.simulation.resource.scheduler.mapper.IndexTemplateMapper;
 import com.css.simulation.resource.scheduler.mapper.ManualProjectMapper;
@@ -57,8 +56,6 @@ public class TaskService {
     @Autowired
     TaskIndexManager taskIndexManager;
     @Autowired
-    TaskManager taskManager;
-    @Autowired
     IndexMapper indexMapper;
     @Autowired
     IndexTemplateMapper indexTemplateMapper;
@@ -102,6 +99,7 @@ public class TaskService {
         if ("Running".equals(state)) {
             // 将运行中的任务的 pod 名称放入 redis
             stringRedisTemplate.opsForValue().set(manualProjectTopic + ":" + userId + ":" + projectId + ":task:" + taskId + ":pod", podName);
+            taskTick(taskId); // 刷新一下心跳
             log.info("TaskService--state 修改任务 " + taskId + "的状态为 Running,pod 名称为:" + podName);
             taskMapper.updateStateWithStartTime(taskId, state, TimeUtil.getNowForMysql());
             return;
@@ -330,8 +328,10 @@ public class TaskService {
 
 
     public boolean retry(String userId, String projectId, String taskId) {
+        log.info("TaskService--retry 重试操作收到的参数为:userId=" + userId + ",projectId=" + projectId + ",taskId=" + taskId);
         //1 首先查看任务是否重试过 3 次
-        int retry = Integer.parseInt(Objects.requireNonNull(stringRedisTemplate.opsForValue().get(manualProjectTopic + ":" + userId + ":" + projectId + ":task:" + taskId + ":retry")));
+        String retryString = stringRedisTemplate.opsForValue().get(manualProjectTopic + ":" + userId + ":" + projectId + ":task:" + taskId + ":retry");
+        int retry = Integer.parseInt(Objects.requireNonNull(retryString));
         //2 如果重试次数没有超过 3 次,则重试
         if (retry > 3) {
             return false;

+ 12 - 34
simulation-resource-scheduler/src/test/java/com/css/simulation/resource/scheduler/SchedulerTest.java

@@ -52,40 +52,18 @@ public class SchedulerTest {
     public void compute() {
 
         /*
-LeafIndexPO(id=0a8cd6c061a24ed2bbb36a45b3a003d4,
-         pId=e8337795555541639659d773e28eafd5,
-          indexId=433838e404a74f87ba8f78c617134eec,
-           parentId=018ae110ca51413ba22268f36c125a03,
-            rootId=018ae110ca51413ba22268f36c125a03,
-             target=433838e404a74f87ba8f78c617134eec,
-              notStandardSceneNum=0, score=100.0, weight=40,
-               scoreExplain=1) 未发生碰撞>,得分 100;2) 发生碰撞,得分 0。),
-
-LeafIndexPO(id=24a53877c1b34b3bb61dc9d7e28035d2,
-                 pId=e8337795555541639659d773e28eafd5,
-                 indexId=a2a1866e5c7047c3bddc905971540043,
-                 parentId=148c7e1fb6474cdf8c106215f92b0d9d,
-                 rootId=018ae110ca51413ba22268f36c125a03,
-                 target=a2a1866e5c7047c3bddc905971540043,
-                 notStandardSceneNum=1,
-                 score=0.0,
-                  weight=70, scoreExplain=1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。),
-
-LeafIndexPO(id=94a9225873534e97be79b25c98861b83,
-      pId=e8337795555541639659d773e28eafd5,
-      indexId=df913a81a34742808cefc76829bfa398,
-       parentId=e28c9687cfdd4fec956d4c3a7fa061ec,
-        rootId=018ae110ca51413ba22268f36c125a03,
-         target=df913a81a34742808cefc76829bfa398,
-         notStandardSceneNum=0, score=100.0, weight=60, scoreExplain=1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。),
-
-LeafIndexPO(id=14d0017b489844bcb33118f7cfeee04c,
-         pId=e8337795555541639659d773e28eafd5,
-          indexId=eefbf9234bad410b801ed860b4add56f,
-           parentId=e28c9687cfdd4fec956d4c3a7fa061ec,
-            rootId=018ae110ca51413ba22268f36c125a03,
-            target=eefbf9234bad410b801ed860b4add56f,
-            notStandardSceneNum=1, score=0.0, weight=40, scoreExplain=1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。)]
+[LeafIndexPO(id=3783c4757af54a289c35d9a5da05d1aa, pId=0af13ea53152480fa692efb04e6b45ee, indexId=105df6a0d1de4bb7ba08d02338a64a67, parentId=4241063c9c3846a2982c6383df9e2661, rootId=d6fbf031543541ee8f688e68ce42796a, target=105df6a0d1de4bb7ba08d02338a64a67, notStandardSceneNum=0, score=0.0, weight=30, scoreExplain=null, packageLevel=4),
+LeafIndexPO(id=466eebd8a3c44441b401692f2ff68a4d, pId=0af13ea53152480fa692efb04e6b45ee, indexId=19cd6ea94c0e4ae5b79c65bb1d242b58, parentId=bc733db732e449c9858631e97331d49c, rootId=d6fbf031543541ee8f688e68ce42796a, target=19cd6ea94c0e4ae5b79c65bb1d242b58, notStandardSceneNum=0, score=100.0, weight=55, scoreExplain=1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。, packageLevel=5),
+LeafIndexPO(id=b07f85a2334e48dfb864032fb1cae94f, pId=0af13ea53152480fa692efb04e6b45ee, indexId=4a45b92909064f0c97a058262a4a8881, parentId=4c27f4e9318843a2911f054e8df6a39c, rootId=d6fbf031543541ee8f688e68ce42796a, target=4a45b92909064f0c97a058262a4a8881, notStandardSceneNum=0, score=100.0, weight=40, scoreExplain=1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。, packageLevel=3),
+LeafIndexPO(id=36a119d748b64f23b5bd7120e8e6e2d7, pId=0af13ea53152480fa692efb04e6b45ee, indexId=58a8c47500954c41b3c4ec8ffe553da4, parentId=1abb262bdd684645b757283c8641b406, rootId=d6fbf031543541ee8f688e68ce42796a, target=58a8c47500954c41b3c4ec8ffe553da4, notStandardSceneNum=0, score=0.0, weight=40, scoreExplain=null, packageLevel=3),
+LeafIndexPO(id=af4cc25bc998455eae6efdad6779534e, pId=0af13ea53152480fa692efb04e6b45ee, indexId=72ec17bcc5234cb3a5c623ed2cecf77a, parentId=0628958aa4584a41bdbcdc4e97afb151, rootId=d6fbf031543541ee8f688e68ce42796a, target=72ec17bcc5234cb3a5c623ed2cecf77a, notStandardSceneNum=0, score=0.0, weight=70, scoreExplain=null, packageLevel=2),
+LeafIndexPO(id=72066cb6d0b043159d0afdcb3eb18514, pId=0af13ea53152480fa692efb04e6b45ee, indexId=8bd982970a3843ffb40373b638d80b8f, parentId=d6fbf031543541ee8f688e68ce42796a, rootId=d6fbf031543541ee8f688e68ce42796a, target=8bd982970a3843ffb40373b638d80b8f, notStandardSceneNum=0, score=0.0, weight=40, scoreExplain=null, packageLevel=1),
+LeafIndexPO(id=bd1964e9701e4591a7c064b4ac1134bd, pId=0af13ea53152480fa692efb04e6b45ee, indexId=8f54b0ac76754ee6b1383236cee6a9da, parentId=bc733db732e449c9858631e97331d49c, rootId=d6fbf031543541ee8f688e68ce42796a, target=8f54b0ac76754ee6b1383236cee6a9da, notStandardSceneNum=2, score=0.0, weight=45, scoreExplain=1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。, packageLevel=5),
+LeafIndexPO(id=d53b2b01edb84683bfcf01f038f035d3, pId=0af13ea53152480fa692efb04e6b45ee, indexId=9afc65292007439ba3b7e8f11fa61417, parentId=4241063c9c3846a2982c6383df9e2661, rootId=d6fbf031543541ee8f688e68ce42796a, target=9afc65292007439ba3b7e8f11fa61417, notStandardSceneNum=0, score=0.0, weight=70, scoreExplain=null, packageLevel=4),
+LeafIndexPO(id=2b5eda8b6811479eb0c101118235a93f, pId=0af13ea53152480fa692efb04e6b45ee, indexId=9f4dea73c08e40fda5a50c445f22ed36, parentId=1f18b24d33424236bec09b8ced88be33, rootId=d6fbf031543541ee8f688e68ce42796a, target=9f4dea73c08e40fda5a50c445f22ed36, notStandardSceneNum=1, score=0.0, weight=70, scoreExplain=1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。, packageLevel=2),
+LeafIndexPO(id=b882d0b3aed84737ae176a52ab6bd761, pId=0af13ea53152480fa692efb04e6b45ee, indexId=be9814fedc0341ea9441f44f2fcd8757, parentId=d6fbf031543541ee8f688e68ce42796a, rootId=d6fbf031543541ee8f688e68ce42796a, target=be9814fedc0341ea9441f44f2fcd8757, notStandardSceneNum=0, score=100.0, weight=40, scoreExplain=1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。, packageLevel=1),
+ LeafIndexPO(id=2e2d91683b07428183012631ef60736f, pId=0af13ea53152480fa692efb04e6b45ee, indexId=f96f144f451a4dd298e0be9dfbeebf3a, parentId=40acb88fbe6344b6bbb34e697278968d, rootId=d6fbf031543541ee8f688e68ce42796a, target=f96f144f451a4dd298e0be9dfbeebf3a, notStandardSceneNum=1, score=50.0, weight=30, scoreExplain=1) 未发生碰撞,得分 100;
+2) 发生碰撞,得分 0。, packageLevel=4)]
          */