|
@@ -5,11 +5,13 @@ import api.common.util.FileUtil;
|
|
import api.common.util.LinuxUtil;
|
|
import api.common.util.LinuxUtil;
|
|
import api.common.util.OsUtil;
|
|
import api.common.util.OsUtil;
|
|
import api.common.util.StringUtil;
|
|
import api.common.util.StringUtil;
|
|
|
|
+import com.css.simulation.resource.video.configuration.constant.ConstantConfiguration;
|
|
|
|
+import com.css.simulation.resource.video.configuration.minio.MinioConfiguration;
|
|
import com.css.simulation.resource.video.configuration.redis.CustomRedisClient;
|
|
import com.css.simulation.resource.video.configuration.redis.CustomRedisClient;
|
|
import com.css.simulation.resource.video.data.entity.VehicleEntity;
|
|
import com.css.simulation.resource.video.data.entity.VehicleEntity;
|
|
import com.css.simulation.resource.video.mapper.ModelConfigMapper;
|
|
import com.css.simulation.resource.video.mapper.ModelConfigMapper;
|
|
-import com.css.simulation.resource.video.mapper.SimulationAutomaticProjectMapper;
|
|
|
|
import com.css.simulation.resource.video.mapper.ModelVehicleMapper;
|
|
import com.css.simulation.resource.video.mapper.ModelVehicleMapper;
|
|
|
|
+import com.css.simulation.resource.video.mapper.SimulationAutomaticProjectMapper;
|
|
import com.css.simulation.resource.video.util.MinioUtil;
|
|
import com.css.simulation.resource.video.util.MinioUtil;
|
|
import io.minio.MinioClient;
|
|
import io.minio.MinioClient;
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
@@ -20,7 +22,6 @@ import org.dom4j.Element;
|
|
import org.dom4j.io.OutputFormat;
|
|
import org.dom4j.io.OutputFormat;
|
|
import org.dom4j.io.SAXReader;
|
|
import org.dom4j.io.SAXReader;
|
|
import org.dom4j.io.XMLWriter;
|
|
import org.dom4j.io.XMLWriter;
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
@@ -44,7 +45,14 @@ public class VideoService {
|
|
@Resource
|
|
@Resource
|
|
private SimulationAutomaticProjectMapper simulationAutomaticProjectMapper;
|
|
private SimulationAutomaticProjectMapper simulationAutomaticProjectMapper;
|
|
@Resource
|
|
@Resource
|
|
|
|
+ private MinioConfiguration minioConfiguration;
|
|
|
|
+ @Resource
|
|
private MinioClient minioClient;
|
|
private MinioClient minioClient;
|
|
|
|
+ @Resource
|
|
|
|
+ private ConstantConfiguration constantConfiguration;
|
|
|
|
+ @Resource
|
|
|
|
+ private CustomRedisClient customRedisClient;
|
|
|
|
+
|
|
//* -------------------------------- Comment --------------------------------
|
|
//* -------------------------------- Comment --------------------------------
|
|
|
|
|
|
public static final String oldXoscName = "simulation_my0.xosc";
|
|
public static final String oldXoscName = "simulation_my0.xosc";
|
|
@@ -55,20 +63,6 @@ public class VideoService {
|
|
public static final String videoName = "simulation_output.mp4";
|
|
public static final String videoName = "simulation_output.mp4";
|
|
|
|
|
|
//* -------------------------------- Comment --------------------------------
|
|
//* -------------------------------- Comment --------------------------------
|
|
- @Value("${scheduler.linux-path.temp}")
|
|
|
|
- private String linuxTempPath;
|
|
|
|
- @Value("${scheduler.xvfb-command}")
|
|
|
|
- private String xvfbCommand;
|
|
|
|
- @Value("${scheduler.esmini-command}")
|
|
|
|
- private String esminiCommand;
|
|
|
|
- @Value("${scheduler.python-command}")
|
|
|
|
- private String pythonCommand;
|
|
|
|
- @Value("${scheduler.minio-path.project-result}")
|
|
|
|
- private String projectResultPathOfMinio;
|
|
|
|
- @Value("${minio.bucket-name}")
|
|
|
|
- private String bucketName;
|
|
|
|
- @Resource
|
|
|
|
- private CustomRedisClient customRedisClient;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -88,21 +82,21 @@ public class VideoService {
|
|
customRedisClient.lock(lockName, 1000L, (Long.parseLong(maxSimulationTime) + 10) * 1000L);
|
|
customRedisClient.lock(lockName, 1000L, (Long.parseLong(maxSimulationTime) + 10) * 1000L);
|
|
customRedisClient.decrement(cpuNodeParallelismKey, 1);
|
|
customRedisClient.decrement(cpuNodeParallelismKey, 1);
|
|
try {
|
|
try {
|
|
- String rootDirectoryPathOfMinio = projectResultPathOfMinio + projectId + "/" + taskId + "/";
|
|
|
|
|
|
+ String rootDirectoryPathOfMinio = minioConfiguration.getProjectResultDirectory() + projectId + "/" + taskId + "/";
|
|
String xodrPathOfMinio = rootDirectoryPathOfMinio + taskId + ".xodr";
|
|
String xodrPathOfMinio = rootDirectoryPathOfMinio + taskId + ".xodr";
|
|
String osgbPathOfMinio = rootDirectoryPathOfMinio + taskId + ".osgb";
|
|
String osgbPathOfMinio = rootDirectoryPathOfMinio + taskId + ".osgb";
|
|
String csv1PathOfMinio = rootDirectoryPathOfMinio + csv1Name;
|
|
String csv1PathOfMinio = rootDirectoryPathOfMinio + csv1Name;
|
|
String csv2PathOfMinio = rootDirectoryPathOfMinio + csv2Name;
|
|
String csv2PathOfMinio = rootDirectoryPathOfMinio + csv2Name;
|
|
- String rootDirectoryPathOfLinux = linuxTempPath + "video/" + projectId + "/" + taskId + "/";
|
|
|
|
|
|
+ String rootDirectoryPathOfLinux = constantConfiguration.getLinuxTempDirectory() + "video/" + projectId + "/" + taskId + "/";
|
|
String xodrPathOfLinux = rootDirectoryPathOfLinux + taskId + ".xodr";
|
|
String xodrPathOfLinux = rootDirectoryPathOfLinux + taskId + ".xodr";
|
|
String osgbPathOfLinux = rootDirectoryPathOfLinux + taskId + ".osgb";
|
|
String osgbPathOfLinux = rootDirectoryPathOfLinux + taskId + ".osgb";
|
|
String csv1PathOfLinux = rootDirectoryPathOfLinux + csv1Name;
|
|
String csv1PathOfLinux = rootDirectoryPathOfLinux + csv1Name;
|
|
String csv2PathOfLinux = rootDirectoryPathOfLinux + csv2Name;
|
|
String csv2PathOfLinux = rootDirectoryPathOfLinux + csv2Name;
|
|
log.info("下载 csv、xodr、osgb。");
|
|
log.info("下载 csv、xodr、osgb。");
|
|
- MinioUtil.downloadToFile(minioClient, bucketName, xodrPathOfMinio, xodrPathOfLinux);
|
|
|
|
- MinioUtil.downloadToFile(minioClient, bucketName, osgbPathOfMinio, osgbPathOfLinux);
|
|
|
|
- MinioUtil.downloadToFile(minioClient, bucketName, csv1PathOfMinio, csv1PathOfLinux);
|
|
|
|
- MinioUtil.downloadToFile(minioClient, bucketName, csv2PathOfMinio, csv2PathOfLinux);
|
|
|
|
|
|
+ MinioUtil.downloadToFile(minioClient, minioConfiguration.getBucketName(), xodrPathOfMinio, xodrPathOfLinux);
|
|
|
|
+ MinioUtil.downloadToFile(minioClient, minioConfiguration.getBucketName(), osgbPathOfMinio, osgbPathOfLinux);
|
|
|
|
+ MinioUtil.downloadToFile(minioClient, minioConfiguration.getBucketName(), csv1PathOfMinio, csv1PathOfLinux);
|
|
|
|
+ MinioUtil.downloadToFile(minioClient, minioConfiguration.getBucketName(), csv2PathOfMinio, csv2PathOfLinux);
|
|
log.info("生成 xosc 文件。");
|
|
log.info("生成 xosc 文件。");
|
|
String xoscPath = generateXosc(rootDirectoryPathOfLinux, xodrPathOfLinux, osgbPathOfLinux, projectId,
|
|
String xoscPath = generateXosc(rootDirectoryPathOfLinux, xodrPathOfLinux, osgbPathOfLinux, projectId,
|
|
projectType);
|
|
projectType);
|
|
@@ -112,8 +106,8 @@ public class VideoService {
|
|
// 获取屏幕号创建新的虚拟屏幕
|
|
// 获取屏幕号创建新的虚拟屏幕
|
|
final long newScreenNum = customRedisClient.increment("screen-number", 1);
|
|
final long newScreenNum = customRedisClient.increment("screen-number", 1);
|
|
log.info("获取新的屏幕号:" + newScreenNum);
|
|
log.info("获取新的屏幕号:" + newScreenNum);
|
|
- final String xvfbCommand2 = xvfbCommand.replaceAll("screen-num", String.valueOf(newScreenNum));
|
|
|
|
- final String esminiCommand2 = esminiCommand.replaceAll("screen-num", String.valueOf(newScreenNum))
|
|
|
|
|
|
+ final String xvfbCommand2 = constantConfiguration.getXvfbCommand().replaceAll("screen-num", String.valueOf(newScreenNum));
|
|
|
|
+ final String esminiCommand2 = constantConfiguration.getEsminiCommand().replaceAll("screen-num", String.valueOf(newScreenNum))
|
|
+ " " + xoscPath + " " + pictureDirectoryPath + "/screenshot " + StringUtil.doubleToString(Double
|
|
+ " " + xoscPath + " " + pictureDirectoryPath + "/screenshot " + StringUtil.doubleToString(Double
|
|
.parseDouble(maxSimulationTime), 2);
|
|
.parseDouble(maxSimulationTime), 2);
|
|
OsUtil.exec(xvfbCommand2);
|
|
OsUtil.exec(xvfbCommand2);
|
|
@@ -139,7 +133,7 @@ public class VideoService {
|
|
log.info("删除全部图片==" + removeAll);
|
|
log.info("删除全部图片==" + removeAll);
|
|
OsUtil.exec(removeAll);
|
|
OsUtil.exec(removeAll);
|
|
//6 将视频上传到 minio
|
|
//6 将视频上传到 minio
|
|
- MinioUtil.uploadFromFile(minioClient, videoTargetPathOfLinux, bucketName, videoTargetPathOfMinio);
|
|
|
|
|
|
+ MinioUtil.uploadFromFile(minioClient, videoTargetPathOfLinux, minioConfiguration.getBucketName(), videoTargetPathOfMinio);
|
|
log.info("上传成功:" + videoTargetPathOfMinio);
|
|
log.info("上传成功:" + videoTargetPathOfMinio);
|
|
OsUtil.kill(xvfbCommand2);
|
|
OsUtil.kill(xvfbCommand2);
|
|
//* -------------------------------- 删除临时文件 --------------------------------
|
|
//* -------------------------------- 删除临时文件 --------------------------------
|
|
@@ -158,7 +152,7 @@ public class VideoService {
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
private String generateXosc(String csvDirectoryPath, String xodrPath, String osgbPath, String projectId, String projectType) {
|
|
private String generateXosc(String csvDirectoryPath, String xodrPath, String osgbPath, String projectId, String projectType) {
|
|
//1 生成 xosc 文件
|
|
//1 生成 xosc 文件
|
|
- String command = pythonCommand + " " + csvDirectoryPath;
|
|
|
|
|
|
+ String command = constantConfiguration.getXoscGenerateCommand() + " " + csvDirectoryPath;
|
|
String execute = LinuxUtil.execute(command); // 执行命令后生成 xosc 到目录下
|
|
String execute = LinuxUtil.execute(command); // 执行命令后生成 xosc 到目录下
|
|
String oldXoscPath = csvDirectoryPath + oldXoscRelativePath; // 生成文件的路径是固定的
|
|
String oldXoscPath = csvDirectoryPath + oldXoscRelativePath; // 生成文件的路径是固定的
|
|
//2 调用修改xosc
|
|
//2 调用修改xosc
|