Search in sources :

Example 61 with JobConfig

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

the class InitJobFailAlarmIT method testF_jobClassIsNotSet.

@Test
public void testF_jobClassIsNotSet() throws Exception {
    String executorName = startOneNewExecutorList().getExecutorName();
    Thread.sleep(1000);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName("testF_jobClassIsNotSet");
    jobConfig.setCron("*/2 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass("");
    jobConfig.setShardingTotalCount(1);
    jobConfig.setShardingItemParameters("0=0");
    // just add to zk, because add fail if add job by console api
    zkAddJob(jobConfig);
    Thread.sleep(2000);
    assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "jobClass is not set")).isTrue();
    zkRemoveJob(jobConfig.getJobName());
}
Also used : JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 62 with JobConfig

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

the class DeleteJobIT method test_A_multiExecutor.

/**
 * 多个Executor
 */
@Test
public void test_A_multiExecutor() throws Exception {
    startExecutorList(3);
    int shardCount = 3;
    final String jobName = "test_A_multiExecutor";
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        SimpleJavaJob.statusMap.put(key, 0);
    }
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName(jobName);
    jobConfig.setCron("*/2 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
    jobConfig.setShardingTotalCount(shardCount);
    jobConfig.setShardingItemParameters("0=0,1=1,2=2");
    addJob(jobConfig);
    Thread.sleep(1000);
    enableReport(jobName);
    enableJob(jobName);
    Thread.sleep(4 * 1000);
    disableJob(jobName);
    Thread.sleep(1000);
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        assertThat(SimpleJavaJob.statusMap.get(key)).isGreaterThanOrEqualTo(1);
    }
    removeJob(jobName);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                for (Main executor : saturnExecutorList) {
                    if (executor == null) {
                        continue;
                    }
                    if (regCenter.isExisted(ServerNode.getServerNode(jobName, executor.getExecutorName()))) {
                        return false;
                    }
                }
                return true;
            }
        }, 10);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) Main(com.vip.saturn.job.executor.Main) JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 63 with JobConfig

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

the class DeleteJobIT method test_B_oneExecutor.

/**
 * 只有一个Executor
 */
@Test
public void test_B_oneExecutor() throws Exception {
    startOneNewExecutorList();
    final int shardCount = 3;
    final String jobName = "test_B_oneExecutor";
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        SimpleJavaJob.statusMap.put(key, 0);
    }
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName(jobName);
    jobConfig.setCron("*/2 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
    jobConfig.setShardingTotalCount(shardCount);
    jobConfig.setShardingItemParameters("0=0,1=1,2=2");
    addJob(jobConfig);
    Thread.sleep(1000);
    enableReport(jobName);
    enableJob(jobName);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                for (int i = 0; i < shardCount; i++) {
                    String key = jobName + "_" + i;
                    if (SimpleJavaJob.statusMap.get(key) < 1) {
                        return false;
                    }
                }
                return true;
            }
        }, 4);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    disableJob(jobName);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                for (int j = 0; j < shardCount; j++) {
                    if (!regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getCompletedNode(j)))) {
                        return false;
                    }
                }
                return true;
            }
        }, 3);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    removeJob(jobName);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                for (Main executor : saturnExecutorList) {
                    if (executor == null) {
                        continue;
                    }
                    if (regCenter.isExisted(ServerNode.getServerNode(jobName, executor.getExecutorName()))) {
                        return false;
                    }
                }
                return true;
            }
        }, 10);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) Main(com.vip.saturn.job.executor.Main) JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 64 with JobConfig

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

the class DeleteJobIT method test_C_alreadyExistsToDelete.

/**
 * 补充删除作业时在启动Executor前有toDelete结点的IT: 如果有在启动Executor前作业有配置toDelete结点则会判断并删除$Jobs/jobName/servers/executorName
 */
@Test
public void test_C_alreadyExistsToDelete() throws Exception {
    final int shardCount = 3;
    final String jobName = "test_C_alreadyExistsToDelete";
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        SimpleJavaJob.statusMap.put(key, 0);
    }
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName(jobName);
    jobConfig.setCron("*/2 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
    jobConfig.setShardingTotalCount(shardCount);
    jobConfig.setShardingItemParameters("0=0,1=1,2=2");
    addJob(jobConfig);
    Thread.sleep(1000);
    enableReport(jobName);
    // 使用hack的方式,直接新增toDelete结点
    zkUpdateJobNode(jobName, ConfigurationNode.TO_DELETE, "1");
    final String serverNodePath = JobNodePath.getServerNodePath(jobName, "executorName0");
    regCenter.persist(serverNodePath, "");
    startOneNewExecutorList();
    Thread.sleep(1000);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                if (regCenter.isExisted(serverNodePath)) {
                    return false;
                }
                return true;
            }
        }, 10);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    removeJob(jobName);
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 65 with JobConfig

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

the class EnableOrNotIT method testB_restartExecutorWithEnabledChanged.

@Test
public void testB_restartExecutorWithEnabledChanged() throws Exception {
    startOneNewExecutorList();
    Thread.sleep(1000);
    SimpleJavaJob.lock.set(false);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName("testB_restartExecutor");
    jobConfig.setCron("*/2 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
    jobConfig.setShardingTotalCount(1);
    jobConfig.setShardingItemParameters("0=0");
    addJob(jobConfig);
    Thread.sleep(1000);
    assertThat(SimpleJavaJob.enabled.get()).isFalse();
    stopExecutorGracefully(0);
    Thread.sleep(1000);
    enableJob(jobConfig.getJobName());
    Thread.sleep(1000);
    startOneNewExecutorList();
    Thread.sleep(1000);
    assertThat(SimpleJavaJob.enabled.get()).isTrue();
    disableJob(jobConfig.getJobName());
    Thread.sleep(1000);
    assertThat(SimpleJavaJob.enabled.get()).isFalse();
    removeJob(jobConfig.getJobName());
}
Also used : SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) 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