Search in sources :

Example 86 with UnderFileSystem

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

the class GlusterFSUnderFileSystemFactoryTest method createGlusterFS.

/**
   * Tests the {@link UnderFileSystem#create(String)} method.
   */
@Test
public void createGlusterFS() throws Exception {
    // Using Assume will mark the tests as skipped rather than passed which provides a truer
    // indication of their status
    Assume.assumeTrue(!StringUtils.isEmpty(mMount));
    Assume.assumeTrue(!StringUtils.isEmpty(mVolume));
    UnderFileSystem gfs = UnderFileSystem.Factory.get("glusterfs:///");
    Assert.assertNotNull(gfs.create("alluxio_test"));
}
Also used : UnderFileSystem(alluxio.underfs.UnderFileSystem) Test(org.junit.Test)

Example 87 with UnderFileSystem

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

the class FileOutStream method close.

@Override
public void close() throws IOException {
    if (mClosed) {
        return;
    }
    try {
        if (mCurrentBlockOutStream != null) {
            mPreviousBlockOutStreams.add(mCurrentBlockOutStream);
        }
        CompleteFileOptions options = CompleteFileOptions.defaults();
        if (mUnderStorageType.isSyncPersist()) {
            if (mUfsDelegation) {
                mUnderStorageOutputStream.close();
                if (mCanceled) {
                    mFileSystemWorkerClient.cancelUfsFile(mUfsFileId, CancelUfsFileOptions.defaults());
                } else {
                    long len = mFileSystemWorkerClient.completeUfsFile(mUfsFileId, CompleteUfsFileOptions.defaults());
                    options.setUfsLength(len);
                }
            } else {
                UnderFileSystem ufs = UnderFileSystem.Factory.get(mUfsPath);
                if (mCanceled) {
                    // TODO(yupeng): Handle this special case in under storage integrations.
                    mUnderStorageOutputStream.close();
                    ufs.deleteFile(mUfsPath);
                } else {
                    mUnderStorageOutputStream.flush();
                    mUnderStorageOutputStream.close();
                    options.setUfsLength(ufs.getFileSize(mUfsPath));
                }
            }
        }
        if (mAlluxioStorageType.isStore()) {
            if (mCanceled) {
                for (OutputStream bos : mPreviousBlockOutStreams) {
                    outStreamCancel(bos);
                }
            } else {
                for (OutputStream bos : mPreviousBlockOutStreams) {
                    bos.close();
                }
            }
        }
        // Complete the file if it's ready to be completed.
        if (!mCanceled && (mUnderStorageType.isSyncPersist() || mAlluxioStorageType.isStore())) {
            try (CloseableResource<FileSystemMasterClient> masterClient = mContext.acquireMasterClientResource()) {
                masterClient.get().completeFile(mUri, options);
            }
        }
        if (mUnderStorageType.isAsyncPersist()) {
            scheduleAsyncPersist();
        }
    } catch (AlluxioException e) {
        throw mCloser.rethrow(new IOException(e));
    } catch (Throwable e) {
        // IOException will be thrown as-is
        throw mCloser.rethrow(e);
    } finally {
        mClosed = true;
        mCloser.close();
    }
}
Also used : OutputStream(java.io.OutputStream) CompleteFileOptions(alluxio.client.file.options.CompleteFileOptions) IOException(java.io.IOException) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioException(alluxio.exception.AlluxioException)

Example 88 with UnderFileSystem

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

the class CheckConsistencyCommandTest method inconsistent.

/**
   * Tests the check consistency shell command correctly identifies inconsistent files in a subtree.
   */
@Test
public void inconsistent() throws Exception {
    FileSystemTestUtils.createByteFile(mFileSystem, "/testRoot/testFileA", WriteType.CACHE_THROUGH, 10);
    FileSystemTestUtils.createByteFile(mFileSystem, "/testRoot/testDir/testFileB", WriteType.CACHE_THROUGH, 20);
    String ufsPath = mFileSystem.getStatus(new AlluxioURI("/testRoot/testDir")).getUfsPath();
    UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsPath);
    ufs.deleteDirectory(ufsPath, DeleteOptions.defaults().setRecursive(true));
    mFsShell.run("checkConsistency", "/testRoot");
    StringBuilder expected = new StringBuilder();
    expected.append("The following files are inconsistent:\n");
    expected.append("/testRoot/testDir\n");
    expected.append("/testRoot/testDir/testFileB\n");
    Assert.assertEquals(expected.toString(), mOutput.toString());
    mOutput.reset();
    mFsShell.run("checkConsistency", "-r", "/testRoot");
    String res = mOutput.toString();
    Assert.assertTrue(res.contains("/testRoot" + " has: " + "2 inconsistent files.\n") && res.contains("repairing path: " + "/testRoot/testDir\n") && res.contains("repairing path: " + "/testRoot/testDir/testFileB\n"));
    Assert.assertTrue(!mFileSystem.exists(new AlluxioURI("/testRoot/testDir")));
    Assert.assertTrue(!mFileSystem.exists(new AlluxioURI("/testRoot/testDir/testFileB")));
    FileSystemTestUtils.createByteFile(mFileSystem, "/testRoot/testDir/testFileB", WriteType.CACHE_THROUGH, 20);
    ufsPath = mFileSystem.getStatus(new AlluxioURI("/testRoot/testDir/testFileB")).getUfsPath();
    ufs.deleteFile(ufsPath);
    OutputStream outputStream = ufs.create(ufsPath);
    byte[] bytes = { 1, 2, 3 };
    outputStream.write(bytes);
    outputStream.close();
    mOutput.reset();
    mFsShell.run("checkConsistency", "-r", "/testRoot");
    res = mOutput.toString();
    Assert.assertTrue(res.contains("/testRoot" + " has: " + "1 inconsistent files.\n") && res.contains("repairing path: " + "/testRoot/testDir/testFileB\n"));
    Assert.assertTrue(mFileSystem.exists(new AlluxioURI("/testRoot/testDir/testFileB")));
    Assert.assertTrue(3 == mFileSystem.getStatus(new AlluxioURI("/testRoot/testDir/testFileB")).getLength());
}
Also used : OutputStream(java.io.OutputStream) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) AbstractAlluxioShellTest(alluxio.shell.AbstractAlluxioShellTest)

Example 89 with UnderFileSystem

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

the class PersistCommandTest method persistWithAncestorPermission.

@Test
public void persistWithAncestorPermission() throws Exception {
    String ufsRoot = PathUtils.concatPath(Configuration.get(PropertyKey.UNDERFS_ADDRESS));
    UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsRoot);
    // Skip non-local and non-HDFS UFSs.
    Assume.assumeTrue(UnderFileSystemUtils.isLocal(ufs) || UnderFileSystemUtils.isHdfs(ufs));
    AlluxioURI testFile = new AlluxioURI("/grand/parent/file");
    AlluxioURI grandParent = new AlluxioURI("/grand");
    Mode grandParentMode = new Mode((short) 0777);
    FileSystemTestUtils.createByteFile(mFileSystem, testFile, WriteType.MUST_CACHE, 10);
    URIStatus status = mFileSystem.getStatus(testFile);
    Assert.assertFalse(status.isPersisted());
    mFileSystem.setAttribute(grandParent, SetAttributeOptions.defaults().setMode(grandParentMode));
    int ret = mFsShell.run("persist", testFile.toString());
    Assert.assertEquals(0, ret);
    checkFilePersisted(testFile, 10);
    // Check the permission of the created file and ancestor dir are in-sync between Alluxio and UFS
    short fileMode = (short) status.getMode();
    short parentMode = (short) mFileSystem.getStatus(testFile.getParent()).getMode();
    Assert.assertEquals(fileMode, ufs.getMode(PathUtils.concatPath(ufsRoot, testFile)));
    Assert.assertEquals(parentMode, ufs.getMode(PathUtils.concatPath(ufsRoot, testFile.getParent())));
    Assert.assertEquals(grandParentMode, new Mode(ufs.getMode(PathUtils.concatPath(ufsRoot, grandParent))));
}
Also used : Mode(alluxio.security.authorization.Mode) UnderFileSystem(alluxio.underfs.UnderFileSystem) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) AlluxioShellUtilsTest(alluxio.shell.AlluxioShellUtilsTest) AbstractAlluxioShellTest(alluxio.shell.AbstractAlluxioShellTest)

Example 90 with UnderFileSystem

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

the class UfsJournal method isFormatted.

@Override
public boolean isFormatted() throws IOException {
    UfsStatus[] files;
    try (UnderFileSystem ufs = UnderFileSystem.Factory.create(mLocation.toString(), UnderFileSystemConfiguration.defaults(ServerConfiguration.global()))) {
        files = ufs.listStatus(mLocation.toString());
    }
    if (files == null) {
        return false;
    }
    // Search for the format file.
    String formatFilePrefix = ServerConfiguration.getString(PropertyKey.MASTER_FORMAT_FILE_PREFIX);
    for (UfsStatus file : files) {
        if (file.getName().startsWith(formatFilePrefix)) {
            return true;
        }
    }
    return false;
}
Also used : UfsStatus(alluxio.underfs.UfsStatus) 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