Search in sources :

Example 6 with ZookeeperConfiguration

use of com.vip.saturn.job.reg.zookeeper.ZookeeperConfiguration 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());
    }
}
Also used : JobScheduler(com.vip.saturn.job.basic.JobScheduler) ZookeeperRegistryCenter(com.vip.saturn.job.reg.zookeeper.ZookeeperRegistryCenter) Calendar(java.util.Calendar) ZookeeperConfiguration(com.vip.saturn.job.reg.zookeeper.ZookeeperConfiguration) Test(org.junit.Test)

Example 7 with ZookeeperConfiguration

use of com.vip.saturn.job.reg.zookeeper.ZookeeperConfiguration 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();
    }
}
Also used : ZookeeperRegistryCenter(com.vip.saturn.job.reg.zookeeper.ZookeeperRegistryCenter) Stat(org.apache.zookeeper.data.Stat) ZookeeperConfiguration(com.vip.saturn.job.reg.zookeeper.ZookeeperConfiguration)

Example 8 with ZookeeperConfiguration

use of com.vip.saturn.job.reg.zookeeper.ZookeeperConfiguration 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;
    }
}
Also used : ZookeeperRegistryCenter(com.vip.saturn.job.reg.zookeeper.ZookeeperRegistryCenter) ZookeeperConfiguration(com.vip.saturn.job.reg.zookeeper.ZookeeperConfiguration) SaturnExecutorException(com.vip.saturn.job.exception.SaturnExecutorException) IOException(java.io.IOException)

Aggregations

ZookeeperConfiguration (com.vip.saturn.job.reg.zookeeper.ZookeeperConfiguration)8 ZookeeperRegistryCenter (com.vip.saturn.job.reg.zookeeper.ZookeeperRegistryCenter)8 JobScheduler (com.vip.saturn.job.basic.JobScheduler)4 Calendar (java.util.Calendar)4 Test (org.junit.Test)4 NestedZkUtils (com.vip.saturn.it.utils.NestedZkUtils)2 SaturnExecutorException (com.vip.saturn.job.exception.SaturnExecutorException)1 IOException (java.io.IOException)1 Stat (org.apache.zookeeper.data.Stat)1