Search in sources :

Example 21 with FileState

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

the class CompressionScheduler method supportCompression.

/**
 * Check if the file type support compression action.
 *
 * @param path
 * @return true if the file supports compression action, else false
 */
public boolean supportCompression(String path) throws MetaStoreException, IOException {
    if (path == null) {
        LOG.warn("File path is not specified.");
        return false;
    }
    if (dfsClient.getFileInfo(path).isDir()) {
        LOG.warn("Compression is not applicable to a directory.");
        return false;
    }
    // Current implementation: only normal file type supports compression action
    FileState fileState = metaStore.getFileState(path);
    if (fileState.getFileType().equals(FileState.FileType.NORMAL) && fileState.getFileStage().equals(FileState.FileStage.DONE)) {
        return true;
    }
    LOG.debug("File " + path + " doesn't support compression action. " + "Type: " + fileState.getFileType() + "; Stage: " + fileState.getFileStage());
    return false;
}
Also used : FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState)

Example 22 with FileState

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

the class CompressionScheduler method supportDecompression.

public boolean supportDecompression(String path) throws MetaStoreException, IOException {
    if (path == null) {
        LOG.warn("File path is not specified!");
        return false;
    }
    // Exclude directory case
    if (dfsClient.getFileInfo(path).isDir()) {
        LOG.warn("Decompression is not applicable to a directory.");
        return false;
    }
    FileState fileState = metaStore.getFileState(path);
    if (fileState instanceof CompressionFileState) {
        return true;
    }
    LOG.debug("A compressed file path should be given!");
    return false;
}
Also used : FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) CompressionFileState(org.smartdata.model.CompressionFileState)

Example 23 with FileState

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

the class SmartFileSystem method isFileClosed.

@Override
public boolean isFileClosed(final Path src) throws IOException {
    boolean isFileClosed = super.isFileClosed(src);
    if (!isFileClosed) {
        FileState fileState = smartDFSClient.getFileState(getPathName(src));
        if (fileState instanceof CompactFileState) {
            String containerFile = ((CompactFileState) fileState).getFileContainerInfo().getContainerFilePath();
            isFileClosed = smartDFSClient.isFileClosed(containerFile);
        }
    }
    return isFileClosed;
}
Also used : CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) CompactFileState(org.smartdata.model.CompactFileState)

Example 24 with FileState

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

the class SmartDFSClient method getFileChecksum.

@Override
public MD5MD5CRC32FileChecksum getFileChecksum(String src, long length) throws IOException {
    MD5MD5CRC32FileChecksum ret = super.getFileChecksum(src, length);
    if (ret.getChecksumOpt().getBytesPerChecksum() == 0) {
        FileState fileState = getFileState(src);
        if (fileState instanceof CompactFileState) {
            try {
                // Get original checksum for small file.
                byte[] bytes = getXAttr(src, SmartConstants.SMART_FILE_CHECKSUM_XATTR_NAME);
                ret = new MD5MD5CRC32FileChecksum();
                ret.readFields(new DataInputStream(new ByteArrayInputStream(bytes)));
            } catch (IOException e) {
                throw new IOException("Failed to get checksum for SSM Small File: " + e.getMessage());
            }
        }
    }
    return ret;
}
Also used : NormalFileState(org.smartdata.model.NormalFileState) CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) MD5MD5CRC32FileChecksum(org.apache.hadoop.fs.MD5MD5CRC32FileChecksum) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) CompactFileState(org.smartdata.model.CompactFileState)

Example 25 with FileState

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

the class SmartDFSClient method isFileClosed.

@Override
public boolean isFileClosed(String src) throws IOException {
    boolean isFileClosed = super.isFileClosed(src);
    if (!isFileClosed) {
        FileState fileState = getFileState(src);
        if (fileState instanceof CompactFileState) {
            String containerFile = ((CompactFileState) fileState).getFileContainerInfo().getContainerFilePath();
            isFileClosed = super.isFileClosed(containerFile);
        }
    }
    return isFileClosed;
}
Also used : NormalFileState(org.smartdata.model.NormalFileState) CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) 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