Search in sources :

Example 1 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 2 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 3 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 4 with DataMediaPair

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

the class BehaviorHistoryCurve method execute.

public void execute(@Param("d5221") String startTime, @Param("d5222") String endTime, @Param("dataMediaPairId") Long dataMediaPairId, HttpSession session, Context context) throws Exception {
    Date end = null;
    Date start = null;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) {
        start = new Date(System.currentTimeMillis() / 60000 * 60000 - 24 * 60 * 60 * 1000);
        end = new Date(System.currentTimeMillis() / 60000 * 60000);
    } else {
        // 当前24小时,时间取整分钟
        sdf.setLenient(false);
        if (null != startTime && null != endTime) {
            start = sdf.parse(startTime);
            end = sdf.parse(endTime);
        }
    }
    DataMediaPair dataMediaPair = dataMediaPairService.findById(dataMediaPairId);
    Channel channel = channelService.findByPipelineId(dataMediaPair.getPipelineId());
    Map<Long, BehaviorHistoryInfo> behaviourHistoryInfos = new LinkedHashMap<Long, BehaviorHistoryInfo>();
    TimelineBehaviorHistoryCondition condition = new TimelineBehaviorHistoryCondition();
    if (null != start && null != end) {
        condition.setStart(start);
        condition.setEnd(end);
        condition.setPairId(dataMediaPairId);
        behaviourHistoryInfos = tableStatService.listTimelineBehaviorHistory(condition);
    }
    Long totalInsert = 0L;
    Long totalUpdate = 0L;
    Long totalDelete = 0L;
    Long totalFileCount = 0L;
    Long totalFileSize = 0L;
    for (BehaviorHistoryInfo info : behaviourHistoryInfos.values()) {
        totalInsert += info.getInsertNumber();
        totalUpdate += info.getUpdateNumber();
        totalDelete += info.getDeleteNumber();
        totalFileCount += info.getFileNumber();
        totalFileSize += info.getFileSize();
    }
    context.put("totalInsert", totalInsert);
    context.put("totalUpdate", totalUpdate);
    context.put("totalDelete", totalDelete);
    context.put("totalFileCount", totalFileCount);
    context.put("totalFileSize", totalFileSize);
    context.put("behaviourHistoryInfos", behaviourHistoryInfos);
    context.put("start", sdf.format(start));
    context.put("end", sdf.format(end));
    context.put("dataMediaPair", dataMediaPair);
    context.put("channel", channel);
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) BehaviorHistoryInfo(com.alibaba.otter.manager.biz.statistics.table.param.BehaviorHistoryInfo) TimelineBehaviorHistoryCondition(com.alibaba.otter.manager.biz.statistics.table.param.TimelineBehaviorHistoryCondition) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with DataMediaPair

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

the class DataMediaPairAction method doBatchAdd.

/**
 * 批量添加DataMediaPair
 *
 * @param dataMediaPairInfo
 * @throws Exception
 */
public void doBatchAdd(@FormGroup("batchDataMediaPairInfo") Group batchDataMediaPairInfo, @Param("pipelineId") Long pipelineId, @FormField(name = "formBatchDataMediaPairError", group = "batchDataMediaPairInfo") CustomErrors err, Navigator nav) throws Exception {
    String batchPairContent = batchDataMediaPairInfo.getField("batchPairContent").getStringValue();
    List<String> StringPairs = Arrays.asList(batchPairContent.split("\r\n"));
    try {
        for (String stringPair : StringPairs) {
            List<String> pairData = Arrays.asList(stringPair.split(","));
            if (pairData.size() < 4) {
                throw new ManagerException("[" + stringPair + "] the line not all parameters");
            }
            // build the pair source
            DataMedia sourceDataMedia = new DataMedia();
            DataMediaSource sourceDataMediaSource = dataMediaSourceService.findById(Long.parseLong(StringUtils.trimToNull(pairData.get(2))));
            sourceDataMedia.setNamespace(StringUtils.trimToNull(pairData.get(0)));
            sourceDataMedia.setName(StringUtils.trimToNull(pairData.get(1)));
            sourceDataMedia.setSource(sourceDataMediaSource);
            Long sourceMediaId = dataMediaService.createReturnId(sourceDataMedia);
            sourceDataMedia.setId(sourceMediaId);
            // build the pair target
            DataMedia targetDataMedia = new DataMedia();
            Long weight = 5L;
            if (StringUtils.isNumeric(pairData.get(3)) && pairData.size() <= 5) {
                // 如果是纯数字,那说明是简化配置模式
                DataMediaSource targetDataMediaSource = dataMediaSourceService.findById(Long.parseLong(StringUtils.trimToNull(pairData.get(3))));
                targetDataMedia.setNamespace(StringUtils.trimToNull(pairData.get(0)));
                targetDataMedia.setName(StringUtils.trimToNull(pairData.get(1)));
                targetDataMedia.setSource(targetDataMediaSource);
                Long targetMediaId = dataMediaService.createReturnId(targetDataMedia);
                targetDataMedia.setId(targetMediaId);
                if (pairData.size() >= 5) {
                    weight = Long.parseLong(StringUtils.trimToNull(pairData.get(4)));
                }
            } else {
                DataMediaSource targetDataMediaSource = dataMediaSourceService.findById(Long.parseLong(StringUtils.trimToNull(pairData.get(5))));
                targetDataMedia.setNamespace(StringUtils.trimToNull(pairData.get(3)));
                targetDataMedia.setName(StringUtils.trimToNull(pairData.get(4)));
                targetDataMedia.setSource(targetDataMediaSource);
                Long targetMediaId = dataMediaService.createReturnId(targetDataMedia);
                targetDataMedia.setId(targetMediaId);
                if (pairData.size() >= 7) {
                    weight = Long.parseLong(StringUtils.trimToNull(pairData.get(6)));
                }
            }
            // build the pair
            DataMediaPair dataMediaPair = new DataMediaPair();
            dataMediaPair.setSource(sourceDataMedia);
            dataMediaPair.setTarget(targetDataMedia);
            dataMediaPair.setPushWeight(weight);
            dataMediaPair.setPipelineId(pipelineId);
            dataMediaPairService.createIfNotExist(dataMediaPair);
        }
    } catch (Exception e) {
        err.setMessage("invalidBatchDataMediaPair");
        return;
    }
    nav.redirectToLocation("dataMediaPairList.htm?pipelineId=" + pipelineId);
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) DataMediaSource(com.alibaba.otter.shared.common.model.config.data.DataMediaSource) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) DataMedia(com.alibaba.otter.shared.common.model.config.data.DataMedia) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) WebxException(com.alibaba.citrus.webx.WebxException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

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