Search in sources :

Example 6 with JobConfiguration

use of com.vip.saturn.job.internal.config.JobConfiguration in project Saturn by vipshop.

the class DeleteJobIT method test_B.

/**
 * 部分结点存活
 *
 * @throws Exception
 */
@Test
public void test_B() throws Exception {
    final int shardCount = 3;
    final String jobName = "deleteITJob";
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        SimpleJavaJob.statusMap.put(key, 0);
    }
    stopExecutor(0);
    stopExecutor(1);
    JobConfiguration jobConfiguration = new JobConfiguration(jobName);
    jobConfiguration.setCron("0/2 * * * * ?");
    jobConfiguration.setJobType(JobType.JAVA_JOB.toString());
    jobConfiguration.setJobClass(SimpleJavaJob.class.getCanonicalName());
    jobConfiguration.setShardingTotalCount(shardCount);
    jobConfiguration.setShardingItemParameters("0=0,1=1,2=2");
    addJob(jobConfiguration);
    Thread.sleep(1000);
    enableJob(jobConfiguration.getJobName());
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean docheck() {
                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(jobConfiguration.getJobName());
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean docheck() {
                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(jobConfiguration.getJobName());
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean docheck() {
                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 : SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) Main(com.vip.saturn.job.executor.Main) JobConfiguration(com.vip.saturn.job.internal.config.JobConfiguration) Test(org.junit.Test)

Example 7 with JobConfiguration

use of com.vip.saturn.job.internal.config.JobConfiguration in project Saturn by vipshop.

the class DeleteJobIT method test_A.

/**
 * 全部结点存活时删除
 *
 * @throws InterruptedException
 */
@Test
public void test_A() throws InterruptedException {
    int shardCount = 3;
    final String jobName = "deleteITJob";
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        SimpleJavaJob.statusMap.put(key, 0);
    }
    JobConfiguration jobConfiguration = new JobConfiguration(jobName);
    jobConfiguration.setCron("0/2 * * * * ?");
    jobConfiguration.setJobType(JobType.JAVA_JOB.toString());
    jobConfiguration.setJobClass(SimpleJavaJob.class.getCanonicalName());
    jobConfiguration.setShardingTotalCount(shardCount);
    jobConfiguration.setShardingItemParameters("0=0,1=1,2=2");
    addJob(jobConfiguration);
    Thread.sleep(1000);
    enableJob(jobConfiguration.getJobName());
    Thread.sleep(4 * 1000);
    disableJob(jobConfiguration.getJobName());
    Thread.sleep(1000);
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        assertThat(SimpleJavaJob.statusMap.get(key)).isGreaterThanOrEqualTo(1);
    }
    removeJob(jobConfiguration.getJobName());
    Thread.sleep(5000);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean docheck() {
                if (regCenter.isExisted(JobNodePath.getJobNameFullPath(jobName))) {
                    return false;
                }
                return true;
            }
        }, 30);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) JobConfiguration(com.vip.saturn.job.internal.config.JobConfiguration) Test(org.junit.Test)

Example 8 with JobConfiguration

use of com.vip.saturn.job.internal.config.JobConfiguration in project Saturn by vipshop.

the class ZkStopStartIT method test_A_JavaJob.

@Test
public void test_A_JavaJob() throws InterruptedException, IOException {
    final int shardCount = 3;
    final String jobName = "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.killed = false;
        status.timeout = false;
        status.running = false;
        LongtimeJavaJob.statusMap.put(key, status);
    }
    JobConfiguration jobConfiguration = new JobConfiguration(jobName);
    jobConfiguration.setCron("0 0 0/1 * * ?");
    jobConfiguration.setJobType(JobType.JAVA_JOB.toString());
    jobConfiguration.setJobClass(LongtimeJavaJob.class.getCanonicalName());
    jobConfiguration.setShardingTotalCount(shardCount);
    jobConfiguration.setShardingItemParameters("0=0,1=1,2=2");
    addJob(jobConfiguration);
    Thread.sleep(2000);
    enableJob(jobConfiguration.getJobName());
    Thread.sleep(2000);
    runAtOnce(jobName);
    Thread.sleep(2000);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean docheck() {
                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 docheck() {
                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 : Collection(java.util.Collection) JobConfiguration(com.vip.saturn.job.internal.config.JobConfiguration) IOException(java.io.IOException) LongtimeJavaJob(com.vip.saturn.it.job.LongtimeJavaJob)

Example 9 with JobConfiguration

use of com.vip.saturn.job.internal.config.JobConfiguration in project Saturn by vipshop.

the class SaturnExecutor method scheduleJob.

private boolean scheduleJob(String jobName) {
    log.info("[{}] msg=add new job {} - {}", jobName, executorName, jobName);
    JobConfiguration jobConfig = new JobConfiguration(regCenter, jobName);
    if (jobConfig.getSaturnJobClass() == null) {
        log.warn("[{}] msg={} - {} the saturnJobClass is null, jobType is {}", jobConfig, executorName, jobName, jobConfig.getJobType());
        return false;
    }
    if (jobConfig.isDeleting()) {
        log.warn("[{}] msg={} - {} the job is on deleting", jobName, executorName, jobName);
        String serverNodePath = JobNodePath.getServerNodePath(jobName, executorName);
        regCenter.remove(serverNodePath);
        return false;
    }
    JobScheduler scheduler = new JobScheduler(regCenter, jobConfig);
    scheduler.setSaturnExecutorService(saturnExecutorService);
    return scheduler.init();
}
Also used : JobScheduler(com.vip.saturn.job.basic.JobScheduler) JobConfiguration(com.vip.saturn.job.internal.config.JobConfiguration)

Example 10 with JobConfiguration

use of com.vip.saturn.job.internal.config.JobConfiguration in project Saturn by vipshop.

the class SaturnAutoBasic method addShellMsgJobWithQueue.

public static JobConfiguration addShellMsgJobWithQueue(String jobName, String queue, int shardCount, String shardingItemParameters) throws InterruptedException {
    JobConfiguration jobCfg = initConfigOfShellMsgJob(jobName, queue, shardCount, shardingItemParameters);
    addJob(jobCfg);
    Thread.sleep(1000);
    // updateJobNode(jobConfiguration, "config/cron", "0/1 * * * * ?");
    return jobCfg;
}
Also used : JobConfiguration(com.vip.saturn.job.internal.config.JobConfiguration)

Aggregations

JobConfiguration (com.vip.saturn.job.internal.config.JobConfiguration)15 SimpleJavaJob (com.vip.saturn.it.job.SimpleJavaJob)3 Test (org.junit.Test)3 LongtimeJavaJob (com.vip.saturn.it.job.LongtimeJavaJob)2 Collection (java.util.Collection)2 JobScheduler (com.vip.saturn.job.basic.JobScheduler)1 Main (com.vip.saturn.job.executor.Main)1 JobNodeStorage (com.vip.saturn.job.internal.storage.JobNodeStorage)1 IOException (java.io.IOException)1