Search in sources :

Example 16 with AbstractFileSystem

use of org.apache.hadoop.fs.AbstractFileSystem in project hadoop by apache.

the class TestChRootedFs method testDeleteSnapshot.

@Test(timeout = 30000)
public void testDeleteSnapshot() throws Exception {
    Path snapRootPath = new Path("/snapPath");
    Path chRootedSnapRootPath = new Path(Path.getPathWithoutSchemeAndAuthority(chrootedTo), "snapPath");
    AbstractFileSystem baseFs = Mockito.spy(fc.getDefaultFileSystem());
    ChRootedFs chRootedFs = new ChRootedFs(baseFs, chrootedTo);
    Mockito.doNothing().when(baseFs).deleteSnapshot(chRootedSnapRootPath, "snap1");
    chRootedFs.deleteSnapshot(snapRootPath, "snap1");
    Mockito.verify(baseFs).deleteSnapshot(chRootedSnapRootPath, "snap1");
}
Also used : Path(org.apache.hadoop.fs.Path) AbstractFileSystem(org.apache.hadoop.fs.AbstractFileSystem) ChRootedFs(org.apache.hadoop.fs.viewfs.ChRootedFs) Test(org.junit.Test)

Example 17 with AbstractFileSystem

use of org.apache.hadoop.fs.AbstractFileSystem in project hadoop by apache.

the class TestChRootedFs method testCreateSnapshot.

@Test(timeout = 30000)
public void testCreateSnapshot() throws Exception {
    Path snapRootPath = new Path("/snapPath");
    Path chRootedSnapRootPath = new Path(Path.getPathWithoutSchemeAndAuthority(chrootedTo), "snapPath");
    AbstractFileSystem baseFs = Mockito.spy(fc.getDefaultFileSystem());
    ChRootedFs chRootedFs = new ChRootedFs(baseFs, chrootedTo);
    Mockito.doReturn(snapRootPath).when(baseFs).createSnapshot(chRootedSnapRootPath, "snap1");
    Assert.assertEquals(snapRootPath, chRootedFs.createSnapshot(snapRootPath, "snap1"));
    Mockito.verify(baseFs).createSnapshot(chRootedSnapRootPath, "snap1");
}
Also used : Path(org.apache.hadoop.fs.Path) AbstractFileSystem(org.apache.hadoop.fs.AbstractFileSystem) ChRootedFs(org.apache.hadoop.fs.viewfs.ChRootedFs) Test(org.junit.Test)

Example 18 with AbstractFileSystem

use of org.apache.hadoop.fs.AbstractFileSystem in project hadoop by apache.

the class TestChRootedFs method testIsValidNameValidInBaseFs.

@Test
public void testIsValidNameValidInBaseFs() throws Exception {
    AbstractFileSystem baseFs = Mockito.spy(fc.getDefaultFileSystem());
    ChRootedFs chRootedFs = new ChRootedFs(baseFs, new Path("/chroot"));
    Mockito.doReturn(true).when(baseFs).isValidName(Mockito.anyString());
    Assert.assertTrue(chRootedFs.isValidName("/test"));
    Mockito.verify(baseFs).isValidName("/chroot/test");
}
Also used : AbstractFileSystem(org.apache.hadoop.fs.AbstractFileSystem) Path(org.apache.hadoop.fs.Path) ChRootedFs(org.apache.hadoop.fs.viewfs.ChRootedFs) Test(org.junit.Test)

Example 19 with AbstractFileSystem

use of org.apache.hadoop.fs.AbstractFileSystem in project hadoop by apache.

the class ViewFs method listStatus.

@Override
public FileStatus[] listStatus(final Path f) throws AccessControlException, FileNotFoundException, UnresolvedLinkException, IOException {
    InodeTree.ResolveResult<AbstractFileSystem> res = fsState.resolve(getUriPath(f), true);
    FileStatus[] statusLst = res.targetFileSystem.listStatus(res.remainingPath);
    if (!res.isInternalDir()) {
        // We need to change the name in the FileStatus as described in
        // {@link #getFileStatus }
        ChRootedFs targetFs;
        targetFs = (ChRootedFs) res.targetFileSystem;
        int i = 0;
        for (FileStatus status : statusLst) {
            String suffix = targetFs.stripOutRoot(status.getPath());
            statusLst[i++] = new ViewFsFileStatus(status, this.makeQualified(suffix.length() == 0 ? f : new Path(res.resolvedPath, suffix)));
        }
    }
    return statusLst;
}
Also used : AbstractFileSystem(org.apache.hadoop.fs.AbstractFileSystem) Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus)

Example 20 with AbstractFileSystem

use of org.apache.hadoop.fs.AbstractFileSystem in project hadoop by apache.

the class ViewFs method getFileStatus.

@Override
public FileStatus getFileStatus(final Path f) throws AccessControlException, FileNotFoundException, UnresolvedLinkException, IOException {
    InodeTree.ResolveResult<AbstractFileSystem> res = fsState.resolve(getUriPath(f), true);
    //  FileStatus#getPath is a fully qualified path relative to the root of 
    // target file system.
    // We need to change it to viewfs URI - relative to root of mount table.
    // The implementors of RawLocalFileSystem were trying to be very smart.
    // They implement FileStatus#getOwener lazily -- the object
    // returned is really a RawLocalFileSystem that expect the
    // FileStatus#getPath to be unchanged so that it can get owner when needed.
    // Hence we need to interpose a new ViewFsFileStatus that works around.
    FileStatus status = res.targetFileSystem.getFileStatus(res.remainingPath);
    return new ViewFsFileStatus(status, this.makeQualified(f));
}
Also used : AbstractFileSystem(org.apache.hadoop.fs.AbstractFileSystem) FileStatus(org.apache.hadoop.fs.FileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus)

Aggregations

AbstractFileSystem (org.apache.hadoop.fs.AbstractFileSystem)20 Test (org.junit.Test)16 Path (org.apache.hadoop.fs.Path)13 Configuration (org.apache.hadoop.conf.Configuration)9 ChRootedFs (org.apache.hadoop.fs.viewfs.ChRootedFs)5 URI (java.net.URI)4 FileContext (org.apache.hadoop.fs.FileContext)4 FileStatus (org.apache.hadoop.fs.FileStatus)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)3 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)3 FileSystem (org.apache.hadoop.fs.FileSystem)2 LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)2 LocalDirsHandlerService (org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService)2 LocalizationProtocol (org.apache.hadoop.yarn.server.nodemanager.api.LocalizationProtocol)2 NMNullStateStoreService (org.apache.hadoop.yarn.server.nodemanager.recovery.NMNullStateStoreService)2 Principal (java.security.Principal)1 Random (java.util.Random)1 Scanner (java.util.Scanner)1