本文整理汇总了Java中org.apache.hadoop.fs.Trash类的典型用法代码示例。如果您正苦于以下问题:Java Trash类的具体用法?Java Trash怎么用?Java Trash使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Trash类属于org.apache.hadoop.fs包,在下文中一共展示了Trash类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: moveToTrash
import org.apache.hadoop.fs.Trash; //导入依赖的package包/类
private boolean moveToTrash(PathData item) throws IOException {
boolean success = false;
if (!skipTrash) {
try {
success = Trash.moveToAppropriateTrash(item.fs, item.path, getConf());
} catch(FileNotFoundException fnfe) {
throw fnfe;
} catch (IOException ioe) {
String msg = ioe.getMessage();
if (ioe.getCause() != null) {
msg += ": " + ioe.getCause().getMessage();
}
throw new IOException(msg + ". Consider using -skipTrash option", ioe);
}
}
return success;
}
示例2: startTrashEmptier
import org.apache.hadoop.fs.Trash; //导入依赖的package包/类
private void startTrashEmptier(final Configuration conf) throws IOException {
long trashInterval =
conf.getLong(FS_TRASH_INTERVAL_KEY, FS_TRASH_INTERVAL_DEFAULT);
if (trashInterval == 0) {
return;
} else if (trashInterval < 0) {
throw new IOException("Cannot start trash emptier with negative interval."
+ " Set " + FS_TRASH_INTERVAL_KEY + " to a positive value.");
}
// This may be called from the transitionToActive code path, in which
// case the current user is the administrator, not the NN. The trash
// emptier needs to run as the NN. See HDFS-3972.
FileSystem fs = SecurityUtil.doAsLoginUser(
new PrivilegedExceptionAction<FileSystem>() {
@Override
public FileSystem run() throws IOException {
return FileSystem.get(conf);
}
});
this.emptier = new Thread(new Trash(fs, conf).getEmptier(), "Trash Emptier");
this.emptier.setDaemon(true);
this.emptier.start();
}
示例3: moveToTrash
import org.apache.hadoop.fs.Trash; //导入依赖的package包/类
private boolean moveToTrash(PathData item) throws IOException {
boolean success = false;
if (!skipTrash) {
try {
success = Trash.moveToAppropriateTrash(item.fs, item.path, getConf());
} catch(FileNotFoundException fnfe) {
throw fnfe;
} catch (IOException ioe) {
String msg = ioe.getMessage();
if (ioe.getCause() != null) {
msg += ": " + ioe.getCause().getMessage();
}
throw new IOException(msg + ". Consider using -skipTrash option", ioe);
}
}
return success;
}
示例4: deleteDirectory
import org.apache.hadoop.fs.Trash; //导入依赖的package包/类
/**
* Delete the specified directory, using the trash as available.
*
* @param conf configuration object
* @param path path to delete
*
* @throws IOException if there's an error deleting the directory.
*/
public static void deleteDirectory(Configuration conf, Path path) throws IOException {
Trash trash = new Trash(path.getFileSystem(conf), conf);
try {
if (!trash.isEnabled()) {
LOG.debug("Trash is not enabled for " + path + " so deleting instead");
FileSystem fs = path.getFileSystem(conf);
fs.delete(path, true);
} else {
boolean removed = trash.moveToTrash(path);
if (removed) {
LOG.debug("Moved to trash: " + path);
} else {
LOG.error("Item already in trash: " + path);
}
}
} catch (FileNotFoundException e) {
LOG.debug("Attempting to delete non-existent directory " + path);
return;
}
}
示例5: trashNonDefaultFS
import org.apache.hadoop.fs.Trash; //导入依赖的package包/类
public static void trashNonDefaultFS(Configuration conf) throws IOException {
conf.set("fs.trash.interval", "10"); // 10 minute
// attempt non-default FileSystem trash
{
final FileSystem lfs = FileSystem.getLocal(conf);
Path p = TEST_DIR;
Path f = new Path(p, "foo/bar");
if (lfs.exists(p)) {
lfs.delete(p, true);
}
try {
f = writeFile(lfs, f);
FileSystem.closeAll();
FileSystem localFs = FileSystem.get(URI.create("file:///"), conf);
Trash lTrash = new Trash(localFs, conf);
lTrash.moveToTrash(f.getParent());
checkTrash(localFs, lTrash.getCurrentTrashDir(), f);
} finally {
if (lfs.exists(p)) {
lfs.delete(p, true);
}
}
}
}
示例6: startTrashEmptier
import org.apache.hadoop.fs.Trash; //导入依赖的package包/类
private void startTrashEmptier(final Configuration conf) throws IOException {
long trashInterval =
conf.getLong(FS_TRASH_INTERVAL_KEY, FS_TRASH_INTERVAL_DEFAULT);
if (trashInterval == 0) {
return;
} else if (trashInterval < 0) {
throw new IOException(
"Cannot start tresh emptier with negative interval." + " Set " +
FS_TRASH_INTERVAL_KEY + " to a positive value.");
}
// This may be called from the transitionToActive code path, in which
// case the current user is the administrator, not the NN. The trash
// emptier needs to run as the NN. See HDFS-3972.
FileSystem fs =
SecurityUtil.doAsLoginUser(new PrivilegedExceptionAction<FileSystem>() {
@Override
public FileSystem run() throws IOException {
return FileSystem.get(conf);
}
});
this.emptier =
new Thread(new Trash(fs, conf).getEmptier(), "Trash Emptier");
this.emptier.setDaemon(true);
this.emptier.start();
}
示例7: testMoveToTrash
import org.apache.hadoop.fs.Trash; //导入依赖的package包/类
@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);
Assert.assertTrue(fs.exists(hadoopUtilsTestDir));
trash.moveToTrash(hadoopUtilsTestDir.getParent());
Assert.assertFalse(fs.exists(hadoopUtilsTestDir));
Assert.assertTrue(fs.exists(trashPath));
}
示例8: processArguments
import org.apache.hadoop.fs.Trash; //导入依赖的package包/类
@Override
protected void processArguments(LinkedList<PathData> args)
throws IOException {
Trash trash = new Trash(getConf());
trash.expunge();
trash.checkpoint();
}
示例9: moveToTrash
import org.apache.hadoop.fs.Trash; //导入依赖的package包/类
public static void moveToTrash(Configuration conf, Path path) throws IOException {
Trash t = new Trash(conf);
boolean isMoved = t.moveToTrash(path);
t.expunge();
if (!isMoved) {
logger.error("Trash is not enabled or file is already in the trash.");
}
}
示例10: testPluggableTrash
import org.apache.hadoop.fs.Trash; //导入依赖的package包/类
@Test
public void testPluggableTrash() throws IOException {
Configuration conf = new Configuration();
// Test plugged TrashPolicy
conf.setClass("fs.trash.classname", TestTrashPolicy.class, TrashPolicy.class);
Trash trash = new Trash(conf);
assertTrue(trash.getTrashPolicy().getClass().equals(TestTrashPolicy.class));
}
示例11: startTrashEmptier
import org.apache.hadoop.fs.Trash; //导入依赖的package包/类
private void startTrashEmptier(Configuration conf) throws IOException {
if (conf.getInt("fs.trash.interval", 0) == 0) {
return;
}
FileSystem fs = NameNode.getTrashFileSystem(conf);
this.trash = new Trash(fs, conf);
this.emptier = new Thread(trash.getEmptier(), "Trash Emptier");
this.emptier.setDaemon(true);
this.emptier.start();
}
示例12: moveToTrash
import org.apache.hadoop.fs.Trash; //导入依赖的package包/类
private boolean moveToTrash(PathData item) throws IOException {
boolean success = false;
if (!skipTrash) {
try {
success = Trash.moveToAppropriateTrash(item.fs, item.path, getConf());
} catch(FileNotFoundException fnfe) {
throw fnfe;
} catch (IOException ioe) {
throw new IOException(ioe.getMessage() + ". Consider using -skipTrash option", ioe);
}
}
return success;
}
示例13: trash
import org.apache.hadoop.fs.Trash; //导入依赖的package包/类
public boolean trash(final Path path)
{
return run(new Retryable<Boolean>()
{
@Override
public Boolean call()
throws Exception
{
return Trash.moveToAppropriateTrash(fs, path, conf);
}
});
}