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());
}
}
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());
}
}
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();
}
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();
}
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;
}
Aggregations