martin 3 年之前
父節點
當前提交
80510e40a7

文件差異過大導致無法顯示
+ 0 - 375
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/consumer/ManualProjectConsumerTest.java


+ 0 - 61
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/controller/KafkaController.java

@@ -1,61 +0,0 @@
-package com.css.simulation.resource.scheduler.controller;
-
-import api.common.pojo.dto.ProjectMessageDTO;
-import api.common.util.JsonUtil;
-import lombok.SneakyThrows;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.kafka.core.KafkaTemplate;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-@RequestMapping("/kafka")
-@RestController
-@Slf4j
-public class KafkaController {
-
-    @Autowired
-    KafkaTemplate<String, String> kafkaTemplate;
-
-
-
-    @PostMapping("/hello")
-    public void hello() {
-        kafkaTemplate.send("hello", "hello world!").addCallback(success -> {
-            // 消息发送到的topic
-            String topic = success.getRecordMetadata().topic();
-            // 消息发送到的分区
-            int partition = success.getRecordMetadata().partition();
-            // 消息在分区内的offset
-            long offset = success.getRecordMetadata().offset();
-            log.info("------- 发送消息成功:\n"
-                    + "主题 topic 为:" + topic + "\n"
-                    + "分区 partition 为:" + partition + "\n"
-                    + "偏移量为:" + offset);
-        }, failure -> {
-            log.error("------- 发送消息失败:" + failure.getMessage());
-        });
-    }
-
-
-    @PostMapping("/send")
-    @SneakyThrows
-    public void send(@RequestBody ProjectMessageDTO projectMessageDTO) {
-        kafkaTemplate.send(projectMessageDTO.getProjectId(), JsonUtil.beanToJson(projectMessageDTO)).addCallback(success -> {
-            // 消息发送到的topic
-            String topic = success.getRecordMetadata().topic();
-            // 消息发送到的分区
-            int partition = success.getRecordMetadata().partition();
-            // 消息在分区内的offset
-            long offset = success.getRecordMetadata().offset();
-            log.info("------- 发送消息成功:\n"
-                    + "主题 topic 为:" + topic + "\n"
-                    + "分区 partition 为:" + partition + "\n"
-                    + "偏移量为:" + offset);
-        }, failure -> {
-            log.error("------- 发送消息失败:" + failure.getMessage());
-        });
-    }
-}

+ 0 - 52
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/controller/MinioController.java

@@ -1,52 +0,0 @@
-package com.css.simulation.resource.scheduler.controller;
-
-import api.common.pojo.param.MinioParameter;
-import api.common.util.FileUtil;
-import com.css.simulation.resource.scheduler.util.MinioUtil;
-import io.minio.MinioClient;
-import io.minio.errors.*;
-import lombok.SneakyThrows;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.MediaType;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-
-@RequestMapping("/minio")
-@RestController
-@Slf4j
-public class MinioController {
-
-    @Autowired
-    MinioClient minioClient;
-
-    private static final String BUCKET_NAME = "test";
-
-
-    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
-    @SneakyThrows
-    public void upload(@RequestPart("file") MultipartFile file, String path) {
-        MinioUtil.uploadFromMultipartFile(minioClient, file, BUCKET_NAME, path);
-    }
-
-    @PostMapping("/download")
-    public void download(
-            @RequestBody @Validated MinioParameter minioParameter,
-            HttpServletResponse response
-    ) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
-        InputStream inputStream = MinioUtil.downloadToStream(
-                minioClient,
-                BUCKET_NAME,
-                minioParameter.getObjectName()
-        );
-        String fileName = FileUtil.getFileName(minioParameter.getObjectName());
-        FileUtil.downloadForHttp(fileName, inputStream, response, 4096);
-    }
-}

+ 7 - 26
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/controller/TaskController.java

@@ -1,7 +1,6 @@
 package com.css.simulation.resource.scheduler.controller;
 
 
-import api.common.util.IoUtil;
 import com.css.simulation.resource.scheduler.service.TaskService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
@@ -10,10 +9,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import javax.servlet.http.HttpServletResponse;
-import java.io.FileInputStream;
-import java.io.IOException;
-
 @RefreshScope
 @RestController
 @RequestMapping("/task")
@@ -22,20 +17,16 @@ public class TaskController {
     @Autowired
     TaskService taskService;
 
+    // -------------------------------- Comment --------------------------------
 
-    @RequestMapping("/download")
-    public void download(
-            @RequestParam("filePath") String filePath,
-            HttpServletResponse response
-    ) throws IOException {
-        FileInputStream inputStream = new FileInputStream(filePath);
-        IoUtil.copyBytes(inputStream, response.getOutputStream(), 4096);
+    /**
+     * 修改任务状态
+     */
+    @GetMapping("/state")
+    public void taskState(@RequestParam("taskId") String taskId, @RequestParam("state") String state, @RequestParam("podName") String podName) {
+        taskService.taskState(taskId, state, podName);
     }
 
-
-
-
-
     /**
      * Pod 的心跳接口
      */
@@ -44,16 +35,6 @@ public class TaskController {
         taskService.taskTick(taskId);
     }
 
-    /**
-     * 修改任务状态
-     */
-    @GetMapping("/state")
-    public void taskState(@RequestParam("taskId") String taskId, @RequestParam("state") String state, @RequestParam("podName") String podName) {
-        taskService.taskState(taskId, state, podName);
-    }
-
-
-
     /**
      * 任务执行前调用该接口,确定该任务没有被终止
      */

+ 6 - 11
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/controller/TestController.java

@@ -1,13 +1,8 @@
 package com.css.simulation.resource.scheduler.controller;
 
 
-import api.common.pojo.dto.ProjectMessageDTO;
-import com.css.simulation.resource.scheduler.consumer.ManualProjectConsumerTest;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -18,16 +13,16 @@ public class TestController {
 
     @Value("${hello}")
     String hello;
-    @Autowired
-    ManualProjectConsumerTest manualProjectConsumerTest;
+//    @Autowired
+//    ManualProjectConsumerTest manualProjectConsumerTest;
 
     @RequestMapping("/hello")
     public String hello() {
         return hello;
     }
 
-    @PostMapping("/message")
-    public void test(@RequestBody ProjectMessageDTO projectMessageDTO) {
-        manualProjectConsumerTest.parseManualProjectTest(projectMessageDTO);
-    }
+//    @PostMapping("/message")
+//    public void test(@RequestBody ProjectMessageDTO projectMessageDTO) {
+//        manualProjectConsumerTest.parseManualProjectTest(projectMessageDTO);
+//    }
 }

+ 7 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/IndexMapper.java

@@ -14,6 +14,13 @@ import java.util.List;
 @Mapper
 public interface IndexMapper {
 
+    @Delete("delete from simulation_mpt_last_target_score where p_id = #{projectId}")
+    void deleteLastTargetScoreByProjectId(@Param("projectId") String projectId);
+
+    @Delete("delete from simulation_mpt_first_target_score where p_id = #{projectId}")
+    void deleteFirstTargetScoreByProjectId(@Param("projectId") String projectId);
+
+
 
     @Insert("insert into simulation_mpt_last_target_score(id,\n" +
             "                                             p_id,\n" +

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

@@ -38,7 +38,7 @@ public interface TaskMapper {
             "where p_id = #{projectId}")
     List<TaskPO> selectTaskListByProjectId(@Param("projectId") String projectId);
 
-
+    @ResultMap("task")
     @Select("select p_id, create_user_id\n" +
             "from simulation_manual_project_task\n" +
             "where id = #{taskId}")
@@ -116,11 +116,6 @@ public interface TaskMapper {
             "where id = #{taskId}")
     String selectLastTargetIdById(@Param("taskId") String taskId);
 
-    @Update("update simulation_manual_project_task\n" +
-            "set run_state = #{runState}\n" +
-            "where p_id = #{projectId}")
-    void updateStateByProjectId(@Param("projectId") String projectId, @Param("runState") String runState);
-
     @Update("update simulation_manual_project_task\n" +
             "set run_state = #{runState}\n" +
             "where id = #{taskId}")

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

@@ -105,9 +105,9 @@ 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")));
+                long lastTickTime = Long.parseLong(Objects.requireNonNull(redisTemplate.opsForValue().get(manualProjectTopic + ":" + userId + ":" + projectId + ":task:" + taskId + ":tick")));
                 if (TimeUtil.getNow() - lastTickTime > timeout) {
-                    String podName = redisTemplate.opsForValue().get(manualProjectTopic+ ":" + userId + ":" + projectId + ":task:" + taskId + ":pod");
+                    String podName = redisTemplate.opsForValue().get(manualProjectTopic + ":" + userId + ":" + projectId + ":task:" + taskId + ":pod");
                     taskService.taskState(taskId, DictConstants.TASK_ABORTED, podName);
                 }
             }
@@ -133,7 +133,7 @@ public class ProjectScheduler {
             String projectId = project.getId();
             String userId = project.getCreateUserId();
             try {
-                String checkKey = manualProjectTopic+ ":" + userId + ":" + projectId + ":check";
+                String checkKey = manualProjectTopic + ":" + userId + ":" + projectId + ":check";
                 String lastNowString = redisTemplate.opsForValue().get(checkKey);
                 String podList = SshUtil.execute(session, "kubectl get pod | grep project-" + projectId);
                 log.info("ProjectScheduler--projectCheck 项目 " + projectId + " 正在运行的 pod 为:\n" + podList);

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

@@ -61,6 +61,8 @@ public class ManualProjectService {
     @Autowired
     IndexTemplateMapper indexTemplateMapper;
     @Autowired
+    IndexMapper indexMapper;
+    @Autowired
     SceneMapper sceneMapper;
     @Autowired
     AlgorithmMapper algorithmMapper;
@@ -77,7 +79,10 @@ public class ManualProjectService {
         stringRedisTemplate.opsForValue().set(manualProjectTopic + ":" + userId + ":" + projectId + ":completed", "0");
         stringRedisTemplate.opsForValue().set(manualProjectTopic + ":" + userId + ":" + projectId + ":start", projectJson);
         manualProjectMapper.updateInit(projectId, DictConstants.PROJECT_RUNNING);   // 修改该 project 的状态为执行中,同时将已完成任务重置为 0 。
-        taskMapper.deleteByProject(projectId); // 将该 project 下所有任务删除。
+        // 将该 project 下所有旧的任务和指标得分删除。
+        taskMapper.deleteByProject(projectId);
+        indexMapper.deleteFirstTargetScoreByProjectId(projectId);
+        indexMapper.deleteLastTargetScoreByProjectId(projectId);
     }
 
     @SneakyThrows

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

@@ -92,6 +92,8 @@ public class TaskService {
 
     @SneakyThrows
     public void taskState(String taskId, String state, String podName) {
+        log.info("TaskService--state 接收到参数为:taskId=" + taskId + ",state=" + state + ",podName=" + podName);
+
         TaskPO taskPO = taskMapper.selectById(taskId);
         String projectId = taskPO.getPId();
         String userId = taskPO.getCreateUserId();
@@ -168,11 +170,13 @@ public class TaskService {
         indexMapper.deleteFirstByProjectId(projectId);
         indexMapper.deleteLastByProjectId(projectId);
         //1 查询场景包对应指标
+        String allIndexTemplateListJson = stringRedisTemplate.opsForValue().get(manualProjectTopic + ":" + userId + ":" + projectId + ":package:" + packageId + ":all");
         List<IndexTemplatePO> allIndexTemplateList = JsonUtil.jsonToList(stringRedisTemplate.opsForValue().get(manualProjectTopic + ":" + userId + ":" + projectId + ":package:" + packageId + ":all"), IndexTemplatePO.class);
-        List<IndexTemplatePO> leafIndexTemplateList = JsonUtil.jsonToList(stringRedisTemplate.opsForValue().get(manualProjectTopic + ":" + userId + ":" + projectId + ":package:" + packageId + ":leaf"), IndexTemplatePO.class);
+        String leafIndexTemplateListJson = stringRedisTemplate.opsForValue().get(manualProjectTopic + ":" + userId + ":" + projectId + ":package:" + packageId + ":leaf");
+        List<IndexTemplatePO> leafIndexTemplateList = JsonUtil.jsonToList(leafIndexTemplateListJson, IndexTemplatePO.class);
+        log.info("TaskService--state 共有 " + leafIndexTemplateList.size() + "个叶子节点:" + leafIndexTemplateListJson);
         int maxLevel = 1; // 用于计算指标得分
         List<LeafIndexPO> leafIndexList = new ArrayList<>();
-        log.info("TaskService--state 共有 " + leafIndexTemplateList.size() + "个叶子节点!");
         for (int i = 0; i < leafIndexTemplateList.size(); i++) {
             AtomicReference<String> scoreExplain = new AtomicReference<>(); // 每个叶子指标下的任务的得分说明一样和叶子指标一致
             IndexTemplatePO leafIndexTemplate = leafIndexTemplateList.get(i);

部分文件因文件數量過多而無法顯示