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