Search in sources :

Example 16 with ISelectedTab

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

the class TestFlinkCDCMongoDBSourceFunction method testStart.

public void testStart() throws Exception {
    FlinkCDCMongoDBSourceFactory mongoDBSourceFactory = this.mock("mongoDBSourceFactory", FlinkCDCMongoDBSourceFactory.class);
    FlinkCDCMongoDBSourceFunction mongoDBSourceFunction = new FlinkCDCMongoDBSourceFunction(mongoDBSourceFactory);
    DataXMongodbReader mongodbReader = new DataXMongodbReader();
    List<ISelectedTab> tabs = Lists.newArrayList();
    IDataxProcessor dataXProcessor = this.mock("dataxProcess", IDataxProcessor.class);
    this.replay();
    TargetResName dataXName = new TargetResName("test");
    mongoDBSourceFunction.start(dataXName, mongodbReader, tabs, dataXProcessor);
    this.verifyAll();
}
Also used : TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) DataXMongodbReader(com.qlangtech.tis.plugin.datax.DataXMongodbReader) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor)

Example 17 with ISelectedTab

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

the class ElasticSearchSinkFactory method createSinkFunction.

@Override
public Map<IDataxProcessor.TableAlias, SinkFunction<DTO>> createSinkFunction(IDataxProcessor dataxProcessor) {
    DataXElasticsearchWriter dataXWriter = (DataXElasticsearchWriter) dataxProcessor.getWriter(null);
    Objects.requireNonNull(dataXWriter, "dataXWriter can not be null");
    IHttpToken token = dataXWriter.getToken();
    ESTableAlias esSchema = null;
    for (Map.Entry<String, IDataxProcessor.TableAlias> e : dataxProcessor.getTabAlias().entrySet()) {
        IDataxProcessor.TableAlias value = e.getValue();
        if (!(value instanceof ESTableAlias)) {
            throw new IllegalStateException("value must be type of 'ESTableAlias',but now is :" + value.getClass());
        }
        esSchema = (ESTableAlias) value;
        break;
    }
    Objects.requireNonNull(esSchema, "esSchema can not be null");
    List<ISelectedTab.ColMeta> cols = esSchema.getSourceCols();
    if (CollectionUtils.isEmpty(cols)) {
        throw new IllegalStateException("cols can not be null");
    }
    Optional<ISelectedTab.ColMeta> firstPK = cols.stream().filter((c) -> c.isPk()).findFirst();
    if (!firstPK.isPresent()) {
        throw new IllegalStateException("has not set PK col");
    }
    /**
     ******************************************************
     * 初始化索引Schema
     ******************************************************
     */
    dataXWriter.initialIndex(esSchema);
    // JSONArray schemaCols = esSchema.getSchemaCols();
    // ESClient esClient = new ESClient();
    // esClient.createClient(token.getEndpoint(),
    // token.getAccessKeyId(),
    // token.getAccessKeySecret(),
    // false,
    // 300000,
    // false,
    // false);
    // try {
    // esClient.createIndex(dataXWriter.getIndexName()
    // , dataXWriter.type
    // , esClient.genMappings(schemaCols, dataXWriter.type, (columnList) -> {
    // }), dataXWriter.settings, false);
    // } catch (Exception e) {
    // throw new RuntimeException(e);
    // } finally {
    // try {
    // esClient.closeJestClient();
    // } catch (Throwable e) {
    // 
    // }
    // }
    // if (!) {
    // throw new IllegalStateException("create index or mapping failed indexName:" + dataXWriter.getIndexName());
    // }
    // Map<String, String> config = new HashMap<>();
    // config.put("cluster.name", "my-cluster-name");
    // // This instructs the sink to emit after every element, otherwise they would be buffered
    // config.put("bulk.flush.max.actions", "1");
    List<HttpHost> transportAddresses = new ArrayList<>();
    transportAddresses.add(HttpHost.create(token.getEndpoint()));
    ElasticsearchSink.Builder<DTO> sinkBuilder = new ElasticsearchSink.Builder<>(transportAddresses, new DefaultElasticsearchSinkFunction(cols.stream().map((c) -> c.getName()).collect(Collectors.toSet()), firstPK.get().getName(), dataXWriter.getIndexName()));
    if (this.bulkFlushMaxActions != null) {
        sinkBuilder.setBulkFlushMaxActions(this.bulkFlushMaxActions);
    }
    if (this.bulkFlushMaxSizeMb != null) {
        sinkBuilder.setBulkFlushMaxSizeMb(bulkFlushMaxSizeMb);
    }
    if (this.bulkFlushIntervalMs != null) {
        sinkBuilder.setBulkFlushInterval(this.bulkFlushIntervalMs);
    }
    // new RestClientBuilder.HttpClientConfigCallback() {
    // @Override
    // public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
    // return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
    // }
    // }
    sinkBuilder.setFailureHandler(new DefaultActionRequestFailureHandler());
    if (StringUtils.isNotEmpty(token.getAccessKeyId()) || StringUtils.isNotEmpty(token.getAccessKeySecret())) {
        // 如果用户设置了accessKey 或者accessSecret
        sinkBuilder.setRestClientFactory(new TISElasticRestClientFactory(token.getAccessKeyId(), token.getAccessKeySecret()));
    // sinkBuilder.setRestClientFactory(new RestClientFactory() {
    // @Override
    // public void configureRestClientBuilder(RestClientBuilder restClientBuilder) {
    // final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    // credentialsProvider.setCredentials(AuthScope.ANY,
    // new UsernamePasswordCredentials(token.getAccessKeyId(), token.getAccessKeySecret()));
    // restClientBuilder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
    // @Override
    // public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) {
    // return httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
    // }
    // });
    // }
    // });
    }
    IDataxProcessor.TableAlias tableMapper = new IDataxProcessor.TableAlias();
    tableMapper.setTo(dataXWriter.getIndexName());
    IDataxReader reader = dataxProcessor.getReader(null);
    for (ISelectedTab selectedTab : reader.getSelectedTabs()) {
        tableMapper.setFrom(selectedTab.getName());
    }
    return Collections.singletonMap(tableMapper, sinkBuilder.build());
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) ActionRequestFailureHandler(org.apache.flink.streaming.connectors.elasticsearch.ActionRequestFailureHandler) java.util(java.util) RuntimeContext(org.apache.flink.api.common.functions.RuntimeContext) RequestIndexer(org.apache.flink.streaming.connectors.elasticsearch.RequestIndexer) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) LoggerFactory(org.slf4j.LoggerFactory) FormField(com.qlangtech.tis.plugin.annotation.FormField) DTO(com.qlangtech.tis.realtime.transfer.DTO) ElasticsearchSinkFunction(org.apache.flink.streaming.connectors.elasticsearch.ElasticsearchSinkFunction) IndexRequest(org.elasticsearch.action.index.IndexRequest) CollectionUtils(org.apache.commons.collections.CollectionUtils) IDataXPluginMeta(com.qlangtech.tis.datax.IDataXPluginMeta) IDataxReader(com.qlangtech.tis.datax.IDataxReader) ESTableAlias(com.qlangtech.tis.datax.impl.ESTableAlias) Public(org.apache.flink.annotation.Public) Requests(org.elasticsearch.client.Requests) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) Validator(com.qlangtech.tis.plugin.annotation.Validator) TISSinkFactory(com.qlangtech.tis.plugin.incr.TISSinkFactory) TISExtension(com.qlangtech.tis.extension.TISExtension) ActionRequest(org.elasticsearch.action.ActionRequest) ElasticsearchSink(org.apache.flink.streaming.connectors.elasticsearch7.ElasticsearchSink) Logger(org.slf4j.Logger) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) IHttpToken(com.qlangtech.tis.config.aliyun.IHttpToken) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) DataXElasticsearchWriter(com.qlangtech.tis.plugin.datax.DataXElasticsearchWriter) HttpHost(com.qlangtech.org.apache.http.HttpHost) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) DataXElasticsearchWriter(com.qlangtech.tis.plugin.datax.DataXElasticsearchWriter) IDataxReader(com.qlangtech.tis.datax.IDataxReader) HttpHost(com.qlangtech.org.apache.http.HttpHost) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) ESTableAlias(com.qlangtech.tis.datax.impl.ESTableAlias) IHttpToken(com.qlangtech.tis.config.aliyun.IHttpToken) ESTableAlias(com.qlangtech.tis.datax.impl.ESTableAlias) ElasticsearchSink(org.apache.flink.streaming.connectors.elasticsearch7.ElasticsearchSink) DTO(com.qlangtech.tis.realtime.transfer.DTO)

Example 18 with ISelectedTab

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

the class SourceChannel method getSourceFunction.

// https://ververica.github.io/flink-cdc-connectors/master/
public static List<ReaderSource> getSourceFunction(BasicDataSourceFactory dsFactory, Function<DBTable, String> tabnameCreator, List<ISelectedTab> tabs, ReaderSourceCreator sourceFunctionCreator) {
    try {
        DBConfig dbConfig = dsFactory.getDbConfig();
        List<ReaderSource> sourceFuncs = Lists.newArrayList();
        Map<String, List<String>> ip2dbs = Maps.newHashMap();
        Map<String, List<ISelectedTab>> db2tabs = Maps.newHashMap();
        dbConfig.vistDbName((config, ip, dbName) -> {
            List<String> dbs = ip2dbs.get(ip);
            if (dbs == null) {
                dbs = Lists.newArrayList();
                ip2dbs.put(ip, dbs);
            }
            dbs.add(dbName);
            if (db2tabs.get(dbName) == null) {
                db2tabs.put(dbName, tabs);
            }
            return false;
        });
        for (Map.Entry<String, List<String>> /**
         *dbs
         */
        entry : ip2dbs.entrySet()) {
            // Set<String> tbs = entry.getValue().stream().flatMap(
            // (dbName) -> db2tabs.get(dbName).stream().map((tab) -> dbName + "." + tab.getName())).collect(Collectors.toSet());
            Set<String> tbs = entry.getValue().stream().flatMap((dbName) -> db2tabs.get(dbName).stream().map((tab) -> {
                // return (dsSchemaSupport ? ((BasicDataSourceFactory.ISchemaSupported) dsFactory).getDBSchema() : dbName) + "." + tab.getName();
                return tabnameCreator.apply(new DBTable(dbName, tab));
            })).collect(Collectors.toSet());
            Properties debeziumProperties = new Properties();
            // do not use lock
            debeziumProperties.put("snapshot.locking.mode", "none");
            String dbHost = entry.getKey();
            List<String> dbs = entry.getValue();
            sourceFuncs.addAll(sourceFunctionCreator.create(dbHost, dbs, tbs, debeziumProperties));
        }
        return sourceFuncs;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DBConfig(com.qlangtech.tis.plugin.ds.DBConfig) StringUtils(org.apache.commons.lang.StringUtils) Properties(java.util.Properties) Lists(org.apache.commons.compress.utils.Lists) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) Set(java.util.Set) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AsyncMsg(com.qlangtech.tis.async.message.client.consumer.AsyncMsg) BasicDataSourceFactory(com.qlangtech.tis.plugin.ds.BasicDataSourceFactory) ReaderSource(com.qlangtech.tis.realtime.ReaderSource) List(java.util.List) Map(java.util.Map) Properties(java.util.Properties) IOException(java.io.IOException) DBConfig(com.qlangtech.tis.plugin.ds.DBConfig) List(java.util.List) ReaderSource(com.qlangtech.tis.realtime.ReaderSource) Map(java.util.Map)

Example 19 with ISelectedTab

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

the class TestFlinkCDCMySQLSourceFactory method testBinlogConsumeWithDataStreamRegisterInstaneDetailTable.

/**
 * 测试 instancedetail
 *
 * @throws Exception
 */
@Test
public void testBinlogConsumeWithDataStreamRegisterInstaneDetailTable() throws Exception {
    FlinkCDCMySQLSourceFactory mysqlCDCFactory = new FlinkCDCMySQLSourceFactory();
    mysqlCDCFactory.startupOptions = "latest";
    final String tabName = "instancedetail";
    CUDCDCTestSuit cdcTestSuit = new CUDCDCTestSuit() {

        @Override
        protected BasicDataSourceFactory createDataSourceFactory(TargetResName dataxName) {
            return createMySqlDataSourceFactory(dataxName);
        }

        @Override
        protected String getColEscape() {
            return "`";
        }

        @Override
        protected IResultRows createConsumerHandle(String tabName) {
            return new TestTableRegisterFlinkSourceHandle(tabName, cols);
        }

        @Override
        protected void verfiyTableCrudProcess(String tabName, BasicDataXRdbmsReader dataxReader, ISelectedTab tab, IResultRows consumerHandle, IMQListener<JobExecutionResult> imqListener) throws MQConsumeException, InterruptedException {
            // super.verfiyTableCrudProcess(tabName, dataxReader, tab, consumerHandle, imqListener);
            List<ISelectedTab> tabs = Collections.singletonList(tab);
            List<TestRow> exampleRows = Lists.newArrayList();
            exampleRows.add(this.parseTestRow(RowKind.INSERT, TestFlinkCDCMySQLSourceFactory.class, tabName + "/insert1.txt"));
            Assert.assertEquals(1, exampleRows.size());
            imqListener.start(dataxName, dataxReader, tabs, null);
            Thread.sleep(1000);
            CloseableIterator<Row> snapshot = consumerHandle.getRowSnapshot(tabName);
            BasicDataSourceFactory dataSourceFactory = (BasicDataSourceFactory) dataxReader.getDataSourceFactory();
            Assert.assertNotNull("dataSourceFactory can not be null", dataSourceFactory);
            dataSourceFactory.visitFirstConnection((conn) -> {
                startProcessConn(conn);
                for (TestRow t : exampleRows) {
                    RowVals<Object> vals = t.vals;
                    final String insertBase = "insert into " + createTableName(tabName) + "(" + cols.stream().filter((c) -> vals.notNull(c.getName())).map((col) -> getColEscape() + col.getName() + getColEscape()).collect(Collectors.joining(" , ")) + ") " + "values(" + cols.stream().filter((c) -> vals.notNull(c.getName())).map((col) -> "?").collect(Collectors.joining(" , ")) + ")";
                    PreparedStatement statement = conn.prepareStatement(insertBase);
                    AtomicInteger ci = new AtomicInteger();
                    cols.stream().filter((c) -> vals.notNull(c.getName())).forEach((col) -> {
                        col.type.accept(new DataType.TypeVisitor<Void>() {

                            @Override
                            public Void longType(DataType type) {
                                try {
                                    statement.setLong(ci.incrementAndGet(), Long.parseLong(vals.getString(col.getName())));
                                } catch (SQLException e) {
                                    throw new RuntimeException(e);
                                }
                                return null;
                            }

                            @Override
                            public Void doubleType(DataType type) {
                                try {
                                    statement.setDouble(ci.incrementAndGet(), Double.parseDouble(vals.getString(col.getName())));
                                } catch (SQLException e) {
                                    throw new RuntimeException(e);
                                }
                                return null;
                            }

                            @Override
                            public Void dateType(DataType type) {
                                try {
                                    statement.setDate(ci.incrementAndGet(), java.sql.Date.valueOf(vals.getString(col.getName())));
                                } catch (Exception e) {
                                    throw new RuntimeException(e);
                                }
                                return null;
                            }

                            @Override
                            public Void timestampType(DataType type) {
                                try {
                                    statement.setTimestamp(ci.incrementAndGet(), java.sql.Timestamp.valueOf(vals.getString(col.getName())));
                                } catch (Exception e) {
                                    throw new RuntimeException(e);
                                }
                                return null;
                            }

                            @Override
                            public Void bitType(DataType type) {
                                try {
                                    statement.setByte(ci.incrementAndGet(), Byte.parseByte(vals.getString(col.getName())));
                                } catch (Exception e) {
                                    throw new RuntimeException(e);
                                }
                                return null;
                            }

                            @Override
                            public Void blobType(DataType type) {
                                try {
                                    try (InputStream input = new ByteArrayInputStream(vals.getString(col.getName()).getBytes(TisUTF8.get()))) {
                                        statement.setBlob(ci.incrementAndGet(), input);
                                    }
                                } catch (Exception e) {
                                    throw new RuntimeException(e);
                                }
                                return null;
                            }

                            @Override
                            public Void varcharType(DataType type) {
                                try {
                                    statement.setString(ci.incrementAndGet(), (vals.getString(col.getName())));
                                } catch (Exception e) {
                                    throw new RuntimeException(e);
                                }
                                return null;
                            }

                            @Override
                            public Void intType(DataType type) {
                                try {
                                    statement.setInt(ci.incrementAndGet(), Integer.parseInt(vals.getString(col.getName())));
                                } catch (Exception e) {
                                    throw new RuntimeException(e);
                                }
                                return null;
                            }

                            @Override
                            public Void floatType(DataType type) {
                                try {
                                    statement.setFloat(ci.incrementAndGet(), Float.parseFloat(vals.getString(col.getName())));
                                } catch (Exception e) {
                                    throw new RuntimeException(e);
                                }
                                return null;
                            }

                            @Override
                            public Void decimalType(DataType type) {
                                try {
                                    statement.setBigDecimal(ci.incrementAndGet(), BigDecimal.valueOf(Double.parseDouble(vals.getString(col.getName()))));
                                } catch (Exception e) {
                                    throw new RuntimeException(e);
                                }
                                return null;
                            }

                            @Override
                            public Void timeType(DataType type) {
                                try {
                                    statement.setTime(ci.incrementAndGet(), java.sql.Time.valueOf(vals.getString(col.getName())));
                                } catch (Exception e) {
                                    throw new RuntimeException(e);
                                }
                                return null;
                            }

                            @Override
                            public Void tinyIntType(DataType dataType) {
                                try {
                                    statement.setShort(ci.incrementAndGet(), Short.parseShort(vals.getString(col.getName())));
                                } catch (Exception e) {
                                    throw new RuntimeException(e);
                                }
                                return null;
                            }

                            @Override
                            public Void smallIntType(DataType dataType) {
                                tinyIntType(dataType);
                                return null;
                            }
                        });
                    });
                    Assert.assertEquals(1, executePreparedStatement(conn, statement));
                    statement.close();
                    sleepForAWhile();
                    System.out.println("wait to show insert rows");
                    waitForSnapshotStarted(snapshot);
                    List<TestRow> rows = fetchRows(snapshot, 1, false);
                    for (TestRow rr : rows) {
                        System.out.println("------------" + rr.get("instance_id"));
                        assertTestRow(tabName, RowKind.INSERT, consumerHandle, t, rr);
                    }
                }
            });
        }
    };
    cdcTestSuit.startTest(mysqlCDCFactory, tabName);
}
Also used : TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) CUDCDCTestSuit(com.qlangtech.plugins.incr.flink.cdc.CUDCDCTestSuit) IResultRows(com.qlangtech.plugins.incr.flink.cdc.IResultRows) TIS(com.qlangtech.tis.TIS) RowVals(com.qlangtech.plugins.incr.flink.cdc.RowVals) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) BasicDataSourceFactory(com.qlangtech.tis.plugin.ds.BasicDataSourceFactory) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException) Lists(com.google.common.collect.Lists) CenterResource(com.qlangtech.tis.manage.common.CenterResource) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TisUTF8(com.qlangtech.tis.manage.common.TisUTF8) TestTableRegisterFlinkSourceHandle(com.qlangtech.plugins.incr.flink.cdc.source.TestTableRegisterFlinkSourceHandle) TestRow(com.qlangtech.plugins.incr.flink.cdc.TestRow) Before(org.junit.Before) MQConsumeException(com.qlangtech.tis.async.message.client.consumer.MQConsumeException) BasicDataXRdbmsReader(com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader) Descriptor(com.qlangtech.tis.extension.Descriptor) Test(org.junit.Test) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) TISEasyMock(com.qlangtech.tis.test.TISEasyMock) CloseableIterator(org.apache.flink.util.CloseableIterator) List(java.util.List) RowKind(org.apache.flink.types.RowKind) DataType(com.qlangtech.tis.plugin.ds.DataType) Row(org.apache.flink.types.Row) Assert(org.junit.Assert) IMQListener(com.qlangtech.tis.async.message.client.consumer.IMQListener) Collections(java.util.Collections) InputStream(java.io.InputStream) BasicDataSourceFactory(com.qlangtech.tis.plugin.ds.BasicDataSourceFactory) SQLException(java.sql.SQLException) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) CUDCDCTestSuit(com.qlangtech.plugins.incr.flink.cdc.CUDCDCTestSuit) IResultRows(com.qlangtech.plugins.incr.flink.cdc.IResultRows) IMQListener(com.qlangtech.tis.async.message.client.consumer.IMQListener) TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) DataType(com.qlangtech.tis.plugin.ds.DataType) BasicDataXRdbmsReader(com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestRow(com.qlangtech.plugins.incr.flink.cdc.TestRow) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) MQConsumeException(com.qlangtech.tis.async.message.client.consumer.MQConsumeException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) TestTableRegisterFlinkSourceHandle(com.qlangtech.plugins.incr.flink.cdc.source.TestTableRegisterFlinkSourceHandle) TestRow(com.qlangtech.plugins.incr.flink.cdc.TestRow) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 20 with ISelectedTab

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

the class FlinkCDCOracleSourceFunction method start.

@Override
public JobExecutionResult start(TargetResName channalName, IDataxReader dataSource, List<ISelectedTab> tabs, IDataxProcessor dataXProcessor) throws MQConsumeException {
    try {
        BasicDataXRdbmsReader reader = (BasicDataXRdbmsReader) dataSource;
        BasicDataSourceFactory f = (BasicDataSourceFactory) reader.getDataSourceFactory();
        SourceChannel sourceChannel = new SourceChannel(SourceChannel.getSourceFunction(f, (tab) -> tab.getTabName(), tabs, (dbHost, dbs, tbs, debeziumProperties) -> {
            return dbs.stream().map((databaseName) -> {
                SourceFunction<DTO> sourceFunction = OracleSource.<DTO>builder().hostname(dbHost).debeziumProperties(debeziumProperties).port(f.port).startupOptions(sourceFactory.getStartupOptions()).database(// monitor XE database
                StringUtils.upperCase(f.dbName)).tableList(// monitor products table
                tbs.toArray(new String[tbs.size()])).username(f.getUserName()).password(f.getPassword()).deserializer(// converts SourceRecord to JSON String
                new TISDeserializationSchema()).build();
                return new ReaderSource(dbHost + ":" + f.port + "_" + databaseName, sourceFunction);
            }).collect(Collectors.toList());
        }));
        for (ISelectedTab tab : tabs) {
            sourceChannel.addFocusTab(tab.getName());
        }
        return (JobExecutionResult) getConsumerHandle().consume(channalName, sourceChannel, dataXProcessor);
    } catch (Exception e) {
        throw new MQConsumeException(e.getMessage(), e);
    }
}
Also used : MQConsumeException(com.qlangtech.tis.async.message.client.consumer.MQConsumeException) IConsumerHandle(com.qlangtech.tis.async.message.client.consumer.IConsumerHandle) StringUtils(org.apache.commons.lang.StringUtils) TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) OracleSource(com.ververica.cdc.connectors.oracle.OracleSource) 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) 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)

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