Search in sources :

Example 1 with JobSettings

use of com.vip.saturn.job.console.domain.JobSettings in project Saturn by vipshop.

the class JobConfigInitializationServiceImpl method exportToDbByZkCluster.

private void exportToDbByZkCluster(String userName, ZkCluster tmp, ExportJobConfigPageStatus exportJobConfigPageStatus) throws SaturnJobConsoleException {
    log.info(" start to export db by single zkCluster, zkCluster Addr is :{}", tmp.getZkAddr());
    ZkCluster zkCluster = tmp;
    ArrayList<RegistryCenterConfiguration> oldRccs = zkCluster.getRegCenterConfList();
    ArrayList<RegistryCenterConfiguration> rccs = new ArrayList<RegistryCenterConfiguration>(oldRccs);
    for (RegistryCenterConfiguration rcc : rccs) {
        List<String> jobNames = getAllUnSystemJobs(rcc.getNamespace(), zkCluster.getCuratorFramework());
        for (String jobName : jobNames) {
            try {
                JobSettings jobSettings = getJobSettings(jobName, rcc, zkCluster.getCuratorFramework());
                CurrentJobConfig current = mapper.map(jobSettings, CurrentJobConfig.class);
                current.setCreateBy(userName);
                current.setCreateTime(new Date());
                current.setLastUpdateBy(userName);
                current.setLastUpdateTime(new Date());
                current.setNamespace(rcc.getNamespace());
                currentJobConfigService.create(current);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                throw new SaturnJobConsoleException(e.getMessage());
            }
        }
        exportJobConfigPageStatus.setSuccessJobNum(exportJobConfigPageStatus.getSuccessJobNum() + jobNames.size());
        exportJobConfigPageStatus.setSuccessNamespaceNum(exportJobConfigPageStatus.getSuccessNamespaceNum() + 1);
        temporarySharedStatusService.update(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS, gson.toJson(exportJobConfigPageStatus));
    }
    log.info("export db by single zkCluster successfully, zkCluster Addr is :{}", tmp.getZkAddr());
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) JobSettings(com.vip.saturn.job.console.domain.JobSettings) CurrentJobConfig(com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ArrayList(java.util.ArrayList) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) Date(java.util.Date) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 2 with JobSettings

use of com.vip.saturn.job.console.domain.JobSettings in project Saturn by vipshop.

the class JobConfigInitializationServiceImpl method getJobSettings.

private JobSettings getJobSettings(final String jobName, RegistryCenterConfiguration rcc, CuratorFramework curatorFramework) {
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.newCuratorFrameworkOp(curatorFramework);
    JobSettings result = new JobSettings();
    result.setJobName(jobName);
    result.setJobClass(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "jobClass"))));
    result.setShardingTotalCount(parseInt(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "shardingTotalCount")))));
    String timeZone = curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "timeZone")));
    if (Strings.isNullOrEmpty(timeZone)) {
        result.setTimeZone(SaturnConstants.TIME_ZONE_ID_DEFAULT);
    } else {
        result.setTimeZone(timeZone);
    }
    result.setTimeZonesProvided(Arrays.asList(TimeZone.getAvailableIDs()));
    result.setCron(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "cron"))));
    result.setCustomContext(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "customContext"))));
    result.setPausePeriodDate(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "pausePeriodDate"))));
    result.setPausePeriodTime(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "pausePeriodTime"))));
    result.setShardingItemParameters(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "shardingItemParameters"))));
    result.setJobParameter(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "jobParameter"))));
    result.setProcessCountIntervalSeconds(parseInt(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "processCountIntervalSeconds")))));
    String timeout4AlarmSecondsStr = curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "timeout4AlarmSeconds")));
    if (Strings.isNullOrEmpty(timeout4AlarmSecondsStr)) {
        result.setTimeout4AlarmSeconds(0);
    } else {
        result.setTimeout4AlarmSeconds(parseInt(timeout4AlarmSecondsStr));
    }
    result.setTimeoutSeconds(parseInt(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "timeoutSeconds")))));
    String lv = curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "loadLevel")));
    if (Strings.isNullOrEmpty(lv)) {
        result.setLoadLevel(1);
    } else {
        result.setLoadLevel(parseInt(lv));
    }
    String jobDegree = curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "jobDegree")));
    if (Strings.isNullOrEmpty(jobDegree)) {
        result.setJobDegree(0);
    } else {
        result.setJobDegree(parseInt(jobDegree));
    }
    result.setEnabled(Boolean.valueOf(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), // 默认是禁用的
    JobNodePath.getConfigNodePath(jobName, "enabled")))));
    result.setPreferList(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "preferList"))));
    String useDispreferList = curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "useDispreferList")));
    if (Strings.isNullOrEmpty(useDispreferList)) {
        result.setUseDispreferList(null);
    } else {
        result.setUseDispreferList(Boolean.valueOf(useDispreferList));
    }
    result.setUseSerial(Boolean.valueOf(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "useSerial")))));
    result.setLocalMode(Boolean.valueOf(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "localMode")))));
    result.setFailover(Boolean.valueOf(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "failover")))));
    result.setDependencies(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "dependencies"))));
    result.setGroups(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "groups"))));
    result.setDescription(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "description"))));
    result.setJobMode(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "jobMode"))));
    result.setQueueName(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "queueName"))));
    result.setChannelName(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "channelName"))));
    String jobType = curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "jobType")));
    result.setJobType(jobType);
    String enabledReport = curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "enabledReport")));
    Boolean enabledReportValue = Boolean.valueOf(enabledReport);
    if (Strings.isNullOrEmpty(enabledReport)) {
        if (JobType.JAVA_JOB.name().equals(jobType) || JobType.SHELL_JOB.name().equals(jobType)) {
            enabledReportValue = true;
        } else {
            enabledReportValue = false;
        }
    }
    result.setEnabledReport(enabledReportValue);
    // 兼容旧版没有msg_job。
    if (StringUtils.isBlank(result.getJobType())) {
        if (result.getJobClass() != null) {
            if (result.getJobClass().indexOf("script") > 0) {
                result.setJobType(JobType.SHELL_JOB.name());
            } else {
                result.setJobType(JobType.JAVA_JOB.name());
            }
        } else {
            result.setJobType(JobType.JAVA_JOB.name());
        }
    }
    result.setShowNormalLog(Boolean.valueOf(curatorFrameworkOp.getData(getConfigNodePathWithNamespace(rcc.getNamespace(), JobNodePath.getConfigNodePath(jobName, "showNormalLog")))));
    return result;
}
Also used : JobSettings(com.vip.saturn.job.console.domain.JobSettings) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)

Aggregations

JobSettings (com.vip.saturn.job.console.domain.JobSettings)2 RegistryCenterConfiguration (com.vip.saturn.job.console.domain.RegistryCenterConfiguration)1 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)1 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)1 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)1 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1