/** * Moves the object to the filesystem trash according to the file system policy. * @param fs FileSystem object * @param path Path to the object to be moved to trash. * @throws IOException */ public static void moveToTrash(FileSystem fs, Path path) throws IOException { Trash trash = new Trash(fs, new Configuration()); trash.moveToTrash(path); } /**
protected Trash getTrash() throws IOException { if (this.trash == null) { this.trash = new Trash(getConf()); } return this.trash; }
throw new IOException("Failed to get server trash configuration", e); Trash trash = new Trash(fullyResolvedFs, conf); return trash.moveToTrash(fullyResolvedPath);
@Override protected void processArguments(LinkedList<PathData> args) throws IOException { FileSystem[] childFileSystems = FileSystem.get(getConf()).getChildFileSystems(); if (null != childFileSystems) { for (FileSystem fs : childFileSystems) { Trash trash = new Trash(fs, getConf()); trash.expunge(); trash.checkpoint(); } } else { Trash trash = new Trash(getConf()); trash.expunge(); trash.checkpoint(); } } }
@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)); } }
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(); }
@Override public boolean moveToTrash(Path path) throws IOException { FileSystem fs = getVolumeByPath(path).getFileSystem(); Trash trash = new Trash(fs, fs.getConf()); return trash.moveToTrash(path); }
GarbageCollectWriteAheadLogs(Instance instance, FileSystem fs, boolean noTrash) throws IOException { this.instance = instance; this.fs = fs; if (!noTrash) this.trash = new Trash(fs, fs.getConf()); }
protected Trash getTrash() throws IOException { if (this.trash == null) { this.trash = new Trash(getConf()); } return this.trash; }
protected Trash getTrash() throws IOException{ if (this.trash != null) { return this.trash; } synchronized(this) { if (this.trash == null) { this.trash = new Trash(getConf()); } } return this.trash; }
protected Trash getTrash() throws IOException { if (this.trash == null) { this.trash = new Trash(getConf()); } return this.trash; }
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(); }
@Override public boolean moveToAppropriateTrash(FileSystem fs, Path path, Configuration conf) throws IOException { // older versions of Hadoop don't have a Trash constructor based on the // Path or FileSystem. So need to achieve this by creating a dummy conf. // this needs to be filtered out based on version Configuration dupConf = new Configuration(conf); FileSystem.setDefaultUri(dupConf, fs.getUri()); Trash trash = new Trash(dupConf); return trash.moveToTrash(path); } @Override
@Override public boolean moveToAppropriateTrash(FileSystem fs, Path path, Configuration conf) throws IOException { // older versions of Hadoop don't have a Trash constructor based on the // Path or FileSystem. So need to achieve this by creating a dummy conf. // this needs to be filtered out based on version Configuration dupConf = new Configuration(conf); FileSystem.setDefaultUri(dupConf, fs.getUri()); Trash trash = new Trash(dupConf); return trash.moveToTrash(path); } @Override
@Override public boolean moveToAppropriateTrash(FileSystem fs, Path path, Configuration conf) throws IOException { // older versions of Hadoop don't have a Trash constructor based on the // Path or FileSystem. So need to achieve this by creating a dummy conf. // this needs to be filtered out based on version Configuration dupConf = new Configuration(conf); FileSystem.setDefaultUri(dupConf, fs.getUri()); Trash trash = new Trash(dupConf); return trash.moveToTrash(path); }
@Override public FileSystem run() throws Exception { Trash trash = new Trash(fs.getConf()); if (!trash.moveToTrash(p)) { throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FS005", "Could not move path [{0}] to trash on delete", p); } return null; } });
@Override public boolean moveToTrash(Path path) throws IOException { FileSystem fs = getVolumeByPath(path).getFileSystem(); Trash trash = new Trash(fs, fs.getConf()); return trash.moveToTrash(path); }
public void init() throws IOException { getConf().setQuietMode(true); if (this.fs == null) { this.fs = FileSystem.get(getConf()); } if (this.trash == null) { this.trash = new Trash(getConf()); } }
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)); }
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)); }