Search in sources :

Example 1 with JobFlowDag

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

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

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

the class JobFlowService method updateFlowById.

@Transactional(rollbackFor = Exception.class)
public void updateFlowById(JobFlow origin) {
    if (origin.getId() == null) {
        return;
    }
    JobFlow newJobFlow = new JobFlow();
    newJobFlow.setId(origin.getId());
    if (origin.getFlow() != null) {
        newJobFlow.setFlow(origin.getFlow());
    } else {
        newJobFlow.setFlow(new JobFlowDag());
    }
    updateById(newJobFlow);
}
Also used : JobFlowDag(com.flink.platform.dao.entity.JobFlowDag) JobFlow(com.flink.platform.dao.entity.JobFlow) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with JobFlowDag

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

the class FlowExecuteThread method run.

@Override
public void run() {
    // Update status of jobFlowRun.
    JobFlowRun newJobFlowRun = new JobFlowRun();
    newJobFlowRun.setId(jobFlowRun.getId());
    newJobFlowRun.setStatus(RUNNING);
    jobFlowRunService.updateById(newJobFlowRun);
    // Process job flow.
    JobFlowDag flow = jobFlowRun.getFlow();
    flow.getBeginVertices().forEach(jobVertex -> execVertex(jobVertex, flow));
    // Wait until all vertices are executed.
    while (JobFlowDagHelper.hasUnExecutedVertices(flow)) {
        ThreadUtil.sleep(5000);
    }
    // Wait for all jobs complete.
    CompletableFuture.allOf(runningJobs.values().toArray(new CompletableFuture[0])).thenAccept(unused -> completeAndNotify(flow)).thenAccept(unused -> jobExecService.shutdownNow());
}
Also used : SpringContext(com.flink.platform.web.common.SpringContext) ThreadUtil(com.flink.platform.web.util.ThreadUtil) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JobVertex(com.flink.platform.common.model.JobVertex) CompletableFuture(java.util.concurrent.CompletableFuture) JobFlowRunService(com.flink.platform.dao.service.JobFlowRunService) Supplier(java.util.function.Supplier) CollectionUtils(org.apache.commons.collections4.CollectionUtils) RUNNING(com.flink.platform.common.enums.ExecutionStatus.RUNNING) JobFlowDagHelper(com.flink.platform.web.util.JobFlowDagHelper) Slf4j(lombok.extern.slf4j.Slf4j) ExecutionStatus(com.flink.platform.common.enums.ExecutionStatus) WorkerConfig(com.flink.platform.web.config.WorkerConfig) Map(java.util.Map) JobFlowRun(com.flink.platform.dao.entity.JobFlowRun) AlertSendingService(com.flink.platform.web.service.AlertSendingService) JobFlowDag(com.flink.platform.dao.entity.JobFlowDag) ExecutorService(java.util.concurrent.ExecutorService) CompletableFuture(java.util.concurrent.CompletableFuture) JobFlowDag(com.flink.platform.dao.entity.JobFlowDag) JobFlowRun(com.flink.platform.dao.entity.JobFlowRun)

Example 5 with JobFlowDag

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

the class JobFlowTest method test1.

@Test
public void test1() {
    JobFlowDag dag = new JobFlowDag();
    JobVertex jobVertex1 = new JobVertex(19L, 19L);
    JobVertex jobVertex2 = new JobVertex(20L, 20L);
    dag.addVertex(jobVertex1);
    dag.addVertex(jobVertex2);
    JobEdge jobEdge = new JobEdge(19L, 20L, SUCCESS);
    dag.addEdge(jobEdge);
    JobFlowRequest jobFlowRequest = new JobFlowRequest();
    jobFlowRequest.setCode(UuidGenerator.generateShortUuid());
    jobFlowRequest.setName("test_1");
    jobFlowRequest.setUserId(0L);
    jobFlowRequest.setDescription("description");
    jobFlowRequest.setCronExpr("0 0/10 * * * ?");
    jobFlowRequest.setFlow(dag);
    jobFlowRequest.setPriority(8);
    jobFlowRequest.setAlerts(new LongArrayList());
    jobFlowRequest.setStatus(OFFLINE);
    String json = JsonUtil.toJsonString(jobFlowRequest.getJobFlow());
    System.out.println(json);
}
Also used : JobFlowDag(com.flink.platform.dao.entity.JobFlowDag) JobVertex(com.flink.platform.common.model.JobVertex) JobFlowRequest(com.flink.platform.web.entity.request.JobFlowRequest) JobEdge(com.flink.platform.common.model.JobEdge) LongArrayList(com.flink.platform.dao.entity.LongArrayList) Test(org.junit.Test)

Aggregations

JobFlowDag (com.flink.platform.dao.entity.JobFlowDag)5 JobVertex (com.flink.platform.common.model.JobVertex)2 JobFlow (com.flink.platform.dao.entity.JobFlow)2 JobFlowRun (com.flink.platform.dao.entity.JobFlowRun)2 JobFlowRequest (com.flink.platform.web.entity.request.JobFlowRequest)2 ExecutionStatus (com.flink.platform.common.enums.ExecutionStatus)1 RUNNING (com.flink.platform.common.enums.ExecutionStatus.RUNNING)1 JobFlowStatus (com.flink.platform.common.enums.JobFlowStatus)1 JobEdge (com.flink.platform.common.model.JobEdge)1 LongArrayList (com.flink.platform.dao.entity.LongArrayList)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 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 ExecutorService (java.util.concurrent.ExecutorService)1