use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project druid by druid-io.
the class CuratorDruidCoordinatorTest method setUp.
@Before
public void setUp() throws Exception {
segmentsMetadataManager = EasyMock.createNiceMock(SegmentsMetadataManager.class);
dataSourcesSnapshot = EasyMock.createNiceMock(DataSourcesSnapshot.class);
coordinatorRuntimeParams = EasyMock.createNiceMock(DruidCoordinatorRuntimeParams.class);
metadataRuleManager = EasyMock.createNiceMock(MetadataRuleManager.class);
configManager = EasyMock.createNiceMock(JacksonConfigManager.class);
EasyMock.expect(configManager.watch(EasyMock.eq(CoordinatorDynamicConfig.CONFIG_KEY), EasyMock.anyObject(Class.class), EasyMock.anyObject())).andReturn(new AtomicReference<>(CoordinatorDynamicConfig.builder().build())).anyTimes();
EasyMock.expect(configManager.watch(EasyMock.eq(CoordinatorCompactionConfig.CONFIG_KEY), EasyMock.anyObject(Class.class), EasyMock.anyObject())).andReturn(new AtomicReference(CoordinatorCompactionConfig.empty())).anyTimes();
EasyMock.replay(configManager);
setupServerAndCurator();
curator.start();
curator.blockUntilConnected();
curator.create().creatingParentsIfNeeded().forPath(SEGPATH);
curator.create().creatingParentsIfNeeded().forPath(SOURCE_LOAD_PATH);
curator.create().creatingParentsIfNeeded().forPath(DESTINATION_LOAD_PATH);
objectMapper = new DefaultObjectMapper();
druidCoordinatorConfig = new TestDruidCoordinatorConfig(new Duration(COORDINATOR_START_DELAY), new Duration(COORDINATOR_PERIOD), null, null, null, new Duration(COORDINATOR_PERIOD), null, null, null, null, null, null, null, null, null, null, 10, new Duration("PT0s"));
sourceLoadQueueChildrenCache = new PathChildrenCache(curator, SOURCE_LOAD_PATH, true, true, Execs.singleThreaded("coordinator_test_path_children_cache_src-%d"));
destinationLoadQueueChildrenCache = new PathChildrenCache(curator, DESTINATION_LOAD_PATH, true, true, Execs.singleThreaded("coordinator_test_path_children_cache_dest-%d"));
sourceLoadQueuePeon = new CuratorLoadQueuePeon(curator, SOURCE_LOAD_PATH, objectMapper, peonExec, callbackExec, druidCoordinatorConfig);
destinationLoadQueuePeon = new CuratorLoadQueuePeon(curator, DESTINATION_LOAD_PATH, objectMapper, peonExec, callbackExec, druidCoordinatorConfig);
druidNode = new DruidNode("hey", "what", false, 1234, null, true, false);
loadManagementPeons = new ConcurrentHashMap<>();
scheduledExecutorFactory = (corePoolSize, nameFormat) -> Executors.newSingleThreadScheduledExecutor();
leaderAnnouncerLatch = new CountDownLatch(1);
leaderUnannouncerLatch = new CountDownLatch(1);
coordinator = new DruidCoordinator(druidCoordinatorConfig, new ZkPathsConfig() {
@Override
public String getBase() {
return "druid";
}
}, configManager, segmentsMetadataManager, baseView, metadataRuleManager, () -> curator, new NoopServiceEmitter(), scheduledExecutorFactory, null, null, new NoopServiceAnnouncer() {
@Override
public void announce(DruidNode node) {
// count down when this coordinator becomes the leader
leaderAnnouncerLatch.countDown();
}
@Override
public void unannounce(DruidNode node) {
leaderUnannouncerLatch.countDown();
}
}, druidNode, loadManagementPeons, null, null, new CoordinatorCustomDutyGroups(ImmutableSet.of()), new CostBalancerStrategyFactory(), EasyMock.createNiceMock(LookupCoordinatorManager.class), new TestDruidLeaderSelector(), null, ZkEnablementConfig.ENABLED);
}
use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project flink by apache.
the class ZooKeeperJobGraphsStoreITCase method createZooKeeperJobGraphStore.
@Nonnull
private JobGraphStore createZooKeeperJobGraphStore(String fullPath) throws Exception {
final CuratorFramework client = ZooKeeper.getClient();
// Ensure that the job graphs path exists
client.newNamespaceAwareEnsurePath(fullPath).ensure(client.getZookeeperClient());
// All operations will have the path as root
CuratorFramework facade = client.usingNamespace(client.getNamespace() + fullPath);
final ZooKeeperStateHandleStore<JobGraph> zooKeeperStateHandleStore = new ZooKeeperStateHandleStore<>(facade, localStateStorage);
return new DefaultJobGraphStore<>(zooKeeperStateHandleStore, new ZooKeeperJobGraphStoreWatcher(new PathChildrenCache(facade, "/", false)), ZooKeeperJobGraphStoreUtil.INSTANCE);
}
use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project Mycat-Server by MyCATApache.
the class ZKUtils method addChildPathCache.
public static void addChildPathCache(String path, PathChildrenCacheListener listener) {
NameableExecutor businessExecutor = MycatServer.getInstance().getBusinessExecutor();
ExecutorService executor = businessExecutor == null ? Executors.newFixedThreadPool(5) : businessExecutor;
try {
/**
* 监听子节点的变化情况
*/
final PathChildrenCache childrenCache = new PathChildrenCache(getConnection(), path, true);
childrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
childrenCache.getListenable().addListener(listener, executor);
watchMap.put(path, childrenCache);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project chassis by Kixeye.
the class DynamicZookeeperConfigurationSource method initializePathChildrenCache.
private void initializePathChildrenCache() {
pathChildrenCache = new PathChildrenCache(curatorFramework, configPathRoot, true);
pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
LOGGER.debug("Got event {}", event);
if (event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED && event.getData().getPath().equals(instanceConfigPath)) {
// do stuff
LOGGER.info("Detected creation of node {}. Initializing zookeeper configuration source...", instanceConfigPath);
try {
initializeZookeeperConfigurationSource();
} catch (BootstrapException e) {
LOGGER.error("Failed to initialized zookeeper configuration source for path " + instanceConfigPath, e);
throw e;
}
return;
}
if (event.getType() == PathChildrenCacheEvent.Type.CHILD_REMOVED && event.getData().getPath().equals(instanceConfigPath)) {
if (running) {
LOGGER.info("Detected deletion of node {}, destroying zookeeper configuration source...", instanceConfigPath);
destroyZookeeperCofigurationSource();
return;
}
LOGGER.warn("Detected deletion of node {}, but zookeeper configuration source not currently running. This should not happen. Ignoring event...", instanceConfigPath);
return;
}
LOGGER.debug("Ignoring event {}", event);
}
});
try {
pathChildrenCache.start(StartMode.BUILD_INITIAL_CACHE);
} catch (Exception e) {
throw new BootstrapException("Failed to initialize zookeeper configuration path cache" + configPathRoot, e);
}
}
use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project hive by apache.
the class KillQueryZookeeperManager method start.
@Override
public synchronized void start() {
super.start();
if (zooKeeperClient == null) {
throw new ServiceException("Failed start zookeeperClient in KillQueryZookeeperManager");
}
try {
ZookeeperUtils.setupZookeeperAuth(this.getHiveConf(), SASL_LOGIN_CONTEXT_NAME, zkPrincipal, zkKeytab);
zooKeeperClient.start();
try {
zooKeeperClient.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath("/" + zkNameSpace);
if (ZookeeperUtils.isKerberosEnabled(conf)) {
zooKeeperClient.setACL().withACL(createSecureAcls()).forPath("/" + zkNameSpace);
}
LOG.info("Created the root namespace: " + zkNameSpace + " on ZooKeeper");
} catch (KeeperException e) {
if (e.code() != KeeperException.Code.NODEEXISTS) {
LOG.error("Unable to create namespace: " + zkNameSpace + " on ZooKeeper", e);
throw e;
}
}
// Create a path cache and start to listen for every kill query request from other servers.
killQueryListener = new PathChildrenCache(zooKeeperClient, "/" + zkNameSpace, false);
killQueryListener.start(PathChildrenCache.StartMode.NORMAL);
startListeningForQueries();
// Init closeable utils in case register is not called (see HIVE-13322)
CloseableUtils.class.getName();
} catch (Exception e) {
throw new RuntimeException("Failed start zookeeperClient in KillQueryZookeeperManager", e);
}
LOG.info("KillQueryZookeeperManager service started.");
}
Aggregations