root 2 жил өмнө
parent
commit
80dcd24f77

+ 4 - 5
api-common/src/main/java/api/common/util/FileUtil.java

@@ -330,7 +330,6 @@ public class FileUtil {
     }
 
 
-
     /**
      * 创建父目录
      */
@@ -711,10 +710,10 @@ public class FileUtil {
      * 获取所有同一类型的文件列表。
      *
      * @param rootPath 文件 File 路径。
-     * @param type   文件类型不带点,如 txt。
+     * @param type     文件类型不带点,如 txt。
      */
     @SneakyThrows
-    public static List<String> listAbsolutePathByType(String rootPath, String type) {
+    public static List<String> listAbsolutePathByTypeAndLength(String rootPath, String type, int length) {
         List<String> result = new LinkedList<>();
         File rootFile = new File(rootPath);
         //1 判断文件是否存在
@@ -722,7 +721,7 @@ public class FileUtil {
             throw new RuntimeException("FileUtil.listAbsolutePathByType() 文件 " + rootPath + " 不存在!");
         }
         //2 判断是否是文件
-        if (rootFile.isFile() && rootFile.getName().endsWith(type)) {
+        if (rootFile.isFile() && rootFile.getName().endsWith(type) && rootFile.getName().length() == length) {
             return new ArrayList<>(Collections.singletonList(rootPath));
         }
         //3 判断是否是目录
@@ -730,7 +729,7 @@ public class FileUtil {
             File[] children = rootFile.listFiles();
             if (children != null) {
                 for (File child : children) {
-                    result.addAll(listAbsolutePathByType(child.getAbsolutePath(), type));
+                    result.addAll(listAbsolutePathByTypeAndLength(child.getAbsolutePath(), type, length));
                 }
             }
         }

+ 3 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/consumer/ProjectConsumer.java

@@ -374,8 +374,10 @@ public class ProjectConsumer {
         // -------------------------------- 0 准备 --------------------------------
 //        projectService.prepare(projectMessageDTO, projectWaitingKey, projectRunningKey);
         // -------------------------------- 1 获取任务 json 列表 --------------------------------
-        List<String> taskJsonList = FileUtil.listAbsolutePathByType(projectPath, "json");
+        List<String> taskJsonList = FileUtil.listAbsolutePathByTypeAndLength(projectPath, "json", 37);
         int taskTotal = taskJsonList.size();
+        projectMessageDTO.setTaskTotal(taskTotal);
+        projectMessageDTO.setTaskCompleted(0);
 
         // 设置任务数量之后,获取运行节点,并将项目运行信息放入 redis
         Map<String, Integer> nodeMap;

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

@@ -97,7 +97,7 @@ public class TaskManager {
     private SqlSessionFactory sqlSessionFactory;
 
     public void batchInsertTask(List<TaskPO> taskPOList) {
-        try(SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false)){
+        try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
             TaskMapper taskMapper1 = sqlSession.getMapper(TaskMapper.class);
             for (TaskPO taskPO : taskPOList) {
                 taskMapper1.insert(taskPO);
@@ -215,12 +215,12 @@ public class TaskManager {
         //1 查询场景包对应指标
 //        String allIndexTemplateListJson = stringRedisTemplate.opsForValue().get(redisPrefix.getProjectRunningKey() + ":package:" + packageId + ":all");
         List<IndexTemplatePO> allIndexTemplateList = JsonUtil.jsonToList(
-                FileUtil.read(linuxTempPath + "project/all-index-list.json"), IndexTemplatePO.class);
+                FileUtil.read(linuxTempPath + "project/" + projectId + "/all-index-list.json"), IndexTemplatePO.class);
         String leafIndexTemplateListJson = stringRedisTemplate.opsForValue()
                 .get(redisPrefix.getProjectRunningKey() + ":package:" + packageId + ":leaf");
 //        List<IndexTemplatePO> leafIndexTemplateList = JsonUtil.jsonToList(leafIndexTemplateListJson, IndexTemplatePO.class);
         List<IndexTemplatePO> leafIndexTemplateList = JsonUtil.jsonToList(
-                FileUtil.read(linuxTempPath + "project/leaf-index-list.json"), IndexTemplatePO.class);
+                FileUtil.read(linuxTempPath + "project/" + projectId + "/leaf-index-list.json"), IndexTemplatePO.class);
         log.info("TaskManager--score 共有 " + leafIndexTemplateList.size() + "个叶子节点:" + leafIndexTemplateListJson);
         int maxLevel = 1; // 用于计算指标得分
         List<LeafIndexPO> leafIndexList = new ArrayList<>();

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

@@ -552,6 +552,9 @@ public class ProjectService {
     @SneakyThrows
     public void stopProject(String projectId, String projectType) {
 
+        //7 删除 kafka 消息
+        ApacheKafkaUtil.deleteTopic(kafkaAdminClient, projectId);
+
         //1 删除项目所有任务
         taskMapper.deleteByProject(projectId);
 
@@ -580,6 +583,9 @@ public class ProjectService {
 
         //6 删除 minio 残留文件
         MinioUtil.rmR(minioClient, bucketName, projectResultPathOfMinio + projectId + "/");
+
+
+        log.info("ProjectService.stopProject() 项目 " + projectId + " 终止成功!");
     }
 
 

+ 12 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/util/ApacheKafkaUtil.java

@@ -9,6 +9,7 @@ import org.apache.kafka.clients.producer.KafkaProducer;
 import org.apache.kafka.clients.producer.ProducerRecord;
 import org.apache.kafka.clients.producer.RecordMetadata;
 
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.concurrent.Future;
 
@@ -31,6 +32,17 @@ public class ApacheKafkaUtil {
         log.info("ApacheKafkaUtil--createTopic 创建主题 " + name + ",分区数为:" + numPartitions + ",副本数为:" + replicationFactor);
     }
 
+    /**
+     * 删除主题
+     *
+     * @param admin  管理员对象
+     * @param topics 需要删除的所有主题序列
+     */
+    public static void deleteTopic(Admin admin, String... topics) {
+        admin.deleteTopics(Arrays.asList(topics));
+        log.info("ApacheKafkaUtil.deleteTopic() 删除主题:" + Arrays.toString(topics));
+    }
+
 
     //* -------------------------------- Producer --------------------------------