use of com.vip.saturn.job.basic.JobScheduler in project Saturn by vipshop.
the class ConfigurationServiceTest method test_getShardingItemParameters_withInvalidNonnumericKey.
/**
* If sharding parameters appear nonnumeric key, the key should be dropped
* For issue #844 fixed by ray.leung
*/
@Test
public void test_getShardingItemParameters_withInvalidNonnumericKey() {
JobConfiguration jobConfiguration = mock(JobConfiguration.class);
when(jobConfiguration.getShardingItemParameters()).thenReturn("0=1,1=2,1={aa},2=a,a=");
JobScheduler jobScheduler = mock(JobScheduler.class);
when(jobScheduler.getCurrentConf()).thenReturn(jobConfiguration);
ConfigurationService configurationService = new ConfigurationService(jobScheduler);
Map parameters = configurationService.getShardingItemParameters();
assertNull(parameters.get("a"));
}
use of com.vip.saturn.job.basic.JobScheduler in project Saturn by vipshop.
the class ConfigurationServiceTest method test_A_isInPausePeriodDate2.
@Test
public void test_A_isInPausePeriodDate2() throws Exception {
JobConfiguration jobConfiguration = new JobConfiguration("");
jobConfiguration.setPausePeriodDate("9/1-9/33,10/01-10/02");
ZookeeperRegistryCenter zookeeperRegistryCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration());
zookeeperRegistryCenter.setExecutorName("haha");
ConfigurationService configurationService = new ConfigurationService(new JobScheduler(zookeeperRegistryCenter, jobConfiguration));
try {
Calendar calendar = Calendar.getInstance();
// 注意,日期从0-11,这里实际上是9月
calendar.set(2016, 8, 12, 11, 40);
boolean inPausePeriod = configurationService.isInPausePeriod(calendar.getTime());
assertThat(inPausePeriod).isTrue();
} finally {
JobRegistry.clearExecutor(zookeeperRegistryCenter.getExecutorName());
}
}
use of com.vip.saturn.job.basic.JobScheduler in project Saturn by vipshop.
the class SaturnExecutor method shutdownAllCountThread.
private void shutdownAllCountThread() {
Map<String, JobScheduler> schdMap = JobRegistry.getSchedulerMap().get(executorName);
if (schdMap != null) {
Iterator<String> it = schdMap.keySet().iterator();
while (it.hasNext()) {
String jobName = it.next();
JobScheduler jobScheduler = schdMap.get(jobName);
if (jobScheduler != null) {
jobScheduler.shutdownCountThread();
}
}
}
}
use of com.vip.saturn.job.basic.JobScheduler in project Saturn by vipshop.
the class ProcessCountResetTask method run.
@Override
public void run() {
try {
Map<String, ConcurrentHashMap<String, JobScheduler>> schedulerMap = JobRegistry.getSchedulerMap();
if (schedulerMap == null) {
return;
}
// 只清零本executor的统计信息数据
if (schedulerMap.containsKey(executorName)) {
ConcurrentHashMap<String, JobScheduler> jobSchedulerMap = schedulerMap.get(executorName);
if (jobSchedulerMap == null) {
return;
}
Iterator<Map.Entry<String, JobScheduler>> iterator = jobSchedulerMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, JobScheduler> next = iterator.next();
String jobName = next.getKey();
JobScheduler jobScheduler = next.getValue();
// 清零内存统计值
ProcessCountStatistics.resetSuccessFailureCount(executorName, jobName);
// 清零zk统计值
jobScheduler.getServerService().persistProcessFailureCount(0);
jobScheduler.getServerService().persistProcessSuccessCount(0);
LogUtils.info(log, jobName, "{} reset the job {}'s statistics data", executorName, jobName);
}
}
} catch (Throwable t) {
LogUtils.error(log, LogEvents.ExecutorEvent.COMMON, "process count reset error", t);
}
}
use of com.vip.saturn.job.basic.JobScheduler in project Saturn by vipshop.
the class SaturnExecutor method blockUntilJobCompletedIfNotTimeout.
/**
* block until all Job is completed if it is not timeout
*/
private void blockUntilJobCompletedIfNotTimeout() {
Map<String, JobScheduler> schdMap = JobRegistry.getSchedulerMap().get(executorName);
if (schdMap == null) {
return;
}
Set<Entry<String, JobScheduler>> entries = schdMap.entrySet();
if (CollectionUtils.isEmpty(entries)) {
return;
}
long startTime = System.currentTimeMillis();
boolean hasRunning = false;
do {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
LogUtils.error(log, LogEvents.ExecutorEvent.GRACEFUL_SHUTDOWN, e.getMessage(), e);
Thread.currentThread().interrupt();
}
for (Entry<String, JobScheduler> entry : entries) {
JobScheduler jobScheduler = entry.getValue();
if (jobScheduler.isAllowedShutdownGracefully()) {
if (jobScheduler.getJob().isRunning()) {
hasRunning = true;
break;
} else {
hasRunning = false;
}
}
// 其他作业(消息作业)不等,因为在接下来的forceStop是优雅强杀的,即等待一定时间让业务执行再强杀
}
} while (hasRunning && System.currentTimeMillis() - startTime < SystemEnvProperties.VIP_SATURN_SHUTDOWN_TIMEOUT * 1000);
LogUtils.info(log, LogEvents.ExecutorEvent.GRACEFUL_SHUTDOWN, "Shutdown phase [blockUntilJobCompletedIfNotTimeout] took {}ms", System.currentTimeMillis() - startTime);
}
Aggregations