Search in sources :

Example 1 with JobFlow

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);
}
Also used : JobFlowDag(com.flink.platform.dao.entity.JobFlowDag) JobFlowRequest(com.flink.platform.web.entity.request.JobFlowRequest) JobFlow(com.flink.platform.dao.entity.JobFlow) JobFlowStatus(com.flink.platform.common.enums.JobFlowStatus) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with JobFlow

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());
}
Also used : JobFlow(com.flink.platform.dao.entity.JobFlow) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiException(com.flink.platform.web.config.annotation.ApiException)

Example 3 with JobFlow

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());
    }
}
Also used : JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey) JobVertex(com.flink.platform.common.model.JobVertex) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) JobFlow(com.flink.platform.dao.entity.JobFlow) JobEdge(com.flink.platform.common.model.JobEdge) JobFlowRun(com.flink.platform.dao.entity.JobFlowRun)

Example 4 with JobFlow

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);
}
Also used : JobFlowRequest(com.flink.platform.web.entity.request.JobFlowRequest) JobFlow(com.flink.platform.dao.entity.JobFlow) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with JobFlow

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);
}
Also used : JobFlow(com.flink.platform.dao.entity.JobFlow) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

JobFlow (com.flink.platform.dao.entity.JobFlow)9 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 JobFlowQuartzInfo (com.flink.platform.web.entity.JobFlowQuartzInfo)3 Transactional (org.springframework.transaction.annotation.Transactional)3 JobFlowStatus (com.flink.platform.common.enums.JobFlowStatus)2 JobFlowDag (com.flink.platform.dao.entity.JobFlowDag)2 JobFlowRun (com.flink.platform.dao.entity.JobFlowRun)2 JobFlowRequest (com.flink.platform.web.entity.request.JobFlowRequest)2 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 JobEdge (com.flink.platform.common.model.JobEdge)1 JobVertex (com.flink.platform.common.model.JobVertex)1 ApiException (com.flink.platform.web.config.annotation.ApiException)1 JobDetail (org.quartz.JobDetail)1 JobKey (org.quartz.JobKey)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1