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;
}
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());
}
}
}
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);
}
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"));
}
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"));
}
Aggregations