m1a2st commented on code in PR #24247:
URL: https://github.com/apache/kafka/pull/24247#discussion_r4631052740
##########
tools/src/main/java/org/apache/kafka/tools/ConfigCommand.java:
##########
@@ -248,13 +250,21 @@ static void alterConfig(Admin adminClient,
ConfigCommandOptions opts) throws IOE
validateBrokerId(entityName, entityType);
}
configResourceType = ConfigResource.Type.BROKER;
- } else {
+ } else if (GROUP_TYPE.equals(entityType)) {
configResourceType = ConfigResource.Type.GROUP;
+ } else if (CLUSTER_MIRROR_TYPE.equals(entityType)) {
Review Comment:
`CLUSTER_MIRROR_TYPE.equals(entityType)` is always true here, so we can
simplify it by using `else` instead.
##########
tools/src/main/java/org/apache/kafka/tools/ConfigCommand.java:
##########
@@ -519,6 +529,8 @@ private static void describeResourceConfig(Admin
adminClient, String entityType,
System.out.println("The " + entityTypeSingular + " '"
+ name + "' doesn't exist and doesn't have dynamic config.");
return;
}
+ } else if (CLUSTER_MIRROR_TYPE.equals(entityType)) {
+ // cluster mirrors cannot be listed until KAFKA-21530, so
the existence check is skipped
Review Comment:
I think we should print a warning message here.
##########
tools/src/main/java/org/apache/kafka/tools/ConfigCommand.java:
##########
Review Comment:
Other entity types in `kafka-configs.sh` have shortcut flags. Should we add
a `--cluster-mirror <name>` shortcut for consistency?
KIP-1279 doesn't mention this option, so adding it would require updating
the KIP first.
@fvaleri, WDYT?
##########
tools/src/test/java/org/apache/kafka/tools/ConfigCommandTest.java:
##########
@@ -1295,6 +1303,119 @@ public synchronized AlterConfigsResult
incrementalAlterConfigs(Map<ConfigResourc
verify(alterResult).all();
}
+ @Test
+ public void shouldAlterClusterMirrorConfig() throws Exception {
+ ConfigCommand.ConfigCommandOptions alterOpts = new
ConfigCommand.ConfigCommandOptions(toArray("--bootstrap-server",
"localhost:9092",
+ "--entity-type", "cluster-mirrors",
+ "--entity-name", "mirror",
+ "--alter",
+ "--delete-config", "a",
+ "--add-config", "b=c"));
+ alterOpts.checkArgs();
+
+ KafkaFutureImpl<Void> alterFuture = new KafkaFutureImpl<>();
+ alterFuture.complete(null);
+ AlterConfigsResult alterResult = mock(AlterConfigsResult.class);
+ when(alterResult.all()).thenReturn(alterFuture);
+
+ Node node = new Node(1, "localhost", 9092);
+ MockAdminClient mockAdminClient = new MockAdminClient(List.of(node),
node) {
+ @Override
+ public synchronized AlterConfigsResult
incrementalAlterConfigs(Map<ConfigResource, Collection<AlterConfigOp>> configs,
AlterConfigsOptions options) {
+ assertEquals(Map.of(new
ConfigResource(ConfigResource.Type.CLUSTER_MIRROR, "mirror"), List.of(
+ new AlterConfigOp(new ConfigEntry("a", ""),
AlterConfigOp.OpType.DELETE),
+ new AlterConfigOp(new ConfigEntry("b", "c"),
AlterConfigOp.OpType.SET)
+ )), configs);
+ return alterResult;
+ }
+ };
+ ConfigCommand.alterConfig(mockAdminClient, alterOpts);
+ verify(alterResult).all();
+ }
+
+ @Test
+ public void
shouldPropagateUnsupportedVersionWhenAlteringClusterMirrorConfig() {
+ ConfigCommand.ConfigCommandOptions alterOpts = new
ConfigCommand.ConfigCommandOptions(toArray("--bootstrap-server",
"localhost:9092",
+ "--entity-type", "cluster-mirrors",
+ "--entity-name", "mirror",
+ "--alter",
+ "--add-config", "b=c"));
+
+ KafkaFutureImpl<Void> alterFuture = new KafkaFutureImpl<>();
+ alterFuture.completeExceptionally(new
UnsupportedVersionException("Cluster mirror configs are not supported yet."));
+ AlterConfigsResult alterResult = mock(AlterConfigsResult.class);
+ when(alterResult.all()).thenReturn(alterFuture);
+
+ Node node = new Node(1, "localhost", 9092);
+ MockAdminClient mockAdminClient = new MockAdminClient(List.of(node),
node) {
+ @Override
+ public synchronized AlterConfigsResult
incrementalAlterConfigs(Map<ConfigResource, Collection<AlterConfigOp>> configs,
AlterConfigsOptions options) {
+ return alterResult;
+ }
+ };
+ UnsupportedVersionException exception =
assertThrows(UnsupportedVersionException.class,
+ () -> ConfigCommand.alterConfig(mockAdminClient, alterOpts));
+ assertEquals("Cluster mirror configs are not supported yet.",
exception.getMessage());
+ }
+
+ @Test
+ public void shouldDescribeClusterMirrorConfig() {
+ ConfigCommand.ConfigCommandOptions describeOpts = new
ConfigCommand.ConfigCommandOptions(toArray("--bootstrap-server",
"localhost:9092",
+ "--entity-type", "cluster-mirrors",
+ "--entity-name", "mirror",
+ "--describe"));
+ describeOpts.checkArgs();
+
+ ConfigResource resource = new
ConfigResource(ConfigResource.Type.CLUSTER_MIRROR, "mirror");
+ KafkaFutureImpl<Config> future = new KafkaFutureImpl<>();
+ future.complete(new Config(List.of(
+ new ConfigEntry("a", "b",
ConfigEntry.ConfigSource.DYNAMIC_CLUSTER_MIRROR_CONFIG, false, false,
List.of(), ConfigEntry.ConfigType.STRING, null),
+ new ConfigEntry("c", "d", ConfigEntry.ConfigSource.DEFAULT_CONFIG,
false, false, List.of(), ConfigEntry.ConfigType.STRING, null))));
+ DescribeConfigsResult describeResult =
mock(DescribeConfigsResult.class);
+ when(describeResult.values()).thenReturn(Map.of(resource, future));
+
+ Node node = new Node(1, "localhost", 9092);
+ MockAdminClient mockAdminClient = new MockAdminClient(List.of(node),
node) {
+ @Override
+ public synchronized DescribeConfigsResult
describeConfigs(Collection<ConfigResource> resources, DescribeConfigsOptions
options) {
+ assertEquals(List.of(resource), List.copyOf(resources));
+ return describeResult;
+ }
+ };
+ String output = ToolsTestUtils.captureStandardOut(() -> {
+ try {
+ ConfigCommand.describeConfig(mockAdminClient, describeOpts);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ });
+ assertTrue(output.contains("Dynamic configs for cluster-mirror mirror
are:"), output);
+ assertTrue(output.contains("a=b"), output);
+ // without --all, only dynamic cluster mirror configs are shown
+ assertFalse(output.contains("c=d"), output);
+ }
+
+ @Test
+ public void shouldNotDescribeClusterMirrorConfigWithoutEntityName() {
+ ConfigCommand.ConfigCommandOptions describeOpts = new
ConfigCommand.ConfigCommandOptions(toArray("--bootstrap-server",
"localhost:9092",
+ "--entity-type", "cluster-mirrors",
+ "--describe"));
+
+ IllegalArgumentException exception =
assertThrows(IllegalArgumentException.class, describeOpts::checkArgs);
+ assertEquals("An entity name must be specified with --describe of
cluster-mirrors", exception.getMessage());
+ }
+
+ @Test
+ public void shouldNotAlterClusterMirrorConfigWithoutEntityName() {
+ ConfigCommand.ConfigCommandOptions alterOpts = new
ConfigCommand.ConfigCommandOptions(toArray("--bootstrap-server",
"localhost:9092",
+ "--entity-type", "cluster-mirrors",
+ "--alter",
+ "--add-config", "a=b"));
+
+ IllegalArgumentException exception =
assertThrows(IllegalArgumentException.class, alterOpts::checkArgs);
+ assertEquals("An entity name must be specified with --alter of
cluster-mirrors", exception.getMessage());
+ }
+
Review Comment:
Could we add a test for `--entity-default`, too? `--alter --entity-type
cluster-mirrors --entity-default` is rejected today
##########
tools/src/main/java/org/apache/kafka/tools/ConfigCommand.java:
##########
Review Comment:
```
* This script can be used to change configs for
topics/clients/users/brokers/ips/client-metrics/groups/cluster-mirrors
dynamically
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]