Prechádzať zdrojové kódy

下载算法平台文件

LingxinMeng 1 rok pred
rodič
commit
8ef75631c7

+ 3 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/app/service/ProjectApplicationService.java

@@ -487,8 +487,8 @@ public class ProjectApplicationService {
             projectDomainService.useLicense(clusterUserId, modelType, finalParallelism);
         }
         String projectId = projectMessageModel.getProjectId();    // 项目 id
+        final String projectType = projectMessageModel.getType();
         String vehicleConfigId = projectMessageModel.getVehicleConfigId();
-        String algorithmId = projectMessageModel.getAlgorithmId();    // 算法 id
         String projectPath = linuxTempPath + "project/" + projectId + "/";
         // -------------------------------- 1 获取任务 json 列表 --------------------------------
         List<String> taskJsonList = FileUtil.listAbsolutePathByTypeAndLength(projectPath, "json", (StringUtil.getRandomUUID() + ".json").length());
@@ -503,7 +503,7 @@ public class ProjectApplicationService {
         log.info("项目 " + projectId + " 运行在:" + nodeMap);
         stringRedisTemplate.opsForValue().set(projectRunningKey, JsonUtil.beanToJson(projectMessageModel));
         //* -------------------------------- 3 根据算法id查询算法名称 --------------------------------
-        String algorithmDockerImage = algorithmMapper.selectDockerImageById(algorithmId);
+        String algorithmDockerImage = projectDomainService.getAlgorithmDockerImageByProjectTypeAndProjectId(projectType, projectId);
         // -------------------------------- 4 发送任务消息 --------------------------------
         List<NodeEntity> nodeListToCount = projectDomainService.getNodeListToCount(nodeMap);
         int messageNumber = 0;
@@ -760,6 +760,7 @@ public class ProjectApplicationService {
                 OsUtil.exec("docker push " + dockerImage);
 //                FileUtil.rm(algorithmTarLinuxTempPath);
 //                log.info("已删除算法临时文件:" + algorithmTarLinuxTempPath);
+                algorithmExpandMapper.updateDockerImportAndDockerImageById(dockerImage, algorithmId);
                 algorithmExpandMapper.updateStatusByAlgorithmId(AlgorithmExpandEntity.builder().algorithmId(algorithmId).status(DictConstants.ALGORITHM_EXPAND_STATUS_TESTING).build());
             } else {
                 log.info("算法镜像" + dockerImageWithoutVersion + "已导入。");

+ 26 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/domain/service/ProjectDomainService.java

@@ -82,6 +82,8 @@ public class ProjectDomainService {
     @Resource
     private ApiClient apiClient;
     @Resource
+    private AlgorithmMapper algorithmMapper;
+    @Resource
     private AlgorithmExpandMapper algorithmExpandMapper;
 
 
@@ -956,10 +958,11 @@ public class ProjectDomainService {
 
     /**
      * 如果是算法平台算法则修改状态
+     *
      * @param projectType
      * @param projectId
      */
-    public void checkAlgorithmIsExpand(String projectType, String projectId,String algorithmStatus) {
+    public void checkAlgorithmIsExpand(String projectType, String projectId, String algorithmStatus) {
         String algorithmType;
         String algorithmId;
         if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
@@ -972,8 +975,29 @@ public class ProjectDomainService {
         } else {
             throw new RuntimeException("未知项目类型:" + projectType);
         }
-        if(DictConstants.ALGORITHM_UPLOAD_MODE_PLATFORM.equals(algorithmType)) {
+        if (DictConstants.ALGORITHM_UPLOAD_MODE_PLATFORM.equals(algorithmType)) {
             algorithmExpandMapper.updateStatusByAlgorithmId(AlgorithmExpandEntity.builder().algorithmId(algorithmId).status(algorithmStatus).build());
         }
     }
+
+
+    public String getAlgorithmDockerImageByProjectTypeAndProjectId(String projectType, String projectId) {
+        String algorithmType;
+        String algorithmId;
+        if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
+            algorithmType = simulationManualProjectMapper.selectAlgorithmTypeById(SimulationManualProjectEntity.builder().id(projectId).build());
+            algorithmId = simulationManualProjectMapper.selectAlgorithmById(SimulationManualProjectEntity.builder().id(projectId).build());
+        } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
+            String automaticProjectId = simulationAutomaticSubprojectMapper.selectParentIdById(SimulationAutomaticSubprojectEntity.builder().id(projectId).build());
+            algorithmType = simulationAutomaticProjectMapper.selectAlgorithmTypeById(SimulationAutomaticProjectEntity.builder().id(automaticProjectId).build());
+            algorithmId = simulationAutomaticProjectMapper.selectAlgorithmById(SimulationAutomaticProjectEntity.builder().id(automaticProjectId).build());
+        } else {
+            throw new RuntimeException("未知项目类型:" + projectType);
+        }
+        if ( DictConstants.ALGORITHM_UPLOAD_MODE_PLATFORM.equals(algorithmType)) {
+            return algorithmExpandMapper.selectDockerImageByAlgorithmId(algorithmId);
+        } else {
+            return algorithmMapper.selectDockerImageById(algorithmId);
+        }
+    }
 }

+ 5 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/infra/db/mysql/mapper/AlgorithmExpandMapper.java

@@ -2,10 +2,15 @@ package com.css.simulation.resource.scheduler.infra.db.mysql.mapper;
 
 import com.css.simulation.resource.scheduler.infra.db.entity.AlgorithmExpandEntity;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 @Mapper
 public interface AlgorithmExpandMapper {
     void updateStatusByAlgorithmId(AlgorithmExpandEntity algorithmExpandEntity);
 
     String selectIdByAlgorithmId(AlgorithmExpandEntity build);
+
+    void updateDockerImportAndDockerImageById(@Param("dockerImage") String dockerImage, @Param("algorithmId") String algorithmId);
+
+    String selectDockerImageByAlgorithmId(@Param("algorithmId") String algorithmId);
 }

+ 1 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/infra/db/mysql/mapper/AlgorithmMapper.java

@@ -39,6 +39,7 @@ public interface AlgorithmMapper {
             "from algorithm\n" +
             "where id = #{id}")
     AlgorithmEntity selectById(@Param("id") String id);
+
     @Select("select docker_image\n" +
             "from algorithm\n" +
             "where id = #{id}")

+ 11 - 0
simulation-resource-scheduler/src/main/resources/mysql/mapper/AlgorithmExpandMapper.xml

@@ -8,7 +8,18 @@
         set status = #{status}
         where algorithm_id = #{algorithmId}
     </update>
+    <update id="updateDockerImportAndDockerImageById">
+        update algorithm_expand
+            set docker_import = #{dockerImport},
+                docker_image  = #{dockerImage}
+            where id = #{algorithmId}
+    </update>
     <select id="selectIdByAlgorithmId" resultType="java.lang.String">
         select id from algorithm_expand where algorithm_id = #{algorithmId}
     </select>
+    <select id="selectDockerImageByAlgorithmId" resultType="java.lang.String">
+        select docker_image
+        from algorithm_expand
+        where id = #{id}
+    </select>
 </mapper>