Search in sources :

Example 1 with NormalFileState

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

the class ProtoBufferHelper method convert.

public static FileState convert(FileStateProto proto) {
    FileState fileState = null;
    String path = proto.getPath();
    FileState.FileType type = FileState.FileType.fromValue(proto.getType());
    FileState.FileStage stage = FileState.FileStage.fromValue(proto.getStage());
    // FileState.FileStage stage = FileState.FileStage.fromValue(proto.getStage());
    if (type == null) {
        return new NormalFileState(path);
    }
    switch(type) {
        case NORMAL:
            fileState = new NormalFileState(path);
            break;
        case COMPACT:
            CompactFileStateProto compactProto = proto.getCompactFileState();
            fileState = new CompactFileState(path, convert(compactProto));
            break;
        case COMPRESSION:
            CompressionFileStateProto compressionProto = proto.getCompressionFileState();
            // convert to CompressionFileState
            fileState = convert(path, stage, compressionProto);
            break;
        case S3:
            S3FileStateProto s3Proto = proto.getS3FileState();
            // fileState = convert(path, type, stage, s3Proto);
            break;
        default:
    }
    return fileState;
}
Also used : CompressionFileStateProto(org.smartdata.protocol.ClientServerProto.CompressionFileStateProto) NormalFileState(org.smartdata.model.NormalFileState) CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) NormalFileState(org.smartdata.model.NormalFileState) CompactFileStateProto(org.smartdata.protocol.ClientServerProto.CompactFileStateProto) S3FileStateProto(org.smartdata.protocol.ClientServerProto.S3FileStateProto) CompactFileState(org.smartdata.model.CompactFileState)

Example 2 with NormalFileState

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

the class SmartClient method getFileState.

@Override
public FileState getFileState(String filePath) throws IOException {
    checkOpen();
    int triedServerNum = 0;
    while (true) {
        try {
            SmartClientProtocol server = serverQue.getFirst();
            return server.getFileState(filePath);
        } catch (ConnectException e) {
            triedServerNum++;
            // If all servers has been tried, interrupt and throw the exception.
            if (triedServerNum == serverQue.size()) {
                // client cannot connect to server
                // don't report access event for this file this time
                singleIgnoreList.put(filePath, 0);
                // the file is compacted or compressed by SSM.
                return new NormalFileState(filePath);
            }
            // Put the first server to last, and will pick the second one to try.
            serverQue.addLast(serverQue.pollFirst());
        }
    }
}
Also used : SmartClientProtocol(org.smartdata.protocol.SmartClientProtocol) NormalFileState(org.smartdata.model.NormalFileState) ConnectException(java.net.ConnectException)

Example 3 with NormalFileState

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

the class TestSmartClient method testGetFileState.

@Test
public void testGetFileState() throws Exception {
    waitTillSSMExitSafeMode();
    MetaStore metaStore = ssm.getMetaStore();
    String path = "/file1";
    FileState fileState = new NormalFileState(path);
    SmartClient client = new SmartClient(smartContext.getConf());
    FileState fileState1;
    // No entry in file_state table (Normal type as default)
    fileState1 = client.getFileState(path);
    Assert.assertEquals(fileState, fileState1);
    metaStore.insertUpdateFileState(fileState);
    fileState1 = client.getFileState(path);
    Assert.assertEquals(fileState, fileState1);
}
Also used : MetaStore(org.smartdata.metastore.MetaStore) FileState(org.smartdata.model.FileState) NormalFileState(org.smartdata.model.NormalFileState) NormalFileState(org.smartdata.model.NormalFileState) SmartClient(org.smartdata.client.SmartClient) Test(org.junit.Test)

Example 4 with NormalFileState

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

the class TestMetaStore method testDeleteFileState.

@Test
public void testDeleteFileState() throws MetaStoreException {
    // Normal file
    FileState fileState1 = new NormalFileState("/test1");
    metaStore.insertUpdateFileState(fileState1);
    Assert.assertEquals(fileState1, metaStore.getFileState("/test1"));
    // Compression & Processing (without compression info)
    // FileState fileState2 = new FileState("/test2", FileState.FileType.COMPRESSION,
    // FileState.FileStage.PROCESSING);
    // metaStore.insertUpdateFileState(fileState2);
    // Assert.assertEquals(fileState2, metaStore.getFileState("/test2"));
    // Compression & Done (with compression info)
    int bufferSize = 1024;
    long originalLen = 100;
    long compressedLen = 50;
    Long[] originPos = { 0L, 30L, 60L, 90L };
    Long[] compressedPos = { 0L, 13L, 30L, 41L };
    FileState fileState3 = new CompressionFileState("/test3", bufferSize, originalLen, compressedLen, originPos, compressedPos);
    metaStore.insertUpdateFileState(fileState3);
    compareCompressionInfo(fileState3, metaStore.getFileState("/test3"));
    // Delete /test3
    metaStore.deleteFileState("/test3");
    Assert.assertNull(metaStore.getCompressionInfo("/test3"));
    Assert.assertEquals(new NormalFileState("/test3"), metaStore.getFileState("/test3"));
    // Delete all
    metaStore.deleteAllFileState();
    Assert.assertEquals(new NormalFileState("/test1"), metaStore.getFileState("/test1"));
    Assert.assertEquals(new NormalFileState("/test2"), metaStore.getFileState("/test2"));
    Assert.assertEquals(new NormalFileState("/test3"), metaStore.getFileState("/test3"));
}
Also used : NormalFileState(org.smartdata.model.NormalFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) NormalFileState(org.smartdata.model.NormalFileState) CompressionFileState(org.smartdata.model.CompressionFileState) Test(org.junit.Test)

Example 5 with NormalFileState

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

the class TestMetaStore method testInsertUpdateFileState.

@Test
public void testInsertUpdateFileState() throws MetaStoreException {
    // Normal file
    FileState fileState = new NormalFileState("/test1");
    metaStore.insertUpdateFileState(fileState);
    Assert.assertEquals(fileState, metaStore.getFileState("/test1"));
    // Compression & Processing (without compression info)
    // fileState = new FileState("/test1", FileState.FileType.COMPRESSION,
    // FileState.FileStage.PROCESSING);
    // metaStore.insertUpdateFileState(fileState);
    // Assert.assertEquals(fileState, metaStore.getFileState("/test1"));
    // Compression & Done (with compression info)
    int bufferSize = 1024;
    long originalLen = 100;
    long compressedLen = 50;
    Long[] originPos = { 0L, 30L, 60L, 90L };
    Long[] compressedPos = { 0L, 13L, 30L, 41L };
    fileState = new CompressionFileState("/test1", bufferSize, originalLen, compressedLen, originPos, compressedPos);
    metaStore.insertUpdateFileState(fileState);
    compareCompressionInfo(fileState, metaStore.getFileState("/test1"));
}
Also used : NormalFileState(org.smartdata.model.NormalFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) NormalFileState(org.smartdata.model.NormalFileState) CompressionFileState(org.smartdata.model.CompressionFileState) Test(org.junit.Test)

Aggregations

NormalFileState (org.smartdata.model.NormalFileState)6 FileState (org.smartdata.model.FileState)5 CompressionFileState (org.smartdata.model.CompressionFileState)4 Test (org.junit.Test)3 CompactFileState (org.smartdata.model.CompactFileState)2 ConnectException (java.net.ConnectException)1 SQLException (java.sql.SQLException)1 SmartClient (org.smartdata.client.SmartClient)1 MetaStore (org.smartdata.metastore.MetaStore)1 S3FileState (org.smartdata.model.S3FileState)1 CompactFileStateProto (org.smartdata.protocol.ClientServerProto.CompactFileStateProto)1 CompressionFileStateProto (org.smartdata.protocol.ClientServerProto.CompressionFileStateProto)1 S3FileStateProto (org.smartdata.protocol.ClientServerProto.S3FileStateProto)1 SmartClientProtocol (org.smartdata.protocol.SmartClientProtocol)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1