Search in sources :

Example 1 with PostedDSProp

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);
}
Also used : IDataxContext(com.qlangtech.tis.datax.IDataxContext) Context(com.alibaba.citrus.turbine.Context) IPluginContext(com.qlangtech.tis.util.IPluginContext) DataSourceFactory(com.qlangtech.tis.plugin.ds.DataSourceFactory) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory) IPluginContext(com.qlangtech.tis.util.IPluginContext) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) DataSourceFactoryPluginStore(com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore) Descriptor(com.qlangtech.tis.extension.Descriptor) PluginExtraProps(com.qlangtech.tis.extension.util.PluginExtraProps) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory)

Example 2 with PostedDSProp

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);
}
Also used : DataSourceFactory(com.qlangtech.tis.plugin.ds.DataSourceFactory) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp)

Example 3 with PostedDSProp

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());
}
Also used : IDumpTable(com.qlangtech.tis.fullbuild.indexbuild.IDumpTable) StringUtils(org.apache.commons.lang.StringUtils) SqlTaskNode(com.qlangtech.tis.sql.parser.SqlTaskNode) TabExtraMeta(com.qlangtech.tis.sql.parser.meta.TabExtraMeta) DataSourceFactoryPluginStore(com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore) TIS(com.qlangtech.tis.TIS) JSONField(com.alibaba.fastjson.annotation.JSONField) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) TISTable(com.qlangtech.tis.plugin.ds.TISTable) Yaml(org.yaml.snakeyaml.Yaml) DumperOptions(org.yaml.snakeyaml.DumperOptions) Node(org.yaml.snakeyaml.nodes.Node) Lists(com.google.common.collect.Lists) CenterResource(com.qlangtech.tis.manage.common.CenterResource) Map(java.util.Map) PrimaryLinkKey(com.qlangtech.tis.sql.parser.meta.PrimaryLinkKey) TisUTF8(com.qlangtech.tis.manage.common.TisUTF8) DependencyNode(com.qlangtech.tis.sql.parser.meta.DependencyNode) EntityName(com.qlangtech.tis.sql.parser.tuple.creator.EntityName) Constructor(org.yaml.snakeyaml.constructor.Constructor) Property(org.yaml.snakeyaml.introspector.Property) FileUtils(org.apache.commons.io.FileUtils) Tag(org.yaml.snakeyaml.nodes.Tag) Collectors(java.util.stream.Collectors) File(java.io.File) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple) Objects(java.util.Objects) List(java.util.List) Representer(org.yaml.snakeyaml.representer.Representer) Optional(java.util.Optional) TypeDescription(org.yaml.snakeyaml.TypeDescription) SqlTaskNodeMeta(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) DependencyNode(com.qlangtech.tis.sql.parser.meta.DependencyNode) DataSourceFactoryPluginStore(com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore) TISTable(com.qlangtech.tis.plugin.ds.TISTable) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData)

Example 4 with PostedDSProp

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);
    }
}
Also used : PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) FacadeDataSource(com.qlangtech.tis.plugin.ds.FacadeDataSource) DataSourceFactoryPluginStore(com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore) Map(java.util.Map)

Example 5 with PostedDSProp

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);
    }
}
Also used : PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) DataSourceFactoryPluginStore(com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore) ExtensionRefreshException(com.qlangtech.tis.extension.impl.ExtensionRefreshException) IOException(java.io.IOException)

Aggregations

PostedDSProp (com.qlangtech.tis.plugin.ds.PostedDSProp)10 DataSourceFactoryPluginStore (com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore)6 DataSourceFactory (com.qlangtech.tis.plugin.ds.DataSourceFactory)4 TIS (com.qlangtech.tis.TIS)3 Descriptor (com.qlangtech.tis.extension.Descriptor)3 ParamsConfigPluginStore (com.qlangtech.tis.plugin.credentials.ParamsConfigPluginStore)3 Collectors (java.util.stream.Collectors)3 Context (com.alibaba.citrus.turbine.Context)2 Lists (com.google.common.collect.Lists)2 IPluginEnum (com.qlangtech.tis.IPluginEnum)2 DataxReader (com.qlangtech.tis.datax.impl.DataxReader)2 DataXJobWorker (com.qlangtech.tis.datax.job.DataXJobWorker)2 Describable (com.qlangtech.tis.extension.Describable)2 IAppSource (com.qlangtech.tis.manage.IAppSource)2 IPluginStore (com.qlangtech.tis.plugin.IPluginStore)2 TISTable (com.qlangtech.tis.plugin.ds.TISTable)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 StringUtils (org.apache.commons.lang.StringUtils)2