use of com.vip.saturn.job.console.domain.JobConfig 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);
}
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class NamespaceServiceImplTest method testImportJobs.
@Test
public void testImportJobs() throws Exception {
List<JobConfig> jobConfigs = new ArrayList<>();
jobConfigs.add(new JobConfig());
jobConfigs.add(new JobConfig());
jobConfigs.add(new JobConfig());
when(jobService.getUnSystemJobs("saturn.vip.vip.com")).thenReturn(jobConfigs);
Map<String, List> result = namespaceService.importJobsFromNamespaceToNamespace("saturn.vip.vip.com", "saturn.vip.vip.com_tt", "ray.leung");
Assert.assertThat(result.get("success").size(), is(3));
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class UpdateJobConfigVo method toJobConfig.
public JobConfig toJobConfig() {
JobConfig jobConfig = new JobConfig();
SaturnBeanUtils.copyProperties(this, jobConfig);
if (onlyUsePreferList != null) {
jobConfig.setUseDispreferList(!onlyUsePreferList);
}
return jobConfig;
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class ExecutorServiceImplTest method getExecutorRunningInfo.
@Test
public void getExecutorRunningInfo() throws SaturnJobConsoleException {
String namespace = "www.abc.com";
String executorName = "exec01";
when(registryCenterService.getCuratorFrameworkOp(namespace)).thenReturn(curatorFrameworkOp);
JobConfig jobConfigA = new JobConfig();
jobConfigA.setJobName("jobA");
jobConfigA.setJobType(JobType.JAVA_JOB.name());
jobConfigA.setEnabledReport(Boolean.TRUE);
jobConfigA.setFailover(Boolean.TRUE);
jobConfigA.setLocalMode(Boolean.FALSE);
JobConfig jobConfigB = new JobConfig();
jobConfigB.setJobName("jobB");
jobConfigB.setJobType(JobType.MSG_JOB.name());
jobConfigB.setEnabledReport(Boolean.FALSE);
jobConfigB.setFailover(Boolean.FALSE);
jobConfigB.setLocalMode(Boolean.FALSE);
JobConfig jobConfigC = new JobConfig();
jobConfigC.setJobName("jobC");
jobConfigC.setJobType(JobType.JAVA_JOB.name());
jobConfigC.setEnabledReport(Boolean.TRUE);
jobConfigC.setFailover(Boolean.FALSE);
jobConfigC.setLocalMode(Boolean.FALSE);
when(jobService.getUnSystemJobs(namespace)).thenReturn(Lists.newArrayList(jobConfigA, jobConfigB, jobConfigC));
when(curatorFrameworkOp.checkExists(String.format("/%s/%s/servers", $JOBS_NODE_NAME, jobConfigA.getJobName()))).thenReturn(true);
when(curatorFrameworkOp.checkExists(String.format("/%s/%s/servers", $JOBS_NODE_NAME, jobConfigB.getJobName()))).thenReturn(true);
when(curatorFrameworkOp.checkExists(String.format("/%s/%s/servers", $JOBS_NODE_NAME, jobConfigC.getJobName()))).thenReturn(true);
when(curatorFrameworkOp.getData(String.format("%s/%s/%s", JobNodePath.getServerNodePath(jobConfigA.getJobName()), executorName, "sharding"))).thenReturn("1,2");
when(curatorFrameworkOp.getData(String.format("%s/%s/%s", JobNodePath.getServerNodePath(jobConfigB.getJobName()), executorName, "sharding"))).thenReturn("2,3");
when(curatorFrameworkOp.getData(String.format("%s/%s/%s", JobNodePath.getServerNodePath(jobConfigC.getJobName()), executorName, "sharding"))).thenReturn("0,1");
when(curatorFrameworkOp.getChildren(JobNodePath.getExecutionNodePath("jobA"))).thenReturn(Lists.newArrayList("0", "1", "2", "3"));
when(curatorFrameworkOp.getChildren(JobNodePath.getExecutionNodePath("jobB"))).thenReturn(Lists.newArrayList("0", "1", "2", "3"));
when(curatorFrameworkOp.getChildren(JobNodePath.getExecutionNodePath("jobC"))).thenReturn(Lists.newArrayList("0", "1", "2", "3"));
when(curatorFrameworkOp.checkExists(JobNodePath.getExecutionNodePath("jobA", "0", "running"))).thenReturn(true);
when(curatorFrameworkOp.getData(JobNodePath.getExecutionNodePath("jobA", "0", "failover"))).thenReturn(executorName);
when(curatorFrameworkOp.checkExists(JobNodePath.getExecutionNodePath("jobA", "1", "running"))).thenReturn(true);
when(curatorFrameworkOp.checkExists(JobNodePath.getExecutionNodePath("jobA", "2", "running"))).thenReturn(true);
when(curatorFrameworkOp.checkExists(JobNodePath.getExecutionNodePath("jobA", "3", "running"))).thenReturn(true);
when(curatorFrameworkOp.getData(JobNodePath.getExecutionNodePath("jobA", "3", "failover"))).thenReturn("other-exec");
when(curatorFrameworkOp.checkExists(JobNodePath.getExecutionNodePath("jobC", "0", "running"))).thenReturn(false);
when(curatorFrameworkOp.checkExists(JobNodePath.getExecutionNodePath("jobC", "1", "running"))).thenReturn(true);
when(curatorFrameworkOp.checkExists(JobNodePath.getExecutionNodePath("jobC", "2", "running"))).thenReturn(true);
when(curatorFrameworkOp.checkExists(JobNodePath.getExecutionNodePath("jobC", "3", "running"))).thenReturn(true);
ServerRunningInfo serverRunningInfo = executorService.getExecutorRunningInfo(namespace, executorName);
assertEquals(2, serverRunningInfo.getRunningJobItems().size());
assertEquals("0,1,2", serverRunningInfo.getRunningJobItems().get("jobA"));
assertEquals("1", serverRunningInfo.getRunningJobItems().get("jobC"));
assertEquals(0, serverRunningInfo.getPotentialRunningJobItems().size());
assertEquals(null, serverRunningInfo.getPotentialRunningJobItems().get("jobB"));
}
Aggregations