Search in sources :

Example 36 with Main

use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.

the class AbstractSaturnIT method stopExecutor.

public void stopExecutor(int index) throws Exception {
    assertThat(saturnExecutorList.size()).isGreaterThan(index);
    Main main = saturnExecutorList.get(index);
    if (main != null) {
        main.shutdown();
    } else {
        log.warn("the {} Executor has stopped", index);
    }
    saturnExecutorList.set(index, null);
    for (Main tmp : saturnExecutorList) {
        if (tmp != null) {
            return;
        }
    }
    saturnExecutorList.clear();
}
Also used : Main(com.vip.saturn.job.executor.Main)

Example 37 with Main

use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.

the class AbstractSaturnIT method getExecutorConfig.

public ExecutorConfig getExecutorConfig(int index) {
    assertThat(saturnExecutorList.size()).isGreaterThan(index);
    Main main = saturnExecutorList.get(index);
    SaturnExecutor saturnExecutor = (SaturnExecutor) main.getSaturnExecutor();
    return saturnExecutor.getSaturnExecutorService().getExecutorConfig();
}
Also used : SaturnExecutor(com.vip.saturn.job.executor.SaturnExecutor) Main(com.vip.saturn.job.executor.Main)

Example 38 with Main

use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.

the class AbstractSaturnIT method startExecutor.

public Main startExecutor(int index) throws Exception {
    assertThat(nestedZkUtils.isStarted());
    Main main = saturnExecutorList.get(index);
    if (main != null) {
        // 如果节点正在运行则退出
        log.warn("the executor{} already exist.", index);
        return main;
    } else {
        main = new Main();
        String executorName = "executorName" + index;
        String[] args = { "-namespace", NAMESPACE, "-executorName", executorName };
        main.launchInner(args, Main.class.getClassLoader(), Main.class.getClassLoader());
        saturnExecutorList.set(index, main);
        Thread.sleep(1000);
        return main;
    }
}
Also used : Main(com.vip.saturn.job.executor.Main)

Example 39 with Main

use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.

the class LocalModeIT method test_B.

@Test
public void test_B() throws Exception {
    startExecutorList(2);
    int shardCount = 3;
    final String jobName = "test_B";
    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("*/1 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setProcessCountIntervalSeconds(1);
    jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
    jobConfig.setShardingItemParameters("*=0");
    jobConfig.setLocalMode(true);
    addJob(jobConfig);
    Thread.sleep(1000);
    enableJob(jobName);
    Thread.sleep(1000);
    waitForFinish(new FinishCheck() {

        @Override
        public boolean isOk() {
            for (Main executor : saturnExecutorList) {
                String count = zkGetJobNode(jobName, "servers/" + executor.getExecutorName() + "/processSuccessCount");
                System.out.println("count:" + count + ";executor:" + executor.getExecutorName());
                if (count == null)
                    return false;
                int times = Integer.parseInt(count);
                if (times <= 0)
                    return false;
            }
            return true;
        }
    }, 60);
    disableJob(jobName);
    Thread.sleep(1000);
    removeJob(jobName);
}
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 40 with Main

use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.

the class LocalModeIT method test_C_withPreferList.

@Test
public void test_C_withPreferList() throws Exception {
    startExecutorList(2);
    int shardCount = 3;
    final String jobName = "test_C_withPreferList";
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        SimpleJavaJob.statusMap.put(key, 0);
    }
    final Main preferExecutor = saturnExecutorList.get(0);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName(jobName);
    jobConfig.setCron("*/1 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setProcessCountIntervalSeconds(1);
    jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
    jobConfig.setShardingItemParameters("*=0");
    jobConfig.setLocalMode(true);
    jobConfig.setPreferList(preferExecutor.getExecutorName());
    addJob(jobConfig);
    Thread.sleep(1000);
    enableJob(jobName);
    Thread.sleep(1000);
    waitForFinish(new FinishCheck() {

        @Override
        public boolean isOk() {
            String count0 = zkGetJobNode(jobName, "servers/" + preferExecutor.getExecutorName() + "/processSuccessCount");
            System.out.println("count:" + count0 + ";executor:" + preferExecutor.getExecutorName());
            if (count0 == null)
                return false;
            int times0 = Integer.parseInt(count0);
            if (times0 <= 0)
                return false;
            for (int i = 1; i < saturnExecutorList.size(); i++) {
                Main executor = saturnExecutorList.get(i);
                String count = zkGetJobNode(jobName, "servers/" + executor.getExecutorName() + "/processSuccessCount");
                System.out.println("count:" + count + ";executor:" + executor.getExecutorName());
                if (count != null) {
                    int times = Integer.parseInt(count);
                    if (times != 0)
                        return false;
                }
            }
            return true;
        }
    }, 30);
    disableJob(jobName);
    Thread.sleep(1000);
    removeJob(jobName);
}
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)

Aggregations

Main (com.vip.saturn.job.executor.Main)43 JobConfig (com.vip.saturn.job.console.domain.JobConfig)31 FinishCheck (com.vip.saturn.it.base.FinishCheck)26 SimpleJavaJob (com.vip.saturn.it.job.SimpleJavaJob)25 Test (org.junit.Test)24 List (java.util.List)4 LongtimeJavaJob (com.vip.saturn.it.job.LongtimeJavaJob)2 UpdateCronJob (com.vip.saturn.it.job.UpdateCronJob)1 SaturnExecutor (com.vip.saturn.job.executor.SaturnExecutor)1 JobConfiguration (com.vip.saturn.job.internal.config.JobConfiguration)1 File (java.io.File)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1