Java Code Examples for org.apache.curator.framework.CuratorFramework#createContainers()

The following examples show how to use org.apache.curator.framework.CuratorFramework#createContainers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestFramework.java    From xian with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateContainersWithNamespace() throws Exception
{
    final String namespace = "container1";
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
    CuratorFramework client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).namespace(namespace).build();
    try
    {
        client.start();
        String path = "/path1/path2";
        client.createContainers(path);
        Assert.assertNotNull(client.checkExists().forPath(path));
        Assert.assertNotNull(client.getZookeeperClient().getZooKeeper().exists("/" + namespace + path, false));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
Example 2
Source File: TestFramework.java    From xian with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateContainersUsingNamespace() throws Exception
{
    final String namespace = "container2";
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
    CuratorFramework client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).build();
    try
    {
        client.start();
        CuratorFramework nsClient = client.usingNamespace(namespace);
        String path = "/path1/path2";
        nsClient.createContainers(path);
        Assert.assertNotNull(nsClient.checkExists().forPath(path));
        Assert.assertNotNull(nsClient.getZookeeperClient().getZooKeeper().exists("/" + namespace + path, false));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
Example 3
Source File: DefaultSlotManager.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
@Override
protected void doStart() throws Exception {

	CuratorFramework client = zkClient.get();
	client.createContainers(MetaZkConfig.getMetaServerSlotsPath());

	refresh();

	future = scheduled.scheduleWithFixedDelay(new Runnable() {
		@Override
		public void run() {
			try{
				refresh();
			}catch(Throwable th){
				logger.error("[run]", th);
			}
		}
	}, config.getSlotRefreshMilli(), config.getSlotRefreshMilli(), TimeUnit.MILLISECONDS);
}
 
Example 4
Source File: DefaultClusterArrangerTest.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitArrange() throws Exception{
	
	CuratorFramework client = getCurator();
	client.createContainers(MetaZkConfig.getMetaServerSlotsPath());
	
	List<String> children = client.getChildren().forPath(MetaZkConfig.getMetaServerSlotsPath());
	Assert.assertEquals(0, children.size());
	
	arrangeTaskStart(true);
	startRegistry();
	
	sleep(3000);
	children = client.getChildren().forPath(MetaZkConfig.getMetaServerSlotsPath());
	logger.info("[testInitArrange][getSlots]{}, {}", children.size(), children);
}
 
Example 5
Source File: TestFramework.java    From curator with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateContainersWithNamespace() throws Exception
{
    final String namespace = "container1";
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
    CuratorFramework client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).namespace(namespace).build();
    try
    {
        client.start();
        String path = "/path1/path2";
        client.createContainers(path);
        Assert.assertNotNull(client.checkExists().forPath(path));
        Assert.assertNotNull(client.getZookeeperClient().getZooKeeper().exists("/" + namespace + path, false));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
Example 6
Source File: TestFramework.java    From curator with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateContainersUsingNamespace() throws Exception
{
    final String namespace = "container2";
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
    CuratorFramework client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).build();
    try
    {
        client.start();
        CuratorFramework nsClient = client.usingNamespace(namespace);
        String path = "/path1/path2";
        nsClient.createContainers(path);
        Assert.assertNotNull(nsClient.checkExists().forPath(path));
        Assert.assertNotNull(nsClient.getZookeeperClient().getZooKeeper().exists("/" + namespace + path, false));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
Example 7
Source File: ServiceDiscoveryConfiguration.java    From Kafdrop with Apache License 2.0 5 votes vote down vote up
@Bean(initMethod = "start", destroyMethod = "close")
public ServiceDiscovery curatorServiceDiscovery(
   @Qualifier("serviceDiscovery") CuratorFramework curatorFramework,
   @Value("${curator.discovery.basePath:/homeadvisor/services}") String basePath) throws Exception
{
   final Class payloadClass = Object.class;
   curatorFramework.createContainers(basePath);
   return ServiceDiscoveryBuilder.builder(payloadClass)
      .client(curatorFramework)
      .basePath(basePath)
      .serializer(new JsonInstanceSerializer(payloadClass))
      .build();
}
 
Example 8
Source File: AbstractSlotMoveTask.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
protected void setSlotInfo(SlotInfo slotInfo) throws ShardingException {
	
	CuratorFramework client = zkClient.get();

	String path = getSlotZkPath();
	try {
		client.createContainers(path);
		client.setData().forPath(path, slotInfo.encode());
	} catch (Exception e) {
		throw new ShardingException(String.format("path:%s, slotInfo:%s", path, slotInfo), e);
	}
}
 
Example 9
Source File: TestPathChildren.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
private void createPath(CuratorFramework curatorFramework, String path, int start, int count) throws Exception {

        curatorFramework.createContainers(path);

        for (int i = 0; i < count; i++) {
            try {
                curatorFramework.create().withMode(CreateMode.EPHEMERAL).forPath(
                        String.format("%s/%d", path, start + i),
                        randomString(1 << 15).getBytes()
                );
            } catch (Exception e) {
                logger.error("[run]", e);
            }
        }
    }
 
Example 10
Source File: MetaServerPrepareResourcesAndStart.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
private void setupZkNodes(CuratorFramework client, DcMeta dcMeta) throws Exception {

		for(ClusterMeta clusterMeta : dcMeta.getClusters().values()){
			for(ShardMeta shardMeta : clusterMeta.getShards().values()){
				String path = MetaZkConfig.getKeeperLeaderLatchPath(clusterMeta.getId(), shardMeta.getId());
				client.createContainers(path);
			}
		}
		String metaPath = MetaZkConfig.getMetaRootPath();
		client.createContainers(metaPath);
	}