Search in sources :

Example 21 with DataMediaPair

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

the class DataMediaPairList method execute.

public void execute(@Param("pipelineId") Long pipelineId, Context context) throws Exception {
    // Pipeline pipeline = pipelineService.findById(pipelineId);
    Channel channel = channelService.findByPipelineId(pipelineId);
    List<DataMediaPair> dataMediaPairs = dataMediaPairService.listByPipelineId(pipelineId);
    Map<Long, TableStat> tableStatMap = new HashMap<Long, TableStat>(dataMediaPairs.size(), 1f);
    List<TableStat> tableStats = tableStatService.listTableStat(pipelineId);
    for (DataMediaPair dataMediaPair : dataMediaPairs) {
        int flag = 0;
        for (TableStat tableStat : tableStats) {
            if (dataMediaPair.getId().equals(tableStat.getDataMediaPairId())) {
                tableStatMap.put(dataMediaPair.getId(), tableStat);
                flag = 1;
                break;
            }
        }
        if (flag == 0) {
            TableStat tableStat = new TableStat();
            tableStat.setFileSize(0L);
            tableStat.setFileCount(0L);
            tableStat.setDeleteCount(0L);
            tableStat.setUpdateCount(0L);
            tableStat.setInsertCount(0L);
            // tableStat.setGmtModified(dataMediaPair.getGmtModified());
            tableStatMap.put(dataMediaPair.getId(), tableStat);
        }
    }
    context.put("dataMediaPairs", dataMediaPairs);
    // 通过PipelineId不能获取到Channel状态,所以需要传递Channel对象
    context.put("channel", channel);
    context.put("pipelineId", pipelineId);
    context.put("tableStatMap", tableStatMap);
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) HashMap(java.util.HashMap) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) TableStat(com.alibaba.otter.shared.common.model.statistics.table.TableStat)

Example 22 with DataMediaPair

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

the class DbLoadAction method buildWeightBuckets.

/**
     * 构建基于weight权重分组的item集合列表
     */
private WeightBuckets<EventData> buildWeightBuckets(DbLoadContext context, List<EventData> datas) {
    WeightBuckets<EventData> buckets = new WeightBuckets<EventData>();
    for (EventData data : datas) {
        // 获取对应的weight
        DataMediaPair pair = ConfigHelper.findDataMediaPair(context.getPipeline(), data.getPairId());
        buckets.addItem(pair.getPushWeight(), data);
    }
    return buckets;
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) WeightBuckets(com.alibaba.otter.node.etl.load.loader.weight.WeightBuckets) EventData(com.alibaba.otter.shared.etl.model.EventData)

Example 23 with DataMediaPair

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

the class FileExtractor method doFileExtract.

/**
     * 返回这批变更数据对应的FileInfo.
     * 
     * @param rowBatch
     * @return
     */
private List<FileData> doFileExtract(RowBatch rowBatch) {
    List<FileData> fileDatas = new ArrayList<FileData>();
    // 处理数据
    Pipeline pipeline = getPipeline(rowBatch.getIdentity().getPipelineId());
    List<EventData> eventDatas = rowBatch.getDatas();
    for (EventData eventData : eventDatas) {
        if (eventData.getEventType().isDdl()) {
            continue;
        }
        List<DataMediaPair> dataMediaPairs = ConfigHelper.findDataMediaPairByMediaId(pipeline, eventData.getTableId());
        if (dataMediaPairs == null) {
            throw new ExtractException("ERROR ## the dataMediaId = " + eventData.getTableId() + " dataMediaPair is null,please check");
        }
        for (DataMediaPair dataMediaPair : dataMediaPairs) {
            if (dataMediaPair.getResolverData() == null || dataMediaPair.getResolverData().getExtensionDataType() == null || (dataMediaPair.getResolverData().getExtensionDataType().isClazz() && StringUtils.isBlank(dataMediaPair.getResolverData().getClazzPath())) || (dataMediaPair.getResolverData().getExtensionDataType().isSource() && StringUtils.isBlank(dataMediaPair.getResolverData().getSourceText()))) {
                continue;
            }
            FileResolver fileResolver = null;
            if (dataMediaPair.getResolverData() != null) {
                fileResolver = extensionFactory.getExtension(FileResolver.class, dataMediaPair.getResolverData());
            } else {
                continue;
            }
            if (fileResolver == null) {
                throw new ExtractException("ERROR ## the dataMediaId = " + eventData.getTableId() + " the fileResolver className  = " + dataMediaPair.getResolverData().getClazzPath() + " is null ,please check the class");
            }
            if (fileResolver instanceof RemoteDirectoryFetcherAware) {
                RemoteDirectoryFetcherAware remoteDirectoryFetcherAware = (RemoteDirectoryFetcherAware) fileResolver;
                remoteDirectoryFetcherAware.setRemoteDirectoryFetcher(arandaRemoteDirectoryFetcher);
            }
            List<FileData> singleRowFileDatas = getSingleRowFileInfos(dataMediaPair.getId(), fileResolver, eventData);
            // 做一下去重处理
            for (FileData data : singleRowFileDatas) {
                if (!fileDatas.contains(data)) {
                    fileDatas.add(data);
                }
            }
        }
    }
    // 判断是否需要进行图片重复同步检查
    if (pipeline.getParameters().getFileDetect()) {
        doFileDetectCollector(pipeline, fileDatas);
    }
    return fileDatas;
}
Also used : ExtractException(com.alibaba.otter.node.etl.extract.exceptions.ExtractException) RemoteDirectoryFetcherAware(com.alibaba.otter.shared.etl.extend.fileresolver.support.RemoteDirectoryFetcherAware) DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) ArrayList(java.util.ArrayList) FileResolver(com.alibaba.otter.shared.etl.extend.fileresolver.FileResolver) FileData(com.alibaba.otter.shared.etl.model.FileData) EventData(com.alibaba.otter.shared.etl.model.EventData) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 24 with DataMediaPair

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

the class GroupExtractor method extract.

@Override
public void extract(DbBatch dbBatch) throws ExtractException {
    Assert.notNull(dbBatch);
    Assert.notNull(dbBatch.getRowBatch());
    Pipeline pipeline = getPipeline(dbBatch.getRowBatch().getIdentity().getPipelineId());
    List<DataMediaPair> dataMediaPairs = pipeline.getPairs();
    /**
         * Key = TableId<br>
         * Value = a List of this tableId's column need to sync<br>
         */
    Map<Long, List<ColumnGroup>> groupColumns = new HashMap<Long, List<ColumnGroup>>();
    for (DataMediaPair dataMediaPair : dataMediaPairs) {
        List<ColumnGroup> columnGroups = dataMediaPair.getColumnGroups();
        if (!CollectionUtils.isEmpty(columnGroups)) {
            groupColumns.put(dataMediaPair.getSource().getId(), columnGroups);
        }
    }
    List<EventData> eventDatas = dbBatch.getRowBatch().getDatas();
    for (EventData eventData : eventDatas) {
        if (eventData.getEventType().isDdl()) {
            continue;
        }
        List<ColumnGroup> columnGroups = groupColumns.get(eventData.getTableId());
        if (!CollectionUtils.isEmpty(columnGroups)) {
            for (ColumnGroup columnGroup : columnGroups) {
                if (columnGroup != null && !CollectionUtils.isEmpty(columnGroup.getColumnPairs())) {
                    groupFilter(eventData, columnGroup);
                }
            }
        }
    }
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ColumnGroup(com.alibaba.otter.shared.common.model.config.data.ColumnGroup) EventData(com.alibaba.otter.shared.etl.model.EventData) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 25 with DataMediaPair

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

the class FileLoadAction method buildWeightBuckets.

/**
     * 构建基于weight权重分组的item集合列表
     */
private WeightBuckets<FileData> buildWeightBuckets(Identity identity, List<FileData> datas) {
    WeightBuckets<FileData> buckets = new WeightBuckets<FileData>();
    for (FileData data : datas) {
        // 获取对应的weight
        DataMediaPair pair = ConfigHelper.findDataMediaPair(getPipeline(identity), data.getPairId());
        buckets.addItem(pair.getPushWeight(), data);
    }
    return buckets;
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) WeightBuckets(com.alibaba.otter.node.etl.load.loader.weight.WeightBuckets) FileData(com.alibaba.otter.shared.etl.model.FileData)

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