use of org.apache.curator.framework.api.DeleteBuilder in project heron by twitter.
the class CuratorStateManager method deleteNode.
@Override
protected ListenableFuture<Boolean> deleteNode(String path, boolean deleteChildrenIfNecessary) {
final SettableFuture<Boolean> result = SettableFuture.create();
try {
DeleteBuilder deleteBuilder = client.delete();
if (deleteChildrenIfNecessary) {
deleteBuilder = (DeleteBuilder) deleteBuilder.deletingChildrenIfNeeded();
}
deleteBuilder.withVersion(-1).forPath(path);
LOG.info("Deleted node for path: " + path);
result.set(true);
} catch (KeeperException e) {
if (KeeperException.Code.NONODE.equals(e.code())) {
result.set(true);
} else {
result.setException(new RuntimeException("Could not deleteNode", e));
}
// Suppress it since forPath() throws Exception
// SUPPRESS CHECKSTYLE IllegalCatch
} catch (Exception e) {
result.setException(new RuntimeException("Could not deleteNode", e));
}
return result;
}
use of org.apache.curator.framework.api.DeleteBuilder in project hadoop by apache.
the class CuratorService method zkDelete.
/**
* Delete a directory/directory tree.
* It is not an error to delete a path that does not exist
* @param path path of operation
* @param recursive flag to trigger recursive deletion
* @param backgroundCallback callback; this being set converts the operation
* into an async/background operation.
* task
* @throws IOException on problems other than no-such-path
*/
public void zkDelete(String path, boolean recursive, BackgroundCallback backgroundCallback) throws IOException {
checkServiceLive();
String fullpath = createFullPath(path);
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Deleting {}", fullpath);
}
DeleteBuilder delete = curator.delete();
if (recursive) {
delete.deletingChildrenIfNeeded();
}
if (backgroundCallback != null) {
delete.inBackground(backgroundCallback);
}
delete.forPath(fullpath);
} catch (KeeperException.NoNodeException e) {
// not an error
} catch (Exception e) {
throw operationFailure(fullpath, "delete()", e);
}
}
use of org.apache.curator.framework.api.DeleteBuilder in project incubator-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.curator.framework.api.DeleteBuilder in project incubator-atlas by apache.
the class SetupStepsTest method shouldDeleteSetupInProgressNodeAfterCompletion.
@Test
public void shouldDeleteSetupInProgressNodeAfterCompletion() 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();
DeleteBuilder deleteBuilder = setupSetupInProgressPathMocks(aclList).getRight();
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(deleteBuilder).forPath(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT + SetupSteps.SETUP_IN_PROGRESS_NODE);
}
use of org.apache.curator.framework.api.DeleteBuilder in project metron by apache.
the class GlobalConfigServiceImplTest method deleteShouldProperlyCatchNonNoNodeExceptionAndThrowRestException.
@Test
public void deleteShouldProperlyCatchNonNoNodeExceptionAndThrowRestException() throws Exception {
exception.expect(RestException.class);
DeleteBuilder builder = mock(DeleteBuilder.class);
when(curatorFramework.delete()).thenReturn(builder);
when(builder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot())).thenThrow(Exception.class);
assertFalse(globalConfigService.delete());
}
Aggregations