Search in sources :

Example 1 with CrailDirectory

use of org.apache.crail.CrailDirectory 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 2 with CrailDirectory

use of org.apache.crail.CrailDirectory in project incubator-crail by apache.

the class CrailHadoopFileSystem method mkdirs.

@Override
public boolean mkdirs(Path path, FsPermission permission) throws IOException {
    try {
        CrailDirectory file = dfs.create(path.toUri().getRawPath(), CrailNodeType.DIRECTORY, CrailStorageClass.PARENT, CrailLocationClass.DEFAULT, true).get().asDirectory();
        file.syncDir();
        return true;
    } catch (Exception e) {
        if (e.getMessage().contains(RpcErrors.messages[RpcErrors.ERR_PARENT_MISSING])) {
            Path parent = path.getParent();
            mkdirs(parent);
            return mkdirs(path);
        } else if (e.getMessage().contains(RpcErrors.messages[RpcErrors.ERR_FILE_EXISTS])) {
            return true;
        } else {
            throw new IOException(e);
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) CrailDirectory(org.apache.crail.CrailDirectory) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with CrailDirectory

use of org.apache.crail.CrailDirectory in project incubator-crail by apache.

the class CrailHDFS method mkdir.

@Override
public void mkdir(Path path, FsPermission permission, boolean createParent) throws AccessControlException, FileAlreadyExistsException, FileNotFoundException, UnresolvedLinkException, IOException {
    try {
        CrailDirectory file = dfs.create(path.toUri().getRawPath(), CrailNodeType.DIRECTORY, CrailStorageClass.PARENT, CrailLocationClass.DEFAULT, true).get().asDirectory();
        file.syncDir();
    } catch (Exception e) {
        if (e.getMessage().contains(RpcErrors.messages[RpcErrors.ERR_PARENT_MISSING])) {
            Path parent = path.getParent();
            mkdir(parent, permission, createParent);
            mkdir(path, permission, createParent);
        } else if (e.getMessage().contains(RpcErrors.messages[RpcErrors.ERR_FILE_EXISTS])) {
        } else {
            throw new IOException(e);
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) CrailDirectory(org.apache.crail.CrailDirectory) IOException(java.io.IOException) 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)

Aggregations

CrailDirectory (org.apache.crail.CrailDirectory)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Path (org.apache.hadoop.fs.Path)2 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CrailFile (org.apache.crail.CrailFile)1 CrailMultiFile (org.apache.crail.CrailMultiFile)1 CrailNode (org.apache.crail.CrailNode)1 CrailStore (org.apache.crail.CrailStore)1 CrailConfiguration (org.apache.crail.conf.CrailConfiguration)1 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)1 ParentNotDirectoryException (org.apache.hadoop.fs.ParentNotDirectoryException)1 UnresolvedLinkException (org.apache.hadoop.fs.UnresolvedLinkException)1 UnsupportedFileSystemException (org.apache.hadoop.fs.UnsupportedFileSystemException)1 AccessControlException (org.apache.hadoop.security.AccessControlException)1