use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class ScriptJobIT method test_A_Normalsh.
@Test
public void test_A_Normalsh() throws Exception {
if (!OS.isFamilyUnix()) {
return;
}
startOneNewExecutorList();
final String jobName = "test_A_Normalsh";
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("*/4 * * * * ?");
jobConfig.setJobType(JobType.SHELL_JOB.toString());
jobConfig.setShardingTotalCount(1);
jobConfig.setProcessCountIntervalSeconds(1);
jobConfig.setShardingItemParameters("0=sh " + NORMAL_SH_PATH);
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(1000);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
String count = zkGetJobNode(jobName, "servers/" + saturnExecutorList.get(0).getExecutorName() + "/processSuccessCount");
log.info("success count: {}", count);
int cc = Integer.parseInt(count);
if (cc > 0) {
return true;
}
return false;
}
}, 15);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class ShardingWithTrafficIT method test_A_NormalFlow.
/**
* 一般流量摘取和恢复流程:<br> 两个启用状态的作业,两台机A、B;<br> 摘取B的流量,结果B的分片被分配到A;<br> 下线B,分片分配依然不变;<br> 上线B,分配分配依然不变;<br>
* 恢复B的流量,结果平均分配分片到A、B。
*/
@Test
public void test_A_NormalFlow() throws Exception {
String jobName = "test_A_NormalFlow";
String jobName2 = "test_A_NormalFlow2";
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(2);
jobConfig.setShardingItemParameters("0=0,1=1");
final 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(2);
jobConfig2.setShardingItemParameters("0=0,1=1");
addJob(jobConfig);
Thread.sleep(1000L);
addJob(jobConfig2);
Thread.sleep(1000L);
enableJob(jobName);
Thread.sleep(1000L);
enableJob(jobName2);
Thread.sleep(1000L);
Main executor1 = startOneNewExecutorList();
String executorName1 = executor1.getExecutorName();
Main executor2 = startOneNewExecutorList();
String executorName2 = executor2.getExecutorName();
runAtOnceAndWaitShardingCompleted(jobName);
runAtOnceAndWaitShardingCompleted(jobName2);
isItemsBalanceOk(jobName, jobName2, executorName1, executorName2);
extractTraffic(executorName2);
Thread.sleep(1000L);
runAtOnceAndWaitShardingCompleted(jobName);
runAtOnceAndWaitShardingCompleted(jobName2);
isItemsToExecutor1(jobName, jobName2, executorName1, executorName2);
stopExecutorGracefully(1);
Thread.sleep(1000L);
runAtOnceAndWaitShardingCompleted(jobName);
runAtOnceAndWaitShardingCompleted(jobName2);
isItemsToExecutor1(jobName, jobName2, executorName1, executorName2);
executor2 = startExecutor(1);
executorName2 = executor2.getExecutorName();
runAtOnceAndWaitShardingCompleted(jobName);
runAtOnceAndWaitShardingCompleted(jobName2);
isItemsToExecutor1(jobName, jobName2, executorName1, executorName2);
recoverTraffic(executorName2);
Thread.sleep(1000L);
runAtOnceAndWaitShardingCompleted(jobName);
runAtOnceAndWaitShardingCompleted(jobName2);
isItemsBalanceOk(jobName, jobName2, executorName1, executorName2);
// 清理,不影响其他Test
disableJob(jobName);
disableJob(jobName2);
Thread.sleep(1000L);
removeJob(jobName);
removeJob(jobName2);
Thread.sleep(1000L);
stopExecutorListGracefully();
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class TimeoutJobIT method test_B_shJob.
@Test
public void test_B_shJob() throws Exception {
// bacause ScriptPidUtils.isPidRunning don't support mac
if (!OS.isFamilyUnix() || OS.isFamilyMac()) {
return;
}
final int shardCount = 3;
final String jobName = "test_B_shJob";
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.SHELL_JOB.toString());
jobConfig.setJobClass(LongtimeJavaJob.class.getCanonicalName());
jobConfig.setTimeoutSeconds(3);
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("0=sh " + LONG_TIME_SH_PATH + ",1=sh " + LONG_TIME_SH_PATH + ",2=sh " + LONG_TIME_SH_PATH);
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobConfig.getJobName());
Thread.sleep(1000);
runAtOnce(jobName);
// wait executor receive the runAtOnce event
Thread.sleep(500L);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (int i = 0; i < saturnExecutorList.size(); i++) {
Main saturnContainer = saturnExecutorList.get(i);
for (int j = 0; j < shardCount; j++) {
long pid = ScriptPidUtils.getFirstPidFromFile(saturnContainer.getExecutorName(), jobName, "" + j);
if (pid > 0 && ScriptPidUtils.isPidRunning(pid)) {
return false;
}
}
}
return true;
}
}, 10);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (int j = 0; j < shardCount; j++) {
if (!regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getCompletedNode(j)))) {
return false;
}
}
return true;
}
}, 10);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
disableJob(jobConfig.getJobName());
Thread.sleep(1000);
removeJob(jobConfig.getJobName());
LongtimeJavaJob.statusMap.clear();
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class UpdateCronJobIT method updateCron.
@Test
public void updateCron() throws Exception {
final int shardCount = 3;
final String jobName = "toBeupdatedITJob";
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.setTimeoutSeconds(0);
jobConfig.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(2000);
enableJob(jobName);
jobConfig = new JobConfig();
jobConfig.setJobName("updateCronITJob");
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(UpdateCronJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(1);
jobConfig.setProcessCountIntervalSeconds(1);
jobConfig.setShardingItemParameters("0=toBeupdatedITJob");
addJob(jobConfig);
Thread.sleep(2000);
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
assertThat(SimpleJavaJob.statusMap.get(key)).isEqualTo(0);
}
enableJob(jobConfig.getJobName());
Thread.sleep(2000);
runAtOnce(jobConfig.getJobName());
Thread.sleep(2000);
final JobConfig t = jobConfig;
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (Main executor : saturnExecutorList) {
String count = zkGetJobNode(t.getJobName(), "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;
}
}, 10);
disableJob(jobConfig.getJobName());
Thread.sleep(2 * 1000);
removeJob(jobConfig.getJobName());
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
if (SimpleJavaJob.statusMap.get(key) < 1) {
return false;
}
}
return true;
}
}, 30);
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
Thread.sleep(2000);
SimpleJavaJob.statusMap.clear();
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class JobOperationRestApiController method constructJobConfigOfUpdate.
private JobConfig constructJobConfigOfUpdate(String namespace, String jobName, Map<String, Object> reqParams) throws SaturnJobConsoleException {
checkMissingParameter("namespace", namespace);
checkMissingParameter("jobName", jobName);
if (!reqParams.containsKey("jobConfig")) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(INVALID_REQUEST_MSG, "jobConfig", "cannot be blank"));
}
JobConfig jobConfig = new JobConfig();
Map<String, Object> configParams = (Map<String, Object>) reqParams.get("jobConfig");
jobConfig.setJobName(jobName);
jobConfig.setDescription(checkAndGetParametersValueAsString(reqParams, "description", false));
jobConfig.setChannelName(checkAndGetParametersValueAsString(configParams, "channelName", false));
jobConfig.setCron(checkAndGetParametersValueAsString(configParams, "cron", false));
jobConfig.setJobParameter(checkAndGetParametersValueAsString(configParams, "jobParameter", false));
jobConfig.setLoadLevel(checkAndGetParametersValueAsInteger(configParams, "loadLevel", false));
jobConfig.setLocalMode(checkAndGetParametersValueAsBoolean(configParams, "localMode", false));
jobConfig.setPausePeriodDate(checkAndGetParametersValueAsString(configParams, "pausePeriodDate", false));
jobConfig.setPausePeriodTime(checkAndGetParametersValueAsString(configParams, "pausePeriodTime", false));
jobConfig.setPreferList(checkAndGetParametersValueAsString(configParams, "preferList", false));
jobConfig.setQueueName(checkAndGetParametersValueAsString(configParams, "queueName", false));
jobConfig.setShardingItemParameters(checkAndGetParametersValueAsString(configParams, "shardingItemParameters", false));
jobConfig.setShardingTotalCount(checkAndGetParametersValueAsInteger(configParams, "shardingTotalCount", false));
jobConfig.setTimeout4AlarmSeconds(checkAndGetParametersValueAsInteger(configParams, "timeout4AlarmSeconds", false));
jobConfig.setUseDispreferList(checkAndGetParametersValueAsBoolean(configParams, "useDispreferList", false));
jobConfig.setUseSerial(checkAndGetParametersValueAsBoolean(configParams, "useSerial", false));
jobConfig.setJobDegree(checkAndGetParametersValueAsInteger(configParams, "jobDegree", false));
jobConfig.setDependencies(checkAndGetParametersValueAsString(configParams, "dependencies", false));
jobConfig.setTimeZone(checkAndGetParametersValueAsString(configParams, "timeZone", false));
jobConfig.setTimeoutSeconds(checkAndGetParametersValueAsInteger(configParams, "timeoutSeconds", false));
jobConfig.setProcessCountIntervalSeconds(checkAndGetParametersValueAsInteger(configParams, "processCountIntervalSeconds", false));
jobConfig.setGroups(checkAndGetParametersValueAsString(configParams, "groups", false));
jobConfig.setShowNormalLog(checkAndGetParametersValueAsBoolean(configParams, "showNormalLog", false));
jobConfig.setRerun(checkAndGetParametersValueAsBoolean(configParams, "rerun", false));
jobConfig.setFailover(checkAndGetParametersValueAsBoolean(configParams, "failover", false));
jobConfig.setUpStream(checkAndGetParametersValueAsString(configParams, "upStream", false));
jobConfig.setDownStream(checkAndGetParametersValueAsString(configParams, "downStream", false));
return jobConfig;
}
Aggregations