fix: job 接口调整
This commit is contained in:
@@ -87,6 +87,7 @@ public enum RCode {
|
|||||||
ENVIRONMENT_NOT_EXIST(601002, "environment does not exist"),
|
ENVIRONMENT_NOT_EXIST(601002, "environment does not exist"),
|
||||||
ENVIRONMENT_USED(601003, "The environment is already in use"),
|
ENVIRONMENT_USED(601003, "The environment is already in use"),
|
||||||
ENVIRONMENT_STATUS_ERROR(601004, "The environment status is unavailable"),
|
ENVIRONMENT_STATUS_ERROR(601004, "The environment status is unavailable"),
|
||||||
|
ENVIRONMENT_ID_CANNOT_EMPTY(601005, "environment id cannot be empty"),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,55 +10,67 @@ import net.geedge.asw.module.runner.service.IJobService;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/job")
|
@RequestMapping("/api/v1/workspace")
|
||||||
public class JobController {
|
public class JobController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IJobService jobService;
|
private IJobService jobService;
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{workspaceId}/job/{id}")
|
||||||
public R detail(@PathVariable("id") String id) {
|
public R detail(@PathVariable("workspaceId") String workspaceId,
|
||||||
|
@PathVariable("id") String id) {
|
||||||
JobEntity jobEntity = jobService.queryInfo(id);
|
JobEntity jobEntity = jobService.queryInfo(id);
|
||||||
return R.ok().putData("record", jobEntity);
|
return R.ok().putData("record", jobEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping("/{workspaceId}/job")
|
||||||
public R list(@RequestParam Map<String, Object> params) {
|
public R list(@PathVariable("workspaceId") String workspaceId,
|
||||||
|
@RequestParam Map<String, Object> params) {
|
||||||
T.VerifyUtil.is(params).notNull()
|
T.VerifyUtil.is(params).notNull()
|
||||||
.and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
.and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||||
Page page = jobService.queryList(params);
|
Page page = jobService.queryList(params);
|
||||||
return R.ok(page);
|
return R.ok(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping("/{workspaceId}/job")
|
||||||
public R add(@RequestBody JobEntity entity) {
|
public R add(@PathVariable("workspaceId") String workspaceId,
|
||||||
|
@RequestBody JobEntity entity) {
|
||||||
T.VerifyUtil.is(entity).notNull()
|
T.VerifyUtil.is(entity).notNull()
|
||||||
.and(entity.getRunnerId()).notEmpty(RCode.RUNNER_ID_CANNOT_EMPTY)
|
.and(entity.getEnvironmentId()).notEmpty(RCode.ENVIRONMENT_ID_CANNOT_EMPTY)
|
||||||
.and(entity.getPackageId()).notEmpty(RCode.PACKAGE_ID_CANNOT_EMPTY)
|
.and(entity.getPackageId()).notEmpty(RCode.PACKAGE_ID_CANNOT_EMPTY)
|
||||||
|
.and(entity.getPlaybookId()).notEmpty(RCode.PLAYBOOK_ID_CANNOT_EMPTY)
|
||||||
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||||
|
|
||||||
|
entity.setEnvId(entity.getEnvironmentId());
|
||||||
|
|
||||||
JobEntity jobEntity = jobService.saveJob(entity);
|
JobEntity jobEntity = jobService.saveJob(entity);
|
||||||
return R.ok().putData("id", jobEntity.getId());
|
return R.ok().putData("id", jobEntity.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping
|
@DeleteMapping("/{workspaceId}/job")
|
||||||
public R delete(String[] ids) {
|
public R delete(@PathVariable("workspaceId") String workspaceId,
|
||||||
|
@RequestParam String ids) {
|
||||||
T.VerifyUtil.is(ids).notEmpty();
|
T.VerifyUtil.is(ids).notEmpty();
|
||||||
jobService.removeJob(T.ListUtil.of(ids));
|
List<String> idList = Arrays.asList(ids.split(","));
|
||||||
|
jobService.removeJob(idList);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/cancel")
|
@PutMapping("/{workspaceId}/job/cancel")
|
||||||
public R cancel(String[] ids) {
|
public R cancel(@PathVariable("workspaceId") String workspaceId,
|
||||||
|
@RequestParam String ids) {
|
||||||
T.VerifyUtil.is(ids).notEmpty();
|
T.VerifyUtil.is(ids).notEmpty();
|
||||||
|
List<String> idList = Arrays.asList(ids.split(","));
|
||||||
// TODO 其他处理
|
// TODO 其他处理
|
||||||
|
|
||||||
// update state
|
// update state
|
||||||
jobService.update(new LambdaUpdateWrapper<JobEntity>()
|
jobService.update(new LambdaUpdateWrapper<JobEntity>()
|
||||||
.in(JobEntity::getId, ids)
|
.in(JobEntity::getId, idList)
|
||||||
.set(JobEntity::getStatus, "cancel")
|
.set(JobEntity::getStatus, "cancel")
|
||||||
);
|
);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
|
|||||||
@@ -1,174 +1,174 @@
|
|||||||
package net.geedge.asw.module.runner.controller;
|
//package net.geedge.asw.module.runner.controller;
|
||||||
|
//
|
||||||
import cn.dev33.satoken.annotation.SaIgnore;
|
//import cn.dev33.satoken.annotation.SaIgnore;
|
||||||
import cn.hutool.core.lang.Opt;
|
//import cn.hutool.core.lang.Opt;
|
||||||
import cn.hutool.log.Log;
|
//import cn.hutool.log.Log;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
//import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
//import jakarta.servlet.http.HttpServletResponse;
|
||||||
import net.geedge.asw.common.util.R;
|
//import net.geedge.asw.common.util.R;
|
||||||
import net.geedge.asw.common.util.RCode;
|
//import net.geedge.asw.common.util.RCode;
|
||||||
import net.geedge.asw.common.util.T;
|
//import net.geedge.asw.common.util.T;
|
||||||
import net.geedge.asw.module.app.entity.PackageEntity;
|
//import net.geedge.asw.module.app.entity.PackageEntity;
|
||||||
import net.geedge.asw.module.runner.entity.JobEntity;
|
//import net.geedge.asw.module.runner.entity.JobEntity;
|
||||||
import net.geedge.asw.module.runner.entity.PlaybookEntity;
|
//import net.geedge.asw.module.runner.entity.PlaybookEntity;
|
||||||
import net.geedge.asw.module.runner.entity.RunnerEntity;
|
//import net.geedge.asw.module.runner.entity.RunnerEntity;
|
||||||
import net.geedge.asw.module.runner.service.IJobService;
|
//import net.geedge.asw.module.runner.service.IJobService;
|
||||||
import net.geedge.asw.module.runner.service.IRunnerService;
|
//import net.geedge.asw.module.runner.service.IRunnerService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
//import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
//import org.springframework.web.multipart.MultipartFile;
|
||||||
|
//
|
||||||
import java.io.IOException;
|
//import java.io.IOException;
|
||||||
import java.util.Map;
|
//import java.util.Map;
|
||||||
|
//
|
||||||
@RestController
|
//@RestController
|
||||||
@RequestMapping("/api/v1/runner")
|
//@RequestMapping("/api/v1/runner")
|
||||||
public class RunnerController {
|
//public class RunnerController {
|
||||||
|
//
|
||||||
private static final Log log = Log.get();
|
// private static final Log log = Log.get();
|
||||||
|
//
|
||||||
@Autowired
|
// @Autowired
|
||||||
private IJobService jobService;
|
// private IJobService jobService;
|
||||||
|
//
|
||||||
@Autowired
|
// @Autowired
|
||||||
private IRunnerService runnerService;
|
// private IRunnerService runnerService;
|
||||||
|
//
|
||||||
@GetMapping("/{id}")
|
// @GetMapping("/{id}")
|
||||||
public R detail(@PathVariable("id") String id) {
|
// public R detail(@PathVariable("id") String id) {
|
||||||
RunnerEntity runnerEntity = runnerService.getById(id);
|
// RunnerEntity runnerEntity = runnerService.getById(id);
|
||||||
return R.ok().putData("record", runnerEntity);
|
// return R.ok().putData("record", runnerEntity);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@GetMapping
|
// @GetMapping
|
||||||
public R list(@RequestParam Map<String, Object> params) {
|
// public R list(@RequestParam Map<String, Object> params) {
|
||||||
T.VerifyUtil.is(params).notNull()
|
// T.VerifyUtil.is(params).notNull()
|
||||||
.and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
// .and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||||
|
//
|
||||||
Page page = runnerService.queryList(params);
|
// Page page = runnerService.queryList(params);
|
||||||
return R.ok(page);
|
// return R.ok(page);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@PostMapping
|
// @PostMapping
|
||||||
public R add(@RequestBody RunnerEntity entity) {
|
// public R add(@RequestBody RunnerEntity entity) {
|
||||||
T.VerifyUtil.is(entity).notNull()
|
// T.VerifyUtil.is(entity).notNull()
|
||||||
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
// .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||||
|
//
|
||||||
RunnerEntity runner = runnerService.saveRunner(entity);
|
// RunnerEntity runner = runnerService.saveRunner(entity);
|
||||||
return R.ok().putData("record", runner);
|
// return R.ok().putData("record", runner);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@PutMapping
|
// @PutMapping
|
||||||
public R update(@RequestBody RunnerEntity entity) {
|
// public R update(@RequestBody RunnerEntity entity) {
|
||||||
T.VerifyUtil.is(entity).notNull()
|
// T.VerifyUtil.is(entity).notNull()
|
||||||
.and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY)
|
// .and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY)
|
||||||
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
// .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||||
|
//
|
||||||
RunnerEntity runner = runnerService.updateRunner(entity);
|
// RunnerEntity runner = runnerService.updateRunner(entity);
|
||||||
return R.ok().putData("record", runner);
|
// return R.ok().putData("record", runner);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@DeleteMapping("/{id}")
|
// @DeleteMapping("/{id}")
|
||||||
public R delete(@PathVariable("id") String id) {
|
// public R delete(@PathVariable("id") String id) {
|
||||||
runnerService.removeById(id);
|
// runnerService.removeById(id);
|
||||||
return R.ok();
|
// return R.ok();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@SaIgnore
|
// @SaIgnore
|
||||||
@PostMapping("/register")
|
// @PostMapping("/register")
|
||||||
public void register(@RequestHeader("Authorization") String token, HttpServletResponse response) throws IOException {
|
// public void register(@RequestHeader("Authorization") String token, HttpServletResponse response) throws IOException {
|
||||||
RunnerEntity runner = runnerService.getOne(new LambdaUpdateWrapper<RunnerEntity>().eq(RunnerEntity::getToken, token));
|
// RunnerEntity runner = runnerService.getOne(new LambdaUpdateWrapper<RunnerEntity>().eq(RunnerEntity::getToken, token));
|
||||||
String status = Opt.ofNullable(runner).map(RunnerEntity::getStatus).orElseGet(() -> null);
|
// String status = Opt.ofNullable(runner).map(RunnerEntity::getStatus).orElseGet(() -> null);
|
||||||
if (!T.StrUtil.equals("online", status)) {
|
// if (!T.StrUtil.equals("online", status)) {
|
||||||
log.warn("[register] [runner is offline] [token: {}]", token);
|
// log.warn("[register] [runner is offline] [token: {}]", token);
|
||||||
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Runner is offline");
|
// response.sendError(HttpServletResponse.SC_FORBIDDEN, "Runner is offline");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@SaIgnore
|
// @SaIgnore
|
||||||
@PostMapping("/heartbeat")
|
// @PostMapping("/heartbeat")
|
||||||
public void heartbeat(@RequestHeader("Authorization") String token, @RequestBody Map<String, Integer> platformMap,
|
// public void heartbeat(@RequestHeader("Authorization") String token, @RequestBody Map<String, Integer> platformMap,
|
||||||
HttpServletResponse response) throws IOException {
|
// HttpServletResponse response) throws IOException {
|
||||||
RunnerEntity runner = runnerService.getOne(new LambdaUpdateWrapper<RunnerEntity>().eq(RunnerEntity::getToken, token));
|
// RunnerEntity runner = runnerService.getOne(new LambdaUpdateWrapper<RunnerEntity>().eq(RunnerEntity::getToken, token));
|
||||||
String status = Opt.ofNullable(runner).map(RunnerEntity::getStatus).orElseGet(() -> null);
|
// String status = Opt.ofNullable(runner).map(RunnerEntity::getStatus).orElseGet(() -> null);
|
||||||
if (!T.StrUtil.equals("online", status)) {
|
// if (!T.StrUtil.equals("online", status)) {
|
||||||
log.warn("[heartbeat] [runner is offline] [token: {}]", token);
|
// log.warn("[heartbeat] [runner is offline] [token: {}]", token);
|
||||||
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Runner is offline");
|
// response.sendError(HttpServletResponse.SC_FORBIDDEN, "Runner is offline");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// update last_heartbeat_timestamp
|
// // update last_heartbeat_timestamp
|
||||||
runnerService.update(new LambdaUpdateWrapper<RunnerEntity>()
|
// runnerService.update(new LambdaUpdateWrapper<RunnerEntity>()
|
||||||
.set(RunnerEntity::getLastHeartbeatTimestamp, System.currentTimeMillis())
|
// .set(RunnerEntity::getLastHeartbeatTimestamp, System.currentTimeMillis())
|
||||||
.eq(RunnerEntity::getId, runner.getId()));
|
// .eq(RunnerEntity::getId, runner.getId()));
|
||||||
|
//
|
||||||
// findjob by platform
|
// // findjob by platform
|
||||||
String platform = platformMap.entrySet().stream().filter(entry -> entry.getValue() > 0).findFirst().map(entry -> entry.getKey()).orElseGet(null);
|
// String platform = platformMap.entrySet().stream().filter(entry -> entry.getValue() > 0).findFirst().map(entry -> entry.getKey()).orElseGet(null);
|
||||||
JobEntity job = jobService.assignPendingJob(runner.getId(), platform);
|
// JobEntity job = jobService.assignPendingJob(runner.getId(), platform);
|
||||||
if (T.ObjectUtil.isNotNull(job)) {
|
// if (T.ObjectUtil.isNotNull(job)) {
|
||||||
// package
|
// // package
|
||||||
PackageEntity pkg = job.getPkg();
|
// PackageEntity pkg = job.getPkg();
|
||||||
Map<String, String> pkgInfo = T.MapUtil.builder("id", pkg.getId())
|
// Map<String, String> pkgInfo = T.MapUtil.builder("id", pkg.getId())
|
||||||
.put("platform", pkg.getPlatform())
|
// .put("platform", pkg.getPlatform())
|
||||||
.put("identifier", pkg.getIdentifier())
|
// .put("identifier", pkg.getIdentifier())
|
||||||
.put("version", pkg.getVersion())
|
// .put("version", pkg.getVersion())
|
||||||
.build();
|
// .build();
|
||||||
|
//
|
||||||
// playbook
|
// // playbook
|
||||||
PlaybookEntity playbook = job.getPlaybook();
|
// PlaybookEntity playbook = job.getPlaybook();
|
||||||
Map<String, String> pbInfo = T.MapUtil.builder("id", playbook.getId())
|
// Map<String, String> pbInfo = T.MapUtil.builder("id", playbook.getId())
|
||||||
.put("name", playbook.getName())
|
// .put("name", playbook.getName())
|
||||||
.build();
|
// .build();
|
||||||
|
//
|
||||||
// response job info
|
// // response job info
|
||||||
Map<Object, Object> responseData = T.MapUtil.builder()
|
// Map<Object, Object> responseData = T.MapUtil.builder()
|
||||||
.put("id", job.getId())
|
// .put("id", job.getId())
|
||||||
.put("pkg", pkgInfo)
|
// .put("pkg", pkgInfo)
|
||||||
.put("playbook", pbInfo)
|
// .put("playbook", pbInfo)
|
||||||
.build();
|
// .build();
|
||||||
response.setCharacterEncoding("UTF-8");
|
// response.setCharacterEncoding("UTF-8");
|
||||||
response.setContentType("text/html; charset=UTF-8");
|
// response.setContentType("text/html; charset=UTF-8");
|
||||||
response.getWriter().write(T.JSONUtil.toJsonStr(responseData));
|
// response.getWriter().write(T.JSONUtil.toJsonStr(responseData));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@SaIgnore
|
// @SaIgnore
|
||||||
@PutMapping("/trace/{jobId}")
|
// @PutMapping("/trace/{jobId}")
|
||||||
public void trace(@RequestHeader("Authorization") String token, @PathVariable String jobId, @RequestBody byte[] bytes,
|
// public void trace(@RequestHeader("Authorization") String token, @PathVariable String jobId, @RequestBody byte[] bytes,
|
||||||
HttpServletResponse response) throws IOException {
|
// HttpServletResponse response) throws IOException {
|
||||||
RunnerEntity runner = runnerService.getOne(new LambdaUpdateWrapper<RunnerEntity>().eq(RunnerEntity::getToken, token));
|
// RunnerEntity runner = runnerService.getOne(new LambdaUpdateWrapper<RunnerEntity>().eq(RunnerEntity::getToken, token));
|
||||||
String status = Opt.ofNullable(runner).map(RunnerEntity::getStatus).orElseGet(() -> null);
|
// String status = Opt.ofNullable(runner).map(RunnerEntity::getStatus).orElseGet(() -> null);
|
||||||
if (!T.StrUtil.equals("online", status)) {
|
// if (!T.StrUtil.equals("online", status)) {
|
||||||
log.warn("[trace] [runner is offline] [token: {}]", token);
|
// log.warn("[trace] [runner is offline] [token: {}]", token);
|
||||||
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Runner is offline");
|
// response.sendError(HttpServletResponse.SC_FORBIDDEN, "Runner is offline");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
// 追加到文件中
|
// // 追加到文件中
|
||||||
String content = T.StrUtil.str(bytes, T.CharsetUtil.CHARSET_UTF_8);
|
// String content = T.StrUtil.str(bytes, T.CharsetUtil.CHARSET_UTF_8);
|
||||||
jobService.appendTraceLogStrToFile(jobId, content);
|
// jobService.appendTraceLogStrToFile(jobId, content);
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
log.error("[trace] [error] [job: {}]", jobId);
|
// log.error("[trace] [error] [job: {}]", jobId);
|
||||||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
// response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@SaIgnore
|
// @SaIgnore
|
||||||
@PutMapping("/jobResult/{jobId}")
|
// @PutMapping("/jobResult/{jobId}")
|
||||||
public void jobResult(@RequestHeader("Authorization") String token, @PathVariable String jobId, @RequestParam String state,
|
// public void jobResult(@RequestHeader("Authorization") String token, @PathVariable String jobId, @RequestParam String state,
|
||||||
@RequestParam(value = "file", required = false) MultipartFile pcapFile,
|
// @RequestParam(value = "file", required = false) MultipartFile pcapFile,
|
||||||
HttpServletResponse response) throws IOException {
|
// HttpServletResponse response) throws IOException {
|
||||||
RunnerEntity runner = runnerService.getOne(new LambdaUpdateWrapper<RunnerEntity>().eq(RunnerEntity::getToken, token));
|
// RunnerEntity runner = runnerService.getOne(new LambdaUpdateWrapper<RunnerEntity>().eq(RunnerEntity::getToken, token));
|
||||||
String status = Opt.ofNullable(runner).map(RunnerEntity::getStatus).orElseGet(() -> null);
|
// String status = Opt.ofNullable(runner).map(RunnerEntity::getStatus).orElseGet(() -> null);
|
||||||
if (!T.StrUtil.equals("online", status)) {
|
// if (!T.StrUtil.equals("online", status)) {
|
||||||
log.warn("[trace] [runner is offline] [token: {}]", token);
|
// log.warn("[trace] [runner is offline] [token: {}]", token);
|
||||||
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Runner is offline");
|
// response.sendError(HttpServletResponse.SC_FORBIDDEN, "Runner is offline");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// 更新任务状态
|
// // 更新任务状态
|
||||||
jobService.updateJobResult(jobId, state, pcapFile);
|
// jobService.updateJobResult(jobId, state, pcapFile);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
@@ -14,6 +14,4 @@ public interface JobDao extends BaseMapper<JobEntity>{
|
|||||||
|
|
||||||
List<JobEntity> queryList(IPage page, Map<String, Object> params);
|
List<JobEntity> queryList(IPage page, Map<String, Object> params);
|
||||||
|
|
||||||
JobEntity getPendingJobByPlatform(@Param("platform") String platform);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import net.geedge.asw.module.app.entity.ApplicationEntity;
|
|
||||||
import net.geedge.asw.module.app.entity.PackageEntity;
|
import net.geedge.asw.module.app.entity.PackageEntity;
|
||||||
|
import net.geedge.asw.module.environment.entity.EnvironmentEntity;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@TableName("job")
|
@TableName("job")
|
||||||
@@ -15,12 +15,10 @@ public class JobEntity {
|
|||||||
|
|
||||||
@TableId(type = IdType.ASSIGN_UUID)
|
@TableId(type = IdType.ASSIGN_UUID)
|
||||||
private String id;
|
private String id;
|
||||||
private String playbookId;
|
|
||||||
private String packageId;
|
private String packageId;
|
||||||
private String runnerId;
|
private String envId;
|
||||||
private String scheduleId;
|
private String playbookId;
|
||||||
private String signatureIds;
|
private String playbookParam;
|
||||||
private String tags;
|
|
||||||
private Long startTimestamp;
|
private Long startTimestamp;
|
||||||
private Long endTimestamp;
|
private Long endTimestamp;
|
||||||
private String status;
|
private String status;
|
||||||
@@ -35,17 +33,14 @@ public class JobEntity {
|
|||||||
private String workspaceId;
|
private String workspaceId;
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String workbookId;
|
private String environmentId;
|
||||||
|
|
||||||
@TableField(exist = false)
|
|
||||||
private ApplicationEntity application;
|
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
@JsonProperty(value = "package")
|
@JsonProperty(value = "package")
|
||||||
private PackageEntity pkg;
|
private PackageEntity pkg;
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private RunnerEntity runner;
|
private EnvironmentEntity environment;
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private PlaybookEntity playbook;
|
private PlaybookEntity playbook;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import lombok.Data;
|
|||||||
import net.geedge.asw.common.util.T;
|
import net.geedge.asw.common.util.T;
|
||||||
import net.geedge.asw.module.app.entity.ApplicationEntity;
|
import net.geedge.asw.module.app.entity.ApplicationEntity;
|
||||||
import net.geedge.asw.module.app.entity.PackageEntity;
|
import net.geedge.asw.module.app.entity.PackageEntity;
|
||||||
|
import net.geedge.asw.module.environment.entity.EnvironmentEntity;
|
||||||
import net.geedge.asw.module.workspace.entity.WorkspaceEntity;
|
import net.geedge.asw.module.workspace.entity.WorkspaceEntity;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -45,7 +46,7 @@ public class PcapEntity {
|
|||||||
private PackageEntity pkg;
|
private PackageEntity pkg;
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private RunnerEntity runner;
|
private EnvironmentEntity environment;
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private PlaybookEntity playbook;
|
private PlaybookEntity playbook;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package net.geedge.asw.module.runner.service;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import net.geedge.asw.module.runner.entity.JobEntity;
|
import net.geedge.asw.module.runner.entity.JobEntity;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -18,10 +17,10 @@ public interface IJobService extends IService<JobEntity>{
|
|||||||
|
|
||||||
void removeJob(List<String> ids);
|
void removeJob(List<String> ids);
|
||||||
|
|
||||||
JobEntity assignPendingJob(String id, String platform);
|
// JobEntity assignPendingJob(String id, String platform);
|
||||||
|
//
|
||||||
void appendTraceLogStrToFile(String jobId, String content) throws RuntimeException;
|
// void appendTraceLogStrToFile(String jobId, String content) throws RuntimeException;
|
||||||
|
//
|
||||||
void updateJobResult(String jobId, String state, MultipartFile pcapFile);
|
// void updateJobResult(String jobId, String state, MultipartFile pcapFile);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import net.geedge.asw.module.runner.entity.PcapEntity;
|
import net.geedge.asw.module.runner.entity.PcapEntity;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -14,8 +13,6 @@ public interface IPcapService extends IService<PcapEntity>{
|
|||||||
|
|
||||||
Page queryList(Map<String, Object> params);
|
Page queryList(Map<String, Object> params);
|
||||||
|
|
||||||
PcapEntity savePcap(String jobId, Resource fileResource);
|
|
||||||
|
|
||||||
PcapEntity savePcap(Resource fileResource,String... params);
|
PcapEntity savePcap(Resource fileResource,String... params);
|
||||||
|
|
||||||
void deletePcap(String... ids);
|
void deletePcap(String... ids);
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
package net.geedge.asw.module.runner.service;
|
//package net.geedge.asw.module.runner.service;
|
||||||
|
//
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
//import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import net.geedge.asw.module.runner.entity.RunnerEntity;
|
//import net.geedge.asw.module.runner.entity.RunnerEntity;
|
||||||
|
//
|
||||||
import java.util.Map;
|
//import java.util.Map;
|
||||||
|
//
|
||||||
public interface IRunnerService extends IService<RunnerEntity>{
|
//public interface IRunnerService extends IService<RunnerEntity>{
|
||||||
|
//
|
||||||
Page queryList(Map<String, Object> params);
|
// Page queryList(Map<String, Object> params);
|
||||||
|
//
|
||||||
RunnerEntity saveRunner(RunnerEntity entity);
|
// RunnerEntity saveRunner(RunnerEntity entity);
|
||||||
|
//
|
||||||
RunnerEntity updateRunner(RunnerEntity entity);
|
// RunnerEntity updateRunner(RunnerEntity entity);
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|||||||
@@ -1,33 +1,25 @@
|
|||||||
package net.geedge.asw.module.runner.service.impl;
|
package net.geedge.asw.module.runner.service.impl;
|
||||||
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.io.IORuntimeException;
|
|
||||||
import cn.hutool.log.Log;
|
import cn.hutool.log.Log;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import net.geedge.asw.common.util.RCode;
|
import net.geedge.asw.common.util.RCode;
|
||||||
import net.geedge.asw.common.util.T;
|
import net.geedge.asw.common.util.T;
|
||||||
import net.geedge.asw.module.app.entity.ApplicationEntity;
|
|
||||||
import net.geedge.asw.module.app.entity.PackageEntity;
|
import net.geedge.asw.module.app.entity.PackageEntity;
|
||||||
import net.geedge.asw.module.app.service.IApplicationService;
|
|
||||||
import net.geedge.asw.module.app.service.IPackageService;
|
import net.geedge.asw.module.app.service.IPackageService;
|
||||||
|
import net.geedge.asw.module.environment.entity.EnvironmentEntity;
|
||||||
|
import net.geedge.asw.module.environment.service.IEnvironmentService;
|
||||||
import net.geedge.asw.module.runner.dao.JobDao;
|
import net.geedge.asw.module.runner.dao.JobDao;
|
||||||
import net.geedge.asw.module.runner.entity.JobEntity;
|
import net.geedge.asw.module.runner.entity.JobEntity;
|
||||||
import net.geedge.asw.module.runner.entity.PcapEntity;
|
|
||||||
import net.geedge.asw.module.runner.entity.PlaybookEntity;
|
import net.geedge.asw.module.runner.entity.PlaybookEntity;
|
||||||
import net.geedge.asw.module.runner.entity.RunnerEntity;
|
|
||||||
import net.geedge.asw.module.runner.service.IJobService;
|
import net.geedge.asw.module.runner.service.IJobService;
|
||||||
import net.geedge.asw.module.runner.service.IPcapService;
|
|
||||||
import net.geedge.asw.module.runner.service.IPlaybookService;
|
import net.geedge.asw.module.runner.service.IPlaybookService;
|
||||||
import net.geedge.asw.module.runner.service.IRunnerService;
|
|
||||||
import net.geedge.asw.module.runner.util.RunnerConstant;
|
import net.geedge.asw.module.runner.util.RunnerConstant;
|
||||||
import net.geedge.asw.module.workbook.service.IWorkbookResourceService;
|
|
||||||
import net.geedge.asw.module.workbook.util.WorkbookConstant;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -39,10 +31,7 @@ public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements IJ
|
|||||||
private static final Log log = Log.get();
|
private static final Log log = Log.get();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IPcapService pcapService;
|
private IEnvironmentService environmentService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IRunnerService runnerService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IPlaybookService playbookService;
|
private IPlaybookService playbookService;
|
||||||
@@ -50,11 +39,6 @@ public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements IJ
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IPackageService packageService;
|
private IPackageService packageService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IApplicationService applicationService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IWorkbookResourceService workbookResourceService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rootPath/result/{jobId}
|
* rootPath/result/{jobId}
|
||||||
@@ -71,8 +55,8 @@ public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements IJ
|
|||||||
JobEntity job = this.getById(id);
|
JobEntity job = this.getById(id);
|
||||||
T.VerifyUtil.is(job).notNull(RCode.SYS_RECORD_NOT_FOUND);
|
T.VerifyUtil.is(job).notNull(RCode.SYS_RECORD_NOT_FOUND);
|
||||||
|
|
||||||
RunnerEntity runner = runnerService.getById(job.getRunnerId());
|
EnvironmentEntity env = environmentService.getById(job.getEnvId());
|
||||||
job.setRunner(runner);
|
job.setEnvironment(env);
|
||||||
|
|
||||||
PlaybookEntity playbook = playbookService.getById(job.getPlaybookId());
|
PlaybookEntity playbook = playbookService.getById(job.getPlaybookId());
|
||||||
job.setPlaybook(playbook);
|
job.setPlaybook(playbook);
|
||||||
@@ -97,13 +81,11 @@ public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements IJ
|
|||||||
entity.setUpdateTimestamp(System.currentTimeMillis());
|
entity.setUpdateTimestamp(System.currentTimeMillis());
|
||||||
entity.setCreateUserId(StpUtil.getLoginIdAsString());
|
entity.setCreateUserId(StpUtil.getLoginIdAsString());
|
||||||
entity.setUpdateUserId(StpUtil.getLoginIdAsString());
|
entity.setUpdateUserId(StpUtil.getLoginIdAsString());
|
||||||
|
entity.setStatus(RunnerConstant.JobStatus.CREATED.getValue());
|
||||||
|
|
||||||
// save
|
// save
|
||||||
this.save(entity);
|
this.save(entity);
|
||||||
|
|
||||||
// workbook resource
|
|
||||||
workbookResourceService.saveResource(entity.getWorkbookId(), entity.getId(), WorkbookConstant.ResourceType.JOB.getValue());
|
|
||||||
|
|
||||||
// trace log file path
|
// trace log file path
|
||||||
File traceLogFile = T.FileUtil.file(this.getJobResultPath(entity.getId()), "trace.log");
|
File traceLogFile = T.FileUtil.file(this.getJobResultPath(entity.getId()), "trace.log");
|
||||||
this.update(new LambdaUpdateWrapper<JobEntity>()
|
this.update(new LambdaUpdateWrapper<JobEntity>()
|
||||||
@@ -117,63 +99,61 @@ public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements IJ
|
|||||||
public void removeJob(List<String> ids) {
|
public void removeJob(List<String> ids) {
|
||||||
// remove
|
// remove
|
||||||
this.removeBatchByIds(ids);
|
this.removeBatchByIds(ids);
|
||||||
// workbook resource
|
|
||||||
workbookResourceService.removeResource(ids, WorkbookConstant.ResourceType.JOB.getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public synchronized JobEntity assignPendingJob(String runnerId, String platform) {
|
// public synchronized JobEntity assignPendingJob(String runnerId, String platform) {
|
||||||
if (T.StrUtil.hasEmpty(runnerId, platform)) {
|
// if (T.StrUtil.hasEmpty(runnerId, platform)) {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
// query
|
// // query
|
||||||
JobEntity job = this.getBaseMapper().getPendingJobByPlatform(platform);
|
// JobEntity job = this.getBaseMapper().getPendingJobByPlatform(platform);
|
||||||
if (T.ObjectUtil.isNotNull(job)) {
|
// if (T.ObjectUtil.isNotNull(job)) {
|
||||||
// update
|
// // update
|
||||||
this.update(new LambdaUpdateWrapper<JobEntity>()
|
// this.update(new LambdaUpdateWrapper<JobEntity>()
|
||||||
.set(JobEntity::getRunnerId, runnerId)
|
// .set(JobEntity::getRunnerId, runnerId)
|
||||||
.set(JobEntity::getStatus, RunnerConstant.JobStatus.RUNNING.getValue())
|
// .set(JobEntity::getStatus, RunnerConstant.JobStatus.RUNNING.getValue())
|
||||||
.set(JobEntity::getStartTimestamp, System.currentTimeMillis())
|
// .set(JobEntity::getStartTimestamp, System.currentTimeMillis())
|
||||||
.eq(JobEntity::getId, job.getId())
|
// .eq(JobEntity::getId, job.getId())
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
return job;
|
// return job;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void appendTraceLogStrToFile(String jobId, String content) throws RuntimeException {
|
// public void appendTraceLogStrToFile(String jobId, String content) throws RuntimeException {
|
||||||
try {
|
// try {
|
||||||
JobEntity job = this.getById(jobId);
|
// JobEntity job = this.getById(jobId);
|
||||||
if (T.StrUtil.isEmpty(job.getLogPath())) {
|
// if (T.StrUtil.isEmpty(job.getLogPath())) {
|
||||||
File traceLogFile = T.FileUtil.file(this.getJobResultPath(jobId), "trace.log");
|
// File traceLogFile = T.FileUtil.file(this.getJobResultPath(jobId), "trace.log");
|
||||||
job.setLogPath(traceLogFile.getPath());
|
// job.setLogPath(traceLogFile.getPath());
|
||||||
}
|
// }
|
||||||
// append content
|
// // append content
|
||||||
T.FileUtil.appendString(content, T.FileUtil.file(job.getLogPath()), T.CharsetUtil.CHARSET_UTF_8);
|
// T.FileUtil.appendString(content, T.FileUtil.file(job.getLogPath()), T.CharsetUtil.CHARSET_UTF_8);
|
||||||
} catch (IORuntimeException e) {
|
// } catch (IORuntimeException e) {
|
||||||
log.error(e, "[appendTraceLogStrToFile] [error] [job: {}] [content: {}]", jobId, content);
|
// log.error(e, "[appendTraceLogStrToFile] [error] [job: {}] [content: {}]", jobId, content);
|
||||||
throw new RuntimeException(e.getMessage());
|
// throw new RuntimeException(e.getMessage());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
// @Transactional(rollbackFor = Exception.class)
|
||||||
public void updateJobResult(String jobId, String state, MultipartFile pcapFile) {
|
// public void updateJobResult(String jobId, String state, MultipartFile pcapFile) {
|
||||||
String pcapId = T.StrUtil.EMPTY;
|
// String pcapId = T.StrUtil.EMPTY;
|
||||||
// save pcap file
|
// // save pcap file
|
||||||
if (T.ObjectUtil.isNotNull(pcapFile)) {
|
// if (T.ObjectUtil.isNotNull(pcapFile)) {
|
||||||
PcapEntity pcapEntity = pcapService.savePcap(jobId, pcapFile.getResource());
|
// PcapEntity pcapEntity = pcapService.savePcap(jobId, pcapFile.getResource());
|
||||||
pcapId = pcapEntity.getId();
|
// pcapId = pcapEntity.getId();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// update job status&pcap_id
|
// // update job status&pcap_id
|
||||||
state = T.StrUtil.equals("success", state) ? RunnerConstant.JobStatus.PASSED.getValue() : state;
|
// state = T.StrUtil.equals("success", state) ? RunnerConstant.JobStatus.PASSED.getValue() : state;
|
||||||
this.update(new LambdaUpdateWrapper<JobEntity>()
|
// this.update(new LambdaUpdateWrapper<JobEntity>()
|
||||||
.set(JobEntity::getStatus, state)
|
// .set(JobEntity::getStatus, state)
|
||||||
.set(T.StrUtil.isNotEmpty(pcapId), JobEntity::getPcapId, pcapId)
|
// .set(T.StrUtil.isNotEmpty(pcapId), JobEntity::getPcapId, pcapId)
|
||||||
.set(JobEntity::getEndTimestamp, System.currentTimeMillis())
|
// .set(JobEntity::getEndTimestamp, System.currentTimeMillis())
|
||||||
.eq(JobEntity::getId, jobId)
|
// .eq(JobEntity::getId, jobId)
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,27 +9,25 @@ import com.alibaba.fastjson2.JSONArray;
|
|||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import net.geedge.asw.common.config.SpringContextUtils;
|
import net.geedge.asw.common.config.SpringContextUtils;
|
||||||
import net.geedge.asw.common.util.ASWException;
|
import net.geedge.asw.common.util.ASWException;
|
||||||
import net.geedge.asw.common.util.RCode;
|
import net.geedge.asw.common.util.RCode;
|
||||||
import net.geedge.asw.common.util.T;
|
import net.geedge.asw.common.util.T;
|
||||||
import net.geedge.asw.module.app.entity.ApplicationEntity;
|
|
||||||
import net.geedge.asw.module.app.entity.PackageEntity;
|
import net.geedge.asw.module.app.entity.PackageEntity;
|
||||||
import net.geedge.asw.module.app.service.IApplicationService;
|
import net.geedge.asw.module.app.service.IApplicationService;
|
||||||
import net.geedge.asw.module.app.service.IPackageService;
|
import net.geedge.asw.module.app.service.IPackageService;
|
||||||
|
import net.geedge.asw.module.environment.entity.EnvironmentEntity;
|
||||||
|
import net.geedge.asw.module.environment.service.IEnvironmentService;
|
||||||
import net.geedge.asw.module.feign.client.KibanaClient;
|
import net.geedge.asw.module.feign.client.KibanaClient;
|
||||||
import net.geedge.asw.module.runner.dao.PcapDao;
|
import net.geedge.asw.module.runner.dao.PcapDao;
|
||||||
import net.geedge.asw.module.runner.entity.JobEntity;
|
import net.geedge.asw.module.runner.entity.JobEntity;
|
||||||
import net.geedge.asw.module.runner.entity.PcapEntity;
|
import net.geedge.asw.module.runner.entity.PcapEntity;
|
||||||
import net.geedge.asw.module.runner.entity.PlaybookEntity;
|
import net.geedge.asw.module.runner.entity.PlaybookEntity;
|
||||||
import net.geedge.asw.module.runner.entity.RunnerEntity;
|
|
||||||
import net.geedge.asw.module.runner.service.IJobService;
|
import net.geedge.asw.module.runner.service.IJobService;
|
||||||
import net.geedge.asw.module.runner.service.IPcapService;
|
import net.geedge.asw.module.runner.service.IPcapService;
|
||||||
import net.geedge.asw.module.runner.service.IPlaybookService;
|
import net.geedge.asw.module.runner.service.IPlaybookService;
|
||||||
import net.geedge.asw.module.runner.service.IRunnerService;
|
|
||||||
import net.geedge.asw.module.runner.util.PcapParserThread;
|
import net.geedge.asw.module.runner.util.PcapParserThread;
|
||||||
import net.geedge.asw.module.runner.util.RunnerConstant;
|
import net.geedge.asw.module.runner.util.RunnerConstant;
|
||||||
import net.geedge.asw.module.workbook.service.IWorkbookResourceService;
|
import net.geedge.asw.module.workbook.service.IWorkbookResourceService;
|
||||||
@@ -68,7 +66,7 @@ public class PcapServiceImpl extends ServiceImpl<PcapDao, PcapEntity> implements
|
|||||||
private IJobService jobService;
|
private IJobService jobService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IRunnerService runnerService;
|
private IEnvironmentService environmentService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IPlaybookService playbookService;
|
private IPlaybookService playbookService;
|
||||||
@@ -103,8 +101,8 @@ public class PcapServiceImpl extends ServiceImpl<PcapDao, PcapEntity> implements
|
|||||||
if (T.ObjectUtil.isNotNull(job)) {
|
if (T.ObjectUtil.isNotNull(job)) {
|
||||||
pcap.setJobId(job.getId());
|
pcap.setJobId(job.getId());
|
||||||
|
|
||||||
RunnerEntity runner = runnerService.getById(job.getRunnerId());
|
EnvironmentEntity environment = environmentService.getById(job.getEnvId());
|
||||||
pcap.setRunner(runner);
|
pcap.setEnvironment(environment);
|
||||||
|
|
||||||
PackageEntity pkg = packageService.getById(job.getPackageId());
|
PackageEntity pkg = packageService.getById(job.getPackageId());
|
||||||
pcap.setPkg(pkg);
|
pcap.setPkg(pkg);
|
||||||
@@ -123,13 +121,6 @@ public class PcapServiceImpl extends ServiceImpl<PcapDao, PcapEntity> implements
|
|||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PcapEntity savePcap(String jobId, Resource fileResource) {
|
|
||||||
JobEntity job = jobService.getById(jobId);
|
|
||||||
return this.savePcap(fileResource, job.getTags(), job.getWorkbookId(), job.getWorkspaceId(), job.getCreateUserId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PcapEntity savePcap(Resource fileResource, String... params) {
|
public PcapEntity savePcap(Resource fileResource, String... params) {
|
||||||
String description = T.ArrayUtil.get(params, 0);
|
String description = T.ArrayUtil.get(params, 0);
|
||||||
|
|||||||
@@ -1,51 +1,51 @@
|
|||||||
package net.geedge.asw.module.runner.service.impl;
|
//package net.geedge.asw.module.runner.service.impl;
|
||||||
|
//
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
//import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import net.geedge.asw.common.util.T;
|
//import net.geedge.asw.common.util.T;
|
||||||
import net.geedge.asw.module.runner.dao.RunnerDao;
|
//import net.geedge.asw.module.runner.dao.RunnerDao;
|
||||||
import net.geedge.asw.module.runner.entity.RunnerEntity;
|
//import net.geedge.asw.module.runner.entity.RunnerEntity;
|
||||||
import net.geedge.asw.module.runner.service.IRunnerService;
|
//import net.geedge.asw.module.runner.service.IRunnerService;
|
||||||
import org.springframework.stereotype.Service;
|
//import org.springframework.stereotype.Service;
|
||||||
|
//
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
import java.util.Map;
|
//import java.util.Map;
|
||||||
|
//
|
||||||
@Service
|
//@Service
|
||||||
public class RunnerServiceImpl extends ServiceImpl<RunnerDao, RunnerEntity> implements IRunnerService {
|
//public class RunnerServiceImpl extends ServiceImpl<RunnerDao, RunnerEntity> implements IRunnerService {
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public Page queryList(Map<String, Object> params) {
|
// public Page queryList(Map<String, Object> params) {
|
||||||
Page page = T.PageUtil.getPage(params);
|
// Page page = T.PageUtil.getPage(params);
|
||||||
List<RunnerEntity> jobList = this.getBaseMapper().queryList(page, params);
|
// List<RunnerEntity> jobList = this.getBaseMapper().queryList(page, params);
|
||||||
page.setRecords(jobList);
|
// page.setRecords(jobList);
|
||||||
return page;
|
// return page;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public RunnerEntity saveRunner(RunnerEntity entity) {
|
// public RunnerEntity saveRunner(RunnerEntity entity) {
|
||||||
entity.setCreateTimestamp(System.currentTimeMillis());
|
// entity.setCreateTimestamp(System.currentTimeMillis());
|
||||||
entity.setUpdateTimestamp(System.currentTimeMillis());
|
// entity.setUpdateTimestamp(System.currentTimeMillis());
|
||||||
entity.setCreateUserId(StpUtil.getLoginIdAsString());
|
// entity.setCreateUserId(StpUtil.getLoginIdAsString());
|
||||||
entity.setUpdateUserId(StpUtil.getLoginIdAsString());
|
// entity.setUpdateUserId(StpUtil.getLoginIdAsString());
|
||||||
|
//
|
||||||
// token
|
// // token
|
||||||
entity.setToken(T.IdUtil.fastSimpleUUID());
|
// entity.setToken(T.IdUtil.fastSimpleUUID());
|
||||||
|
//
|
||||||
// save
|
// // save
|
||||||
this.save(entity);
|
// this.save(entity);
|
||||||
return entity;
|
// return entity;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public RunnerEntity updateRunner(RunnerEntity entity) {
|
// public RunnerEntity updateRunner(RunnerEntity entity) {
|
||||||
entity.setUpdateTimestamp(System.currentTimeMillis());
|
// entity.setUpdateTimestamp(System.currentTimeMillis());
|
||||||
entity.setUpdateUserId(StpUtil.getLoginIdAsString());
|
// entity.setUpdateUserId(StpUtil.getLoginIdAsString());
|
||||||
|
//
|
||||||
// update
|
// // update
|
||||||
this.updateById(entity);
|
// this.updateById(entity);
|
||||||
return entity;
|
// return entity;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
@@ -7,10 +7,7 @@
|
|||||||
<id property="id" column="id"/>
|
<id property="id" column="id"/>
|
||||||
<result property="playbookId" column="playbook_id"/>
|
<result property="playbookId" column="playbook_id"/>
|
||||||
<result property="packageId" column="package_id"/>
|
<result property="packageId" column="package_id"/>
|
||||||
<result property="runnerId" column="runner_id"/>
|
<result property="envId" column="env_id"/>
|
||||||
<result property="scheduleId" column="schedule_id"/>
|
|
||||||
<result property="signatureIds" column="signature_ids"/>
|
|
||||||
<result property="tags" column="tags"/>
|
|
||||||
<result property="startTimestamp" column="start_timestamp"/>
|
<result property="startTimestamp" column="start_timestamp"/>
|
||||||
<result property="endTimestamp" column="end_timestamp"/>
|
<result property="endTimestamp" column="end_timestamp"/>
|
||||||
<result property="status" column="status"/>
|
<result property="status" column="status"/>
|
||||||
@@ -25,18 +22,11 @@
|
|||||||
<association property="pkg" columnPrefix="pkg_" javaType="net.geedge.asw.module.app.entity.PackageEntity">
|
<association property="pkg" columnPrefix="pkg_" javaType="net.geedge.asw.module.app.entity.PackageEntity">
|
||||||
<id property="id" column="id"/>
|
<id property="id" column="id"/>
|
||||||
<result property="platform" column="platform"/>
|
<result property="platform" column="platform"/>
|
||||||
<result property="identifier" column="identifier"/>
|
|
||||||
<result property="version" column="version"/>
|
<result property="version" column="version"/>
|
||||||
<result property="logo" column="logo"/>
|
|
||||||
</association>
|
|
||||||
|
|
||||||
<association property="application" columnPrefix="app_"
|
|
||||||
javaType="net.geedge.asw.module.app.entity.ApplicationEntity">
|
|
||||||
<id property="id" column="id"/>
|
|
||||||
<result property="name" column="name"/>
|
<result property="name" column="name"/>
|
||||||
</association>
|
</association>
|
||||||
|
|
||||||
<association property="runner" columnPrefix="run_" javaType="net.geedge.asw.module.runner.entity.RunnerEntity">
|
<association property="environment" columnPrefix="em_" javaType="net.geedge.asw.module.environment.entity.EnvironmentEntity">
|
||||||
<id property="id" column="id"/>
|
<id property="id" column="id"/>
|
||||||
<result property="name" column="name"/>
|
<result property="name" column="name"/>
|
||||||
</association>
|
</association>
|
||||||
@@ -55,60 +45,38 @@
|
|||||||
pkg.id AS pkg_id,
|
pkg.id AS pkg_id,
|
||||||
pkg.platform AS pkg_platform,
|
pkg.platform AS pkg_platform,
|
||||||
pkg.version AS pkg_version,
|
pkg.version AS pkg_version,
|
||||||
pkg.logo AS pkg_logo,
|
pkg.name AS pkg_name,
|
||||||
pkg.identifier AS pkg_identifier,
|
|
||||||
|
|
||||||
app.id AS app_id,
|
env.id AS em_id,
|
||||||
app.name AS app_name,
|
env.name AS em_name,
|
||||||
|
|
||||||
run.id AS run_id,
|
|
||||||
run.name AS run_name,
|
|
||||||
|
|
||||||
pb.id AS pb_id,
|
pb.id AS pb_id,
|
||||||
pb.name AS pb_name
|
pb.name AS pb_name
|
||||||
FROM
|
FROM
|
||||||
job job
|
job job
|
||||||
LEFT JOIN runner run ON job.runner_id = run.id
|
LEFT JOIN environment env ON job.env_id = env.id
|
||||||
LEFT JOIN package pkg ON job.package_id = pkg.id
|
LEFT JOIN package pkg ON job.package_id = pkg.id
|
||||||
LEFT JOIN playbook pb ON job.playbook_id = pb.id
|
LEFT JOIN playbook pb ON job.playbook_id = pb.id
|
||||||
LEFT JOIN application app ON pb.app_id = app.id
|
|
||||||
LEFT JOIN workbook_resource wr ON job.id = wr.resource_id AND wr.resource_type = 'job'
|
|
||||||
<where>
|
<where>
|
||||||
<if test="params.ids != null and params.ids != ''">
|
<if test="params.ids != null and params.ids != ''">
|
||||||
job.id in
|
job.id in
|
||||||
<foreach item="id" collection="params.ids.split(',')" separator="," open="(" close=")">#{id}</foreach>
|
<foreach item="id" collection="params.ids.split(',')" separator="," open="(" close=")">#{id}</foreach>
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
<if test="params.appIds != null and params.appIds != ''">
|
|
||||||
AND app.id in
|
|
||||||
<foreach item="id" collection="params.appIds.split(',')" separator="," open="(" close=")">#{id}</foreach>
|
|
||||||
</if>
|
|
||||||
|
|
||||||
<if test="params.packageIds != null and params.packageIds != ''">
|
<if test="params.packageIds != null and params.packageIds != ''">
|
||||||
AND pkg.id in
|
AND pkg.id in
|
||||||
<foreach item="id" collection="params.packageIds.split(',')" separator="," open="(" close=")">#{id}</foreach>
|
<foreach item="id" collection="params.packageIds.split(',')" separator="," open="(" close=")">#{id}</foreach>
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
<if test="params.runnerIds != null and params.runnerIds != ''">
|
<if test="params.environmentIds != null and params.environmentIds != ''">
|
||||||
AND run.id in
|
AND env.id in
|
||||||
<foreach item="id" collection="params.runnerIds.split(',')" separator="," open="(" close=")">#{id}</foreach>
|
<foreach item="id" collection="params.environmentIds.split(',')" separator="," open="(" close=")">#{id}</foreach>
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
<if test="params.playbooks != null and params.playbooks != ''">
|
<if test="params.playbooks != null and params.playbooks != ''">
|
||||||
AND pb.id in
|
AND pb.id in
|
||||||
<foreach item="id" collection="params.playbooks.split(',')" separator="," open="(" close=")">#{id}</foreach>
|
<foreach item="id" collection="params.playbooks.split(',')" separator="," open="(" close=")">#{id}</foreach>
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
<if test="params.signatureIds != null and params.signatureIds != ''">
|
|
||||||
AND <foreach item="item" collection="params.signatureIds.split(',')" separator="OR" index="" open="(" close=")">
|
|
||||||
locate(#{item}, job.signature_ids)
|
|
||||||
</foreach>
|
|
||||||
</if>
|
|
||||||
|
|
||||||
<if test="params.workbookId != null and params.workbookId != ''">
|
|
||||||
AND wr.workbook_id = #{params.workbookId}
|
|
||||||
</if>
|
|
||||||
|
|
||||||
<if test="params.workspaceId != null and params.workspaceId != ''">
|
<if test="params.workspaceId != null and params.workspaceId != ''">
|
||||||
AND job.workspace_id = #{params.workspaceId}
|
AND job.workspace_id = #{params.workspaceId}
|
||||||
</if>
|
</if>
|
||||||
@@ -122,26 +90,4 @@
|
|||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getPendingJobByPlatform" resultMap="jobResultMap">
|
|
||||||
SELECT
|
|
||||||
job.*,
|
|
||||||
|
|
||||||
pkg.id AS pkg_id,
|
|
||||||
pkg.platform AS pkg_platform,
|
|
||||||
pkg.identifier AS pkg_identifier,
|
|
||||||
pkg.version AS pkg_version,
|
|
||||||
|
|
||||||
pb.id AS pb_id,
|
|
||||||
pb.name AS pb_name
|
|
||||||
FROM
|
|
||||||
job job
|
|
||||||
LEFT JOIN package pkg ON job.package_id = pkg.id
|
|
||||||
LEFT JOIN playbook pb ON job.playbook_id = pb.id
|
|
||||||
WHERE
|
|
||||||
job.status = 'pending' and pkg.platform = #{platform}
|
|
||||||
ORDER BY job.create_timestamp ASC
|
|
||||||
LIMIT 1
|
|
||||||
</select>
|
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -135,6 +135,9 @@ INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_
|
|||||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (227, '601004', 'ENVIRONMENT_STATUS_ERROR', '环境状态不可用', 'zh', '', 'admin', 1724030366000);
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (227, '601004', 'ENVIRONMENT_STATUS_ERROR', '环境状态不可用', 'zh', '', 'admin', 1724030366000);
|
||||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (228, '100019', 'SYS_USER_OLDPWD_INCORRECT', 'Incorrect old password. Please try again.', 'en', '', 'admin', 1724030366000);
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (228, '100019', 'SYS_USER_OLDPWD_INCORRECT', 'Incorrect old password. Please try again.', 'en', '', 'admin', 1724030366000);
|
||||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (229, '100019', 'SYS_USER_OLDPWD_INCORRECT', '旧密码不正确,请重新输入', 'zh', '', 'admin', 1724030366000);
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (229, '100019', 'SYS_USER_OLDPWD_INCORRECT', '旧密码不正确,请重新输入', 'zh', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (230, '302002', 'PLAYBOOK_NAME_DUPLICATE', 'playbook name duplicate', 'en', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (231, '302002', 'PLAYBOOK_NAME_DUPLICATE', '剧本名称重复', 'zh', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (232, '601005', 'ENVIRONMENT_ID_CANNOT_EMPTY', 'environment id cannot be empty', 'en', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (233, '601005', 'ENVIRONMENT_ID_CANNOT_EMPTY', '环境 id 不能为空', 'zh', '', 'admin', 1724030366000);
|
||||||
|
|
||||||
SET FOREIGN_KEY_CHECKS = 1;
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
|
|||||||
@@ -200,10 +200,8 @@ CREATE TABLE `job` (
|
|||||||
`id` varchar(64) NOT NULL COMMENT '主键',
|
`id` varchar(64) NOT NULL COMMENT '主键',
|
||||||
`playbook_id` varchar(64) NOT NULL DEFAULT '' COMMENT 'Playbook ID',
|
`playbook_id` varchar(64) NOT NULL DEFAULT '' COMMENT 'Playbook ID',
|
||||||
`package_id` varchar(64) NOT NULL DEFAULT '' COMMENT 'Package ID',
|
`package_id` varchar(64) NOT NULL DEFAULT '' COMMENT 'Package ID',
|
||||||
`runner_id` varchar(64) NOT NULL DEFAULT '' COMMENT 'Runner ID',
|
`env_id` varchar(64) NOT NULL DEFAULT '' COMMENT 'env ID',
|
||||||
`schedule_id` varchar(64) NOT NULL DEFAULT '' COMMENT '定时器ID',
|
`playbook_param` varchar(1024) NOT NULL DEFAULT '' COMMENT 'playbook运行参数',
|
||||||
`signature_ids` text NOT NULL DEFAULT '' COMMENT '特征ID,多个逗号分隔',
|
|
||||||
`tags` varchar(256) NOT NULL DEFAULT '' COMMENT '标签; 默认:"";多个用逗号分隔;例:kz,vpn,android',
|
|
||||||
`start_timestamp` bigint(20) NOT NULL DEFAULT -1 COMMENT '开始时间戳',
|
`start_timestamp` bigint(20) NOT NULL DEFAULT -1 COMMENT '开始时间戳',
|
||||||
`end_timestamp` bigint(20) NOT NULL DEFAULT -1 COMMENT '结束时间戳',
|
`end_timestamp` bigint(20) NOT NULL DEFAULT -1 COMMENT '结束时间戳',
|
||||||
`status` varchar(64) NOT NULL DEFAULT '' COMMENT '状态; 可选值: created,pending,running,passed,failed,cancel',
|
`status` varchar(64) NOT NULL DEFAULT '' COMMENT '状态; 可选值: created,pending,running,passed,failed,cancel',
|
||||||
@@ -217,7 +215,7 @@ CREATE TABLE `job` (
|
|||||||
PRIMARY KEY (`id`) USING BTREE,
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
KEY `idx_playbook_id` (`playbook_id`) USING BTREE,
|
KEY `idx_playbook_id` (`playbook_id`) USING BTREE,
|
||||||
KEY `idx_package_id` (`package_id`) USING BTREE,
|
KEY `idx_package_id` (`package_id`) USING BTREE,
|
||||||
KEY `idx_runner_id` (`runner_id`) USING BTREE,
|
KEY `idx_env_id` (`env_id`) USING BTREE,
|
||||||
KEY `idx_workspace_id` (`workspace_id`) USING BTREE
|
KEY `idx_workspace_id` (`workspace_id`) USING BTREE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user