This is an automated email from the ASF dual-hosted git repository. mpochatkin pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push: new c8bd7550b6 IGNITE-22463 Improve CLI error message when executing commands on uninitialized cluster (#3921) c8bd7550b6 is described below commit c8bd7550b6bb3b989a7d0a79dc576c16f98ae37f Author: Maksim Myskov <maxim.mys...@gmail.com> AuthorDate: Wed Jun 26 15:43:54 2024 +0300 IGNITE-22463 Improve CLI error message when executing commands on uninitialized cluster (#3921) --- ...liCommandTestNotInitializedIntegrationBase.java | 7 + .../cli/commands/ItNonInitializedClusterTest.java | 161 +++++++++++++++++++++ ...t.java => ItReplNonInitializedClusterTest.java} | 22 ++- .../cluster/config/ClusterConfigShowCommand.java | 4 +- .../config/ClusterConfigShowReplCommand.java | 2 +- .../cluster/config/ClusterConfigUpdateCommand.java | 4 +- .../config/ClusterConfigUpdateReplCommand.java | 2 +- .../cluster/topology/LogicalTopologyCommand.java | 4 +- .../topology/LogicalTopologyReplCommand.java | 2 +- .../cluster/unit/ClusterUnitDeployCommand.java | 2 +- .../cluster/unit/ClusterUnitDeployReplCommand.java | 2 +- .../cluster/unit/ClusterUnitListCommand.java | 2 +- .../cluster/unit/ClusterUnitListReplCommand.java | 2 +- .../cluster/unit/ClusterUnitUndeployCommand.java | 2 +- .../unit/ClusterUnitUndeployReplCommand.java | 2 +- .../node/metric/NodeMetricSetListCommand.java | 2 + .../node/metric/NodeMetricSetListReplCommand.java | 2 + .../metric/NodeMetricSourceDisableCommand.java | 2 +- .../metric/NodeMetricSourceDisableReplCommand.java | 2 +- .../node/metric/NodeMetricSourceEnableCommand.java | 2 +- .../metric/NodeMetricSourceEnableReplCommand.java | 2 +- .../node/metric/NodeMetricSourceListCommand.java | 2 +- .../metric/NodeMetricSourceListReplCommand.java | 2 +- .../commands/node/unit/NodeUnitListCommand.java | 2 +- .../node/unit/NodeUnitListReplCommand.java | 2 +- .../partitions/reset/ResetPartitionsCommand.java | 2 + .../reset/ResetPartitionsReplCommand.java | 2 + .../restart/RestartPartitionsCommand.java | 2 + .../restart/RestartPartitionsReplCommand.java | 2 + .../partitions/states/PartitionStatesCommand.java | 2 + .../states/PartitionStatesReplCommand.java | 2 + .../ClusterNotInitializedExceptionHandler.java | 18 +++ 32 files changed, 240 insertions(+), 30 deletions(-) diff --git a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/CliCommandTestNotInitializedIntegrationBase.java b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/CliCommandTestNotInitializedIntegrationBase.java index 6057e7d0ed..86bcbba6b5 100644 --- a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/CliCommandTestNotInitializedIntegrationBase.java +++ b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/CliCommandTestNotInitializedIntegrationBase.java @@ -27,6 +27,13 @@ import org.junit.jupiter.api.TestInfo; * won't be initialized. If you want to use initialized cluster use {@link CliIntegrationTest} directly. */ public class CliCommandTestNotInitializedIntegrationBase extends CliIntegrationTest { + + protected static String CLUSTER_NOT_INITIALIZED_ERROR_MESSAGE = "Probably, you have not initialized the cluster, " + + "try to run ignite cluster init command"; + + protected static String CLUSTER_NOT_INITIALIZED_REPL_ERROR_MESSAGE = "Probably, you have not initialized the cluster, " + + "try to run cluster init command"; + @BeforeAll @Override protected void beforeAll(TestInfo testInfo) { diff --git a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItNonInitializedClusterTest.java b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItNonInitializedClusterTest.java new file mode 100644 index 0000000000..e3aab836c2 --- /dev/null +++ b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItNonInitializedClusterTest.java @@ -0,0 +1,161 @@ +/* + * 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; + +import static org.apache.ignite.internal.cli.commands.Options.Constants.CLUSTER_URL_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_TABLE_NAME_OPTION; +import static org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_ZONE_NAME_OPTION; +import static org.junit.jupiter.api.Assertions.assertAll; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +/** + * Tests for non-initialized cluster fir Non-REPL mode. + */ +public class ItNonInitializedClusterTest extends CliCommandTestNotInitializedIntegrationBase { + + protected String getExpectedErrorMessage() { + return CLUSTER_NOT_INITIALIZED_ERROR_MESSAGE; + } + + private Path testDirectory; + private String testFile; + + @BeforeAll + void beforeAll() throws IOException { + testDirectory = Files.createDirectory(WORK_DIR.resolve("test")); + testFile = Files.createFile(testDirectory.resolve("test.txt")).toString(); + } + + @Test + @DisplayName("Should print error message when run node metric list on not initialized cluster") + void nodeMetricListError() { + execute("node", "metric", "list"); + + assertAll( + () -> assertErrOutputContains("Cannot list metrics"), + () -> assertErrOutputContains(getExpectedErrorMessage()) + ); + } + + @Test + @DisplayName("Should print error message when run node metric source list on not initialized cluster") + void nodeMetricSourceListError() { + execute("node", "metric", "source", "list"); + + assertAll( + () -> assertErrOutputContains("Cannot list metrics"), + () -> assertErrOutputContains(getExpectedErrorMessage()) + ); + } + + @Test + @DisplayName("Should print error message when run node metric source enable on not initialized cluster") + void nodeMetricSourceEnableError() { + execute("node", "metric", "source", "enable", "metricName"); + + assertAll( + () -> assertErrOutputContains("Cannot enable metrics"), + () -> assertErrOutputContains(getExpectedErrorMessage()) + ); + } + + @Test + @DisplayName("Should print error message when run node metric source disable on not initialized cluster") + void nodeMetricSourceDisableError() { + execute("node", "metric", "source", "disable", "metricName"); + + assertAll( + () -> assertErrOutputContains("Cannot disable metrics"), + () -> assertErrOutputContains(getExpectedErrorMessage()) + ); + } + + @Test + @DisplayName("Should print error message when recovery reset-partitions on not initialized cluster") + void resetPartitionsError() { + execute("recovery", "partitions", "reset", CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_TABLE_NAME_OPTION, "tableName", + RECOVERY_ZONE_NAME_OPTION, "zoneName"); + assertAll( + () -> assertErrOutputContains("Cannot reset partitions"), + () -> assertErrOutputContains(getExpectedErrorMessage()) + ); + } + + @Test + @DisplayName("Should print error message when recovery partition-states on not initialized cluster") + void partitionsStatesError() { + execute("recovery", "partitions", "states", CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_PARTITION_GLOBAL_OPTION); + assertAll( + () -> assertErrOutputContains("Cannot list partition states"), + () -> assertErrOutputContains(getExpectedErrorMessage()) + ); + } + + @Test + @DisplayName("Should print error message when recovery restart-partitions on not initialized cluster") + void partitionsRestartErrror() { + execute("recovery", "partitions", "restart", CLUSTER_URL_OPTION, NODE_URL, + RECOVERY_TABLE_NAME_OPTION, "tableName", RECOVERY_ZONE_NAME_OPTION, "zoneName"); + assertAll( + () -> assertErrOutputContains("Cannot restart partitions"), + () -> assertErrOutputContains(getExpectedErrorMessage()) + ); + } + + @Test + @DisplayName("Should print error message when deploy a unit on not initialized cluster") + void unitDeployError() { + execute("cluster", "unit", "deploy", "test.unit.id.1", "--version", "1.0.0", "--path", testFile); + + assertAll( + () -> assertErrOutputContains("Cannot deploy unit"), + () -> assertErrOutputContains(getExpectedErrorMessage()) + ); + } + + @Test + @DisplayName("Should display error when undeploy a unit on not initialized cluster") + void unitUndeployError() { + execute("cluster", "unit", "undeploy", "test.unit.id.2", "--version", "1.0.0"); + + assertAll( + () -> assertErrOutputContains("Cannot undeploy unit"), + () -> assertErrOutputContains(getExpectedErrorMessage()) + ); + } + + @Test + @DisplayName("Should display error when listing deploy units on not initialized cluster") + void listUnitsError() { + execute("node", "unit", "list"); + + assertAll( + () -> assertErrOutputContains("Cannot list units"), + () -> assertErrOutputContains(getExpectedErrorMessage()) + ); + } +} diff --git a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/ItRestartPartitionsReplCommandTest.java b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItReplNonInitializedClusterTest.java similarity index 64% rename from modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/ItRestartPartitionsReplCommandTest.java rename to modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItReplNonInitializedClusterTest.java index 0bffc6df58..5f236bdd0b 100644 --- a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/ItRestartPartitionsReplCommandTest.java +++ b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItReplNonInitializedClusterTest.java @@ -15,13 +15,27 @@ * limitations under the License. */ -package org.apache.ignite.internal.cli.commands.recovery.partitions.restart; +package org.apache.ignite.internal.cli.commands; -/** Test class for {@link RestartPartitionsReplCommand}. */ -public class ItRestartPartitionsReplCommandTest extends ItRestartPartitionsTest { +import org.junit.jupiter.api.BeforeEach; + +/** + * Tests for non-initialized cluster fir REPL mode. + */ +public class ItReplNonInitializedClusterTest extends ItNonInitializedClusterTest { @Override protected Class<?> getCommandClass() { - return RestartPartitionsReplCommand.class; + return TopLevelCliReplCommand.class; + } + + @BeforeEach + void connect() { + execute("connect"); + } + + @Override + protected String getExpectedErrorMessage() { + return CLUSTER_NOT_INITIALIZED_REPL_ERROR_MESSAGE; } } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigShowCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigShowCommand.java index 091987aa92..0b8f1334af 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigShowCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigShowCommand.java @@ -61,9 +61,7 @@ public class ClusterConfigShowCommand extends BaseCommand implements Callable<In .output(spec.commandLine().getOut()) .errOutput(spec.commandLine().getErr()) .decorator(new JsonDecorator(isHighlightEnabled())) - .exceptionHandler(new ClusterNotInitializedExceptionHandler( - "Cannot show cluster config", "ignite cluster init" - )) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot show cluster config")) .verbose(verbose) .build() .runPipeline(); diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigShowReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigShowReplCommand.java index d01e84599d..c606ef1a07 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigShowReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigShowReplCommand.java @@ -63,7 +63,7 @@ public class ClusterConfigShowReplCommand extends BaseCommand implements Runnabl question.askQuestionIfNotConnected(clusterUrl.getClusterUrl()) .map(this::configShowCallInput) .then(Flows.fromCall(call)) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot show cluster config", "cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot show cluster config")) .verbose(verbose) .print(new JsonDecorator(isHighlightEnabled())) .start(); diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigUpdateCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigUpdateCommand.java index 55daeecd3a..49135925f8 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigUpdateCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigUpdateCommand.java @@ -52,9 +52,7 @@ public class ClusterConfigUpdateCommand extends BaseCommand implements Callable< .inputProvider(this::buildCallInput) .output(spec.commandLine().getOut()) .errOutput(spec.commandLine().getErr()) - .exceptionHandler(new ClusterNotInitializedExceptionHandler( - "Cannot update cluster config", "ignite cluster init" - )) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot update cluster config")) .verbose(verbose) .build() .runPipeline(); diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigUpdateReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigUpdateReplCommand.java index 73250006cd..2021a7c9b3 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigUpdateReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/config/ClusterConfigUpdateReplCommand.java @@ -54,7 +54,7 @@ public class ClusterConfigUpdateReplCommand extends BaseCommand implements Runna question.askQuestionIfNotConnected(clusterUrl.getClusterUrl()) .map(this::configUpdateCallInput) .then(Flows.fromCall(call)) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot update cluster config", "cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot update cluster config")) .verbose(verbose) .print() .start(); diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/topology/LogicalTopologyCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/topology/LogicalTopologyCommand.java index 5afa5a53cf..b9fd71b1cd 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/topology/LogicalTopologyCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/topology/LogicalTopologyCommand.java @@ -56,9 +56,7 @@ public class LogicalTopologyCommand extends BaseCommand implements Callable<Inte .output(spec.commandLine().getOut()) .errOutput(spec.commandLine().getErr()) .decorator(new TopologyDecorator(plain)) - .exceptionHandler(new ClusterNotInitializedExceptionHandler( - "Cannot show logical topology", "ignite cluster init" - )) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot show logical topology")) .verbose(verbose) .build() .runPipeline(); diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/topology/LogicalTopologyReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/topology/LogicalTopologyReplCommand.java index 2eb008b52c..4739dc4a50 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/topology/LogicalTopologyReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/topology/LogicalTopologyReplCommand.java @@ -57,7 +57,7 @@ public class LogicalTopologyReplCommand extends BaseCommand implements Runnable question.askQuestionIfNotConnected(clusterUrl.getClusterUrl()) .map(UrlCallInput::new) .then(Flows.fromCall(call)) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot show logical topology", "cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot show logical topology")) .print(new TopologyDecorator(plain)) .start(); } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitDeployCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitDeployCommand.java index 38eb288c09..357dc39ac4 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitDeployCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitDeployCommand.java @@ -48,7 +48,7 @@ public class ClusterUnitDeployCommand extends BaseCommand implements Callable<In .output(spec.commandLine().getOut()) .errOutput(spec.commandLine().getErr()) .verbose(verbose) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot deploy unit", "ignite cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot deploy unit")) .build().runPipeline(); } } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitDeployReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitDeployReplCommand.java index 14ff293556..e7e0b23f1b 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitDeployReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitDeployReplCommand.java @@ -55,7 +55,7 @@ public class ClusterUnitDeployReplCommand extends BaseCommand implements Runnabl .output(spec.commandLine().getOut()) .errOutput(spec.commandLine().getErr()) .verbose(verbose) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot deploy unit", "cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot deploy unit")) .build().runPipeline() )) .start(); diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitListCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitListCommand.java index 2eca96a3df..dea9d7a16b 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitListCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitListCommand.java @@ -58,7 +58,7 @@ public class ClusterUnitListCommand extends BaseCommand implements Callable<Inte .errOutput(spec.commandLine().getErr()) .verbose(verbose) .decorator(new UnitListDecorator(plain)) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot list units", "ignite cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot list units")) .build().runPipeline(); } } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitListReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitListReplCommand.java index ab874ace9a..5b696ca297 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitListReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitListReplCommand.java @@ -58,7 +58,7 @@ public class ClusterUnitListReplCommand extends BaseCommand implements Runnable question.askQuestionIfNotConnected(clusterUrl.getClusterUrl()) .map(listOptions::toListUnitCallInput) .then(Flows.fromCall(call)) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot list units", "cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot list units")) .verbose(verbose) .print(new UnitListDecorator(plain)) .start(); diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitUndeployCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitUndeployCommand.java index b435bb991d..3502e9cdf9 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitUndeployCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitUndeployCommand.java @@ -63,7 +63,7 @@ public class ClusterUnitUndeployCommand extends BaseCommand implements Callable< .output(spec.commandLine().getOut()) .errOutput(spec.commandLine().getErr()) .verbose(verbose) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot undeploy unit", "ignite cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot undeploy unit")) .build().runPipeline(); } } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitUndeployReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitUndeployReplCommand.java index df8fdc493a..870301372b 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitUndeployReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/unit/ClusterUnitUndeployReplCommand.java @@ -64,7 +64,7 @@ public class ClusterUnitUndeployReplCommand extends BaseCommand implements Runna .clusterUrl(clusterUrl) .build()) .then(Flows.fromCall(call)) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot undeploy unit", "cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot undeploy unit")) .verbose(verbose) .print() .start(); diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSetListCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSetListCommand.java index 9867ecda54..da07db099a 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSetListCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSetListCommand.java @@ -27,6 +27,7 @@ import org.apache.ignite.internal.cli.commands.BaseCommand; import org.apache.ignite.internal.cli.commands.node.NodeUrlProfileMixin; import org.apache.ignite.internal.cli.core.call.CallExecutionPipeline; import org.apache.ignite.internal.cli.core.call.UrlCallInput; +import org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializedExceptionHandler; import org.apache.ignite.internal.cli.decorators.MetricSetListDecorator; import picocli.CommandLine.Command; import picocli.CommandLine.Mixin; @@ -54,6 +55,7 @@ public class NodeMetricSetListCommand extends BaseCommand implements Callable<In .errOutput(spec.commandLine().getErr()) .decorator(new MetricSetListDecorator(plain)) .verbose(verbose) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot list metrics")) .build() .runPipeline(); } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSetListReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSetListReplCommand.java index 5bbc6b9b4b..2b6d9ac1e9 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSetListReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSetListReplCommand.java @@ -26,6 +26,7 @@ import org.apache.ignite.internal.cli.commands.BaseCommand; import org.apache.ignite.internal.cli.commands.node.NodeUrlMixin; import org.apache.ignite.internal.cli.commands.questions.ConnectToClusterQuestion; import org.apache.ignite.internal.cli.core.call.UrlCallInput; +import org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializedExceptionHandler; import org.apache.ignite.internal.cli.core.flow.builder.Flows; import org.apache.ignite.internal.cli.decorators.MetricSetListDecorator; import picocli.CommandLine.Command; @@ -54,6 +55,7 @@ public class NodeMetricSetListReplCommand extends BaseCommand implements Runnabl question.askQuestionIfNotConnected(nodeUrl.getNodeUrl()) .map(UrlCallInput::new) .then(Flows.fromCall(call)) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot list metrics")) .print(new MetricSetListDecorator(plain)) .start(); } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceDisableCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceDisableCommand.java index 1529ec55de..27fd4bde0d 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceDisableCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceDisableCommand.java @@ -49,7 +49,7 @@ public class NodeMetricSourceDisableCommand extends BaseCommand implements Calla .output(spec.commandLine().getOut()) .errOutput(spec.commandLine().getErr()) .verbose(verbose) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot disable metrics", "ignite cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot disable metrics")) .build() .runPipeline(); } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceDisableReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceDisableReplCommand.java index bf8d525f9f..d485e067b2 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceDisableReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceDisableReplCommand.java @@ -49,7 +49,7 @@ public class NodeMetricSourceDisableReplCommand extends BaseCommand implements R question.askQuestionIfNotConnected(nodeUrl.getNodeUrl()) .map(metricSource::buildDisableCallInput) .then(Flows.fromCall(call)) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot disable metrics", "cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot disable metrics")) .verbose(verbose) .print() .start(); diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceEnableCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceEnableCommand.java index 0c2fdd45d1..6e4ef57512 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceEnableCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceEnableCommand.java @@ -49,7 +49,7 @@ public class NodeMetricSourceEnableCommand extends BaseCommand implements Callab .output(spec.commandLine().getOut()) .errOutput(spec.commandLine().getErr()) .verbose(verbose) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot enable metrics", "ignite cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot enable metrics")) .build() .runPipeline(); } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceEnableReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceEnableReplCommand.java index 84cc518371..9f47a2d270 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceEnableReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceEnableReplCommand.java @@ -49,7 +49,7 @@ public class NodeMetricSourceEnableReplCommand extends BaseCommand implements Ru question.askQuestionIfNotConnected(nodeUrl.getNodeUrl()) .map(metricSource::buildEnableCallInput) .then(Flows.fromCall(call)) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot enable metrics", "cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot enable metrics")) .verbose(verbose) .print() .start(); diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceListCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceListCommand.java index ab1814ed2a..abd7d27fc7 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceListCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceListCommand.java @@ -55,7 +55,7 @@ public class NodeMetricSourceListCommand extends BaseCommand implements Callable .errOutput(spec.commandLine().getErr()) .decorator(new MetricSourceListDecorator(plain)) .verbose(verbose) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot list metrics", "ignite cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot list metrics")) .build() .runPipeline(); } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceListReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceListReplCommand.java index 99bcc97b31..a14f4b1bfd 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceListReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceListReplCommand.java @@ -55,7 +55,7 @@ public class NodeMetricSourceListReplCommand extends BaseCommand implements Runn question.askQuestionIfNotConnected(nodeUrl.getNodeUrl()) .map(UrlCallInput::new) .then(Flows.fromCall(call)) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot list metrics", "cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot list metrics")) .print(new MetricSourceListDecorator(plain)) .start(); } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/unit/NodeUnitListCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/unit/NodeUnitListCommand.java index 96245c1df5..27ccc9d349 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/unit/NodeUnitListCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/unit/NodeUnitListCommand.java @@ -58,7 +58,7 @@ public class NodeUnitListCommand extends BaseCommand implements Callable<Integer .errOutput(spec.commandLine().getErr()) .verbose(verbose) .decorator(new UnitListDecorator(plain)) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot list units", "ignite cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot list units")) .build().runPipeline(); } } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/unit/NodeUnitListReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/unit/NodeUnitListReplCommand.java index 5e35d6d365..a4ad93a99e 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/unit/NodeUnitListReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/unit/NodeUnitListReplCommand.java @@ -57,7 +57,7 @@ public class NodeUnitListReplCommand extends BaseCommand implements Runnable { question.askQuestionIfNotConnected(nodeUrl.getNodeUrl()) .map(listOptions::toListUnitCallInput) .then(Flows.fromCall(call)) - .exceptionHandler(new ClusterNotInitializedExceptionHandler("Cannot list units", "cluster init")) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot list units")) .verbose(verbose) .print(new UnitListDecorator(plain)) .start(); diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsCommand.java index 124703cb32..33330ed018 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsCommand.java @@ -23,6 +23,7 @@ import org.apache.ignite.internal.cli.call.recovery.reset.ResetPartitionsCall; import org.apache.ignite.internal.cli.call.recovery.reset.ResetPartitionsCallInput; import org.apache.ignite.internal.cli.commands.BaseCommand; import org.apache.ignite.internal.cli.core.call.CallExecutionPipeline; +import org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializedExceptionHandler; import picocli.CommandLine.Command; import picocli.CommandLine.Mixin; @@ -42,6 +43,7 @@ public class ResetPartitionsCommand extends BaseCommand implements Callable<Inte .output(spec.commandLine().getOut()) .errOutput(spec.commandLine().getErr()) .verbose(verbose) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot reset partitions")) .build() .runPipeline(); } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsReplCommand.java index d2951415cd..87fc635050 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsReplCommand.java @@ -22,6 +22,7 @@ import org.apache.ignite.internal.cli.call.recovery.reset.ResetPartitionsCall; import org.apache.ignite.internal.cli.call.recovery.reset.ResetPartitionsCallInput; import org.apache.ignite.internal.cli.commands.BaseCommand; import org.apache.ignite.internal.cli.commands.questions.ConnectToClusterQuestion; +import org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializedExceptionHandler; import org.apache.ignite.internal.cli.core.flow.builder.Flows; import picocli.CommandLine.Command; import picocli.CommandLine.Mixin; @@ -44,6 +45,7 @@ public class ResetPartitionsReplCommand extends BaseCommand implements Runnable .map(url -> ResetPartitionsCallInput.of(options, url)) .then(Flows.fromCall(call)) .verbose(verbose) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot reset partitions")) .print() .start(); } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsCommand.java index 07ffc5767a..b12924e3ac 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsCommand.java @@ -23,6 +23,7 @@ import org.apache.ignite.internal.cli.call.recovery.restart.RestartPartitionsCal import org.apache.ignite.internal.cli.call.recovery.restart.RestartPartitionsCallInput; import org.apache.ignite.internal.cli.commands.BaseCommand; import org.apache.ignite.internal.cli.core.call.CallExecutionPipeline; +import org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializedExceptionHandler; import picocli.CommandLine.Command; import picocli.CommandLine.Mixin; @@ -42,6 +43,7 @@ public class RestartPartitionsCommand extends BaseCommand implements Callable<In .output(spec.commandLine().getOut()) .errOutput(spec.commandLine().getErr()) .verbose(verbose) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot restart partitions")) .build() .runPipeline(); } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsReplCommand.java index d392cfefa6..b71c337295 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsReplCommand.java @@ -22,6 +22,7 @@ import org.apache.ignite.internal.cli.call.recovery.restart.RestartPartitionsCal import org.apache.ignite.internal.cli.call.recovery.restart.RestartPartitionsCallInput; import org.apache.ignite.internal.cli.commands.BaseCommand; import org.apache.ignite.internal.cli.commands.questions.ConnectToClusterQuestion; +import org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializedExceptionHandler; import org.apache.ignite.internal.cli.core.flow.builder.Flows; import picocli.CommandLine.Command; import picocli.CommandLine.Mixin; @@ -44,6 +45,7 @@ public class RestartPartitionsReplCommand extends BaseCommand implements Runnabl .map(url -> RestartPartitionsCallInput.of(options, url)) .then(Flows.fromCall(call)) .verbose(verbose) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot restart partitions")) .print() .start(); } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesCommand.java index 30776e1ec1..08b2d4ea90 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesCommand.java @@ -23,6 +23,7 @@ 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.core.call.CallExecutionPipeline; +import org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializedExceptionHandler; import org.apache.ignite.internal.cli.decorators.TableDecorator; import picocli.CommandLine.Command; import picocli.CommandLine.Mixin; @@ -44,6 +45,7 @@ public class PartitionStatesCommand extends BaseCommand implements Callable<Inte .errOutput(spec.commandLine().getErr()) .decorator(new TableDecorator(options.plain())) .verbose(verbose) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createHandler("Cannot list partition states")) .build() .runPipeline(); } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesReplCommand.java index f43ded24a3..bbae949018 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesReplCommand.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesReplCommand.java @@ -22,6 +22,7 @@ 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.questions.ConnectToClusterQuestion; +import org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializedExceptionHandler; import org.apache.ignite.internal.cli.core.flow.builder.Flows; import org.apache.ignite.internal.cli.decorators.TableDecorator; import picocli.CommandLine.Command; @@ -45,6 +46,7 @@ public class PartitionStatesReplCommand extends BaseCommand implements Runnable .map(url -> PartitionStatesCallInput.of(options, url)) .then(Flows.fromCall(call)) .print(new TableDecorator(options.plain())) + .exceptionHandler(ClusterNotInitializedExceptionHandler.createReplHandler("Cannot list partition states")) .verbose(verbose) .start(); } diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/core/exception/handler/ClusterNotInitializedExceptionHandler.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/core/exception/handler/ClusterNotInitializedExceptionHandler.java index 7cbde65b61..6864c3059c 100644 --- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/core/exception/handler/ClusterNotInitializedExceptionHandler.java +++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/core/exception/handler/ClusterNotInitializedExceptionHandler.java @@ -61,4 +61,22 @@ public class ClusterNotInitializedExceptionHandler extends IgniteCliApiException } return super.handle(err, e); } + + /** + * Creates handler for Non-REPL command. + * + * @param message command-specific text like 'cannot list nodes' + */ + public static ClusterNotInitializedExceptionHandler createHandler(String message) { + return new ClusterNotInitializedExceptionHandler(message, "ignite cluster init"); + } + + /** + * Creates handler for REPL command. + * + * @param message command-specific text like 'cannot list nodes' + */ + public static ClusterNotInitializedExceptionHandler createReplHandler(String message) { + return new ClusterNotInitializedExceptionHandler(message, "cluster init"); + } }