Search in sources :

Example 6 with CompressionFileState

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

the class TestCompressionFileDao method testGetCompressionInfo.

@Test
public void testGetCompressionInfo() throws Exception {
    long originalLen = 100;
    long compressedLen = 50;
    CompressionFileState compressionInfo = new CompressionFileState("/test1", 131072, compressionImpl, originalLen, compressedLen, originalPos.toArray(new Long[0]), compressedPos.toArray(new Long[0]));
    CompressionFileState compressionInfo2 = new CompressionFileState("/test2", 131072, compressionImpl, originalPos.toArray(new Long[0]), compressedPos.toArray(new Long[0]));
    compressionFileDao.insert(compressionInfo);
    compressionFileDao.insert(compressionInfo2);
    CompressionFileState dbcompressionInfo = compressionFileDao.getInfoByPath("/test1");
    Assert.assertTrue(dbcompressionInfo.getPath().equals("/test1"));
    Assert.assertTrue(dbcompressionInfo.getBufferSize() == 131072);
    Assert.assertTrue(dbcompressionInfo.getCompressionImpl().equals(compressionImpl));
    Assert.assertTrue(dbcompressionInfo.getOriginalPos()[0].equals(9000L));
    Assert.assertTrue(dbcompressionInfo.getCompressedPos()[1].equals(2000L));
    Assert.assertTrue(compressionFileDao.getAll().size() == 2);
    Assert.assertEquals(originalLen, dbcompressionInfo.getOriginalLength());
    Assert.assertEquals(compressedLen, dbcompressionInfo.getCompressedLength());
}
Also used : CompressionFileState(org.smartdata.model.CompressionFileState) Test(org.junit.Test)

Example 7 with CompressionFileState

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

the class TestCompressionFileDao method testInsertDeleteCompressionFiles.

@Test
public void testInsertDeleteCompressionFiles() throws Exception {
    CompressionFileState compressionInfo = new CompressionFileState("/test", 131072, compressionImpl, originalPos.toArray(new Long[0]), compressedPos.toArray(new Long[0]));
    // insert test
    compressionFileDao.insert(compressionInfo);
    Assert.assertTrue(compressionFileDao.getInfoByPath("/test").getOriginalPos()[0].equals(9000L));
    // delete test
    compressionFileDao.deleteByPath("/test");
    Assert.assertTrue(compressionFileDao.getAll().size() == 0);
}
Also used : CompressionFileState(org.smartdata.model.CompressionFileState) Test(org.junit.Test)

Example 8 with CompressionFileState

use of org.smartdata.model.CompressionFileState 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 9 with CompressionFileState

use of org.smartdata.model.CompressionFileState 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 10 with CompressionFileState

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

the class CheckCompressAction method execute.

@Override
protected void execute() throws Exception {
    if (srcPath == null) {
        throw new IOException("File path is not given!");
    }
    // Consider directory case.
    if (dfsClient.getFileInfo(srcPath).isDir()) {
        appendLog("The given path is a directory, " + "not applicable to checking compression status.");
        return;
    }
    FileState fileState = HadoopUtil.getFileState(dfsClient, srcPath);
    if (fileState instanceof CompressionFileState) {
        appendLog("The given file has already been compressed by SSM.");
        appendLog("The compression codec is " + ((CompressionFileState) fileState).getCompressionImpl());
        appendLog("The original file length is " + ((CompressionFileState) fileState).getOriginalLength());
        appendLog("The current file length is " + ((CompressionFileState) fileState).getCompressedLength());
        return;
    }
    appendLog("The given file is not compressed.");
}
Also used : FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) CompressionFileState(org.smartdata.model.CompressionFileState) IOException(java.io.IOException)

Aggregations

CompressionFileState (org.smartdata.model.CompressionFileState)22 FileState (org.smartdata.model.FileState)13 Test (org.junit.Test)7 CompactFileState (org.smartdata.model.CompactFileState)7 IOException (java.io.IOException)6 NormalFileState (org.smartdata.model.NormalFileState)5 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)4 Gson (com.google.gson.Gson)3 CompressionFileInfo (org.smartdata.model.CompressionFileInfo)3 OutputStream (java.io.OutputStream)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)2 DFSInputStream (org.apache.hadoop.hdfs.DFSInputStream)2 HdfsLocatedFileStatus (org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus)2 HdfsNamedFileStatus (org.apache.hadoop.hdfs.protocol.HdfsNamedFileStatus)2 ActionException (org.smartdata.action.ActionException)2 CompactFileStateProto (org.smartdata.protocol.ClientServerProto.CompactFileStateProto)2 CompressionFileStateProto (org.smartdata.protocol.ClientServerProto.CompressionFileStateProto)2