use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class ExecutorCleanIT method test_A_Clean.
@Test
public void test_A_Clean() throws Exception {
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = true;
startOneNewExecutorList();
final String executorName = saturnExecutorList.get(0).getExecutorName();
final JobConfig job = new JobConfig();
job.setJobName("test_A_Clean");
job.setCron("*/2 * * * * ?");
job.setJobType(JobType.JAVA_JOB.toString());
job.setJobClass(SimpleJavaJob.class.getCanonicalName());
job.setShardingTotalCount(1);
job.setShardingItemParameters("0=0");
job.setPreferList(executorName);
addJob(job);
Thread.sleep(1000);
enableJob(job.getJobName());
Thread.sleep(3 * 1000);
stopExecutorListGracefully();
Thread.sleep(2000);
assertDelete(job.getJobName(), executorName);
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class FailoverIT method failover.
private void failover(final int shardCount, final String jobName) throws Exception {
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的作业,它只能手工触发
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);
// 2 启动作业并立刻执行一次
enableJob(jobName);
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;
}
}, 6);
} 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 (Integer item : items) {
if (!isFailoverAssigned(jobName, item)) {
return false;
}
}
return true;
}
}, 20);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
Thread.sleep(1000);
// 5 检查停止的executor 上面的分片是否已经被KILL
for (Integer item : items) {
String key = jobName + "_" + item;
LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
if (!status.finished || status.killed == 0) {
fail("should finish and killed");
}
status.runningCount = 0;
}
// 6 保证全部分片都会执行一次(被停止的executor上的分片会失败转移从而也会执行一次)
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (int j = 0; j < shardCount; j++) {
String key = jobName + "_" + j;
LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
if (status.runningCount <= 0) {
return false;
}
}
return true;
}
}, 60);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
Thread.sleep(2000);
LongtimeJavaJob.statusMap.clear();
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class RunAtOnceJobIT method test_B_ignoreWhenIsRunning.
@Test
public void test_B_ignoreWhenIsRunning() throws Exception {
final int shardCount = 1;
final String jobName = "test_B_ignoreWhenIsRunning";
LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
status.runningCount = 0;
status.sleepSeconds = 3;
status.finished = false;
status.timeout = false;
LongtimeJavaJob.statusMap.put(jobName + "_" + 0, 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.setTimeoutSeconds(0);
jobConfig.setShardingItemParameters("0=0");
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(1000);
runAtOnce(jobName);
Thread.sleep(1000);
// suppose to be ignored.
try {
runAtOnce(jobName);
} catch (Exception e) {
assertThat(e.getMessage()).isEqualTo("该作业(" + jobName + ")不处于READY状态,不能立即执行");
}
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
String path = JobNodePath.getNodeFullPath(jobName, String.format(ServerNode.RUNONETIME, "executorName0"));
if (regCenter.isExisted(path)) {
return false;
}
return true;
}
}, 20);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
if (LongtimeJavaJob.statusMap.get(jobName + "_" + 0).runningCount < 1) {
return false;
}
return true;
}
}, 30);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
LongtimeJavaJob.statusMap.clear();
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class ShardingIT method test_F_LocalModeWithPreferList.
/**
* 本地模式作业,配置了preferList,并且useDispreferList为false,则只有preferList能得到该作业分片
*/
@Test
public void test_F_LocalModeWithPreferList() throws Exception {
Main executor1 = startOneNewExecutorList();
Main executor2 = startOneNewExecutorList();
int shardCount = 2;
final String jobName = "test_F_LocalModeWithPreferList";
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("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("*=0");
jobConfig.setLocalMode(true);
// 设置preferList为executor2
jobConfig.setPreferList(executor2.getExecutorName());
// 设置useDispreferList为false
jobConfig.setUseDispreferList(false);
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return isNeedSharding(jobName);
}
}, 10);
runAtOnce(jobName);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return !isNeedSharding(jobName);
}
}, 10);
List<Integer> items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).contains(0);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).isEmpty();
// wait running completed
Thread.sleep(1000);
// executor2下线
stopExecutorGracefully(1);
Thread.sleep(1000);
// 等待sharding分片完成
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return isNeedSharding(jobName);
}
}, 10);
runAtOnce(jobName);
// 等待拿走分片
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return !isNeedSharding(jobName);
}
}, 10);
// executor1仍然获取不到分片
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).isEmpty();
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
stopExecutorListGracefully();
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class ShardingIT method test_N_NotifyNecessaryJobs.
/**
* sharding仅仅通知分片信息改变的作业
*/
@Test
public void test_N_NotifyNecessaryJobs() throws Exception {
// 启动1个executor
Main executor1 = startOneNewExecutorList();
Thread.sleep(1000);
// 启动第一个作业
Thread.sleep(1000);
final String jobName1 = "test_N_NotifyNecessaryJobs1";
JobConfig jobConfig1 = new JobConfig();
jobConfig1.setJobName(jobName1);
jobConfig1.setCron("9 9 9 9 9 ? 2099");
jobConfig1.setJobType(JobType.JAVA_JOB.toString());
jobConfig1.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig1.setShardingTotalCount(1);
jobConfig1.setShardingItemParameters("0=0");
addJob(jobConfig1);
Thread.sleep(1000);
enableJob(jobName1);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return isNeedSharding(jobName1);
}
}, 10);
runAtOnce(jobName1);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return !isNeedSharding(jobName1);
}
}, 10);
// 启动第二个作业
Thread.sleep(1000);
final String jobName2 = "test_N_NotifyNecessaryJobs2";
JobConfig jobConfig2 = new JobConfig();
jobConfig2.setJobName(jobName2);
jobConfig2.setCron("9 9 9 9 9 ? 2099");
jobConfig2.setJobType(JobType.JAVA_JOB.toString());
jobConfig2.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig2.setShardingTotalCount(1);
jobConfig2.setShardingItemParameters("0=0");
addJob(jobConfig2);
// job1和job2均无需re-sharding
Thread.sleep(1000);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return !isNeedSharding(jobName1) && !isNeedSharding(jobName2);
}
}, 10);
enableJob(jobName2);
// job1无需re-sharding
Thread.sleep(1000);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return !isNeedSharding(jobName1);
}
}, 10);
disableJob(jobName1);
removeJob(jobName1);
disableJob(jobName2);
removeJob(jobName2);
stopExecutorListGracefully();
}
Aggregations