|
@@ -2,7 +2,7 @@ package com.css.simulation.resource.scheduler.infra.runnable;
|
|
|
|
|
|
import api.common.pojo.constants.DictConstants;
|
|
import api.common.pojo.constants.DictConstants;
|
|
import api.common.pojo.param.scene.SceneEvaluationComputeParam;
|
|
import api.common.pojo.param.scene.SceneEvaluationComputeParam;
|
|
-import api.common.pojo.param.scene.SceneImportParam;
|
|
|
|
|
|
+import api.common.pojo.param.scene.SceneEvaluationComputeSubParam;
|
|
import api.common.pojo.po.scene.SceneComplexityPO;
|
|
import api.common.pojo.po.scene.SceneComplexityPO;
|
|
import api.common.pojo.po.scene.SceneEvaluationRulePO;
|
|
import api.common.pojo.po.scene.SceneEvaluationRulePO;
|
|
import api.common.pojo.po.scene.SceneRiskPO;
|
|
import api.common.pojo.po.scene.SceneRiskPO;
|
|
@@ -26,7 +26,6 @@ import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.attribute.PosixFilePermission;
|
|
import java.nio.file.attribute.PosixFilePermission;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
-import java.util.List;
|
|
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
|
import static api.common.pojo.enums.SceneEvaluationEnum.matchLevelEnumByLevel;
|
|
import static api.common.pojo.enums.SceneEvaluationEnum.matchLevelEnumByLevel;
|
|
@@ -38,22 +37,17 @@ import static api.common.pojo.enums.SceneEvaluationEnum.matchLevelEnumByLevel;
|
|
@Slf4j
|
|
@Slf4j
|
|
public class SceneEvaluationComputeRunnable implements Runnable {
|
|
public class SceneEvaluationComputeRunnable implements Runnable {
|
|
|
|
|
|
- private final String linuxTempPath;
|
|
|
|
- private final SceneImportParam param;
|
|
|
|
- private final String bucketName;
|
|
|
|
- private final List<SceneEvaluationComputeParam> sceneEvaluationComputeParams;
|
|
|
|
|
|
+ private final SceneEvaluationComputeParam sceneEvaluationComputeParam;
|
|
|
|
|
|
- public SceneEvaluationComputeRunnable(SceneImportParam param, List<SceneEvaluationComputeParam> sceneEvaluationComputeParams, String linuxTempPath, String bucketName) {
|
|
|
|
- this.param = param;
|
|
|
|
- this.sceneEvaluationComputeParams = sceneEvaluationComputeParams;
|
|
|
|
- this.linuxTempPath = linuxTempPath;
|
|
|
|
- this.bucketName = bucketName;
|
|
|
|
|
|
+ public SceneEvaluationComputeRunnable(SceneEvaluationComputeParam sceneEvaluationComputeParam) {
|
|
|
|
+ this.sceneEvaluationComputeParam = sceneEvaluationComputeParam;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void run() {
|
|
public void run() {
|
|
- String ruleId = param.getSceneEvaluationRuleId();
|
|
|
|
|
|
+ String ruleId = sceneEvaluationComputeParam.getSceneEvaluationRuleId();
|
|
log.info("开始执行线程:" + ruleId);
|
|
log.info("开始执行线程:" + ruleId);
|
|
|
|
+ String bucketName = sceneEvaluationComputeParam.getBucketName();
|
|
SceneEvaluationRuleMapper sceneEvaluationRuleMapper = ApplicationContextAwareImpl.getApplicationContext().getBean(SceneEvaluationRuleMapper.class);
|
|
SceneEvaluationRuleMapper sceneEvaluationRuleMapper = ApplicationContextAwareImpl.getApplicationContext().getBean(SceneEvaluationRuleMapper.class);
|
|
SceneComplexityMapper sceneComplexityMapper = ApplicationContextAwareImpl.getApplicationContext().getBean(SceneComplexityMapper.class);
|
|
SceneComplexityMapper sceneComplexityMapper = ApplicationContextAwareImpl.getApplicationContext().getBean(SceneComplexityMapper.class);
|
|
SceneRiskMapper sceneRiskMapper = ApplicationContextAwareImpl.getApplicationContext().getBean(SceneRiskMapper.class);
|
|
SceneRiskMapper sceneRiskMapper = ApplicationContextAwareImpl.getApplicationContext().getBean(SceneRiskMapper.class);
|
|
@@ -66,7 +60,7 @@ public class SceneEvaluationComputeRunnable implements Runnable {
|
|
}
|
|
}
|
|
log.info("场景评价规则为:" + sceneEvaluationRulePO);
|
|
log.info("场景评价规则为:" + sceneEvaluationRulePO);
|
|
// 1 判断有没有用户目录,没有则复制
|
|
// 1 判断有没有用户目录,没有则复制
|
|
- String evaluationDirectoryOfUser = linuxTempPath + "scene/evaluation/" + sceneEvaluationComputeParams.get(0).getTaskId() + "/";
|
|
|
|
|
|
+ String evaluationDirectoryOfUser = sceneEvaluationComputeParam.getLinuxTempPath() + "scene/evaluation/" + sceneEvaluationComputeParam.getTaskId() + "/";
|
|
String scriptsPath = evaluationDirectoryOfUser + "scripts";
|
|
String scriptsPath = evaluationDirectoryOfUser + "scripts";
|
|
if (!new File(evaluationDirectoryOfUser).exists()) {
|
|
if (!new File(evaluationDirectoryOfUser).exists()) {
|
|
// 1 将场景评价规则脚本保存到 script 目录
|
|
// 1 将场景评价规则脚本保存到 script 目录
|
|
@@ -99,9 +93,9 @@ public class SceneEvaluationComputeRunnable implements Runnable {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
String scenePathFather = evaluationDirectoryOfUser + "scene/";
|
|
String scenePathFather = evaluationDirectoryOfUser + "scene/";
|
|
- for (SceneEvaluationComputeParam sceneEvaluationComputeParam : sceneEvaluationComputeParams) {
|
|
|
|
|
|
+ for (SceneEvaluationComputeSubParam sceneEvaluationComputeSubParam : sceneEvaluationComputeParam.getSceneEvaluationComputeSubParam()) {
|
|
// 创建场景路径
|
|
// 创建场景路径
|
|
- String scenePath = scenePathFather + sceneEvaluationComputeParam.getSceneId();
|
|
|
|
|
|
+ String scenePath = scenePathFather + sceneEvaluationComputeSubParam.getSceneId();
|
|
if (!new File(scenePath).exists()) {
|
|
if (!new File(scenePath).exists()) {
|
|
FileUtil.createDirectory(scenePath);
|
|
FileUtil.createDirectory(scenePath);
|
|
} else {
|
|
} else {
|
|
@@ -110,27 +104,27 @@ public class SceneEvaluationComputeRunnable implements Runnable {
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.COMPLEXITY)) {
|
|
if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.COMPLEXITY)) {
|
|
- if (StringUtil.isEmpty(sceneEvaluationComputeParam.getSceneXODRPath())
|
|
|
|
- || StringUtil.isEmpty(sceneEvaluationComputeParam.getSceneXOSCPath())) {
|
|
|
|
|
|
+ if (StringUtil.isEmpty(sceneEvaluationComputeSubParam.getSceneXODRPath())
|
|
|
|
+ || StringUtil.isEmpty(sceneEvaluationComputeSubParam.getSceneXOSCPath())) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
// 计算复杂度,根据场景 id 获取场景信息,下载 osc odr
|
|
// 计算复杂度,根据场景 id 获取场景信息,下载 osc odr
|
|
- String scenarioOsc = sceneEvaluationComputeParam.getSceneXOSCPath();
|
|
|
|
|
|
+ String scenarioOsc = sceneEvaluationComputeSubParam.getSceneXOSCPath();
|
|
String[] splitXosc = scenarioOsc.split("/");
|
|
String[] splitXosc = scenarioOsc.split("/");
|
|
String xoscName = splitXosc[splitXosc.length - 1];
|
|
String xoscName = splitXosc[splitXosc.length - 1];
|
|
- MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeParam.getSceneXOSCPath(), scenePath + "/" + xoscName);
|
|
|
|
|
|
+ MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeSubParam.getSceneXOSCPath(), scenePath + "/" + xoscName);
|
|
|
|
|
|
- String scenarioOdr = sceneEvaluationComputeParam.getSceneXODRPath();
|
|
|
|
|
|
+ String scenarioOdr = sceneEvaluationComputeSubParam.getSceneXODRPath();
|
|
String[] splitXodr = scenarioOdr.split("/");
|
|
String[] splitXodr = scenarioOdr.split("/");
|
|
String xodrName = splitXodr[splitXodr.length - 1];
|
|
String xodrName = splitXodr[splitXodr.length - 1];
|
|
- MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeParam.getSceneXODRPath(), scenePath + "/" + xodrName);
|
|
|
|
|
|
+ MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeSubParam.getSceneXODRPath(), scenePath + "/" + xodrName);
|
|
} else if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.RISK)) {
|
|
} else if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.RISK)) {
|
|
- if (StringUtil.isEmpty(sceneEvaluationComputeParam.getEvaluationPath())) {
|
|
|
|
|
|
+ if (StringUtil.isEmpty(sceneEvaluationComputeSubParam.getEvaluationPath())) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
// 计算危险度 从 minio path 下载 csv (ego 和 sensors)
|
|
// 计算危险度 从 minio path 下载 csv (ego 和 sensors)
|
|
- MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeParam.getEvaluationPath() + "/Ego.csv", scenePath + "/Ego.csv");
|
|
|
|
- MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeParam.getEvaluationPath() + "/evaluation.csv", scenePath + "/evaluation.csv");
|
|
|
|
|
|
+ MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeSubParam.getEvaluationPath() + "/Ego.csv", scenePath + "/Ego.csv");
|
|
|
|
+ MinioUtil.downloadToFile(minioClient, bucketName, sceneEvaluationComputeSubParam.getEvaluationPath() + "/evaluation.csv", scenePath + "/evaluation.csv");
|
|
} else {
|
|
} else {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -140,7 +134,7 @@ public class SceneEvaluationComputeRunnable implements Runnable {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
String sceneEvaluationCommand;
|
|
String sceneEvaluationCommand;
|
|
- if (StringUtils.equals(sceneEvaluationComputeParams.get(0).getComputeType(), DictConstants.COMPLEXITY)) {
|
|
|
|
|
|
+ if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), DictConstants.COMPLEXITY)) {
|
|
sceneEvaluationCommand = pyMainPath + " " + scenePathFather + " complexity";
|
|
sceneEvaluationCommand = pyMainPath + " " + scenePathFather + " complexity";
|
|
} else {
|
|
} else {
|
|
sceneEvaluationCommand = pyMainPath + " " + scenePathFather + " criticality";
|
|
sceneEvaluationCommand = pyMainPath + " " + scenePathFather + " criticality";
|
|
@@ -170,11 +164,11 @@ public class SceneEvaluationComputeRunnable implements Runnable {
|
|
}
|
|
}
|
|
sceneEvaluationResult = sb.toString();
|
|
sceneEvaluationResult = sb.toString();
|
|
log.info("场景评价结束,结果为:" + sceneEvaluationResult);
|
|
log.info("场景评价结束,结果为:" + sceneEvaluationResult);
|
|
- for (SceneEvaluationComputeParam sceneEvaluationComputeParam : sceneEvaluationComputeParams) {
|
|
|
|
|
|
+ for (SceneEvaluationComputeSubParam sceneEvaluationComputeSubParam : sceneEvaluationComputeParam.getSceneEvaluationComputeSubParam()) {
|
|
// 读文件
|
|
// 读文件
|
|
StringBuilder result = new StringBuilder();
|
|
StringBuilder result = new StringBuilder();
|
|
try {
|
|
try {
|
|
- FileInputStream fileInputStream = new FileInputStream(scenePathFather + sceneEvaluationComputeParam.getSceneId() + "/scenario_evaluation.json");
|
|
|
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(scenePathFather + sceneEvaluationComputeSubParam.getSceneId() + "/scenario_evaluation.json");
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
|
|
|
|
|
|
String line;
|
|
String line;
|
|
@@ -198,9 +192,9 @@ public class SceneEvaluationComputeRunnable implements Runnable {
|
|
String complexity = rootNode.path("复杂度").asText();
|
|
String complexity = rootNode.path("复杂度").asText();
|
|
String complexityLevel = rootNode.path("复杂度等级").asText();
|
|
String complexityLevel = rootNode.path("复杂度等级").asText();
|
|
SceneComplexityPO sceneComplexityPO = new SceneComplexityPO();
|
|
SceneComplexityPO sceneComplexityPO = new SceneComplexityPO();
|
|
- sceneComplexityPO.setSceneId(sceneEvaluationComputeParam.getSceneId());
|
|
|
|
|
|
+ sceneComplexityPO.setSceneId(sceneEvaluationComputeSubParam.getSceneId());
|
|
sceneComplexityPO.setComplexityId(StringUtil.getRandomUUID());
|
|
sceneComplexityPO.setComplexityId(StringUtil.getRandomUUID());
|
|
- sceneComplexityPO.setSceneType(sceneEvaluationComputeParam.getSceneType());
|
|
|
|
|
|
+ sceneComplexityPO.setSceneType(sceneEvaluationComputeSubParam.getSceneType());
|
|
sceneComplexityPO.setRuleId(ruleId);
|
|
sceneComplexityPO.setRuleId(ruleId);
|
|
sceneComplexityPO.setTaskId(sceneEvaluationComputeParam.getTaskId());
|
|
sceneComplexityPO.setTaskId(sceneEvaluationComputeParam.getTaskId());
|
|
sceneComplexityPO.setComplexity(complexity);
|
|
sceneComplexityPO.setComplexity(complexity);
|
|
@@ -213,9 +207,9 @@ public class SceneEvaluationComputeRunnable implements Runnable {
|
|
String risk = rootNode.path("危险度").asText();
|
|
String risk = rootNode.path("危险度").asText();
|
|
String riskLevel = rootNode.path("危险度等级").asText();
|
|
String riskLevel = rootNode.path("危险度等级").asText();
|
|
SceneRiskPO sceneRiskPO = new SceneRiskPO();
|
|
SceneRiskPO sceneRiskPO = new SceneRiskPO();
|
|
- sceneRiskPO.setSceneId(sceneEvaluationComputeParam.getSceneId());
|
|
|
|
|
|
+ sceneRiskPO.setSceneId(sceneEvaluationComputeSubParam.getSceneId());
|
|
sceneRiskPO.setRuleId(StringUtil.getRandomUUID());
|
|
sceneRiskPO.setRuleId(StringUtil.getRandomUUID());
|
|
- sceneRiskPO.setSceneType(sceneEvaluationComputeParam.getSceneType());
|
|
|
|
|
|
+ sceneRiskPO.setSceneType(sceneEvaluationComputeSubParam.getSceneType());
|
|
sceneRiskPO.setRuleId(ruleId);
|
|
sceneRiskPO.setRuleId(ruleId);
|
|
sceneRiskPO.setTaskId(sceneEvaluationComputeParam.getTaskId());
|
|
sceneRiskPO.setTaskId(sceneEvaluationComputeParam.getTaskId());
|
|
sceneRiskPO.setRisk(risk);
|
|
sceneRiskPO.setRisk(risk);
|
|
@@ -226,7 +220,7 @@ public class SceneEvaluationComputeRunnable implements Runnable {
|
|
sceneRiskMapper.saveSceneRisk(sceneRiskPO);
|
|
sceneRiskMapper.saveSceneRisk(sceneRiskPO);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("场景" + sceneEvaluationComputeParam.getSceneId() + " 的场景评价失败:", e);
|
|
|
|
|
|
+ log.error("场景" + sceneEvaluationComputeSubParam.getSceneId() + " 的场景评价失败:", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 删除临时文件
|
|
// 删除临时文件
|