Search in sources :

Example 31 with JobConfig

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

the class ShutdownGracefullyIT method test_B_INT_Signal.

@Test
public void test_B_INT_Signal() throws Exception {
    SystemEnvProperties.VIP_SATURN_SHUTDOWN_TIMEOUT = 5;
    startExecutorList(1);
    final int shardCount = 3;
    final String jobName = "test_B_INT_Signal";
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
        status.runningCount = 0;
        status.sleepSeconds = 3;
        status.finished = false;
        status.timeout = false;
        LongtimeJavaJob.statusMap.put(key, status);
    }
    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.setShardingItemParameters("0=0,1=1,2=2");
    addJob(jobConfig);
    Thread.sleep(1000);
    enableJob(jobName);
    Thread.sleep(1000);
    runAtOnce(jobName);
    Thread.sleep(50);
    ShutdownHandler.exitAfterHandler(false);
    Signal.raise(new Signal("INT"));
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
                for (LongtimeJavaJob.JobStatus status : values) {
                    if (!status.finished) {
                        return false;
                    }
                }
                return true;
            }
        }, 5);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    stopExecutorListGracefully();
}
Also used : Signal(sun.misc.Signal) FinishCheck(com.vip.saturn.it.base.FinishCheck) Collection(java.util.Collection) JobConfig(com.vip.saturn.job.console.domain.JobConfig) LongtimeJavaJob(com.vip.saturn.it.job.LongtimeJavaJob)

Example 32 with JobConfig

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

the class UpdateConfigIT method updatePauseDate.

@Test
public void updatePauseDate() throws Exception {
    int shardCount = 1;
    String jobName = "updatePauseDate";
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        SimpleJavaJob.statusMap.put(key, 0);
    }
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName(jobName);
    jobConfig.setTimeZone(TimeZone.getDefault().getID());
    jobConfig.setCron("*/1 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
    jobConfig.setShardingTotalCount(shardCount);
    jobConfig.setShardingItemParameters("0=0");
    addJob(jobConfig);
    Thread.sleep(1000);
    enableJob(jobName);
    Thread.sleep(2 * 1000);
    disableJob(jobName);
    Thread.sleep(2 * 1000);
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        assertThat(SimpleJavaJob.statusMap.get(key)).isGreaterThanOrEqualTo(1);
    }
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        SimpleJavaJob.statusMap.put(key, 0);
    }
    int month = Calendar.getInstance().get(Calendar.MONTH) + 1;
    String pauseDate = month + "/" + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "-" + month + "/" + Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
    String pauseTime = Calendar.getInstance().get(Calendar.HOUR_OF_DAY) + ":00" + "-" + Calendar.getInstance().get(Calendar.HOUR_OF_DAY) + ":59";
    zkUpdateJobNode(jobName, "config/pausePeriodDate", pauseDate);
    zkUpdateJobNode(jobName, "config/pausePeriodTime", pauseTime);
    Thread.sleep(1000);
    enableJob(jobConfig.getJobName());
    Thread.sleep(2 * 1000);
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        assertThat(SimpleJavaJob.statusMap.get(key)).isEqualTo(0);
    }
    SimpleJavaJob.statusMap.clear();
    disableJob(jobName);
    Thread.sleep(1000);
    removeJob(jobName);
    Thread.sleep(2000);
}
Also used : SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) JobConfig(com.vip.saturn.job.console.domain.JobConfig) Test(org.junit.Test)

Example 33 with JobConfig

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

the class ZkStopStartIT method test_A_zkStopStartJobJava.

@Test
public void test_A_zkStopStartJobJava() throws Exception {
    final int shardCount = 3;
    final String jobName = "test_A_zkStopStartJobJava";
    LongtimeJavaJob.statusMap.clear();
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
        status.runningCount = 0;
        status.sleepSeconds = 60;
        status.finished = false;
        status.timeout = false;
        status.running = false;
        LongtimeJavaJob.statusMap.put(key, status);
    }
    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.setShardingItemParameters("0=0,1=1,2=2");
    addJob(jobConfig);
    Thread.sleep(2000);
    enableJob(jobName);
    Thread.sleep(2000);
    runAtOnce(jobName);
    Thread.sleep(2000);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
                for (LongtimeJavaJob.JobStatus status : values) {
                    if (!status.running) {
                        return false;
                    }
                }
                return true;
            }
        }, 40);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    stopZkServer();
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
                for (LongtimeJavaJob.JobStatus status : values) {
                    if (!status.finished) {
                        return false;
                    }
                }
                return true;
            }
        }, 40);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    LongtimeJavaJob.statusMap.clear();
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) Collection(java.util.Collection) JobConfig(com.vip.saturn.job.console.domain.JobConfig) LongtimeJavaJob(com.vip.saturn.it.job.LongtimeJavaJob)

Example 34 with JobConfig

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

the class InitJobFailAlarmIT method testH_clearRecord.

@Test
public void testH_clearRecord() throws Exception {
    String executorName = startOneNewExecutorList().getExecutorName();
    Thread.sleep(1000);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName("testH_clearRecord");
    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());
    jobConfig.setJobClass(InitSuccessfullyJob.class.getCanonicalName());
    addJob(jobConfig);
    Thread.sleep(2000);
    assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "jobClass is not set")).isFalse();
    removeJob(jobConfig.getJobName());
}
Also used : JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 35 with JobConfig

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

the class InitJobFailAlarmIT method testA_InitFailOfGetObjectJob.

@Test
public void testA_InitFailOfGetObjectJob() throws Exception {
    String executorName = startOneNewExecutorList().getExecutorName();
    Thread.sleep(1000);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName("testA_InitFailOfGetObjectJob");
    jobConfig.setCron("*/2 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass(InitFailOfGetObjectJob.class.getCanonicalName());
    jobConfig.setShardingTotalCount(1);
    jobConfig.setShardingItemParameters("0=0");
    addJob(jobConfig);
    Thread.sleep(2000);
    assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "java.lang.ArithmeticException: / by zero")).isTrue();
    removeJob(jobConfig.getJobName());
}
Also used : 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