Search in sources :

Example 96 with JobConfig4DB

use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.

the class JobServiceImpl method getJobConfig.

@Override
public JobConfig getJobConfig(String namespace, String jobName) throws SaturnJobConsoleException {
    JobConfig4DB jobConfig4DB = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (jobConfig4DB == null) {
        throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, String.format("该作业(%s)不存在", jobName));
    }
    JobConfig jobConfig = new JobConfig();
    SaturnBeanUtils.copyProperties(jobConfig4DB, jobConfig);
    return jobConfig;
}
Also used : SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)

Example 97 with JobConfig4DB

use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.

the class HistoryJobConfigServiceImpl method selectPage.

@Transactional
@Override
public List<JobConfig4DB> selectPage(JobConfig4DB historyjobconfig, Pageable pageable) throws SaturnJobConsoleException {
    List<JobConfig4DB> historyJobConfigs = historyJobConfigRepo.selectPage(historyjobconfig, pageable);
    if (historyJobConfigs != null) {
        int i = 1;
        for (JobConfig4DB historyJobConfig : historyJobConfigs) {
            historyJobConfig.setRownum(i++);
            historyJobConfig.setDefaultValues();
        }
    }
    return historyJobConfigs;
}
Also used : JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Transactional(org.springframework.transaction.annotation.Transactional)

Example 98 with JobConfig4DB

use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.

the class JobOverviewController method updateJobOverviewDetail.

private List<JobOverviewJobVo> updateJobOverviewDetail(String namespace, List<JobConfig4DB> unSystemJobs, JobStatus jobStatus) {
    List<JobOverviewJobVo> result = Lists.newArrayList();
    for (JobConfig4DB jobConfig : unSystemJobs) {
        try {
            jobConfig.setDefaultValues();
            JobOverviewJobVo jobOverviewJobVo = new JobOverviewJobVo();
            SaturnBeanUtils.copyProperties(jobConfig, jobOverviewJobVo);
            updateJobTypesInOverview(jobConfig, jobOverviewJobVo);
            if (jobStatus == null) {
                jobOverviewJobVo.setStatus(jobService.getJobStatus(namespace, jobConfig));
            } else {
                jobOverviewJobVo.setStatus(jobStatus);
            }
            result.add(jobOverviewJobVo);
        } catch (Exception e) {
            log.error("list job " + jobConfig.getJobName() + " error", e);
        }
    }
    return result;
}
Also used : JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 99 with JobConfig4DB

use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.

the class RestApiServiceImpl method runDownStream.

@Override
public List<BatchJobResult> runDownStream(final String namespace, final String jobName, final Map<String, Object> triggeredData) throws SaturnJobConsoleException {
    return ReuseUtils.reuse(namespace, jobName, registryCenterService, curatorRepository, new ReuseCallBack<List<BatchJobResult>>() {

        @Override
        public List<BatchJobResult> call(CuratorRepository.CuratorFrameworkOp curatorFrameworkOp) throws SaturnJobConsoleException {
            JobConfig4DB jobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
            if (jobConfig == null) {
                throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), "不能触发该作业(" + jobName + ")的下游,因为该作业不存在");
            }
            List<BatchJobResult> batchJobResultList = new ArrayList<>();
            String downStream = jobConfig.getDownStream();
            if (StringUtils.isBlank(downStream)) {
                return batchJobResultList;
            }
            // Maybe should validate downStream, but it seems unnecessary, because it's validated when add/copy/import/update job
            String[] split = downStream.split(",");
            for (String childName : split) {
                String childNameTrim = childName.trim();
                if (childNameTrim.isEmpty()) {
                    continue;
                }
                BatchJobResult batchJobResult = new BatchJobResult();
                batchJobResult.setJobName(childNameTrim);
                try {
                    runJobAtOnce(namespace, childNameTrim, triggeredData);
                    batchJobResult.setSuccess(true);
                } catch (SaturnJobConsoleException e) {
                    batchJobResult.setSuccess(false);
                    batchJobResult.setMessage(e.getMessage());
                } finally {
                    batchJobResultList.add(batchJobResult);
                }
            }
            return batchJobResultList;
        }
    });
}
Also used : CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 100 with JobConfig4DB

use of com.vip.saturn.job.console.mybatis.entity.JobConfig4DB in project Saturn by vipshop.

the class ZkDBDiffServiceImpl method diffByJob.

@Override
public JobDiffInfo diffByJob(String namespace, String jobName) throws SaturnJobConsoleException {
    CuratorRepository.CuratorFrameworkOp zkClient;
    try {
        zkClient = initCuratorClient(namespace);
        if (zkClient == null) {
            return null;
        }
        log.info("start to diff job:{}", jobName);
        JobConfig4DB dbJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
        JobConfig zkJobConfig = jobService.getJobConfigFromZK(namespace, jobName);
        if (dbJobConfig == null) {
            if (zkJobConfig != null) {
                return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.ZK_ONLY, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList());
            } else {
                return null;
            }
        }
        if (zkJobConfig == null) {
            return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.DB_ONLY, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList());
        }
        // diff only when dbJobConfig and zkJobConfig both not null
        return diff(namespace, dbJobConfig, zkJobConfig, true);
    } catch (Exception e) {
        log.error("exception throws during diff by namespace [{}] and job [{}]", namespace, jobName, e);
        throw new SaturnJobConsoleException(e);
    }
}
Also used : JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) JobConfig(com.vip.saturn.job.console.domain.JobConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Aggregations

JobConfig4DB (com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)103 Test (org.junit.Test)70 File (java.io.File)28 FileInputStream (java.io.FileInputStream)28 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)28 MultipartFile (org.springframework.web.multipart.MultipartFile)28 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)23 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)11 Transactional (org.springframework.transaction.annotation.Transactional)10 CuratorFrameworkOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)8 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)5 Stat (org.apache.zookeeper.data.Stat)4 JobConfig (com.vip.saturn.job.console.domain.JobConfig)2 JobDiffInfo (com.vip.saturn.job.console.domain.JobDiffInfo)2 ParseException (java.text.ParseException)2 Audit (com.vip.saturn.job.console.aop.annotation.Audit)1 GetJobConfigVo (com.vip.saturn.job.console.vo.GetJobConfigVo)1 JobConfigInfo (com.vip.saturn.job.integrate.entity.JobConfigInfo)1 UpdateJobConfigException (com.vip.saturn.job.integrate.exception.UpdateJobConfigException)1 Boolean (java.lang.Boolean)1