Search in sources :

Example 6 with MappingConfig

use of com.alibaba.otter.canal.client.adapter.phoenix.config.MappingConfig in project canal by alibaba.

the class PhoenixAdapter method init.

/**
 * 初始化方法
 *
 * @param configuration 外部适配器配置信息
 */
@Override
public void init(OuterAdapterConfig configuration, Properties envProperties) {
    this.envProperties = envProperties;
    Map<String, MappingConfig> phoenixMappingTmp = ConfigLoader.load(envProperties);
    // 过滤不匹配的key的配置
    phoenixMappingTmp.forEach((key, mappingConfig) -> {
        if ((mappingConfig.getOuterAdapterKey() == null && configuration.getKey() == null) || (mappingConfig.getOuterAdapterKey() != null && mappingConfig.getOuterAdapterKey().equalsIgnoreCase(configuration.getKey()))) {
            phoenixMapping.put(key, mappingConfig);
        }
    });
    if (phoenixMapping.isEmpty()) {
        throw new RuntimeException("No phoenix adapter found for config key: " + configuration.getKey());
    } else {
        logger.info("[{}]phoenix config mapping: {}", this, phoenixMapping.keySet());
    }
    for (Map.Entry<String, MappingConfig> entry : phoenixMapping.entrySet()) {
        String configName = entry.getKey();
        MappingConfig mappingConfig = entry.getValue();
        String key;
        if (envProperties != null && !"tcp".equalsIgnoreCase(envProperties.getProperty("canal.conf.mode"))) {
            key = StringUtils.trimToEmpty(mappingConfig.getDestination()) + "-" + StringUtils.trimToEmpty(mappingConfig.getGroupId()) + "_" + mappingConfig.getDbMapping().getDatabase() + "-" + mappingConfig.getDbMapping().getTable().toLowerCase();
        } else {
            key = StringUtils.trimToEmpty(mappingConfig.getDestination()) + "_" + mappingConfig.getDbMapping().getDatabase() + "-" + mappingConfig.getDbMapping().getTable().toLowerCase();
        }
        Map<String, MappingConfig> configMap = mappingConfigCache.computeIfAbsent(key, k1 -> new ConcurrentHashMap<>());
        configMap.put(configName, mappingConfig);
    }
    Map<String, String> properties = configuration.getProperties();
    DriverClass = properties.get("jdbc.driverClassName");
    PhoenixUrl = properties.get("jdbc.url");
    try {
        // phoenix内部本身有连接池,不需要使用Druid初始化
        phoenixPro.setProperty("hbase.rpc.timeout", "600000");
        phoenixPro.setProperty("hbase.client.scanner.timeout.period", "600000");
        phoenixPro.setProperty("dfs.client.socket-timeout", "600000");
        phoenixPro.setProperty("phoenix.query.keepAliveMs", "600000");
        phoenixPro.setProperty("phoenix.query.timeoutMs", "3600000");
        Class.forName(DriverClass);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    String threads = properties.get("threads");
    phoenixSyncService = new PhoenixSyncService(threads != null ? Integer.valueOf(threads) : null);
    phoenixConfigMonitor = new PhoenixConfigMonitor();
    phoenixConfigMonitor.init(configuration.getKey(), this, envProperties);
}
Also used : MappingConfig(com.alibaba.otter.canal.client.adapter.phoenix.config.MappingConfig) PhoenixSyncService(com.alibaba.otter.canal.client.adapter.phoenix.service.PhoenixSyncService) PhoenixConfigMonitor(com.alibaba.otter.canal.client.adapter.phoenix.monitor.PhoenixConfigMonitor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

MappingConfig (com.alibaba.otter.canal.client.adapter.phoenix.config.MappingConfig)6 SQLException (java.sql.SQLException)3 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)2 ParserException (com.alibaba.druid.sql.parser.ParserException)2 DbMapping (com.alibaba.otter.canal.client.adapter.phoenix.config.MappingConfig.DbMapping)2 SingleDml (com.alibaba.otter.canal.client.adapter.phoenix.support.SingleDml)2 SyncUtil (com.alibaba.otter.canal.client.adapter.phoenix.support.SyncUtil)2 TypeUtil (com.alibaba.otter.canal.client.adapter.phoenix.support.TypeUtil)2 Util (com.alibaba.otter.canal.client.adapter.support.Util)2 Connection (java.sql.Connection)2 java.util (java.util)2 LinkedHashMap (java.util.LinkedHashMap)2 DataSource (javax.sql.DataSource)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 SQLUtils (com.alibaba.druid.sql.SQLUtils)1 SQLName (com.alibaba.druid.sql.ast.SQLName)1 com.alibaba.druid.sql.ast.statement (com.alibaba.druid.sql.ast.statement)1 JdbcConstants (com.alibaba.druid.util.JdbcConstants)1 JSON (com.alibaba.fastjson.JSON)1