Ver Fonte

Merge branch 'master' of http://10.12.10.70:3000/CSS/simulation-cloud

zuoqingtong há 2 anos atrás
pai
commit
267072fb4a

+ 2 - 1
api-common/src/main/java/api/common/util/PythonUtil.java

@@ -22,6 +22,7 @@ public class PythonUtil {
     public static String R = "R";
     public static String W = "W";
     public static String E = "E";
+    public static String E0401 = "E0401";
     public static String F = "F";
     public static String PASS = "Your code has been rated at 10.00/10";
 
@@ -32,7 +33,7 @@ public class PythonUtil {
     @SneakyThrows
     public static String pylint(String pythonCode, String... disables) {
         //1 把代码保存成本地文件
-        String filePath = "/tmp/" + UUID.randomUUID().toString().replace("-", "") + ".py";
+        String filePath = "/home/ubuntu/test/" + UUID.randomUUID().toString().replace("-", "") + ".py";
         FileUtil.writeStringToLocalFile(pythonCode, filePath);
         //2 执行命令检查格式
         StringBuilder command = new StringBuilder("pylint --disable=");

+ 1 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/configuration/docker/DockerConfiguration.java

@@ -12,6 +12,7 @@ import java.util.List;
 @Data
 public class DockerConfiguration {
     private String registry;
+    private String registryVolume;
     private Integer maxAlgorithmImage;
     private Integer minAlgorithmImage;
     private List<DockerNodeTO> nodeList;

+ 45 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/scheduler/ClusterScheduler.java

@@ -0,0 +1,45 @@
+package com.css.simulation.resource.scheduler.scheduler;
+
+import api.common.util.CollectionUtil;
+import com.css.simulation.resource.scheduler.configuration.kubernetes.KubernetesConfiguration;
+import com.css.simulation.resource.scheduler.pojo.to.KubernetesNodeTO;
+import com.css.simulation.resource.scheduler.util.KubernetesUtil;
+import io.kubernetes.client.openapi.ApiClient;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Component
+@Slf4j
+public class ClusterScheduler {
+
+
+    @Resource
+    KubernetesConfiguration kubernetesConfiguration;
+    @Resource
+    ApiClient apiClient;
+    @Resource
+    StringRedisTemplate stringRedisTemplate;
+
+
+    /**
+     * 闲时重置所有并行度
+     */
+    @Scheduled(fixedDelay = 2 * 60 * 1000)
+    @SneakyThrows
+    public void initNodeParallelism() {
+        List<KubernetesNodeTO> initialNodeList = kubernetesConfiguration.getNodeList(); // 预设并行度的节点列表
+        List<String> podNameList = KubernetesUtil.getPod(apiClient, kubernetesConfiguration.getNamespace());
+        if (CollectionUtil.isEmpty(podNameList)) {
+            for (KubernetesNodeTO kubernetesNodeTO : initialNodeList) {
+                stringRedisTemplate.opsForValue().set("node:" + kubernetesNodeTO.getName() + ":parallelism", kubernetesNodeTO.getMaxParallelism() + "");
+                log.info("ClusterScheduler--initNodeParallelism 重置节点并行度为:" + initialNodeList);
+            }
+        }
+    }
+}

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

@@ -371,7 +371,7 @@ public class ProjectService {
                     String gitUrl = algorithmPO.getGitUrl().replace(gitConfiguration.getName(), gitConfiguration.getUrl());
                     String gitUserName = algorithmPO.getGitUserName();
                     String gitPassword = algorithmPO.getGitPassword();
-                    GitUtil.clone(gitUrl, gitUserName, gitPassword, algorithmDirectoryLinuxTempPath); // 下载算法文件到目录
+                    GitUtil.clone(gitUrl, gitUserName, gitPassword, algorithmDirectoryLinuxTempPath, true); // 下载算法文件到目录
                     for (String filename : Objects.requireNonNull(new File(algorithmDirectoryLinuxTempPath).list())) {
                         if (filename.endsWith(".tar")) {
                             algorithmTarLinuxTempPath = algorithmDirectoryLinuxTempPath + filename;

+ 1 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/VideoService.java

@@ -9,7 +9,6 @@ import com.css.simulation.resource.scheduler.mapper.SimulationAutomaticProjectMa
 import com.css.simulation.resource.scheduler.mapper.VehicleMapper;
 import com.css.simulation.resource.scheduler.util.MinioUtil;
 import io.minio.MinioClient;
-import lombok.NoArgsConstructor;
 import lombok.SneakyThrows;
 import org.dom4j.Attribute;
 import org.dom4j.Document;
@@ -30,7 +29,6 @@ import java.nio.file.Paths;
 import java.util.Iterator;
 
 @Service
-@NoArgsConstructor
 public class VideoService {
     @Resource
     VehicleMapper vehicleMapper;
@@ -144,6 +142,7 @@ public class VideoService {
                                     name.setText("Audi_A3_2009_red");
                                     Attribute vehicleCategory = node3.attribute("vehicleCategory");
                                     vehicleCategory.setText(po.getVehicleCategory());
+                                    node3.addAttribute("model3d",po.getModel3d());//自车渲染
                                     Iterator<Element> iterator4 = node3.elementIterator();
                                     while (iterator4.hasNext()) {
                                         Element node4 = iterator4.next();

+ 29 - 12
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/util/GitUtil.java

@@ -19,26 +19,43 @@ import java.io.File;
 public class GitUtil {
 
     /**
-     * @param url                 git 地址
-     * @param username            用户名
-     * @param password            密码
-     * @param localEmptyDirectory 空目录
+     * @param url           git 地址
+     * @param username      用户名
+     * @param password      密码
+     * @param directoryPath 空目录
+     * @param cover         如果目录内有文件,是否覆盖
      */
     @SneakyThrows
-    public static void clone(String url, String username, String password, String localEmptyDirectory) {
-        File localEmptyDirectoryFile = new File(localEmptyDirectory);
-        if (localEmptyDirectoryFile.exists()) {
-            File[] files = localEmptyDirectoryFile.listFiles();
-            if (files == null || files.length > 0) {
-                throw new RuntimeException("GitUtil--clone 目标下载目录不是空目录。");
+    @SuppressWarnings("all")
+    public static void clone(String url, String username, String password, String directoryPath, boolean cover) {
+        File directoryFile = new File(directoryPath);
+        if (directoryFile.exists()) {
+            File[] files = directoryFile.listFiles();
+            if (files == null || files.length == 0) {
+                clone(url, username, password, directoryFile);
+            } else {
+                if (cover) {
+                    for (File file : files) {
+                        file.delete();
+                    }
+                    clone(url, username, password, directoryFile);
+                } else {
+                    throw new RuntimeException("GitUtil--clone 目标下载目录不是空目录。");
+                }
             }
         } else {
-            localEmptyDirectoryFile.mkdirs();
+            directoryFile.mkdirs();
+            clone(url, username, password, directoryFile);
         }
+
+    }
+
+    @SneakyThrows
+    private static void clone(String url, String username, String password, File directoryFile) {
         Git git = Git.cloneRepository()
                 .setURI(url)
                 .setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password))
-                .setDirectory(localEmptyDirectoryFile)
+                .setDirectory(directoryFile)
                 .call();
     }
 }

+ 3 - 3
simulation-resource-server/src/main/java/com/css/simulation/resource/scene/ctrl/ScoringRulesController.java

@@ -85,7 +85,7 @@ public class ScoringRulesController {
             return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "规则名称 ruleName 已存在,请重新命名。");
         }
         //2 校验 python 语法错误
-        String pylint = PythonUtil.pylint(scoringRulesPO.getRuleDetails(), PythonUtil.C, PythonUtil.R, PythonUtil.W);
+        String pylint = PythonUtil.pylint(scoringRulesPO.getRuleDetails(), PythonUtil.C, PythonUtil.R, PythonUtil.W, PythonUtil.E0401);
         if (!pylint.contains(PythonUtil.PASS)) {
             return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "代码格式错误,请检查。");
         }
@@ -105,14 +105,14 @@ public class ScoringRulesController {
     @ResponseBody
     public ResponseBodyVO<String> fxScoringRules(@RequestBody ScoringRulesParam params) {
         if (ObjectUtil.isNull(params.getRulesId())) {
-            return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "参数 RulesId 不能为空,请检查","");
+            return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "参数 RulesId 不能为空,请检查", "");
         }
         ScoringRulesPO po = scoringRulesService.queryScoringRules(params);
         params.setShare("1");
         params.setRuleName(po.getRuleName());
         List<ScoringRulesPO> list = scoringRulesService.queryScoringRulesByRuleName(params);
         if (list != null && list.size() > 0) {
-            return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "规则名称ruleName已存在,请重新命名","");
+            return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "规则名称ruleName已存在,请重新命名", "");
         }
         po.setShare("1");
         scoringRulesService.saveScoringRules(po);