Search in sources :

Example 1 with BooleanWrapper

use of com.vip.saturn.job.console.utils.BooleanWrapper in project Saturn by vipshop.

the class JobDimensionServiceImpl method updateJobSettings.

@Transactional
@Override
public String updateJobSettings(final JobSettings jobSettings, RegistryCenterConfiguration configInSession) {
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
    // Modify JobSettings.updateFields() sync, if the update fields changed.
    jobSettings.setDefaultValues();
    BooleanWrapper bw = new BooleanWrapper(false);
    CuratorTransactionOp curatorTransactionOp = null;
    try {
        curatorTransactionOp = curatorFrameworkOp.inTransaction().replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "jobMode"), jobSettings.getJobMode(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "shardingTotalCount"), jobSettings.getShardingTotalCount(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "loadLevel"), jobSettings.getLoadLevel(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "jobDegree"), jobSettings.getJobDegree(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "enabledReport"), jobSettings.getEnabledReport(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "timeZone"), StringUtils.trim(jobSettings.getTimeZone()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "cron"), StringUtils.trim(jobSettings.getCron()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "pausePeriodDate"), jobSettings.getPausePeriodDate(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "pausePeriodTime"), jobSettings.getPausePeriodTime(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "shardingItemParameters"), jobSettings.getShardingItemParameters(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "jobParameter"), jobSettings.getJobParameter(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "processCountIntervalSeconds"), jobSettings.getProcessCountIntervalSeconds(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "timeout4AlarmSeconds"), jobSettings.getTimeout4AlarmSeconds(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "timeoutSeconds"), jobSettings.getTimeoutSeconds(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "dependencies"), jobSettings.getDependencies(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "groups"), jobSettings.getGroups(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "description"), jobSettings.getDescription(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "channelName"), StringUtils.trim(jobSettings.getChannelName()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "queueName"), StringUtils.trim(jobSettings.getQueueName()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "showNormalLog"), jobSettings.getShowNormalLog(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "preferList"), jobSettings.getPreferList(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "useDispreferList"), jobSettings.getUseDispreferList(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "failover"), jobSettings.getFailover(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "localMode"), jobSettings.getLocalMode(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "useSerial"), jobSettings.getUseSerial(), bw);
        if (jobSettings.getEnabledReport() != null && !jobSettings.getEnabledReport()) {
            // 当enabledReport关闭上报时,要清理execution节点
            log.info("the switch of enabledReport set to false, now deleteJob the execution zk node");
            String executionNodePath = JobNodePath.getExecutionNodePath(jobSettings.getJobName());
            if (curatorFrameworkOp.checkExists(executionNodePath)) {
                curatorFrameworkOp.deleteRecursive(executionNodePath);
            }
        }
    } catch (Exception e) {
        log.error("update settings to zk failed: {}", e.getMessage());
        log.error(e.getMessage(), e);
        return e.getMessage();
    }
    try {
        CurrentJobConfig jobconfig = currentJobConfigService.findConfigByNamespaceAndJobName(configInSession.getNamespace(), jobSettings.getJobName());
        // config not exists, save it to current config.
        if (jobconfig == null) {
            CurrentJobConfig current = mapper.map(jobSettings, CurrentJobConfig.class);
            current.setNamespace(configInSession.getNamespace());
            current.setCreateTime(new Date());
            current.setLastUpdateTime(new Date());
            currentJobConfigService.create(current);
        } else if (bw.isValue()) {
            // config changed, update current config and save a copy to history config.
            currentJobConfigService.updateConfigAndSave2History(jobconfig, jobSettings, null);
        }
        if (curatorTransactionOp != null) {
            curatorTransactionOp.commit();
        }
    } catch (Exception e) {
        log.error("update settings to db failed: {}", e.getMessage());
        log.error(e.getMessage(), e);
        return e.getMessage();
    }
    return null;
}
Also used : BooleanWrapper(com.vip.saturn.job.console.utils.BooleanWrapper) CurrentJobConfig(com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) CuratorTransactionOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp.CuratorTransactionOp) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) ParseException(java.text.ParseException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)1 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)1 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)1 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)1 CuratorTransactionOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp.CuratorTransactionOp)1 BooleanWrapper (com.vip.saturn.job.console.utils.BooleanWrapper)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 Transactional (org.springframework.transaction.annotation.Transactional)1