Search in sources :

Example 1 with IgfsFile

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

the class IgfsTask method map.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public final Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable IgfsTaskArgs<T> args) {
    assert ignite != null;
    assert args != null;
    IgniteFileSystem fs = ignite.fileSystem(args.igfsName());
    IgfsProcessorAdapter igfsProc = ((IgniteKernal) ignite).context().igfs();
    Map<ComputeJob, ClusterNode> splitMap = new HashMap<>();
    Map<UUID, ClusterNode> nodes = mapSubgrid(subgrid);
    for (IgfsPath path : args.paths()) {
        IgfsFile file = fs.info(path);
        if (file == null) {
            if (args.skipNonExistentFiles())
                continue;
            else
                throw new IgniteException("Failed to process IGFS file because it doesn't exist: " + path);
        }
        Collection<IgfsBlockLocation> aff = fs.affinity(path, 0, file.length(), args.maxRangeLength());
        long totalLen = 0;
        for (IgfsBlockLocation loc : aff) {
            ClusterNode node = null;
            for (UUID nodeId : loc.nodeIds()) {
                node = nodes.get(nodeId);
                if (node != null)
                    break;
            }
            if (node == null)
                throw new IgniteException("Failed to find any of block affinity nodes in subgrid [loc=" + loc + ", subgrid=" + subgrid + ']');
            IgfsJob job = createJob(path, new IgfsFileRange(file.path(), loc.start(), loc.length()), args);
            if (job != null) {
                ComputeJob jobImpl = igfsProc.createJob(job, fs.name(), file.path(), loc.start(), loc.length(), args.recordResolver());
                splitMap.put(jobImpl, node);
            }
            totalLen += loc.length();
        }
        assert totalLen == file.length();
    }
    return splitMap;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgfsProcessorAdapter(org.apache.ignite.internal.processors.igfs.IgfsProcessorAdapter) HashMap(java.util.HashMap) IgniteFileSystem(org.apache.ignite.IgniteFileSystem) IgfsBlockLocation(org.apache.ignite.igfs.IgfsBlockLocation) IgfsPath(org.apache.ignite.igfs.IgfsPath) ComputeJob(org.apache.ignite.compute.ComputeJob) IgniteException(org.apache.ignite.IgniteException) UUID(java.util.UUID) IgfsFile(org.apache.ignite.igfs.IgfsFile) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with IgfsFile

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

the class IgfsAbstractSelfTest method testInfo.

/**
 * Test info routine when the path exists both locally and remotely.
 *
 * @throws Exception If failed.
 */
public void testInfo() throws Exception {
    create(igfs, paths(DIR), null);
    IgfsFile info = igfs.info(DIR);
    assert info != null;
    assertEquals(DIR, info.path());
}
Also used : IgfsFile(org.apache.ignite.igfs.IgfsFile)

Example 3 with IgfsFile

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

the class IgfsDualAbstractSelfTest method checkParentListingTime.

/**
 * Checks file access & modification time equality in the file itself and in the same file found through
 * the listing of its parent.
 *
 * @param fs The file system.
 * @param p The file path.
 *
 * @return Tuple of access and modification times of the file.
 */
private T2<Long, Long> checkParentListingTime(IgfsSecondaryFileSystem fs, IgfsPath p) {
    IgfsFile f0 = fs.info(p);
    T2<Long, Long> t0 = new T2<>(f0.accessTime(), f0.modificationTime());
    // Root cannot be seen through the parent listing:
    if (!F.eq(IgfsPath.ROOT, p)) {
        assertNotNull(f0);
        Collection<IgfsFile> listing = fs.listFiles(p.parent());
        IgfsFile f1 = null;
        for (IgfsFile fi : listing) {
            if (F.eq(fi.path(), p)) {
                f1 = fi;
                break;
            }
        }
        // file should be found in parent listing.
        assertNotNull(f1);
        T2<Long, Long> t1 = new T2<>(f1.accessTime(), f1.modificationTime());
        assertEquals(t0, t1);
    }
    return t0;
}
Also used : IgfsFile(org.apache.ignite.igfs.IgfsFile) T2(org.apache.ignite.internal.util.typedef.T2)

Example 4 with IgfsFile

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

the class HadoopIgfs20FileSystemAbstractSelfTest 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(primaryFsUri);
        Path file = new Path(igfsHome, "someFile");
        try (FSDataOutputStream out = fs.create(file, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault()), Options.CreateOpts.repFac((short) 1))) {
            out.write(new byte[1024 * 1024]);
        }
        IgniteFileSystem igfs = grid(0).fileSystem("igfs");
        IgfsPath filePath = new IgfsPath("/someFile");
        IgfsFile fileInfo = igfs.info(filePath);
        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) CreateFlag(org.apache.hadoop.fs.CreateFlag) 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)

Example 5 with IgfsFile

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

the class HadoopClientProtocolSelfTest method dumpIgfs.

/**
 * Dump IGFS content.
 *
 * @param igfs IGFS.
 * @param path Path.
 * @throws Exception If failed.
 */
@SuppressWarnings("ConstantConditions")
private static void dumpIgfs(IgniteFileSystem igfs, IgfsPath path) throws Exception {
    IgfsFile file = igfs.info(path);
    assert file != null;
    System.out.println(file.path());
    if (file.isDirectory()) {
        for (IgfsPath child : igfs.listPaths(path)) dumpIgfs(igfs, child);
    } else {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(igfs.open(path)))) {
            String line = br.readLine();
            while (line != null) {
                System.out.println(line);
                line = br.readLine();
            }
        }
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) 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