use of com.flink.platform.dao.entity.JobFlow in project flink-platform-backend by itinycheng.
the class JobFlowController method start.
@GetMapping(value = "/schedule/start/{flowId}")
public ResultInfo<Long> start(@PathVariable Long flowId) {
JobFlowRequest jobFlowRequest = new JobFlowRequest();
jobFlowRequest.setId(flowId);
String errorMsg = jobFlowRequest.verifyId();
if (StringUtils.isNotBlank(errorMsg)) {
return failure(ERROR_PARAMETER, errorMsg);
}
JobFlow jobFlow = jobFlowService.getById(jobFlowRequest.getId());
JobFlowStatus status = jobFlow.getStatus();
if (status == null || !status.isRunnable()) {
return failure(NOT_RUNNABLE_STATUS);
}
if (StringUtils.isEmpty(jobFlow.getCronExpr())) {
return failure(NO_CRONTAB_SET);
}
JobFlowDag flow = jobFlow.getFlow();
if (flow == null || jobFlowService.containsStreamingJob(flow)) {
return failure(UNABLE_SCHEDULE_STREAMING_JOB);
}
jobFlowQuartzService.scheduleJob(jobFlow);
return ResultInfo.success(flowId);
}
use of com.flink.platform.dao.entity.JobFlow in project flink-platform-backend by itinycheng.
the class JobFlowController method create.
@ApiException
@PostMapping(value = "/create")
public ResultInfo<Long> create(@RequestAttribute(value = Constant.SESSION_USER) User loginUser, @RequestBody JobFlowRequest jobFlowRequest) {
String errorMsg = jobFlowRequest.validateOnCreate();
if (StringUtils.isNotBlank(errorMsg)) {
return failure(ERROR_PARAMETER, errorMsg);
}
JobFlow jobFlow = jobFlowRequest.getJobFlow();
jobFlow.setId(null);
jobFlow.setCode(UuidGenerator.generateShortUuid());
jobFlow.setUserId(loginUser.getId());
jobFlow.setStatus(JobFlowStatus.OFFLINE);
jobFlowService.save(jobFlow);
return ResultInfo.success(jobFlowRequest.getId());
}
use of com.flink.platform.dao.entity.JobFlow in project flink-platform-backend by itinycheng.
the class JobFlowRunner method execute.
@Override
public void execute(JobExecutionContext context) {
JobDetail detail = context.getJobDetail();
JobKey key = detail.getKey();
String code = key.getName();
synchronized (getProcessLock(code)) {
// Get job flow info.
JobFlow jobFlow = jobFlowService.getOne(new QueryWrapper<JobFlow>().lambda().eq(JobFlow::getCode, code).in(JobFlow::getStatus, ONLINE, SCHEDULING));
if (jobFlow == null) {
log.warn("The job flow: {} isn't exists or not in scheduling status", code);
return;
}
// Validate flow json.
DAG<Long, JobVertex, JobEdge> flow = jobFlow.getFlow();
if (flow == null || flow.getVertices().isEmpty()) {
log.warn("The job flow: {} doesn't contain any vertices", jobFlow.getCode());
return;
}
// Avoid preforming the same job flow multiple times at the same time.
JobFlowRun jobFlowRun = jobFlowRunService.getOne(new QueryWrapper<JobFlowRun>().lambda().eq(JobFlowRun::getFlowId, jobFlow.getId()).in(JobFlowRun::getStatus, getNonTerminals()));
if (jobFlowRun != null) {
log.warn("The job flow:{} is in non-terminal status, run id: {}", jobFlow.getId(), jobFlowRun.getId());
return;
}
// Create job flow run instance.
jobFlowRun = new JobFlowRun();
jobFlowRun.setFlowId(jobFlow.getId());
jobFlowRun.setName(String.join("-", jobFlow.getName(), jobFlow.getCode(), String.valueOf(System.currentTimeMillis())));
jobFlowRun.setFlow(jobFlow.getFlow());
jobFlowRun.setUserId(jobFlow.getUserId());
jobFlowRun.setHost(Constant.HOST_IP);
jobFlowRun.setPriority(jobFlow.getPriority());
jobFlowRun.setAlerts(jobFlow.getAlerts());
jobFlowRun.setStatus(SUBMITTED);
jobFlowRunService.save(jobFlowRun);
// register job flow run.
jobFlowScheduleService.registerToScheduler(jobFlowRun);
log.info("Job flow run: {} is created, job flow: {}, time: {}", jobFlowRun.getFlowId(), code, System.currentTimeMillis());
}
}
use of com.flink.platform.dao.entity.JobFlow in project flink-platform-backend by itinycheng.
the class JobFlowController method stop.
@GetMapping(value = "/schedule/stop/{flowId}")
public ResultInfo<Long> stop(@PathVariable Long flowId) {
JobFlowRequest jobFlowRequest = new JobFlowRequest();
jobFlowRequest.setId(flowId);
String errorMsg = jobFlowRequest.verifyId();
if (StringUtils.isNotBlank(errorMsg)) {
return failure(ERROR_PARAMETER, errorMsg);
}
JobFlow jobFlow = jobFlowService.getById(jobFlowRequest.getId());
if (jobFlow == null) {
return failure(SERVICE_ERROR, "Job flow not found");
}
jobFlowQuartzService.stopJob(jobFlow);
return ResultInfo.success(flowId);
}
use of com.flink.platform.dao.entity.JobFlow in project flink-platform-backend by itinycheng.
the class JobFlowController method delete.
@GetMapping(value = "/delete/{flowId}")
public ResultInfo<Boolean> delete(@RequestAttribute(value = Constant.SESSION_USER) User loginUser, @PathVariable long flowId) {
JobFlow jobFlow = jobFlowService.getById(flowId);
if (jobFlow == null) {
return ResultInfo.failure(ERROR_PARAMETER);
}
if (!loginUser.getId().equals(jobFlow.getUserId())) {
return ResultInfo.failure(USER_HAVE_NO_PERMISSION);
}
boolean bool = jobFlowService.deleteAllById(flowId);
return ResultInfo.success(bool);
}
Aggregations