Search in sources :

Example 11 with DeleteBuilder

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;
}
Also used : DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder) KeeperException(org.apache.zookeeper.KeeperException) KeeperException(org.apache.zookeeper.KeeperException) ExecutionException(java.util.concurrent.ExecutionException)

Example 12 with DeleteBuilder

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);
    }
}
Also used : DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder) KeeperException(org.apache.zookeeper.KeeperException) NoChildrenForEphemeralsException(org.apache.hadoop.registry.client.exceptions.NoChildrenForEphemeralsException) AuthenticationFailedException(org.apache.hadoop.registry.client.exceptions.AuthenticationFailedException) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) KeeperException(org.apache.zookeeper.KeeperException) PathNotFoundException(org.apache.hadoop.fs.PathNotFoundException) IOException(java.io.IOException) RegistryIOException(org.apache.hadoop.registry.client.exceptions.RegistryIOException) PathIsNotEmptyDirectoryException(org.apache.hadoop.fs.PathIsNotEmptyDirectoryException) ServiceStateException(org.apache.hadoop.service.ServiceStateException) NoPathPermissionsException(org.apache.hadoop.registry.client.exceptions.NoPathPermissionsException)

Example 13 with DeleteBuilder

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;
}
Also used : CreateBuilder(org.apache.curator.framework.api.CreateBuilder) ExistsBuilder(org.apache.curator.framework.api.ExistsBuilder) DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder)

Example 14 with DeleteBuilder

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ACL(org.apache.zookeeper.data.ACL) SetupStep(org.apache.atlas.setup.SetupStep) Id(org.apache.zookeeper.data.Id) DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder) InterProcessMutex(org.apache.curator.framework.recipes.locks.InterProcessMutex) Test(org.testng.annotations.Test)

Example 15 with DeleteBuilder

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());
}
Also used : DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder) Test(org.junit.Test)

Aggregations

DeleteBuilder (org.apache.curator.framework.api.DeleteBuilder)17 Test (org.junit.Test)13 KeeperException (org.apache.zookeeper.KeeperException)6 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 SetupStep (org.apache.atlas.setup.SetupStep)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 BackgroundPathable (org.apache.curator.framework.api.BackgroundPathable)1 CreateBuilder (org.apache.curator.framework.api.CreateBuilder)1 ExistsBuilder (org.apache.curator.framework.api.ExistsBuilder)1 InterProcessMutex (org.apache.curator.framework.recipes.locks.InterProcessMutex)1 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)1 PathIsNotEmptyDirectoryException (org.apache.hadoop.fs.PathIsNotEmptyDirectoryException)1 PathNotFoundException (org.apache.hadoop.fs.PathNotFoundException)1 AuthenticationFailedException (org.apache.hadoop.registry.client.exceptions.AuthenticationFailedException)1 NoChildrenForEphemeralsException (org.apache.hadoop.registry.client.exceptions.NoChildrenForEphemeralsException)1 NoPathPermissionsException (org.apache.hadoop.registry.client.exceptions.NoPathPermissionsException)1 RegistryIOException (org.apache.hadoop.registry.client.exceptions.RegistryIOException)1