@Override public void setWorkingDirectory(Path newWDir) throws IOException { fc.setWorkingDirectory(newWDir); }
@Override public void setWorkingDirectory(Path newWDir) throws IOException { fc.setWorkingDirectory(newWDir); }
@Test /** Test setWorkingDirectory not resolves symlinks */ public void testSetWDNotResolvesLinks() throws IOException { Path dir = new Path(testBaseDir1()); Path linkToDir = new Path(testBaseDir1()+"/link"); fc.createSymlink(dir, linkToDir, false); fc.setWorkingDirectory(linkToDir); assertEquals(linkToDir.getName(), fc.getWorkingDirectory().getName()); }
fc.setWorkingDirectory(dir); fc.createSymlink(file, link, false); readFile(link);
@Test /** Test create symlink to . */ public void testCreateLinkToDot() throws IOException { Path dir = new Path(testBaseDir1()); Path file = new Path(testBaseDir1(), "file"); Path link = new Path(testBaseDir1(), "linkToDot"); createAndWriteFile(file); fc.setWorkingDirectory(dir); try { fc.createSymlink(new Path("."), link, false); fail("Created symlink to dot"); } catch (IOException x) { // Expected. Path(".") resolves to "" because URI normalizes // the dot away and AbstractFileSystem considers "" invalid. } }
@Test /** Test create symlink to ../file */ public void testCreateLinkToDotDotPrefix() throws IOException { Path file = new Path(testBaseDir1(), "file"); Path dir = new Path(testBaseDir1(), "test"); Path link = new Path(testBaseDir1(), "test/link"); createAndWriteFile(file); fc.mkdir(dir, FsPermission.getDefault(), false); fc.setWorkingDirectory(dir); fc.createSymlink(new Path("../file"), link, false); readFile(link); assertEquals(new Path("../file"), fc.getLinkTarget(link)); }
fc.setWorkingDirectory(workDir); Assert.assertEquals(workDir, fc.getWorkingDirectory()); fc.setWorkingDirectory(new Path(".")); Assert.assertEquals(workDir, fc.getWorkingDirectory()); fc.setWorkingDirectory(new Path("..")); Assert.assertEquals(workDir.getParent(), fc.getWorkingDirectory()); fc.setWorkingDirectory(workDir); Assert.assertEquals(workDir, fc.getWorkingDirectory()); Path absoluteDir = new Path(workDir,"existingDir1"); fc.mkdir(absoluteDir, FileContext.DEFAULT_PERM, true); fc.setWorkingDirectory(relativeDir); Assert.assertEquals(absoluteDir, fc.getWorkingDirectory()); fc.setWorkingDirectory(absoluteDir); Assert.assertEquals(absoluteDir, fc.getWorkingDirectory()); fc.setWorkingDirectory(absoluteDir); Assert.fail("cd to non existing dir should have failed"); } catch (Exception e) { fc.setWorkingDirectory(absoluteDir); Assert.assertEquals(absoluteDir, fc.getWorkingDirectory());
@Test /** Test creating a symlink using relative paths */ public void testCreateLinkUsingRelPaths() throws IOException { Path fileAbs = new Path(testBaseDir1(), "file"); Path linkAbs = new Path(testBaseDir1(), "linkToFile"); Path schemeAuth = new Path(testURI().toString()); Path fileQual = new Path(schemeAuth, testBaseDir1()+"/file"); createAndWriteFile(fileAbs); fc.setWorkingDirectory(new Path(testBaseDir1())); fc.createSymlink(new Path("file"), new Path("linkToFile"), false); checkLink(linkAbs, new Path("file"), fileQual); // Now rename the link's parent. Because the target was specified // with a relative path the link should still resolve. Path dir1 = new Path(testBaseDir1()); Path dir2 = new Path(testBaseDir2()); Path linkViaDir2 = new Path(testBaseDir2(), "linkToFile"); Path fileViaDir2 = new Path(schemeAuth, testBaseDir2()+"/file"); fc.rename(dir1, dir2, Rename.OVERWRITE); assertEquals(fileViaDir2, fc.getFileLinkStatus(linkViaDir2).getSymlink()); readFile(linkViaDir2); }
@Test /** Test create symlink to / */ public void testCreateLinkToSlash() throws IOException { Path dir = new Path(testBaseDir1()); Path file = new Path(testBaseDir1(), "file"); Path link = new Path(testBaseDir1(), "linkToSlash"); Path fileViaLink = new Path(testBaseDir1()+"/linkToSlash"+ testBaseDir1()+"/file"); createAndWriteFile(file); fc.setWorkingDirectory(dir); fc.createSymlink(new Path("/"), link, false); readFile(fileViaLink); assertEquals(fileSize, fc.getFileStatus(fileViaLink).getLen()); // Ditto when using another file context since the file system // for the slash is resolved according to the link's parent. FileContext localFc = FileContext.getLocalFSFileContext(); Path linkQual = new Path(cluster.getURI().toString(), fileViaLink); assertEquals(fileSize, localFc.getFileStatus(linkQual).getLen()); }
@Test /** Link from Hdfs to LocalFs */ public void testLinkAcrossFileSystems() throws IOException { Path localDir = new Path("file://"+getAbsoluteTestRootDir(fc)+"/test"); Path localFile = new Path("file://"+getAbsoluteTestRootDir(fc)+"/test/file"); Path link = new Path(testBaseDir1(), "linkToFile"); FileContext localFc = FileContext.getLocalFSFileContext(); localFc.delete(localDir, true); localFc.mkdir(localDir, FileContext.DEFAULT_PERM, true); localFc.setWorkingDirectory(localDir); assertEquals(localDir, localFc.getWorkingDirectory()); createAndWriteFile(localFc, localFile); fc.createSymlink(localFile, link, false); readFile(link); assertEquals(fileSize, fc.getFileStatus(link).getLen()); }
@Override public synchronized void startLocalizer(Path nmPrivateContainerTokensPath, InetSocketAddress nmAddr, String user, String appId, String locId, LocalDirsHandlerService dirsHandler) throws IOException, InterruptedException { List<String> localDirs = dirsHandler.getLocalDirs(); List<String> logDirs = dirsHandler.getLogDirs(); ContainerLocalizer localizer = new ContainerLocalizer(lfs, user, appId, locId, getPaths(localDirs), RecordFactoryProvider.getRecordFactory(getConf())); createUserLocalDirs(localDirs, user); createUserCacheDirs(localDirs, user); createAppDirs(localDirs, user, appId); createAppLogDirs(appId, logDirs, user); // randomly choose the local directory Path appStorageDir = getWorkingDir(localDirs, user, appId); String tokenFn = String.format(ContainerLocalizer.TOKEN_FILE_NAME_FMT, locId); Path tokenDst = new Path(appStorageDir, tokenFn); copyFile(nmPrivateContainerTokensPath, tokenDst, user); LOG.info("Copying from " + nmPrivateContainerTokensPath + " to " + tokenDst); lfs.setWorkingDirectory(appStorageDir); LOG.info("CWD set to " + appStorageDir + " = " + lfs.getWorkingDirectory()); // TODO: DO it over RPC for maintaining similarity? localizer.runLocalization(nmAddr); }
@Override public synchronized void startLocalizer(Path nmPrivateContainerTokensPath, InetSocketAddress nmAddr, String user, String appId, String locId, LocalDirsHandlerService dirsHandler) throws IOException, InterruptedException { List<String> localDirs = dirsHandler.getLocalDirs(); List<String> logDirs = dirsHandler.getLogDirs(); ContainerLocalizer localizer = new ContainerLocalizer(lfs, user, appId, locId, getPaths(localDirs), RecordFactoryProvider.getRecordFactory(getConf())); createUserLocalDirs(localDirs, user); createUserCacheDirs(localDirs, user); createAppDirs(localDirs, user, appId); createAppLogDirs(appId, logDirs, user); // randomly choose the local directory Path appStorageDir = getWorkingDir(localDirs, user, appId); String tokenFn = String.format(ContainerLocalizer.TOKEN_FILE_NAME_FMT, locId); Path tokenDst = new Path(appStorageDir, tokenFn); copyFile(nmPrivateContainerTokensPath, tokenDst, user); LOG.info("Copying from " + nmPrivateContainerTokensPath + " to " + tokenDst); lfs.setWorkingDirectory(appStorageDir); LOG.info("CWD set to " + appStorageDir + " = " + lfs.getWorkingDirectory()); // TODO: DO it over RPC for maintaining similarity? localizer.runLocalization(nmAddr); }
@Override public void startLocalizer(Path nmPrivateContainerTokensPath, InetSocketAddress nmAddr, String user, String appId, String locId, LocalDirsHandlerService dirsHandler) throws IOException, InterruptedException { List<String> localDirs = dirsHandler.getLocalDirs(); List<String> logDirs = dirsHandler.getLogDirs(); createUserLocalDirs(localDirs, user); createUserCacheDirs(localDirs, user); createAppDirs(localDirs, user, appId); createAppLogDirs(appId, logDirs, user); // randomly choose the local directory Path appStorageDir = getWorkingDir(localDirs, user, appId); String tokenFn = String.format(ContainerLocalizer.TOKEN_FILE_NAME_FMT, locId); Path tokenDst = new Path(appStorageDir, tokenFn); copyFile(nmPrivateContainerTokensPath, tokenDst, user); LOG.info("Copying from " + nmPrivateContainerTokensPath + " to " + tokenDst); FileContext localizerFc = FileContext.getFileContext( lfs.getDefaultFileSystem(), getConf()); localizerFc.setUMask(lfs.getUMask()); localizerFc.setWorkingDirectory(appStorageDir); LOG.info("Localizer CWD set to " + appStorageDir + " = " + localizerFc.getWorkingDirectory()); ContainerLocalizer localizer = new ContainerLocalizer(localizerFc, user, appId, locId, getPaths(localDirs), RecordFactoryProvider.getRecordFactory(getConf())); // TODO: DO it over RPC for maintaining similarity? localizer.runLocalization(nmAddr); }
Path workDir = new Path("/testWd"); Path fqWd = fc.makeQualified(workDir); fc.setWorkingDirectory(workDir); Assert.assertEquals(fqWd, fc.getWorkingDirectory()); fc.setWorkingDirectory(new Path(".")); Assert.assertEquals(fqWd, fc.getWorkingDirectory()); fc.setWorkingDirectory(new Path("..")); Assert.assertEquals(fqWd.getParent(), fc.getWorkingDirectory()); fc.setWorkingDirectory(workDir); Assert.assertEquals(fqWd, fc.getWorkingDirectory()); fc.mkdir(absoluteDir, FileContext.DEFAULT_PERM, true); Path fqAbsoluteDir = fc.makeQualified(absoluteDir); fc.setWorkingDirectory(relativeDir); Assert.assertEquals(fqAbsoluteDir, fc.getWorkingDirectory()); fqAbsoluteDir = fc.makeQualified(absoluteDir); fc.mkdir(absoluteDir, FileContext.DEFAULT_PERM, true); fc.setWorkingDirectory(absoluteDir); Assert.assertEquals(fqAbsoluteDir, fc.getWorkingDirectory()); fc.setWorkingDirectory(absoluteDir); Assert.fail("cd to non existing dir should have failed"); } catch (Exception e) { absoluteDir = new Path(LOCAL_FS_ROOT_URI + "/existingDir");
@Override public void startLocalizer(Path nmPrivateContainerTokensPath, InetSocketAddress nmAddr, String user, String appId, String locId, LocalDirsHandlerService dirsHandler) throws IOException, InterruptedException { List<String> localDirs = dirsHandler.getLocalDirs(); List<String> logDirs = dirsHandler.getLogDirs(); createUserLocalDirs(localDirs, user); createUserCacheDirs(localDirs, user); createAppDirs(localDirs, user, appId); createAppLogDirs(appId, logDirs, user); // randomly choose the local directory Path appStorageDir = getWorkingDir(localDirs, user, appId); String tokenFn = String.format(ContainerLocalizer.TOKEN_FILE_NAME_FMT, locId); Path tokenDst = new Path(appStorageDir, tokenFn); copyFile(nmPrivateContainerTokensPath, tokenDst, user); LOG.info("Copying from " + nmPrivateContainerTokensPath + " to " + tokenDst); FileContext localizerFc = FileContext.getFileContext( lfs.getDefaultFileSystem(), getConf()); localizerFc.setUMask(lfs.getUMask()); localizerFc.setWorkingDirectory(appStorageDir); LOG.info("Localizer CWD set to " + appStorageDir + " = " + localizerFc.getWorkingDirectory()); ContainerLocalizer localizer = new ContainerLocalizer(localizerFc, user, appId, locId, getPaths(localDirs), RecordFactoryProvider.getRecordFactory(getConf())); // TODO: DO it over RPC for maintaining similarity? localizer.runLocalization(nmAddr); }
copyFile(nmPrivateContainerTokensPath, tokenDst, user); LOG.info("Copying from " + nmPrivateContainerTokensPath + " to " + tokenDst); lfs.setWorkingDirectory(appStorageDir); LOG.info("CWD set to " + appStorageDir + " = " + lfs.getWorkingDirectory());
lfs.getDefaultFileSystem(), getConf()); localizerFc.setUMask(lfs.getUMask()); localizerFc.setWorkingDirectory(appStorageDir); LOG.info("Localizer CWD set to " + appStorageDir + " = " + localizerFc.getWorkingDirectory());
fc.setWorkingDirectory(new Path(wdDir)); // in case testdir relative to wd. Log.info("Working dir is: " + fc.getWorkingDirectory());
fc.setWorkingDirectory(new Path(wdDir)); // in case testdir relative to wd. Log.info("Working dir is: " + fc.getWorkingDirectory());
FileContext.getFileContext(lfs.getDefaultFileSystem(), getConf()); localizerFc.setUMask(lfs.getUMask()); localizerFc.setWorkingDirectory(appStorageDir); LOG.info("Localizer CWD set to " + appStorageDir + " = " + localizerFc.getWorkingDirectory());