Search in sources :

Example 1 with IgfsParentNotDirectoryException

use of org.apache.ignite.igfs.IgfsParentNotDirectoryException in project ignite by apache.

the class IgfsMetaManager method mkdirs.

/**
     * Mkdirs implementation.
     *
     * @param path The path to create.
     * @param props The properties to use for created directories.
     * @return True if a directory was created during the operation.
     * @throws IgniteCheckedException If a non-directory file exists on the requested path, and in case of other errors.
     */
boolean mkdirs(final IgfsPath path, final Map<String, String> props) throws IgniteCheckedException {
    validTxState(false);
    while (true) {
        if (busyLock.enterBusy()) {
            try {
                // Prepare path IDs.
                IgfsPathIds pathIds = pathIds(path);
                // Prepare lock IDs. Essentially, they consist of two parts: existing IDs and potential new IDs.
                Set<IgniteUuid> lockIds = new TreeSet<>(PATH_ID_SORTING_COMPARATOR);
                pathIds.addExistingIds(lockIds, relaxed);
                pathIds.addSurrogateIds(lockIds);
                // Start TX.
                try (GridNearTxLocal tx = startTx()) {
                    final Map<IgniteUuid, IgfsEntryInfo> lockInfos = lockIds(lockIds);
                    if (!pathIds.verifyIntegrity(lockInfos, relaxed))
                        // Directory structure changed concurrently. So we simply re-try.
                        continue;
                    // Check if the whole structure is already in place.
                    if (pathIds.allExists()) {
                        if (lockInfos.get(pathIds.lastExistingId()).isDirectory())
                            return false;
                        else
                            throw new IgfsParentNotDirectoryException("Failed to create directory (parent " + "element is not a directory)");
                    }
                    IgfsPathsCreateResult res = createDirectory(pathIds, lockInfos, props);
                    if (res == null)
                        continue;
                    // Commit TX.
                    tx.commit();
                    generateCreateEvents(res.createdPaths(), false);
                    // We are done.
                    return true;
                }
            } finally {
                busyLock.leaveBusy();
            }
        } else
            throw new IllegalStateException("Failed to mkdir because Grid is stopping. [path=" + path + ']');
    }
}
Also used : IgfsParentNotDirectoryException(org.apache.ignite.igfs.IgfsParentNotDirectoryException) TreeSet(java.util.TreeSet) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)

Example 2 with IgfsParentNotDirectoryException

use of org.apache.ignite.igfs.IgfsParentNotDirectoryException in project ignite by apache.

the class IgfsAbstractSelfTest method testMkdirs.

/**
     * Test mkdirs in case both local and remote file systems have the same folder structure.
     *
     * @throws Exception If failed.
     */
@SuppressWarnings("ConstantConditions")
public void testMkdirs() throws Exception {
    if (!propertiesSupported())
        return;
    // mkdirs command doesn't propagate user info.
    Map<String, String> props = properties(null, null, "0555");
    igfs.mkdirs(new IgfsPath("/x"), null);
    checkExist(igfs, igfsSecondary, new IgfsPath("/x"));
    igfs.mkdirs(new IgfsPath("/k/l"), null);
    checkExist(igfs, igfsSecondary, new IgfsPath("/k/l"));
    igfs.mkdirs(new IgfsPath("/x/y"), null);
    checkExist(igfs, igfsSecondary, new IgfsPath("/x/y"));
    igfs.mkdirs(new IgfsPath("/a/b/c/d"), null);
    checkExist(igfs, igfsSecondary, new IgfsPath("/a/b/c/d"));
    igfs.mkdirs(new IgfsPath("/a/b/c/d/e"), null);
    checkExist(igfs, igfsSecondary, new IgfsPath("/a/b/c/d/e"));
    // "f" is a file.
    create(igfs, null, new IgfsPath[] { new IgfsPath("/d/f") });
    checkExist(igfs, igfsSecondary, new IgfsPath("/d/f"));
    assertTrue(igfs.info(new IgfsPath("/d/f")).isFile());
    try {
        igfs.mkdirs(new IgfsPath("/d/f"), null);
        fail("IgfsParentNotDirectoryException expected.");
    } catch (IgfsParentNotDirectoryException ignore) {
    // No-op.
    } catch (IgfsException e) {
        // Currently Ok for Hadoop fs:
        if (!getClass().getSimpleName().startsWith("Hadoop"))
            throw e;
    }
    try {
        igfs.mkdirs(new IgfsPath("/d/f/something/else"), null);
        fail("IgfsParentNotDirectoryException expected.");
    } catch (IgfsParentNotDirectoryException ignore) {
    // No-op.
    } catch (IgfsException e) {
        // Currently Ok for Hadoop fs:
        if (!getClass().getSimpleName().startsWith("Hadoop"))
            throw e;
    }
    create(igfs, paths(DIR, SUBDIR), null);
    igfs.mkdirs(SUBSUBDIR, props);
    // Ensure that directory was created and properties are propagated.
    checkExist(igfs, igfsSecondary, SUBSUBDIR);
    if (permissionsSupported()) {
        if (dual)
            // Check only permissions because user and group will always be present in Hadoop Fs.
            assertEquals(props.get(IgfsUtils.PROP_PERMISSION), igfsSecondary.permissions(SUBSUBDIR.toString()));
        // We check only permission because IGFS client adds username and group name explicitly.
        assertEquals(props.get(IgfsUtils.PROP_PERMISSION), igfs.info(SUBSUBDIR).properties().get(IgfsUtils.PROP_PERMISSION));
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsException(org.apache.ignite.igfs.IgfsException) IgfsParentNotDirectoryException(org.apache.ignite.igfs.IgfsParentNotDirectoryException)

Aggregations

IgfsParentNotDirectoryException (org.apache.ignite.igfs.IgfsParentNotDirectoryException)2 TreeSet (java.util.TreeSet)1 IgfsException (org.apache.ignite.igfs.IgfsException)1 IgfsPath (org.apache.ignite.igfs.IgfsPath)1 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)1 IgniteUuid (org.apache.ignite.lang.IgniteUuid)1