Search in sources :

Example 6 with DataMediaSource

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

the class DataBatchLoader method split.

/**
     * 将rowBatch中的记录,按找载入的目标数据源进行分类
     */
private List<RowBatch> split(RowBatch rowBatch) {
    final Identity identity = rowBatch.getIdentity();
    Map<DataMediaSource, RowBatch> result = new MapMaker().makeComputingMap(new Function<DataMediaSource, RowBatch>() {

        public RowBatch apply(DataMediaSource input) {
            RowBatch rowBatch = new RowBatch();
            rowBatch.setIdentity(identity);
            return rowBatch;
        }
    });
    for (EventData eventData : rowBatch.getDatas()) {
        // 获取介质信息
        DataMedia media = ConfigHelper.findDataMedia(configClientService.findPipeline(identity.getPipelineId()), eventData.getTableId());
        // 归类
        result.get(media.getSource()).merge(eventData);
    }
    return new ArrayList<RowBatch>(result.values());
}
Also used : RowBatch(com.alibaba.otter.shared.etl.model.RowBatch) MapMaker(com.google.common.collect.MapMaker) ArrayList(java.util.ArrayList) DataMediaSource(com.alibaba.otter.shared.common.model.config.data.DataMediaSource) Identity(com.alibaba.otter.shared.etl.model.Identity) EventData(com.alibaba.otter.shared.etl.model.EventData) DataMedia(com.alibaba.otter.shared.common.model.config.data.DataMedia)

Example 7 with DataMediaSource

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

the class DataMediaServiceImpl method doToModel.

/**
     * 用于DO对象转化为Model对象
     * 
     * @param dataMediaDo
     * @return DataMedia
     */
private DataMedia doToModel(DataMediaDO dataMediaDo) {
    DataMedia dataMedia = null;
    try {
        DataMediaSource dataMediaSource = dataMediaSourceService.findById(dataMediaDo.getDataMediaSourceId());
        if (dataMediaSource.getType().isMysql() || dataMediaSource.getType().isOracle()) {
            dataMedia = JsonUtils.unmarshalFromString(dataMediaDo.getProperties(), DbDataMedia.class);
            dataMedia.setSource(dataMediaSource);
        } else if (dataMediaSource.getType().isNapoli() || dataMediaSource.getType().isMq()) {
            dataMedia = JsonUtils.unmarshalFromString(dataMediaDo.getProperties(), MqDataMedia.class);
            dataMedia.setSource(dataMediaSource);
        }
        dataMedia.setId(dataMediaDo.getId());
        dataMedia.setGmtCreate(dataMediaDo.getGmtCreate());
        dataMedia.setGmtModified(dataMediaDo.getGmtModified());
    } catch (Exception e) {
        logger.error("ERROR ## change the dataMedia Do to Model has an exception");
        throw new ManagerException(e);
    }
    return dataMedia;
}
Also used : DataMediaSource(com.alibaba.otter.shared.common.model.config.data.DataMediaSource) DbDataMedia(com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) MqDataMedia(com.alibaba.otter.shared.common.model.config.data.mq.MqDataMedia) DataMedia(com.alibaba.otter.shared.common.model.config.data.DataMedia) DbDataMedia(com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

Example 8 with DataMediaSource

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

the class DataSourceChecker method checkMap.

public String checkMap(String namespace, String name, Long dataSourceId) {
    Connection conn = null;
    Statement stmt = null;
    DataMediaSource source = dataMediaSourceService.findById(dataSourceId);
    DataSource dataSource = null;
    try {
        DbMediaSource dbMediaSource = (DbMediaSource) source;
        dataSource = dataSourceCreator.createDataSource(dbMediaSource);
        // conn = dataSource.getConnection();
        // if (null == conn) {
        // return DATABASE_FAIL;
        // }
        ModeValue namespaceValue = ConfigHelper.parseMode(namespace);
        ModeValue nameValue = ConfigHelper.parseMode(name);
        String tempNamespace = namespaceValue.getSingleValue();
        String tempName = nameValue.getSingleValue();
        try {
            Table table = DdlUtils.findTable(new JdbcTemplate(dataSource), tempNamespace, tempNamespace, tempName);
            if (table == null) {
                return SELECT_FAIL;
            }
        } catch (SQLException se) {
            logger.error("check error!", se);
            return SELECT_FAIL;
        } catch (Exception e) {
            logger.error("check error!", e);
            return SELECT_FAIL;
        }
    // String selectSql = "SELECT * from " + tempNamespace + "." +
    // tempName + " where 1 = 0";
    // String insertSql = "INSERT INTO " + tempNamespace + "." +
    // tempName + " select * from ";
    // insertSql += "( SELECT * from " + tempNamespace + "." + tempName
    // + ") table2 where 1 = 0";
    // String deleteSql = "DELETE from " + tempNamespace + "." +
    // tempName + " where 1 = 0";
    //
    // stmt = conn.createStatement();
    //
    // try {
    // stmt.executeQuery(selectSql);
    // } catch (SQLException se) {
    // return SELECT_FAIL;
    // }
    //
    // try {
    // stmt.execute(insertSql);
    // } catch (SQLException se) {
    // return INSERT_FAIL;
    // }
    //
    // try {
    // stmt.execute(deleteSql);
    // } catch (SQLException se) {
    // return DELETE_FAIL;
    // }
    } finally {
        closeConnection(conn, stmt);
        dataSourceCreator.destroyDataSource(dataSource);
    }
    return TABLE_SUCCESS;
}
Also used : Table(org.apache.ddlutils.model.Table) ModeValue(com.alibaba.otter.shared.common.model.config.data.DataMedia.ModeValue) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) DataMediaSource(com.alibaba.otter.shared.common.model.config.data.DataMediaSource) DbMediaSource(com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) SQLException(java.sql.SQLException) DataSource(javax.sql.DataSource)

Example 9 with DataMediaSource

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

the class DataMediaSourceServiceImpl method doToModel.

/**
     * 类型:数据库类型 Mysql和Oracle 用于DO对象转化为Model对象
     * 
     * @param dataMediaSourceDo
     * @return DataMediaSource
     */
private DataMediaSource doToModel(DataMediaSourceDO dataMediaSourceDo) {
    DataMediaSource dataMediaSource = new DbMediaSource();
    try {
        if (dataMediaSourceDo.getType().isMysql() || dataMediaSourceDo.getType().isOracle()) {
            dataMediaSource = JsonUtils.unmarshalFromString(dataMediaSourceDo.getProperties(), DbMediaSource.class);
        } else if (dataMediaSourceDo.getType().isNapoli() || dataMediaSourceDo.getType().isMq()) {
            dataMediaSource = JsonUtils.unmarshalFromString(dataMediaSourceDo.getProperties(), MqMediaSource.class);
        }
        dataMediaSource.setId(dataMediaSourceDo.getId());
        dataMediaSource.setGmtCreate(dataMediaSourceDo.getGmtCreate());
        dataMediaSource.setGmtModified(dataMediaSourceDo.getGmtModified());
    } catch (Exception e) {
        logger.error("ERROR ## change the dataMediaSource Do to Model has an exception");
        throw new ManagerException(e);
    }
    return dataMediaSource;
}
Also used : DataMediaSource(com.alibaba.otter.shared.common.model.config.data.DataMediaSource) DbMediaSource(com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

Example 10 with DataMediaSource

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

the class DataMediaSourceServiceImpl method listByCondition.

@Override
public List<DataMediaSource> listByCondition(Map condition) {
    List<DataMediaSource> dataMediaSources = new ArrayList<DataMediaSource>();
    try {
        List<DataMediaSourceDO> dataMediaSourceDos = dataMediaSourceDao.listByCondition(condition);
        if (dataMediaSourceDos.isEmpty()) {
            logger.debug("DEBUG ## couldn't query any DataMediaSources by the condition:" + JsonUtils.marshalToString(condition));
            return dataMediaSources;
        }
        dataMediaSources = doToModel(dataMediaSourceDos);
    } catch (Exception e) {
        logger.error("ERROR ## query DataMediaSources by condition has an exception!");
        throw new ManagerException(e);
    }
    return dataMediaSources;
}
Also used : ArrayList(java.util.ArrayList) DataMediaSource(com.alibaba.otter.shared.common.model.config.data.DataMediaSource) DataMediaSourceDO(com.alibaba.otter.manager.biz.config.datamediasource.dal.dataobject.DataMediaSourceDO) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

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