Search in sources :

Example 1 with DataMediaSource

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

the class DataSourceChecker method checkNamespaceTables.

public String checkNamespaceTables(final String namespace, final String name, final Long dataSourceId) {
    DataSource dataSource = null;
    try {
        DataMediaSource source = dataMediaSourceService.findById(dataSourceId);
        DbMediaSource dbMediaSource = (DbMediaSource) source;
        dataSource = dataSourceCreator.createDataSource(dbMediaSource);
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        List<String> schemaList;
        {
            ModeValue mode = ConfigHelper.parseMode(namespace);
            String schemaPattern = ConfigHelper.makeSQLPattern(mode, namespace);
            final ModeValueFilter modeValueFilter = ConfigHelper.makeModeValueFilter(mode, namespace);
            if (source.getType().isOracle()) {
                schemaList = Arrays.asList(namespace);
            } else {
                schemaList = DdlUtils.findSchemas(jdbcTemplate, schemaPattern, new DdlSchemaFilter() {

                    @Override
                    public boolean accept(String schemaName) {
                        return modeValueFilter.accept(schemaName);
                    }
                });
            }
        }
        final List<String> matchSchemaTables = new ArrayList<String>();
        matchSchemaTables.add("Find schema and tables:");
        if (schemaList != null) {
            ModeValue mode = ConfigHelper.parseMode(name);
            String tableNamePattern = ConfigHelper.makeSQLPattern(mode, name);
            final ModeValueFilter modeValueFilter = ConfigHelper.makeModeValueFilter(mode, name);
            for (String schema : schemaList) {
                DdlUtils.findTables(jdbcTemplate, schema, schema, tableNamePattern, null, new DdlTableNameFilter() {

                    @Override
                    public boolean accept(String catalogName, String schemaName, String tableName) {
                        if (modeValueFilter.accept(tableName)) {
                            matchSchemaTables.add(schemaName + "." + tableName);
                        }
                        return false;
                    }
                });
            }
        }
        if (matchSchemaTables.size() == 1) {
            return TABLE_FAIL;
        }
        return StringUtils.join(matchSchemaTables, "<br>\n");
    } catch (Exception e) {
        logger.error("check error!", e);
        return TABLE_FAIL;
    } finally {
        dataSourceCreator.destroyDataSource(dataSource);
    }
}
Also used : ModeValue(com.alibaba.otter.shared.common.model.config.data.DataMedia.ModeValue) ModeValueFilter(com.alibaba.otter.shared.common.model.config.ModeValueFilter) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) SQLException(java.sql.SQLException) DataSource(javax.sql.DataSource) DdlTableNameFilter(com.alibaba.otter.shared.common.utils.meta.DdlTableNameFilter) DataMediaSource(com.alibaba.otter.shared.common.model.config.data.DataMediaSource) DbMediaSource(com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource) DdlSchemaFilter(com.alibaba.otter.shared.common.utils.meta.DdlSchemaFilter)

Example 2 with DataMediaSource

use of com.alibaba.otter.shared.common.model.config.data.DataMediaSource 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)

Example 3 with DataMediaSource

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

the class DataMediaSourceAction method doAdd.

/**
     * 添加Channel
     * 
     * @param channelInfo
     * @param channelParameterInfo
     * @throws Exception
     */
public void doAdd(@FormGroup("dataMediaSourceInfo") Group dataMediaSourceInfo, @FormField(name = "formDataMediaSourceError", group = "dataMediaSourceInfo") CustomErrors err, Navigator nav) throws Exception {
    DataMediaSource dataMediaSource = new DataMediaSource();
    dataMediaSourceInfo.setProperties(dataMediaSource);
    if (dataMediaSource.getType().isMysql() || dataMediaSource.getType().isOracle()) {
        DbMediaSource dbMediaSource = new DbMediaSource();
        dataMediaSourceInfo.setProperties(dbMediaSource);
        if (dataMediaSource.getType().isMysql()) {
            dbMediaSource.setDriver("com.mysql.jdbc.Driver");
        } else if (dataMediaSource.getType().isOracle()) {
            dbMediaSource.setDriver("oracle.jdbc.driver.OracleDriver");
        }
        try {
            dataMediaSourceService.create(dbMediaSource);
        } catch (RepeatConfigureException rce) {
            err.setMessage("invalidDataMediaSource");
            return;
        }
    } else if (dataMediaSource.getType().isNapoli() || dataMediaSource.getType().isMq()) {
        MqMediaSource mqMediaSource = new MqMediaSource();
        dataMediaSourceInfo.setProperties(mqMediaSource);
        try {
            dataMediaSourceService.create(mqMediaSource);
        } catch (RepeatConfigureException rce) {
            err.setMessage("invalidDataMediaSource");
            return;
        }
    }
    nav.redirectTo(WebConstant.DATA_MEDIA_SOURCE_LIST_LINK);
}
Also used : RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) MqMediaSource(com.alibaba.otter.shared.common.model.config.data.mq.MqMediaSource) DataMediaSource(com.alibaba.otter.shared.common.model.config.data.DataMediaSource) DbMediaSource(com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource)

Example 4 with DataMediaSource

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

the class DataMatrixInfo method execute.

public void execute(@Param("matrixId") Long matrixId, Context context) throws Exception {
    DataMatrix matrix = dataMatrixService.findById(matrixId);
    Map condition = new HashMap();
    condition.put("searchKey", "jdbc:mysql://groupKey=" + matrix.getGroupKey());
    List<DataMediaSource> dataSources = dataMediaSourceService.listByCondition(condition);
    context.put("dataMatrix", matrix);
    context.put("dataSources", dataSources);
}
Also used : HashMap(java.util.HashMap) DataMediaSource(com.alibaba.otter.shared.common.model.config.data.DataMediaSource) DataMatrix(com.alibaba.otter.shared.common.model.config.data.DataMatrix) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with DataMediaSource

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

the class DataSourceInfo method execute.

public void execute(@Param("dataMediaSourceId") Long dataMediaSourceId, Context context) throws Exception {
    DataMediaSource dataMediaSource = dataMediaSourceService.findById(dataMediaSourceId);
    // 查询dataSource关联的同步任务
    List<DataMedia> dataMedias = dataMediaService.listByDataMediaSourceId(dataMediaSource.getId());
    context.put("source", dataMediaSource);
    context.put("dataMedias", dataMedias);
}
Also used : DataMediaSource(com.alibaba.otter.shared.common.model.config.data.DataMediaSource) DataMedia(com.alibaba.otter.shared.common.model.config.data.DataMedia)

Aggregations

DataMediaSource (com.alibaba.otter.shared.common.model.config.data.DataMediaSource)16 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)7 DataMedia (com.alibaba.otter.shared.common.model.config.data.DataMedia)7 DbMediaSource (com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource)5 ArrayList (java.util.ArrayList)5 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)4 MqMediaSource (com.alibaba.otter.shared.common.model.config.data.mq.MqMediaSource)4 HashMap (java.util.HashMap)4 Paginator (com.alibaba.citrus.util.Paginator)3 DataMatrix (com.alibaba.otter.shared.common.model.config.data.DataMatrix)2 ModeValue (com.alibaba.otter.shared.common.model.config.data.DataMedia.ModeValue)2 SQLException (java.sql.SQLException)2 Map (java.util.Map)2 DataSource (javax.sql.DataSource)2 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)2 WebxException (com.alibaba.citrus.webx.WebxException)1 DataMediaSourceDO (com.alibaba.otter.manager.biz.config.datamediasource.dal.dataobject.DataMediaSourceDO)1 SeniorDataMatrix (com.alibaba.otter.manager.web.common.model.SeniorDataMatrix)1 SeniorDataMediaSource (com.alibaba.otter.manager.web.common.model.SeniorDataMediaSource)1 ModeValueFilter (com.alibaba.otter.shared.common.model.config.ModeValueFilter)1