Example usage for org.apache.hadoop.fs TrashPolicy getCurrentTrashDir

List of usage examples for org.apache.hadoop.fs TrashPolicy getCurrentTrashDir

Introduction

In this page you can find the example usage for org.apache.hadoop.fs TrashPolicy getCurrentTrashDir.

Prototype

public abstract Path getCurrentTrashDir();

Source Link

Document

Get the current working directory of the Trash Policy This API does not work with files deleted from encryption zone when HDFS data encryption at rest feature is enabled as rename file between encryption zones or encryption zone and non-encryption zone is not allowed.

Usage

From source file:org.apache.ambari.view.filebrowser.HdfsApi.java

License:Apache License

/**
 * Trash directory//from   w  ww.j  a v a  2s.co  m
 * @return trash directory
 * @throws Exception
 */
public Path getTrashDir() throws Exception {
    return ugi.doAs(new PrivilegedExceptionAction<Path>() {
        public Path run() throws IOException {
            TrashPolicy trashPolicy = TrashPolicy.getInstance(conf, fs, fs.getHomeDirectory());
            return trashPolicy.getCurrentTrashDir().getParent();
        }
    });
}

From source file:org.apache.ambari.view.utils.hdfs.HdfsApi.java

License:Apache License

/**
 * Trash directory//w w  w. j  a va 2s  .  co m
 * @return trash directory
 * @throws Exception
 */
public Path getTrashDir() throws Exception {
    return execute(new PrivilegedExceptionAction<Path>() {
        public Path run() throws IOException {
            TrashPolicy trashPolicy = TrashPolicy.getInstance(conf, fs, fs.getHomeDirectory());
            return trashPolicy.getCurrentTrashDir().getParent();
        }
    });
}

From source file:org.apache.gobblin.util.HadoopUtilsTest.java

License:Apache License

@Test
public void testMoveToTrash() throws IOException {
    Path hadoopUtilsTestDir = new Path(Files.createTempDir().getAbsolutePath(), "HadoopUtilsTestDir");
    Configuration conf = new Configuration();
    // Set the time to keep it in trash to 10 minutes.
    // 0 means object will be deleted instantly.
    conf.set("fs.trash.interval", "10");
    FileSystem fs = FileSystem.getLocal(conf);
    Trash trash = new Trash(fs, conf);
    TrashPolicy trashPolicy = TrashPolicy.getInstance(conf, fs, fs.getHomeDirectory());
    Path trashPath = trashPolicy.getCurrentTrashDir();

    fs.mkdirs(hadoopUtilsTestDir);//from   w  w w . j av a2 s .c  o m
    Assert.assertTrue(fs.exists(hadoopUtilsTestDir));
    trash.moveToTrash(hadoopUtilsTestDir.getParent());
    Assert.assertFalse(fs.exists(hadoopUtilsTestDir));
    Assert.assertTrue(fs.exists(trashPath));
}