@Test public void diff() { List<JobDiffInfo.ConfigDiffInfo> diffInfoList = Lists.newArrayList(); zkDBDiffService.diff("ns", "", "", diffInfoList); assertEquals(0, diffInfoList.size()); diffInfoList.clear(); zkDBDiffService.diff("ns", "123", "", diffInfoList); assertEquals(1, diffInfoList.size()); diffInfoList.clear(); zkDBDiffService.diff("ns", "", "123", diffInfoList); assertEquals(1, diffInfoList.size()); diffInfoList.clear(); zkDBDiffService.diff("ns", "123", "123 ", diffInfoList); assertEquals(0, diffInfoList.size()); diffInfoList.clear(); zkDBDiffService.diff("ns", "123", "456", diffInfoList); assertEquals(1, diffInfoList.size()); diffInfoList.clear(); }
protected JobDiffInfo diff(String namespace, JobConfig dbJobConfig, JobConfig zkJobConfig, boolean needDetail) { String jobName = dbJobConfig.getJobName(); List<JobDiffInfo.ConfigDiffInfo> configDiffInfos = Lists.newArrayList(); String jobTypeInDB = dbJobConfig.getJobType(); diff("jobType", jobTypeInDB, zkJobConfig.getJobType(), configDiffInfos); diff("jobClass", dbJobConfig.getJobClass(), zkJobConfig.getJobClass(), configDiffInfos); diff("shardingTotalCount", dbJobConfig.getShardingTotalCount(), zkJobConfig.getShardingTotalCount(), configDiffInfos); diff("timeZone", dbJobConfig.getTimeZone(), zkJobConfig.getTimeZone(), configDiffInfos); diff("cron", dbJobConfig.getCron(), zkJobConfig.getCron(), configDiffInfos); diff("pausePeriodDate", dbJobConfig.getPausePeriodDate(), zkJobConfig.getPausePeriodDate(), configDiffInfos); diff("pausePeriodTime", dbJobConfig.getPausePeriodTime(), zkJobConfig.getPausePeriodTime(), configDiffInfos); diff("shardingItemParameters", dbJobConfig.getShardingItemParameters(), zkJobConfig.getShardingItemParameters(), configDiffInfos); diff("jobParameter", dbJobConfig.getJobParameter(), zkJobConfig.getJobParameter(), configDiffInfos); diff("processCountIntervalSeconds", dbJobConfig.getProcessCountIntervalSeconds(), zkJobConfig.getProcessCountIntervalSeconds(), configDiffInfos); diff("timeout4AlarmSeconds", dbJobConfig.getTimeout4AlarmSeconds(), zkJobConfig.getTimeout4AlarmSeconds(), configDiffInfos); diff("timeoutSeconds", dbJobConfig.getTimeoutSeconds(), zkJobConfig.getTimeoutSeconds(), configDiffInfos); diff("loadLevel", dbJobConfig.getLoadLevel(), zkJobConfig.getLoadLevel(), configDiffInfos); diff("jobDegree", dbJobConfig.getJobDegree(), zkJobConfig.getJobDegree(), configDiffInfos); diff("enabled", dbJobConfig.getEnabled(), zkJobConfig.getEnabled(), configDiffInfos); diff("preferList", dbJobConfig.getPreferList(), zkJobConfig.getPreferList(), configDiffInfos); diff("useDispreferList", dbJobConfig.getUseDispreferList(), zkJobConfig.getUseDispreferList(), configDiffInfos); diff("useSerial", dbJobConfig.getUseSerial(), zkJobConfig.getUseSerial(), configDiffInfos); diff("queueName", dbJobConfig.getQueueName(), zkJobConfig.getQueueName(), configDiffInfos); diff("localMode", dbJobConfig.getLocalMode(), zkJobConfig.getLocalMode(), configDiffInfos); diff("dependencies", dbJobConfig.getDependencies(), zkJobConfig.getDependencies(), configDiffInfos); diff("groups", dbJobConfig.getGroups(), zkJobConfig.getGroups(), configDiffInfos); diff("description", dbJobConfig.getDescription(), zkJobConfig.getDescription(), configDiffInfos); diff("jobMode", dbJobConfig.getJobMode(), zkJobConfig.getJobMode(), configDiffInfos); diff("channelName", dbJobConfig.getChannelName(), zkJobConfig.getChannelName(), configDiffInfos); diff("showNormalLog", dbJobConfig.getShowNormalLog(), zkJobConfig.getShowNormalLog(), configDiffInfos); diff("enabledReport", dbJobConfig.getEnabledReport(), zkJobConfig.getEnabledReport(), configDiffInfos); diff("showNormalLog", dbJobConfig.getShowNormalLog(), zkJobConfig.getShowNormalLog(), configDiffInfos); if (!configDiffInfos.isEmpty()) { if (needDetail) { return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.HAS_DIFFERENCE, configDiffInfos); } return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.HAS_DIFFERENCE, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList()); } return null; }
ZkDBDiffServiceImpl implements ZkDBDiffService { protected JobDiffInfo diff(String namespace, JobConfig dbJobConfig, JobConfig zkJobConfig, boolean needDetail) { String jobName = dbJobConfig.getJobName(); List<JobDiffInfo.ConfigDiffInfo> configDiffInfos = Lists.newArrayList(); String jobTypeInDB = dbJobConfig.getJobType(); diff("jobType", jobTypeInDB, zkJobConfig.getJobType(), configDiffInfos); diff("jobClass", dbJobConfig.getJobClass(), zkJobConfig.getJobClass(), configDiffInfos); diff("shardingTotalCount", dbJobConfig.getShardingTotalCount(), zkJobConfig.getShardingTotalCount(), configDiffInfos); diff("timeZone", dbJobConfig.getTimeZone(), zkJobConfig.getTimeZone(), configDiffInfos); diff("cron", dbJobConfig.getCron(), zkJobConfig.getCron(), configDiffInfos); diff("pausePeriodDate", dbJobConfig.getPausePeriodDate(), zkJobConfig.getPausePeriodDate(), configDiffInfos); diff("pausePeriodTime", dbJobConfig.getPausePeriodTime(), zkJobConfig.getPausePeriodTime(), configDiffInfos); diff("shardingItemParameters", dbJobConfig.getShardingItemParameters(), zkJobConfig.getShardingItemParameters(), configDiffInfos); diff("jobParameter", dbJobConfig.getJobParameter(), zkJobConfig.getJobParameter(), configDiffInfos); diff("processCountIntervalSeconds", dbJobConfig.getProcessCountIntervalSeconds(), zkJobConfig.getProcessCountIntervalSeconds(), configDiffInfos); diff("timeout4AlarmSeconds", dbJobConfig.getTimeout4AlarmSeconds(), zkJobConfig.getTimeout4AlarmSeconds(), configDiffInfos); diff("timeoutSeconds", dbJobConfig.getTimeoutSeconds(), zkJobConfig.getTimeoutSeconds(), configDiffInfos); diff("loadLevel", dbJobConfig.getLoadLevel(), zkJobConfig.getLoadLevel(), configDiffInfos); diff("jobDegree", dbJobConfig.getJobDegree(), zkJobConfig.getJobDegree(), configDiffInfos); diff("enabled", dbJobConfig.getEnabled(), zkJobConfig.getEnabled(), configDiffInfos); diff("preferList", dbJobConfig.getPreferList(), zkJobConfig.getPreferList(), configDiffInfos); diff("useDispreferList", dbJobConfig.getUseDispreferList(), zkJobConfig.getUseDispreferList(), configDiffInfos); diff("useSerial", dbJobConfig.getUseSerial(), zkJobConfig.getUseSerial(), configDiffInfos); diff("queueName", dbJobConfig.getQueueName(), zkJobConfig.getQueueName(), configDiffInfos); diff("localMode", dbJobConfig.getLocalMode(), zkJobConfig.getLocalMode(), configDiffInfos); diff("dependencies", dbJobConfig.getDependencies(), zkJobConfig.getDependencies(), configDiffInfos); diff("groups", dbJobConfig.getGroups(), zkJobConfig.getGroups(), configDiffInfos); diff("description", dbJobConfig.getDescription(), zkJobConfig.getDescription(), configDiffInfos); diff("jobMode", dbJobConfig.getJobMode(), zkJobConfig.getJobMode(), configDiffInfos); diff("channelName", dbJobConfig.getChannelName(), zkJobConfig.getChannelName(), configDiffInfos); diff("showNormalLog", dbJobConfig.getShowNormalLog(), zkJobConfig.getShowNormalLog(), configDiffInfos); diff("enabledReport", dbJobConfig.getEnabledReport(), zkJobConfig.getEnabledReport(), configDiffInfos); diff("showNormalLog", dbJobConfig.getShowNormalLog(), zkJobConfig.getShowNormalLog(), configDiffInfos); if (!configDiffInfos.isEmpty()) { if (needDetail) { return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.HAS_DIFFERENCE, configDiffInfos); } return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.HAS_DIFFERENCE, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList()); } return null; } }
ZkDBDiffServiceImpl implements ZkDBDiffService { protected JobDiffInfo diff(String namespace, JobConfig dbJobConfig, JobConfig zkJobConfig, boolean needDetail) { String jobName = dbJobConfig.getJobName(); List<JobDiffInfo.ConfigDiffInfo> configDiffInfos = Lists.newArrayList(); String jobTypeInDB = dbJobConfig.getJobType(); diff("jobType", jobTypeInDB, zkJobConfig.getJobType(), configDiffInfos); diff("jobClass", dbJobConfig.getJobClass(), zkJobConfig.getJobClass(), configDiffInfos); diff("shardingTotalCount", dbJobConfig.getShardingTotalCount(), zkJobConfig.getShardingTotalCount(), configDiffInfos); diff("timeZone", dbJobConfig.getTimeZone(), zkJobConfig.getTimeZone(), configDiffInfos); diff("cron", dbJobConfig.getCron(), zkJobConfig.getCron(), configDiffInfos); diff("pausePeriodDate", dbJobConfig.getPausePeriodDate(), zkJobConfig.getPausePeriodDate(), configDiffInfos); diff("pausePeriodTime", dbJobConfig.getPausePeriodTime(), zkJobConfig.getPausePeriodTime(), configDiffInfos); diff("shardingItemParameters", dbJobConfig.getShardingItemParameters(), zkJobConfig.getShardingItemParameters(), configDiffInfos); diff("jobParameter", dbJobConfig.getJobParameter(), zkJobConfig.getJobParameter(), configDiffInfos); diff("processCountIntervalSeconds", dbJobConfig.getProcessCountIntervalSeconds(), zkJobConfig.getProcessCountIntervalSeconds(), configDiffInfos); diff("timeout4AlarmSeconds", dbJobConfig.getTimeout4AlarmSeconds(), zkJobConfig.getTimeout4AlarmSeconds(), configDiffInfos); diff("timeoutSeconds", dbJobConfig.getTimeoutSeconds(), zkJobConfig.getTimeoutSeconds(), configDiffInfos); diff("loadLevel", dbJobConfig.getLoadLevel(), zkJobConfig.getLoadLevel(), configDiffInfos); diff("jobDegree", dbJobConfig.getJobDegree(), zkJobConfig.getJobDegree(), configDiffInfos); diff("enabled", dbJobConfig.getEnabled(), zkJobConfig.getEnabled(), configDiffInfos); diff("preferList", dbJobConfig.getPreferList(), zkJobConfig.getPreferList(), configDiffInfos); diff("useDispreferList", dbJobConfig.getUseDispreferList(), zkJobConfig.getUseDispreferList(), configDiffInfos); diff("useSerial", dbJobConfig.getUseSerial(), zkJobConfig.getUseSerial(), configDiffInfos); diff("queueName", dbJobConfig.getQueueName(), zkJobConfig.getQueueName(), configDiffInfos); diff("localMode", dbJobConfig.getLocalMode(), zkJobConfig.getLocalMode(), configDiffInfos); diff("dependencies", dbJobConfig.getDependencies(), zkJobConfig.getDependencies(), configDiffInfos); diff("groups", dbJobConfig.getGroups(), zkJobConfig.getGroups(), configDiffInfos); diff("description", dbJobConfig.getDescription(), zkJobConfig.getDescription(), configDiffInfos); diff("jobMode", dbJobConfig.getJobMode(), zkJobConfig.getJobMode(), configDiffInfos); diff("channelName", dbJobConfig.getChannelName(), zkJobConfig.getChannelName(), configDiffInfos); diff("showNormalLog", dbJobConfig.getShowNormalLog(), zkJobConfig.getShowNormalLog(), configDiffInfos); diff("enabledReport", dbJobConfig.getEnabledReport(), zkJobConfig.getEnabledReport(), configDiffInfos); diff("showNormalLog", dbJobConfig.getShowNormalLog(), zkJobConfig.getShowNormalLog(), configDiffInfos); if (!configDiffInfos.isEmpty()) { if (needDetail) { return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.HAS_DIFFERENCE, configDiffInfos); } return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.HAS_DIFFERENCE, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList()); } return null; }  }
ZkDBDiffServiceImpl implements ZkDBDiffService { protected JobDiffInfo diff(String namespace, JobConfig dbJobConfig, JobConfig zkJobConfig, boolean needDetail) { String jobName = dbJobConfig.getJobName(); List<JobDiffInfo.ConfigDiffInfo> configDiffInfos = Lists.newArrayList(); String jobTypeInDB = dbJobConfig.getJobType(); diff("jobType", jobTypeInDB, zkJobConfig.getJobType(), configDiffInfos); diff("jobClass", dbJobConfig.getJobClass(), zkJobConfig.getJobClass(), configDiffInfos); diff("shardingTotalCount", dbJobConfig.getShardingTotalCount(), zkJobConfig.getShardingTotalCount(), configDiffInfos); diff("timeZone", dbJobConfig.getTimeZone(), zkJobConfig.getTimeZone(), configDiffInfos); diff("cron", dbJobConfig.getCron(), zkJobConfig.getCron(), configDiffInfos); diff("pausePeriodDate", dbJobConfig.getPausePeriodDate(), zkJobConfig.getPausePeriodDate(), configDiffInfos); diff("pausePeriodTime", dbJobConfig.getPausePeriodTime(), zkJobConfig.getPausePeriodTime(), configDiffInfos); diff("shardingItemParameters", dbJobConfig.getShardingItemParameters(), zkJobConfig.getShardingItemParameters(), configDiffInfos); diff("jobParameter", dbJobConfig.getJobParameter(), zkJobConfig.getJobParameter(), configDiffInfos); diff("processCountIntervalSeconds", dbJobConfig.getProcessCountIntervalSeconds(), zkJobConfig.getProcessCountIntervalSeconds(), configDiffInfos); diff("timeout4AlarmSeconds", dbJobConfig.getTimeout4AlarmSeconds(), zkJobConfig.getTimeout4AlarmSeconds(), configDiffInfos); diff("timeoutSeconds", dbJobConfig.getTimeoutSeconds(), zkJobConfig.getTimeoutSeconds(), configDiffInfos); diff("loadLevel", dbJobConfig.getLoadLevel(), zkJobConfig.getLoadLevel(), configDiffInfos); diff("jobDegree", dbJobConfig.getJobDegree(), zkJobConfig.getJobDegree(), configDiffInfos); diff("enabled", dbJobConfig.getEnabled(), zkJobConfig.getEnabled(), configDiffInfos); diff("preferList", dbJobConfig.getPreferList(), zkJobConfig.getPreferList(), configDiffInfos); diff("useDispreferList", dbJobConfig.getUseDispreferList(), zkJobConfig.getUseDispreferList(), configDiffInfos); diff("useSerial", dbJobConfig.getUseSerial(), zkJobConfig.getUseSerial(), configDiffInfos); diff("queueName", dbJobConfig.getQueueName(), zkJobConfig.getQueueName(), configDiffInfos); diff("localMode", dbJobConfig.getLocalMode(), zkJobConfig.getLocalMode(), configDiffInfos); diff("dependencies", dbJobConfig.getDependencies(), zkJobConfig.getDependencies(), configDiffInfos); diff("groups", dbJobConfig.getGroups(), zkJobConfig.getGroups(), configDiffInfos); diff("description", dbJobConfig.getDescription(), zkJobConfig.getDescription(), configDiffInfos); diff("jobMode", dbJobConfig.getJobMode(), zkJobConfig.getJobMode(), configDiffInfos); diff("channelName", dbJobConfig.getChannelName(), zkJobConfig.getChannelName(), configDiffInfos); diff("showNormalLog", dbJobConfig.getShowNormalLog(), zkJobConfig.getShowNormalLog(), configDiffInfos); diff("enabledReport", dbJobConfig.getEnabledReport(), zkJobConfig.getEnabledReport(), configDiffInfos); diff("showNormalLog", dbJobConfig.getShowNormalLog(), zkJobConfig.getShowNormalLog(), configDiffInfos); if (!configDiffInfos.isEmpty()) { if (needDetail) { return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.HAS_DIFFERENCE, configDiffInfos); } return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.HAS_DIFFERENCE, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList()); } return null; }  @PostConstruct void init(); @PreDestroy void destroy(); @Override List<JobDiffInfo> diffByCluster(String clusterKey); @Override List<JobDiffInfo> diffByNamespace(String namespace); @Override JobDiffInfo diffByJob(String namespace, String jobName); void diff(String key, Object valueInDb, Object valueInZk, List<JobDiffInfo.ConfigDiffInfo> configDiffInfos); }
ZkDBDiffServiceImpl implements ZkDBDiffService { protected JobDiffInfo diff(String namespace, JobConfig dbJobConfig, JobConfig zkJobConfig, boolean needDetail) { String jobName = dbJobConfig.getJobName(); List<JobDiffInfo.ConfigDiffInfo> configDiffInfos = Lists.newArrayList(); String jobTypeInDB = dbJobConfig.getJobType(); diff("jobType", jobTypeInDB, zkJobConfig.getJobType(), configDiffInfos); diff("jobClass", dbJobConfig.getJobClass(), zkJobConfig.getJobClass(), configDiffInfos); diff("shardingTotalCount", dbJobConfig.getShardingTotalCount(), zkJobConfig.getShardingTotalCount(), configDiffInfos); diff("timeZone", dbJobConfig.getTimeZone(), zkJobConfig.getTimeZone(), configDiffInfos); diff("cron", dbJobConfig.getCron(), zkJobConfig.getCron(), configDiffInfos); diff("pausePeriodDate", dbJobConfig.getPausePeriodDate(), zkJobConfig.getPausePeriodDate(), configDiffInfos); diff("pausePeriodTime", dbJobConfig.getPausePeriodTime(), zkJobConfig.getPausePeriodTime(), configDiffInfos); diff("shardingItemParameters", dbJobConfig.getShardingItemParameters(), zkJobConfig.getShardingItemParameters(), configDiffInfos); diff("jobParameter", dbJobConfig.getJobParameter(), zkJobConfig.getJobParameter(), configDiffInfos); diff("processCountIntervalSeconds", dbJobConfig.getProcessCountIntervalSeconds(), zkJobConfig.getProcessCountIntervalSeconds(), configDiffInfos); diff("timeout4AlarmSeconds", dbJobConfig.getTimeout4AlarmSeconds(), zkJobConfig.getTimeout4AlarmSeconds(), configDiffInfos); diff("timeoutSeconds", dbJobConfig.getTimeoutSeconds(), zkJobConfig.getTimeoutSeconds(), configDiffInfos); diff("loadLevel", dbJobConfig.getLoadLevel(), zkJobConfig.getLoadLevel(), configDiffInfos); diff("jobDegree", dbJobConfig.getJobDegree(), zkJobConfig.getJobDegree(), configDiffInfos); diff("enabled", dbJobConfig.getEnabled(), zkJobConfig.getEnabled(), configDiffInfos); diff("preferList", dbJobConfig.getPreferList(), zkJobConfig.getPreferList(), configDiffInfos); diff("useDispreferList", dbJobConfig.getUseDispreferList(), zkJobConfig.getUseDispreferList(), configDiffInfos); diff("useSerial", dbJobConfig.getUseSerial(), zkJobConfig.getUseSerial(), configDiffInfos); diff("queueName", dbJobConfig.getQueueName(), zkJobConfig.getQueueName(), configDiffInfos); diff("localMode", dbJobConfig.getLocalMode(), zkJobConfig.getLocalMode(), configDiffInfos); diff("dependencies", dbJobConfig.getDependencies(), zkJobConfig.getDependencies(), configDiffInfos); diff("groups", dbJobConfig.getGroups(), zkJobConfig.getGroups(), configDiffInfos); diff("description", dbJobConfig.getDescription(), zkJobConfig.getDescription(), configDiffInfos); diff("jobMode", dbJobConfig.getJobMode(), zkJobConfig.getJobMode(), configDiffInfos); diff("channelName", dbJobConfig.getChannelName(), zkJobConfig.getChannelName(), configDiffInfos); diff("showNormalLog", dbJobConfig.getShowNormalLog(), zkJobConfig.getShowNormalLog(), configDiffInfos); diff("enabledReport", dbJobConfig.getEnabledReport(), zkJobConfig.getEnabledReport(), configDiffInfos); diff("showNormalLog", dbJobConfig.getShowNormalLog(), zkJobConfig.getShowNormalLog(), configDiffInfos); if (!configDiffInfos.isEmpty()) { if (needDetail) { return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.HAS_DIFFERENCE, configDiffInfos); } return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.HAS_DIFFERENCE, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList()); } return null; }  @PostConstruct void init(); @PreDestroy void destroy(); @Override List<JobDiffInfo> diffByCluster(String clusterKey); @Override List<JobDiffInfo> diffByNamespace(String namespace); @Override JobDiffInfo diffByJob(String namespace, String jobName); void diff(String key, Object valueInDb, Object valueInZk, List<JobDiffInfo.ConfigDiffInfo> configDiffInfos);  }