root 2 anos atrás
pai
commit
9ae5902734

+ 19 - 4
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/configuration/redis/CustomRedisClient.java

@@ -19,12 +19,16 @@ public class CustomRedisClient {
 
     //* -------------------------------- Comment --------------------------------
 
+    public Set<String> keys(String pattern) {
+        return stringRedisTemplate.keys(pattern);
+    }
+
     public String get(String key) {
         return stringRedisTemplate.opsForValue().get(key);
     }
 
     public void set(String key, String value) {
-         stringRedisTemplate.opsForValue().set(key, value);
+        stringRedisTemplate.opsForValue().set(key, value);
     }
 
     public void flushdb() {
@@ -34,6 +38,20 @@ public class CustomRedisClient {
         }
     }
 
+    public Boolean createLock(String key) {
+        return stringRedisTemplate.opsForValue().setIfAbsent(key, "", 1L, TimeUnit.HOURS);
+    }
+
+    public void deleteLock(String key) {
+        delete(key);
+    }
+
+    public void delete(String key) {
+        stringRedisTemplate.delete(key);
+    }
+
+    //* -------------------------------- Comment --------------------------------
+
     public void deleteByKey(String key) {
         stringRedisTemplate.delete(key);
     }
@@ -57,7 +75,4 @@ public class CustomRedisClient {
     }
 
 
-    public Boolean getDistributedLock(String key) {
-        return stringRedisTemplate.opsForValue().setIfAbsent(key, "1", 10L, TimeUnit.SECONDS);
-    }
 }

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

@@ -144,7 +144,6 @@ public class TaskManager {
                 if (DictConstants.VIDEO_GPU.equals(isChoiceGpu)) {
                     log.info("项目 {} 使用 GPU 生成视频。", projectId);
                 } else if (DictConstants.VIDEO_CPU.equals(isChoiceGpu)) {
-                    log.info("项目 {} 使用 CPU 生成视频。", projectId);
                     log.info("项目 {} 使用 CPU 生成视频。", projectId);
                     videoFeignClient.generateVideo(projectId, projectType, maxSimulationTime, taskId);
                 } else {

+ 209 - 9
simulation-resource-scheduler/src/main/resources/bootstrap-dev.yaml

@@ -1,10 +1,210 @@
+server:
+  port: 8004
+  servlet:
+    context-path: /simulation/resource/scheduler
+
+simulation-cloud:
+  client-id: simulation-oauth-client
+  client-secret: hPT7zVteEXvRzS41NhJXoQYqtGmai3W0
+  token-uri: http://10.14.85.241/simulation/oauth/server/token
+  evaluation-level-uri: http://10.14.85.241/simulation/resource/server/simulationProject/saveEvaluationLevel
+
+algorithm-platform:
+  appid: 2af6f44d98104dc5adcbfb49809ff9d5
+  secret: db129a741fde1e9f474199dea24f3901
+  token-uri: https://open.zoogooy.com.cn/cgi-bin/token/token
+  algorithm-addr-uri: https://open.zoogooy.com.cn/cgi-bin/api/icv-algorithm-agg/simulation/download
+
+minio:
+  endpoint: http://10.14.85.242:9000/
+  endpoint-without-http: 10.14.85.242:9000
+  access-key: minioadmin
+  secret-key: 1qaz2wsx!
+  bucket-name: simulation-cloud
+
 spring:
-  cloud:
-    nacos:
-      discovery:
-        server-addr: 47.93.135.21:8848
-        namespace: 3698bfc2-a612-487a-b2a2-aaad16cd9d9d
-      config:
-        server-addr: 47.93.135.21:8848
-        namespace: 3698bfc2-a612-487a-b2a2-aaad16cd9d9d
-        file-extension: yaml
+  mvc:
+    async:
+      request-timeout: 30000
+  servlet:
+    multipart:
+      max-request-size: 10240MB
+      max-file-size: 10240MB
+  datasource:
+    druid:
+      url: jdbc:mysql://10.14.85.240:3306/simulation?characterEncoding=utf8&connectTimeout=60000&socketTimeout=60000&useSSL=false
+      username: root
+      password: 1qaz2wsx!
+      driver-class-name: com.mysql.jdbc.Driver
+      initial-size: 200
+      min-idle: 200
+      max-active: 200
+      max-wait: 300000
+      filter:
+        stat:
+          enabled: true
+        wall:
+          enabled: true
+        slf4j:
+          enabled: true
+      stat-view-servlet:
+        enabled: true
+        url-pattern: /druid/*
+        login-username: druid
+        login-password: 1qaz2wsx!
+  #* -------------------------------- kafka 消息队列 --------------------------------
+  kafka:
+    hostname: 10.14.85.239
+    username: root
+    password: Ubuntu_cicv
+    delete-command: /mnt/disk001/kafka_2.13-3.1.0/bin/kafka-topics.sh --bootstrap-server 10.14.85.239:9092 --delete --topic topicName
+    bootstrap-servers: 10.14.85.239:9092    # 指定连接的 kafka 集群。
+    listener:
+      missing-topics-fatal: false
+    consumer:
+      group-id: simulation-resource-scheduler
+      enable-auto-commit: true
+      auto-commit-interval: 1000
+      auto-offset-reset: latest
+      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
+      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
+      properties:
+        session:
+          timeout:
+            ms: 12000
+        request:
+          timeout:
+            ms: 180000
+    producer:
+      retries: 3
+      acks: 1
+      batch-size: 16384
+      buffer-memory: 33554432
+      key-serializer: org.apache.kafka.common.serialization.StringSerializer
+      value-serializer: org.apache.kafka.common.serialization.StringSerializer
+      properties:
+        linger:
+          ms: 0
+  cache:
+    type: redis
+  redis:
+    host: 10.14.85.240
+    port: 6379
+    password: 1qaz2wsx!
+    connect-timeout: 10000
+    timeout: 10000
+    database: 2
+    lettuce:
+      pool:
+        max-active: 8
+        max-idle: 8
+        min-idle: 0
+        max-wait: 1000
+
+kubernetes:
+  namespace: simulation
+  pod-timeout: 120000
+  image-vtd-gpu: 10.14.85.237:5000/vtd.run.perception.release:latest
+  command-vtd-gpu: /Controller/config/docker_cloud.ini
+  command-vtd-carsim-gpu: /Controller/config/docker_cloud_carsim.ini
+  image-vtd-nogpu: 10.14.85.237:5000/vtd.run.control.release:latest
+  command-vtd-nogpu: /Controller/config/docker_cloud_noig.ini
+  command-vtd-carsim-nogpu: /Controller/config/docker_cloud_noig_carsim.ini
+  carsim-image: 10.14.85.237:5000/carsim:latest
+  carsim-command: /root/VTD_CarSim
+  node-list:
+    - hostname: cicv-node-1
+      parallelism: 2
+    - hostname: cicv-node-2
+      parallelism: 2
+    - hostname: cicv-node-3
+      parallelism: 2
+    - hostname: cicv-node-4
+      parallelism: 2
+    - hostname: cicv-node-5
+      parallelism: 2
+    - hostname: cicv-node-6
+      parallelism: 2
+    - hostname: cicv-node-7
+      parallelism: 2
+    - hostname: cicv-node-8
+      parallelism: 2
+
+
+git:
+  name: gitlab-441-442-443
+  url: 10.14.85.241:441
+
+docker:
+  registry: 10.14.85.237:5000
+  registry-volume: /mnt/disk001/simulation-cloud/docker/registry-5000/data/docker/registry/v2/repositories
+  max-algorithm-image: 30
+  min-algorithm-image: 10
+  node-list:
+    - name: gpu001
+      hostname: 10.14.85.237
+      username: root
+      password: Ubuntu_cicv
+    - name: gpu002
+      hostname: 10.14.85.236
+      username: root
+      password: Ubuntu_cicv
+    - name: gpu003
+      hostname: 10.14.85.238
+      username: root
+      password: Ubuntu_cicv
+    - name: cicv-node-1
+      hostname: 20.7.1.101
+      username: root
+      password: Ubuntu_cicv
+    - name: cicv-node-2
+      hostname: 20.7.1.102
+      username: root
+      password: Ubuntu_cicv
+    - name: cicv-node-3
+      hostname: 20.7.1.103
+      username: root
+      password: Ubuntu_cicv
+    - name: cicv-node-4
+      hostname: 20.7.1.104
+      username: root
+      password: Ubuntu_cicv
+    - name: cicv-node-5
+      hostname: 20.7.1.105
+      username: root
+      password: Ubuntu_cicv
+    - name: cicv-node-6
+      hostname: 20.7.1.106
+      username: root
+      password: Ubuntu_cicv
+    - name: cicv-node-7
+      hostname: 20.7.1.107
+      username: root
+      password: Ubuntu_cicv
+    - name: cicv-node-8
+      hostname: 20.7.1.108
+      username: root
+      password: Ubuntu_cicv
+
+scheduler:
+  simulation-cloud-ip: 10.14.85.241
+  host:
+    hostname: 10.14.85.237
+    username: root
+    password: Ubuntu_cicv
+  start-topic: project
+  stop-topic: stopProject
+  linux-path:
+    temp: /mnt/disk001/simulation-cloud/simulation-resource-scheduler-8004/temp/
+    pod-template-yaml: /mnt/disk001/simulation-cloud/simulation-resource-scheduler-8004/pod-template/pod-template.yaml
+    vtd-pod-template-yaml: /mnt/disk001/simulation-cloud/simulation-resource-scheduler-8004/pod-template/vtd-pod-template.yaml
+    carsim-pod-template-yaml: /mnt/disk001/simulation-cloud/simulation-resource-scheduler-8004/pod-template/carsim-pod-template.yaml
+    pod-yaml-directory: /mnt/disk001/simulation-cloud/simulation-resource-scheduler-8004/pod-yaml/
+    score-py: /SimulationCloud/Evaluate
+  minio-path:
+    project-result: /project/
+
+esmini:
+  node-list:
+    - hostname: simulation003
+      parallelism: 1

+ 36 - 9
simulation-resource-video/src/main/java/com/css/simulation/resource/video/configuration/redis/CustomRedisClient.java

@@ -17,6 +17,41 @@ public class CustomRedisClient {
     @Resource
     private StringRedisTemplate stringRedisTemplate;
 
+    //* -------------------------------- Comment --------------------------------
+
+    public Set<String> keys(String pattern) {
+        return stringRedisTemplate.keys(pattern);
+    }
+
+    public String get(String key) {
+        return stringRedisTemplate.opsForValue().get(key);
+    }
+
+    public void set(String key, String value) {
+        stringRedisTemplate.opsForValue().set(key, value);
+    }
+
+    public void flushdb() {
+        Set<String> keys = stringRedisTemplate.keys("*");
+        if (CollectionUtil.isNotEmpty(keys)) {
+            stringRedisTemplate.delete(keys);
+        }
+    }
+
+    public Boolean createLock(String key) {
+        return stringRedisTemplate.opsForValue().setIfAbsent(key, "", 1L, TimeUnit.HOURS);
+    }
+
+    public void deleteLock(String key) {
+        delete(key);
+    }
+
+    public void delete(String key) {
+        stringRedisTemplate.delete(key);
+    }
+
+    //* -------------------------------- Comment --------------------------------
+
     public void deleteByKey(String key) {
         stringRedisTemplate.delete(key);
     }
@@ -34,18 +69,10 @@ public class CustomRedisClient {
         return stringRedisTemplate.opsForValue().get(key);
     }
 
+
     public Set<String> getKeySetByPrefix(String prefix) {
         return stringRedisTemplate.keys(prefix + "*");
     }
 
-    public void flushdb() {
-        Set<String> keys = stringRedisTemplate.keys("*");
-        if (CollectionUtil.isNotEmpty(keys)) {
-            stringRedisTemplate.delete(keys);
-        }
-    }
 
-    public Boolean getDistributedLock(String key) {
-        return stringRedisTemplate.opsForValue().setIfAbsent(key, "1", 10L, TimeUnit.SECONDS);
-    }
 }

+ 27 - 2
simulation-resource-video/src/main/java/com/css/simulation/resource/video/service/VideoService.java

@@ -4,11 +4,13 @@ import api.common.pojo.po.scene.VehicleTypePO;
 import api.common.util.FileUtil;
 import api.common.util.LinuxUtil;
 import api.common.util.StringUtil;
+import com.css.simulation.resource.video.configuration.redis.CustomRedisClient;
 import com.css.simulation.resource.video.entity.VehicleEntity;
 import com.css.simulation.resource.video.mapper.ConfigMapper;
 import com.css.simulation.resource.video.mapper.SimulationAutomaticProjectMapper;
 import com.css.simulation.resource.video.mapper.VehicleMapper;
 import com.css.simulation.resource.video.util.MinioUtil;
+import com.css.simulation.resource.video.util.OsUtil;
 import io.minio.MinioClient;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
@@ -30,6 +32,8 @@ import java.math.RoundingMode;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
 
 @Service
 @Slf4j
@@ -59,11 +63,13 @@ public class VideoService {
     @Value("${scheduler.esmini-command}")
     private String esminiCommand;
     @Value("${scheduler.python-command}")
-    private  String pythonCommand;
+    private String pythonCommand;
     @Value("${scheduler.minio-path.project-result}")
     private String projectResultPathOfMinio;
     @Value("${minio.bucket-name}")
-    private  String bucketName;
+    private String bucketName;
+    @Resource
+    private CustomRedisClient customRedisClient;
 
 
     /**
@@ -71,6 +77,24 @@ public class VideoService {
      */
     @SneakyThrows
     public void generateVideo(String projectId, String projectType, String maxSimulationTime, String taskId) {
+        final Set<String> cpuNodeParallelismKeys = customRedisClient.keys("cpu-node*");
+        // 获取本地 hostname
+        final String hostName = OsUtil.getHostName();
+        int parallelism = 0;
+        String cpuNodeParallelismKey = "cpu-node:simulation003:parallelism";
+        for (String tempCpuNodeParallelismKey : cpuNodeParallelismKeys) {
+            if (tempCpuNodeParallelismKey.contains(hostName)) {
+                cpuNodeParallelismKey = tempCpuNodeParallelismKey;
+            }
+        }
+        // 检查是否有并行度可用
+        while (parallelism < 1) {
+            parallelism = Integer.parseInt(customRedisClient.get(cpuNodeParallelismKey));
+            TimeUnit.SECONDS.sleep(7);
+        }
+        customRedisClient.set(cpuNodeParallelismKey, (parallelism - 1) + "");
+
+
         String rootDirectoryPathOfMinio = projectResultPathOfMinio + projectId + "/" + taskId + "/";
         String xodrPathOfMinio = rootDirectoryPathOfMinio + taskId + ".xodr";
         String osgbPathOfMinio = rootDirectoryPathOfMinio + taskId + ".osgb";
@@ -128,6 +152,7 @@ public class VideoService {
 
         //* -------------------------------- 删除临时文件 --------------------------------
         LinuxUtil.execute(removeAll);
+        customRedisClient.set(cpuNodeParallelismKey, (Integer.parseInt(customRedisClient.get(cpuNodeParallelismKey)) + 1) + "");
     }
 
     /**

+ 80 - 0
simulation-resource-video/src/main/java/com/css/simulation/resource/video/util/OsUtil.java

@@ -0,0 +1,80 @@
+package com.css.simulation.resource.video.util;
+
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.net.InetAddress;
+
+/**
+ * 对本地系统进行操作
+ */
+@Slf4j
+public class OsUtil {
+
+    @SneakyThrows
+    public static String getHostName() {
+        final String hostName = InetAddress.getLocalHost().getHostName();
+        log.info("本地系统主机名为:{}", hostName);
+        return hostName;
+    }
+
+    @SneakyThrows
+    public static String getIp() {
+        return InetAddress.getLocalHost().getHostAddress();
+    }
+
+    @SneakyThrows
+    public static String execute(String command) {
+        String result;
+        log.info("开始执行 linux 命令:" + command);
+        Runtime run = Runtime.getRuntime();
+        Process process = run.exec(command);
+        InputStream in = new BufferedInputStream(process.getInputStream());
+        StringBuilder out = new StringBuilder();
+        byte[] b = new byte[8192];
+        for (int n; (n = in.read(b)) != -1; ) {
+            out.append(new String(b, 0, n));
+        }
+        in.close();
+        process.destroy();
+        result = out.toString();
+        log.info("执行结果为:" + result);
+        return result;
+    }
+
+    /**
+     * 指定工作目录执行目录
+     *
+     * @param command   命令
+     * @param directory 工作目录
+     * @return 执行结果
+     */
+    @SneakyThrows
+    public static String execute(String command, String directory) {
+        String result;
+        log.info("执行本地操作系统命令:{}", command);
+        Runtime run = Runtime.getRuntime();
+        Process process = run.exec(command, null, new File(directory));
+        InputStream in = new BufferedInputStream(process.getInputStream());
+        StringBuilder out = new StringBuilder();
+        byte[] b = new byte[8192];
+        for (int n; (n = in.read(b)) != -1; ) {
+            out.append(new String(b, 0, n));
+        }
+        in.close();
+        process.destroy();
+        result = out.toString();
+        log.info("执行结果为:{}", result);
+        return result;
+    }
+
+
+    public static String kill(String command) {
+        return execute("echo kill $(ps -ef | grep '" + command + "' | awk '{ print $2 }')");
+    }
+
+
+}