Search in sources :

Example 76 with UnderFileSystem

use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.

the class Format method formatFolder.

private static boolean formatFolder(String name, String folder) throws IOException {
    UnderFileSystem ufs = UnderFileSystem.Factory.get(folder);
    LOG.info("Formatting {}:{}", name, folder);
    if (ufs.isDirectory(folder)) {
        for (UnderFileStatus p : ufs.listStatus(folder)) {
            String childPath = PathUtils.concatPath(folder, p.getName());
            boolean failedToDelete;
            if (p.isDirectory()) {
                failedToDelete = !ufs.deleteDirectory(childPath, DeleteOptions.defaults().setRecursive(true));
            } else {
                failedToDelete = !ufs.deleteFile(childPath);
            }
            if (failedToDelete) {
                LOG.info("Failed to delete {}", childPath);
                return false;
            }
        }
    } else if (!ufs.mkdirs(folder)) {
        LOG.info("Failed to create {}:{}", name, folder);
        return false;
    }
    return true;
}
Also used : UnderFileStatus(alluxio.underfs.UnderFileStatus) UnderFileSystem(alluxio.underfs.UnderFileSystem)

Example 77 with UnderFileSystem

use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.

the class CheckConsistencyIntegrationTest method largeTree.

/**
   * Tests the {@link FileSystemMaster#checkConsistency(AlluxioURI, CheckConsistencyOptions)} method
   * when some files are consistent in a larger inode tree.
   */
@Test
public void largeTree() throws Exception {
    CreateDirectoryOptions dirOptions = CreateDirectoryOptions.defaults().setWriteType(WriteType.CACHE_THROUGH);
    CreateFileOptions fileOptions = CreateFileOptions.defaults().setWriteType(WriteType.CACHE_THROUGH);
    AlluxioURI nestedDir = DIRECTORY.join("/dir2");
    AlluxioURI topLevelFile = new AlluxioURI("/file");
    AlluxioURI thirdLevelFile = nestedDir.join("/file");
    mFileSystem.createDirectory(nestedDir, dirOptions);
    mFileSystem.createFile(topLevelFile, fileOptions).close();
    mFileSystem.createFile(thirdLevelFile, fileOptions).close();
    String ufsDirectory = mFileSystem.getStatus(nestedDir).getUfsPath();
    UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsDirectory);
    ufs.deleteDirectory(ufsDirectory, DeleteOptions.defaults().setRecursive(true));
    List<AlluxioURI> expected = Lists.newArrayList(nestedDir, thirdLevelFile);
    List<AlluxioURI> result = mFileSystemMaster.checkConsistency(new AlluxioURI("/"), CheckConsistencyOptions.defaults());
    Collections.sort(expected);
    Collections.sort(result);
    Assert.assertEquals(expected, result);
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) CreateDirectoryOptions(alluxio.client.file.options.CreateDirectoryOptions) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 78 with UnderFileSystem

use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.

the class CheckConsistencyIntegrationTest method partiallyInconsistent.

/**
   * Tests the {@link FileSystemMaster#checkConsistency(AlluxioURI, CheckConsistencyOptions)} method
   * when some files are consistent.
   */
@Test
public void partiallyInconsistent() throws Exception {
    String ufsFile = mFileSystem.getStatus(FILE).getUfsPath();
    UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsFile);
    ufs.deleteFile(ufsFile);
    List<AlluxioURI> expected = Lists.newArrayList(FILE);
    Assert.assertEquals(expected, mFileSystemMaster.checkConsistency(new AlluxioURI("/"), CheckConsistencyOptions.defaults()));
}
Also used : UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 79 with UnderFileSystem

use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.

the class CheckConsistencyIntegrationTest method inconsistentFile.

/**
   * Tests the {@link FileSystemMaster#checkConsistency(AlluxioURI, CheckConsistencyOptions)} method
   * when running on a file that is inconsistent.
   */
@Test
public void inconsistentFile() throws Exception {
    String ufsFile = mFileSystem.getStatus(FILE).getUfsPath();
    UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsFile);
    ufs.deleteFile(ufsFile);
    List<AlluxioURI> expected = Lists.newArrayList(FILE);
    Assert.assertEquals(expected, mFileSystemMaster.checkConsistency(FILE, CheckConsistencyOptions.defaults()));
}
Also used : UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 80 with UnderFileSystem

use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.

the class MountPointInfo method setUfsInfo.

/**
   * Sets information related to under filesystem, including its uri, type, storage usage.
   *
   * @param ufsUri the under filesystem uri
   */
public void setUfsInfo(String ufsUri) {
    mUfsUri = ufsUri;
    UnderFileSystem ufs = UnderFileSystem.Factory.get(mUfsUri);
    mUfsType = ufs.getUnderFSType();
    try {
        mUfsCapacityBytes = ufs.getSpace(mUfsUri, UnderFileSystem.SpaceType.SPACE_TOTAL);
    } catch (IOException e) {
        mUfsCapacityBytes = UNKNOWN_CAPACITY_BYTES;
    }
    try {
        mUfsUsedBytes = ufs.getSpace(mUfsUri, UnderFileSystem.SpaceType.SPACE_USED);
    } catch (IOException e) {
        mUfsUsedBytes = UNKNOWN_USED_BYTES;
    }
}
Also used : IOException(java.io.IOException) UnderFileSystem(alluxio.underfs.UnderFileSystem)

Aggregations

UnderFileSystem (alluxio.underfs.UnderFileSystem)123 AlluxioURI (alluxio.AlluxioURI)59 Test (org.junit.Test)44 IOException (java.io.IOException)37 MountTable (alluxio.master.file.meta.MountTable)24 URIStatus (alluxio.client.file.URIStatus)17 Mode (alluxio.security.authorization.Mode)15 UfsManager (alluxio.underfs.UfsManager)13 UfsStatus (alluxio.underfs.UfsStatus)13 InvalidPathException (alluxio.exception.InvalidPathException)12 Inode (alluxio.master.file.meta.Inode)12 OutputStream (java.io.OutputStream)12 ArrayList (java.util.ArrayList)12 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)11 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)9 AccessControlException (alluxio.exception.AccessControlException)8 BlockInfoException (alluxio.exception.BlockInfoException)7 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)7 InodeDirectory (alluxio.master.file.meta.InodeDirectory)7 InodeFile (alluxio.master.file.meta.InodeFile)7