Search in sources :

Example 1 with KuduTemplate

use of com.alibaba.otter.canal.client.adapter.kudu.support.KuduTemplate in project canal by alibaba.

the class KuduAdapter method init.

@Override
public void init(OuterAdapterConfig configuration, Properties envProperties) {
    this.envProperties = envProperties;
    Map<String, KuduMappingConfig> kuduMappingTmp = KuduMappingConfigLoader.load(envProperties);
    // 过滤不匹配的key的配置,获取连接key,key为配置文件名称
    kuduMappingTmp.forEach((key, mappingConfig) -> {
        if ((mappingConfig.getOuterAdapterKey() == null && configuration.getKey() == null) || (mappingConfig.getOuterAdapterKey() != null && mappingConfig.getOuterAdapterKey().equalsIgnoreCase(configuration.getKey()))) {
            kuduMapping.put(key, mappingConfig);
            dataSourceKey = mappingConfig.getDataSourceKey();
        }
    });
    // 判断目标字段是否为空
    if (kuduMapping.isEmpty()) {
        throw new RuntimeException("No kudu adapter found for config key: " + configuration.getKey());
    }
    for (Map.Entry<String, KuduMappingConfig> entry : kuduMapping.entrySet()) {
        String configName = entry.getKey();
        KuduMappingConfig mappingConfig = entry.getValue();
        String k;
        if (envProperties != null && !"tcp".equalsIgnoreCase(envProperties.getProperty("canal.conf.mode"))) {
            k = StringUtils.trimToEmpty(mappingConfig.getDestination()) + "-" + StringUtils.trimToEmpty(mappingConfig.getGroupId()) + "_" + mappingConfig.getKuduMapping().getDatabase() + "-" + mappingConfig.getKuduMapping().getTable();
        } else {
            k = StringUtils.trimToEmpty(mappingConfig.getDestination()) + "_" + mappingConfig.getKuduMapping().getDatabase() + "-" + mappingConfig.getKuduMapping().getTable();
        }
        Map<String, KuduMappingConfig> configMap = mappingConfigCache.computeIfAbsent(k, k1 -> new ConcurrentHashMap<>());
        configMap.put(configName, mappingConfig);
    }
    Map<String, String> properties = configuration.getProperties();
    String kudu_master = properties.get("kudu.master.address");
    kuduTemplate = new KuduTemplate(kudu_master);
    kuduSyncService = new KuduSyncService(kuduTemplate);
    kuduConfigMonitor = new KuduConfigMonitor();
    kuduConfigMonitor.init(this, envProperties);
}
Also used : KuduConfigMonitor(com.alibaba.otter.canal.client.adapter.kudu.monitor.KuduConfigMonitor) KuduSyncService(com.alibaba.otter.canal.client.adapter.kudu.service.KuduSyncService) KuduMappingConfig(com.alibaba.otter.canal.client.adapter.kudu.config.KuduMappingConfig) KuduTemplate(com.alibaba.otter.canal.client.adapter.kudu.support.KuduTemplate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

KuduMappingConfig (com.alibaba.otter.canal.client.adapter.kudu.config.KuduMappingConfig)1 KuduConfigMonitor (com.alibaba.otter.canal.client.adapter.kudu.monitor.KuduConfigMonitor)1 KuduSyncService (com.alibaba.otter.canal.client.adapter.kudu.service.KuduSyncService)1 KuduTemplate (com.alibaba.otter.canal.client.adapter.kudu.support.KuduTemplate)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1