Search in sources :

Example 41 with JobConfig4DB

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

the class JobServiceImpl method getUnSystemJobNames.

@Override
public List<String> getUnSystemJobNames(String namespace) throws SaturnJobConsoleException {
    List<String> unSystemJobs = new ArrayList<>();
    List<JobConfig4DB> jobConfig4DBList = currentJobConfigService.findConfigsByNamespace(namespace);
    if (jobConfig4DBList != null) {
        for (JobConfig4DB jobConfig4DB : jobConfig4DBList) {
            if (!(StringUtils.isNotBlank(jobConfig4DB.getJobMode()) && jobConfig4DB.getJobMode().startsWith(JobMode.SYSTEM_PREFIX))) {
                unSystemJobs.add(jobConfig4DB.getJobName());
            }
        }
    }
    return unSystemJobs;
}
Also used : JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)

Example 42 with JobConfig4DB

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

the class JobServiceImpl method updateJobConfig.

@Transactional(rollbackFor = Exception.class)
@Override
public void updateJobConfig(String namespace, JobConfig jobConfig, String updatedBy) throws SaturnJobConsoleException {
    JobConfig4DB oldJobConfig4DB = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobConfig.getJobName());
    if (oldJobConfig4DB == null) {
        throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, String.format("该作业(%s)不存在", jobConfig.getJobName()));
    }
    // 从数据库拿出老的数据,将需要更新的数据赋值(为空的字段视为不需要更新)
    JobConfig4DB newJobConfig4DB = new JobConfig4DB();
    SaturnBeanUtils.copyProperties(oldJobConfig4DB, newJobConfig4DB);
    SaturnBeanUtils.copyPropertiesIgnoreNull(jobConfig, newJobConfig4DB);
    // 与老的数据库中的该作业的配置对比,如果没有改变,则直接返回
    if (oldJobConfig4DB.equals(newJobConfig4DB)) {
        return;
    }
    // 设置作业配置字段默认值,并且强制纠正某些字段
    correctConfigValueWhenUpdateJob(newJobConfig4DB);
    // 校验作业配置
    List<JobConfig> unSystemJobs = getUnSystemJobs(namespace);
    Set<JobConfig> streamChangedJobs = new HashSet<>();
    validateJobConfig(namespace, newJobConfig4DB, unSystemJobs, streamChangedJobs);
    // 更新该作业到数据库
    currentJobConfigService.updateNewAndSaveOld2History(newJobConfig4DB, oldJobConfig4DB, updatedBy);
    // 更新关联作业的上下游
    for (JobConfig streamChangedJob : streamChangedJobs) {
        currentJobConfigService.updateStream(constructJobConfig4DB(namespace, streamChangedJob, null, updatedBy));
    }
    // 更新作业配置到zk,并联动更新关联作业的上下游
    updateJobConfigToZk(newJobConfig4DB, streamChangedJobs, registryCenterService.getCuratorFrameworkOp(namespace));
}
Also used : SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with JobConfig4DB

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

the class UpdateJobConfigServiceImpl method batchUpdatePreferList.

@Override
public void batchUpdatePreferList(List<JobConfigInfo> jobConfigInfos) throws UpdateJobConfigException {
    if (CollectionUtils.isEmpty(jobConfigInfos)) {
        return;
    }
    List<JobConfig4DB> currentJobConfigs = new ArrayList<JobConfig4DB>();
    JobConfig4DB currentJobConfig = null;
    for (JobConfigInfo jobConfigInfo : jobConfigInfos) {
        currentJobConfig = new JobConfig4DB();
        currentJobConfig.setNamespace(jobConfigInfo.getNamespace());
        currentJobConfig.setJobName(jobConfigInfo.getJobName());
        currentJobConfig.setPreferList(jobConfigInfo.getPerferList());
        currentJobConfigs.add(currentJobConfig);
    }
    try {
        currentJobConfigService.batchUpdatePreferList(currentJobConfigs);
    } catch (SaturnJobConsoleException e) {
        throw new UpdateJobConfigException(e);
    }
}
Also used : UpdateJobConfigException(com.vip.saturn.job.integrate.exception.UpdateJobConfigException) JobConfigInfo(com.vip.saturn.job.integrate.entity.JobConfigInfo) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ArrayList(java.util.ArrayList) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)

Example 44 with JobConfig4DB

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

the class ZkDBDiffServiceImpl method diffByNamespace.

@Override
public List<JobDiffInfo> diffByNamespace(String namespace) throws SaturnJobConsoleException {
    long startTime = System.currentTimeMillis();
    List<JobDiffInfo> jobDiffInfos = Lists.newArrayList();
    CuratorRepository.CuratorFrameworkOp zkClient;
    try {
        List<JobConfig4DB> dbJobConfigList = currentJobConfigService.findConfigsByNamespace(namespace);
        if (dbJobConfigList == null || dbJobConfigList.isEmpty()) {
            return jobDiffInfos;
        }
        zkClient = initCuratorClient(namespace);
        if (zkClient == null) {
            return jobDiffInfos;
        }
        Set<String> jobNamesInDb = getAllJobNames(dbJobConfigList);
        for (JobConfig4DB dbJobConfig : dbJobConfigList) {
            String jobName = dbJobConfig.getJobName();
            log.info("start to diff job:{}@{}", jobName, namespace);
            if (!checkJobIsExsitInZk(jobName, zkClient)) {
                jobDiffInfos.add(new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.DB_ONLY, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList()));
                continue;
            }
            JobConfig jobConfigFromZK = jobService.getJobConfigFromZK(namespace, jobName);
            JobDiffInfo jobDiffInfo = diff(namespace, dbJobConfig, jobConfigFromZK, false);
            if (jobDiffInfo != null) {
                jobDiffInfos.add(jobDiffInfo);
            }
        }
        List<JobDiffInfo> jobsInZkOnly = getJobNamesWhichInZKOnly(namespace, jobNamesInDb);
        if (jobsInZkOnly != null && !jobsInZkOnly.isEmpty()) {
            jobDiffInfos.addAll(jobsInZkOnly);
        }
    } catch (SaturnJobConsoleException e) {
        log.error(e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        log.error("exception throws during diff by namespace [{}]", namespace, e);
        throw new SaturnJobConsoleException(e);
    } finally {
        log.info("Finish diff namespace:{} which cost {}ms", namespace, System.currentTimeMillis() - startTime);
    }
    return jobDiffInfos;
}
Also used : JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo) 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) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 45 with JobConfig4DB

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

the class JobServiceImpl method disableJob.

@Transactional(rollbackFor = Exception.class)
@Override
public void disableJob(String namespace, String jobName, String updatedBy) throws SaturnJobConsoleException {
    JobConfig4DB jobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (jobConfig == null) {
        throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能禁用该作业(" + jobName + "),因为该作业不存在");
    }
    if (!jobConfig.getEnabled()) {
        throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, "该作业(" + jobName + ")已经处于禁用状态");
    }
    jobConfig.setEnabled(Boolean.FALSE);
    jobConfig.setLastUpdateTime(new Date());
    jobConfig.setLastUpdateBy(updatedBy);
    currentJobConfigService.updateByPrimaryKey(jobConfig);
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
    curatorFrameworkOp.update(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_ENABLED), false);
}
Also used : CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Transactional(org.springframework.transaction.annotation.Transactional)

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