Search in sources :

Example 1 with DefaultCredentials

use of com.alicloud.openservices.tablestore.core.auth.DefaultCredentials in project canal by alibaba.

the class TablestoreAdapter method init.

@Override
public void init(OuterAdapterConfig configuration, Properties envProperties) {
    this.envProperties = envProperties;
    this.configuration = configuration;
    Map<String, MappingConfig> tablestoreMappingTmp = ConfigLoader.load(envProperties);
    // 过滤不匹配的key的配置
    tablestoreMappingTmp.forEach((key, mappingConfig) -> {
        if ((mappingConfig.getOuterAdapterKey() == null && configuration.getKey() == null) || (mappingConfig.getOuterAdapterKey() != null && mappingConfig.getOuterAdapterKey().equalsIgnoreCase(configuration.getKey()))) {
            tablestoreMapping.put(key, mappingConfig);
            mappingConfig.getDbMapping().init(mappingConfig);
        }
    });
    if (tablestoreMapping.isEmpty()) {
        throw new RuntimeException("No tablestore adapter found for config key: " + configuration.getKey());
    }
    Map<String, String> properties = configuration.getProperties();
    for (Map.Entry<String, MappingConfig> entry : tablestoreMapping.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();
        } else {
            key = StringUtils.trimToEmpty(mappingConfig.getDestination()) + "_" + mappingConfig.getDbMapping().getDatabase() + "-" + mappingConfig.getDbMapping().getTable();
        }
        Map<String, MappingConfig> configMap = mappingConfigCache.computeIfAbsent(key, k1 -> new ConcurrentHashMap<>());
        configMap.put(configName, mappingConfig);
        // 构建对应的 TableStoreWriter
        ServiceCredentials credentials = new DefaultCredentials(properties.get(PropertyConstants.TABLESTORE_ACCESSSECRETID), properties.get(PropertyConstants.TABLESTORE_ACCESSSECRETKEY));
        WriterConfig config = getWriterConfig(mappingConfig);
        TableStoreWriter writer = new DefaultTableStoreWriter(properties.get(PropertyConstants.TABLESTORE_ENDPOINT), credentials, properties.get(PropertyConstants.TABLESTORE_INSTANCENAME), mappingConfig.getDbMapping().getTargetTable(), config, null);
        Map<String, TableStoreWriter> config2writerMap = writerCache.computeIfAbsent(key, k1 -> new ConcurrentHashMap<>());
        config2writerMap.put(configName, writer);
    }
    tablestoreSyncService = new TablestoreSyncService();
}
Also used : DefaultTableStoreWriter(com.alicloud.openservices.tablestore.DefaultTableStoreWriter) TableStoreWriter(com.alicloud.openservices.tablestore.TableStoreWriter) ServiceCredentials(com.alicloud.openservices.tablestore.core.auth.ServiceCredentials) TablestoreSyncService(com.alibaba.otter.canal.client.adapter.tablestore.service.TablestoreSyncService) WriterConfig(com.alicloud.openservices.tablestore.writer.WriterConfig) DefaultCredentials(com.alicloud.openservices.tablestore.core.auth.DefaultCredentials) MappingConfig(com.alibaba.otter.canal.client.adapter.tablestore.config.MappingConfig) DefaultTableStoreWriter(com.alicloud.openservices.tablestore.DefaultTableStoreWriter)

Example 2 with DefaultCredentials

use of com.alicloud.openservices.tablestore.core.auth.DefaultCredentials in project canal by alibaba.

the class TablestoreAdapter method buildEtlWriter.

/**
 * 构造批量导入的writer
 * @param configuration
 * @param mappingConfig
 * @return
 */
private TableStoreWriter buildEtlWriter(OuterAdapterConfig configuration, MappingConfig mappingConfig) {
    Map<String, String> properties = configuration.getProperties();
    ServiceCredentials credentials = new DefaultCredentials(properties.get(PropertyConstants.TABLESTORE_ACCESSSECRETID), properties.get(PropertyConstants.TABLESTORE_ACCESSSECRETKEY));
    WriterConfig config = getWriterConfig(mappingConfig);
    config.setBucketCount(3);
    config.setAllowDuplicatedRowInBatchRequest(true);
    config.setConcurrency(8);
    config.setWriteMode(WriteMode.PARALLEL);
    TableStoreWriter writer = new DefaultTableStoreWriter(properties.get(PropertyConstants.TABLESTORE_ENDPOINT), credentials, properties.get(PropertyConstants.TABLESTORE_INSTANCENAME), mappingConfig.getDbMapping().getTargetTable(), config, null);
    return writer;
}
Also used : DefaultCredentials(com.alicloud.openservices.tablestore.core.auth.DefaultCredentials) DefaultTableStoreWriter(com.alicloud.openservices.tablestore.DefaultTableStoreWriter) TableStoreWriter(com.alicloud.openservices.tablestore.TableStoreWriter) ServiceCredentials(com.alicloud.openservices.tablestore.core.auth.ServiceCredentials) DefaultTableStoreWriter(com.alicloud.openservices.tablestore.DefaultTableStoreWriter) WriterConfig(com.alicloud.openservices.tablestore.writer.WriterConfig)

Aggregations

DefaultTableStoreWriter (com.alicloud.openservices.tablestore.DefaultTableStoreWriter)2 TableStoreWriter (com.alicloud.openservices.tablestore.TableStoreWriter)2 DefaultCredentials (com.alicloud.openservices.tablestore.core.auth.DefaultCredentials)2 ServiceCredentials (com.alicloud.openservices.tablestore.core.auth.ServiceCredentials)2 WriterConfig (com.alicloud.openservices.tablestore.writer.WriterConfig)2 MappingConfig (com.alibaba.otter.canal.client.adapter.tablestore.config.MappingConfig)1 TablestoreSyncService (com.alibaba.otter.canal.client.adapter.tablestore.service.TablestoreSyncService)1