Search in sources :

Example 1 with PipelineNodeRelationDO

use of com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineNodeRelationDO in project otter by alibaba.

the class PipelineServiceImpl method doToModelWithoutColumn.

private Pipeline doToModelWithoutColumn(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.listByPipelineIdWithoutColumn(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 2 with PipelineNodeRelationDO

use of com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineNodeRelationDO 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 3 with PipelineNodeRelationDO

use of com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineNodeRelationDO in project otter by alibaba.

the class IbatisPipelineNodeRelationDAO method insertBatch.

public void insertBatch(List<PipelineNodeRelationDO> pipelineNodeRelationDos) {
    try {
        getSqlMapClientTemplate().getSqlMapClient().startBatch();
        Iterator it = pipelineNodeRelationDos.iterator();
        while (it.hasNext()) {
            PipelineNodeRelationDO pipelineNodeRelationDo = (PipelineNodeRelationDO) it.next();
            getSqlMapClientTemplate().getSqlMapClient().insert("insertPipelineNodeRelation", pipelineNodeRelationDo);
        }
        getSqlMapClientTemplate().getSqlMapClient().executeBatch();
    } catch (SQLException ex1) {
        ex1.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) Iterator(java.util.Iterator) PipelineNodeRelationDO(com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineNodeRelationDO)

Example 4 with PipelineNodeRelationDO

use of com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineNodeRelationDO in project otter by alibaba.

the class PipelineServiceImpl method create.

/**
     * 添加
     */
public void create(final Pipeline pipeline) {
    Assert.assertNotNull(pipeline);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            try {
                PipelineDO pipelineDo = modelToDo(pipeline);
                pipelineDo.setId(0L);
                if (!pipelineDao.checkUnique(pipelineDo)) {
                    String exceptionCause = "exist the same name pipeline under the channel(" + pipelineDo.getChannelId() + ") in the database.";
                    logger.warn("WARN ## " + exceptionCause);
                    throw new RepeatConfigureException(exceptionCause);
                }
                pipelineDao.insert(pipelineDo);
                List<PipelineNodeRelationDO> pipelineNodeRelationDos = new ArrayList<PipelineNodeRelationDO>();
                for (Node node : pipeline.getSelectNodes()) {
                    PipelineNodeRelationDO pipelineNodeRelationDo = new PipelineNodeRelationDO();
                    pipelineNodeRelationDo.setPipelineId(pipelineDo.getId());
                    pipelineNodeRelationDo.setNodeId(node.getId());
                    pipelineNodeRelationDo.setLocation(Location.SELECT);
                    pipelineNodeRelationDos.add(pipelineNodeRelationDo);
                }
                for (Node node : pipeline.getExtractNodes()) {
                    PipelineNodeRelationDO pipelineNodeRelationDo = new PipelineNodeRelationDO();
                    pipelineNodeRelationDo.setPipelineId(pipelineDo.getId());
                    pipelineNodeRelationDo.setNodeId(node.getId());
                    pipelineNodeRelationDo.setLocation(Location.EXTRACT);
                    pipelineNodeRelationDos.add(pipelineNodeRelationDo);
                }
                for (Node node : pipeline.getLoadNodes()) {
                    PipelineNodeRelationDO pipelineNodeRelationDo = new PipelineNodeRelationDO();
                    pipelineNodeRelationDo.setPipelineId(pipelineDo.getId());
                    pipelineNodeRelationDo.setNodeId(node.getId());
                    pipelineNodeRelationDo.setLocation(Location.LOAD);
                    pipelineNodeRelationDos.add(pipelineNodeRelationDo);
                }
                pipelineNodeRelationDao.insertBatch(pipelineNodeRelationDos);
                arbitrateManageService.pipelineEvent().init(pipelineDo.getChannelId(), pipelineDo.getId());
            } catch (RepeatConfigureException rce) {
                throw rce;
            } catch (Exception e) {
                logger.error("ERROR ## create pipeline has an exception!");
                throw new ManagerException(e);
            }
        }
    });
}
Also used : RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) Node(com.alibaba.otter.shared.common.model.config.node.Node) TransactionStatus(org.springframework.transaction.TransactionStatus) PipelineDO(com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineDO) ArrayList(java.util.ArrayList) List(java.util.List) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) PipelineNodeRelationDO(com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineNodeRelationDO)

Example 5 with PipelineNodeRelationDO

use of com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineNodeRelationDO in project otter by alibaba.

the class PipelineServiceImpl method modify.

/**
     * 修改
     */
public void modify(Pipeline pipeline) {
    Assert.assertNotNull(pipeline);
    try {
        PipelineDO pipelineDo = modelToDo(pipeline);
        if (!pipelineDao.checkUnique(pipelineDo)) {
            String exceptionCause = "exist the same name pipeline under the channel(" + pipelineDo.getChannelId() + ") in the database.";
            logger.warn("WARN ## " + exceptionCause);
            throw new RepeatConfigureException(exceptionCause);
        }
        pipelineNodeRelationDao.deleteByPipelineId(pipelineDo.getId());
        pipelineDao.update(pipelineDo);
        List<PipelineNodeRelationDO> pipelineNodeRelationDos = new ArrayList<PipelineNodeRelationDO>();
        for (Node node : pipeline.getSelectNodes()) {
            PipelineNodeRelationDO pipelineNodeRelationDo = new PipelineNodeRelationDO();
            pipelineNodeRelationDo.setPipelineId(pipelineDo.getId());
            pipelineNodeRelationDo.setNodeId(node.getId());
            pipelineNodeRelationDo.setLocation(Location.SELECT);
            pipelineNodeRelationDos.add(pipelineNodeRelationDo);
        }
        for (Node node : pipeline.getExtractNodes()) {
            PipelineNodeRelationDO pipelineNodeRelationDo = new PipelineNodeRelationDO();
            pipelineNodeRelationDo.setPipelineId(pipelineDo.getId());
            pipelineNodeRelationDo.setNodeId(node.getId());
            pipelineNodeRelationDo.setLocation(Location.EXTRACT);
            pipelineNodeRelationDos.add(pipelineNodeRelationDo);
        }
        for (Node node : pipeline.getLoadNodes()) {
            PipelineNodeRelationDO pipelineNodeRelationDo = new PipelineNodeRelationDO();
            pipelineNodeRelationDo.setPipelineId(pipelineDo.getId());
            pipelineNodeRelationDo.setNodeId(node.getId());
            pipelineNodeRelationDo.setLocation(Location.LOAD);
            pipelineNodeRelationDos.add(pipelineNodeRelationDo);
        }
        pipelineNodeRelationDao.insertBatch(pipelineNodeRelationDos);
    } catch (Exception e) {
        logger.error("ERROR ## modify the pipeline(" + pipeline.getId() + ") has an exception!");
        throw new ManagerException(e);
    }
}
Also used : RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) Node(com.alibaba.otter.shared.common.model.config.node.Node) ArrayList(java.util.ArrayList) PipelineDO(com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineDO) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) PipelineNodeRelationDO(com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineNodeRelationDO)

Aggregations

PipelineNodeRelationDO (com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineNodeRelationDO)6 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)5 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)5 ArrayList (java.util.ArrayList)5 Node (com.alibaba.otter.shared.common.model.config.node.Node)4 PipelineDO (com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineDO)3 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)3 DataMediaPair (com.alibaba.otter.shared.common.model.config.data.DataMediaPair)2 DataMediaPairComparable (com.alibaba.otter.shared.common.model.config.data.DataMediaPairComparable)2 SQLException (java.sql.SQLException)1 Iterator (java.util.Iterator)1 List (java.util.List)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1