Search in sources :

Example 91 with QueryWrapper

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);
    }
}
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)

Example 92 with QueryWrapper

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);
    }
}
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 93 with QueryWrapper

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());
    }
}
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 94 with QueryWrapper

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);
            }
        }
    }
}
Also used : Arrays(java.util.Arrays) JsonUtil(com.flink.platform.common.util.JsonUtil) FlinkCommand(com.flink.platform.web.command.FlinkCommand) JobCallback(com.flink.platform.web.command.JobCallback) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) JobInfoService(com.flink.platform.dao.service.JobInfoService) SqlVar(com.flink.platform.web.enums.SqlVar) Pair(org.apache.commons.lang3.tuple.Pair) Collectors.toMap(java.util.stream.Collectors.toMap) Service(org.springframework.stereotype.Service) Map(java.util.Map) SUCCESS(com.flink.platform.common.enums.ExecutionStatus.SUCCESS) JobStatus(com.flink.platform.common.enums.JobStatus) CommandBuilder(com.flink.platform.web.command.CommandBuilder) JobType(com.flink.platform.common.enums.JobType) MapUtils(org.apache.commons.collections4.MapUtils) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) JobInfo(com.flink.platform.dao.entity.JobInfo) Files(java.nio.file.Files) JobRunInfoService(com.flink.platform.dao.service.JobRunInfoService) JobRunInfo(com.flink.platform.dao.entity.JobRunInfo) CommandExecutor(com.flink.platform.web.command.CommandExecutor) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ExecutionStatus(com.flink.platform.common.enums.ExecutionStatus) JobCommand(com.flink.platform.web.command.JobCommand) Paths(java.nio.file.Paths) JobCommandGenException(com.flink.platform.common.exception.JobCommandGenException) LocalDateTime(java.time.LocalDateTime) JobCommandGenException(com.flink.platform.common.exception.JobCommandGenException) JobRunInfo(com.flink.platform.dao.entity.JobRunInfo) JobCommandGenException(com.flink.platform.common.exception.JobCommandGenException) JobType(com.flink.platform.common.enums.JobType) SqlVar(com.flink.platform.web.enums.SqlVar) JobInfo(com.flink.platform.dao.entity.JobInfo) ExecutionStatus(com.flink.platform.common.enums.ExecutionStatus) JobCommand(com.flink.platform.web.command.JobCommand) FlinkCommand(com.flink.platform.web.command.FlinkCommand) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) JobCallback(com.flink.platform.web.command.JobCallback)

Example 95 with QueryWrapper

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;
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Users(com.codingmore.model.Users)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)723 Transactional (org.springframework.transaction.annotation.Transactional)98 IPage (com.baomidou.mybatisplus.core.metadata.IPage)82 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)74 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)72 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)65 ArrayList (java.util.ArrayList)61 Session (org.apache.shiro.session.Session)61 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)60 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)55 Problem (top.hcode.hoj.pojo.entity.problem.Problem)50 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)45 Date (java.util.Date)44 HttpServletRequest (javax.servlet.http.HttpServletRequest)35 HashMap (java.util.HashMap)34 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)34 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)34 ApiOperation (io.swagger.annotations.ApiOperation)32 HttpSession (javax.servlet.http.HttpSession)31 Judge (top.hcode.hoj.pojo.entity.judge.Judge)30