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));
}
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());
}
}
}
Aggregations