use of com.flink.platform.dao.entity.JobInfo in project flink-platform-backend by itinycheng.
the class JobRunner method execute.
@Override
public void execute(JobExecutionContext context) {
JobDetail detail = context.getJobDetail();
JobDataMap jobDataMap = detail.getJobDataMap();
JobKey key = detail.getKey();
Long jobId = Long.parseLong(key.getName());
try {
// Avoid preforming the same job multiple times at the same time.
Long previous = RUNNER_MAP.putIfAbsent(jobId, System.currentTimeMillis());
if (previous != null && previous > 0) {
log.warn("The job: {} is already running, start time: {}", jobId, previous);
return;
}
// 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;
}
// Step 2: build cluster url, set localhost as default url if not specified.
String routeUrl = jobInfo.getRouteUrl();
routeUrl = HttpUtil.getUrlOrDefault(routeUrl);
// Step 3: send http request.
Map<String, Object> wrappedMap = jobDataMap.getWrappedMap();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(APPLICATION_JSON);
String httpUri = routeUrl + String.format(JOB_PROCESS_REST_PATH, jobId);
ResultInfo<Long> response = restTemplate.exchange(httpUri, HttpMethod.POST, new HttpEntity<>(wrappedMap, headers), new ParameterizedTypeReference<ResultInfo<Long>>() {
}).getBody();
log.info("The job: {} is processed, job run result: {}", jobId, response);
} catch (Exception e) {
log.error("Cannot exec job: {}", jobId, e);
} finally {
RUNNER_MAP.remove(jobId);
}
}
use of com.flink.platform.dao.entity.JobInfo 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);
}
}
use of com.flink.platform.dao.entity.JobInfo in project flink-platform-backend by itinycheng.
the class JobInfoController method update.
@PostMapping(value = "/update")
public ResultInfo<JobInfo> update(@RequestBody JobInfoRequest jobInfoRequest) {
String errorMsg = jobInfoRequest.validateOnUpdate();
if (StringUtils.isNotBlank(errorMsg)) {
return failure(ERROR_PARAMETER, errorMsg);
}
JobInfo jobInfo = jobInfoRequest.getJobInfo();
jobInfoService.updateById(jobInfo);
return ResultInfo.success(jobInfo);
}
use of com.flink.platform.dao.entity.JobInfo in project flink-platform-backend by itinycheng.
the class JobInfoController method create.
@PostMapping(value = "/create")
public ResultInfo<JobInfo> create(@RequestBody JobInfoRequest jobInfoRequest) {
String errorMsg = jobInfoRequest.validateOnCreate();
if (StringUtils.isNotBlank(errorMsg)) {
return failure(ERROR_PARAMETER, errorMsg);
}
JobInfo jobInfo = jobInfoRequest.getJobInfo();
jobInfo.setId(null);
jobInfo.setStatus(JobStatus.ONLINE);
jobInfoService.save(jobInfo);
return ResultInfo.success(jobInfo);
}
use of com.flink.platform.dao.entity.JobInfo in project flink-platform-backend by itinycheng.
the class UserGroupController method createOrUpdate.
@PostMapping(value = "/createOrUpdate")
public ResultInfo<Long> createOrUpdate(@RequestBody UserGroupRequest userGroupRequest) {
try {
ResultInfo<String> sqlInfo = insertSelect(userGroupRequest.getSelect());
String sql = sqlInfo.getData();
JobInfo jobInfo = new JobInfo();
BeanUtils.copyProperties(userGroupRequest, jobInfo);
jobInfo.setSubject(sql);
jobInfo.setType(JobType.FLINK_SQL);
jobInfo.setDeployMode(DeployMode.FLINK_YARN_PER);
jobInfo.setExecMode(ExecutionMode.BATCH);
LongArrayList longs = new LongArrayList();
longs.add(1L);
jobInfo.setCatalogs(longs);
jobInfo.setStatus(JobStatus.ONLINE);
boolean bool = jobInfoService.saveOrUpdate(jobInfo);
if (bool && userGroupRequest.getId() == null) {
JobQuartzInfo jobQuartzInfo = new JobQuartzInfo(jobInfo);
quartzService.runOnce(jobQuartzInfo);
quartzService.addJobToQuartz(jobQuartzInfo);
}
return ResultInfo.success(jobInfo.getId());
} catch (Exception e) {
log.error("create or update user group failed", e);
return ResultInfo.failure(ResponseStatus.SERVICE_ERROR);
}
}
Aggregations