Search in sources :

Example 11 with FileState

use of org.smartdata.model.FileState in project SSM by Intel-bigdata.

the class SmartFileSystem method getFileLinkStatus.

@Override
public FileStatus getFileLinkStatus(final Path f) throws IOException {
    FileStatus fileStatus = super.getFileLinkStatus(f);
    if (fileStatus.getLen() == 0) {
        Path target = getLinkTarget(f);
        FileState fileState = smartDFSClient.getFileState(getPathName(target));
        if (fileState instanceof CompactFileState) {
            fileStatus = getFileStatus(target);
        }
    } else {
        Path target = getLinkTarget(f);
        FileState fileState = smartDFSClient.getFileState(getPathName(target));
        if (fileState instanceof CompressionFileState) {
            fileStatus = getFileStatus(target);
        }
    }
    return fileStatus;
}
Also used : Path(org.apache.hadoop.fs.Path) CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) FileStatus(org.apache.hadoop.fs.FileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) HdfsNamedFileStatus(org.apache.hadoop.hdfs.protocol.HdfsNamedFileStatus) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) HdfsLocatedFileStatus(org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus) CompressionFileState(org.smartdata.model.CompressionFileState) CompactFileState(org.smartdata.model.CompactFileState)

Example 12 with FileState

use of org.smartdata.model.FileState in project SSM by Intel-bigdata.

the class SmartFileSystem method getFileBlockLocations.

@Override
public BlockLocation[] getFileBlockLocations(Path p, final long start, final long len) throws IOException {
    BlockLocation[] blockLocations = super.getFileBlockLocations(p, start, len);
    if (blockLocations.length == 0) {
        FileState fileState = smartDFSClient.getFileState(getPathName(p));
        if (fileState instanceof CompactFileState) {
            FileContainerInfo fileContainerInfo = ((CompactFileState) fileState).getFileContainerInfo();
            String containerFile = fileContainerInfo.getContainerFilePath();
            long offset = fileContainerInfo.getOffset();
            blockLocations = super.getFileBlockLocations(new Path(containerFile), offset + start, len);
            for (BlockLocation blockLocation : blockLocations) {
                blockLocation.setOffset(blockLocation.getOffset() - offset);
            }
        }
    }
    return blockLocations;
}
Also used : Path(org.apache.hadoop.fs.Path) CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) BlockLocation(org.apache.hadoop.fs.BlockLocation) FileContainerInfo(org.smartdata.model.FileContainerInfo) CompactFileState(org.smartdata.model.CompactFileState)

Example 13 with FileState

use of org.smartdata.model.FileState in project SSM by Intel-bigdata.

the class SmartFileSystem method listStatus.

@Override
public FileStatus[] listStatus(Path p) throws IOException {
    FileStatus[] oldStatus = super.listStatus(p);
    ArrayList<FileStatus> newStatus = new ArrayList<>(oldStatus.length);
    for (FileStatus status : oldStatus) {
        if (oldStatus == null) {
            newStatus.add(null);
            continue;
        }
        if (status.getLen() == 0) {
            FileState fileState = smartDFSClient.getFileState(getPathName(status.getPath()));
            if (fileState instanceof CompactFileState) {
                long len = ((CompactFileState) fileState).getFileContainerInfo().getLength();
                newStatus.add(new FileStatus(len, status.isDirectory(), status.getReplication(), status.getBlockSize(), status.getModificationTime(), status.getAccessTime(), status.getPermission(), status.getOwner(), status.getGroup(), status.isSymlink() ? status.getSymlink() : null, status.getPath()));
            } else {
                newStatus.add(status);
            }
        } else {
            FileState fileState = smartDFSClient.getFileState(getPathName(status.getPath()));
            if (fileState instanceof CompressionFileState) {
                long len = ((CompressionFileState) fileState).getOriginalLength();
                newStatus.add(new FileStatus(len, status.isDirectory(), status.getReplication(), status.getBlockSize(), status.getModificationTime(), status.getAccessTime(), status.getPermission(), status.getOwner(), status.getGroup(), status.isSymlink() ? status.getSymlink() : null, status.getPath()));
            } else {
                newStatus.add(status);
            }
        }
    }
    return newStatus.toArray(new FileStatus[oldStatus.length]);
}
Also used : CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) FileStatus(org.apache.hadoop.fs.FileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) HdfsNamedFileStatus(org.apache.hadoop.hdfs.protocol.HdfsNamedFileStatus) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) HdfsLocatedFileStatus(org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus) ArrayList(java.util.ArrayList) CompressionFileState(org.smartdata.model.CompressionFileState) CompactFileState(org.smartdata.model.CompactFileState)

Example 14 with FileState

use of org.smartdata.model.FileState in project SSM by Intel-bigdata.

the class SmartDFSClient method open.

@Override
public DFSInputStream open(String src, int buffersize, boolean verifyChecksum) throws IOException {
    DFSInputStream is = super.open(src, buffersize, verifyChecksum);
    if (is.getFileLength() == 0) {
        is.close();
        FileState fileState = getFileState(src);
        if (fileState.getFileStage().equals(FileState.FileStage.PROCESSING)) {
            throw new IOException("Cannot open " + src + " when it is under PROCESSING to " + fileState.getFileType());
        }
        is = SmartInputStreamFactory.create(this, src, verifyChecksum, fileState);
    } else {
        is.close();
        FileState fileState = getFileState(src);
        if (fileState.getFileStage().equals(FileState.FileStage.PROCESSING)) {
            throw new IOException("Cannot open " + src + " when it is under PROCESSING to " + fileState.getFileType());
        }
        is = SmartInputStreamFactory.create(this, src, verifyChecksum, fileState);
    }
    reportFileAccessEvent(src);
    return is;
}
Also used : NormalFileState(org.smartdata.model.NormalFileState) CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) DFSInputStream(org.apache.hadoop.hdfs.DFSInputStream) IOException(java.io.IOException)

Example 15 with FileState

use of org.smartdata.model.FileState in project SSM by Intel-bigdata.

the class SmartDFSClient method listCorruptFileBlocks.

@Override
public CorruptFileBlocks listCorruptFileBlocks(String path, String cookie) throws IOException {
    CorruptFileBlocks corruptFileBlocks = super.listCorruptFileBlocks(path, cookie);
    FileState fileState = getFileState(path);
    if (fileState instanceof CompactFileState) {
        corruptFileBlocks = super.listCorruptFileBlocks(((CompactFileState) fileState).getFileContainerInfo().getContainerFilePath(), cookie);
    }
    return corruptFileBlocks;
}
Also used : NormalFileState(org.smartdata.model.NormalFileState) CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) CorruptFileBlocks(org.apache.hadoop.hdfs.protocol.CorruptFileBlocks) CompactFileState(org.smartdata.model.CompactFileState)

Aggregations

FileState (org.smartdata.model.FileState)34 CompressionFileState (org.smartdata.model.CompressionFileState)26 CompactFileState (org.smartdata.model.CompactFileState)19 NormalFileState (org.smartdata.model.NormalFileState)15 IOException (java.io.IOException)9 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)4 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)4 Gson (com.google.gson.Gson)3 HashMap (java.util.HashMap)3 Path (org.apache.hadoop.fs.Path)3 DFSInputStream (org.apache.hadoop.hdfs.DFSInputStream)3 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)3 SQLException (java.sql.SQLException)2 BlockLocation (org.apache.hadoop.fs.BlockLocation)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)2 HdfsLocatedFileStatus (org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus)2 HdfsNamedFileStatus (org.apache.hadoop.hdfs.protocol.HdfsNamedFileStatus)2 LocatedBlocks (org.apache.hadoop.hdfs.protocol.LocatedBlocks)2