use of org.apache.flink.shaded.curator5.org.apache.curator.framework.api.CreateBuilder in project incubator-atlas by apache.
the class SetupStepsTest method shouldCreateSetupInProgressNode.
@Test
public void shouldCreateSetupInProgressNode() throws Exception {
Set<SetupStep> steps = new LinkedHashSet<>();
SetupStep setupStep1 = mock(SetupStep.class);
steps.add(setupStep1);
when(configuration.getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
when(configuration.getString(HAConfiguration.HA_ZOOKEEPER_ACL)).thenReturn("digest:user:pwd");
List<ACL> aclList = Arrays.asList(new ACL(ZooDefs.Perms.ALL, new Id("digest", "user:pwd")));
setupServerIdSelectionMocks();
CreateBuilder createBuilder = setupSetupInProgressPathMocks(aclList).getLeft();
InterProcessMutex lock = mock(InterProcessMutex.class);
when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(lock);
SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration);
setupSteps.runSetup();
verify(createBuilder).withACL(aclList);
verify(createBuilder).forPath(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT + SetupSteps.SETUP_IN_PROGRESS_NODE, "id2".getBytes(Charsets.UTF_8));
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.api.CreateBuilder in project hadoop by apache.
the class CuratorService method zkMkPath.
/**
* Create a directory. It is not an error if it already exists
* @param path path to create
* @param mode mode for path
* @param createParents flag to trigger parent creation
* @param acls ACL for path
* @throws IOException any problem
*/
public boolean zkMkPath(String path, CreateMode mode, boolean createParents, List<ACL> acls) throws IOException {
checkServiceLive();
path = createFullPath(path);
if (acls == null || acls.isEmpty()) {
throw new NoPathPermissionsException(path, "Empty ACL list");
}
try {
RegistrySecurity.AclListInfo aclInfo = new RegistrySecurity.AclListInfo(acls);
if (LOG.isDebugEnabled()) {
LOG.debug("Creating path {} with mode {} and ACL {}", path, mode, aclInfo);
}
CreateBuilder createBuilder = curator.create();
createBuilder.withMode(mode).withACL(acls);
if (createParents) {
createBuilder.creatingParentsIfNeeded();
}
createBuilder.forPath(path);
} catch (KeeperException.NodeExistsException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("path already present: {}", path, e);
}
return false;
} catch (Exception e) {
throw operationFailure(path, "mkdir() ", e, acls);
}
return true;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.api.CreateBuilder in project pravega by pravega.
the class ZKStoreHelper method createZNodeIfNotExist.
CompletableFuture<Void> createZNodeIfNotExist(final String path, final byte[] data, final boolean createParent) {
final CompletableFuture<Void> result = new CompletableFuture<>();
try {
CreateBuilder createBuilder = client.create();
BackgroundCallback callback = callback(x -> result.complete(null), e -> {
if (e instanceof StoreException.DataExistsException) {
result.complete(null);
} else {
result.completeExceptionally(e);
}
}, path);
if (createParent) {
createBuilder.creatingParentsIfNeeded().inBackground(callback, executor).forPath(path, data);
} else {
createBuilder.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 atlas by apache.
the class SetupStepsTest method setupSetupInProgressPathMocks.
private Pair<CreateBuilder, DeleteBuilder> setupSetupInProgressPathMocks(List<ACL> acls, Stat stat) throws Exception {
when(curatorFactory.clientInstance()).thenReturn(client);
CreateBuilder createBuilder = mock(CreateBuilder.class);
when(createBuilder.withACL(acls)).thenReturn(createBuilder);
when(client.create()).thenReturn(createBuilder);
DeleteBuilder deleteBuilder = mock(DeleteBuilder.class);
when(client.delete()).thenReturn(deleteBuilder);
Pair<CreateBuilder, DeleteBuilder> pair = Pair.of(createBuilder, deleteBuilder);
ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
when(client.checkExists()).thenReturn(existsBuilder);
when(existsBuilder.forPath(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT + SetupSteps.SETUP_IN_PROGRESS_NODE)).thenReturn(stat);
return pair;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.api.CreateBuilder in project atlas by apache.
the class SetupStepsTest method shouldCreateSetupInProgressNode.
@Test
public void shouldCreateSetupInProgressNode() throws Exception {
Set<SetupStep> steps = new LinkedHashSet<>();
SetupStep setupStep1 = mock(SetupStep.class);
steps.add(setupStep1);
when(configuration.getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
when(configuration.getString(HAConfiguration.HA_ZOOKEEPER_ACL)).thenReturn("digest:user:pwd");
List<ACL> aclList = Arrays.asList(new ACL(ZooDefs.Perms.ALL, new Id("digest", "user:pwd")));
setupServerIdSelectionMocks();
CreateBuilder createBuilder = setupSetupInProgressPathMocks(aclList).getLeft();
InterProcessMutex lock = mock(InterProcessMutex.class);
when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(lock);
SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration);
setupSteps.runSetup();
verify(createBuilder).withACL(aclList);
verify(createBuilder).forPath(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT + SetupSteps.SETUP_IN_PROGRESS_NODE, "id2".getBytes(Charsets.UTF_8));
}
Aggregations