Search in sources :

Example 1 with PathNotFoundException

use of org.apache.hadoop.fs.PathNotFoundException in project hadoop by apache.

the class RegistryUtils method statChildren.

/**
   * List children of a directory and retrieve their
   * {@link RegistryPathStatus} values.
   * <p>
   * This is not an atomic operation; A child may be deleted
   * during the iteration through the child entries. If this happens,
   * the <code>PathNotFoundException</code> is caught and that child
   * entry ommitted.
   *
   * @param path path
   * @return a possibly empty map of child entries listed by
   * their short name.
   * @throws PathNotFoundException path is not in the registry.
   * @throws InvalidPathnameException the path is invalid.
   * @throws IOException Any other IO Exception
   */
public static Map<String, RegistryPathStatus> statChildren(RegistryOperations registryOperations, String path) throws PathNotFoundException, InvalidPathnameException, IOException {
    List<String> childNames = registryOperations.list(path);
    Map<String, RegistryPathStatus> results = new HashMap<String, RegistryPathStatus>();
    for (String childName : childNames) {
        String child = join(path, childName);
        try {
            RegistryPathStatus stat = registryOperations.stat(child);
            results.put(childName, stat);
        } catch (PathNotFoundException pnfe) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("stat failed on {}: moved? {}", child, pnfe, pnfe);
            }
        // and continue
        }
    }
    return results;
}
Also used : RegistryPathStatus(org.apache.hadoop.registry.client.types.RegistryPathStatus) HashMap(java.util.HashMap) PathNotFoundException(org.apache.hadoop.fs.PathNotFoundException)

Example 2 with PathNotFoundException

use of org.apache.hadoop.fs.PathNotFoundException 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 3 with PathNotFoundException

use of org.apache.hadoop.fs.PathNotFoundException in project hadoop by apache.

the class CuratorService method zkStat.

/**
   * Stat the file
   * @param path path of operation
   * @return a curator stat entry
   * @throws IOException on a failure
   * @throws PathNotFoundException if the path was not found
   */
public Stat zkStat(String path) throws IOException {
    checkServiceLive();
    String fullpath = createFullPath(path);
    Stat stat;
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Stat {}", fullpath);
        }
        stat = curator.checkExists().forPath(fullpath);
    } catch (Exception e) {
        throw operationFailure(fullpath, "read()", e);
    }
    if (stat == null) {
        throw new PathNotFoundException(path);
    }
    return stat;
}
Also used : Stat(org.apache.zookeeper.data.Stat) PathNotFoundException(org.apache.hadoop.fs.PathNotFoundException) 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 4 with PathNotFoundException

use of org.apache.hadoop.fs.PathNotFoundException in project hadoop by apache.

the class RegistryAdminService method purge.

/**
   * Recursive operation to purge all matching records under a base path.
   * <ol>
   *   <li>Uses a depth first search</li>
   *   <li>A match is on ID and persistence policy, or, if policy==-1, any match</li>
   *   <li>If a record matches then it is deleted without any child searches</li>
   *   <li>Deletions will be asynchronous if a callback is provided</li>
   * </ol>
   *
   * The code is designed to be robust against parallel deletions taking place;
   * in such a case it will stop attempting that part of the tree. This
   * avoid the situation of more than 1 purge happening in parallel and
   * one of the purge operations deleteing the node tree above the other.
   * @param path base path
   * @param selector selector for the purge policy
   * @param purgePolicy what to do if there is a matching record with children
   * @param callback optional curator callback
   * @return the number of delete operations perfomed. As deletes may be for
   * everything under a path, this may be less than the number of records
   * actually deleted
   * @throws IOException problems
   * @throws PathIsNotEmptyDirectoryException if an entry cannot be deleted
   * as it has children and the purge policy is FailOnChildren
   */
@VisibleForTesting
public int purge(String path, NodeSelector selector, PurgePolicy purgePolicy, BackgroundCallback callback) throws IOException {
    boolean toDelete = false;
    // look at self to see if it has a service record
    Map<String, RegistryPathStatus> childEntries;
    Collection<RegistryPathStatus> entries;
    try {
        // list this path's children
        childEntries = RegistryUtils.statChildren(this, path);
        entries = childEntries.values();
    } catch (PathNotFoundException e) {
        // exit
        return 0;
    }
    try {
        RegistryPathStatus registryPathStatus = stat(path);
        ServiceRecord serviceRecord = resolve(path);
        // there is now an entry here.
        toDelete = selector.shouldSelect(path, registryPathStatus, serviceRecord);
    } catch (EOFException ignored) {
    // ignore
    } catch (InvalidRecordException ignored) {
    // ignore
    } catch (NoRecordException ignored) {
    // ignore
    } catch (PathNotFoundException e) {
        // exit
        return 0;
    }
    if (toDelete && !entries.isEmpty()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Match on record @ {} with children ", path);
        }
        // there's children
        switch(purgePolicy) {
            case SkipOnChildren:
                // don't do the deletion... continue to next record
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Skipping deletion");
                }
                toDelete = false;
                break;
            case PurgeAll:
                // mark for deletion
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Scheduling for deletion with children");
                }
                toDelete = true;
                entries = new ArrayList<RegistryPathStatus>(0);
                break;
            case FailOnChildren:
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Failing deletion operation");
                }
                throw new PathIsNotEmptyDirectoryException(path);
        }
    }
    int deleteOps = 0;
    if (toDelete) {
        try {
            zkDelete(path, true, callback);
        } catch (PathNotFoundException e) {
            // this is a no-op, and all children can be skipped
            return deleteOps;
        }
        deleteOps++;
    }
    // now go through the children
    for (RegistryPathStatus status : entries) {
        String childname = status.path;
        String childpath = RegistryPathUtils.join(path, childname);
        deleteOps += purge(childpath, selector, purgePolicy, callback);
    }
    return deleteOps;
}
Also used : PathIsNotEmptyDirectoryException(org.apache.hadoop.fs.PathIsNotEmptyDirectoryException) ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord) RegistryPathStatus(org.apache.hadoop.registry.client.types.RegistryPathStatus) EOFException(java.io.EOFException) NoRecordException(org.apache.hadoop.registry.client.exceptions.NoRecordException) PathNotFoundException(org.apache.hadoop.fs.PathNotFoundException) InvalidRecordException(org.apache.hadoop.registry.client.exceptions.InvalidRecordException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with PathNotFoundException

use of org.apache.hadoop.fs.PathNotFoundException in project hadoop by apache.

the class TestRegistryOperations method testMkdirNoParent.

@Test
public void testMkdirNoParent() throws Throwable {
    String path = ENTRY_PATH + "/missing";
    try {
        operations.mknode(path, false);
        RegistryPathStatus stat = operations.stat(path);
        fail("Got a status " + stat);
    } catch (PathNotFoundException expected) {
    // expected
    }
}
Also used : RegistryPathStatus(org.apache.hadoop.registry.client.types.RegistryPathStatus) PathNotFoundException(org.apache.hadoop.fs.PathNotFoundException) Test(org.junit.Test) AbstractRegistryTest(org.apache.hadoop.registry.AbstractRegistryTest)

Aggregations

PathNotFoundException (org.apache.hadoop.fs.PathNotFoundException)6 RegistryPathStatus (org.apache.hadoop.registry.client.types.RegistryPathStatus)4 PathIsNotEmptyDirectoryException (org.apache.hadoop.fs.PathIsNotEmptyDirectoryException)3 IOException (java.io.IOException)2 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)2 AbstractRegistryTest (org.apache.hadoop.registry.AbstractRegistryTest)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 ServiceRecord (org.apache.hadoop.registry.client.types.ServiceRecord)2 KeeperException (org.apache.zookeeper.KeeperException)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 EOFException (java.io.EOFException)1 HashMap (java.util.HashMap)1 InvalidRecordException (org.apache.hadoop.registry.client.exceptions.InvalidRecordException)1 NoRecordException (org.apache.hadoop.registry.client.exceptions.NoRecordException)1 ServiceStateException (org.apache.hadoop.service.ServiceStateException)1 Stat (org.apache.zookeeper.data.Stat)1