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());
}
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;
}
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;
}
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;
}
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;
}
Aggregations