use of org.apache.crail.CrailNode in project incubator-crail by apache.
the class CrailHDFS method getFileStatus.
@Override
public FileStatus getFileStatus(Path path) throws AccessControlException, FileNotFoundException, UnresolvedLinkException, IOException {
CrailNode directFile = null;
try {
directFile = dfs.lookup(path.toUri().getRawPath()).get();
} catch (Exception e) {
throw new IOException(e);
}
if (directFile == null) {
throw new FileNotFoundException("filename " + path);
}
FsPermission permission = FsPermission.getFileDefault();
if (directFile.getType().isDirectory()) {
permission = FsPermission.getDirDefault();
}
FileStatus status = new FileStatus(directFile.getCapacity(), directFile.getType().isContainer(), CrailConstants.SHADOW_REPLICATION, CrailConstants.BLOCK_SIZE, directFile.getModificationTime(), directFile.getModificationTime(), permission, CrailConstants.USER, CrailConstants.USER, path.makeQualified(this.getUri(), this.workingDir));
return status;
}
use of org.apache.crail.CrailNode in project incubator-crail by apache.
the class CrailHDFS method listStatus.
@Override
public FileStatus[] listStatus(Path path) throws AccessControlException, FileNotFoundException, UnresolvedLinkException, IOException {
try {
CrailNode node = dfs.lookup(path.toUri().getRawPath()).get();
Iterator<String> iter = node.asContainer().listEntries();
ArrayList<FileStatus> statusList = new ArrayList<FileStatus>();
while (iter.hasNext()) {
String filepath = iter.next();
CrailNode directFile = dfs.lookup(filepath).get();
if (directFile != null) {
FsPermission permission = FsPermission.getFileDefault();
if (directFile.getType().isDirectory()) {
permission = FsPermission.getDirDefault();
}
FileStatus status = new FileStatus(directFile.getCapacity(), directFile.getType().isContainer(), CrailConstants.SHADOW_REPLICATION, CrailConstants.BLOCK_SIZE, directFile.getModificationTime(), directFile.getModificationTime(), permission, CrailConstants.USER, CrailConstants.USER, new Path(filepath).makeQualified(this.getUri(), workingDir));
statusList.add(status);
}
}
FileStatus[] list = new FileStatus[statusList.size()];
statusList.toArray(list);
return list;
} catch (Exception e) {
throw new FileNotFoundException(path.toUri().getRawPath());
}
}
use of org.apache.crail.CrailNode in project incubator-crail by apache.
the class CrailFsck method blockStatistics.
public void blockStatistics(String filename) throws Exception {
HashMap<String, AtomicInteger> stats = new HashMap<String, AtomicInteger>();
CrailConfiguration conf = new CrailConfiguration();
CrailStore fs = CrailStore.newInstance(conf);
CrailNode node = fs.lookup(filename).get();
if (node.getType() == CrailNodeType.DIRECTORY) {
CrailDirectory directory = node.asDirectory();
Iterator<String> iter = directory.listEntries();
while (iter.hasNext()) {
String path = iter.next();
CrailFile child = fs.lookup(path).get().asFile();
walkBlocks(stats, fs, child.getPath(), 0, child.getCapacity());
}
} else if (node.getType() == CrailNodeType.DATAFILE) {
CrailFile file = node.asFile();
walkBlocks(stats, fs, file.getPath(), 0, file.getCapacity());
} else if (node.getType() == CrailNodeType.MULTIFILE) {
CrailMultiFile directory = node.asMultiFile();
Iterator<String> iter = directory.listEntries();
while (iter.hasNext()) {
String path = iter.next();
CrailFile child = fs.lookup(path).get().asFile();
walkBlocks(stats, fs, child.getPath(), 0, child.getCapacity());
}
}
printStats(stats);
fs.close();
}
use of org.apache.crail.CrailNode in project incubator-crail by apache.
the class CrailHadoopFileSystem method listStatus.
@Override
public FileStatus[] listStatus(Path path) throws FileNotFoundException, IOException {
try {
CrailNode node = dfs.lookup(path.toUri().getRawPath()).get();
Iterator<String> iter = node.asContainer().listEntries();
ArrayList<FileStatus> statusList = new ArrayList<FileStatus>();
while (iter.hasNext()) {
String filepath = iter.next();
CrailNode directFile = dfs.lookup(filepath).get();
if (directFile != null) {
FsPermission permission = FsPermission.getFileDefault();
if (directFile.getType().isDirectory()) {
permission = FsPermission.getDirDefault();
}
FileStatus status = new FileStatus(directFile.getCapacity(), directFile.getType().isContainer(), CrailConstants.SHADOW_REPLICATION, CrailConstants.BLOCK_SIZE, directFile.getModificationTime(), directFile.getModificationTime(), permission, CrailConstants.USER, CrailConstants.USER, new Path(filepath).makeQualified(this.getUri(), this.workingDir));
statusList.add(status);
}
}
FileStatus[] list = new FileStatus[statusList.size()];
statusList.toArray(list);
return list;
} catch (Exception e) {
throw new FileNotFoundException(path.toUri().getRawPath());
}
}
use of org.apache.crail.CrailNode in project incubator-crail by apache.
the class CrailHadoopFileSystem method getFileStatus.
@Override
public FileStatus getFileStatus(Path path) throws IOException {
CrailNode directFile = null;
try {
directFile = dfs.lookup(path.toUri().getRawPath()).get();
} catch (Exception e) {
throw new IOException(e);
}
if (directFile == null) {
throw new FileNotFoundException("File does not exist: " + path);
}
FsPermission permission = FsPermission.getFileDefault();
if (directFile.getType().isDirectory()) {
permission = FsPermission.getDirDefault();
}
FileStatus status = new FileStatus(directFile.getCapacity(), directFile.getType().isContainer(), CrailConstants.SHADOW_REPLICATION, CrailConstants.BLOCK_SIZE, directFile.getModificationTime(), directFile.getModificationTime(), permission, CrailConstants.USER, CrailConstants.USER, path.makeQualified(this.getUri(), this.workingDir));
return status;
}
Aggregations