Search in sources :

Example 21 with ISelectedTab

use of com.qlangtech.tis.plugin.ds.ISelectedTab in project plugins by qlangtech.

the class FlinkCDCPostgreSQLSourceFunction method start.

@Override
public JobExecutionResult start(TargetResName dataxName, IDataxReader dataSource, List<ISelectedTab> tabs, IDataxProcessor dataXProcessor) throws MQConsumeException {
    try {
        BasicDataXRdbmsReader rdbmsReader = (BasicDataXRdbmsReader) dataSource;
        final BasicDataSourceFactory dsFactory = (BasicDataSourceFactory) rdbmsReader.getDataSourceFactory();
        BasicDataSourceFactory.ISchemaSupported schemaSupported = (BasicDataSourceFactory.ISchemaSupported) dsFactory;
        if (StringUtils.isEmpty(schemaSupported.getDBSchema())) {
            throw new IllegalStateException("dsFactory:" + dsFactory.dbName + " relevant dbSchema can not be null");
        }
        SourceChannel sourceChannel = new SourceChannel(SourceChannel.getSourceFunction(dsFactory, (tab) -> schemaSupported.getDBSchema() + "." + tab.getTabName(), tabs, (dbHost, dbs, tbs, debeziumProperties) -> {
            DateTimeConverter.setDatetimeConverters(PGDateTimeConverter.class.getName(), debeziumProperties);
            return dbs.stream().map((dbname) -> {
                SourceFunction<DTO> sourceFunction = PostgreSQLSource.<DTO>builder().hostname(dbHost).port(dsFactory.port).database(// monitor postgres database
                dbname).schemaList(// monitor inventory schema
                schemaSupported.getDBSchema()).tableList(// monitor products table
                tbs.toArray(new String[tbs.size()])).username(dsFactory.userName).password(dsFactory.password).debeziumProperties(debeziumProperties).deserializer(// converts SourceRecord to JSON String
                new TISDeserializationSchema()).build();
                return new ReaderSource(dbHost + ":" + dsFactory.port + "_" + dbname, sourceFunction);
            }).collect(Collectors.toList());
        }));
        for (ISelectedTab tab : tabs) {
            sourceChannel.addFocusTab(tab.getName());
        }
        return (JobExecutionResult) getConsumerHandle().consume(dataxName, sourceChannel, dataXProcessor);
    } catch (Exception e) {
        throw new MQConsumeException(e.getMessage(), e);
    }
}
Also used : MQConsumeException(com.qlangtech.tis.async.message.client.consumer.MQConsumeException) DateTimeConverter(com.qlangtech.plugins.incr.flink.cdc.valconvert.DateTimeConverter) IConsumerHandle(com.qlangtech.tis.async.message.client.consumer.IConsumerHandle) StringUtils(org.apache.commons.lang.StringUtils) TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) BasicDataXRdbmsReader(com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) DTO(com.qlangtech.tis.realtime.transfer.DTO) TISDeserializationSchema(com.qlangtech.plugins.incr.flink.cdc.TISDeserializationSchema) Collectors(java.util.stream.Collectors) BasicDataSourceFactory(com.qlangtech.tis.plugin.ds.BasicDataSourceFactory) SourceChannel(com.qlangtech.plugins.incr.flink.cdc.SourceChannel) ReaderSource(com.qlangtech.tis.realtime.ReaderSource) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) List(java.util.List) SourceFunction(org.apache.flink.streaming.api.functions.source.SourceFunction) IDataxReader(com.qlangtech.tis.datax.IDataxReader) IAsyncMsgDeserialize(com.qlangtech.tis.async.message.client.consumer.IAsyncMsgDeserialize) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) IMQListener(com.qlangtech.tis.async.message.client.consumer.IMQListener) PostgreSQLSource(com.ververica.cdc.connectors.postgres.PostgreSQLSource) BasicDataSourceFactory(com.qlangtech.tis.plugin.ds.BasicDataSourceFactory) SourceChannel(com.qlangtech.plugins.incr.flink.cdc.SourceChannel) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) MQConsumeException(com.qlangtech.tis.async.message.client.consumer.MQConsumeException) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) TISDeserializationSchema(com.qlangtech.plugins.incr.flink.cdc.TISDeserializationSchema) MQConsumeException(com.qlangtech.tis.async.message.client.consumer.MQConsumeException) BasicDataXRdbmsReader(com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader) ReaderSource(com.qlangtech.tis.realtime.ReaderSource) DTO(com.qlangtech.tis.realtime.transfer.DTO)

Example 22 with ISelectedTab

use of com.qlangtech.tis.plugin.ds.ISelectedTab in project plugins by qlangtech.

the class TISFlinkCDCStart method deploy.

private static void deploy(TargetResName dataxName, BasicFlinkSourceHandle tableStreamHandle, ReplicasSpec incrSpec, long timestamp) throws Exception {
    // BasicFlinkSourceHandle tisFlinkSourceHandle = new TISFlinkSourceHandle();
    if (tableStreamHandle == null) {
        throw new IllegalStateException("tableStreamHandle has not been instantiated");
    }
    // ElasticSearchSinkFactory esSinkFactory = new ElasticSearchSinkFactory();
    // IPluginContext pluginContext = IPluginContext.namedContext(dataxName.getName());
    // List<TISSinkFactory> sinkFactories = TISSinkFactory.sinkFactory.getPlugins(pluginContext, null);
    // logger.info("sinkFactories size:" + sinkFactories.size());
    // for (TISSinkFactory factory : sinkFactories) {
    // sinkFactory = factory;
    // break;
    // }
    // Objects.requireNonNull(sinkFactory, "sinkFactories.size():" + sinkFactories.size());
    tableStreamHandle.setSinkFuncFactory(TISSinkFactory.getIncrSinKFactory(dataxName.getName()));
    // List<MQListenerFactory> mqFactories = HeteroEnum.MQ.getPlugins(pluginContext, null);
    MQListenerFactory mqFactory = HeteroEnum.getIncrSourceListenerFactory(dataxName.getName());
    mqFactory.setConsumerHandle(tableStreamHandle);
    // for (MQListenerFactory factory : mqFactories) {
    // factory.setConsumerHandle(tableStreamHandle);
    // mqFactory = factory;
    // }
    // Objects.requireNonNull(mqFactory, "mqFactory can not be null, mqFactories size:" + mqFactories.size());
    IMQListener mq = mqFactory.create();
    IDataxProcessor dataXProcess = DataxProcessor.load(null, dataxName.getName());
    DataxReader reader = (DataxReader) dataXProcess.getReader(null);
    if (reader == null) {
        throw new IllegalStateException("dataXReader is illegal");
    }
    // DBConfigGetter rdbmsReader = (DBConfigGetter) reader;
    List<ISelectedTab> tabs = reader.getSelectedTabs();
    mq.start(dataxName, reader, tabs, dataXProcess);
}
Also used : MQListenerFactory(com.qlangtech.tis.async.message.client.consumer.impl.MQListenerFactory) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) IMQListener(com.qlangtech.tis.async.message.client.consumer.IMQListener)

Example 23 with ISelectedTab

use of com.qlangtech.tis.plugin.ds.ISelectedTab in project plugins by qlangtech.

the class TestDataXDorisWriter method testDescriptorsJSONGenerate.

public void testDescriptorsJSONGenerate() {
    DataxReader dataxReader = EasyMock.createMock("dataxReader", DataxReader.class);
    List<ISelectedTab> selectedTabs = TestSelectedTabs.createSelectedTabs(1).stream().map((t) -> t).collect(Collectors.toList());
    for (ISelectedTab tab : selectedTabs) {
        for (ISelectedTab.ColMeta cm : tab.getCols()) {
            cm.setType(DataXReaderColType.STRING.dataType);
        }
    }
    // EasyMock.expect(dataxReader.getSelectedTabs()).andReturn(selectedTabs).anyTimes();
    DataxReader.dataxReaderThreadLocal.set(dataxReader);
    EasyMock.replay(dataxReader);
    DataXDorisWriter writer = new DataXDorisWriter();
    DescriptorsJSON descJson = new DescriptorsJSON(writer.getDescriptor());
    JsonUtil.assertJSONEqual(DataXDorisWriter.class, "doris-datax-writer-descriptor.json", descJson.getDescriptorsJSON(), (m, e, a) -> {
        assertEquals(m, e, a);
    });
    JsonUtil.assertJSONEqual(DataXDorisWriter.class, "doris-datax-writer-descriptor.json", descJson.getDescriptorsJSON(), (m, e, a) -> {
        assertEquals(m, e, a);
    });
    EasyMock.verify(dataxReader);
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) TestSelectedTabs(com.qlangtech.tis.plugin.datax.test.TestSelectedTabs) DescriptorsJSON(com.qlangtech.tis.util.DescriptorsJSON) JsonUtil(com.qlangtech.tis.trigger.util.JsonUtil) Lists(com.google.common.collect.Lists) CenterResource(com.qlangtech.tis.manage.common.CenterResource) DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) TisUTF8(com.qlangtech.tis.manage.common.TisUTF8) TestCase(junit.framework.TestCase) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) DorisSourceFactory(com.qlangtech.tis.plugin.ds.doris.DorisSourceFactory) PluginExtraProps(com.qlangtech.tis.extension.util.PluginExtraProps) DataxWriter(com.qlangtech.tis.datax.impl.DataxWriter) FileUtils(org.apache.commons.io.FileUtils) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) File(java.io.File) Consumer(java.util.function.Consumer) DataXReaderColType(com.qlangtech.tis.plugin.ds.DataXReaderColType) List(java.util.List) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) IOUtils(com.qlangtech.tis.extension.impl.IOUtils) TestDorisSourceFactory(com.qlangtech.tis.plugin.ds.doris.TestDorisSourceFactory) Optional(java.util.Optional) JSONObject(com.alibaba.fastjson.JSONObject) WriterTemplate(com.qlangtech.tis.plugin.common.WriterTemplate) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) DescriptorsJSON(com.qlangtech.tis.util.DescriptorsJSON) DataxReader(com.qlangtech.tis.datax.impl.DataxReader)

Example 24 with ISelectedTab

use of com.qlangtech.tis.plugin.ds.ISelectedTab in project plugins by qlangtech.

the class TestDataXStarRocksWriter method testDescriptorsJSONGenerate.

public void testDescriptorsJSONGenerate() {
    DataxReader dataxReader = EasyMock.createMock("dataxReader", DataxReader.class);
    List<ISelectedTab> selectedTabs = TestSelectedTabs.createSelectedTabs(1).stream().map((t) -> t).collect(Collectors.toList());
    for (ISelectedTab tab : selectedTabs) {
        for (ISelectedTab.ColMeta cm : tab.getCols()) {
            cm.setType(DataXReaderColType.STRING.dataType);
        }
    }
    // EasyMock.expect(dataxReader.getSelectedTabs()).andReturn(selectedTabs).anyTimes();
    DataxReader.dataxReaderThreadLocal.set(dataxReader);
    EasyMock.replay(dataxReader);
    DataXStarRocksWriter writer = new DataXStarRocksWriter();
    DescriptorsJSON descJson = new DescriptorsJSON(writer.getDescriptor());
    JsonUtil.assertJSONEqual(DataXStarRocksWriter.class, "starrocks-datax-writer-descriptor.json", descJson.getDescriptorsJSON(), (m, e, a) -> {
        assertEquals(m, e, a);
    });
    JsonUtil.assertJSONEqual(DataXStarRocksWriter.class, "starrocks-datax-writer-descriptor.json", descJson.getDescriptorsJSON(), (m, e, a) -> {
        assertEquals(m, e, a);
    });
    EasyMock.verify(dataxReader);
}
Also used : DataXDorisWriter(com.qlangtech.tis.plugin.datax.doris.DataXDorisWriter) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) TestSelectedTabs(com.qlangtech.tis.plugin.datax.test.TestSelectedTabs) DescriptorsJSON(com.qlangtech.tis.util.DescriptorsJSON) JsonUtil(com.qlangtech.tis.trigger.util.JsonUtil) Lists(com.google.common.collect.Lists) CenterResource(com.qlangtech.tis.manage.common.CenterResource) DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) TisUTF8(com.qlangtech.tis.manage.common.TisUTF8) TestCase(junit.framework.TestCase) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) DorisSourceFactory(com.qlangtech.tis.plugin.ds.doris.DorisSourceFactory) PluginExtraProps(com.qlangtech.tis.extension.util.PluginExtraProps) DataxWriter(com.qlangtech.tis.datax.impl.DataxWriter) FileUtils(org.apache.commons.io.FileUtils) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) File(java.io.File) DataXReaderColType(com.qlangtech.tis.plugin.ds.DataXReaderColType) List(java.util.List) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) TestDorisSourceFactory(com.qlangtech.tis.plugin.ds.doris.TestDorisSourceFactory) Optional(java.util.Optional) JSONObject(com.alibaba.fastjson.JSONObject) WriterTemplate(com.qlangtech.tis.plugin.common.WriterTemplate) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) DescriptorsJSON(com.qlangtech.tis.util.DescriptorsJSON) DataxReader(com.qlangtech.tis.datax.impl.DataxReader)

Example 25 with ISelectedTab

use of com.qlangtech.tis.plugin.ds.ISelectedTab in project plugins by qlangtech.

the class DataXElasticsearchWriter method initSchemaMetaContent.

@Override
public SchemaMetaContent initSchemaMetaContent(ISelectedTab tab) {
    SchemaMetaContent metaContent = new SchemaMetaContent();
    ESSchema schema = new ESSchema();
    metaContent.parseResult = schema;
    ESField field = null;
    for (ISelectedTab.ColMeta m : tab.getCols()) {
        field = new ESField();
        field.setName(m.getName());
        field.setStored(true);
        field.setIndexed(true);
        field.setType(this.mapSearchEngineType(m.getType().getCollapse()));
        // field.setSharedKey();
        // field.setUniqueKey();
        schema.fields.add(field);
    }
    byte[] schemaContent = null;
    metaContent.content = schemaContent;
    return metaContent;
}
Also used : SchemaMetaContent(com.qlangtech.tis.solrdao.SchemaMetaContent) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab)

Aggregations

ISelectedTab (com.qlangtech.tis.plugin.ds.ISelectedTab)31 IDataxProcessor (com.qlangtech.tis.datax.IDataxProcessor)14 Collectors (java.util.stream.Collectors)13 IDataxReader (com.qlangtech.tis.datax.IDataxReader)10 DTO (com.qlangtech.tis.realtime.transfer.DTO)10 List (java.util.List)8 StringUtils (org.apache.commons.lang.StringUtils)8 DataxReader (com.qlangtech.tis.datax.impl.DataxReader)7 Lists (com.google.common.collect.Lists)6 JSONObject (com.alibaba.fastjson.JSONObject)5 MQConsumeException (com.qlangtech.tis.async.message.client.consumer.MQConsumeException)5 ReaderSource (com.qlangtech.tis.realtime.ReaderSource)5 java.util (java.util)5 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)5 SinkFunction (org.apache.flink.streaming.api.functions.sink.SinkFunction)5 Maps (com.google.common.collect.Maps)4 SourceChannel (com.qlangtech.plugins.incr.flink.cdc.SourceChannel)4 TISDeserializationSchema (com.qlangtech.plugins.incr.flink.cdc.TISDeserializationSchema)4 IMQListener (com.qlangtech.tis.async.message.client.consumer.IMQListener)4 TargetResName (com.qlangtech.tis.coredefine.module.action.TargetResName)4