类org.apache.hadoop.fs.PathIsNotEmptyDirectoryException源码实例Demo

下面列出了怎么用org.apache.hadoop.fs.PathIsNotEmptyDirectoryException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hadoop   文件: TestRegistryRMOperations.java

@Test
public void testChildDeletion() throws Throwable {
  ServiceRecord app = createRecord("app1",
      PersistencePolicies.APPLICATION, "app",
      null);
  ServiceRecord container = createRecord("container1",
      PersistencePolicies.CONTAINER, "container",
      null);

  operations.bind("/app", app, BindFlags.OVERWRITE);
  operations.bind("/app/container", container, BindFlags.OVERWRITE);

  try {
    int p = purge("/",
        "app1",
        PersistencePolicies.APPLICATION,
        RegistryAdminService.PurgePolicy.FailOnChildren);
    fail("expected a failure, got a purge count of " + p);
  } catch (PathIsNotEmptyDirectoryException expected) {
    // expected
  }

}
 
源代码2 项目: hadoop   文件: FSDirDeleteOp.java

/**
 * Remove a file/directory from the namespace.
 * <p>
 * For large directories, deletion is incremental. The blocks under
 * the directory are collected and deleted a small number at a time holding
 * the {@link FSNamesystem} lock.
 * <p>
 * For small directory or file the deletion is done in one shot.
 *
 */
static BlocksMapUpdateInfo delete(
    FSNamesystem fsn, String src, boolean recursive, boolean logRetryCache)
    throws IOException {
  FSDirectory fsd = fsn.getFSDirectory();
  FSPermissionChecker pc = fsd.getPermissionChecker();
  byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);

  src = fsd.resolvePath(pc, src, pathComponents);
  final INodesInPath iip = fsd.getINodesInPath4Write(src, false);
  if (!recursive && fsd.isNonEmptyDirectory(iip)) {
    throw new PathIsNotEmptyDirectoryException(src + " is non empty");
  }
  if (fsd.isPermissionEnabled()) {
    fsd.checkPermission(pc, iip, false, null, FsAction.WRITE, null,
                        FsAction.ALL, true);
  }

  return deleteInternal(fsn, src, iip, logRetryCache);
}
 
源代码3 项目: big-c   文件: TestRegistryRMOperations.java

@Test
public void testChildDeletion() throws Throwable {
  ServiceRecord app = createRecord("app1",
      PersistencePolicies.APPLICATION, "app",
      null);
  ServiceRecord container = createRecord("container1",
      PersistencePolicies.CONTAINER, "container",
      null);

  operations.bind("/app", app, BindFlags.OVERWRITE);
  operations.bind("/app/container", container, BindFlags.OVERWRITE);

  try {
    int p = purge("/",
        "app1",
        PersistencePolicies.APPLICATION,
        RegistryAdminService.PurgePolicy.FailOnChildren);
    fail("expected a failure, got a purge count of " + p);
  } catch (PathIsNotEmptyDirectoryException expected) {
    // expected
  }

}
 
源代码4 项目: big-c   文件: FSDirDeleteOp.java

/**
 * Remove a file/directory from the namespace.
 * <p>
 * For large directories, deletion is incremental. The blocks under
 * the directory are collected and deleted a small number at a time holding
 * the {@link FSNamesystem} lock.
 * <p>
 * For small directory or file the deletion is done in one shot.
 *
 */
static BlocksMapUpdateInfo delete(
    FSNamesystem fsn, String src, boolean recursive, boolean logRetryCache)
    throws IOException {
  FSDirectory fsd = fsn.getFSDirectory();
  FSPermissionChecker pc = fsd.getPermissionChecker();
  byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);

  src = fsd.resolvePath(pc, src, pathComponents);
  final INodesInPath iip = fsd.getINodesInPath4Write(src, false);
  if (!recursive && fsd.isNonEmptyDirectory(iip)) {
    throw new PathIsNotEmptyDirectoryException(src + " is non empty");
  }
  if (fsd.isPermissionEnabled()) {
    fsd.checkPermission(pc, iip, false, null, FsAction.WRITE, null,
                        FsAction.ALL, true);
  }

  return deleteInternal(fsn, src, iip, logRetryCache);
}
 

/** @throws Exception If failed. */
@Test
public void testDeleteFailsIfNonRecursive() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    Path someDir3 = new Path(fsHome, "/someDir1/someDir2/someDir3");

    FSDataOutputStream os = fs.create(someDir3, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    final Path someDir2 = new Path(fsHome, "/someDir1/someDir2");

    GridTestUtils.assertThrows(log, new Callable<Object>() {
        @Override public Object call() throws Exception {
            fs.delete(someDir2, false);

            return null;
        }
    }, PathIsNotEmptyDirectoryException.class, null);

    assertPathExists(fs, someDir2);
    assertPathExists(fs, someDir3);
}
 
源代码6 项目: hbase   文件: CleanerChore.java

/**
 * Perform a delete on a specified type.
 * @param deletion a delete
 * @param type possible values are 'files', 'subdirs', 'dirs'
 * @return true if it deleted successfully, false otherwise
 */
private boolean deleteAction(Action<Boolean> deletion, String type, Path dir) {
  boolean deleted;
  try {
    LOG.trace("Start deleting {} under {}", type, dir);
    deleted = deletion.act();
  } catch (PathIsNotEmptyDirectoryException exception) {
    // N.B. HDFS throws this exception when we try to delete a non-empty directory, but
    // LocalFileSystem throws a bare IOException. So some test code will get the verbose
    // message below.
    LOG.debug("Couldn't delete '{}' yet because it isn't empty w/exception.", dir, exception);
    deleted = false;
  } catch (IOException ioe) {
    LOG.info("Could not delete {} under {}. might be transient; we'll retry. if it keeps "
        + "happening, use following exception when asking on mailing list.",
      type, dir, ioe);
    deleted = false;
  } catch (Exception e) {
    LOG.info("unexpected exception: ", e);
    deleted = false;
  }
  LOG.trace("Finish deleting {} under {}, deleted=", type, dir, deleted);
  return deleted;
}
 

/**
 * Helper function. Delete a path non-recursively and expect failure.
 * @param f Path to delete.
 * @throws IOException
 */
private void deleteNonRecursivelyAndFail(Path f) throws IOException {
  try {
    fs.delete(f, false);
    Assert.fail("Should have thrown PathIsNotEmptyDirectoryException!");
  } catch (PathIsNotEmptyDirectoryException ignored) {
  }
}
 

DeleteIterator(Path f, boolean recursive)
    throws IOException {
  super(f);
  this.recursive = recursive;
  if (getStatus().isDirectory()
      && !this.recursive
      && listStatus(f).length != 0) {
    throw new PathIsNotEmptyDirectoryException(f.toString());
  }
  // Initialize bucket here to reduce number of RPC calls
  OFSPath ofsPath = new OFSPath(f);
  // TODO: Refactor later.
  adapterImpl = (BasicRootedOzoneClientAdapterImpl) adapter;
  this.bucket = adapterImpl.getBucket(ofsPath, false);
}
 

DeleteIterator(Path f, boolean recursive)
    throws IOException {
  super(f);
  this.recursive = recursive;
  if (getStatus().isDirectory()
      && !this.recursive
      && listStatus(f).length != 0) {
    throw new PathIsNotEmptyDirectoryException(f.toString());
  }
}
 
源代码10 项目: hadoop   文件: TestRegistryOperations.java

@Test
public void testDeleteNonEmpty() throws Throwable {
  putExampleServiceEntry(ENTRY_PATH, 0);
  try {
    operations.delete(PARENT_PATH, false);
    fail("Expected a failure");
  } catch (PathIsNotEmptyDirectoryException expected) {
    // expected; ignore
  }
  operations.delete(PARENT_PATH, true);
}
 
源代码11 项目: hadoop   文件: TestCuratorService.java

@Test
public void testRMNonRf() throws Throwable {
  mkPath("/rm", CreateMode.PERSISTENT);
  mkPath("/rm/child", CreateMode.PERSISTENT);
  try {
    curatorService.zkDelete("/rm", false, null);
    fail("expected a failure");
  } catch (PathIsNotEmptyDirectoryException expected) {

  }
}
 
源代码12 项目: hadoop   文件: Delete.java

@Override
protected void processPath(PathData item) throws IOException {
  if (!item.stat.isDirectory()) {
    throw new PathIsNotDirectoryException(item.toString());
  }      
  if (item.fs.listStatus(item.path).length == 0) {
    if (!item.fs.delete(item.path, false)) {
      throw new PathIOException(item.toString());
    }
  } else if (!ignoreNonEmpty) {
    throw new PathIsNotEmptyDirectoryException(item.toString());
  }
}
 
源代码13 项目: big-c   文件: TestRegistryOperations.java

@Test
public void testDeleteNonEmpty() throws Throwable {
  putExampleServiceEntry(ENTRY_PATH, 0);
  try {
    operations.delete(PARENT_PATH, false);
    fail("Expected a failure");
  } catch (PathIsNotEmptyDirectoryException expected) {
    // expected; ignore
  }
  operations.delete(PARENT_PATH, true);
}
 
源代码14 项目: big-c   文件: TestCuratorService.java

@Test
public void testRMNonRf() throws Throwable {
  mkPath("/rm", CreateMode.PERSISTENT);
  mkPath("/rm/child", CreateMode.PERSISTENT);
  try {
    curatorService.zkDelete("/rm", false, null);
    fail("expected a failure");
  } catch (PathIsNotEmptyDirectoryException expected) {

  }
}
 
源代码15 项目: big-c   文件: Delete.java

@Override
protected void processPath(PathData item) throws IOException {
  if (!item.stat.isDirectory()) {
    throw new PathIsNotDirectoryException(item.toString());
  }      
  if (item.fs.listStatus(item.path).length == 0) {
    if (!item.fs.delete(item.path, false)) {
      throw new PathIOException(item.toString());
    }
  } else if (!ignoreNonEmpty) {
    throw new PathIsNotEmptyDirectoryException(item.toString());
  }
}
 

/**
 * Cast IO exception to IGFS exception.
 *
 * @param msg Error message.
 * @param e IO exception.
 * @return IGFS exception.
 */
public static IgfsException cast(String msg, IOException e) {
    if (e instanceof FileNotFoundException)
        return new IgfsPathNotFoundException(e);
    else if (e instanceof ParentNotDirectoryException)
        return new IgfsParentNotDirectoryException(msg, e);
    else if (e instanceof PathIsNotEmptyDirectoryException)
        return new IgfsDirectoryNotEmptyException(e);
    else if (e instanceof PathExistsException)
        return new IgfsPathAlreadyExistsException(msg, e);
    else
        return new IgfsException(msg, e);
}
 
源代码17 项目: hadoop   文件: RegistryOperations.java

/**
 * Delete a path.
 *
 * If the operation returns without an error then the entry has been
 * deleted.
 * @param path path delete recursively
 * @param recursive recursive flag
 * @throws PathNotFoundException path is not in the registry.
 * @throws InvalidPathnameException the path is invalid.
 * @throws PathIsNotEmptyDirectoryException path has child entries, but
 * recursive is false.
 * @throws IOException Any other IO Exception
 *
 */
void delete(String path, boolean recursive)
    throws PathNotFoundException,
    PathIsNotEmptyDirectoryException,
    InvalidPathnameException,
    IOException;
 
源代码18 项目: big-c   文件: RegistryOperations.java

/**
 * Delete a path.
 *
 * If the operation returns without an error then the entry has been
 * deleted.
 * @param path path delete recursively
 * @param recursive recursive flag
 * @throws PathNotFoundException path is not in the registry.
 * @throws InvalidPathnameException the path is invalid.
 * @throws PathIsNotEmptyDirectoryException path has child entries, but
 * recursive is false.
 * @throws IOException Any other IO Exception
 *
 */
void delete(String path, boolean recursive)
    throws PathNotFoundException,
    PathIsNotEmptyDirectoryException,
    InvalidPathnameException,
    IOException;
 
 类所在包
 同包方法