use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper 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.baomidou.mybatisplus.core.conditions.query.QueryWrapper 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);
}
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper 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());
}
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project flink-platform-backend by itinycheng.
the class ProcessJobService method processJob.
public JobRunInfo processJob(final long jobId, final long flowRunId) throws Exception {
JobCommand jobCommand = null;
JobInfo jobInfo = null;
try {
// step 1: get job info
jobInfo = jobInfoService.getOne(new QueryWrapper<JobInfo>().lambda().eq(JobInfo::getId, jobId).eq(JobInfo::getStatus, JobStatus.ONLINE));
if (jobInfo == null) {
throw new JobCommandGenException(String.format("The job: %s is no longer exists or in delete status.", jobId));
}
// step 2: replace variables in the sql statement
JobInfo finalJobInfo = jobInfo;
Map<String, Object> variableMap = Arrays.stream(SqlVar.values()).filter(sqlVar -> sqlVar.type == SqlVar.VarType.VARIABLE).filter(sqlVar -> finalJobInfo.getSubject().contains(sqlVar.variable)).map(sqlVar -> Pair.of(sqlVar.variable, sqlVar.valueProvider.apply(finalJobInfo))).collect(toMap(Pair::getLeft, Pair::getRight));
MapUtils.emptyIfNull(finalJobInfo.getVariables()).forEach((name, value) -> {
SqlVar sqlVar = SqlVar.matchPrefix(name);
variableMap.put(name, sqlVar.valueProvider.apply(value));
});
// replace variable with actual value
for (Map.Entry<String, Object> entry : variableMap.entrySet()) {
String originSubject = jobInfo.getSubject();
String distSubject = originSubject.replace(entry.getKey(), entry.getValue().toString());
jobInfo.setSubject(distSubject);
}
JobType jobType = jobInfo.getType();
String version = jobInfo.getVersion();
// step 3: build job command, create a SqlContext if needed
jobCommand = jobCommandBuilders.stream().filter(builder -> builder.isSupported(jobType, version)).findFirst().orElseThrow(() -> new JobCommandGenException("No available job command builder")).buildCommand(jobInfo);
// step 4: submit job
LocalDateTime submitTime = LocalDateTime.now();
String commandString = jobCommand.toCommandString();
JobCallback callback = jobCommandExecutors.stream().filter(executor -> executor.isSupported(jobType)).findFirst().orElseThrow(() -> new JobCommandGenException("No available job command executor")).execCommand(commandString);
// step 5: write job run info to db
ExecutionStatus executionStatus = getExecutionStatus(jobType, callback);
JobRunInfo jobRunInfo = new JobRunInfo();
jobRunInfo.setName(jobInfo.getName() + "-" + System.currentTimeMillis());
jobRunInfo.setJobId(jobInfo.getId());
jobRunInfo.setFlowRunId(flowRunId);
jobRunInfo.setDeployMode(jobInfo.getDeployMode());
jobRunInfo.setExecMode(jobInfo.getExecMode());
jobRunInfo.setSubject(jobInfo.getSubject());
jobRunInfo.setStatus(executionStatus);
jobRunInfo.setVariables(JsonUtil.toJsonString(variableMap));
jobRunInfo.setBackInfo(JsonUtil.toJsonString(callback));
jobRunInfo.setSubmitTime(submitTime);
if (executionStatus.isTerminalState()) {
jobRunInfo.setStopTime(LocalDateTime.now());
}
jobRunInfoService.save(jobRunInfo);
// step 6: print job command info
log.info("Job: {} submitted, time: {}", jobId, System.currentTimeMillis());
return jobRunInfo;
} finally {
if (jobInfo != null && jobInfo.getType() == JobType.FLINK_SQL && jobCommand != null) {
try {
FlinkCommand flinkCommand = (FlinkCommand) jobCommand;
if (flinkCommand.getMainArgs() != null) {
Files.deleteIfExists(Paths.get(flinkCommand.getMainArgs()));
}
} catch (Exception e) {
log.warn("Delete sql context file failed", e);
}
}
}
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project codingmore-learning by itwanger.
the class UsersServiceImpl method updatePassword.
@Override
public int updatePassword(UpdateAdminPasswordParam updatePasswordParam) {
if (StringUtils.isEmpty(updatePasswordParam.getUsername()) || StringUtils.isEmpty(updatePasswordParam.getOldPassword()) || StringUtils.isEmpty(updatePasswordParam.getNewPassword())) {
return -1;
}
QueryWrapper<Users> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userLogin", updatePasswordParam.getUsername());
List<Users> usersList = baseMapper.selectList(queryWrapper);
if (CollUtil.isEmpty(usersList)) {
return -2;
}
Users user = usersList.get(0);
if (!passwordEncoder.matches(updatePasswordParam.getOldPassword(), user.getUserPass())) {
return -3;
}
user.setUserPass(passwordEncoder.encode(updatePasswordParam.getNewPassword()));
baseMapper.updateById(user);
// adminCacheService.delAdmin(umsAdmin.getId());
return 1;
}
Aggregations