Explorar el Código

多线程生成视频

root hace 2 años
padre
commit
1e1f999bb3

+ 25 - 0
api-common/src/main/java/api/common/util/FileUtil.java

@@ -16,6 +16,31 @@ import java.nio.file.Paths;
 import java.util.*;
 import java.util.*;
 
 
 public class FileUtil {
 public class FileUtil {
+    /**
+     * 获得绝对路径
+     *
+     * @param parentDirectoryPath 父目录
+     * @param subStringOfFileName 文件名的子串
+     * @return 绝对路径
+     */
+    @SneakyThrows
+    public static String getAbsolutePath(String parentDirectoryPath, String subStringOfFileName) {
+        File parentDirectoryFile = new File(parentDirectoryPath);
+        if (!parentDirectoryFile.exists()) {
+            throw new RuntimeException("FileUtil.getAbsolutePath() -- 目录 " + parentDirectoryPath + " 不存在!");
+        }
+        File[] files = parentDirectoryFile.listFiles();
+        if (files == null || files.length == 0) {
+            throw new RuntimeException("FileUtil.getAbsolutePath() -- 目录 " + parentDirectoryPath + " 下没有文件!");
+
+        }
+        for (File file : files) {
+            if (file.getName().contains(subStringOfFileName)) {
+                return file.getAbsolutePath();
+            }
+        }
+        throw new RuntimeException("FileUtil.getAbsolutePath() -- 目录 " + parentDirectoryPath + " 下的文件名包含" + subStringOfFileName + " 的文件不存在!");
+    }
 
 
     /**
     /**
      * 获取所有同一类型的文件列表。
      * 获取所有同一类型的文件列表。

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

@@ -31,20 +31,20 @@ public class TaskController {
         taskService.taskState(taskId, state, podName);
         taskService.taskState(taskId, state, podName);
     }
     }
 
 
-    /**
-     * 修改任务状态
-     */
-    @GetMapping("/state")
-    public void taskState(
-            @RequestParam("taskId") String taskId,
-            @RequestParam("state") String state,
-            @RequestParam("podName") String podName,
-            @RequestParam("partition") String partition,
-            @RequestParam("offset") String offset
-
-    ) {
-        taskService.taskState(taskId, state, podName);
-    }
+//    /**
+//     * 修改任务状态
+//     */
+//    @GetMapping("/state")
+//    public void taskState(
+//            @RequestParam("taskId") String taskId,
+//            @RequestParam("state") String state,
+//            @RequestParam("podName") String podName,
+//            @RequestParam("partition") String partition,
+//            @RequestParam("offset") String offset
+//
+//    ) {
+//        taskService.taskState(taskId, state, podName);
+//    }
 
 
     /**
     /**
      * Pod 的心跳接口
      * Pod 的心跳接口

+ 1 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/manager/ProjectManager.java

@@ -34,7 +34,7 @@ public class ProjectManager {
     @SneakyThrows
     @SneakyThrows
     public void createTempYaml(String projectId, String algorithmDockerImage, String nodeName) {
     public void createTempYaml(String projectId, String algorithmDockerImage, String nodeName) {
         String podName = projectUtil.getRandomPodName(projectId);   // 生成 podName
         String podName = projectUtil.getRandomPodName(projectId);   // 生成 podName
-        String podTemplateFileNameOfProject = projectUtil.getPodYamlName(podName, nodeName);     // 模板文件名称
+        String podTemplateFileNameOfProject = projectUtil.getPodYamlName(nodeName, podName);     // 模板文件名称
         String podString = FileUtil.read(new File(podTemplateYaml));
         String podString = FileUtil.read(new File(podTemplateYaml));
         String replace0 = podString.replace("vtd-container", "vtd-" + projectId);
         String replace0 = podString.replace("vtd-container", "vtd-" + projectId);
         String replace1 = replace0.replace("vtd-image", kubernetesConfiguration.getVtdImage());
         String replace1 = replace0.replace("vtd-image", kubernetesConfiguration.getVtdImage());

+ 21 - 22
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/util/ProjectUtil.java

@@ -74,7 +74,7 @@ public class ProjectUtil {
         return "project-" + projectId + "-" + StringUtil.getRandomEightBitUUID();
         return "project-" + projectId + "-" + StringUtil.getRandomEightBitUUID();
     }
     }
 
 
-    public String getPodYamlName(String podName, String nodeName) {
+    public String getPodYamlName(String nodeName, String podName) {
         return nodeName + "#" + podName + ".yaml";
         return nodeName + "#" + podName + ".yaml";
     }
     }
 
 
@@ -112,6 +112,25 @@ public class ProjectUtil {
         return stringRedisTemplate.opsForValue().get("pod:" + podName + ":node");
         return stringRedisTemplate.opsForValue().get("pod:" + podName + ":node");
     }
     }
 
 
+    /**
+     * 更改一个名字继续启动
+     *
+     * @param projectId   项目 id
+     * @param nodeName    运行 pod 的节点名称
+     * @param lastPodName 即将删除的 pod 名称
+     */
+    @SneakyThrows
+    public void createNextPod(String projectId, String nodeName, String lastPodName) {
+        //1 删除上一个 pod 和 redis 键值对
+        deletePod(lastPodName);
+//        String lastPodString = FileUtil.read(podYamlDirectory + lastPodName + ".yaml");
+        String lastPodString = FileUtil.read(podYamlDirectory + getPodYamlName(nodeName, lastPodName));
+        String nextPodName = getRandomPodName(projectId);
+        String nextPodString = lastPodString.replace(lastPodName, nextPodName); // pod 名称包括 projectId 和 随机字符串
+        log.info("TaskManager--createNextPod 创建项目 " + projectId + " 的下一个 pod。");
+        createPod(nodeName, nextPodName, nextPodString);
+    }
+
 
 
     /**
     /**
      * @param nodeName       节点名称
      * @param nodeName       节点名称
@@ -121,7 +140,7 @@ public class ProjectUtil {
     @SneakyThrows
     @SneakyThrows
     public void createPod(String nodeName, String podName, String podYamlContent) {
     public void createPod(String nodeName, String podName, String podYamlContent) {
         stringRedisTemplate.opsForValue().set("pod:" + podName + ":node", nodeName);    // 将 pod 运行在哪个 node 上记录到 redis
         stringRedisTemplate.opsForValue().set("pod:" + podName + ":node", nodeName);    // 将 pod 运行在哪个 node 上记录到 redis
-        String podYamlName = getNodeNameOfPod(podName);
+        String podYamlName = getPodYamlName(nodeName, podName);
         String podYamlPath = podYamlDirectory + podYamlName;
         String podYamlPath = podYamlDirectory + podYamlName;
         FileUtil.writeStringToLocalFile(podYamlContent, podYamlPath);
         FileUtil.writeStringToLocalFile(podYamlContent, podYamlPath);
         KubernetesUtil.createNs(apiClient, kubernetesConfiguration.getNamespace());
         KubernetesUtil.createNs(apiClient, kubernetesConfiguration.getNamespace());
@@ -132,26 +151,6 @@ public class ProjectUtil {
     }
     }
 
 
 
 
-
-    /**
-     * 更改一个名字继续启动
-     *
-     * @param projectId   项目 id
-     * @param nodeName    运行 pod 的节点名称
-     * @param lastPodName 即将删除的 pod 名称
-     */
-    @SneakyThrows
-    public void createNextPod(String projectId, String nodeName, String lastPodName) {
-        //1 删除上一个 pod 和 redis 键值对
-        deletePod(lastPodName);
-        String lastPodString = FileUtil.read(podYamlDirectory + lastPodName + ".yaml");
-        String nextPodName = getRandomPodName(projectId);
-        String nextPodString = lastPodString.replace(lastPodName, nextPodName); // pod 名称包括 projectId 和 随机字符串
-        log.info("TaskManager--createNextPod 创建项目 " + projectId + " 的下一个 pod。");
-        createPod(nodeName, nextPodName, nextPodString);
-    }
-
-
     public String getProjectTypeByProjectId(String projectId) {
     public String getProjectTypeByProjectId(String projectId) {
         String projectType = null;
         String projectType = null;
         ProjectPO manualProjectPO = manualProjectMapper.selectById(projectId);
         ProjectPO manualProjectPO = manualProjectMapper.selectById(projectId);