|
@@ -22,6 +22,7 @@ import lombok.SneakyThrows;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.http.client.config.RequestConfig;
|
|
import org.apache.http.client.config.RequestConfig;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
+import org.apache.sshd.client.SshClient;
|
|
import org.apache.sshd.client.session.ClientSession;
|
|
import org.apache.sshd.client.session.ClientSession;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -124,17 +125,21 @@ public class TaskService {
|
|
}
|
|
}
|
|
projectMapper.updateProjectState(projectId, DictConstants.PROJECT_COMPLETED); // 修改该 project 的状态为已完成
|
|
projectMapper.updateProjectState(projectId, DictConstants.PROJECT_COMPLETED); // 修改该 project 的状态为已完成
|
|
LinuxUtil.execute("kubectl delete job project-" + projectId);
|
|
LinuxUtil.execute("kubectl delete job project-" + projectId);
|
|
- ClientSession sessionKafka = SshUtil.getSession(hostnameKafka, usernameKafka, passwordKafka);
|
|
|
|
-// String topicDeleteCommand = StringUtil.replace(kafkaDeleteCommand,"topicName",projectId);
|
|
|
|
- String topicDeleteCommand = StringUtil.replace(kafkaDeleteCommand, "topicName", "test");
|
|
|
|
|
|
+ SshClient clientKafka = SshUtil.getClient();
|
|
|
|
+ ClientSession sessionKafka = SshUtil.getSession(clientKafka, hostnameKafka, usernameKafka, passwordKafka);
|
|
|
|
+ String topicDeleteCommand = StringUtil.replace(kafkaDeleteCommand, "topicName", projectId);
|
|
SshUtil.execute(sessionKafka, topicDeleteCommand);
|
|
SshUtil.execute(sessionKafka, topicDeleteCommand);
|
|
|
|
+ SshUtil.stop(clientKafka, sessionKafka);
|
|
List<TaskPO> taskList = taskMapper.selectTaskListByProjectId(projectId); // 所有任务信息
|
|
List<TaskPO> taskList = taskMapper.selectTaskListByProjectId(projectId); // 所有任务信息
|
|
|
|
+ taskIndexMapper.deleteFirstByProjectId(projectId);
|
|
|
|
+ taskIndexMapper.deleteLastByProjectId(projectId);
|
|
// -------------------------------- 查询叶子指标 --------------------------------
|
|
// -------------------------------- 查询叶子指标 --------------------------------
|
|
List<IndexTemplatePO> leafIndexTemplateList = indexTemplateMapper.selectLeafIndexWithRuleDetailsByPackageId(scenePackageId);
|
|
List<IndexTemplatePO> leafIndexTemplateList = indexTemplateMapper.selectLeafIndexWithRuleDetailsByPackageId(scenePackageId);
|
|
List<TaskIndexPO> leafTaskIndexList = new ArrayList<>();
|
|
List<TaskIndexPO> leafTaskIndexList = new ArrayList<>();
|
|
log.info("------- /state 共有 " + leafIndexTemplateList.size() + "个叶子节点!");
|
|
log.info("------- /state 共有 " + leafIndexTemplateList.size() + "个叶子节点!");
|
|
|
|
|
|
- ClientSession sessionScore = SshUtil.getSession(hostnameScore, usernameScore, passwordScore);
|
|
|
|
|
|
+ SshClient clientScore = SshUtil.getClient();
|
|
|
|
+ ClientSession sessionScore = SshUtil.getSession(clientScore, hostnameScore, usernameScore, passwordScore);
|
|
for (int i = 0; i < leafIndexTemplateList.size(); i++) {
|
|
for (int i = 0; i < leafIndexTemplateList.size(); i++) {
|
|
IndexTemplatePO indexTemplatePO = leafIndexTemplateList.get(i);
|
|
IndexTemplatePO indexTemplatePO = leafIndexTemplateList.get(i);
|
|
String indexId = indexTemplatePO.getIndexId();
|
|
String indexId = indexTemplatePO.getIndexId();
|
|
@@ -234,29 +239,14 @@ public class TaskService {
|
|
leafTaskIndex.setIsDeleted("0");
|
|
leafTaskIndex.setIsDeleted("0");
|
|
leafTaskIndexList.add(leafTaskIndex);
|
|
leafTaskIndexList.add(leafTaskIndex);
|
|
}
|
|
}
|
|
- SshUtil.stop(sessionScore);
|
|
|
|
-
|
|
|
|
- log.info("------- /state 根据每个指标的得分和权重算出 project 的总得分:" + leafIndexTemplateList);
|
|
|
|
- double totalScore = compute(leafIndexTemplateList);
|
|
|
|
- log.info("------- /state 总得分为:" + totalScore);
|
|
|
|
- // 保存分数
|
|
|
|
|
|
+ SshUtil.stop(clientScore, sessionScore);
|
|
// 保存任务分数
|
|
// 保存任务分数
|
|
taskManager.batchUpdateByScoreResult(taskList);
|
|
taskManager.batchUpdateByScoreResult(taskList);
|
|
- // 保存指标分数
|
|
|
|
|
|
+ // 保存末级指标分数
|
|
taskIndexManager.batchInsertLeafIndex(leafTaskIndexList);
|
|
taskIndexManager.batchInsertLeafIndex(leafTaskIndexList);
|
|
- // 保存总分数
|
|
|
|
- TaskIndexPO totalTaskIndex = TaskIndexPO.builder()
|
|
|
|
- .id(StringUtil.getRandomUUID())
|
|
|
|
- .pId(projectId)
|
|
|
|
- .target(scenePackageId)
|
|
|
|
- .score(totalScore)
|
|
|
|
- .build();
|
|
|
|
- totalTaskIndex.setCreateUserId(USER_ID);
|
|
|
|
- totalTaskIndex.setCreateTime(TimeUtil.getNowForMysql());
|
|
|
|
- totalTaskIndex.setModifyUserId(USER_ID);
|
|
|
|
- totalTaskIndex.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
|
- totalTaskIndex.setIsDeleted("0");
|
|
|
|
- taskIndexMapper.insertTotalIndex(totalTaskIndex);
|
|
|
|
|
|
+ // 保存一级指标分数
|
|
|
|
+ log.info("------- /state 根据每个指标的得分和权重算出各个一级指标的得分(即 project 对应的场景测试包下的一级指标)!");
|
|
|
|
+ computeFirst(leafIndexTemplateList, projectId);
|
|
|
|
|
|
// 调用 server 的接口,计算评价等级
|
|
// 调用 server 的接口,计算评价等级
|
|
String tokenUrl = tokenUri + "?grant_type=client_credentials"
|
|
String tokenUrl = tokenUri + "?grant_type=client_credentials"
|
|
@@ -285,19 +275,40 @@ public class TaskService {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public double compute(List<IndexTemplatePO> leaf) {
|
|
|
|
- double result = 0.0;
|
|
|
|
- Map<String, List<IndexTemplatePO>> groups = leaf.stream().collect(Collectors.groupingBy(IndexTemplatePO::getParentId));
|
|
|
|
- Set<String> parentIdSet = groups.keySet();
|
|
|
|
|
|
+ public void computeFirst(List<IndexTemplatePO> leaf, String projectId) {
|
|
|
|
+ Map<String, List<IndexTemplatePO>> parentIndexMap = leaf.stream().collect(Collectors.groupingBy(IndexTemplatePO::getParentId));
|
|
|
|
+ Set<String> parentIdSet = parentIndexMap.keySet();
|
|
|
|
+ List<String> parentIdList = CollectionUtil.setToList(parentIdSet);
|
|
log.info("------- /state 将叶子指标按父指标分组父指标集合为:" + parentIdSet);
|
|
log.info("------- /state 将叶子指标按父指标分组父指标集合为:" + parentIdSet);
|
|
- List<IndexTemplatePO> indexTemplatePOList = indexTemplateMapper.selectByIdList(CollectionUtil.setToList(parentIdSet));
|
|
|
|
- indexTemplatePOList.forEach(index1 -> {
|
|
|
|
- double sum = groups.get(index1.getIndexId()).stream().mapToDouble(index2 -> index2.getTempScore() * Double.parseDouble(index2.getWeight())).sum();
|
|
|
|
|
|
+ List<IndexTemplatePO> parentIndexList = indexTemplateMapper.selectByIdList(parentIdList);
|
|
|
|
+ // 计算父指标得分
|
|
|
|
+ parentIndexList.forEach(index1 -> {
|
|
|
|
+ double sum = parentIndexMap.get(index1.getIndexId()).stream().mapToDouble(index2 -> index2.getTempScore() * Double.parseDouble(index2.getWeight())).sum();
|
|
index1.setTempScore(sum);
|
|
index1.setTempScore(sum);
|
|
});
|
|
});
|
|
- if (indexTemplatePOList.size() > 1) {
|
|
|
|
- result = result + compute(indexTemplatePOList);
|
|
|
|
|
|
+ Iterator<IndexTemplatePO> parentIndexIterator = parentIndexList.iterator();
|
|
|
|
+ while (parentIndexIterator.hasNext()) {
|
|
|
|
+ IndexTemplatePO parentIndex = parentIndexIterator.next();
|
|
|
|
+ String parentId = parentIndex.getParentId();
|
|
|
|
+ String rootId = parentIndex.getRootId();
|
|
|
|
+ if (parentId.equals(rootId)) {
|
|
|
|
+ TaskIndexPO totalTaskIndex = TaskIndexPO.builder()
|
|
|
|
+ .id(StringUtil.getRandomUUID())
|
|
|
|
+ .pId(projectId)
|
|
|
|
+ .target(parentIndex.getIndexId())
|
|
|
|
+ .score(parentIndex.getTempScore())
|
|
|
|
+ .build();
|
|
|
|
+ totalTaskIndex.setCreateUserId(USER_ID);
|
|
|
|
+ totalTaskIndex.setCreateTime(TimeUtil.getNowForMysql());
|
|
|
|
+ totalTaskIndex.setModifyUserId(USER_ID);
|
|
|
|
+ totalTaskIndex.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
|
+ totalTaskIndex.setIsDeleted("0");
|
|
|
|
+ taskIndexMapper.insertTotalIndex(totalTaskIndex);
|
|
|
|
+ parentIndexIterator.remove();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (parentIndexList.size() > 1) {
|
|
|
|
+ computeFirst(parentIndexList, projectId);
|
|
}
|
|
}
|
|
- return result;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|