Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.kafka.connect.runtime;

import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.KafkaProducer;
Expand Down Expand Up @@ -607,8 +608,21 @@ static Map<String, Object> adminConfigs(ConnectorTaskId id,
Class<? extends Connector> connectorClass,
ConnectorClientConfigOverridePolicy connectorClientConfigOverridePolicy) {
Map<String, Object> adminProps = new HashMap<>();
adminProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, Utils.join(config.getList(WorkerConfig.BOOTSTRAP_SERVERS_CONFIG), ","));
// User-specified overrides
// Use the top-level worker configs to retain backwards compatibility with older releases which
// did not require a prefix for connector admin client configs in the worker configuration file
// Ignore configs that begin with "admin." since those will be added next (with the prefix stripped)
// and those that begin with "producer." and "consumer.", since we know they aren't intended for
// the admin client
Map<String, Object> nonPrefixedWorkerConfigs = config.originals().entrySet().stream()
.filter(e -> !e.getKey().startsWith("admin.")
&& !e.getKey().startsWith("producer.")
&& !e.getKey().startsWith("consumer."))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
adminProps.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,
Utils.join(config.getList(WorkerConfig.BOOTSTRAP_SERVERS_CONFIG), ","));
adminProps.putAll(nonPrefixedWorkerConfigs);

// Admin client-specific overrides in the worker config
Comment thread
C0urante marked this conversation as resolved.
adminProps.putAll(config.originalsWithPrefix("admin."));

// Connector-specified overrides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,12 +1138,15 @@ public void testAdminConfigsClientOverridesWithAllPolicy() {
Map<String, String> props = new HashMap<>(workerProps);
props.put("admin.client.id", "testid");
props.put("admin.metadata.max.age.ms", "5000");
props.put("producer.bootstrap.servers", "cbeauho.com");
props.put("consumer.bootstrap.servers", "localhost:4761");
WorkerConfig configWithOverrides = new StandaloneConfig(props);

Map<String, Object> connConfig = new HashMap<String, Object>();
connConfig.put("metadata.max.age.ms", "10000");

Map<String, String> expectedConfigs = new HashMap<>();
Map<String, String> expectedConfigs = new HashMap<>(workerProps);

expectedConfigs.put("bootstrap.servers", "localhost:9092");
expectedConfigs.put("client.id", "testid");
expectedConfigs.put("metadata.max.age.ms", "10000");
Expand All @@ -1153,7 +1156,6 @@ public void testAdminConfigsClientOverridesWithAllPolicy() {
PowerMock.replayAll();
assertEquals(expectedConfigs, Worker.adminConfigs(new ConnectorTaskId("test", 1), configWithOverrides, connectorConfig,
null, allConnectorClientConfigOverridePolicy));

}

@Test(expected = ConnectException.class)
Expand All @@ -1171,7 +1173,6 @@ public void testAdminConfigsClientOverridesWithNonePolicy() {
PowerMock.replayAll();
Worker.adminConfigs(new ConnectorTaskId("test", 1), configWithOverrides, connectorConfig,
null, noneConnectorClientConfigOverridePolicy);

}

private void assertStatusMetrics(long expected, String metricName) {
Expand Down