rpuch commented on code in PR #3668: URL: https://github.com/apache/ignite-3/pull/3668#discussion_r1582686383
########## modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/recovery/ItPartitionStatesTest.java: ########## @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.recovery; + +import static java.util.stream.Collectors.toSet; +import static org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_AIPERSIST_PROFILE_NAME; +import static org.apache.ignite.internal.cli.commands.Options.Constants.CLUSTER_URL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_LOCAL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_NODE_NAMES_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_GLOBAL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_IDS_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_ZONE_NAMES_OPTION; + +import java.util.Set; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.cli.CliIntegrationTest; +import org.apache.ignite.internal.util.CollectionUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +public class ItPartitionStatesTest extends CliIntegrationTest { + private static final int DEFAULT_PARTITION_COUNT = 25; + + private static final Set<String> FILLED_ZONES = Set.of("first_zone", "second_zone", "third_zone"); + + private static final Set<String> TABLE_NAMES = FILLED_ZONES.stream().map(it -> it + "_table").collect(toSet()); + + private static final Set<String> STATES = Set.of("HEALTHY", "AVAILABLE"); + + private static Set<String> nodeNames; + + @BeforeAll + public static void createTables() { + FILLED_ZONES.forEach(name -> { + sql(String.format("CREATE ZONE %s WITH storage_profiles='%s'", name, DEFAULT_AIPERSIST_PROFILE_NAME)); + sql("CREATE TABLE " + name + "_table (id INT PRIMARY KEY, val INT) WITH PRIMARY_ZONE = '" + name.toUpperCase() + "'"); + }); + + sql("CREATE ZONE empty_zone WITH storage_profiles='" + DEFAULT_AIPERSIST_PROFILE_NAME + "'"); + + nodeNames = CLUSTER.runningNodes().map(IgniteImpl::name).collect(toSet()); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStates(boolean global) { + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + for (int i = 0; i < DEFAULT_PARTITION_COUNT; i++) { + assertOutputContains(String.valueOf(i)); + } + + checkOutput(global, FILLED_ZONES, TABLE_NAMES, nodeNames); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesByZones(boolean global) { + Set<String> zoneNames = FILLED_ZONES.stream().sorted().limit(2).collect(toSet()); + Set<String> tableNames = TABLE_NAMES.stream().sorted().limit(2).collect(toSet()); + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, String.join(",", zoneNames), + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + assertOutputContains("Table name"); + assertOutputContains("Partition ID"); + assertOutputContains("State"); + + for (int i = 0; i < DEFAULT_PARTITION_COUNT; i++) { + assertOutputContains(String.valueOf(i)); + } + + checkOutput(global, zoneNames, tableNames, nodeNames); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingZone(boolean global) { + String unknownZone = "UNKNOWN_ZONE"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, unknownZone, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + assertErrOutputContains("Some distribution zones are missing: [UNKNOWN_ZONE]"); + + assertOutputIsEmpty(); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingPartition(boolean global) { + String unknownPartition = "-1"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_PARTITION_IDS_OPTION, unknownPartition, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION); + + assertErrOutputContains("Some partitions are missing: [-1]"); + + assertOutputIsEmpty(); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingNode() { + String unknownNode = "unknown_node"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_NODE_NAMES_OPTION, unknownNode, + RECOVERY_LOCAL_OPTION); + + assertErrOutputContains("Some nodes are missing: [UNKNOWN_NODE]"); + + assertOutputIsEmpty(); + } + + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesEmptyResult(boolean global) { + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, "empty_zone", + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + checkOutput(global, Set.of(), Set.of(), Set.of()); + } + + private void checkOutput(boolean global, Set<String> zoneNames, Set<String> tableNames, Set<String> nodes) { Review Comment: The checks that this method does are too local. For example, if the output breaks for some reason and headers are output in the middle, the test will still pass. I suggest to make the checks more strict, probably parse the output and compare it to what we expect. ########## modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/recovery/ItPartitionStatesTest.java: ########## @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.recovery; + +import static java.util.stream.Collectors.toSet; +import static org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_AIPERSIST_PROFILE_NAME; +import static org.apache.ignite.internal.cli.commands.Options.Constants.CLUSTER_URL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_LOCAL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_NODE_NAMES_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_GLOBAL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_IDS_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_ZONE_NAMES_OPTION; + +import java.util.Set; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.cli.CliIntegrationTest; +import org.apache.ignite.internal.util.CollectionUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +public class ItPartitionStatesTest extends CliIntegrationTest { + private static final int DEFAULT_PARTITION_COUNT = 25; + + private static final Set<String> FILLED_ZONES = Set.of("first_zone", "second_zone", "third_zone"); + + private static final Set<String> TABLE_NAMES = FILLED_ZONES.stream().map(it -> it + "_table").collect(toSet()); + + private static final Set<String> STATES = Set.of("HEALTHY", "AVAILABLE"); + + private static Set<String> nodeNames; + + @BeforeAll + public static void createTables() { + FILLED_ZONES.forEach(name -> { + sql(String.format("CREATE ZONE %s WITH storage_profiles='%s'", name, DEFAULT_AIPERSIST_PROFILE_NAME)); + sql("CREATE TABLE " + name + "_table (id INT PRIMARY KEY, val INT) WITH PRIMARY_ZONE = '" + name.toUpperCase() + "'"); + }); + + sql("CREATE ZONE empty_zone WITH storage_profiles='" + DEFAULT_AIPERSIST_PROFILE_NAME + "'"); + + nodeNames = CLUSTER.runningNodes().map(IgniteImpl::name).collect(toSet()); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStates(boolean global) { + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + for (int i = 0; i < DEFAULT_PARTITION_COUNT; i++) { + assertOutputContains(String.valueOf(i)); + } + + checkOutput(global, FILLED_ZONES, TABLE_NAMES, nodeNames); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesByZones(boolean global) { + Set<String> zoneNames = FILLED_ZONES.stream().sorted().limit(2).collect(toSet()); + Set<String> tableNames = TABLE_NAMES.stream().sorted().limit(2).collect(toSet()); + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, String.join(",", zoneNames), + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + assertOutputContains("Table name"); + assertOutputContains("Partition ID"); + assertOutputContains("State"); + + for (int i = 0; i < DEFAULT_PARTITION_COUNT; i++) { + assertOutputContains(String.valueOf(i)); + } + + checkOutput(global, zoneNames, tableNames, nodeNames); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingZone(boolean global) { + String unknownZone = "UNKNOWN_ZONE"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, unknownZone, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + assertErrOutputContains("Some distribution zones are missing: [UNKNOWN_ZONE]"); + + assertOutputIsEmpty(); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingPartition(boolean global) { + String unknownPartition = "-1"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_PARTITION_IDS_OPTION, unknownPartition, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION); + + assertErrOutputContains("Some partitions are missing: [-1]"); + + assertOutputIsEmpty(); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingNode() { + String unknownNode = "unknown_node"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_NODE_NAMES_OPTION, unknownNode, + RECOVERY_LOCAL_OPTION); + + assertErrOutputContains("Some nodes are missing: [UNKNOWN_NODE]"); + + assertOutputIsEmpty(); + } + + Review Comment: Extra line ########## modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/recovery/ItPartitionStatesTest.java: ########## @@ -0,0 +1,211 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.recovery; + +import static java.util.stream.Collectors.toSet; +import static org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_AIPERSIST_PROFILE_NAME; +import static org.apache.ignite.internal.cli.commands.Options.Constants.CLUSTER_URL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_LOCAL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_NODE_NAMES_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_GLOBAL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_IDS_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_ZONE_NAMES_OPTION; + +import java.util.HashSet; +import java.util.Set; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.cli.CliIntegrationTest; +import org.apache.ignite.internal.util.CollectionUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +public class ItPartitionStatesTest extends CliIntegrationTest { + private static final int DEFAULT_PARTITION_COUNT = 25; + + private static final Set<String> ZONES = Set.of("first_zone", "second_zone", "third_zone"); + + private static final Set<String> MIXED_ZONES = Set.of("mixed_case_zone", "MIXED_CASE_ZONE"); Review Comment: ```suggestion private static final Set<String> MIXED_CASE_ZONES = Set.of("mixed_case_zone", "MIXED_CASE_ZONE"); ``` ########## modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/recovery/ItPartitionStatesTest.java: ########## @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.recovery; + +import static java.util.stream.Collectors.toSet; +import static org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_AIPERSIST_PROFILE_NAME; +import static org.apache.ignite.internal.cli.commands.Options.Constants.CLUSTER_URL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_LOCAL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_NODE_NAMES_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_GLOBAL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_IDS_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_ZONE_NAMES_OPTION; + +import java.util.Set; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.cli.CliIntegrationTest; +import org.apache.ignite.internal.util.CollectionUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +public class ItPartitionStatesTest extends CliIntegrationTest { + private static final int DEFAULT_PARTITION_COUNT = 25; + + private static final Set<String> FILLED_ZONES = Set.of("first_zone", "second_zone", "third_zone"); + + private static final Set<String> TABLE_NAMES = FILLED_ZONES.stream().map(it -> it + "_table").collect(toSet()); + + private static final Set<String> STATES = Set.of("HEALTHY", "AVAILABLE"); + + private static Set<String> nodeNames; + + @BeforeAll + public static void createTables() { + FILLED_ZONES.forEach(name -> { + sql(String.format("CREATE ZONE %s WITH storage_profiles='%s'", name, DEFAULT_AIPERSIST_PROFILE_NAME)); + sql("CREATE TABLE " + name + "_table (id INT PRIMARY KEY, val INT) WITH PRIMARY_ZONE = '" + name.toUpperCase() + "'"); + }); + + sql("CREATE ZONE empty_zone WITH storage_profiles='" + DEFAULT_AIPERSIST_PROFILE_NAME + "'"); + + nodeNames = CLUSTER.runningNodes().map(IgniteImpl::name).collect(toSet()); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStates(boolean global) { + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + for (int i = 0; i < DEFAULT_PARTITION_COUNT; i++) { + assertOutputContains(String.valueOf(i)); + } + + checkOutput(global, FILLED_ZONES, TABLE_NAMES, nodeNames); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesByZones(boolean global) { + Set<String> zoneNames = FILLED_ZONES.stream().sorted().limit(2).collect(toSet()); + Set<String> tableNames = TABLE_NAMES.stream().sorted().limit(2).collect(toSet()); + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, String.join(",", zoneNames), + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + assertOutputContains("Table name"); + assertOutputContains("Partition ID"); + assertOutputContains("State"); + + for (int i = 0; i < DEFAULT_PARTITION_COUNT; i++) { + assertOutputContains(String.valueOf(i)); + } + + checkOutput(global, zoneNames, tableNames, nodeNames); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingZone(boolean global) { + String unknownZone = "UNKNOWN_ZONE"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, unknownZone, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + assertErrOutputContains("Some distribution zones are missing: [UNKNOWN_ZONE]"); + + assertOutputIsEmpty(); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingPartition(boolean global) { + String unknownPartition = "-1"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_PARTITION_IDS_OPTION, unknownPartition, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION); + + assertErrOutputContains("Some partitions are missing: [-1]"); + + assertOutputIsEmpty(); + } + + @ParameterizedTest Review Comment: The test does not seem to be actually parameterized ########## modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/RecoveryReplCommand.java: ########## @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.recovery; + +import org.apache.ignite.internal.cli.commands.BaseCommand; +import org.apache.ignite.internal.cli.commands.recovery.partitions.PartitionStatesReplCommand; +import picocli.CommandLine.Command; + +/** Recovery command. */ Review Comment: Please elaborate that it's about *disaster* recovery ########## modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/RecoveryCommand.java: ########## @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.recovery; + +import org.apache.ignite.internal.cli.commands.BaseCommand; +import org.apache.ignite.internal.cli.commands.recovery.partitions.PartitionStatesCommand; +import picocli.CommandLine.Command; + +/** Recovery command. */ Review Comment: Please elaborate that it's about *disaster* recovery ########## modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/RecoveryCommand.java: ########## @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.recovery; + +import org.apache.ignite.internal.cli.commands.BaseCommand; +import org.apache.ignite.internal.cli.commands.recovery.partitions.PartitionStatesCommand; +import picocli.CommandLine.Command; + +/** Recovery command. */ +@Command(name = "recovery", + subcommands = { + PartitionStatesCommand.class + }, + description = "Managers recovery of Ignite cluster") Review Comment: ```suggestion description = "Manages disaster recovery of Ignite cluster") ``` ########## modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/RecoveryReplCommand.java: ########## @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.recovery; + +import org.apache.ignite.internal.cli.commands.BaseCommand; +import org.apache.ignite.internal.cli.commands.recovery.partitions.PartitionStatesReplCommand; +import picocli.CommandLine.Command; + +/** Recovery command. */ +@Command(name = "recovery", + subcommands = { + PartitionStatesReplCommand.class + }, + description = "Managers recovery of Ignite cluster") Review Comment: ```suggestion description = "Manages disaster recovery of Ignite cluster") ``` ########## modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/PartitionStatesCall.java: ########## @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.call.recovery; + +import static java.util.stream.Collectors.toList; + +import jakarta.inject.Singleton; +import java.util.List; +import java.util.stream.Stream; +import org.apache.ignite.internal.cli.core.call.Call; +import org.apache.ignite.internal.cli.core.call.DefaultCallOutput; +import org.apache.ignite.internal.cli.core.exception.IgniteCliApiException; +import org.apache.ignite.internal.cli.core.rest.ApiClientFactory; +import org.apache.ignite.internal.cli.sql.table.Table; +import org.apache.ignite.rest.client.api.RecoveryApi; +import org.apache.ignite.rest.client.invoker.ApiException; +import org.apache.ignite.rest.client.model.GlobalPartitionStatesResponse; +import org.apache.ignite.rest.client.model.LocalPartitionStatesResponse; + +/** Call to get partition states. */ +@Singleton +public class PartitionStatesCall implements Call<PartitionStatesCallInput, Table> { + private final ApiClientFactory clientFactory; + + private static final List<String> GLOBAL_HEADERS = List.of("Zone name", "Table name", "Partition ID", "State"); + + private static final List<String> LOCAL_HEADERS = Stream + .concat(Stream.of("Node name"), GLOBAL_HEADERS.stream()) + .collect(toList()); + + public PartitionStatesCall(ApiClientFactory clientFactory) { + this.clientFactory = clientFactory; + } + + @Override + public DefaultCallOutput<Table> execute(PartitionStatesCallInput input) { + RecoveryApi client = new RecoveryApi(clientFactory.getClient(input.clusterUrl())); + + List<String> trimmedZoneNames = trim(input.zoneNames()); + List<String> trimmedNodeNames = trim(input.nodeNames()); + + try { + if (input.local()) { + LocalPartitionStatesResponse localStates = client.getLocalPartitionStates( Review Comment: I suggest extracting both branches of this `if` as methods: one for handling local case, another for handling global case ########## modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/PartitionStatesCallInput.java: ########## @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.call.recovery; + +import java.util.List; +import org.apache.ignite.internal.cli.core.call.CallInput; + +/** Input for the {@link PartitionStatesCall} call. */ +public class PartitionStatesCallInput implements CallInput { + private final String clusterUrl; + + private final boolean local; + + private final List<String> nodeNames; + + private final List<String> zoneNames; + + private final List<Integer> partitionIds; + + /** Cluster url. */ + public String clusterUrl() { + return clusterUrl; + } + + /** If local partition states should be returned. */ + public boolean local() { + return local; + } + + /** Returns node names to get partition states from. */ Review Comment: ```suggestion /** Returns node names to get local partition states from. */ ``` ########## modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/ClusterReplCommand.java: ########## @@ -34,7 +35,8 @@ ClusterInitReplCommand.class, ClusterStatusReplCommand.class, TopologyReplCommand.class, - ClusterUnitReplCommand.class + ClusterUnitReplCommand.class, + PartitionStatesReplCommand.class Review Comment: Is it correct that `PartitionStatesReplCommand` is defined both here and in `RecoveryReplCommand`? ########## modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/PartitionStatesCallInput.java: ########## @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.call.recovery; + +import java.util.List; +import org.apache.ignite.internal.cli.core.call.CallInput; + +/** Input for the {@link PartitionStatesCall} call. */ +public class PartitionStatesCallInput implements CallInput { + private final String clusterUrl; + + private final boolean local; + + private final List<String> nodeNames; + + private final List<String> zoneNames; + + private final List<Integer> partitionIds; + + /** Cluster url. */ + public String clusterUrl() { + return clusterUrl; + } + + /** If local partition states should be returned. */ + public boolean local() { + return local; + } + + /** Returns node names to get partition states from. */ + public List<String> nodeNames() { + return nodeNames; + } + + /** Names of zones to get partition states of. */ + public List<String> zoneNames() { + return zoneNames; + } + + /** IDs of partitions to get states of. */ + public List<Integer> partitionIds() { + return partitionIds; + } + + PartitionStatesCallInput( + String clusterUrl, + boolean local, + List<String> nodeNames, + List<String> zoneNames, + List<Integer> partitionIds + ) { + this.clusterUrl = clusterUrl; + this.local = local; + this.nodeNames = nodeNames; + this.zoneNames = zoneNames; + this.partitionIds = partitionIds; Review Comment: I suggest making defensive copies ########## modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/recovery/ItPartitionStatesTest.java: ########## @@ -0,0 +1,211 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.recovery; + +import static java.util.stream.Collectors.toSet; +import static org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_AIPERSIST_PROFILE_NAME; +import static org.apache.ignite.internal.cli.commands.Options.Constants.CLUSTER_URL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_LOCAL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_NODE_NAMES_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_GLOBAL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_IDS_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_ZONE_NAMES_OPTION; + +import java.util.HashSet; +import java.util.Set; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.cli.CliIntegrationTest; +import org.apache.ignite.internal.util.CollectionUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +public class ItPartitionStatesTest extends CliIntegrationTest { + private static final int DEFAULT_PARTITION_COUNT = 25; + + private static final Set<String> ZONES = Set.of("first_zone", "second_zone", "third_zone"); + + private static final Set<String> MIXED_ZONES = Set.of("mixed_case_zone", "MIXED_CASE_ZONE"); + + private static final Set<String> ALL_ZONES = new HashSet<>(CollectionUtils.concat(ZONES, MIXED_ZONES)); + + private static final Set<String> STATES = Set.of("HEALTHY", "AVAILABLE"); + + private static Set<String> nodeNames; + + @BeforeAll + public static void createTables() { + ALL_ZONES.forEach(name -> { + sql(String.format("CREATE ZONE \"%s\" WITH storage_profiles='%s'", name, DEFAULT_AIPERSIST_PROFILE_NAME)); + sql("CREATE TABLE \"" + name + "_table\" (id INT PRIMARY KEY, val INT) WITH PRIMARY_ZONE = '" + name + "'"); + }); + + sql("CREATE ZONE \"empty_zone\" WITH storage_profiles='" + DEFAULT_AIPERSIST_PROFILE_NAME + "'"); + + nodeNames = CLUSTER.runningNodes().map(IgniteImpl::name).collect(toSet()); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStates(boolean global) { + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + for (int i = 0; i < DEFAULT_PARTITION_COUNT; i++) { + assertOutputContains(String.valueOf(i)); + } + + checkOutput(global, ALL_ZONES, nodeNames); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesByZones(boolean global) { + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, String.join(",", ZONES), + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + assertOutputContains("Table name"); + assertOutputContains("Partition ID"); + assertOutputContains("State"); + + for (int i = 0; i < DEFAULT_PARTITION_COUNT; i++) { + assertOutputContains(String.valueOf(i)); + } + + checkOutput(global, ZONES, nodeNames); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesZonesMixedCase(boolean global) { + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, String.join(",", MIXED_ZONES), + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + checkOutput(global, MIXED_ZONES, nodeNames); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingZone(boolean global) { + String unknownZone = "UNKNOWN_ZONE"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, unknownZone, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + assertErrOutputContains("Some distribution zones are missing: [UNKNOWN_ZONE]"); + + assertOutputIsEmpty(); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingPartition(boolean global) { + String unknownPartition = "-1"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_PARTITION_IDS_OPTION, unknownPartition, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION); + + assertErrOutputContains("Some partitions are missing: [-1]"); + + assertOutputIsEmpty(); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingNode() { + String unknownNode = "unknown_node"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_NODE_NAMES_OPTION, unknownNode, + RECOVERY_LOCAL_OPTION); + + assertErrOutputContains("Some nodes are missing: [unknown_node]"); + + assertOutputIsEmpty(); + } + + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesEmptyResult(boolean global) { + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, "empty_zone", + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + checkOutput(global, Set.of(), Set.of()); + } + + private void checkOutput(boolean global, Set<String> zoneNames, Set<String> nodes) { + assertErrOutputIsEmpty(); + + if (global) { + assertOutputDoesNotContain("Node name"); + } else { + assertOutputContains("Node name"); + + if (!nodes.isEmpty()) { + assertOutputContainsAnyIgnoringCase(nodes); + } + + Set<String> anotherNodes = CollectionUtils.difference(nodeNames, nodes); + + if (!anotherNodes.isEmpty()) { + assertOutputDoesNotContainIgnoreCase(anotherNodes); + } + } + + assertOutputContains("Zone name"); + assertOutputContains("Table name"); + assertOutputContains("Partition ID"); + assertOutputContains("State"); + + if (!zoneNames.isEmpty()) { + assertOutputContainsAllIgnoringCase(zoneNames); + + Set<String> tableNames = zoneNames.stream().map(it -> it + "_table").collect(toSet()); + + assertOutputContainsAllIgnoringCase(tableNames); + } + + Set<String> anotherZones = CollectionUtils.difference(ZONES, zoneNames); + + if (!anotherZones.isEmpty()) { + assertOutputDoesNotContainIgnoreCase(anotherZones); + } + + if (!zoneNames.isEmpty() && nodeNames.isEmpty()) { + assertOutputContainsAnyIgnoringCase(STATES); + } + } Review Comment: Is there a test for a situation when we specify partition IDs explicitly (that would check that we only get results for the requested partition IDs)? Same for filtering on node names ########## modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/recovery/ItPartitionStatesTest.java: ########## @@ -0,0 +1,211 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.recovery; + +import static java.util.stream.Collectors.toSet; +import static org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_AIPERSIST_PROFILE_NAME; +import static org.apache.ignite.internal.cli.commands.Options.Constants.CLUSTER_URL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_LOCAL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_NODE_NAMES_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_GLOBAL_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_IDS_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_ZONE_NAMES_OPTION; + +import java.util.HashSet; +import java.util.Set; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.cli.CliIntegrationTest; +import org.apache.ignite.internal.util.CollectionUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +public class ItPartitionStatesTest extends CliIntegrationTest { + private static final int DEFAULT_PARTITION_COUNT = 25; + + private static final Set<String> ZONES = Set.of("first_zone", "second_zone", "third_zone"); + + private static final Set<String> MIXED_ZONES = Set.of("mixed_case_zone", "MIXED_CASE_ZONE"); + + private static final Set<String> ALL_ZONES = new HashSet<>(CollectionUtils.concat(ZONES, MIXED_ZONES)); + + private static final Set<String> STATES = Set.of("HEALTHY", "AVAILABLE"); + + private static Set<String> nodeNames; + + @BeforeAll + public static void createTables() { + ALL_ZONES.forEach(name -> { + sql(String.format("CREATE ZONE \"%s\" WITH storage_profiles='%s'", name, DEFAULT_AIPERSIST_PROFILE_NAME)); + sql("CREATE TABLE \"" + name + "_table\" (id INT PRIMARY KEY, val INT) WITH PRIMARY_ZONE = '" + name + "'"); + }); + + sql("CREATE ZONE \"empty_zone\" WITH storage_profiles='" + DEFAULT_AIPERSIST_PROFILE_NAME + "'"); + + nodeNames = CLUSTER.runningNodes().map(IgniteImpl::name).collect(toSet()); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStates(boolean global) { + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + for (int i = 0; i < DEFAULT_PARTITION_COUNT; i++) { + assertOutputContains(String.valueOf(i)); + } + + checkOutput(global, ALL_ZONES, nodeNames); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesByZones(boolean global) { + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, String.join(",", ZONES), + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + assertOutputContains("Table name"); + assertOutputContains("Partition ID"); + assertOutputContains("State"); + + for (int i = 0; i < DEFAULT_PARTITION_COUNT; i++) { + assertOutputContains(String.valueOf(i)); + } + + checkOutput(global, ZONES, nodeNames); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesZonesMixedCase(boolean global) { + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, String.join(",", MIXED_ZONES), + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + checkOutput(global, MIXED_ZONES, nodeNames); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingZone(boolean global) { + String unknownZone = "UNKNOWN_ZONE"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, unknownZone, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + assertErrOutputContains("Some distribution zones are missing: [UNKNOWN_ZONE]"); + + assertOutputIsEmpty(); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingPartition(boolean global) { + String unknownPartition = "-1"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_PARTITION_IDS_OPTION, unknownPartition, + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION); + + assertErrOutputContains("Some partitions are missing: [-1]"); + + assertOutputIsEmpty(); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesMissingNode() { + String unknownNode = "unknown_node"; + + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_NODE_NAMES_OPTION, unknownNode, + RECOVERY_LOCAL_OPTION); + + assertErrOutputContains("Some nodes are missing: [unknown_node]"); + + assertOutputIsEmpty(); + } + + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testPartitionStatesEmptyResult(boolean global) { + execute("recovery", "partition-states", + CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_ZONE_NAMES_OPTION, "empty_zone", + global ? RECOVERY_PARTITION_GLOBAL_OPTION : RECOVERY_LOCAL_OPTION + ); + + checkOutput(global, Set.of(), Set.of()); + } + + private void checkOutput(boolean global, Set<String> zoneNames, Set<String> nodes) { + assertErrOutputIsEmpty(); + + if (global) { + assertOutputDoesNotContain("Node name"); + } else { + assertOutputContains("Node name"); + + if (!nodes.isEmpty()) { + assertOutputContainsAnyIgnoringCase(nodes); + } + + Set<String> anotherNodes = CollectionUtils.difference(nodeNames, nodes); + + if (!anotherNodes.isEmpty()) { + assertOutputDoesNotContainIgnoreCase(anotherNodes); + } + } + + assertOutputContains("Zone name"); + assertOutputContains("Table name"); + assertOutputContains("Partition ID"); + assertOutputContains("State"); + + if (!zoneNames.isEmpty()) { + assertOutputContainsAllIgnoringCase(zoneNames); + + Set<String> tableNames = zoneNames.stream().map(it -> it + "_table").collect(toSet()); + + assertOutputContainsAllIgnoringCase(tableNames); + } + + Set<String> anotherZones = CollectionUtils.difference(ZONES, zoneNames); + + if (!anotherZones.isEmpty()) { + assertOutputDoesNotContainIgnoreCase(anotherZones); + } + + if (!zoneNames.isEmpty() && nodeNames.isEmpty()) { + assertOutputContainsAnyIgnoringCase(STATES); + } + } +} Review Comment: Is there any test for REPL functionality? ########## modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/PartitionStatesCommand.java: ########## @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.recovery.partitions; + +import static org.apache.ignite.internal.cli.commands.Options.Constants.PLAIN_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.PLAIN_OPTION_DESC; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_IDS_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_IDS_OPTION_DESC; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_ZONE_NAMES_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_ZONE_NAMES_OPTION_DESC; + +import jakarta.inject.Inject; +import java.util.List; +import java.util.concurrent.Callable; +import org.apache.ignite.internal.cli.call.recovery.PartitionStatesCall; +import org.apache.ignite.internal.cli.call.recovery.PartitionStatesCallInput; +import org.apache.ignite.internal.cli.commands.BaseCommand; +import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlMixin; +import org.apache.ignite.internal.cli.core.call.CallExecutionPipeline; +import org.apache.ignite.internal.cli.decorators.TableDecorator; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Mixin; +import picocli.CommandLine.Option; + +/** Command to get partition states. */ +@Command(name = "partition-states", description = "Returns partition states.") +public class PartitionStatesCommand extends BaseCommand implements Callable<Integer> { + /** Cluster endpoint URL option. */ + @Mixin + private ClusterUrlMixin clusterUrl; + + /** Specific local / global states filters. */ + @ArgGroup(exclusive = true, multiplicity = "1") + private PartitionStatesArgGroup statesArgs; + + /** IDs of partitions to get states of. */ + @Option(names = RECOVERY_PARTITION_IDS_OPTION, description = RECOVERY_PARTITION_IDS_OPTION_DESC, split = ",") + private List<Integer> partitionIds; + + /** Names of zones to get partition states of. */ + @Option(names = RECOVERY_ZONE_NAMES_OPTION, description = RECOVERY_ZONE_NAMES_OPTION_DESC, split = ",") + private List<String> zoneNames; Review Comment: Is it possible to extract these as new class and use them as a mixin both here and in the REPL command, to avoid duplication? ########## modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/PartitionStatesCommand.java: ########## @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.recovery.partitions; + +import static org.apache.ignite.internal.cli.commands.Options.Constants.PLAIN_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.PLAIN_OPTION_DESC; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_IDS_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_PARTITION_IDS_OPTION_DESC; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_ZONE_NAMES_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_ZONE_NAMES_OPTION_DESC; + +import jakarta.inject.Inject; +import java.util.List; +import java.util.concurrent.Callable; +import org.apache.ignite.internal.cli.call.recovery.PartitionStatesCall; +import org.apache.ignite.internal.cli.call.recovery.PartitionStatesCallInput; +import org.apache.ignite.internal.cli.commands.BaseCommand; +import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlMixin; +import org.apache.ignite.internal.cli.core.call.CallExecutionPipeline; +import org.apache.ignite.internal.cli.decorators.TableDecorator; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Mixin; +import picocli.CommandLine.Option; + +/** Command to get partition states. */ +@Command(name = "partition-states", description = "Returns partition states.") +public class PartitionStatesCommand extends BaseCommand implements Callable<Integer> { + /** Cluster endpoint URL option. */ + @Mixin + private ClusterUrlMixin clusterUrl; + + /** Specific local / global states filters. */ + @ArgGroup(exclusive = true, multiplicity = "1") + private PartitionStatesArgGroup statesArgs; + + /** IDs of partitions to get states of. */ + @Option(names = RECOVERY_PARTITION_IDS_OPTION, description = RECOVERY_PARTITION_IDS_OPTION_DESC, split = ",") + private List<Integer> partitionIds; + + /** Names of zones to get partition states of. */ + @Option(names = RECOVERY_ZONE_NAMES_OPTION, description = RECOVERY_ZONE_NAMES_OPTION_DESC, split = ",") + private List<String> zoneNames; + + @Option(names = PLAIN_OPTION, description = PLAIN_OPTION_DESC) + private boolean plain; Review Comment: Please add a javadoc explaining what it means -- 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]
