Search in sources :

Example 16 with IgfsFile

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

the class IgfsImpl method summary0.

/**
 * Get summary for path.
 *
 * @param path Path.
 * @return Summary.
 * @throws IgniteCheckedException If failed.
 */
private IgfsPathSummary summary0(IgfsPath path) throws IgniteCheckedException {
    IgfsFile info = info(path);
    if (info == null)
        throw new IgfsPathNotFoundException("Failed to get path summary (path not found): " + path);
    IgfsPathSummary sum = new IgfsPathSummary(path);
    summaryRecursive(info, sum);
    return sum;
}
Also used : IgfsPathSummary(org.apache.ignite.igfs.IgfsPathSummary) IgfsFile(org.apache.ignite.igfs.IgfsFile) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException)

Example 17 with IgfsFile

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

the class IgfsMetaManager method synchronize.

/**
 * Synchronize directory structure with the secondary file system.
 *
 * @param fs Secondary file system.
 * @param startPath Start path.
 * @param startPathInfo Start path info.
 * @param endPath End path.
 * @param strict Whether all paths must exist in the secondary file system.
 * @param created Optional map where data about all created values is put.
 * @return File info of the end path.
 * @throws IgniteCheckedException If failed.
 */
private IgfsEntryInfo synchronize(IgfsSecondaryFileSystem fs, IgfsPath startPath, IgfsEntryInfo startPathInfo, IgfsPath endPath, boolean strict, @Nullable Map<IgfsPath, IgfsEntryInfo> created) throws IgniteCheckedException {
    assert fs != null;
    assert startPath != null && startPathInfo != null && endPath != null;
    validTxState(true);
    IgfsEntryInfo parentInfo = startPathInfo;
    List<String> components = endPath.components();
    IgfsPath curPath = startPath;
    for (int i = startPath.components().size(); i < components.size(); i++) {
        curPath = new IgfsPath(curPath, components.get(i));
        if (created != null && created.containsKey(curPath))
            // Re-use already created info.
            parentInfo = created.get(curPath);
        else {
            // Get file status from the secondary file system.
            IgfsFile status;
            try {
                status = fs.info(curPath);
            } catch (IgniteException e) {
                throw new IgniteCheckedException("Failed to get path information: " + e, e);
            }
            if (status != null) {
                if (!status.isDirectory() && !curPath.equals(endPath))
                    throw new IgniteCheckedException("Failed to create path the locally because secondary file " + "system directory structure was modified concurrently and the path is not a directory as " + "expected: " + curPath);
            } else {
                if (strict) {
                    throw new IgniteCheckedException("Failed to create path locally due to secondary file system " + "exception: " + curPath);
                } else if (created != null)
                    created.put(curPath.parent(), parentInfo);
                return null;
            }
            // Recreate the path locally.
            IgfsEntryInfo curInfo = status.isDirectory() ? IgfsUtils.createDirectory(IgniteUuid.randomUuid(), null, status.properties(), status.accessTime(), status.modificationTime()) : IgfsUtils.createFile(IgniteUuid.randomUuid(), igfsCtx.configuration().getBlockSize(), status.length(), null, null, igfsCtx.igfs().evictExclude(curPath, false), status.properties(), status.accessTime(), status.modificationTime());
            assert parentInfo != null;
            IgniteUuid oldId = putIfAbsentNonTx(parentInfo.id(), components.get(i), curInfo);
            if (oldId != null)
                curInfo = info(oldId);
            if (created != null)
                created.put(curPath, curInfo);
            parentInfo = curInfo;
        }
    }
    return parentInfo;
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgfsFile(org.apache.ignite.igfs.IgfsFile)

Example 18 with IgfsFile

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

the class IgfsAbstractSelfTest method checkSetTimes.

/**
 * Check setTimes logic for path.
 *
 * @param path Path.
 * @throws Exception If failed.
 */
private void checkSetTimes(IgfsPath path) throws Exception {
    if (timesSupported()) {
        IgfsFile info = igfs.info(path);
        T2<Long, Long> secondaryTimes = dual ? igfsSecondary.times(path.toString()) : null;
        assert info != null;
        // Change nothing.
        igfs.setTimes(path, -1, -1);
        IgfsFile newInfo = igfs.info(path);
        assert newInfo != null;
        assertEquals(info.accessTime(), newInfo.accessTime());
        assertEquals(info.modificationTime(), newInfo.modificationTime());
        if (dual) {
            T2<Long, Long> newSecondaryTimes = igfsSecondary.times(path.toString());
            assertEquals(secondaryTimes.get1(), newSecondaryTimes.get1());
            assertEquals(secondaryTimes.get2(), newSecondaryTimes.get2());
        }
        // Change only access time.
        igfs.setTimes(path, -1, info.accessTime() + 1000);
        newInfo = igfs.info(path);
        assert newInfo != null;
        assertEquals(info.accessTime() + 1000, newInfo.accessTime());
        assertEquals(info.modificationTime(), newInfo.modificationTime());
        if (dual) {
            T2<Long, Long> newSecondaryTimes = igfsSecondary.times(path.toString());
            assertEquals(newInfo.accessTime(), (long) newSecondaryTimes.get2());
            assertEquals(secondaryTimes.get1(), newSecondaryTimes.get1());
        }
        // Change only modification time.
        igfs.setTimes(path, info.modificationTime() + 1000, -1);
        newInfo = igfs.info(path);
        assert newInfo != null;
        assertEquals(info.accessTime() + 1000, newInfo.accessTime());
        assertEquals(info.modificationTime() + 1000, newInfo.modificationTime());
        if (dual) {
            T2<Long, Long> newSecondaryTimes = igfsSecondary.times(path.toString());
            assertEquals(newInfo.accessTime(), (long) newSecondaryTimes.get2());
        }
        // Change both.
        igfs.setTimes(path, info.modificationTime() + 2000, info.accessTime() + 2000);
        newInfo = igfs.info(path);
        assert newInfo != null;
        assertEquals(info.accessTime() + 2000, newInfo.accessTime());
        assertEquals(info.modificationTime() + 2000, newInfo.modificationTime());
        if (dual) {
            T2<Long, Long> newSecondaryTimes = igfsSecondary.times(path.toString());
            assertEquals(newInfo.modificationTime(), (long) newSecondaryTimes.get1());
            assertEquals(newInfo.accessTime(), (long) newSecondaryTimes.get2());
        }
    }
}
Also used : IgfsFile(org.apache.ignite.igfs.IgfsFile)

Example 19 with IgfsFile

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

the class IgfsAbstractSelfTest method testListFiles.

/**
 * Test list files routine.
 *
 * @throws Exception If failed.
 */
public void testListFiles() throws Exception {
    create(igfs, paths(DIR, SUBDIR, SUBSUBDIR), paths(FILE));
    Collection<IgfsFile> paths = igfs.listFiles(SUBDIR);
    assert paths != null;
    assert paths.size() == 2;
    Iterator<IgfsFile> iter = paths.iterator();
    IgfsFile path1 = iter.next();
    IgfsFile path2 = iter.next();
    assert (SUBSUBDIR.equals(path1.path()) && FILE.equals(path2.path())) || (FILE.equals(path1.path()) && SUBSUBDIR.equals(path2.path()));
}
Also used : IgfsFile(org.apache.ignite.igfs.IgfsFile)

Example 20 with IgfsFile

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

the class IgfsDualAbstractSelfTest method testInfoPathMissing.

/**
 * Test info routine when the path doesn't exist locally.
 *
 * @throws Exception If failed.
 */
public void testInfoPathMissing() throws Exception {
    create(igfsSecondary, paths(DIR), null);
    create(igfs, null, null);
    IgfsFile info = igfs.info(DIR);
    assert info != null;
    assertEquals(DIR, info.path());
}
Also used : IgfsFile(org.apache.ignite.igfs.IgfsFile)

Aggregations

IgfsFile (org.apache.ignite.igfs.IgfsFile)30 IgfsPath (org.apache.ignite.igfs.IgfsPath)13 FileNotFoundException (java.io.FileNotFoundException)6 IgniteException (org.apache.ignite.IgniteException)6 IgfsBlockLocation (org.apache.ignite.igfs.IgfsBlockLocation)5 ArrayList (java.util.ArrayList)4 FileStatus (org.apache.hadoop.fs.FileStatus)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)4 IgniteUuid (org.apache.ignite.lang.IgniteUuid)4 IOException (java.io.IOException)3 IgniteFileSystem (org.apache.ignite.IgniteFileSystem)3 IgfsException (org.apache.ignite.igfs.IgfsException)3 Nullable (org.jetbrains.annotations.Nullable)3 File (java.io.File)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)2 Path (org.apache.hadoop.fs.Path)2