Search in sources :

Example 1 with DBConfig

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

the class ClickHouseSinkFactory method createSinkFunction.

@Override
public Map<IDataxProcessor.TableAlias, SinkFunction<DTO>> createSinkFunction(IDataxProcessor dataxProcessor) {
    Map<IDataxProcessor.TableAlias, SinkFunction<DTO>> sinkFuncs = Maps.newHashMap();
    IDataxProcessor.TableAlias tableName = null;
    DataXClickhouseWriter dataXWriter = (DataXClickhouseWriter) dataxProcessor.getWriter(null);
    Objects.requireNonNull(dataXWriter, "dataXWriter can not be null");
    IDataxReader reader = dataxProcessor.getReader(null);
    List<ISelectedTab> tabs = reader.getSelectedTabs();
    ClickHouseDataSourceFactory dsFactory = dataXWriter.getDataSourceFactory();
    DBConfig dbConfig = dsFactory.getDbConfig();
    for (Map.Entry<String, IDataxProcessor.TableAlias> tabAliasEntry : dataxProcessor.getTabAlias().entrySet()) {
        tableName = tabAliasEntry.getValue();
        Objects.requireNonNull(tableName, "tableName can not be null");
        if (StringUtils.isEmpty(tableName.getFrom())) {
            throw new IllegalStateException("tableName.getFrom() can not be empty");
        }
        AtomicReference<SinkFunction<DTO>> sinkFuncRef = new AtomicReference<>();
        final IDataxProcessor.TableAlias tabName = tableName;
        AtomicReference<Object[]> exceptionLoader = new AtomicReference<>();
        final String targetTabName = tableName.getTo();
        dbConfig.vistDbURL(false, (dbName, jdbcUrl) -> {
            try {
                Optional<ISelectedTab> selectedTab = tabs.stream().filter((tab) -> StringUtils.equals(tabName.getFrom(), tab.getName())).findFirst();
                if (!selectedTab.isPresent()) {
                    throw new IllegalStateException("target table:" + tabName.getFrom() + " can not find matched table in:[" + tabs.stream().map((t) -> t.getName()).collect(Collectors.joining(",")) + "]");
                }
                /**
                 * 需要先初始化表starrocks目标库中的表
                 */
                dataXWriter.initWriterTable(targetTabName, Collections.singletonList(jdbcUrl));
                sinkFuncRef.set(createSinkFunction(dbName, targetTabName, selectedTab.get(), jdbcUrl, dsFactory));
            } catch (Throwable e) {
                exceptionLoader.set(new Object[] { jdbcUrl, e });
            }
        });
        if (exceptionLoader.get() != null) {
            Object[] error = exceptionLoader.get();
            throw new RuntimeException((String) error[0], (Throwable) error[1]);
        }
        Objects.requireNonNull(sinkFuncRef.get(), "sinkFunc can not be null");
        sinkFuncs.put(tableName, sinkFuncRef.get());
    }
    if (sinkFuncs.size() < 1) {
        throw new IllegalStateException("size of sinkFuncs can not be small than 1");
    }
    return sinkFuncs;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) FormField(com.qlangtech.tis.plugin.annotation.FormField) DTO(com.qlangtech.tis.realtime.transfer.DTO) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) AtomicReference(java.util.concurrent.atomic.AtomicReference) DataXClickhouseWriter(com.qlangtech.tis.plugin.datax.DataXClickhouseWriter) ClickHouseDataSourceFactory(com.qlangtech.tis.plugin.ds.clickhouse.ClickHouseDataSourceFactory) ClickHouseClusterSettings(ru.ivi.opensource.flinkclickhousesink.model.ClickHouseClusterSettings) CollectionUtils(org.apache.commons.collections.CollectionUtils) IDataXPluginMeta(com.qlangtech.tis.datax.IDataXPluginMeta) IDataxReader(com.qlangtech.tis.datax.IDataxReader) Public(org.apache.flink.annotation.Public) 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) DBConfig(com.qlangtech.tis.plugin.ds.DBConfig) TISExtension(com.qlangtech.tis.extension.TISExtension) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) Lists(org.apache.commons.compress.utils.Lists) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) ClickHouseSinkConst(ru.ivi.opensource.flinkclickhousesink.model.ClickHouseSinkConst) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) AtomicReference(java.util.concurrent.atomic.AtomicReference) IDataxReader(com.qlangtech.tis.datax.IDataxReader) DBConfig(com.qlangtech.tis.plugin.ds.DBConfig) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) DataXClickhouseWriter(com.qlangtech.tis.plugin.datax.DataXClickhouseWriter) ClickHouseDataSourceFactory(com.qlangtech.tis.plugin.ds.clickhouse.ClickHouseDataSourceFactory)

Example 2 with DBConfig

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

the class StarRocksSinkFactory method createSinkFunction.

@Override
public Map<IDataxProcessor.TableAlias, SinkFunction<DTO>> createSinkFunction(IDataxProcessor dataxProcessor) {
    Map<IDataxProcessor.TableAlias, SinkFunction<DTO>> sinkFuncs = Maps.newHashMap();
    IDataxProcessor.TableAlias tableName = null;
    // Map<String, IDataxProcessor.TableAlias> tabAlias = dataxProcessor.getTabAlias();
    BasicDorisStarRocksWriter dataXWriter = (BasicDorisStarRocksWriter) dataxProcessor.getWriter(null);
    Objects.requireNonNull(dataXWriter, "dataXWriter can not be null");
    BasicDorisStarRocksWriter.Separator separator = dataXWriter.getSeparator();
    IDataxReader reader = dataxProcessor.getReader(null);
    List<ISelectedTab> tabs = reader.getSelectedTabs();
    DorisSourceFactory dsFactory = dataXWriter.getDataSourceFactory();
    DBConfig dbConfig = dsFactory.getDbConfig();
    Map<String, IDataxProcessor.TableAlias> selectedTabs = dataxProcessor.getTabAlias();
    if (MapUtils.isEmpty(selectedTabs)) {
        throw new IllegalStateException("selectedTabs can not be empty");
    }
    for (Map.Entry<String, IDataxProcessor.TableAlias> tabAliasEntry : selectedTabs.entrySet()) {
        tableName = tabAliasEntry.getValue();
        Objects.requireNonNull(tableName, "tableName can not be null");
        if (StringUtils.isEmpty(tableName.getFrom())) {
            throw new IllegalStateException("tableName.getFrom() can not be empty");
        }
        AtomicReference<SinkFunction<DTO>> sinkFuncRef = new AtomicReference<>();
        final IDataxProcessor.TableAlias tabName = tableName;
        AtomicReference<Object[]> exceptionLoader = new AtomicReference<>();
        final String targetTabName = tableName.getTo();
        dbConfig.vistDbURL(false, (dbName, jdbcUrl) -> {
            try {
                Optional<ISelectedTab> selectedTab = tabs.stream().filter((tab) -> StringUtils.equals(tabName.getFrom(), tab.getName())).findFirst();
                if (!selectedTab.isPresent()) {
                    throw new IllegalStateException("target table:" + tabName.getFrom() + " can not find matched table in:[" + tabs.stream().map((t) -> t.getName()).collect(Collectors.joining(",")) + "]");
                }
                /**
                 * 需要先初始化表starrocks目标库中的表
                 */
                dataXWriter.initWriterTable(targetTabName, Collections.singletonList(jdbcUrl));
                sinkFuncRef.set(createSinkFunction(dbName, targetTabName, selectedTab.get(), jdbcUrl, dsFactory, separator));
            } catch (Throwable e) {
                exceptionLoader.set(new Object[] { jdbcUrl, e });
            }
        });
        if (exceptionLoader.get() != null) {
            Object[] error = exceptionLoader.get();
            throw new RuntimeException((String) error[0], (Throwable) error[1]);
        }
        Objects.requireNonNull(sinkFuncRef.get(), "sinkFunc can not be null");
        sinkFuncs.put(tableName, sinkFuncRef.get());
    }
    if (sinkFuncs.size() < 1) {
        throw new IllegalStateException("size of sinkFuncs can not be small than 1");
    }
    return sinkFuncs;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) AtomicDataType(org.apache.flink.table.types.AtomicDataType) java.util(java.util) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) Option(com.qlangtech.tis.manage.common.Option) FormField(com.qlangtech.tis.plugin.annotation.FormField) DTO(com.qlangtech.tis.realtime.transfer.DTO) StarRocksSinkOptions(com.starrocks.connector.flink.table.StarRocksSinkOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) Context(com.alibaba.citrus.turbine.Context) IFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler) Lists(com.google.common.collect.Lists) StarRocksSinkOP(com.starrocks.connector.flink.row.StarRocksSinkOP) TextElement(org.apache.flink.configuration.description.TextElement) IDataXPluginMeta(com.qlangtech.tis.datax.IDataXPluginMeta) IDataxReader(com.qlangtech.tis.datax.IDataxReader) org.apache.flink.table.types.logical(org.apache.flink.table.types.logical) Public(org.apache.flink.annotation.Public) ConfigOption(org.apache.flink.configuration.ConfigOption) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) DorisSourceFactory(com.qlangtech.tis.plugin.ds.doris.DorisSourceFactory) Validator(com.qlangtech.tis.plugin.annotation.Validator) TISSinkFactory(com.qlangtech.tis.plugin.incr.TISSinkFactory) StarRocksSink(com.starrocks.connector.flink.StarRocksSink) DBConfig(com.qlangtech.tis.plugin.ds.DBConfig) UnderlineUtils(com.qlangtech.tis.realtime.transfer.UnderlineUtils) TISExtension(com.qlangtech.tis.extension.TISExtension) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) MapUtils(org.apache.commons.collections.MapUtils) BasicDorisStarRocksWriter(com.qlangtech.tis.plugin.datax.BasicDorisStarRocksWriter) DataTypes(org.apache.flink.table.api.DataTypes) TableSchema(org.apache.flink.table.api.TableSchema) Field(java.lang.reflect.Field) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) DataType(com.qlangtech.tis.plugin.ds.DataType) StarRocksSinkSemantic(com.starrocks.connector.flink.table.StarRocksSinkSemantic) BlockElement(org.apache.flink.configuration.description.BlockElement) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) BasicDorisStarRocksWriter(com.qlangtech.tis.plugin.datax.BasicDorisStarRocksWriter) IDataxReader(com.qlangtech.tis.datax.IDataxReader) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) AtomicReference(java.util.concurrent.atomic.AtomicReference) DBConfig(com.qlangtech.tis.plugin.ds.DBConfig) DorisSourceFactory(com.qlangtech.tis.plugin.ds.doris.DorisSourceFactory)

Example 3 with DBConfig

use of com.qlangtech.tis.plugin.ds.DBConfig in project tis by qlangtech.

the class DBConfigParser method main.

public static void main(String[] args) throws Exception {
    File f = new File("./db_config.txt");
    String content = FileUtils.readFileToString(f, "utf8");
    // System.out.println(content);
    DBTokenizer tokenizer = new DBTokenizer(content);
    tokenizer.parse();
    // for (Token t : ) {
    // System.out.println(t.getContent() + " "
    // + t.getToken());
    // }
    DBConfigParser parser = new DBConfigParser(tokenizer.getTokenBuffer());
    DBConfig db = parser.startParser();
    System.out.println("hostDesc:" + parser.hostDesc);
    System.out.println("type:" + db.getDbType());
    System.out.println("name:" + db.getName());
    // System.out.println("getPassword:" + db.getPassword());
    // System.out.println("getPort:" + db.getPort());
    // System.out.println("UserName:" + db.getUserName());
    StringBuffer dbdesc = new StringBuffer();
    for (Map.Entry<String, List<String>> e : db.getDbEnum().entrySet()) {
        dbdesc.append(e.getKey()).append(":");
        for (String dbName : e.getValue()) {
            dbdesc.append(dbName).append(",");
        }
        dbdesc.append("\n");
    }
    System.out.println(dbdesc.toString());
}
Also used : List(java.util.List) File(java.io.File) Map(java.util.Map) DBConfig(com.qlangtech.tis.plugin.ds.DBConfig)

Example 4 with DBConfig

use of com.qlangtech.tis.plugin.ds.DBConfig in project tis by qlangtech.

the class DBConfigParser method parseDBEnum.

/**
 * Parse the dbnode description to struct Object
 *
 * @param dbName
 * @param dbNodeDesc
 * @return
 */
public static Map<String, List<String>> parseDBEnum(String dbName, String dbNodeDesc) {
    if (StringUtils.isEmpty(dbNodeDesc)) {
        throw new IllegalArgumentException("param dbNodeDesc can not be null");
    }
    if (StringUtils.isEmpty(dbName)) {
        throw new IllegalArgumentException("param dbName can not be null");
    }
    DBTokenizer tokenizer = new DBTokenizer(ScannerPatterns.HOST_KEY + ":" + dbNodeDesc);
    tokenizer.parse();
    DBConfigParser parser = new DBConfigParser(tokenizer.getTokenBuffer());
    parser.dbConfigResult.setName(dbName);
    parser.parseHostDesc();
    DBConfig db = parser.dbConfigResult;
    return db.getDbEnum();
}
Also used : DBConfig(com.qlangtech.tis.plugin.ds.DBConfig)

Example 5 with DBConfig

use of com.qlangtech.tis.plugin.ds.DBConfig in project tis by qlangtech.

the class JavaCompilerProcess method main.

public static void main(String[] args) throws Exception {
    File rootDir = new File("D:\\j2ee_solution\\import_pj\\ibator_koubei\\ibator_koubei\\targett\\src\\main");
    File classpathDir = new File("D:/j2ee_solution/tis-ibatis/target/dependency/");
    DBConfig dbConfig = new DBConfig();
    dbConfig.setName("shop");
    JavaCompilerProcess compilerProcess = new JavaCompilerProcess(dbConfig, rootDir, classpathDir);
    compilerProcess.compileAndBuildJar();
// JarFile jarFile = new JarFile(
// "D:\\j2ee_solution\\mvn_repository\\com\\dfire\\tis\\tis-ibatis\\2.0\\tis-ibatis-2.0.jar");
// JarEntry next = null;
// Enumeration<JarEntry> entries = jarFile.entries();
// InputStream input = null;
// while (entries.hasMoreElements()) {
// next = entries.nextElement();
// 
// System.out.println(next.getName() + ",input is dir:" + next.isDirectory());
// 
// }
// jarFile.close();
}
Also used : File(java.io.File) DBConfig(com.qlangtech.tis.plugin.ds.DBConfig)

Aggregations

DBConfig (com.qlangtech.tis.plugin.ds.DBConfig)11 List (java.util.List)5 Maps (com.google.common.collect.Maps)3 ISelectedTab (com.qlangtech.tis.plugin.ds.ISelectedTab)3 File (java.io.File)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 StringUtils (org.apache.commons.lang.StringUtils)3 IDataXPluginMeta (com.qlangtech.tis.datax.IDataXPluginMeta)2 IDataxProcessor (com.qlangtech.tis.datax.IDataxProcessor)2 IDataxReader (com.qlangtech.tis.datax.IDataxReader)2 TISExtension (com.qlangtech.tis.extension.TISExtension)2 FormField (com.qlangtech.tis.plugin.annotation.FormField)2 FormFieldType (com.qlangtech.tis.plugin.annotation.FormFieldType)2 Validator (com.qlangtech.tis.plugin.annotation.Validator)2 ColumnMetaData (com.qlangtech.tis.plugin.ds.ColumnMetaData)2 TISSinkFactory (com.qlangtech.tis.plugin.incr.TISSinkFactory)2 DTO (com.qlangtech.tis.realtime.transfer.DTO)2 java.util (java.util)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2