fix(任务中心): 全部停止时仅停止当前页的十个任务其他没停止

--bug=1008088 --user=王孝刚 [任务中心]-全部停止 仅停止当前页的十个任务其他没停止
https://www.tapd.cn/55049933/s/1070788
This commit is contained in:
wxg0103 2021-11-19 19:53:54 +08:00 committed by 刘瑞斌
parent e8b9a29092
commit a180146682
6 changed files with 122 additions and 47 deletions

View File

@ -6,5 +6,6 @@ import lombok.Data;
public class TaskRequest {
private String type;
private String reportId;
private String projectId;
}

View File

@ -275,14 +275,31 @@
</select>
<select id="selectPreviousReportByScenarioId" resultType="io.metersphere.base.domain.ApiScenarioReport">
select * from api_scenario_report
WHERE execute_type in ("Completed","Debug") and scenario_id=#{scenarioId} and id != #{nowId} ORDER BY create_time desc LIMIT 5,1
select *
from api_scenario_report
WHERE execute_type in ("Completed", "Debug")
and scenario_id = #{scenarioId}
and id != #{nowId}
ORDER BY create_time desc LIMIT 5, 1
</select>
<select id="countByApiScenarioId" resultType="io.metersphere.dto.ApiReportCountDTO">
SELECT scenario_id AS id, count(id) AS countNum
FROM api_scenario_report
WHERE scenario_id is not null GROUP BY scenario_id;
WHERE scenario_id is not null
GROUP BY scenario_id;
</select>
<select id="selectReportByProjectId" resultType="io.metersphere.base.domain.ApiScenarioReport">
select t.*
from api_scenario_report t
left join `user` t1 ON t.user_id = t1.id
left join test_resource_pool t2 on t.actuator = t2.id
where to_days(FROM_UNIXTIME(t.create_time / 1000)) = to_days(now())
and t.execute_type !='Debug' and t.execute_type !='Marge' and t.project_id=#{projectId}
and t.`STATUS` in ('running'
, 'waiting')
</select>
<select id="selectStatusByIds" resultType="io.metersphere.base.domain.ApiScenarioReport">

View File

@ -1,5 +1,6 @@
package io.metersphere.base.mapper.ext;
import io.metersphere.base.domain.LoadTestReport;
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
import io.metersphere.dto.DashboardTestDTO;
import io.metersphere.dto.ReportDTO;
@ -19,4 +20,6 @@ public interface ExtLoadTestReportMapper {
List<String> selectResourceId(@Param("reportId") String reportId);
void updateJmxContentIfAbsent(LoadTestReportWithBLOBs record);
List<LoadTestReport> selectReportByProjectId(String projectId);
}

View File

@ -149,7 +149,8 @@
FROM load_test
JOIN project ON load_test.project_id = project.id
WHERE workspace_id = #{workspaceId,jdbcType=VARCHAR})
AND create_time > #{startTimestamp}
AND create_time
> #{startTimestamp}
GROUP BY x
</select>
@ -159,11 +160,22 @@
WHERE report_id = #{reportId}
GROUP BY resource_id
</select>
<select id="selectReportByProjectId" resultType="io.metersphere.base.domain.LoadTestReport">
select t.*
from load_test_report t
left join `user` t1 ON t.user_id = t1.id
left join test_resource_pool t2 on t.test_resource_pool_id = t2.id
where to_days(FROM_UNIXTIME(t.create_time / 1000)) = to_days(now())
and t.project_id = #{projectId}
and t.status = 'running'
</select>
<update id="updateJmxContentIfAbsent">
update load_test_report
set jmx_content = #{jmxContent,jdbcType=VARCHAR}
WHERE id = #{id,jdbcType=VARCHAR} and jmx_content is null
WHERE id = #{id,jdbcType=VARCHAR}
and jmx_content is null
</update>
</mapper>

View File

@ -10,6 +10,9 @@ import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
import io.metersphere.base.mapper.ApiScenarioReportMapper;
import io.metersphere.base.mapper.TestResourceMapper;
import io.metersphere.base.mapper.TestResourcePoolMapper;
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
import io.metersphere.base.mapper.ext.ExtTaskMapper;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.NodeDTO;
@ -46,6 +49,12 @@ public class TaskService {
private TestResourcePoolMapper testResourcePoolMapper;
@Resource
private TestResourceMapper testResourceMapper;
@Resource
private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper;
@Resource
private ExtApiScenarioReportMapper extApiScenarioReportMapper;
@Resource
private ExtLoadTestReportMapper extLoadTestReportMapper;
public List<TaskCenterDTO> getTasks(TaskCenterRequest request) {
if (StringUtils.isEmpty(request.getProjectId())) {
@ -102,6 +111,7 @@ public class TaskService {
Map<String, List<String>> poolMap = new HashMap<>();
for (TaskRequest request : reportIds) {
String actuator = null;
if (StringUtils.isNotEmpty(request.getReportId())) {
if (StringUtils.equals(request.getType(), "API")) {
ApiDefinitionExecResult result = apiDefinitionExecResultMapper.selectByPrimaryKey(request.getReportId());
if (result != null) {
@ -120,6 +130,51 @@ public class TaskService {
} else if (StringUtils.equals(request.getType(), "PERFORMANCE")) {
performanceTestService.stopTest(request.getReportId(), false);
}
extracted(poolMap, request, actuator);
} else {
if (StringUtils.equals(request.getType(), "API")) {
List<ApiDefinitionExecResult> result = extApiDefinitionExecResultMapper.selectApiResultByProjectId(request.getProjectId());
if (CollectionUtils.isNotEmpty(result)) {
for (ApiDefinitionExecResult item : result) {
item.setStatus("STOP");
apiDefinitionExecResultMapper.updateByPrimaryKeySelective(item);
actuator = item.getActuator();
MessageCache.caseExecResourceLock.remove(item.getId());
request.setReportId(item.getId());
extracted(poolMap, request, actuator);
}
}
} else if (StringUtils.equals(request.getType(), "SCENARIO")) {
List<ApiScenarioReport> reports = extApiScenarioReportMapper.selectReportByProjectId(request.getProjectId());
if (CollectionUtils.isNotEmpty(reports)) {
for (ApiScenarioReport report : reports) {
report.setStatus("STOP");
apiScenarioReportMapper.updateByPrimaryKeySelective(report);
actuator = report.getActuator();
request.setReportId(report.getId());
extracted(poolMap, request, actuator);
}
}
} else if (StringUtils.equals(request.getType(), "PERFORMANCE")) {
List<LoadTestReport> loadTestReports = extLoadTestReportMapper.selectReportByProjectId(request.getProjectId());
if (CollectionUtils.isNotEmpty(loadTestReports)) {
for (LoadTestReport loadTestReport : loadTestReports) {
performanceTestService.stopTest(loadTestReport.getId(), false);
request.setReportId(loadTestReport.getId());
extracted(poolMap, request, actuator);
}
}
}
}
if (!poolMap.isEmpty()) {
this.send(poolMap);
}
}
}
return "SUCCESS";
}
private void extracted(Map<String, List<String>> poolMap, TaskRequest request, String actuator) {
if (StringUtils.isNotEmpty(actuator) && !StringUtils.equals(actuator, "LOCAL")) {
if (poolMap.containsKey(actuator)) {
poolMap.get(actuator).add(request.getReportId());
@ -134,10 +189,4 @@ public class TaskService {
MessageCache.cache.remove(request.getReportId());
MessageCache.terminationOrderDeque.add(request.getReportId());
}
if (!poolMap.isEmpty()) {
this.send(poolMap);
}
}
return "SUCCESS";
}
}

View File

@ -230,16 +230,9 @@ export default {
let request = {type: row.executionModule, reportId: row.id};
array = [request];
} else {
this.taskData.forEach(item => {
if (this.showStop(item.executionStatus)) {
let request = {type: item.executionModule, reportId: item.id};
array.push(request);
}
});
}
if (array.length === 0) {
this.$warning("没有需要停止的任务");
return;
array.push({type: 'API', projectId: getCurrentProjectID()});
array.push({type: 'SCENARIO', projectId: getCurrentProjectID()});
array.push({type: 'PERFORMANCE', projectId: getCurrentProjectID()});
}
this.$post('/api/automation/stop/batch', array, response => {
this.$success(this.$t('report.test_stop_success'));