new Path(uri.getScheme(), uri.getAuthority(), uri.getPath())); FileContext fc = FileContext.getFileContext(frameworkPath.toUri(), conf); frameworkPath = fc.resolvePath(frameworkPath); uri = frameworkPath.toUri(); try {
Path frameworkPath = fs.makeQualified(new Path(uri.getScheme(), uri.getAuthority(), uri.getPath())); FileContext fc = FileContext.getFileContext(frameworkPath.toUri(), hConf); frameworkPath = fc.resolvePath(frameworkPath); uri = frameworkPath.toUri();
Path frameworkPath = fs.makeQualified(new Path(uri.getScheme(), uri.getAuthority(), uri.getPath())); FileContext fc = FileContext.getFileContext(frameworkPath.toUri(), hConf); frameworkPath = fc.resolvePath(frameworkPath); uri = frameworkPath.toUri();
/** * Resolves a {@link URI} representation from the given {@link Location}. It resolves the URI in the same way * as Spark does. */ private static URI resolveURI(Location location) throws IOException { LocationFactory locationFactory = location.getLocationFactory(); while (locationFactory instanceof ForwardingLocationFactory) { locationFactory = ((ForwardingLocationFactory) locationFactory).getDelegate(); } if (!(locationFactory instanceof FileContextLocationFactory)) { return location.toURI(); } // Resolves the URI the way as Spark does Configuration hConf = ((FileContextLocationFactory) locationFactory).getConfiguration(); org.apache.hadoop.fs.Path path = new org.apache.hadoop.fs.Path(location.toURI().getPath()); path = path.getFileSystem(hConf).makeQualified(path); return ((FileContextLocationFactory) locationFactory).getFileContext().resolvePath(path).toUri(); }
/** * Resolves a {@link URI} representation from the given {@link Location}. It resolves the URI in the same way * as Spark does. */ private static URI resolveURI(Location location) throws IOException { LocationFactory locationFactory = location.getLocationFactory(); while (locationFactory instanceof ForwardingLocationFactory) { locationFactory = ((ForwardingLocationFactory) locationFactory).getDelegate(); } if (!(locationFactory instanceof FileContextLocationFactory)) { return location.toURI(); } // Resolves the URI the way as Spark does Configuration hConf = ((FileContextLocationFactory) locationFactory).getConfiguration(); org.apache.hadoop.fs.Path path = new org.apache.hadoop.fs.Path(location.toURI().getPath()); path = path.getFileSystem(hConf).makeQualified(path); return ((FileContextLocationFactory) locationFactory).getFileContext().resolvePath(path).toUri(); }
@Test(expected=FileNotFoundException.class) public void testResolvePathDanglingLink() throws IOException { fcView.resolvePath(new Path("/danglingLink")); }
@Test(expected=FileNotFoundException.class) public void testResolvePathMissingThroughMountPoints() throws IOException { fcView.resolvePath(new Path("/user/nonExisting")); }
@Test public void testResolvePathInternalPaths() throws IOException { Assert.assertEquals(new Path("/"), fcView.resolvePath(new Path("/"))); Assert.assertEquals(new Path("/internalDir"), fcView.resolvePath(new Path("/internalDir"))); } @Test
@Test public void testResolvePathMountPoints() throws IOException { Assert.assertEquals(new Path(targetTestRoot,"user"), fcView.resolvePath(new Path("/user"))); Assert.assertEquals(new Path(targetTestRoot,"data"), fcView.resolvePath(new Path("/data"))); Assert.assertEquals(new Path(targetTestRoot,"dir2"), fcView.resolvePath(new Path("/internalDir/linkToDir2"))); Assert.assertEquals(new Path(targetTestRoot,"dir3"), fcView.resolvePath(new Path("/internalDir/internalDir2/linkToDir3"))); }
/** * Resolves a {@link URI} representation from the given {@link Location}. It resolves the URI in the same way * as Spark does. */ private static URI resolveURI(Location location) throws IOException { LocationFactory locationFactory = location.getLocationFactory(); while (locationFactory instanceof ForwardingLocationFactory) { locationFactory = ((ForwardingLocationFactory) locationFactory).getDelegate(); } if (!(locationFactory instanceof FileContextLocationFactory)) { return location.toURI(); } // Resolves the URI the way as Spark does Configuration hConf = ((FileContextLocationFactory) locationFactory).getConfiguration(); org.apache.hadoop.fs.Path path = new org.apache.hadoop.fs.Path(location.toURI().getPath()); path = path.getFileSystem(hConf).makeQualified(path); return ((FileContextLocationFactory) locationFactory).getFileContext().resolvePath(path).toUri(); }
@Test(expected=FileNotFoundException.class) public void testResolvePathDanglingLink() throws IOException { fcView.resolvePath(new Path("/danglingLink")); }
@Test(expected=FileNotFoundException.class) public void testResolvePathMissingThroughMountPoints() throws IOException { fcView.resolvePath(new Path("/user/nonExisting")); }
@Test public void testResolvePathMountPoints() throws IOException { Assert.assertEquals(new Path(targetTestRoot,"user"), fcView.resolvePath(new Path("/user"))); Assert.assertEquals(new Path(targetTestRoot,"data"), fcView.resolvePath(new Path("/data"))); Assert.assertEquals(new Path(targetTestRoot,"dir2"), fcView.resolvePath(new Path("/internalDir/linkToDir2"))); Assert.assertEquals(new Path(targetTestRoot,"dir3"), fcView.resolvePath(new Path("/internalDir/internalDir2/linkToDir3"))); }
@Test public void testResolvePathInternalPaths() throws IOException { Assert.assertEquals(new Path("/"), fcView.resolvePath(new Path("/"))); Assert.assertEquals(new Path("/internalDir"), fcView.resolvePath(new Path("/internalDir"))); } @Test
@Test(expected=FileNotFoundException.class) public void testResolvePathMissingThroughMountPoints2() throws IOException { fcView.mkdir( fileContextTestHelper.getTestRootPath(fcView, "/user/dirX"), FileContext.DEFAULT_PERM, false); fcView.resolvePath(new Path("/user/dirX/nonExisting")); }
@Test(expected=FileNotFoundException.class) public void testResolvePathMissingThroughMountPoints2() throws IOException { fcView.mkdir( fileContextTestHelper.getTestRootPath(fcView, "/user/dirX"), FileContext.DEFAULT_PERM, false); fcView.resolvePath(new Path("/user/dirX/nonExisting")); }
@Test public void testResolvePathThroughMountPoints() throws IOException { fileContextTestHelper.createFile(fcView, "/user/foo"); Assert.assertEquals(new Path(targetTestRoot,"user/foo"), fcView.resolvePath(new Path("/user/foo"))); fcView.mkdir( fileContextTestHelper.getTestRootPath(fcView, "/user/dirX"), FileContext.DEFAULT_PERM, false); Assert.assertEquals(new Path(targetTestRoot,"user/dirX"), fcView.resolvePath(new Path("/user/dirX"))); fcView.mkdir( fileContextTestHelper.getTestRootPath(fcView, "/user/dirX/dirY"), FileContext.DEFAULT_PERM, false); Assert.assertEquals(new Path(targetTestRoot,"user/dirX/dirY"), fcView.resolvePath(new Path("/user/dirX/dirY"))); }
@Test public void testResolvePathThroughMountPoints() throws IOException { fileContextTestHelper.createFile(fcView, "/user/foo"); Assert.assertEquals(new Path(targetTestRoot,"user/foo"), fcView.resolvePath(new Path("/user/foo"))); fcView.mkdir( fileContextTestHelper.getTestRootPath(fcView, "/user/dirX"), FileContext.DEFAULT_PERM, false); Assert.assertEquals(new Path(targetTestRoot,"user/dirX"), fcView.resolvePath(new Path("/user/dirX"))); fcView.mkdir( fileContextTestHelper.getTestRootPath(fcView, "/user/dirX/dirY"), FileContext.DEFAULT_PERM, false); Assert.assertEquals(new Path(targetTestRoot,"user/dirX/dirY"), fcView.resolvePath(new Path("/user/dirX/dirY"))); }
@Test /* * Test method * org.apache.hadoop.fs.FileContext.getFileContext(AbstractFileSystem) */ public void testGetFileContext1() throws IOException { final Path rootPath = getTestRootPath(fc, "test"); AbstractFileSystem asf = fc.getDefaultFileSystem(); // create FileContext using the protected #getFileContext(1) method: FileContext fc2 = FileContext.getFileContext(asf); // Now just check that this context can do something reasonable: final Path path = new Path(rootPath, "zoo"); FSDataOutputStream out = fc2.create(path, EnumSet.of(CREATE), Options.CreateOpts.createParent()); out.close(); Path pathResolved = fc2.resolvePath(path); assertEquals(pathResolved.toUri().getPath(), path.toUri().getPath()); }
@Test /* * Test method * org.apache.hadoop.fs.FileContext.getFileContext(AbstractFileSystem) */ public void testGetFileContext1() throws IOException { final Path rootPath = getTestRootPath(fc, "test"); AbstractFileSystem asf = fc.getDefaultFileSystem(); // create FileContext using the protected #getFileContext(1) method: FileContext fc2 = FileContext.getFileContext(asf); // Now just check that this context can do something reasonable: final Path path = new Path(rootPath, "zoo"); FSDataOutputStream out = fc2.create(path, EnumSet.of(CREATE), Options.CreateOpts.createParent()); out.close(); Path pathResolved = fc2.resolvePath(path); assertEquals(pathResolved.toUri().getPath(), path.toUri().getPath()); }