Search in sources :

Example 1 with IPluginContext

use of com.qlangtech.tis.util.IPluginContext in project plugins by qlangtech.

the class TestDataxMySQLReader method testGetSubTasks.

public void testGetSubTasks() {
    MySQLDataSourceFactory mysqlDs = new MySQLDataSourceFactory() {

        // @Override
        // protected Connection getConnection(String jdbcUrl, String username, String password) throws SQLException {
        // throw new UnsupportedOperationException();
        // }
        @Override
        public List<ColumnMetaData> getTableMetadata(String table) {
            switch(table) {
                case TestSelectedTabs.tabNameOrderDetail:
                    return TestSelectedTabs.tabColsMetaOrderDetail;
                case TestSelectedTabs.tabNameTotalpayinfo:
                    return TestSelectedTabs.tabColsMetaTotalpayinfo;
                default:
                    throw new IllegalArgumentException("table:" + table);
            }
        }
    };
    mysqlDs.dbName = dbName;
    mysqlDs.port = 3306;
    mysqlDs.encode = "utf8";
    mysqlDs.userName = userName;
    mysqlDs.password = password;
    mysqlDs.nodeDesc = "192.168.28.200[0-7]";
    Descriptor.ParseDescribable<DataSourceFactory> desc = new Descriptor.ParseDescribable<>(mysqlDs);
    Context context = EasyMock.createMock("context", Context.class);
    EasyMock.expect(context.hasErrors()).andReturn(false);
    IPluginContext pluginContext = EasyMock.createMock("pluginContext", IPluginContext.class);
    pluginContext.addDb(desc, dbName, context, true);
    EasyMock.replay(pluginContext, context);
    DataSourceFactoryPluginStore dbStore = TIS.getDataBasePluginStore(new PostedDSProp(dbName));
    assertTrue("save mysql db Config faild", dbStore.setPlugins(pluginContext, Optional.of(context), Collections.singletonList(desc)));
    DataxMySQLReader mySQLReader = new DataxMySQLReader() {

        @Override
        public MySQLDataSourceFactory getDataSourceFactory() {
            return mysqlDs;
        }
    };
    mySQLReader.dataXName = this.dataXName;
    List<SelectedTab> selectedTabs = TestSelectedTabs.createSelectedTabs();
    mySQLReader.setSelectedTabs(selectedTabs);
    List<SelectedTab> selectedTabs2 = mySQLReader.getSelectedTabs();
    assertEquals(2, selectedTabs2.size());
    for (SelectedTab tab : selectedTabs2) {
        tab.getCols().forEach((c) -> {
            assertNotNull("table:" + tab.getName() + "'s col " + c.getName() + " relevant type can not be null", c.getType());
        });
    }
    List<String> tabs = Lists.newArrayList();
    for (SelectedTab tab : selectedTabs) {
        for (int i = 0; i < 8; i++) {
            tabs.add(tab.name);
        }
    }
    int readerContextCount = 0;
    IDataxReaderContext readerContext = null;
    IGroupChildTaskIterator subTasks = mySQLReader.getSubTasks();
    while (subTasks.hasNext()) {
        readerContext = subTasks.next();
        assertEquals(tabs.get(readerContextCount), readerContext.getSourceEntityName());
        assertEquals(tabs.get(readerContextCount) + "_" + readerContextCount, readerContext.getTaskName());
        System.out.println(readerContext.getSourceEntityName() + " " + readerContext.getTaskName());
        assertNotNull(readerContext);
        readerContextCount++;
    }
    assertEquals(16, readerContextCount);
    Map<String, List<String>> groupedInfo = subTasks.getGroupedInfo();
    assertNotNull("groupedInfo can not be null", groupedInfo);
    List<String> subTabs = groupedInfo.get(TestSelectedTabs.tabNameOrderDetail);
    assertEquals(8, subTabs.size());
    subTabs = groupedInfo.get(TestSelectedTabs.tabNameTotalpayinfo);
    assertEquals(8, subTabs.size());
    EasyMock.verify(pluginContext, context);
}
Also used : Context(com.alibaba.citrus.turbine.Context) IDataxReaderContext(com.qlangtech.tis.datax.IDataxReaderContext) IPluginContext(com.qlangtech.tis.util.IPluginContext) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory) IPluginContext(com.qlangtech.tis.util.IPluginContext) IDataxReaderContext(com.qlangtech.tis.datax.IDataxReaderContext) IGroupChildTaskIterator(com.qlangtech.tis.datax.IGroupChildTaskIterator) Descriptor(com.qlangtech.tis.extension.Descriptor) List(java.util.List) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory)

Example 2 with IPluginContext

use of com.qlangtech.tis.util.IPluginContext 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 3 with IPluginContext

use of com.qlangtech.tis.util.IPluginContext in project tis by qlangtech.

the class DataxReader method createDataXReaderKey.

private static TIS.DataXReaderAppKey createDataXReaderKey(IPluginContext pluginContext, boolean db, String appname) {
    return new TIS.DataXReaderAppKey(pluginContext, db, appname, new PluginStore.IPluginProcessCallback<DataxReader>() {

        @Override
        public void afterDeserialize(final DataxReader reader) {
            List<PluginFormProperties> subFieldFormPropertyTypes = reader.getDescriptor().getSubPluginFormPropertyTypes();
            if (subFieldFormPropertyTypes.size() > 0) {
                // 加载子字段
                subFieldFormPropertyTypes.forEach((pt) -> {
                    pt.accept(new PluginFormProperties.IVisitor() {

                        @Override
                        public Void visit(final SuFormProperties props) {
                            SubFieldFormAppKey<DataxReader> subFieldKey = new SubFieldFormAppKey<>(pluginContext, db, appname, props, DataxReader.class);
                            KeyedPluginStore<DataxReader> subFieldStore = KeyedPluginStore.getPluginStore(subFieldKey);
                            // 子表单中的内容更新了之后,要同步父表单中的状态
                            subFieldStore.addPluginsUpdateListener(new PluginStore.PluginsUpdateListener<DataxReader>(subFieldKey.getSerializeFileName(), reader) {

                                @Override
                                public void accept(PluginStore<DataxReader> pluginStore) {
                                    setReaderSubFormProp(props, pluginStore.getPlugin());
                                }
                            });
                            DataxReader subFieldReader = subFieldStore.getPlugin();
                            if (subFieldReader == null) {
                                return null;
                            }
                            setReaderSubFormProp(props, subFieldReader);
                            return null;
                        }

                        private void setReaderSubFormProp(SuFormProperties props, DataxReader subFieldReader) {
                            setReaderSubFormProp(props, reader, subFieldReader);
                        }

                        private void setReaderSubFormProp(SuFormProperties props, DataxReader reader, DataxReader subFieldReader) {
                            if (reader == null) {
                                return;
                            }
                            try {
                                props.subFormField.set(reader, props.subFormField.get(subFieldReader));
                            } catch (IllegalAccessException e) {
                                throw new RuntimeException("get subField:" + props.getSubFormFieldName(), e);
                            }
                        }
                    });
                });
            }
        }
    });
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) PluginStore(com.qlangtech.tis.plugin.PluginStore) TIS(com.qlangtech.tis.TIS) Descriptor(com.qlangtech.tis.extension.Descriptor) IPluginContext(com.qlangtech.tis.util.IPluginContext) Lists(com.google.common.collect.Lists) Public(com.qlangtech.tis.annotation.Public) IDataXPluginMeta(com.qlangtech.tis.datax.IDataXPluginMeta) IDataxReader(com.qlangtech.tis.datax.IDataxReader) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) KeyedPluginStore(com.qlangtech.tis.plugin.KeyedPluginStore) IPluginStore(com.qlangtech.tis.plugin.IPluginStore) Describable(com.qlangtech.tis.extension.Describable) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) IDataxReader(com.qlangtech.tis.datax.IDataxReader) PluginStore(com.qlangtech.tis.plugin.PluginStore) KeyedPluginStore(com.qlangtech.tis.plugin.KeyedPluginStore) IPluginStore(com.qlangtech.tis.plugin.IPluginStore) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties)

Example 4 with IPluginContext

use of com.qlangtech.tis.util.IPluginContext in project tis by qlangtech.

the class DataSourceFactoryPluginStore method setPlugins.

@Override
public synchronized boolean setPlugins(IPluginContext pluginContext, Optional<Context> context, List<Descriptor.ParseDescribable<DataSourceFactory>> dlist, boolean update) {
    if (dlist.size() != 1) {
        throw new IllegalArgumentException("size of dlist must equal to 1");
    }
    if (!context.isPresent()) {
        throw new IllegalArgumentException("Context shall exist");
    }
    Context ctx = context.get();
    final String dbName = this.key.keyVal.getVal();
    if (!super.setPlugins(pluginContext, context, dlist, update)) {
        return false;
    }
    Descriptor.ParseDescribable<DataSourceFactory> dbDesc = dlist.get(0);
    pluginContext.addDb(dbDesc, dbName, ctx, (shallUpdateDB && !update));
    return !ctx.hasErrors();
}
Also used : IPluginContext(com.qlangtech.tis.util.IPluginContext) Context(com.alibaba.citrus.turbine.Context) Descriptor(com.qlangtech.tis.extension.Descriptor)

Example 5 with IPluginContext

use of com.qlangtech.tis.util.IPluginContext in project tis by qlangtech.

the class TISSinkFactory method getIncrSinKFactory.

public static TISSinkFactory getIncrSinKFactory(String dataXName) {
    IPluginContext pluginContext = IPluginContext.namedContext(dataXName);
    List<TISSinkFactory> sinkFactories = sinkFactory.getPlugins(pluginContext, null);
    TISSinkFactory sinkFactory = null;
    logger.info("sinkFactories size:" + sinkFactories.size());
    for (TISSinkFactory factory : sinkFactories) {
        sinkFactory = factory;
        break;
    }
    Objects.requireNonNull(sinkFactory, "sinkFactories.size():" + sinkFactories.size());
    return sinkFactory;
}
Also used : IPluginContext(com.qlangtech.tis.util.IPluginContext)

Aggregations

IPluginContext (com.qlangtech.tis.util.IPluginContext)8 Context (com.alibaba.citrus.turbine.Context)4 Descriptor (com.qlangtech.tis.extension.Descriptor)4 Lists (com.google.common.collect.Lists)2 TIS (com.qlangtech.tis.TIS)2 PluginExtraProps (com.qlangtech.tis.extension.util.PluginExtraProps)2 ISelectedTab (com.qlangtech.tis.plugin.ds.ISelectedTab)2 MySQLDataSourceFactory (com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory)2 java.util (java.util)2 StringUtils (org.apache.commons.lang.StringUtils)2 JSON (com.alibaba.fastjson.JSON)1 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps (com.google.common.collect.Maps)1 Public (com.qlangtech.tis.annotation.Public)1 IDataXPluginMeta (com.qlangtech.tis.datax.IDataXPluginMeta)1 IDataxContext (com.qlangtech.tis.datax.IDataxContext)1 IDataxProcessor (com.qlangtech.tis.datax.IDataxProcessor)1 IDataxReader (com.qlangtech.tis.datax.IDataxReader)1