Search in sources :

Example 1 with PhoenixSyncService

use of com.alibaba.otter.canal.client.adapter.phoenix.service.PhoenixSyncService 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)1 PhoenixConfigMonitor (com.alibaba.otter.canal.client.adapter.phoenix.monitor.PhoenixConfigMonitor)1 PhoenixSyncService (com.alibaba.otter.canal.client.adapter.phoenix.service.PhoenixSyncService)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1