Search in sources :

Example 1 with DynamicConfigProvider

use of org.apache.druid.metadata.DynamicConfigProvider in project druid by druid-io.

the class KafkaRecordSupplierTest method testAddConsumerPropertiesFromConfig.

@Test
public void testAddConsumerPropertiesFromConfig() {
    DynamicConfigProvider dynamicConfigProvider = new MapStringDynamicConfigProvider(ImmutableMap.of("kafka.prop.2", "value.2", KafkaSupervisorIOConfig.TRUST_STORE_PASSWORD_KEY, "pwd2"));
    Properties properties = new Properties();
    Map<String, Object> consumerProperties = ImmutableMap.of(KafkaSupervisorIOConfig.TRUST_STORE_PASSWORD_KEY, "pwd1", "kafka.prop.1", "value.1", "druid.dynamic.config.provider", OBJECT_MAPPER.convertValue(dynamicConfigProvider, Map.class));
    KafkaRecordSupplier.addConsumerPropertiesFromConfig(properties, OBJECT_MAPPER, consumerProperties);
    Assert.assertEquals(3, properties.size());
    Assert.assertEquals("value.1", properties.getProperty("kafka.prop.1"));
    Assert.assertEquals("value.2", properties.getProperty("kafka.prop.2"));
    Assert.assertEquals("pwd2", properties.getProperty(KafkaSupervisorIOConfig.TRUST_STORE_PASSWORD_KEY));
}
Also used : MapStringDynamicConfigProvider(org.apache.druid.metadata.MapStringDynamicConfigProvider) DynamicConfigProvider(org.apache.druid.metadata.DynamicConfigProvider) MapStringDynamicConfigProvider(org.apache.druid.metadata.MapStringDynamicConfigProvider) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 2 with DynamicConfigProvider

use of org.apache.druid.metadata.DynamicConfigProvider in project druid by druid-io.

the class KafkaRecordSupplier method addConsumerPropertiesFromConfig.

public static void addConsumerPropertiesFromConfig(Properties properties, ObjectMapper configMapper, Map<String, Object> consumerProperties) {
    // Extract passwords before SSL connection to Kafka
    for (Map.Entry<String, Object> entry : consumerProperties.entrySet()) {
        String propertyKey = entry.getKey();
        if (!KafkaSupervisorIOConfig.DRUID_DYNAMIC_CONFIG_PROVIDER_KEY.equals(propertyKey)) {
            if (propertyKey.equals(KafkaSupervisorIOConfig.TRUST_STORE_PASSWORD_KEY) || propertyKey.equals(KafkaSupervisorIOConfig.KEY_STORE_PASSWORD_KEY) || propertyKey.equals(KafkaSupervisorIOConfig.KEY_PASSWORD_KEY)) {
                PasswordProvider configPasswordProvider = configMapper.convertValue(entry.getValue(), PasswordProvider.class);
                properties.setProperty(propertyKey, configPasswordProvider.getPassword());
            } else {
                properties.setProperty(propertyKey, String.valueOf(entry.getValue()));
            }
        }
    }
    // Additional DynamicConfigProvider based extensible support for all consumer properties
    Object dynamicConfigProviderJson = consumerProperties.get(KafkaSupervisorIOConfig.DRUID_DYNAMIC_CONFIG_PROVIDER_KEY);
    if (dynamicConfigProviderJson != null) {
        DynamicConfigProvider dynamicConfigProvider = configMapper.convertValue(dynamicConfigProviderJson, DynamicConfigProvider.class);
        Map<String, String> dynamicConfig = dynamicConfigProvider.getConfig();
        for (Map.Entry<String, String> e : dynamicConfig.entrySet()) {
            properties.setProperty(e.getKey(), e.getValue());
        }
    }
}
Also used : DynamicConfigProvider(org.apache.druid.metadata.DynamicConfigProvider) Map(java.util.Map) PasswordProvider(org.apache.druid.metadata.PasswordProvider)

Aggregations

Map (java.util.Map)2 DynamicConfigProvider (org.apache.druid.metadata.DynamicConfigProvider)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 MapStringDynamicConfigProvider (org.apache.druid.metadata.MapStringDynamicConfigProvider)1 PasswordProvider (org.apache.druid.metadata.PasswordProvider)1 Test (org.junit.Test)1