use of org.apache.flink.shaded.curator5.org.apache.curator.framework.api.CreateBuilder in project pravega by pravega.
the class ZKStoreHelper method createEphemeralZNode.
public CompletableFuture<Boolean> createEphemeralZNode(final String path, byte[] data) {
final CompletableFuture<Boolean> result = new CompletableFuture<>();
try {
CreateBuilder createBuilder = client.create();
BackgroundCallback callback = callback(x -> result.complete(true), e -> {
if (e instanceof StoreException.DataExistsException) {
result.complete(false);
} else {
result.completeExceptionally(e);
}
}, path);
createBuilder.creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).inBackground(callback, executor).forPath(path, data);
} catch (Exception e) {
result.completeExceptionally(StoreException.create(StoreException.Type.UNKNOWN, e, path));
}
return result;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.api.CreateBuilder in project pravega by pravega.
the class ZKStoreHelper method createZNode.
public CompletableFuture<Integer> createZNode(final String path, final byte[] data) {
final CompletableFuture<Integer> result = new CompletableFuture<>();
try {
CreateBuilder createBuilder = client.create();
BackgroundCallback callback = callback(x -> result.complete(x.getStat().getVersion()), e -> result.completeExceptionally(e), path);
createBuilder.creatingParentsIfNeeded().inBackground(callback, executor).forPath(path, data);
} catch (Exception e) {
result.completeExceptionally(StoreException.create(StoreException.Type.UNKNOWN, e, path));
}
return result;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.api.CreateBuilder in project pinpoint by naver.
the class CuratorZookeeperClient method createNode0.
private void createNode0(CreateNodeMessage message, boolean orSet) throws PinpointZookeeperException {
checkState();
try {
CuratorFramework curator = connectionManager.getCuratorFramework();
CreateBuilder createBuilder = curator.create();
if (message.isCreatingParentPathsIfNeeded()) {
createBuilder.creatingParentsIfNeeded();
}
if (orSet) {
createBuilder.orSetData();
}
String nodePath = message.getNodePath();
byte[] data = message.getData();
createBuilder.withMode(CreateMode.EPHEMERAL).forPath(nodePath, data);
} catch (Exception e) {
ZookeeperExceptionResolver.resolveAndThrow(e);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.api.CreateBuilder in project incubator-atlas by apache.
the class ActiveInstanceStateTest method testSharedPathIsCreatedIfNotExists.
@Test
public void testSharedPathIsCreatedIfNotExists() throws Exception {
when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX + "id1")).thenReturn(HOST_PORT);
when(configuration.getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
when(curatorFactory.clientInstance()).thenReturn(curatorFramework);
ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
when(curatorFramework.checkExists()).thenReturn(existsBuilder);
when(existsBuilder.forPath(getPath())).thenReturn(null);
CreateBuilder createBuilder = mock(CreateBuilder.class);
when(curatorFramework.create()).thenReturn(createBuilder);
when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(createBuilder);
when(createBuilder.withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE)).thenReturn(createBuilder);
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(curatorFramework.setData()).thenReturn(setDataBuilder);
ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
activeInstanceState.update("id1");
verify(createBuilder).forPath(getPath());
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.api.CreateBuilder in project incubator-atlas by apache.
the class ActiveInstanceStateTest method testSharedPathIsCreatedWithRightACLIfNotExists.
@Test
public void testSharedPathIsCreatedWithRightACLIfNotExists() throws Exception {
when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX + "id1")).thenReturn(HOST_PORT);
when(configuration.getString(HAConfiguration.HA_ZOOKEEPER_ACL)).thenReturn("sasl:myclient@EXAMPLE.COM");
when(configuration.getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
when(curatorFactory.clientInstance()).thenReturn(curatorFramework);
ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
when(curatorFramework.checkExists()).thenReturn(existsBuilder);
when(existsBuilder.forPath(getPath())).thenReturn(null);
CreateBuilder createBuilder = mock(CreateBuilder.class);
when(curatorFramework.create()).thenReturn(createBuilder);
when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(createBuilder);
ACL expectedAcl = new ACL(ZooDefs.Perms.ALL, new Id("sasl", "myclient@EXAMPLE.COM"));
when(createBuilder.withACL(Arrays.asList(new ACL[] { expectedAcl }))).thenReturn(createBuilder);
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(curatorFramework.setData()).thenReturn(setDataBuilder);
ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
activeInstanceState.update("id1");
verify(createBuilder).forPath(getPath());
}
Aggregations