Search in sources :

Example 1 with IgfsPath

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

the class IgfsExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     * @throws Exception If example execution failed.
     */
public static void main(String[] args) throws Exception {
    Ignite ignite = Ignition.start("examples/config/filesystem/example-igfs.xml");
    System.out.println();
    System.out.println(">>> IGFS example started.");
    try {
        // Get an instance of Ignite File System.
        IgniteFileSystem fs = ignite.fileSystem("igfs");
        // Working directory path.
        IgfsPath workDir = new IgfsPath("/examples/fs");
        // Cleanup working directory.
        delete(fs, workDir);
        // Create empty working directory.
        mkdirs(fs, workDir);
        // Print information for working directory.
        printInfo(fs, workDir);
        // File path.
        IgfsPath filePath = new IgfsPath(workDir, "file.txt");
        // Create file.
        create(fs, filePath, new byte[] { 1, 2, 3 });
        // Print information for file.
        printInfo(fs, filePath);
        // Append more data to previously created file.
        append(fs, filePath, new byte[] { 4, 5 });
        // Print information for file.
        printInfo(fs, filePath);
        // Read data from file.
        read(fs, filePath);
        // Delete file.
        delete(fs, filePath);
        // Print information for file.
        printInfo(fs, filePath);
        // Create several files.
        for (int i = 0; i < 5; i++) create(fs, new IgfsPath(workDir, "file-" + i + ".txt"), null);
        list(fs, workDir);
    } finally {
        Ignition.stop(false);
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) Ignite(org.apache.ignite.Ignite) IgniteFileSystem(org.apache.ignite.IgniteFileSystem)

Example 2 with IgfsPath

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

the class IgfsExample method list.

/**
     * Lists files in directory.
     *
     * @param fs IGFS.
     * @param path Directory path.
     * @throws IgniteException In case of error.
     */
private static void list(IgniteFileSystem fs, IgfsPath path) throws IgniteException {
    assert fs != null;
    assert path != null;
    assert fs.info(path).isDirectory();
    Collection<IgfsPath> files = fs.listPaths(path);
    if (files.isEmpty()) {
        System.out.println();
        System.out.println(">>> No files in directory: " + path);
    } else {
        System.out.println();
        System.out.println(">>> List of files in directory: " + path);
        for (IgfsPath f : files) System.out.println(">>>     " + f.name());
    }
    System.out.println();
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath)

Example 3 with IgfsPath

use of org.apache.ignite.igfs.IgfsPath 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 4 with IgfsPath

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

the class IgfsModeResolver method readExternal.

/** {@inheritDoc} */
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    dfltMode = IgfsMode.fromOrdinal(in.readByte());
    if (in.readBoolean()) {
        int size = in.readInt();
        modes = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            IgfsPath path = IgfsUtils.readPath(in);
            modes.add(new T2<>(path, IgfsMode.fromOrdinal(in.readByte())));
        }
        modesCache = new GridBoundedConcurrentLinkedHashMap<>(MAX_PATH_CACHE);
    }
    dualParentsWithPrimaryChildren = new HashSet<>();
    if (in.readBoolean()) {
        int size = in.readInt();
        for (int i = 0; i < size; i++) dualParentsWithPrimaryChildren.add(IgfsUtils.readPath(in));
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath)

Example 5 with IgfsPath

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

the class IgfsModeResolver method writeExternal.

/** {@inheritDoc} */
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    U.writeEnum(out, dfltMode);
    if (modes != null) {
        out.writeBoolean(true);
        out.writeInt(modes.size());
        for (T2<IgfsPath, IgfsMode> pathMode : modes) {
            assert pathMode.getKey() != null;
            pathMode.getKey().writeExternal(out);
            U.writeEnum(out, pathMode.getValue());
        }
    } else
        out.writeBoolean(false);
    if (!F.isEmpty(dualParentsWithPrimaryChildren)) {
        out.writeBoolean(true);
        out.writeInt(dualParentsWithPrimaryChildren.size());
        for (IgfsPath p : dualParentsWithPrimaryChildren) p.writeExternal(out);
    } else
        out.writeBoolean(false);
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsMode(org.apache.ignite.igfs.IgfsMode)

Aggregations

IgfsPath (org.apache.ignite.igfs.IgfsPath)161 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)23 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 HashMap (java.util.HashMap)13 IgniteException (org.apache.ignite.IgniteException)13 IgniteFileSystem (org.apache.ignite.IgniteFileSystem)13 IgfsFile (org.apache.ignite.igfs.IgfsFile)13 IgfsException (org.apache.ignite.igfs.IgfsException)12 IgniteUuid (org.apache.ignite.lang.IgniteUuid)11 IgfsBlockLocation (org.apache.ignite.igfs.IgfsBlockLocation)10 IgfsInputStream (org.apache.ignite.igfs.IgfsInputStream)10 Map (java.util.Map)9 Path (org.apache.hadoop.fs.Path)9 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)9 FileNotFoundException (java.io.FileNotFoundException)6 OutputStream (java.io.OutputStream)6 IgfsDirectoryNotEmptyException (org.apache.ignite.igfs.IgfsDirectoryNotEmptyException)6 IgfsParentNotDirectoryException (org.apache.ignite.igfs.IgfsParentNotDirectoryException)6