Search in sources :

Example 1 with NoPathPermissionsException

use of org.apache.hadoop.registry.client.exceptions.NoPathPermissionsException in project hadoop by apache.

the class CuratorService method operationFailure.

/**
   * Create an IOE when an operation fails
   * @param path path of operation
   * @param operation operation attempted
   * @param exception caught the exception caught
   * @return an IOE to throw that contains the path and operation details.
   */
protected IOException operationFailure(String path, String operation, Exception exception, List<ACL> acls) {
    IOException ioe;
    String aclList = "[" + RegistrySecurity.aclsToString(acls) + "]";
    if (exception instanceof KeeperException.NoNodeException) {
        ioe = new PathNotFoundException(path);
    } else if (exception instanceof KeeperException.NodeExistsException) {
        ioe = new FileAlreadyExistsException(path);
    } else if (exception instanceof KeeperException.NoAuthException) {
        ioe = new NoPathPermissionsException(path, "Not authorized to access path; ACLs: " + aclList);
    } else if (exception instanceof KeeperException.NotEmptyException) {
        ioe = new PathIsNotEmptyDirectoryException(path);
    } else if (exception instanceof KeeperException.AuthFailedException) {
        ioe = new AuthenticationFailedException(path, "Authentication Failed: " + exception + "; " + securityConnectionDiagnostics, exception);
    } else if (exception instanceof KeeperException.NoChildrenForEphemeralsException) {
        ioe = new NoChildrenForEphemeralsException(path, "Cannot create a path under an ephemeral node: " + exception, exception);
    } else if (exception instanceof KeeperException.InvalidACLException) {
        // this is a security exception of a kind
        // include the ACLs to help the diagnostics
        StringBuilder builder = new StringBuilder();
        builder.append("Path access failure ").append(aclList);
        builder.append(" ");
        builder.append(securityConnectionDiagnostics);
        ioe = new NoPathPermissionsException(path, builder.toString());
    } else {
        ioe = new RegistryIOException(path, "Failure of " + operation + " on " + path + ": " + exception.toString(), exception);
    }
    if (ioe.getCause() == null) {
        ioe.initCause(exception);
    }
    return ioe;
}
Also used : NoPathPermissionsException(org.apache.hadoop.registry.client.exceptions.NoPathPermissionsException) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) AuthenticationFailedException(org.apache.hadoop.registry.client.exceptions.AuthenticationFailedException) PathIsNotEmptyDirectoryException(org.apache.hadoop.fs.PathIsNotEmptyDirectoryException) IOException(java.io.IOException) RegistryIOException(org.apache.hadoop.registry.client.exceptions.RegistryIOException) NoChildrenForEphemeralsException(org.apache.hadoop.registry.client.exceptions.NoChildrenForEphemeralsException) PathNotFoundException(org.apache.hadoop.fs.PathNotFoundException) RegistryIOException(org.apache.hadoop.registry.client.exceptions.RegistryIOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with NoPathPermissionsException

use of org.apache.hadoop.registry.client.exceptions.NoPathPermissionsException 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;
}
Also used : NoPathPermissionsException(org.apache.hadoop.registry.client.exceptions.NoPathPermissionsException) CreateBuilder(org.apache.curator.framework.api.CreateBuilder) 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)

Aggregations

IOException (java.io.IOException)2 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)2 PathIsNotEmptyDirectoryException (org.apache.hadoop.fs.PathIsNotEmptyDirectoryException)2 PathNotFoundException (org.apache.hadoop.fs.PathNotFoundException)2 AuthenticationFailedException (org.apache.hadoop.registry.client.exceptions.AuthenticationFailedException)2 NoChildrenForEphemeralsException (org.apache.hadoop.registry.client.exceptions.NoChildrenForEphemeralsException)2 NoPathPermissionsException (org.apache.hadoop.registry.client.exceptions.NoPathPermissionsException)2 RegistryIOException (org.apache.hadoop.registry.client.exceptions.RegistryIOException)2 KeeperException (org.apache.zookeeper.KeeperException)2 CreateBuilder (org.apache.curator.framework.api.CreateBuilder)1 ServiceStateException (org.apache.hadoop.service.ServiceStateException)1