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);
}
}
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();
}
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;
}
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));
}
}
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);
}
Aggregations