Search in sources :

Example 86 with JobConfig

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);
    }
}
Also used : JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) 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)

Example 87 with JobConfig

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));
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) JobConfig(com.vip.saturn.job.console.domain.JobConfig) Test(org.junit.Test)

Example 88 with JobConfig

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;
}
Also used : JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 89 with 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"));
}
Also used : ServerRunningInfo(com.vip.saturn.job.console.domain.ServerRunningInfo) JobConfig(com.vip.saturn.job.console.domain.JobConfig) Test(org.junit.Test)

Aggregations

JobConfig (com.vip.saturn.job.console.domain.JobConfig)89 FinishCheck (com.vip.saturn.it.base.FinishCheck)45 SimpleJavaJob (com.vip.saturn.it.job.SimpleJavaJob)37 Test (org.junit.Test)35 Main (com.vip.saturn.job.executor.Main)31 LongtimeJavaJob (com.vip.saturn.it.job.LongtimeJavaJob)12 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)10 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)9 List (java.util.List)6 Collection (java.util.Collection)5 Map (java.util.Map)4 InitByGroupsJob (com.vip.saturn.it.job.InitByGroupsJob)3 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)3 ArrayList (java.util.ArrayList)3 ResponseEntity (org.springframework.http.ResponseEntity)3 Audit (com.vip.saturn.job.console.aop.annotation.Audit)2 JobDiffInfo (com.vip.saturn.job.console.domain.JobDiffInfo)2 RestApiJobConfig (com.vip.saturn.job.console.domain.RestApiJobConfig)2 JobConfig4DB (com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)2 ParseException (java.text.ParseException)2