Merge remote-tracking branch 'origin/master'
# Conflicts: # src/main/java/com/realtime/protection/server/rule/dynamicrule/DynamicRuleControllerApi.java # src/main/java/com/realtime/protection/server/rule/dynamicrule/DynamicRuleService.java # src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleControllerApi.java # src/main/resources/mappers/StaticRuleMapper.xml # src/test/java/com/realtime/protection/server/rule/dynamic/DynamicRuleServiceTest.java # src/test/java/com/realtime/protection/server/rule/staticrule/StaticRuleServiceTest.java
This commit is contained in:
@@ -57,7 +57,7 @@ public class CommandService {
|
||||
commandBatch.clear();
|
||||
}
|
||||
|
||||
log.debug(String.format("create all the commands from task(%d), rule(%d)",
|
||||
log.debug(String.format("在task(%d)和rule(%d)中构建了全部指令",
|
||||
info.getTaskId(), info.getRuleId()));
|
||||
return null;
|
||||
};
|
||||
@@ -68,6 +68,7 @@ public class CommandService {
|
||||
public void createCommand(TaskCommandInfo commandInfo) throws DorisStartException {
|
||||
try {
|
||||
sqlSessionWrapper.startBatchSession(CommandMapper.class, createCommandBatchFunction, commandInfo);
|
||||
taskService.changeTaskStatus(commandInfo.getTaskId(), StateEnum.RUNNING.getStateNum());
|
||||
} catch (Exception e) {
|
||||
throw new DorisStartException(e, commandInfo.getTaskId());
|
||||
}
|
||||
@@ -92,7 +93,10 @@ public class CommandService {
|
||||
try {
|
||||
sqlSessionWrapper.startBatchSession(CommandMapper.class, function, taskCommandInfos);
|
||||
} catch (Exception e) {
|
||||
TaskCommandInfo info = taskCommandInfos.get(0);
|
||||
TaskCommandInfo info = null;
|
||||
if (taskCommandInfos != null) {
|
||||
info = taskCommandInfos.get(0);
|
||||
}
|
||||
Long taskId = null;
|
||||
if (info != null) {
|
||||
taskId = info.getTaskId();
|
||||
|
||||
@@ -35,7 +35,7 @@ public class ProjectObjectDataListener implements ReadListener<ProtectObject> {
|
||||
private void saveData() {
|
||||
Boolean success = protectObjectService.newProtectObjects(cachedDataList);
|
||||
if (!success) {
|
||||
throw new RuntimeException("Error reading data in /proobj/new");
|
||||
throw new RuntimeException("在/proobj/upload中读取数据时出现了错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ProtectObjectController implements ProtectObjectControllerApi {
|
||||
@Override
|
||||
@PostMapping("/upload")
|
||||
public ResponseResult uploadFile(
|
||||
@NotNull(message = "uploadFile cannot be null. ") MultipartFile uploadFile
|
||||
@NotNull(message = "uploadFile字段不能为空") MultipartFile uploadFile
|
||||
) throws IOException {
|
||||
EasyExcel.read(uploadFile.getInputStream(), ProtectObject.class,
|
||||
new ProjectObjectDataListener(protectObjectService)).sheet().doRead();
|
||||
@@ -85,6 +85,10 @@ public class ProtectObjectController implements ProtectObjectControllerApi {
|
||||
@GetMapping("/{protectObjectId}/query")
|
||||
public ResponseResult queryProtectObject(@PathVariable Integer protectObjectId) throws IllegalAccessException {
|
||||
ProtectObject protectObject = protectObjectService.queryProtectObject(protectObjectId);
|
||||
if (protectObject == null) {
|
||||
return ResponseResult.invalid()
|
||||
.setMessage("无效的防护对象ID,也许该ID指定的防护对象不存在?");
|
||||
}
|
||||
return ResponseResult.ok()
|
||||
.setDataMap(EntityUtils.entityToMap(protectObject));
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public interface ProtectObjectControllerApi {
|
||||
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "上传文件")
|
||||
)
|
||||
ResponseResult uploadFile(
|
||||
@NotNull(message = "uploadFile cannot be null. ") MultipartFile uploadFile
|
||||
@NotNull(message = "uploadFile字段不能为空") MultipartFile uploadFile
|
||||
) throws IOException;
|
||||
|
||||
@GetMapping("/download")
|
||||
|
||||
@@ -102,7 +102,7 @@ public class ProtectObjectService {
|
||||
public Map<String, Object> changeProtectObjectAuditStatus(Integer protectObjectId, Integer auditStatus) {
|
||||
Integer originalAuditStatus = protectObjectMapper.queryProtectObject(protectObjectId).getProtectObjectAuditStatus();
|
||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||
throw new IllegalArgumentException("invalid audit status");
|
||||
throw new IllegalArgumentException("无效的审核状态");
|
||||
}
|
||||
Boolean success = protectObjectMapper.changeProtectObjectAuditStatus(protectObjectId, auditStatus);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TemplateController implements TemplateControllerApi {
|
||||
Template template = templateService.queryTemplate(templateId);
|
||||
if (template == null) {
|
||||
return ResponseResult.invalid()
|
||||
.setMessage("invalid templateId, maybe this template doesn't exist?");
|
||||
.setMessage("无效的策略模板ID,也许该模板不存在?");
|
||||
}
|
||||
return ResponseResult.ok()
|
||||
.setDataMap(EntityUtils.entityToMap(template));
|
||||
|
||||
@@ -95,7 +95,7 @@ public class StaticRuleController implements StaticRuleControllerApi {
|
||||
@Override
|
||||
@PostMapping("/{id}/update")
|
||||
public ResponseResult updateStaticRule(@PathVariable Integer id,
|
||||
@RequestBody @Valid StaticRuleObject object) {
|
||||
@RequestBody @Valid StaticRuleObject object) {
|
||||
log.info("修改静态规则: {}", object);
|
||||
//调用service修改
|
||||
Integer updateValid = staticRuleService.updateStaticRule(id, object);
|
||||
|
||||
@@ -99,7 +99,7 @@ public class TaskController implements TaskControllerApi {
|
||||
|
||||
@Override
|
||||
@GetMapping("/{taskId}/running/{stateNum}")
|
||||
public ResponseResult changeTaskStatus(@PathVariable @NotNull Integer stateNum,
|
||||
public ResponseResult changeTaskStatus(@PathVariable @NotNull @Min(0) @Max(6) Integer stateNum,
|
||||
@PathVariable @NotNull Long taskId) throws DorisStartException {
|
||||
return ResponseResult.ok()
|
||||
.setData("task_id", taskId)
|
||||
|
||||
@@ -160,6 +160,6 @@ public interface TaskControllerApi {
|
||||
@Parameter(name = "stateNum", description = "任务状态编号任务状态(0为未启动,1为生成中,2为运行中,3为暂停中,4为已停止,5为已结束,6为失败)")
|
||||
}
|
||||
)
|
||||
ResponseResult changeTaskStatus(@PathVariable @NotNull Integer stateNum,
|
||||
ResponseResult changeTaskStatus(@PathVariable @NotNull @Min(0) @Max(6) Integer stateNum,
|
||||
@PathVariable @NotNull Long taskId) throws DorisStartException;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class TaskService {
|
||||
public Boolean changeTaskAuditStatus(Long taskId, Integer taskAuditStatus) {
|
||||
Integer originalAuditStatus = taskMapper.queryTaskAuditStatus(taskId);
|
||||
if (originalAuditStatus == null) {
|
||||
throw new IllegalArgumentException("cannot find audit status of task " + taskId + ", maybe task doesn't exist?");
|
||||
throw new IllegalArgumentException("无法找到任务ID为" + taskId + "的任务,也许任务不存在?");
|
||||
}
|
||||
|
||||
if (AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(taskAuditStatus))
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.realtime.protection.server.task.TaskService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class StateChangeService {
|
||||
@@ -22,9 +24,14 @@ public class StateChangeService {
|
||||
|
||||
@DSTransactional
|
||||
public Boolean changeState(Integer stateNum, Long taskId) throws DorisStartException {
|
||||
if (Objects.equals(stateNum, StateEnum.GENERATING.getStateNum()) ||
|
||||
Objects.equals(stateNum, StateEnum.FAILED.getStateNum())) {
|
||||
throw new IllegalArgumentException("非法任务状态:" + StateEnum.getStateByNum(stateNum));
|
||||
}
|
||||
|
||||
Integer originalStateNum = taskService.queryTaskStatus(taskId);
|
||||
if (originalStateNum == null) {
|
||||
throw new IllegalArgumentException("cannot find status of task " + taskId + ", maybe task doesn't exist?");
|
||||
throw new IllegalArgumentException("无法找到" + taskId + "的任务状态,也许任务ID不存在?");
|
||||
}
|
||||
|
||||
State originalState = StateEnum.getStateByNum(originalStateNum);
|
||||
@@ -39,7 +46,7 @@ public class StateChangeService {
|
||||
return false;
|
||||
}
|
||||
|
||||
log.debug(String.format("successfully let task(%d) change state from %s to %s",
|
||||
log.debug(String.format("成功使得task(%d)从%s切换为%s",
|
||||
taskId,
|
||||
originalState.getClass().getSimpleName(),
|
||||
newState.getClass().getSimpleName()));
|
||||
|
||||
@@ -16,13 +16,13 @@ public class StateHandler {
|
||||
Task task = taskService.queryTask(taskId);
|
||||
|
||||
if (task == null) {
|
||||
throw new IllegalArgumentException("invalid task id");
|
||||
throw new IllegalArgumentException("无效task_id,因为无法找到对应任务");
|
||||
}
|
||||
|
||||
Integer taskAuditStatus = task.getTaskAuditStatus();
|
||||
|
||||
if (taskAuditStatus == null) {
|
||||
throw new IllegalArgumentException("invalid task id, because task_audit_status is null");
|
||||
throw new IllegalArgumentException("无效的task_id,因为task_audit_status为空");
|
||||
}
|
||||
|
||||
// 如果审核状态不为已通过审核,则无效
|
||||
@@ -74,7 +74,7 @@ public class StateHandler {
|
||||
// 如果未能获取staticTaskCommandInfos,需要报错
|
||||
List<TaskCommandInfo> staticTaskCommandInfos = taskService.getStaticCommandInfos(taskId);
|
||||
if (staticTaskCommandInfos == null || staticTaskCommandInfos.isEmpty()) {
|
||||
throw new IllegalArgumentException("static rules are empty, need to choose at least one static rule");
|
||||
throw new IllegalArgumentException("静态规则列表为空,请至少选择一个静态规则以启动任务");
|
||||
}
|
||||
|
||||
commandService.createCommands(staticTaskCommandInfos);
|
||||
|
||||
@@ -38,7 +38,7 @@ public class WhiteListController implements WhiteListControllerApi {
|
||||
//post
|
||||
@Override
|
||||
@PostMapping("/upload")
|
||||
public ResponseResult uploadFile(MultipartFile uploadFile) throws IOException {
|
||||
public ResponseResult uploadFile(MultipartFile uploadFile) throws IOException {
|
||||
EasyExcel.read(uploadFile.getInputStream(), WhiteListObject.class,
|
||||
new WhiteListDataListener(whiteListService)).sheet().doRead();
|
||||
return ResponseResult.ok();
|
||||
|
||||
@@ -34,7 +34,7 @@ public interface WhiteListControllerApi {
|
||||
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "白名单信息")
|
||||
)
|
||||
ResponseResult newWhitelistObject(@RequestBody WhiteListObject object) ;
|
||||
ResponseResult newWhitelistObject(@RequestBody WhiteListObject object);
|
||||
|
||||
@Operation(
|
||||
summary = "批量导入白名单",
|
||||
@@ -51,7 +51,7 @@ public interface WhiteListControllerApi {
|
||||
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "Excel文件")
|
||||
)
|
||||
ResponseResult uploadFile(MultipartFile uploadFile) throws IOException ;
|
||||
ResponseResult uploadFile(MultipartFile uploadFile) throws IOException;
|
||||
|
||||
@Operation(
|
||||
summary = "下载白名单模板",
|
||||
@@ -66,7 +66,7 @@ public interface WhiteListControllerApi {
|
||||
)
|
||||
}
|
||||
)
|
||||
void downloadTemplate(HttpServletResponse response) throws IOException ;
|
||||
void downloadTemplate(HttpServletResponse response) throws IOException;
|
||||
|
||||
@Operation(
|
||||
summary = "查询白名单",
|
||||
@@ -88,9 +88,9 @@ public interface WhiteListControllerApi {
|
||||
}
|
||||
)
|
||||
ResponseResult queryWhiteListObject(@RequestParam(value = "whiteobj_name", required = false) String whiteListName,
|
||||
@RequestParam(value = "whiteobj_id", required = false) Integer whiteListId,
|
||||
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(value = "page_size", defaultValue = "10") Integer pageSize) ;
|
||||
@RequestParam(value = "whiteobj_id", required = false) Integer whiteListId,
|
||||
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(value = "page_size", defaultValue = "10") Integer pageSize);
|
||||
|
||||
@Operation(
|
||||
summary = "查询单个白名单",
|
||||
@@ -108,7 +108,7 @@ public interface WhiteListControllerApi {
|
||||
@Parameter(name = "id", description = "白名单ID", example = "2")
|
||||
}
|
||||
)
|
||||
ResponseResult queryWhiteListObjectById(@PathVariable Integer id) ;
|
||||
ResponseResult queryWhiteListObjectById(@PathVariable Integer id);
|
||||
|
||||
@Operation(
|
||||
summary = "删除白名单",
|
||||
@@ -144,7 +144,7 @@ public interface WhiteListControllerApi {
|
||||
@Parameter(name = "ids", description = "白名单id数组")
|
||||
}
|
||||
)
|
||||
ResponseResult deleteWhiteListObjects(@PathVariable List<Integer> whiteListObjIds) ;
|
||||
ResponseResult deleteWhiteListObjects(@PathVariable List<Integer> whiteListObjIds);
|
||||
|
||||
@Operation(
|
||||
summary = "修改白名单",
|
||||
@@ -166,7 +166,7 @@ public interface WhiteListControllerApi {
|
||||
|
||||
)
|
||||
ResponseResult updateWhiteListObject(@PathVariable Integer id,
|
||||
@RequestBody WhiteListObject object) ;
|
||||
@RequestBody WhiteListObject object);
|
||||
|
||||
@Operation(
|
||||
summary = "修改白名单审核状态",
|
||||
@@ -186,9 +186,7 @@ public interface WhiteListControllerApi {
|
||||
}
|
||||
)
|
||||
ResponseResult updateWhiteListObjectAuditStatus(@PathVariable Integer id,
|
||||
@PathVariable Integer auditStatus) ;
|
||||
@PathVariable Integer auditStatus);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public interface WhiteListMapper {
|
||||
@Delete("delete from t_white_list where white_list_id = #{id}")
|
||||
Integer deleteWhiteListObject(Integer id);
|
||||
|
||||
Integer updateWhiteListObject(@Param("id")Integer id, @Param("object") WhiteListObject object);
|
||||
Integer updateWhiteListObject(@Param("id") Integer id, @Param("object") WhiteListObject object);
|
||||
|
||||
List<String> existWhiteListObject(@Param("staticRuleObject") StaticRuleObject staticRuleObject);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user