Search in sources :

Example 21 with IgfsFile

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

the class IgfsDualAbstractSelfTest method testListFilesPathMissing.

/**
 * Test list files routine when the path doesn't exist locally.
 *
 * @throws Exception If failed.
 */
public void testListFilesPathMissing() throws Exception {
    create(igfsSecondary, 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 22 with IgfsFile

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

the class IgfsDualAbstractSelfTest method testSetTimesMissingPartially.

/**
 * Test setTimes method when path is partially missing.
 *
 * @throws Exception If failed.
 */
public void testSetTimesMissingPartially() throws Exception {
    if (!timesSupported())
        return;
    create(igfs, paths(DIR, SUBDIR), null);
    createFile(igfsSecondary, FILE, chunk);
    final long MAX_ALIGN_ON_SECOND = (long) Integer.MAX_VALUE * 1000;
    igfs.setTimes(FILE, MAX_ALIGN_ON_SECOND, MAX_ALIGN_ON_SECOND - 1000);
    IgfsFile info = igfs.info(FILE);
    assert info != null;
    assertEquals(MAX_ALIGN_ON_SECOND - 1000, info.accessTime());
    assertEquals(MAX_ALIGN_ON_SECOND, info.modificationTime());
    T2<Long, Long> secondaryTimes = igfsSecondary.times(FILE.toString());
    assertEquals(info.modificationTime(), (long) secondaryTimes.get1());
    assertEquals(info.accessTime(), (long) secondaryTimes.get2());
    try {
        igfs.setTimes(FILE2, MAX_ALIGN_ON_SECOND, MAX_ALIGN_ON_SECOND);
        fail("Exception is not thrown for missing file.");
    } catch (Exception ignore) {
    // No-op.
    }
}
Also used : IgfsFile(org.apache.ignite.igfs.IgfsFile) IgniteException(org.apache.ignite.IgniteException)

Example 23 with IgfsFile

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

the class IgfsAbstractSelfTest method checkRootPropertyUpdate.

/**
 * Check root property update.
 *
 * @throws Exception If failed.
 */
private void checkRootPropertyUpdate(String prop, String setVal, String expGetVal) throws Exception {
    igfs.update(IgfsPath.ROOT, Collections.singletonMap(prop, setVal));
    igfs.clear();
    IgfsFile file = igfs.info(IgfsPath.ROOT);
    assert file != null;
    Map<String, String> props = file.properties();
    assertEquals(expGetVal, props.get(prop));
}
Also used : IgfsFile(org.apache.ignite.igfs.IgfsFile)

Example 24 with IgfsFile

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

the class HadoopIgfsSecondaryFileSystemDelegateImpl method listFiles.

/**
 * {@inheritDoc}
 */
@Override
public Collection<IgfsFile> listFiles(IgfsPath path) {
    try {
        FileStatus[] statuses = fileSystemForUser().listStatus(convert(path));
        if (statuses == null)
            throw new IgfsPathNotFoundException("Failed to list files (path not found): " + path);
        Collection<IgfsFile> res = new ArrayList<>(statuses.length);
        for (FileStatus s : statuses) {
            IgfsEntryInfo fsInfo = s.isDirectory() ? IgfsUtils.createDirectory(IgniteUuid.randomUuid(), null, properties(s), s.getAccessTime(), s.getModificationTime()) : IgfsUtils.createFile(IgniteUuid.randomUuid(), (int) s.getBlockSize(), s.getLen(), null, null, false, properties(s), s.getAccessTime(), s.getModificationTime());
            res.add(new IgfsFileImpl(new IgfsPath(path, s.getPath().getName()), fsInfo, 1));
        }
        return res;
    } catch (FileNotFoundException ignored) {
        throw new IgfsPathNotFoundException("Failed to list files (path not found): " + path);
    } catch (IOException e) {
        throw handleSecondaryFsError(e, "Failed to list statuses due to secondary file system exception: " + path);
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) FileStatus(org.apache.hadoop.fs.FileStatus) ArrayList(java.util.ArrayList) IgfsEntryInfo(org.apache.ignite.internal.processors.igfs.IgfsEntryInfo) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException) IgfsFile(org.apache.ignite.igfs.IgfsFile) IgfsFileImpl(org.apache.ignite.internal.processors.igfs.IgfsFileImpl)

Example 25 with IgfsFile

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

the class IgniteHadoopFileSystemAbstractSelfTest method testZeroReplicationFactor.

/**
 * @throws Exception If failed.
 */
public void testZeroReplicationFactor() throws Exception {
    // This test doesn't make sense for any mode except of PRIMARY.
    if (mode == PRIMARY) {
        Path igfsHome = new Path(PRIMARY_URI);
        Path file = new Path(igfsHome, "someFile");
        try (FSDataOutputStream out = fs.create(file, (short) 0)) {
            out.write(new byte[1024 * 1024]);
        }
        IgniteFileSystem igfs = grid(0).fileSystem("igfs");
        IgfsPath filePath = new IgfsPath("/someFile");
        IgfsFile fileInfo = igfs.info(filePath);
        awaitPartitionMapExchange();
        Collection<IgfsBlockLocation> locations = igfs.affinity(filePath, 0, fileInfo.length());
        assertEquals(1, locations.size());
        IgfsBlockLocation location = F.first(locations);
        assertEquals(1, location.nodeIds().size());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsPath(org.apache.ignite.igfs.IgfsPath) IgniteFileSystem(org.apache.ignite.IgniteFileSystem) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) IgfsBlockLocation(org.apache.ignite.igfs.IgfsBlockLocation) 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