use of com.qlangtech.tis.plugin.ds.PostedDSProp in project plugins by qlangtech.
the class TestDataxMySQLWriter method testTempateGenerate.
public void testTempateGenerate() throws Exception {
Optional<PluginExtraProps> extraProps = PluginExtraProps.load(DataxMySQLWriter.class);
assertTrue("DataxMySQLWriter extraProps shall exist", extraProps.isPresent());
IPluginContext pluginContext = EasyMock.createMock("pluginContext", IPluginContext.class);
Context context = EasyMock.createMock("context", Context.class);
EasyMock.expect(context.hasErrors()).andReturn(false);
MySQLDataSourceFactory mysqlDs = new MySQLDataSourceFactory() {
@Override
public Connection getConnection(String jdbcUrl) throws SQLException {
return null;
}
};
mysqlDs.dbName = dbWriterName;
mysqlDs.port = 3306;
mysqlDs.encode = "utf8";
mysqlDs.userName = "root";
mysqlDs.password = "123456";
mysqlDs.nodeDesc = "192.168.28.200";
Descriptor.ParseDescribable<DataSourceFactory> desc = new Descriptor.ParseDescribable<>(mysqlDs);
pluginContext.addDb(desc, dbWriterName, context, true);
EasyMock.replay(pluginContext, context);
DataSourceFactoryPluginStore dbStore = TIS.getDataBasePluginStore(new PostedDSProp(dbWriterName));
assertTrue("save mysql db Config faild", dbStore.setPlugins(pluginContext, Optional.of(context), Collections.singletonList(desc)));
DataxMySQLWriter mySQLWriter = new DataxMySQLWriter();
mySQLWriter.dataXName = dataXName;
mySQLWriter.writeMode = "replace";
mySQLWriter.dbName = dbWriterName;
mySQLWriter.template = DataxMySQLWriter.getDftTemplate();
mySQLWriter.batchSize = 1001;
mySQLWriter.preSql = "delete from test";
mySQLWriter.postSql = "delete from test1";
mySQLWriter.session = "set session sql_mode='ANSI'";
validateConfigGenerate("mysql-datax-writer-assert.json", mySQLWriter);
// System.out.println(mySQLWriter.getTemplate());
// 将非必须输入的值去掉再测试一遍
mySQLWriter.batchSize = null;
mySQLWriter.preSql = null;
mySQLWriter.postSql = null;
mySQLWriter.session = null;
validateConfigGenerate("mysql-datax-writer-assert-without-option-val.json", mySQLWriter);
mySQLWriter.preSql = " ";
mySQLWriter.postSql = " ";
mySQLWriter.session = " ";
validateConfigGenerate("mysql-datax-writer-assert-without-option-val.json", mySQLWriter);
}
use of com.qlangtech.tis.plugin.ds.PostedDSProp in project plugins by qlangtech.
the class LocalTableDumpFactory method getDataSourceFactory.
private DataSourceFactory getDataSourceFactory(IDumpTable table) {
if (dataSourceFactoryGetter == null) {
dataSourceFactoryGetter = (tab) -> {
IPluginStore<DataSourceFactory> dbPlugin = TIS.getDataBasePluginStore(new PostedDSProp(tab.getDbName(), DbScope.DETAILED));
Objects.requireNonNull(dbPlugin, "dbPlugin can not be null");
DataSourceFactory dsFactory = dbPlugin.getPlugin();
if (dsFactory == null) {
throw new IllegalStateException("table:" + table + " can not find relevant ds config,config file:" + dbPlugin.getTargetFile());
}
return dsFactory;
};
}
return dataSourceFactoryGetter.get(table);
}
use of com.qlangtech.tis.plugin.ds.PostedDSProp in project tis by qlangtech.
the class ERRules method createDefaultErRule.
/**
* 使用默认DumpNode创建ERRule并且持久化
*
* @param topology
* @throws Exception
*/
public static void createDefaultErRule(SqlTaskNodeMeta.SqlDataFlowTopology topology) throws Exception {
// 还没有定义erRule
DependencyNode dumpNode = topology.getFirstDumpNode();
DataSourceFactoryPluginStore dsStore = TIS.getDataBasePluginStore(new PostedDSProp(dumpNode.getDbName()));
TISTable tab = dsStore.loadTableMeta(dumpNode.getName());
// String topologyName, DependencyNode node, TargetColumnMeta targetColMetas
Optional<ColumnMetaData> firstPK = tab.getReflectCols().stream().filter((col) -> col.isPk()).findFirst();
if (!firstPK.isPresent()) {
throw new IllegalStateException("table:" + dumpNode.parseEntityName() + " can not find relevant PK cols");
}
createErRule(topology.getName(), dumpNode, firstPK.get());
}
use of com.qlangtech.tis.plugin.ds.PostedDSProp in project tis by qlangtech.
the class DBNode method registerDependencyDbsFacadeConfig.
/**
* @param collection
* @param timestamp
* @return
* @throws Exception
*/
public static void registerDependencyDbsFacadeConfig(String collection, long timestamp, DefaultListableBeanFactory factory) {
try {
Map<String, DataSourceFactoryPluginStore> dbConfigsMap = null;
try (InputStream input = FileUtils.openInputStream(StreamContextConstant.getDbDependencyConfigMetaFile(collection, timestamp))) {
// 这样可以去重
dbConfigsMap = DBNode.load(input).stream().collect(Collectors.toMap((db) -> db.getDbName(), (db) -> TIS.getDataBasePluginStore(new PostedDSProp(db.getDbName(), DbScope.FACADE))));
FacadeDataSource ds = null;
for (Map.Entry<String, DataSourceFactoryPluginStore> entry : dbConfigsMap.entrySet()) {
ds = entry.getValue().createFacadeDataSource();
factory.registerSingleton(entry.getKey() + "Datasource", ds.dataSource);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.qlangtech.tis.plugin.ds.PostedDSProp in project tis by qlangtech.
the class TIS method deleteDB.
public static void deleteDB(String dbName, DbScope dbScope) {
try {
DataSourceFactoryPluginStore dsPluginStore = getDataBasePluginStore(new PostedDSProp(dbName, dbScope));
dsPluginStore.deleteDB();
databasePluginStore.clear(dsPluginStore.getDSKey());
} catch (Exception e) {
throw new RuntimeException(dbName, e);
}
}
Aggregations