use of com.alibaba.otter.node.etl.common.pipe.impl.http.HttpPipeKey in project otter by alibaba.
the class RowDataPipeDelegate method get.
public DbBatch get(List<PipeKey> keys) {
Assert.notNull(keys);
DbBatch dbBatch = new DbBatch();
Future<File> future = null;
for (final PipeKey key : keys) {
if (key == null) {
// 忽略空的key
continue;
}
if (key instanceof MemoryPipeKey) {
dbBatch = rowDataMemoryPipe.get((MemoryPipeKey) key);
// 直接返回
return dbBatch;
} else if (key instanceof HttpPipeKey) {
if (key.getDataType().isDbBatch()) {
// 区分一下数据下载
dbBatch = rowDataHttpPipe.get((HttpPipeKey) key);
} else {
future = executorService.submit(new Callable<File>() {
public File call() throws Exception {
try {
HttpPipeKey pipeKey = (HttpPipeKey) key;
MDC.put(OtterConstants.splitPipelineLogFileKey, String.valueOf(pipeKey.getIdentity().getPipelineId()));
return attachmentHttpPipe.get(pipeKey);
} finally {
MDC.remove(OtterConstants.splitPipelineLogFileKey);
}
}
});
}
} else if (key instanceof RpcPipeKey) {
dbBatch = rowDataRpcPipe.get((RpcPipeKey) key);
} else {
throw new PipeException("unknow_PipeKey", key.toString());
}
}
if (future != null && dbBatch != null) {
try {
dbBatch.setRoot(future.get());
} catch (Exception e) {
throw new PipeException(e);
}
}
return dbBatch;
}
use of com.alibaba.otter.node.etl.common.pipe.impl.http.HttpPipeKey in project otter by alibaba.
the class HttpPipeIntegration method test_attachment.
@Test
public void test_attachment() {
final Node currentNode = new Node();
currentNode.setId(1L);
currentNode.setIp("127.0.0.1");
currentNode.setParameters(new NodeParameter());
final Pipeline pipeline = new Pipeline();
pipeline.getParameters().setRetriever(RetrieverType.ARIA2C);
// mock一下
new NonStrictExpectations() {
{
configClientService.currentNode();
returns(currentNode);
configClientService.findPipeline(anyLong);
returns(pipeline);
}
};
Identity identity = new Identity();
identity.setChannelId(100L);
identity.setPipelineId(100L);
identity.setProcessId(100L);
FileBatch fileBatch = new FileBatch();
fileBatch.setIdentity(identity);
File localFile = new File(tmp, "httpPipeTest.jpg");
FileData localFileData = new FileData();
localFileData.setEventType(EventType.INSERT);
localFileData.setPath(localFile.getPath());
fileBatch.getFiles().add(localFileData);
try {
byte[] data = getBlock(10 * 1024);
NioUtils.write(data, localFile);
HttpPipeKey key = attachmentHttpPipe.put(fileBatch);
File target = attachmentHttpPipe.get(key);
byte[] getbytes = NioUtils.read(new File(target, localFile.getPath()));
check(data, getbytes);
} catch (IOException e) {
want.fail();
} finally {
NioUtils.delete(localFile);
}
}
use of com.alibaba.otter.node.etl.common.pipe.impl.http.HttpPipeKey in project otter by alibaba.
the class HttpPipeIntegration method test_rowData.
@Test
public void test_rowData() {
final Node currentNode = new Node();
currentNode.setId(1L);
currentNode.setIp("127.0.0.1");
currentNode.setParameters(new NodeParameter());
final Pipeline pipeline = new Pipeline();
pipeline.getParameters().setRetriever(RetrieverType.ARIA2C);
// mock一下
new NonStrictExpectations() {
{
configClientService.currentNode();
returns(currentNode);
configClientService.findPipeline(anyLong);
returns(pipeline);
}
};
Identity identity = new Identity();
identity.setChannelId(100L);
identity.setPipelineId(100L);
identity.setProcessId(100L);
FileBatch fileBatch = new FileBatch();
fileBatch.setIdentity(identity);
File localFile = new File(tmp, "httpPipeTest.jpg");
FileData localFileData = new FileData();
localFileData.setPath(localFile.getPath());
localFileData.setEventType(EventType.INSERT);
localFileData.setLastModifiedTime(new Date().getTime());
localFileData.setSize(100L);
localFileData.setTableId(1L);
fileBatch.getFiles().add(localFileData);
RowBatch rowBatch = new RowBatch();
rowBatch.setIdentity(identity);
EventData eventData = new EventData();
eventData.setTableId(1L);
eventData.setSchemaName("otter");
eventData.setTableName("test");
eventData.setEventType(EventType.INSERT);
eventData.setExecuteTime(100L);
EventColumn primaryKey = new EventColumn();
primaryKey.setColumnName("id");
primaryKey.setColumnType(1);
primaryKey.setColumnValue("1");
primaryKey.setKey(true);
primaryKey.setNull(false);
eventData.getKeys().add(primaryKey);
EventColumn column = new EventColumn();
column.setColumnName("name");
column.setColumnType(1);
column.setColumnValue("test");
column.setKey(false);
column.setNull(false);
eventData.getColumns().add(column);
rowBatch.merge(eventData);
DbBatch dbBatch = new DbBatch();
dbBatch.setRowBatch(rowBatch);
dbBatch.setFileBatch(fileBatch);
HttpPipeKey key = rowDataHttpPipe.put(dbBatch);
DbBatch target = rowDataHttpPipe.get(key);
want.bool(target.getRowBatch().getIdentity().equals(identity));
want.object(target).notNull();
}
Aggregations