Search in sources :

Example 6 with JobConfig

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

the class ExecutionIT method test_A_report.

@Test
public void test_A_report() throws Exception {
    startExecutorList(1);
    final JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName("test_A_report");
    jobConfig.setCron("9 9 9 9 9 ? 2099");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
    jobConfig.setShardingTotalCount(1);
    jobConfig.setShardingItemParameters("0=0");
    addJob(jobConfig);
    zkUpdateJobNode(jobConfig.getJobName(), "config/enabledReport", "true");
    Thread.sleep(1000);
    enableJob(jobConfig.getJobName());
    Thread.sleep(1000);
    runAtOnce(jobConfig.getJobName());
    Thread.sleep(1000);
    assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/lastBeginTime")).isNull();
    assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/nextFireTime")).isNull();
    assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/lastCompleteTime")).isNull();
    assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/jobMsg")).isNull();
    assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/jobLog")).isNull();
    assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/completed")).isNotNull();
    doReport(jobConfig.getJobName());
    waitForFinish(new FinishCheck() {

        @Override
        public boolean isOk() {
            if (zkGetJobNode(jobConfig.getJobName(), "execution/0/lastBeginTime") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/nextFireTime") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/lastCompleteTime") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/jobMsg") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/jobLog") != null) {
                return true;
            }
            return false;
        }
    }, 3);
    zkRemoveJobNode(jobConfig.getJobName(), "execution/0/lastBeginTime");
    zkRemoveJobNode(jobConfig.getJobName(), "execution/0/nextFireTime");
    zkRemoveJobNode(jobConfig.getJobName(), "execution/0/lastCompleteTime");
    zkRemoveJobNode(jobConfig.getJobName(), "execution/0/jobMsg");
    zkRemoveJobNode(jobConfig.getJobName(), "execution/0/jobLog");
    zkRemoveJobNode(jobConfig.getJobName(), "execution/0/completed");
    disableJob(jobConfig.getJobName());
    Thread.sleep(1000);
    disableReport(jobConfig.getJobName());
    Thread.sleep(1000);
    enableJob(jobConfig.getJobName());
    Thread.sleep(1000);
    runAtOnce(jobConfig.getJobName());
    Thread.sleep(1000);
    assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/completed")).isNull();
    doReport(jobConfig.getJobName());
    waitForFinish(new FinishCheck() {

        @Override
        public boolean isOk() {
            if (zkGetJobNode(jobConfig.getJobName(), "execution/0/lastBeginTime") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/nextFireTime") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/lastCompleteTime") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/jobMsg") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/jobLog") != null) {
                return true;
            }
            return false;
        }
    }, 3);
    disableJob(jobConfig.getJobName());
    Thread.sleep(1000);
    removeJob(jobConfig.getJobName());
    Thread.sleep(1000);
    stopExecutorListGracefully();
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) JobConfig(com.vip.saturn.job.console.domain.JobConfig) Test(org.junit.Test)

Example 7 with JobConfig

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

the class FailoverWithPreferListIT method test_A_JavaJob.

@Test
public void test_A_JavaJob() throws Exception {
    final int shardCount = 2;
    final String jobName = "failoverWithPreferITJobJava";
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
        status.runningCount = 0;
        status.sleepSeconds = 10;
        status.finished = false;
        status.timeout = false;
        LongtimeJavaJob.statusMap.put(key, status);
    }
    // 1 新建一个执行时间为10S的作业,它只能手工触发,它设置了preferList为executor0,并且只能使用优先结点
    final JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName(jobName);
    jobConfig.setCron("9 9 9 9 9 ? 2099");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass(LongtimeJavaJob.class.getCanonicalName());
    jobConfig.setShardingTotalCount(shardCount);
    jobConfig.setPreferList(saturnExecutorList.get(0).getExecutorName());
    jobConfig.setUseDispreferList(false);
    jobConfig.setShardingItemParameters("0=0,1=1,2=2");
    addJob(jobConfig);
    Thread.sleep(1000);
    // 2 启动作业并立刻执行一次
    enableJob(jobConfig.getJobName());
    Thread.sleep(2000);
    runAtOnce(jobName);
    // 3 保证全部作业分片正在运行中
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                for (int j = 0; j < shardCount; j++) {
                    if (!regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getRunningNode(j)))) {
                        return false;
                    }
                }
                return true;
            }
        }, 30);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    Thread.sleep(2000);
    final List<Integer> items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(saturnExecutorList.get(0).getExecutorName()))));
    // 4 停止第一个executor,在该executor上运行的分片不会失败转移(因为优先结点已经全部死掉了)
    stopExecutor(0);
    System.out.println("items:" + items);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                for (int j = 0; j < shardCount; j++) {
                    if (regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getRunningNode(j)))) {
                        return false;
                    }
                }
                return true;
            }
        }, 20);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    // 5 没有失败转移,executor0上面运行的分片不会被执行
    for (Integer item : items) {
        String key = jobName + "_" + item;
        LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
        assertThat(status.runningCount).isEqualTo(0);
    }
    disableJob(jobConfig.getJobName());
    Thread.sleep(1000);
    removeJob(jobConfig.getJobName());
    Thread.sleep(2000);
    LongtimeJavaJob.statusMap.clear();
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) JobConfig(com.vip.saturn.job.console.domain.JobConfig) LongtimeJavaJob(com.vip.saturn.it.job.LongtimeJavaJob)

Example 8 with JobConfig

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

the class InitJobByGroupsIT method testC_ExecutorConfigGroupsAndInitJobFailed.

@Test
public void testC_ExecutorConfigGroupsAndInitJobFailed() throws Exception {
    try {
        System.setProperty(SystemEnvProperties.NAME_VIP_SATURN_INIT_JOB_BY_GROUPS, "group1, group2");
        SystemEnvProperties.loadProperties();
        InitByGroupsJob.inited = false;
        startOneNewExecutorList();
        Thread.sleep(1000);
        JobConfig jobConfig = new JobConfig();
        jobConfig.setJobName("testC_ExecutorConfigGroupsAndInitJobFailed");
        jobConfig.setCron("*/2 * * * * ?");
        jobConfig.setJobType(JobType.JAVA_JOB.toString());
        jobConfig.setJobClass(InitByGroupsJob.class.getCanonicalName());
        jobConfig.setShardingTotalCount(1);
        jobConfig.setShardingItemParameters("0=0");
        jobConfig.setGroups("");
        addJob(jobConfig);
        Thread.sleep(1000);
        assertThat(InitByGroupsJob.inited).isFalse();
        removeJob(jobConfig.getJobName());
    } finally {
        System.clearProperty(SystemEnvProperties.NAME_VIP_SATURN_INIT_JOB_BY_GROUPS);
        SystemEnvProperties.loadProperties();
    }
}
Also used : InitByGroupsJob(com.vip.saturn.it.job.InitByGroupsJob) JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 9 with JobConfig

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

the class InitJobByGroupsIT method testB_ExecutorConfigGroupsAndInitJobSuccessfully.

@Test
public void testB_ExecutorConfigGroupsAndInitJobSuccessfully() throws Exception {
    try {
        System.setProperty(SystemEnvProperties.NAME_VIP_SATURN_INIT_JOB_BY_GROUPS, "group1, group2");
        SystemEnvProperties.loadProperties();
        InitByGroupsJob.inited = false;
        startOneNewExecutorList();
        Thread.sleep(1000);
        JobConfig jobConfig = new JobConfig();
        jobConfig.setJobName("testB_ExecutorConfigGroupsAndInitJobSuccessfully");
        jobConfig.setCron("*/2 * * * * ?");
        jobConfig.setJobType(JobType.JAVA_JOB.toString());
        jobConfig.setJobClass(InitByGroupsJob.class.getCanonicalName());
        jobConfig.setShardingTotalCount(1);
        jobConfig.setShardingItemParameters("0=0");
        jobConfig.setGroups("group2");
        addJob(jobConfig);
        Thread.sleep(1000);
        assertThat(InitByGroupsJob.inited).isTrue();
        removeJob(jobConfig.getJobName());
    } finally {
        System.clearProperty(SystemEnvProperties.NAME_VIP_SATURN_INIT_JOB_BY_GROUPS);
        SystemEnvProperties.loadProperties();
    }
}
Also used : InitByGroupsJob(com.vip.saturn.it.job.InitByGroupsJob) JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 10 with JobConfig

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

the class InitJobByGroupsIT method testA_ExecutorNotConfigGroups.

@Test
public void testA_ExecutorNotConfigGroups() throws Exception {
    System.clearProperty(SystemEnvProperties.NAME_VIP_SATURN_INIT_JOB_BY_GROUPS);
    SystemEnvProperties.loadProperties();
    InitByGroupsJob.inited = false;
    startOneNewExecutorList();
    Thread.sleep(1000);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName("testA_ExecutorNotConfigGroups");
    jobConfig.setCron("*/2 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass(InitByGroupsJob.class.getCanonicalName());
    jobConfig.setShardingTotalCount(1);
    jobConfig.setShardingItemParameters("0=0");
    jobConfig.setGroups("");
    addJob(jobConfig);
    Thread.sleep(1000);
    assertThat(InitByGroupsJob.inited).isTrue();
    removeJob(jobConfig.getJobName());
}
Also used : InitByGroupsJob(com.vip.saturn.it.job.InitByGroupsJob) JobConfig(com.vip.saturn.job.console.domain.JobConfig)

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