Search in sources :

Example 6 with DataMediaPair

use of com.alibaba.otter.shared.common.model.config.data.DataMediaPair in project otter by alibaba.

the class PipelineServiceImpl method doToModel.

/**
     * 用于DO对象转化为Model对象
     * 
     * @param pipelineDO
     * @return Pipeline
     */
private Pipeline doToModel(PipelineDO pipelineDo) {
    Pipeline pipeline = new Pipeline();
    try {
        pipeline.setId(pipelineDo.getId());
        pipeline.setName(pipelineDo.getName());
        pipeline.setParameters(pipelineDo.getParameters());
        pipeline.setDescription(pipelineDo.getDescription());
        pipeline.setGmtCreate(pipelineDo.getGmtCreate());
        pipeline.setGmtModified(pipelineDo.getGmtModified());
        pipeline.setChannelId(pipelineDo.getChannelId());
        pipeline.getParameters().setMainstemClientId(pipeline.getId().shortValue());
        // 组装DatamediaPair
        List<DataMediaPair> pairs = dataMediaPairService.listByPipelineId(pipelineDo.getId());
        Collections.sort(pairs, new DataMediaPairComparable());
        pipeline.setPairs(pairs);
        // 组装Node
        List<PipelineNodeRelationDO> relations = pipelineNodeRelationDao.listByPipelineIds(pipelineDo.getId());
        List<Long> totalNodeIds = new ArrayList<Long>();
        for (PipelineNodeRelationDO relation : relations) {
            Long nodeId = relation.getNodeId();
            if (!totalNodeIds.contains(nodeId)) {
                totalNodeIds.add(nodeId);
            }
        }
        List<Node> totalNodes = nodeService.listByIds(totalNodeIds.toArray(new Long[totalNodeIds.size()]));
        List<Node> selectNodes = new ArrayList<Node>();
        List<Node> extractNodes = new ArrayList<Node>();
        List<Node> loadNodes = new ArrayList<Node>();
        for (Node node : totalNodes) {
            for (PipelineNodeRelationDO relation : relations) {
                if (node.getId().equals(relation.getNodeId())) {
                    if (relation.getLocation().isSelect()) {
                        selectNodes.add(node);
                    } else if (relation.getLocation().isExtract()) {
                        extractNodes.add(node);
                    } else if (relation.getLocation().isLoad()) {
                        loadNodes.add(node);
                    }
                }
            }
        }
        pipeline.setSelectNodes(selectNodes);
        pipeline.setExtractNodes(extractNodes);
        pipeline.setLoadNodes(loadNodes);
    } catch (Exception e) {
        logger.error("ERROR ## change the pipeline Do to Model has an exception");
        throw new ManagerException(e);
    }
    return pipeline;
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) Node(com.alibaba.otter.shared.common.model.config.node.Node) ArrayList(java.util.ArrayList) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) DataMediaPairComparable(com.alibaba.otter.shared.common.model.config.data.DataMediaPairComparable) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) PipelineNodeRelationDO(com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineNodeRelationDO)

Example 7 with DataMediaPair

use of com.alibaba.otter.shared.common.model.config.data.DataMediaPair in project otter by alibaba.

the class FileLoadActionTest method buildPipeline.

protected Pipeline buildPipeline(final int fileDataStartIndex, int fileDataCount) {
    final Pipeline pipeline = new Pipeline();
    pipeline.setParameters(new PipelineParameter());
    int dataMediaPairCount = fileDataCount / NUMBER_OF_FILE_DATA_COPIES;
    pipeline.setPairs(new ArrayList<DataMediaPair>(dataMediaPairCount));
    for (int i = fileDataStartIndex; i < dataMediaPairCount; i++) {
        DataMediaPair dataMediaPair = buildDataMediaPair(i, i);
        pipeline.getPairs().add(dataMediaPair);
    }
    return pipeline;
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) PipelineParameter(com.alibaba.otter.shared.common.model.config.pipeline.PipelineParameter) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 8 with DataMediaPair

use of com.alibaba.otter.shared.common.model.config.data.DataMediaPair in project otter by alibaba.

the class FileLoadActionTest method buildDataMediaPair.

protected DataMediaPair buildDataMediaPair(long id, long pushWeight) {
    DataMediaPair result = new DataMediaPair();
    result.setId(id);
    result.setPushWeight(pushWeight);
    return result;
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair)

Example 9 with DataMediaPair

use of com.alibaba.otter.shared.common.model.config.data.DataMediaPair in project otter by alibaba.

the class LocalFileLoaderActionTest method generatorDataMediaPair.

private List<DataMediaPair> generatorDataMediaPair(int count) {
    List<DataMediaPair> pairs = new ArrayList<DataMediaPair>();
    for (int i = 0; i < count; i++) {
        DataMediaPair pair = new DataMediaPair();
        pair.setId(Long.valueOf(i));
        pair.setPullWeight(Long.valueOf(i));
        pair.setPushWeight(Long.valueOf(i));
        DbDataMedia mysqlMedia = getMysqlMedia();
        mysqlMedia.setId(Long.valueOf(count + 1));
        pair.setSource(mysqlMedia);
        DbDataMedia oracleMedia = getOracleMedia();
        oracleMedia.setId(Long.valueOf(i));
        pair.setTarget(oracleMedia);
        pairs.add(pair);
    }
    return pairs;
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) ArrayList(java.util.ArrayList) DbDataMedia(com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia)

Example 10 with DataMediaPair

use of com.alibaba.otter.shared.common.model.config.data.DataMediaPair in project otter by alibaba.

the class OtterTransformerTest method test_rowData_mysql_oracle.

@Test
public void test_rowData_mysql_oracle() {
    final Pipeline pipeline = new Pipeline();
    pipeline.setId(100L);
    List<DataMediaPair> pairs = new ArrayList<DataMediaPair>();
    DataMediaPair pair1 = new DataMediaPair();
    pair1.setId(1L);
    pair1.setPipelineId(pipeline.getId());
    pair1.setPullWeight(1L);
    pair1.setPushWeight(1L);
    DbDataMedia mysqlMedia = getMysqlMedia();
    mysqlMedia.setId(1L);
    pair1.setSource(mysqlMedia);
    DbDataMedia oracleMedia = getOracleMedia();
    pair1.setTarget(oracleMedia);
    pairs.add(pair1);
    pipeline.setPairs(pairs);
    PipelineParameter param = new PipelineParameter();
    param.setSyncMode(SyncMode.ROW);
    pipeline.setParameters(param);
    new NonStrictExpectations() {

        {
            configClientService.findPipeline(anyLong);
            returns(pipeline);
        }
    };
    Identity identity = new Identity();
    identity.setChannelId(100L);
    identity.setPipelineId(100L);
    identity.setProcessId(100L);
    RowBatch rowBatch = new RowBatch();
    rowBatch.setIdentity(identity);
    EventData eventData = new EventData();
    eventData.setTableId(1L);
    eventData.setSchemaName("srf");
    eventData.setTableName("columns");
    eventData.setEventType(EventType.UPDATE);
    eventData.setExecuteTime(100L);
    eventData.getKeys().add(buildColumn("id", Types.INTEGER, "1", true, false));
    eventData.getKeys().add(buildColumn("name", Types.VARCHAR, "ljh", true, false));
    eventData.getColumns().add(buildColumn("alias_name", Types.CHAR, "hello", false, false));
    eventData.getColumns().add(buildColumn("amount", Types.DECIMAL, "100.01", false, false));
    eventData.getColumns().add(buildColumn("text_b", Types.BLOB, "[116,101,120,116,95,98]", false, false));
    eventData.getColumns().add(buildColumn("text_c", Types.CLOB, "text_c", false, false));
    eventData.getColumns().add(buildColumn("curr_date", Types.DATE, "2011-01-01", false, false));
    eventData.getColumns().add(buildColumn("gmt_create", Types.TIMESTAMP, "2011-01-01 11:11:11", false, false));
    eventData.getColumns().add(buildColumn("gmt_modify", Types.TIMESTAMP, "2011-01-01 11:11:11", false, false));
    rowBatch.merge(eventData);
    Map<Class, BatchObject> batchs = otterTransformFactory.transform(rowBatch);
    RowBatch result = (RowBatch) batchs.get(EventData.class);
    want.number(result.getDatas().size()).isEqualTo(1);
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) ArrayList(java.util.ArrayList) EventData(com.alibaba.otter.shared.etl.model.EventData) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) RowBatch(com.alibaba.otter.shared.etl.model.RowBatch) BatchObject(com.alibaba.otter.shared.etl.model.BatchObject) PipelineParameter(com.alibaba.otter.shared.common.model.config.pipeline.PipelineParameter) Identity(com.alibaba.otter.shared.etl.model.Identity) DbDataMedia(com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia) Test(org.testng.annotations.Test) BaseDbTest(com.alibaba.otter.node.etl.BaseDbTest)

Aggregations

DataMediaPair (com.alibaba.otter.shared.common.model.config.data.DataMediaPair)51 ArrayList (java.util.ArrayList)26 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)19 EventData (com.alibaba.otter.shared.etl.model.EventData)16 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)12 DataMedia (com.alibaba.otter.shared.common.model.config.data.DataMedia)11 DbDataMedia (com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia)10 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)9 BaseDbTest (com.alibaba.otter.node.etl.BaseDbTest)9 RowBatch (com.alibaba.otter.shared.etl.model.RowBatch)9 Test (org.testng.annotations.Test)9 Identity (com.alibaba.otter.shared.etl.model.Identity)8 DataMediaPairDO (com.alibaba.otter.manager.biz.config.datamediapair.dal.dataobject.DataMediaPairDO)6 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)6 HashMap (java.util.HashMap)6 ColumnPair (com.alibaba.otter.shared.common.model.config.data.ColumnPair)5 BatchObject (com.alibaba.otter.shared.etl.model.BatchObject)5 ColumnGroup (com.alibaba.otter.shared.common.model.config.data.ColumnGroup)4 Node (com.alibaba.otter.shared.common.model.config.node.Node)4 DbBatch (com.alibaba.otter.shared.etl.model.DbBatch)4