@Override public boolean rename(Path src, Path dst) throws IOException { if (throwException) { throw new IOException("No more files allowed"); } return super.rename(src, dst); } }
boolean success = false; if (destFs instanceof DistributedFileSystem) { ((DistributedFileSystem)destFs).rename(srcStatus.getPath(), destFile, Options.Rename.OVERWRITE); success = true; } else {
/** * Move a file in HDFS from one path to another. * <p/> * @param source * @param destination * @throws IOException */ public void moveWithinHdfs(Path source, Path destination) throws IOException { dfs.rename(source, destination); }
@Override public boolean rename(Path src, Path dst) throws IOException { if (throwException) { throw new IOException("No more files allowed"); } return super.rename(src, dst); } }
private void changeData2(Path dir) throws Exception { final Path tmpFoo = new Path(dir, "tmpFoo"); final Path test = new Path(dir, "test"); final Path foo = new Path(dir, "foo"); final Path bar = new Path(dir, "bar"); dfs.rename(test, tmpFoo); dfs.rename(foo, test); dfs.rename(bar, foo); dfs.rename(tmpFoo, bar); }
private void changeData2(Path dir) throws Exception { final Path tmpFoo = new Path(dir, "tmpFoo"); final Path test = new Path(dir, "test"); final Path foo = new Path(dir, "foo"); final Path bar = new Path(dir, "bar"); dfs.rename(test, tmpFoo); dfs.rename(foo, test); dfs.rename(bar, foo); dfs.rename(tmpFoo, bar); }
private int changeData6(Path dir) throws Exception { final Path foo = new Path(dir, "foo"); final Path bar = new Path(dir, "bar"); final Path foo2 = new Path(dir, "foo2"); final Path foo_f1 = new Path(foo, "f1"); int numCreatedModified = 0; dfs.rename(foo, foo2); dfs.rename(bar, foo); dfs.rename(foo2, bar); DFSTestUtil.appendFile(dfs, foo_f1, (int) BLOCK_SIZE); numCreatedModified += 1; // modify ./bar/f1 return numCreatedModified; }
private int changeData6(Path dir) throws Exception { final Path foo = new Path(dir, "foo"); final Path bar = new Path(dir, "bar"); final Path foo2 = new Path(dir, "foo2"); final Path foo_f1 = new Path(foo, "f1"); int numDeletedModified = 0; dfs.rename(foo, foo2); dfs.rename(bar, foo); dfs.rename(foo2, bar); DFSTestUtil.appendFile(dfs, foo_f1, (int) blockSize); numDeletedModified += 1; // modify ./bar/f1 return numDeletedModified; }
private void changeData3(Path dir) throws Exception { final Path test = new Path(dir, "test"); final Path foo = new Path(dir, "foo"); final Path bar = new Path(dir, "bar"); final Path f1 = new Path(test, "file"); final Path f2 = new Path(foo, "file"); final Path f3 = new Path(bar, "file"); final Path newf1 = new Path(test, "newfile"); final Path newf2 = new Path(foo, "newfile"); final Path newf3 = new Path(bar, "newfile"); dfs.rename(f1, newf1); dfs.rename(f2, newf2); dfs.rename(f3, newf3); }
private void changeData3(Path dir) throws Exception { final Path test = new Path(dir, "test"); final Path foo = new Path(dir, "foo"); final Path bar = new Path(dir, "bar"); final Path f1 = new Path(test, "file"); final Path f2 = new Path(foo, "file"); final Path f3 = new Path(bar, "file"); final Path newf1 = new Path(test, "newfile"); final Path newf2 = new Path(foo, "newfile"); final Path newf3 = new Path(bar, "newfile"); dfs.rename(f1, newf1); dfs.rename(f2, newf2); dfs.rename(f3, newf3); }
private void changeData4(Path dir) throws Exception { final Path d1 = new Path(dir, "d1"); final Path d11 = new Path(dir, "d11"); final Path d2 = new Path(d1, "d2"); final Path d21 = new Path(d1, "d21"); final Path f1 = new Path(d2, "f1"); dfs.delete(f1, false); dfs.rename(d2, d21); dfs.rename(d1, d11); }
@Override void modify() throws Exception { hdfs.rename(srcPath, dstPath); TestDirectoryTree.Node newDstChild = new TestDirectoryTree.Node( dstPath, dstParent.level + 1, dstParent, hdfs); dstParent.nonSnapshotChildren.add(newDstChild); }
private int changeData4(Path dir) throws Exception { final Path d1 = new Path(dir, "d1"); final Path d11 = new Path(dir, "d11"); final Path d2 = new Path(d1, "d2"); final Path d21 = new Path(d1, "d21"); final Path f1 = new Path(d2, "f1"); int numDeletedAndModified = 0; dfs.delete(f1, false); numDeletedAndModified += 1; dfs.rename(d2, d21); numDeletedAndModified += 1; dfs.rename(d1, d11); numDeletedAndModified += 1; return numDeletedAndModified; }
private void changeData5(Path dir) throws Exception { final Path d1 = new Path(dir, "d1"); final Path d2 = new Path(dir, "d2"); final Path f1 = new Path(d1, "f1"); final Path tmp = new Path(dir, "tmp"); dfs.delete(f1, false); dfs.rename(d1, tmp); dfs.rename(d2, d1); final Path f2 = new Path(d1, "f2"); dfs.delete(f2, false); }
/** * Move hot files to warm and cold, warm files to hot and cold, * and cold files to hot and warm. */ void moveAround(DistributedFileSystem dfs) throws Exception { for(Path srcDir : map.keySet()) { int i = 0; for(Path dstDir : map.keySet()) { if (!srcDir.equals(dstDir)) { final Path src = new Path(srcDir, "file" + i++); final Path dst = new Path(dstDir, srcDir.getName() + "2" + dstDir.getName()); LOG.info("rename " + src + " to " + dst); dfs.rename(src, dst); } } } } }
@Test (timeout=60000) public void testRename() throws Exception { try { fs.rename(objInSnapshot, new Path("/invalid/path")); fail("Didn't throw SnapshotAccessControlException"); } catch (SnapshotAccessControlException e) { /* Ignored */ } try { fs.rename(sub2, objInSnapshot); fail("Didn't throw SnapshotAccessControlException"); } catch (SnapshotAccessControlException e) { /* Ignored */ } try { fs.rename(sub2, objInSnapshot, (Options.Rename) null); fail("Didn't throw SnapshotAccessControlException"); } catch (SnapshotAccessControlException e) { /* Ignored */ } }
private void oldRename(Path src, Path dst, boolean renameSucceeds, boolean exception) throws Exception { DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem(); try { Assert.assertEquals(renameSucceeds, fs.rename(src, dst)); } catch (Exception ex) { Assert.assertTrue(exception); } Assert.assertEquals(renameSucceeds, !exists(fc, src)); Assert.assertEquals(renameSucceeds, exists(fc, dst)); }
public void testRenameMetrics() throws Exception { Path src = getTestPath("src"); createFile(src, 100, (short)1); Path target = getTestPath("target"); createFile(target, 100, (short)1); fs.rename(src, target, Rename.OVERWRITE); updateMetrics(); assertEquals(1, nnMetrics.numFilesRenamed.getPreviousIntervalValue()); assertEquals(1, nnMetrics.numFilesDeleted.getPreviousIntervalValue()); }
private void oldRename(Path src, Path dst, boolean renameSucceeds, boolean exception) throws Exception { DistributedFileSystem fs = cluster.getFileSystem(); try { Assert.assertEquals(renameSucceeds, fs.rename(src, dst)); } catch (Exception ex) { Assert.assertTrue(exception); } Assert.assertEquals(renameSucceeds, !exists(fc, src)); Assert.assertEquals(renameSucceeds, exists(fc, dst)); }
@Test public void testRenameMetrics() throws Exception { Path src = getTestPath("src"); createFile(src, 100, (short)1); Path target = getTestPath("target"); createFile(target, 100, (short)1); fs.rename(src, target, Rename.OVERWRITE); updateMetrics(); MetricsRecordBuilder rb = getMetrics(NN_METRICS); assertCounter("FilesRenamed", 1L, rb); assertCounter("FilesDeleted", 1L, rb); }