Search in sources :

Example 1 with DataRetriever

use of com.alibaba.otter.node.etl.common.io.download.DataRetriever in project otter by alibaba.

the class Aria2cDownLoadIntegration method testDownLoad_ok.

@Test
public void testDownLoad_ok() {
    DataRetriever retriever = new Aria2cRetriever("http://china.alibaba.com", tmp);
    try {
        retriever.connect();
        retriever.doRetrieve();
    } catch (DataRetrieveException ex) {
        retriever.abort();
    } finally {
        retriever.disconnect();
    }
}
Also used : Aria2cRetriever(com.alibaba.otter.node.etl.common.io.download.impl.aria2c.Aria2cRetriever) DataRetrieveException(com.alibaba.otter.node.etl.common.io.download.exception.DataRetrieveException) DataRetriever(com.alibaba.otter.node.etl.common.io.download.DataRetriever) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.node.etl.BaseOtterTest)

Example 2 with DataRetriever

use of com.alibaba.otter.node.etl.common.io.download.DataRetriever in project otter by alibaba.

the class AttachmentHttpPipe method unpackFile.

// 处理对应的附件
private File unpackFile(HttpPipeKey key) {
    Pipeline pipeline = configClientService.findPipeline(key.getIdentity().getPipelineId());
    DataRetriever dataRetriever = dataRetrieverFactory.createRetriever(pipeline.getParameters().getRetriever(), key.getUrl(), downloadDir);
    File archiveFile = null;
    try {
        dataRetriever.connect();
        dataRetriever.doRetrieve();
        archiveFile = dataRetriever.getDataAsFile();
    } catch (Exception e) {
        dataRetriever.abort();
        throw new PipeException("download_error", e);
    } finally {
        dataRetriever.disconnect();
    }
    // 处理下有加密的数据
    if (StringUtils.isNotEmpty(key.getKey()) && StringUtils.isNotEmpty(key.getCrc())) {
        decodeFile(archiveFile, key.getKey(), key.getCrc());
    }
    // 去除末尾的.gzip后缀,做为解压目录
    String dir = StringUtils.removeEnd(archiveFile.getPath(), FilenameUtils.EXTENSION_SEPARATOR_STR + FilenameUtils.getExtension(archiveFile.getPath()));
    File unpackDir = new File(dir);
    // 开始解压
    getArchiveBean().unpack(archiveFile, unpackDir);
    return unpackDir;
}
Also used : PipeException(com.alibaba.otter.node.etl.common.pipe.exception.PipeException) DataRetriever(com.alibaba.otter.node.etl.common.io.download.DataRetriever) File(java.io.File) BeansException(org.springframework.beans.BeansException) PipeException(com.alibaba.otter.node.etl.common.pipe.exception.PipeException) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 3 with DataRetriever

use of com.alibaba.otter.node.etl.common.io.download.DataRetriever in project otter by alibaba.

the class RowDataHttpPipe method getDbBatch.

// 处理对应的dbBatch
private DbBatch getDbBatch(HttpPipeKey key) {
    String dataUrl = key.getUrl();
    Pipeline pipeline = configClientService.findPipeline(key.getIdentity().getPipelineId());
    DataRetriever dataRetriever = dataRetrieverFactory.createRetriever(pipeline.getParameters().getRetriever(), dataUrl, downloadDir);
    File archiveFile = null;
    try {
        dataRetriever.connect();
        dataRetriever.doRetrieve();
        archiveFile = dataRetriever.getDataAsFile();
    } catch (Exception e) {
        dataRetriever.abort();
        throw new PipeException("download_error", e);
    } finally {
        dataRetriever.disconnect();
    }
    // 处理下有加密的数据
    if (StringUtils.isNotEmpty(key.getKey()) && StringUtils.isNotEmpty(key.getCrc())) {
        decodeFile(archiveFile, key.getKey(), key.getCrc());
    }
    InputStream input = null;
    JSONReader reader = null;
    try {
        input = new BufferedInputStream(new FileInputStream(archiveFile));
        DbBatch dbBatch = new DbBatch();
        byte[] lengthBytes = new byte[4];
        input.read(lengthBytes);
        int length = ByteUtils.bytes2int(lengthBytes);
        BatchProto.RowBatch rowbatchProto = BatchProto.RowBatch.parseFrom(new LimitedInputStream(input, length));
        // 构造原始的model对象
        RowBatch rowBatch = new RowBatch();
        rowBatch.setIdentity(build(rowbatchProto.getIdentity()));
        for (BatchProto.RowData rowDataProto : rowbatchProto.getRowsList()) {
            EventData eventData = new EventData();
            eventData.setPairId(rowDataProto.getPairId());
            eventData.setTableId(rowDataProto.getTableId());
            eventData.setTableName(rowDataProto.getTableName());
            eventData.setSchemaName(rowDataProto.getSchemaName());
            eventData.setEventType(EventType.valuesOf(rowDataProto.getEventType()));
            eventData.setExecuteTime(rowDataProto.getExecuteTime());
            // add by ljh at 2012-10-31
            if (StringUtils.isNotEmpty(rowDataProto.getSyncMode())) {
                eventData.setSyncMode(SyncMode.valuesOf(rowDataProto.getSyncMode()));
            }
            if (StringUtils.isNotEmpty(rowDataProto.getSyncConsistency())) {
                eventData.setSyncConsistency(SyncConsistency.valuesOf(rowDataProto.getSyncConsistency()));
            }
            // 处理主键
            List<EventColumn> keys = new ArrayList<EventColumn>();
            for (BatchProto.Column columnProto : rowDataProto.getKeysList()) {
                keys.add(buildColumn(columnProto));
            }
            eventData.setKeys(keys);
            // 处理old主键
            if (CollectionUtils.isEmpty(rowDataProto.getOldKeysList()) == false) {
                List<EventColumn> oldKeys = new ArrayList<EventColumn>();
                for (BatchProto.Column columnProto : rowDataProto.getOldKeysList()) {
                    oldKeys.add(buildColumn(columnProto));
                }
                eventData.setOldKeys(oldKeys);
            }
            // 处理具体的column value
            List<EventColumn> columns = new ArrayList<EventColumn>();
            for (BatchProto.Column columnProto : rowDataProto.getColumnsList()) {
                columns.add(buildColumn(columnProto));
            }
            eventData.setColumns(columns);
            eventData.setRemedy(rowDataProto.getRemedy());
            eventData.setSize(rowDataProto.getSize());
            eventData.setSql(rowDataProto.getSql());
            eventData.setDdlSchemaName(rowDataProto.getDdlSchemaName());
            eventData.setHint(rowDataProto.getHint());
            eventData.setWithoutSchema(rowDataProto.getWithoutSchema());
            // 添加到总记录
            rowBatch.merge(eventData);
        }
        dbBatch.setRowBatch(rowBatch);
        input.read(lengthBytes);
        length = ByteUtils.bytes2int(lengthBytes);
        BatchProto.FileBatch filebatchProto = BatchProto.FileBatch.parseFrom(new LimitedInputStream(input, length));
        // 构造原始的model对象
        FileBatch fileBatch = new FileBatch();
        fileBatch.setIdentity(build(filebatchProto.getIdentity()));
        for (BatchProto.FileData fileDataProto : filebatchProto.getFilesList()) {
            FileData fileData = new FileData();
            fileData.setPairId(fileDataProto.getPairId());
            fileData.setTableId(fileDataProto.getTableId());
            fileData.setEventType(EventType.valuesOf(fileDataProto.getEventType()));
            fileData.setLastModifiedTime(fileDataProto.getLastModifiedTime());
            fileData.setNameSpace(fileDataProto.getNamespace());
            fileData.setPath(fileDataProto.getPath());
            fileData.setSize(fileDataProto.getSize());
            // 添加到filebatch中
            fileBatch.getFiles().add(fileData);
        }
        dbBatch.setFileBatch(fileBatch);
        return dbBatch;
    } catch (IOException e) {
        throw new PipeException("deserial_error", e);
    } finally {
        IOUtils.closeQuietly(reader);
    }
}
Also used : EventColumn(com.alibaba.otter.shared.etl.model.EventColumn) ArrayList(java.util.ArrayList) DbBatch(com.alibaba.otter.shared.etl.model.DbBatch) EventData(com.alibaba.otter.shared.etl.model.EventData) BufferedInputStream(java.io.BufferedInputStream) FileData(com.alibaba.otter.shared.etl.model.FileData) FileBatch(com.alibaba.otter.shared.etl.model.FileBatch) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DataRetriever(com.alibaba.otter.node.etl.common.io.download.DataRetriever) IOException(java.io.IOException) BatchProto(com.alibaba.otter.node.etl.model.protobuf.BatchProto) IOException(java.io.IOException) PipeException(com.alibaba.otter.node.etl.common.pipe.exception.PipeException) FileInputStream(java.io.FileInputStream) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) RowBatch(com.alibaba.otter.shared.etl.model.RowBatch) PipeException(com.alibaba.otter.node.etl.common.pipe.exception.PipeException) JSONReader(com.alibaba.fastjson.JSONReader) File(java.io.File)

Example 4 with DataRetriever

use of com.alibaba.otter.node.etl.common.io.download.DataRetriever in project otter by alibaba.

the class Aria2cDownLoadIntegration method testDownLoad_failed.

@Test
public void testDownLoad_failed() {
    DataRetriever retriever = new Aria2cRetriever("aaaaaaa/sssss", tmp);
    try {
        retriever.connect();
        retriever.doRetrieve();
    } catch (DataRetrieveException ex) {
        retriever.abort();
    } finally {
        retriever.disconnect();
    }
}
Also used : Aria2cRetriever(com.alibaba.otter.node.etl.common.io.download.impl.aria2c.Aria2cRetriever) DataRetrieveException(com.alibaba.otter.node.etl.common.io.download.exception.DataRetrieveException) DataRetriever(com.alibaba.otter.node.etl.common.io.download.DataRetriever) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.node.etl.BaseOtterTest)

Aggregations

DataRetriever (com.alibaba.otter.node.etl.common.io.download.DataRetriever)4 BaseOtterTest (com.alibaba.otter.node.etl.BaseOtterTest)2 DataRetrieveException (com.alibaba.otter.node.etl.common.io.download.exception.DataRetrieveException)2 Aria2cRetriever (com.alibaba.otter.node.etl.common.io.download.impl.aria2c.Aria2cRetriever)2 PipeException (com.alibaba.otter.node.etl.common.pipe.exception.PipeException)2 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)2 File (java.io.File)2 Test (org.testng.annotations.Test)2 JSONReader (com.alibaba.fastjson.JSONReader)1 BatchProto (com.alibaba.otter.node.etl.model.protobuf.BatchProto)1 DbBatch (com.alibaba.otter.shared.etl.model.DbBatch)1 EventColumn (com.alibaba.otter.shared.etl.model.EventColumn)1 EventData (com.alibaba.otter.shared.etl.model.EventData)1 FileBatch (com.alibaba.otter.shared.etl.model.FileBatch)1 FileData (com.alibaba.otter.shared.etl.model.FileData)1 RowBatch (com.alibaba.otter.shared.etl.model.RowBatch)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1