use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class SaturnAutoBasic method startExecutor.
public static Main startExecutor(int index) throws Exception {
assertThat(nestedZkUtils.isStarted());
Main saturnContainer = saturnExecutorList.get(index);
if (saturnContainer != null) {
// 如果节点正在运行则退出
log.warn("the executor{} already exist.", index);
return saturnContainer;
} else {
Main 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;
}
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class SaturnAutoBasic method forceStopJob.
public static void forceStopJob(String jobName) {
for (int i = 0; i < saturnExecutorList.size(); i++) {
Main saturnContainer = saturnExecutorList.get(i);
if (saturnContainer == null) {
continue;
}
String path = JobNodePath.getNodeFullPath(jobName, String.format(ServerNode.STOPONETIME, saturnContainer.getExecutorName()));
if (regCenter.isExisted(path)) {
regCenter.remove(path);
}
regCenter.persist(path, "1");
}
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class SaturnAutoBasic method stopExecutor.
public static void stopExecutor(int index) throws Exception {
assertThat(saturnExecutorList.size()).isGreaterThan(index);
Main saturnContainer = saturnExecutorList.get(index);
if (saturnContainer != null) {
saturnContainer.shutdown();
} else {
log.warn("the {} SaturnContainer has stopped", index);
}
saturnExecutorList.set(index, null);
for (Main tmp : saturnExecutorList) {
if (tmp != null) {
return;
}
}
saturnExecutorList.clear();
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class ShardingIT method test_G_ContainerWithUseDispreferList.
/**
* preferList配置了容器资源,并且useDispreferList为true。当该容器有executor在线,则得到分片;当该容器全部executor下线,则其他executor得到分片
*/
@Test
public void test_G_ContainerWithUseDispreferList() throws Exception {
// 启动一个非容器executor
Main executor1 = startOneNewExecutorList();
boolean cleanOld = SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN;
String taskOld = SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID;
try {
String taskId = "test1";
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = true;
SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID = taskId;
// 启动一个容器executor
Main executor2 = startOneNewExecutorList();
final int shardCount = 2;
final String jobName = "test_G_ContainerWithUseDispreferList";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
SimpleJavaJob.statusMap.put(key, 0);
}
final 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=0,1=1");
jobConfig.setLocalMode(false);
// 设置preferList为@taskId
jobConfig.setPreferList("@" + taskId);
// 设置useDispreferList为true
jobConfig.setUseDispreferList(true);
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);
// executor2获取到0、1分片,executor1获取不到分片
List<Integer> items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).contains(0, 1);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).isEmpty();
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return hasCompletedZnodeForAllShards(jobName, shardCount);
}
}, 10);
// wait running completed
Thread.sleep(1000);
// executor2下线
stopExecutorGracefully(1);
Thread.sleep(1000L);
// 等待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仍然获取0、1分片
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).contains(0, 1);
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
stopExecutorListGracefully();
} finally {
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = cleanOld;
SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID = taskOld;
}
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class ShardingIT method test_K_ContainerWithUseDispreferList_ButInvalidTaskId.
/**
* preferList配置了无效容器资源,并且useDispreferList为true。则非容器资源会得到分片。
*/
@Test
public void test_K_ContainerWithUseDispreferList_ButInvalidTaskId() throws Exception {
// 启动一个非容器executor
Main logicExecutor = startOneNewExecutorList();
boolean cleanOld = SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN;
String taskOld = SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID;
try {
String taskId = "test1";
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = true;
SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID = taskId;
// 启动一个容器executor
Main vdosExecutor = startOneNewExecutorList();
int shardCount = 2;
final String jobName = "test_K_ContainerWithUseDispreferList_ButInvalidTaskId";
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=0,1=1");
jobConfig.setLocalMode(false);
// 设置preferList为@hahataskId
jobConfig.setPreferList("@haha" + taskId);
// 设置useDispreferList为true
jobConfig.setUseDispreferList(true);
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);
// vdosExecutor获取不到分片,logicExecutor获取到0、1分片
List<Integer> items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(vdosExecutor.getExecutorName()))));
assertThat(items).isEmpty();
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(logicExecutor.getExecutorName()))));
assertThat(items).contains(0, 1);
// wait running completed
Thread.sleep(1000);
// vdosExecutor下线
stopExecutorGracefully(1);
Thread.sleep(1000);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return isNeedSharding(jobName);
}
}, 10);
runAtOnce(jobName);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return !isNeedSharding(jobName);
}
}, 10);
// logicExecutor仍然获取0、1分片
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(logicExecutor.getExecutorName()))));
assertThat(items).contains(0, 1);
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
stopExecutorListGracefully();
} finally {
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = cleanOld;
SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID = taskOld;
}
}
Aggregations