Search in sources :

Example 1 with CrailNode

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;
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) CrailNode(org.apache.crail.CrailNode) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FsPermission(org.apache.hadoop.fs.permission.FsPermission) URISyntaxException(java.net.URISyntaxException) UnresolvedLinkException(org.apache.hadoop.fs.UnresolvedLinkException) ParentNotDirectoryException(org.apache.hadoop.fs.ParentNotDirectoryException) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AccessControlException(org.apache.hadoop.security.AccessControlException) UnsupportedFileSystemException(org.apache.hadoop.fs.UnsupportedFileSystemException)

Example 2 with CrailNode

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());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) CrailNode(org.apache.crail.CrailNode) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) FsPermission(org.apache.hadoop.fs.permission.FsPermission) URISyntaxException(java.net.URISyntaxException) UnresolvedLinkException(org.apache.hadoop.fs.UnresolvedLinkException) ParentNotDirectoryException(org.apache.hadoop.fs.ParentNotDirectoryException) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AccessControlException(org.apache.hadoop.security.AccessControlException) UnsupportedFileSystemException(org.apache.hadoop.fs.UnsupportedFileSystemException)

Example 3 with CrailNode

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) CrailDirectory(org.apache.crail.CrailDirectory) CrailNode(org.apache.crail.CrailNode) CrailMultiFile(org.apache.crail.CrailMultiFile) CrailStore(org.apache.crail.CrailStore) CrailFile(org.apache.crail.CrailFile) CrailConfiguration(org.apache.crail.conf.CrailConfiguration)

Example 4 with CrailNode

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());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) CrailNode(org.apache.crail.CrailNode) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) FsPermission(org.apache.hadoop.fs.permission.FsPermission) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 5 with CrailNode

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;
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) CrailNode(org.apache.crail.CrailNode) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FsPermission(org.apache.hadoop.fs.permission.FsPermission) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

CrailNode (org.apache.crail.CrailNode)8 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 FileStatus (org.apache.hadoop.fs.FileStatus)4 FsPermission (org.apache.hadoop.fs.permission.FsPermission)4 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 Future (java.util.concurrent.Future)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 CrailBuffer (org.apache.crail.CrailBuffer)2 CrailFile (org.apache.crail.CrailFile)2 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)2 ParentNotDirectoryException (org.apache.hadoop.fs.ParentNotDirectoryException)2 Path (org.apache.hadoop.fs.Path)2 UnresolvedLinkException (org.apache.hadoop.fs.UnresolvedLinkException)2 UnsupportedFileSystemException (org.apache.hadoop.fs.UnsupportedFileSystemException)2 AccessControlException (org.apache.hadoop.security.AccessControlException)2 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1