Search in sources :

Example 1 with JobFlowRun

use of com.flink.platform.dao.entity.JobFlowRun in project flink-platform-backend by itinycheng.

the class FlowExecuteThread method completeAndNotify.

/**
 * Update status of jobFlow and send notification.
 */
private void completeAndNotify(JobFlowDag flow) {
    ExecutionStatus finalStatus = JobFlowDagHelper.getDagState(flow);
    if (finalStatus.isTerminalState()) {
        jobFlowRun.setStatus(finalStatus);
        JobFlowRun newJobFlowRun = new JobFlowRun();
        newJobFlowRun.setId(jobFlowRun.getId());
        newJobFlowRun.setStatus(finalStatus);
        jobFlowRunService.updateById(newJobFlowRun);
        // send notification.
        sendNotification();
    }
}
Also used : ExecutionStatus(com.flink.platform.common.enums.ExecutionStatus) JobFlowRun(com.flink.platform.dao.entity.JobFlowRun)

Example 2 with JobFlowRun

use of com.flink.platform.dao.entity.JobFlowRun in project flink-platform-backend by itinycheng.

the class InitJobFlowScheduler method appendExistedJobFlowRunToScheduler.

public void appendExistedJobFlowRunToScheduler() {
    List<JobFlowRun> unfinishedFlowRunList = jobFlowRunService.list(new QueryWrapper<JobFlowRun>().lambda().eq(JobFlowRun::getHost, Constant.HOST_IP).in(JobFlowRun::getStatus, getNonTerminals()));
    for (JobFlowRun jobFlowRun : unfinishedFlowRunList) {
        DAG<Long, JobVertex, JobEdge> flow = jobFlowRun.getFlow();
        // Update status of JobVertex in flow.
        jobRunInfoService.list(new QueryWrapper<JobRunInfo>().lambda().eq(JobRunInfo::getFlowRunId, jobFlowRun.getId())).forEach(jobRunInfo -> {
            JobVertex vertex = flow.getVertex(jobRunInfo.getJobId());
            vertex.setJobRunId(jobRunInfo.getId());
            vertex.setJobRunStatus(jobRunInfo.getStatus());
        });
        jobFlowScheduleService.registerToScheduler(jobFlowRun);
    }
}
Also used : JobVertex(com.flink.platform.common.model.JobVertex) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) JobEdge(com.flink.platform.common.model.JobEdge) JobRunInfo(com.flink.platform.dao.entity.JobRunInfo) JobFlowRun(com.flink.platform.dao.entity.JobFlowRun)

Example 3 with JobFlowRun

use of com.flink.platform.dao.entity.JobFlowRun 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 JobFlowRun

use of com.flink.platform.dao.entity.JobFlowRun in project flink-platform-backend by itinycheng.

the class JobFlowScheduleService method registerToScheduler.

public synchronized void registerToScheduler(JobFlowRun jobFlowRun) {
    JobFlowDag flow = jobFlowRun.getFlow();
    if (flow == null || CollectionUtils.isEmpty(flow.getVertices())) {
        log.warn("No JobVertex found, no scheduling required, flow run id: {}", jobFlowRun.getId());
        return;
    }
    if (inFlightFlows.stream().anyMatch(inQueue -> inQueue.getId().equals(jobFlowRun.getId()))) {
        log.warn("The JobFlowRun already registered, jobFlowRun: {} ", jobFlowRun);
        return;
    }
    if (inFlightFlows.size() > 2 * workerConfig.getFlowExecThreads()) {
        log.warn("Not have enough resources to execute flow: {}", jobFlowRun);
        JobFlowRun newJobFlowRun = new JobFlowRun();
        newJobFlowRun.setId(jobFlowRun.getId());
        newJobFlowRun.setStatus(FAILURE);
        newJobFlowRun.setEndTime(LocalDateTime.now());
        jobFlowRunService.updateById(newJobFlowRun);
        return;
    }
    inFlightFlows.offer(jobFlowRun);
}
Also used : JobFlowDag(com.flink.platform.dao.entity.JobFlowDag) JobFlowRun(com.flink.platform.dao.entity.JobFlowRun)

Example 5 with JobFlowRun

use of com.flink.platform.dao.entity.JobFlowRun in project flink-platform-backend by itinycheng.

the class JobFlowController method runOnce.

@GetMapping(value = "/schedule/runOnce/{flowId}")
public ResultInfo<Long> runOnce(@PathVariable Long flowId) {
    JobFlow jobFlow = jobFlowService.getById(flowId);
    JobFlowStatus status = jobFlow.getStatus();
    if (status == null || !status.isRunnable()) {
        return failure(NOT_RUNNABLE_STATUS);
    }
    // TODO better in sync lock.
    JobFlowRun jobFlowRun = jobFlowRunService.getById(flowId);
    if (jobFlowRun != null && !jobFlowRun.getStatus().isTerminalState()) {
        return failure(SERVICE_ERROR);
    }
    JobFlowQuartzInfo jobFlowQuartzInfo = new JobFlowQuartzInfo(jobFlow);
    if (quartzService.runOnce(jobFlowQuartzInfo)) {
        return ResultInfo.success(flowId);
    } else {
        return failure(SERVICE_ERROR);
    }
}
Also used : JobFlowQuartzInfo(com.flink.platform.web.entity.JobFlowQuartzInfo) JobFlow(com.flink.platform.dao.entity.JobFlow) JobFlowStatus(com.flink.platform.common.enums.JobFlowStatus) JobFlowRun(com.flink.platform.dao.entity.JobFlowRun) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

JobFlowRun (com.flink.platform.dao.entity.JobFlowRun)6 JobVertex (com.flink.platform.common.model.JobVertex)3 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)2 ExecutionStatus (com.flink.platform.common.enums.ExecutionStatus)2 JobEdge (com.flink.platform.common.model.JobEdge)2 JobFlow (com.flink.platform.dao.entity.JobFlow)2 JobFlowDag (com.flink.platform.dao.entity.JobFlowDag)2 RUNNING (com.flink.platform.common.enums.ExecutionStatus.RUNNING)1 JobFlowStatus (com.flink.platform.common.enums.JobFlowStatus)1 JobRunInfo (com.flink.platform.dao.entity.JobRunInfo)1 JobFlowRunService (com.flink.platform.dao.service.JobFlowRunService)1 SpringContext (com.flink.platform.web.common.SpringContext)1 WorkerConfig (com.flink.platform.web.config.WorkerConfig)1 JobFlowQuartzInfo (com.flink.platform.web.entity.JobFlowQuartzInfo)1 AlertSendingService (com.flink.platform.web.service.AlertSendingService)1 JobFlowDagHelper (com.flink.platform.web.util.JobFlowDagHelper)1 ThreadUtil (com.flink.platform.web.util.ThreadUtil)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1