use of com.vip.saturn.job.reg.zookeeper.ZookeeperRegistryCenter 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.reg.zookeeper.ZookeeperRegistryCenter in project Saturn by vipshop.
the class JobNodeStorage method deleteJobNode.
/**
* 删除ZK结点
*/
public void deleteJobNode() {
ZookeeperConfiguration zkConfig = ((ZookeeperRegistryCenter) coordinatorRegistryCenter).getZkConfig();
ZookeeperRegistryCenter newZk = new ZookeeperRegistryCenter(zkConfig);
try {
// maybe throw RuntimeException
newZk.init();
newZk.remove(ServerNode.getServerNode(jobName, executorName));
String fullPath = JobNodePath.getJobNameFullPath(jobConfiguration.getJobName());
Stat stat = newZk.getStat(fullPath);
if (stat == null) {
return;
}
long ctime = stat.getCtime();
for (int i = 0; i < MAX_DELETE_RETRY_TIMES; i++) {
stat = newZk.getStat(fullPath);
if (stat == null) {
return;
}
if (stat.getCtime() != ctime) {
LogUtils.info(log, jobName, "the job node ctime has changed, give up to delete");
return;
}
List<String> servers = newZk.getChildrenKeys(ServerNode.getServerRoot(jobName));
if (servers == null || servers.isEmpty()) {
if (tryToRemoveNode(newZk, fullPath)) {
return;
}
}
BlockUtils.waitingShortTime();
}
} catch (Throwable t) {
LogUtils.error(log, jobName, "delete job node error", t);
} finally {
newZk.close();
}
}
use of com.vip.saturn.job.reg.zookeeper.ZookeeperRegistryCenter in project Saturn by vipshop.
the class SaturnExecutor method initRegistryCenter.
private void initRegistryCenter(String serverLists) throws Exception {
try {
// 验证namespace是否存在
saturnExecutorExtension.validateNamespaceExisting(serverLists);
// 初始化注册中心
LogUtils.info(log, LogEvents.ExecutorEvent.INIT, "start to init reg center");
ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(serverLists, namespace, 1000, 3000);
regCenter = new ZookeeperRegistryCenter(zkConfig);
regCenter.init();
connectionLostListener = new EnhancedConnectionStateListener(executorName) {
@Override
public void onLost() {
needRestart = true;
raiseAlarm();
}
};
regCenter.addConnectionStateListener(connectionLostListener);
// 创建SaturnExecutorService
saturnExecutorService = new SaturnExecutorService(regCenter, executorName, saturnExecutorExtension);
saturnExecutorService.setJobClassLoader(jobClassLoader);
saturnExecutorService.setExecutorClassLoader(executorClassLoader);
saturnExecutorService.setSaturnApplication(saturnApplication);
StartCheckUtil.setOk(StartCheckItem.ZK);
} catch (Exception e) {
StartCheckUtil.setError(StartCheckItem.ZK);
throw e;
}
}
Aggregations