Search in sources :

Example 6 with CreateDirectoryOptions

use of alluxio.client.file.options.CreateDirectoryOptions in project alluxio by Alluxio.

the class FileSystemIntegrationTest method mkdir.

@Test
public void mkdir() throws Exception {
    String uniqPath = PathUtils.uniqPath();
    CreateDirectoryOptions options = CreateDirectoryOptions.defaults().setRecursive(true);
    for (int k = 0; k < 10; k++) {
        mFileSystem.createDirectory(new AlluxioURI(uniqPath + k), options);
        try {
            mFileSystem.createDirectory(new AlluxioURI(uniqPath + k), options);
            Assert.fail("createDirectory should throw FileAlreadyExistsException");
        } catch (FileAlreadyExistsException e) {
            Assert.assertEquals(e.getMessage(), ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(uniqPath + k));
        }
    }
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) CreateDirectoryOptions(alluxio.client.file.options.CreateDirectoryOptions) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 7 with CreateDirectoryOptions

use of alluxio.client.file.options.CreateDirectoryOptions in project alluxio by Alluxio.

the class MkdirCommand method run.

@Override
public void run(CommandLine cl) throws AlluxioException, IOException {
    String[] args = cl.getArgs();
    for (String path : args) {
        AlluxioURI inputPath = new AlluxioURI(path);
        CreateDirectoryOptions options = CreateDirectoryOptions.defaults().setRecursive(true);
        mFileSystem.createDirectory(inputPath, options);
        System.out.println("Successfully created directory " + inputPath);
    }
}
Also used : CreateDirectoryOptions(alluxio.client.file.options.CreateDirectoryOptions) AlluxioURI(alluxio.AlluxioURI)

Example 8 with CreateDirectoryOptions

use of alluxio.client.file.options.CreateDirectoryOptions 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 9 with CreateDirectoryOptions

use of alluxio.client.file.options.CreateDirectoryOptions in project alluxio by Alluxio.

the class JournalIntegrationTest method delete.

/**
   * Tests file and directory creation and deletion.
   */
@Test
public void delete() throws Exception {
    CreateDirectoryOptions recMkdir = CreateDirectoryOptions.defaults().setRecursive(true);
    DeleteOptions recDelete = DeleteOptions.defaults().setRecursive(true);
    for (int i = 0; i < 10; i++) {
        String dirPath = "/i" + i;
        mFileSystem.createDirectory(new AlluxioURI(dirPath), recMkdir);
        for (int j = 0; j < 10; j++) {
            CreateFileOptions option = CreateFileOptions.defaults().setBlockSizeBytes((i + j + 1) * 64);
            String filePath = dirPath + "/j" + j;
            mFileSystem.createFile(new AlluxioURI(filePath), option).close();
            if (j >= 5) {
                mFileSystem.delete(new AlluxioURI(filePath), recDelete);
            }
        }
        if (i >= 5) {
            mFileSystem.delete(new AlluxioURI(dirPath), recDelete);
        }
    }
    mLocalAlluxioCluster.stopFS();
    deleteTestUtil();
    deleteFsMasterJournalLogs();
    deleteTestUtil();
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) DeleteOptions(alluxio.client.file.options.DeleteOptions) CreateDirectoryOptions(alluxio.client.file.options.CreateDirectoryOptions) Matchers.anyString(org.mockito.Matchers.anyString) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 10 with CreateDirectoryOptions

use of alluxio.client.file.options.CreateDirectoryOptions in project alluxio by Alluxio.

the class AbstractFileSystem method mkdirs.

/**
   * Attempts to create a folder with the specified path. Parent directories will be created.
   *
   * @param path path to create
   * @param permission permissions to grant the created folder
   * @return true if the indicated folder is created successfully or already exists
   * @throws IOException if the folder cannot be created
   */
@Override
public boolean mkdirs(Path path, FsPermission permission) throws IOException {
    LOG.debug("mkdirs({}, {})", path, permission);
    if (mStatistics != null) {
        mStatistics.incrementWriteOps(1);
    }
    AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
    CreateDirectoryOptions options = CreateDirectoryOptions.defaults().setRecursive(true).setAllowExists(true).setMode(new Mode(permission.toShort()));
    try {
        mFileSystem.createDirectory(uri, options);
        return true;
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
}
Also used : CreateDirectoryOptions(alluxio.client.file.options.CreateDirectoryOptions) Mode(alluxio.security.authorization.Mode) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Aggregations

CreateDirectoryOptions (alluxio.client.file.options.CreateDirectoryOptions)10 AlluxioURI (alluxio.AlluxioURI)8 Test (org.junit.Test)6 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)4 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 URIStatus (alluxio.client.file.URIStatus)1 DeleteOptions (alluxio.client.file.options.DeleteOptions)1 AlluxioException (alluxio.exception.AlluxioException)1 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)1 Mode (alluxio.security.authorization.Mode)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1