Search in sources :

Example 1 with StatusInfo

use of com.flink.platform.web.monitor.StatusInfo in project flink-platform-backend by itinycheng.

the class JobExecuteThread method waitForComplete.

public StatusInfo waitForComplete(String routeUrl, JobRunInfo jobRunInfo) {
    int retryTimes = 0;
    int errorTimes = 0;
    boolean isRemote = isRemoteUrl(routeUrl);
    while (AppRunner.isRunning()) {
        try {
            StatusInfo statusInfo;
            if (isRemote) {
                HttpHeaders headers = new HttpHeaders();
                headers.setContentType(MediaType.APPLICATION_JSON);
                HttpEntity<JobRunInfo> requestEntity = new HttpEntity<>(jobRunInfo, headers);
                statusInfo = restTemplate.postForObject(routeUrl + REST_GET_STATUS, requestEntity, StatusInfo.class);
            } else {
                statusInfo = processJobStatusService.getStatus(jobRunInfo);
            }
            if (jobRunInfo.getExecMode() == STREAMING) {
                if (jobRunInfo.getCreateTime() == null) {
                    jobRunInfo.setCreateTime(LocalDateTime.now());
                }
                statusInfo = updateAndGetStreamJobStatus(statusInfo, jobRunInfo.getCreateTime());
            }
            if (statusInfo != null) {
                log.info("Job runId: {}, name: {} Status: {}", jobRunInfo.getJobId(), jobRunInfo.getName(), statusInfo.getStatus());
                if (statusInfo.getStatus().isTerminalState()) {
                    return statusInfo;
                }
            }
        } catch (Exception e) {
            if (++errorTimes > errorRetries) {
                return new CustomizeStatusInfo(ERROR, LocalDateTime.now(), LocalDateTime.now());
            }
        }
        sleep(++retryTimes);
    }
    return null;
}
Also used : CustomizeStatusInfo(com.flink.platform.web.monitor.CustomizeStatusInfo) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) StatusInfo(com.flink.platform.web.monitor.StatusInfo) CustomizeStatusInfo(com.flink.platform.web.monitor.CustomizeStatusInfo) JobRunInfo(com.flink.platform.dao.entity.JobRunInfo)

Example 2 with StatusInfo

use of com.flink.platform.web.monitor.StatusInfo in project flink-platform-backend by itinycheng.

the class JobExecuteThread method call.

@Override
public JobResponse call() {
    Long jobId = jobVertex.getJobId();
    Long jobRunId = jobVertex.getJobRunId();
    try {
        // Step 1: get job info
        JobInfo jobInfo = jobInfoService.getOne(new QueryWrapper<JobInfo>().lambda().eq(JobInfo::getId, jobId).eq(JobInfo::getStatus, JobStatus.ONLINE));
        if (jobInfo == null) {
            log.warn("The job:{} is no longer exists or not in ready/scheduled status.", jobId);
            return new JobResponse(jobId, jobRunId, NOT_EXIST);
        }
        // Step 2: build route url, set localhost as default url if not specified.
        String routeUrl = jobInfo.getRouteUrl();
        routeUrl = HttpUtil.getUrlOrDefault(routeUrl);
        // Step 3: process job and get jobRun.
        JobRunInfo jobRunInfo;
        if (jobRunId != null) {
            jobRunInfo = jobRunInfoService.getById(jobRunId);
            log.info("Job:{} already submitted, runId = {}.", jobId, jobRunId);
        } else {
            jobRunInfo = processRemoteJob(routeUrl, jobId);
        }
        if (jobRunInfo == null) {
            log.warn("The jobRun:{} is no longer exists.", jobRunId);
            return new JobResponse(jobId, jobRunId, NOT_EXIST);
        }
        // Step 4: Update jobRunId in Memory.
        jobRunId = jobRunInfo.getId();
        // Step 5: Wait for job complete and get final status.
        ExecutionStatus status = jobRunInfo.getStatus();
        if (status == null || !status.isTerminalState()) {
            StatusInfo statusInfo = waitForComplete(routeUrl, jobRunInfo);
            if (statusInfo != null) {
                status = statusInfo.getStatus();
                updateJobRunInfo(jobRunId, statusInfo.getStatus(), statusInfo.getEndTime());
            }
        }
        return new JobResponse(jobId, jobRunId, status);
    } catch (Exception e) {
        log.error("Submit job and wait for complete failed.", e);
        updateJobRunInfo(jobRunId, ERROR, LocalDateTime.now());
        return new JobResponse(jobId, jobRunId, ERROR);
    }
}
Also used : JobInfo(com.flink.platform.dao.entity.JobInfo) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ExecutionStatus(com.flink.platform.common.enums.ExecutionStatus) StatusInfo(com.flink.platform.web.monitor.StatusInfo) CustomizeStatusInfo(com.flink.platform.web.monitor.CustomizeStatusInfo) JobRunInfo(com.flink.platform.dao.entity.JobRunInfo)

Aggregations

JobRunInfo (com.flink.platform.dao.entity.JobRunInfo)2 CustomizeStatusInfo (com.flink.platform.web.monitor.CustomizeStatusInfo)2 StatusInfo (com.flink.platform.web.monitor.StatusInfo)2 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 ExecutionStatus (com.flink.platform.common.enums.ExecutionStatus)1 JobInfo (com.flink.platform.dao.entity.JobInfo)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1