瀏覽代碼

标准化测试

LingxinMeng 2 年之前
父節點
當前提交
4539ed657c

+ 2 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/application/service/ProjectService.java

@@ -489,14 +489,14 @@ public class ProjectService {
             String taskJson = FileUtil.read(taskJsonPath);
             stringRedisTemplate.opsForValue().set(taskMessageKey, taskJson);
 
-            //4-5 将 projectId 作为 topic 名称,根据 parallelism 分散发送 task 信息到 kafka
+            // 将 projectId 作为 topic 名称,根据 parallelism 分散发送 task 信息到 kafka
             SendResult<String, String> stringStringSendResult = kafkaTemplate.send(projectId, messageNumber % finalParallelism, taskId, taskJson).get();
             RecordMetadata recordMetadata = stringStringSendResult.getRecordMetadata();
             String topic = recordMetadata.topic();  // 消息发送到的topic
             int partition = recordMetadata.partition(); // 消息发送到的分区
             long offset = recordMetadata.offset();  // 消息在分区内的offset
             log.info("发送消息成功, 主题 topic 为项目ID:" + topic + " 分区 partition 为:" + partition + " 偏移量为:" + offset);
-            //4-6 发送成功过的同时创建 pod.yaml 文件并把文件地址存到 redis
+            // 发送成功过的同时创建 pod.yaml 文件并把文件地址存到 redis
             // 选一个 count 最少的 node
             String currentNodeName = "";
             NodeEntity currentNodeEntity = null;

+ 13 - 4
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/domain/service/ProjectDomainService.java

@@ -734,7 +734,7 @@ public class ProjectDomainService {
         Map<String, String> params = new HashMap<>();
         params.put("projectType", projectType);
         params.put("id", projectId);
-        String result = HttpUtil.post( customConfiguration.getProjectDetailsUri(), headers, params);
+        String result = HttpUtil.post(customConfiguration.getProjectDetailsUri(), headers, params);
         log.info("访问仿真云平台项目详情接口:" + customConfiguration.getProjectDetailsUri() + ",请求头为:" + headers + ",请求体为:" + params + "结果为:" + result);
         ResponseBodyVO<?> responseBodyVO = JsonUtil.jsonToBean(result, ResponseBodyVO.class);
         String projectDetailsVOJson = JsonUtil.beanToJson(responseBodyVO.getInfo());
@@ -763,7 +763,7 @@ public class ProjectDomainService {
         Map<String, String> params = new HashMap<>();
         params.put("projectType", projectType);
         params.put("id", projectId);
-        String result = HttpUtil.post( customConfiguration.getProjectReportUri(), headers, params);
+        String result = HttpUtil.post(customConfiguration.getProjectReportUri(), headers, params);
         log.info("访问仿真云平台项目报告接口:" + customConfiguration.getProjectReportUri() + ",请求头为:" + headers + ",请求体为:" + params + "结果为:" + result);
         ResponseBodyVO<?> responseBodyVO = JsonUtil.jsonToBean(result, ResponseBodyVO.class);
         String projectReportVOJson = JsonUtil.beanToJson(responseBodyVO.getInfo());
@@ -780,13 +780,22 @@ public class ProjectDomainService {
     public List<ProjectWaitQueueEntity> getWaitQueue() {
         try {
             final String waitQueueJson = customRedisClient.get(DictConstants.PROJECT_WAIT_QUEUE_KEY);
-            if (StringUtil.isNotEmpty(waitQueueJson)){
+            if (StringUtil.isNotEmpty(waitQueueJson)) {
                 return JsonUtil.jsonToList(waitQueueJson, ProjectWaitQueueEntity.class);
-            }else{
+            } else {
                 return null;
             }
         } catch (JsonProcessingException e) {
             throw new RuntimeException(e);
         }
     }
+
+    public void setWaitQueue(List<ProjectWaitQueueEntity> projectWaitQueueEntities) {
+        try {
+            String projectWaitQueueEntitiesJson = JsonUtil.listToJson(projectWaitQueueEntities);
+            customRedisClient.set(DictConstants.PROJECT_WAIT_QUEUE_KEY, projectWaitQueueEntitiesJson);
+        } catch (JsonProcessingException e) {
+            throw new RuntimeException(e);
+        }
+    }
 }

+ 1 - 3
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/infrastructure/entity/ProjectEntity.java

@@ -10,14 +10,12 @@ import lombok.NoArgsConstructor;
 @NoArgsConstructor
 @AllArgsConstructor
 public class ProjectEntity {
-
     private String id;
     private String scenePackageId;
     private String createUserId;
     private String parallelism;
+    private String nowRunState;
     private String projectType;
     private String maxSimulationTime;
     private String isChoiceGpu;
-
-
 }

+ 3 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/infrastructure/persistence/mysql/mapper/AutoSubProjectMapper.java

@@ -16,6 +16,7 @@ public interface AutoSubProjectMapper {
             @Result(column = "scene", property = "scenePackageId", jdbcType = JdbcType.VARCHAR),
             @Result(column = "create_user_id", property = "createUserId", jdbcType = JdbcType.VARCHAR),
             @Result(column = "parallelism", property = "parallelism", jdbcType = JdbcType.VARCHAR),
+            @Result(column = "now_run_state", property = "nowRunState", jdbcType = JdbcType.VARCHAR),
             @Result(column = "project_type", property = "projectType", jdbcType = JdbcType.VARCHAR),
             @Result(column = "is_choice_gpu", property = "isChoiceGpu", jdbcType = JdbcType.VARCHAR),
             @Result(column = "max_simulation_time", property = "maxSimulationTime", jdbcType = JdbcType.VARCHAR)
@@ -23,6 +24,8 @@ public interface AutoSubProjectMapper {
     @Select("select sas.id,\n" +
             "       sap.scene,\n" +
             "       sas.create_user_id,\n" +
+            "       sas.parallelism,\n" +
+            "       sas.now_run_state,\n" +
             "       '2' project_type,\n" +
             "       sap.is_choice_gpu,\n" +
             "       sap.max_simulation_time\n" +

+ 2 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/infrastructure/persistence/mysql/mapper/ManualProjectMapper.java

@@ -16,6 +16,7 @@ public interface ManualProjectMapper {
             @Result(column = "scene", property = "scenePackageId", jdbcType = JdbcType.VARCHAR),
             @Result(column = "create_user_id", property = "createUserId", jdbcType = JdbcType.VARCHAR),
             @Result(column = "parallelism", property = "parallelism", jdbcType = JdbcType.VARCHAR),
+            @Result(column = "now_run_state", property = "nowRunState", jdbcType = JdbcType.VARCHAR),
             @Result(column = "project_type", property = "projectType", jdbcType = JdbcType.VARCHAR),
             @Result(column = "is_choice_gpu", property = "isChoiceGpu", jdbcType = JdbcType.VARCHAR),
             @Result(column = "max_simulation_time", property = "maxSimulationTime", jdbcType = JdbcType.VARCHAR)
@@ -24,6 +25,7 @@ public interface ManualProjectMapper {
             "       scene,\n" +
             "       create_user_id,\n" +
             "       parallelism,\n" +
+            "       now_run_state,\n" +
             "       is_choice_gpu,\n" +
             "       '1' project_type,\n" +
             "       max_simulation_time\n" +

+ 17 - 7
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/infrastructure/scheduler/ProjectScheduler.java

@@ -6,11 +6,13 @@ import com.css.simulation.resource.scheduler.api.model.ProjectMessageModel;
 import com.css.simulation.resource.scheduler.application.entity.ProjectWaitQueueEntity;
 import com.css.simulation.resource.scheduler.application.service.ProjectService;
 import com.css.simulation.resource.scheduler.domain.service.ProjectDomainService;
+import com.css.simulation.resource.scheduler.infrastructure.entity.ProjectEntity;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.util.Collection;
 import java.util.List;
 
 @Component
@@ -24,17 +26,25 @@ public class ProjectScheduler {
     /**
      * 调度项目启动
      */
-    @Scheduled(fixedDelay = 5000)
+    @Scheduled(fixedDelay = 10000)
     public void dispatchProject() {
-
         List<ProjectWaitQueueEntity> projectWaitQueue = projectDomainService.getWaitQueue();
         if (CollectionUtil.isNotEmpty(projectWaitQueue)) {
-            log.info("尝试启动等待中的项目:{}", projectWaitQueue);
-            for (ProjectWaitQueueEntity projectWaitQueueEntity : projectWaitQueue) {
-                final String waitingType = projectWaitQueueEntity.getWaitingType();
+            ProjectWaitQueueEntity projectWaitQueueEntity = projectWaitQueue.get(0);
+            String waitingType = projectWaitQueueEntity.getWaitingType();
+            if (DictConstants.PROJECT_WAIT_TYPE_EXECUTE.equals(waitingType)) {
+                log.info("尝试启动等待中的项目:{}", projectWaitQueueEntity);
                 final ProjectMessageModel projectMessageModel = projectWaitQueueEntity.getProjectMessageModel();
-                if (DictConstants.PROJECT_WAIT_TYPE_EXECUTE.equals(waitingType)) {
-                    projectService.checkIfCanRun(projectMessageModel);
+                projectService.checkIfCanRun(projectMessageModel);
+            } else if (DictConstants.PROJECT_WAIT_TYPE_EXPAND.equals(waitingType)) {
+                log.info("尝试扩充运行中的项目:{}", projectWaitQueueEntity);
+                ProjectMessageModel projectMessageModel = projectWaitQueueEntity.getProjectMessageModel();
+                String projectId = projectMessageModel.getProjectId();
+                ProjectEntity project = projectDomainService.getProjectByProjectId(projectId);
+                if (DictConstants.PROJECT_COMPLETED.equals(project.getNowRunState())) {
+                    log.info("等待扩充的项目" + projectWaitQueueEntity + "已运行完成,无需扩充。");
+                    projectWaitQueue.remove(0);
+                    projectDomainService.setWaitQueue(projectWaitQueue);
                 }
             }
         }