From 789ef9f4b0a4ca63d8a1a6ffe4cc4eb29bc896b3 Mon Sep 17 00:00:00 2001 From: Nikita Amelchev Date: Mon, 16 Dec 2024 11:20:39 +0300 Subject: [PATCH] IGNITE-18312 [IEP-81] Use IgniteClient instead of GridClient in control-utility (#11648) --- .../internal/commandline/ArgumentParser.java | 4 +- .../commandline/CliCommandInvoker.java | 17 +- .../commandline/CliIgniteClientInvoker.java | 92 +++++++++++ .../CloseableCliCommandInvoker.java | 38 +++++ .../internal/commandline/CommandHandler.java | 86 ++++++++-- ...SecurityCommandHandlerPermissionsTest.java | 3 +- .../indexreader/IgniteIndexReaderTest.java | 3 +- ...GridCommandHandlerSslWithSecurityTest.java | 35 +++-- .../IgniteControlUtilityTestSuite.java | 2 + .../apache/ignite/util/CdcCommandTest.java | 12 +- .../util/GridCommandHandlerAbstractTest.java | 11 ++ .../GridCommandHandlerClusterByClassTest.java | 38 +++-- ...mmandHandlerClusterByClassWithSSLTest.java | 2 +- ...GridCommandHandlerDefragmentationTest.java | 9 +- ...GridCommandHandlerFactoryAbstractTest.java | 49 +++++- ...mmandHandlerIncompatibleSslConfigTest.java | 6 +- .../util/GridCommandHandlerIndexListTest.java | 4 +- ...GridCommandHandlerIndexingWithSSLTest.java | 2 +- ...ridCommandHandlerInterruptCommandTest.java | 2 +- .../GridCommandHandlerLegacyClientTest.java | 148 ++++++++++++++++++ .../util/GridCommandHandlerMetadataTest.java | 98 ------------ .../GridCommandHandlerPropertiesTest.java | 2 +- .../util/GridCommandHandlerSslTest.java | 15 +- .../ignite/util/GridCommandHandlerTest.java | 60 ++++--- .../GridCommandHandlerWithSslFactoryTest.java | 4 +- .../util/GridCommandHandlerWithSslTest.java | 2 +- .../util/KillCommandsControlShTest.java | 12 +- .../apache/ignite/util/MetricCommandTest.java | 2 +- .../ignite/util/SystemViewCommandTest.java | 4 +- ...dlerFactoryAbstractTest$TestCommandHandler | 3 +- .../internal/management/ActivateCommand.java | 4 + .../management/DeactivateCommand.java | 31 +++- .../internal/management/SetStateCommand.java | 13 +- .../internal/management/StateCommand.java | 14 ++ .../management/WarmUpStopCommand.java | 6 +- .../api/BeforeNodeStartCommand.java | 5 +- .../management/api/CommandInvoker.java | 21 ++- .../internal/management/api/CommandUtils.java | 28 +++- .../management/api/ComputeCommand.java | 9 ++ .../internal/management/api/LocalCommand.java | 9 +- .../management/api/PreparableCommand.java | 10 +- .../management/cache/CacheDestroyCommand.java | 4 + .../management/cache/CacheListCommand.java | 13 +- .../consistency/ConsistencyRepairCommand.java | 10 +- .../management/kill/KillClientCommand.java | 13 ++ .../management/meta/MetaRemoveCommand.java | 3 +- .../management/meta/MetadataRemoveTask.java | 71 ++------- .../internal/management/tx/TxInfoCommand.java | 6 +- .../processors/cache/GridCacheProcessor.java | 3 + .../client/compute/ClientComputeTask.java | 13 +- .../compute/ClientExecuteTaskRequest.java | 27 +++- .../visor/misc/VisorIdAndTagViewTask.java | 2 +- .../misc/VisorIdAndTagViewTaskResult.java | 14 +- .../security/impl/TestSecurityProcessor.java | 5 + ...mmandHandlerClusterByClassTest_help.output | 2 +- ...ndlerClusterByClassWithSSLTest_help.output | 2 +- .../commandline/CommandsProviderExtImpl.java | 68 +++++++- .../ExtendedControlUtilityTest.java | 50 ++++++ 58 files changed, 904 insertions(+), 317 deletions(-) create mode 100644 modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CliIgniteClientInvoker.java create mode 100644 modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CloseableCliCommandInvoker.java create mode 100644 modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerLegacyClientTest.java diff --git a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/ArgumentParser.java b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/ArgumentParser.java index 1a6e1d19cb95a..e6d7c8517b8e6 100644 --- a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/ArgumentParser.java +++ b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/ArgumentParser.java @@ -48,11 +48,13 @@ import org.apache.ignite.ssl.SslContextFactory; import static org.apache.ignite.IgniteSystemProperties.IGNITE_ENABLE_EXPERIMENTAL_COMMAND; +import static org.apache.ignite.configuration.ConnectorConfiguration.DFLT_TCP_PORT; import static org.apache.ignite.internal.client.GridClientConfiguration.DFLT_PING_INTERVAL; import static org.apache.ignite.internal.client.GridClientConfiguration.DFLT_PING_TIMEOUT; import static org.apache.ignite.internal.commandline.CommandHandler.DFLT_HOST; import static org.apache.ignite.internal.commandline.CommandHandler.DFLT_PORT; import static org.apache.ignite.internal.commandline.CommandHandler.UTILITY_NAME; +import static org.apache.ignite.internal.commandline.CommandHandler.useConnectorConnection; import static org.apache.ignite.internal.commandline.argument.parser.CLIArgument.optionalArg; import static org.apache.ignite.internal.management.api.CommandUtils.CMD_WORDS_DELIM; import static org.apache.ignite.internal.management.api.CommandUtils.NAME_PREFIX; @@ -184,7 +186,7 @@ public ArgumentParser(IgniteLogger log, IgniteCommandRegistry registry) { "Whenever possible, use interactive prompt for password (just discard %s option).", name, name)); arg(CMD_HOST, "HOST_OR_IP", String.class, DFLT_HOST); - arg(CMD_PORT, "PORT", Integer.class, DFLT_PORT, PORT_VALIDATOR); + arg(CMD_PORT, "PORT", Integer.class, useConnectorConnection() ? DFLT_TCP_PORT : DFLT_PORT, PORT_VALIDATOR); arg(CMD_USER, "USER", String.class, null); arg(CMD_PASSWORD, "PASSWORD", String.class, null, (BiConsumer)securityWarn); arg(CMD_PING_INTERVAL, "PING_INTERVAL", Long.class, DFLT_PING_INTERVAL, POSITIVE_LONG); diff --git a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CliCommandInvoker.java b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CliCommandInvoker.java index 816910569fa96..5d13e20c958f5 100644 --- a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CliCommandInvoker.java +++ b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CliCommandInvoker.java @@ -44,8 +44,11 @@ /** * Adapter of new management API command for legacy {@code control.sh} execution flow. + * + * @deprecated Use {@link CliIgniteClientInvoker} instead. Will be removed in the next releases. */ -public class CliCommandInvoker extends CommandInvoker implements AutoCloseable { +@Deprecated +public class CliCommandInvoker extends CommandInvoker implements CloseableCliCommandInvoker { /** Client configuration. */ private final GridClientConfiguration clientCfg; @@ -58,17 +61,15 @@ public CliCommandInvoker(Command cmd, A arg, GridClientConfiguration clien this.clientCfg = clientCfg; } - /** - * @return Message text to show user for. {@code null} means that confirmantion is not required. - */ - public String confirmationPrompt() { + /** {@inheritDoc} */ + @Override public String confirmationPrompt() { return cmd.confirmationPrompt(arg); } - /** */ - public R invokeBeforeNodeStart(Consumer printer) throws Exception { + /** {@inheritDoc} */ + @Override public R invokeBeforeNodeStart(Consumer printer) throws Exception { try (GridClientBeforeNodeStart client = startClientBeforeNodeStart(clientCfg)) { - return ((BeforeNodeStartCommand)cmd).execute(client, arg, printer); + return ((BeforeNodeStartCommand)cmd).execute(client.beforeStartState(), arg, printer); } catch (GridClientDisconnectedException e) { throw new GridClientException(e.getCause()); diff --git a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CliIgniteClientInvoker.java b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CliIgniteClientInvoker.java new file mode 100644 index 0000000000000..637b4dd7b1db2 --- /dev/null +++ b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CliIgniteClientInvoker.java @@ -0,0 +1,92 @@ +/* + * 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.commandline; + +import java.util.function.Consumer; +import org.apache.ignite.Ignition; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.configuration.ClientConfiguration; +import org.apache.ignite.internal.client.GridClientNode; +import org.apache.ignite.internal.client.GridClientNodeStateBeforeStart; +import org.apache.ignite.internal.client.thin.TcpIgniteClient; +import org.apache.ignite.internal.dto.IgniteDataTransferObject; +import org.apache.ignite.internal.management.api.BeforeNodeStartCommand; +import org.apache.ignite.internal.management.api.Command; +import org.apache.ignite.internal.management.api.CommandInvoker; +import org.apache.ignite.internal.management.api.CommandUtils; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.jetbrains.annotations.Nullable; + +import static org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.MANAGEMENT_CLIENT_ATTR; + +/** + * Adapter of new management API command for {@code control.sh} execution flow. + */ +public class CliIgniteClientInvoker extends CommandInvoker implements CloseableCliCommandInvoker { + /** Client configuration. */ + private final ClientConfiguration cfg; + + /** Client. */ + private IgniteClient client; + + /** @param cmd Command to execute. */ + public CliIgniteClientInvoker(Command cmd, A arg, ClientConfiguration cfg) { + super(cmd, arg, null); + + this.cfg = cfg; + } + + /** {@inheritDoc} */ + @Override protected GridClientNode defaultNode() { + return CommandUtils.clusterToClientNode(igniteClient().cluster().forOldest().node()); + } + + /** {@inheritDoc} */ + @Override protected @Nullable IgniteClient igniteClient() { + if (client == null) { + if (cmd instanceof BeforeNodeStartCommand) { + cfg.setUserAttributes(F.asMap(MANAGEMENT_CLIENT_ATTR, Boolean.TRUE.toString())); + cfg.setAutoBinaryConfigurationEnabled(false); + } + + client = Ignition.startClient(cfg); + } + + return client; + } + + /** {@inheritDoc} */ + @Override public String confirmationPrompt() { + return cmd.confirmationPrompt(arg); + } + + /** {@inheritDoc} */ + @Override public R invokeBeforeNodeStart(Consumer printer) throws Exception { + return ((BeforeNodeStartCommand)cmd).execute(new GridClientNodeStateBeforeStart() { + @Override public void stopWarmUp() { + ((TcpIgniteClient)igniteClient()).stopWarmUp(); + } + }, arg, printer); + } + + /** {@inheritDoc} */ + @Override public void close() { + U.closeQuiet(client); + } +} diff --git a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CloseableCliCommandInvoker.java b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CloseableCliCommandInvoker.java new file mode 100644 index 0000000000000..f739c0a91c83b --- /dev/null +++ b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CloseableCliCommandInvoker.java @@ -0,0 +1,38 @@ +/* + * 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.commandline; + +import java.util.function.Consumer; +import org.apache.ignite.internal.management.api.CommandInvoker; + +/** + * CLI command invoker. + */ +public interface CloseableCliCommandInvoker extends AutoCloseable { + /** @return Message text to show user for. {@code null} means that confirmantion is not required. */ + String confirmationPrompt(); + + /** @see CommandInvoker#prepare(Consumer) */ + boolean prepare(Consumer printer) throws Exception; + + /** @see CommandInvoker#invoke(Consumer, boolean) */ + R invoke(Consumer printer, boolean verbose) throws Exception; + + /** */ + R invokeBeforeNodeStart(Consumer printer) throws Exception; +} diff --git a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java index 98c27b87667b1..4446ab51ce669 100644 --- a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java +++ b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java @@ -36,7 +36,12 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteLogger; -import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.client.ClientAuthenticationException; +import org.apache.ignite.client.ClientConnectionException; +import org.apache.ignite.client.SslMode; +import org.apache.ignite.configuration.ClientConfiguration; +import org.apache.ignite.configuration.ClientConnectorConfiguration; +import org.apache.ignite.configuration.ConnectorConfiguration; import org.apache.ignite.internal.client.GridClientAuthenticationException; import org.apache.ignite.internal.client.GridClientClosedException; import org.apache.ignite.internal.client.GridClientConfiguration; @@ -75,6 +80,7 @@ import static java.lang.System.lineSeparator; import static java.util.Objects.nonNull; import static org.apache.ignite.IgniteSystemProperties.IGNITE_ENABLE_EXPERIMENTAL_COMMAND; +import static org.apache.ignite.IgniteSystemProperties.getBoolean; import static org.apache.ignite.internal.IgniteVersionUtils.ACK_VER_STR; import static org.apache.ignite.internal.IgniteVersionUtils.COPYRIGHT; import static org.apache.ignite.internal.commandline.ArgumentParser.CMD_AUTO_CONFIRMATION; @@ -131,7 +137,13 @@ public class CommandHandler { public static final String DFLT_HOST = "127.0.0.1"; /** */ - public static final int DFLT_PORT = 11211; + public static final int DFLT_PORT = 10800; + + /** + * System property for backward compatibility. Will be removed in future releases. + * Enables connection to {@link ConnectorConfiguration REST connector} and forcefully sets default port to 11211. + */ + public static final String IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION = "IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION"; /** */ private final Scanner in = new Scanner(System.in); @@ -255,6 +267,13 @@ public int execute(List rawArgs) { cmdName = toFormattedCommandName(args.cmdPath().peekLast().getClass()).toUpperCase(); + if (useConnectorConnection() && !(args.command() instanceof HelpCommand)) { + logger.warning("WARNING: Deprecated protocol (ConnectorConfiguration) used to connect to cluster. " + + "It will be removed in the next releases. Please update the control utility connection arguments " + + "to use a thin client protocol: set up a port and/or SSL configuration " + + "releated to the ClientConnectorConfiguration on nodes."); + } + int tryConnectMaxCnt = 3; boolean suppliedAuth = !F.isEmpty(args.userName()) && !F.isEmpty(args.password()); @@ -263,8 +282,9 @@ public int execute(List rawArgs) { while (true) { try ( - CliCommandInvoker invoker = - new CliCommandInvoker<>(args.command(), args.commandArg(), getClientConfiguration(args)) + CloseableCliCommandInvoker invoker = useConnectorConnection() + ? new CliCommandInvoker<>(args.command(), args.commandArg(), getClientConfiguration(args)) + : new CliIgniteClientInvoker<>(args.command(), args.commandArg(), clientConfiguration(args)) ) { if (!invoker.prepare(logger::info)) return EXIT_CODE_OK; @@ -349,9 +369,15 @@ else if (args.command() instanceof BeforeNodeStartCommand) e = cause; logger.error("Connection to cluster failed. " + errorMessage(e)); - } + logger.error("Make sure you are connecting to the client connector (configured on a node via '" + + ClientConnectorConfiguration.class.getName() + "'). Connection to the REST connector was " + + "deprecated and will be removed for the control utility in future releases. Set up the '" + + IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION + "' system property to the 'true' to " + + "forcefully connect to the REST connector (configured on a node via '" + + ConnectorConfiguration.class.getName() + "'). "); + logger.info("Command [" + cmdName + "] finished with code: " + EXIT_CODE_CONNECTION_FAILED); if (verbose) @@ -446,6 +472,9 @@ private boolean isSSLMisconfigurationError(Throwable e) { * to secured cluster. */ private boolean isConnectionClosedSilentlyException(Throwable e) { + if (e instanceof ClientConnectionException && e.getMessage().startsWith("Channel is closed")) + return true; + if (!(e instanceof GridClientDisconnectedException)) return false; @@ -495,6 +524,36 @@ private String argumentsToString(List rawArgs) { return sb.toString(); } + /** + * @param args Common arguments. + * @return Thin client configuration to connect to cluster. + * @throws IgniteCheckedException If error occur. + */ + private ClientConfiguration clientConfiguration(ConnectionAndSslParameters args) throws IgniteCheckedException { + ClientConfiguration clientCfg = new ClientConfiguration(); + + clientCfg.setAddresses(args.host() + ":" + args.port()); + + if (!F.isEmpty(args.userName())) { + clientCfg.setUserName(args.userName()); + clientCfg.setUserPassword(args.password()); + } + + if (!F.isEmpty(args.sslKeyStorePath()) || !F.isEmpty(args.sslFactoryConfigPath())) { + if (!F.isEmpty(args.sslKeyStorePath()) && !F.isEmpty(args.sslFactoryConfigPath())) { + throw new IllegalArgumentException("Incorrect SSL configuration. SSL factory config path should " + + "not be specified simultaneously with other SSL options like keystore path."); + } + + clientCfg.setSslContextFactory(createSslSupportFactory(args)); + clientCfg.setSslMode(SslMode.REQUIRED); + } + + clientCfg.setClusterDiscoveryEnabled(false); + + return clientCfg; + } + /** * @param args Common arguments. * @return Thin client configuration to connect to cluster. @@ -531,7 +590,7 @@ private String argumentsToString(List rawArgs) { if (!F.isEmpty(args.sslKeyStorePath()) || !F.isEmpty(args.sslFactoryConfigPath())) { if (!F.isEmpty(args.sslKeyStorePath()) && !F.isEmpty(args.sslFactoryConfigPath())) - throw new IgniteCheckedException("Incorrect SSL configuration. " + + throw new IllegalArgumentException("Incorrect SSL configuration. " + "SSL factory config path should not be specified simultaneously with other SSL options like keystore path."); clientCfg.setSslContextFactory(createSslSupportFactory(args)); @@ -656,10 +715,11 @@ private boolean confirm(String str) { /** * @param e Exception to check. - * @return {@code true} if specified exception is {@link GridClientAuthenticationException}. + * @return {@code true} if specified exception is an authentication exception. */ public static boolean isAuthError(Throwable e) { - return X.hasCause(e, GridClientAuthenticationException.class); + return X.hasCause(e, GridClientAuthenticationException.class) + || X.hasCause(e, ClientAuthenticationException.class); } /** @@ -671,7 +731,8 @@ private static boolean isConnectionError(Throwable e) { e instanceof GridClientConnectionResetException || e instanceof GridClientDisconnectedException || e instanceof GridClientHandshakeException || - e instanceof GridServerUnreachableException; + e instanceof GridServerUnreachableException || + X.hasCause(e, ClientConnectionException.class); } /** @@ -708,7 +769,7 @@ private String requestDataFromConsole(String msg) { /** @param rawArgs Arguments. */ private void printHelp(List rawArgs) { boolean experimentalEnabled = rawArgs.stream().anyMatch(CMD_ENABLE_EXPERIMENTAL::equalsIgnoreCase) || - IgniteSystemProperties.getBoolean(IGNITE_ENABLE_EXPERIMENTAL_COMMAND); + getBoolean(IGNITE_ENABLE_EXPERIMENTAL_COMMAND); logger.info("Control utility script is used to execute admin commands on cluster or get common cluster info. " + "The command has the following syntax:"); @@ -949,6 +1010,11 @@ private static class LengthCalculator implements Consumer { } } + /** */ + public static boolean useConnectorConnection() { + return getBoolean(IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION); + } + /** */ public static class CommandName implements Consumer { /** */ diff --git a/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/SecurityCommandHandlerPermissionsTest.java b/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/SecurityCommandHandlerPermissionsTest.java index 59df6748ece5e..c56d8e2199094 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/SecurityCommandHandlerPermissionsTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/SecurityCommandHandlerPermissionsTest.java @@ -29,6 +29,7 @@ import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.security.impl.TestSecurityData; import org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider; +import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.plugin.security.SecurityPermission; import org.apache.ignite.plugin.security.SecurityPermissionSet; import org.apache.ignite.plugin.security.SecurityPermissionSetBuilder; @@ -64,7 +65,7 @@ public class SecurityCommandHandlerPermissionsTest extends GridCommandHandlerAbs /** */ @Parameterized.Parameters(name = "cmdHnd={0}") public static List commandHandlers() { - return Collections.singletonList(CLI_CMD_HND); + return F.asList(CLI_CMD_HND, CLI_GRID_CLIENT_CMD_HND); } /** {@inheritDoc} */ diff --git a/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/indexreader/IgniteIndexReaderTest.java b/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/indexreader/IgniteIndexReaderTest.java index fdc404820ce52..aeb0a57c96e34 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/indexreader/IgniteIndexReaderTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/indexreader/IgniteIndexReaderTest.java @@ -61,6 +61,7 @@ import org.apache.ignite.internal.util.GridUnsafe; import org.apache.ignite.internal.util.lang.GridTuple3; import org.apache.ignite.internal.util.lang.IgnitePair; +import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.A; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiTuple; @@ -155,7 +156,7 @@ public class IgniteIndexReaderTest extends GridCommandHandlerAbstractTest { /** */ @Parameterized.Parameters(name = "cmdHnd={0}") public static List commandHandlers() { - return Collections.singletonList(CLI_CMD_HND); + return F.asList(CLI_CMD_HND, CLI_GRID_CLIENT_CMD_HND); } /** {@inheritDoc} */ diff --git a/modules/control-utility/src/test/java/org/apache/ignite/internal/processors/security/GridCommandHandlerSslWithSecurityTest.java b/modules/control-utility/src/test/java/org/apache/ignite/internal/processors/security/GridCommandHandlerSslWithSecurityTest.java index dfcaaf113b21d..37797d9f4e23b 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/internal/processors/security/GridCommandHandlerSslWithSecurityTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/internal/processors/security/GridCommandHandlerSslWithSecurityTest.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.configuration.ClientConnectorConfiguration; import org.apache.ignite.configuration.ConnectorConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.IgniteEx; @@ -72,7 +73,7 @@ public class GridCommandHandlerSslWithSecurityTest extends GridCommandHandlerFac /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - Assume.assumeTrue(commandHandler.equalsIgnoreCase(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); super.beforeTest(); } @@ -97,14 +98,26 @@ protected void injectTestSystemOut() { /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { - return super.getConfiguration(igniteInstanceName) + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName) .setPluginProviders(new TestSecurityPluginProvider(login, pwd, ALL_PERMISSIONS, null, false)) - .setSslContextFactory(sslTrustedFactory("node01", "trustone")) - .setConnectorConfiguration( - new ConnectorConfiguration() - .setSslEnabled(true) - .setSslFactory(sslTrustedFactory("connectorServer", "trustthree")) + .setSslContextFactory(sslTrustedFactory("node01", "trustone")); + + if (commandHandler.equals(CLI_GRID_CLIENT_CMD_HND)) { + cfg.setConnectorConfiguration(new ConnectorConfiguration() + .setSslEnabled(true) + .setSslFactory(sslTrustedFactory("connectorServer", "trustthree")) + ); + } + + if (commandHandler.equals(CLI_CMD_HND)) { + cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration() + .setSslEnabled(true) + .setSslContextFactory(sslTrustedFactory("thinServer", "trusttwo")) + .setUseIgniteSslContextFactory(false) ); + } + + return cfg; } /** @@ -153,10 +166,10 @@ else if (fmt.contains("truststore")) { args.add(login); args.add("--keystore"); - args.add(keyStorePath("connectorServer")); + args.add(keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "thinClient" : "connectorServer")); args.add("--truststore"); - args.add(keyStorePath("trustthree")); + args.add(keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "trusttwo" : "trustthree")); assertEquals(EXIT_CODE_OK, cmd.execute(args)); assertEquals(1, keyStorePwdCnt.get()); @@ -180,9 +193,9 @@ public void testConnector() throws Exception { "--state", "--user", login, "--password", pwd, - "--keystore", keyStorePath("connectorClient"), + "--keystore", keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "thinClient" : "connectorServer"), "--keystore-password", keyStorePassword(), - "--truststore", keyStorePath("trustthree"), + "--truststore", keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "trusttwo" : "trustthree"), "--truststore-password", keyStorePassword())); assertEquals(EXIT_CODE_OK, exitCode); diff --git a/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite.java b/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite.java index 5a474670d9cc4..83146274ef535 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite.java @@ -34,6 +34,7 @@ import org.apache.ignite.util.GridCommandHandlerIndexingTest; import org.apache.ignite.util.GridCommandHandlerIndexingWithSSLTest; import org.apache.ignite.util.GridCommandHandlerInterruptCommandTest; +import org.apache.ignite.util.GridCommandHandlerLegacyClientTest; import org.apache.ignite.util.GridCommandHandlerMetadataTest; import org.apache.ignite.util.GridCommandHandlerSslTest; import org.apache.ignite.util.GridCommandHandlerTest; @@ -70,6 +71,7 @@ GridCommandHandlerInterruptCommandTest.class, GridCommandHandlerMetadataTest.class, GridCommandHandlerCheckIncrementalSnapshotTest.class, + GridCommandHandlerLegacyClientTest.class, KillCommandsControlShTest.class, diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/CdcCommandTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/CdcCommandTest.java index 9b78e79ce5e2e..90359af8c7fca 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/CdcCommandTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/CdcCommandTest.java @@ -208,7 +208,7 @@ public void testDeleteLostSegmentLinksApplicationNotClosed() throws Exception { String out = executeCommand(EXIT_CODE_UNEXPECTED_ERROR, CDC, DELETE_LOST_SEGMENT_LINKS, NODE_ID, srv0.localNode().id().toString()); - if (commandHandler.equals(CLI_CMD_HND)) + if (cliCommandHandler()) assertContains(log, out, "Failed to delete lost segment CDC links. Unable to acquire lock to lock CDC folder."); assertFalse(fut.isDone()); @@ -330,7 +330,7 @@ public void testResendCachesNotExist() { String out = executeCommand(EXIT_CODE_UNEXPECTED_ERROR, CDC, RESEND, CACHES, "unknown_cache"); - if (commandHandler.equals(CLI_CMD_HND)) + if (cliCommandHandler()) assertContains(log, out, "Cache does not exist"); String cdcDisabledCacheName = "cdcDisabledCache"; @@ -341,7 +341,7 @@ public void testResendCachesNotExist() { out = executeCommand(EXIT_CODE_UNEXPECTED_ERROR, CDC, RESEND, CACHES, cdcDisabledCacheName); - if (commandHandler.equals(CLI_CMD_HND)) + if (cliCommandHandler()) assertContains(log, out, "CDC is not enabled for given cache"); } @@ -372,7 +372,7 @@ public void testResendCancelOnNodeLeft() { /** */ @Test public void testResendCancelOnRebalanceInProgress() throws Exception { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); injectTestSystemOut(); @@ -426,7 +426,7 @@ public void testResendCancelOnTopologyChangeBeforeStart() throws Exception { String out = executeCommand(EXIT_CODE_UNEXPECTED_ERROR, CDC, RESEND, CACHES, DEFAULT_CACHE_NAME); - if (commandHandler.equals(CLI_CMD_HND)) + if (cliCommandHandler()) assertContains(log, out, "CDC cache data resend cancelled. Topology changed"); }); @@ -466,7 +466,7 @@ public void testResendCancelOnTopologyChange() throws Exception { String out = executeCommand(EXIT_CODE_UNEXPECTED_ERROR, CDC, RESEND, CACHES, DEFAULT_CACHE_NAME); - if (commandHandler.equals(CLI_CMD_HND)) + if (cliCommandHandler()) assertContains(log, out, "CDC cache data resend cancelled. Topology changed"); }); diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerAbstractTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerAbstractTest.java index 76a124ef409d8..cc4054a3ed217 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerAbstractTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerAbstractTest.java @@ -40,6 +40,7 @@ import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.configuration.AtomicConfiguration; import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.ClientConnectorConfiguration; import org.apache.ignite.configuration.ConnectorConfiguration; import org.apache.ignite.configuration.DataRegionConfiguration; import org.apache.ignite.configuration.DataStorageConfiguration; @@ -77,10 +78,12 @@ import static org.apache.ignite.configuration.EncryptionConfiguration.DFLT_REENCRYPTION_BATCH_SIZE; import static org.apache.ignite.configuration.EncryptionConfiguration.DFLT_REENCRYPTION_RATE_MBPS; import static org.apache.ignite.events.EventType.EVT_CONSISTENCY_VIOLATION; +import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_REST_TCP_PORT; import static org.apache.ignite.internal.commandline.ArgumentParser.CMD_AUTO_CONFIRMATION; import static org.apache.ignite.internal.encryption.AbstractEncryptionTest.KEYSTORE_PASSWORD; import static org.apache.ignite.internal.encryption.AbstractEncryptionTest.KEYSTORE_PATH; import static org.apache.ignite.internal.management.cache.VerifyBackupPartitionsDumpTask.IDLE_DUMP_FILE_PREFIX; +import static org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLIENT_LISTENER_PORT; /** * Common abstract class for testing {@link CommandHandler}. @@ -262,6 +265,7 @@ protected boolean idleVerifyRes(Path p) { cfg.setCommunicationSpi(new TestRecordingCommunicationSpi()); cfg.setConnectorConfiguration(new ConnectorConfiguration().setSslEnabled(sslEnabled())); + cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().setSslEnabled(sslEnabled())); if (sslEnabled()) cfg.setSslContextFactory(sslFactory()); @@ -529,4 +533,11 @@ protected void createCacheAndPreload( protected void createCacheAndPreload(Ignite ignite, int countEntries) { createCacheAndPreload(ignite, DEFAULT_CACHE_NAME, countEntries, 32, null); } + + /** */ + protected String connectorPort(IgniteEx srv) { + return srv.localNode().attribute(commandHandler.equals(CLI_GRID_CLIENT_CMD_HND) + ? ATTR_REST_TCP_PORT + : CLIENT_LISTENER_PORT).toString(); + } } diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java index b98b168a0786a..e9fd8090a175e 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java @@ -67,6 +67,7 @@ import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; import org.apache.ignite.cache.query.SqlFieldsQuery; import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.client.SslMode; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.configuration.AtomicConfiguration; import org.apache.ignite.configuration.BinaryConfiguration; @@ -225,16 +226,16 @@ public void testFindAndDeleteGarbage() { new CacheConfiguration<>("garbage1").setGroupName("groupGarbage"), new CacheConfiguration<>("garbage2").setGroupName("groupGarbage"))); - assertEquals(EXIT_CODE_OK, execute("--port", "11212", "--cache", "find_garbage")); + assertEquals(EXIT_CODE_OK, execute("--port", connectorPort(grid(1)), "--cache", "find_garbage")); assertContains(log, testOut.toString(), "garbage not found"); - assertEquals(EXIT_CODE_OK, execute("--port", "11212", "--cache", "find_garbage", + assertEquals(EXIT_CODE_OK, execute("--port", connectorPort(grid(1)), "--cache", "find_garbage", ignite(0).localNode().id().toString())); assertContains(log, testOut.toString(), "garbage not found"); - assertEquals(EXIT_CODE_OK, execute("--port", "11212", "--cache", "find_garbage", + assertEquals(EXIT_CODE_OK, execute("--port", connectorPort(grid(1)), "--cache", "find_garbage", "groupGarbage")); assertContains(log, testOut.toString(), "garbage not found"); @@ -399,7 +400,7 @@ public void testTransactionHistoryInfo() throws Exception { /** */ @Test public void testCacheHelp() throws Exception { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); injectTestSystemOut(); @@ -452,7 +453,7 @@ public void testCacheHelp() throws Exception { /** */ @Test public void testHelp() throws Exception { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); injectTestSystemOut(); @@ -530,7 +531,7 @@ public void testOldReadOnlyApiNotAvailable() { /** */ @Test public void testPrintTimestampAtEndsOfExecution() { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); injectTestSystemOut(); @@ -798,6 +799,11 @@ public void testCacheIdleVerifyDump() throws Exception { .setAutoBinaryConfigurationEnabled(false) .setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(false)); + if (sslEnabled()) { + cliCfg.setSslMode(SslMode.REQUIRED); + cliCfg.setSslContextFactory(sslFactory()); + } + try (IgniteClient cli = TcpIgniteClient.start(cliCfg)) { for (int i = keysCnt; i < keysCnt * 3; i++) cli.cache(DEFAULT_CACHE_NAME).put(new TestClass(i, String.valueOf(i)), i); @@ -1393,7 +1399,7 @@ public void testCacheCreate() { String out = executeCommand(EXIT_CODE_UNEXPECTED_ERROR, "--cache", CREATE, SPRING_XML_CONFIG, cfgPath + "/cache-create-with-spel.xml"); - if (commandHandler.equals(CLI_CMD_HND)) + if (cliCommandHandler()) assertContains(log, out, "Spring expressions are prohibited."); assertEquals(expSize, G.allGrids().size()); @@ -1469,7 +1475,7 @@ public void testCacheDestroy() throws IgniteCheckedException { injectTestSystemIn(CONFIRM_MSG); assertEquals(EXIT_CODE_OK, execute("--cache", DESTROY, DESTROY_ALL_ARG)); - if (commandHandler.equals(CLI_CMD_HND)) + if (cliCommandHandler()) assertContains(log, testOut.toString(), expConfirmation); assertTrue("Caches must be destroyed: " + crd.cacheNames().toString(), crd.cacheNames().isEmpty()); @@ -1497,7 +1503,7 @@ public void testCacheClear() { assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--cache", CLEAR, CACHES, "X,Y", "Z")); assertContains(log, testOut.toString(), "Unexpected argument: Z"); - if (commandHandler.equals(CLI_CMD_HND)) { + if (cliCommandHandler()) { autoConfirmation = false; String expConfirmation = String.format(CacheClearCommand.CONFIRM_MSG, 2, "cache1, cache2"); @@ -2308,7 +2314,7 @@ private IgniteInternalFuture startTransactions( @Test @WithSystemProperty(key = IGNITE_ENABLE_EXPERIMENTAL_COMMAND, value = "true") public void testContainsNotExperimentalCmdInHelpOutputWhenEnableExperimentalTrue() { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); checkContainsNotExperimentalCmdInHelpOutput(); } @@ -2322,7 +2328,7 @@ public void testContainsNotExperimentalCmdInHelpOutputWhenEnableExperimentalTrue @Test @WithSystemProperty(key = IGNITE_ENABLE_EXPERIMENTAL_COMMAND, value = "false") public void testContainsNotExperimentalCmdInHelpOutputWhenEnableExperimentalFalse() { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); checkContainsNotExperimentalCmdInHelpOutput(); } @@ -2334,7 +2340,7 @@ public void testContainsNotExperimentalCmdInHelpOutputWhenEnableExperimentalFals @Test @WithSystemProperty(key = IGNITE_ENABLE_EXPERIMENTAL_COMMAND, value = "true") public void testContainsExperimentalCmdInHelpOutput() { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); checkExperimentalCmdInHelpOutput(true); } @@ -2346,7 +2352,7 @@ public void testContainsExperimentalCmdInHelpOutput() { @Test @WithSystemProperty(key = IGNITE_ENABLE_EXPERIMENTAL_COMMAND, value = "false") public void testNotContainsExperimentalCmdInHelpOutput() { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); checkExperimentalCmdInHelpOutput(false); } @@ -2421,7 +2427,7 @@ public void testCorrectExecCmdWithVerboseInDiffParamsOrder() { */ @Test public void testErrInvalidArgumentsWithVerbose() { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); injectTestSystemOut(); @@ -2441,7 +2447,7 @@ public void testErrInvalidArgumentsWithVerbose() { */ @Test public void testErrConnectionWithVerbose() { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); injectTestSystemOut(); @@ -2461,7 +2467,7 @@ public void testErrConnectionWithVerbose() { */ @Test public void testErrUnexpectedWithWithoutVerbose() { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); injectTestSystemOut(); diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassWithSSLTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassWithSSLTest.java index 6a4a5f7c37c61..f090664a738df 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassWithSSLTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassWithSSLTest.java @@ -30,7 +30,7 @@ public class GridCommandHandlerClusterByClassWithSSLTest extends GridCommandHand /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - Assume.assumeTrue(commandHandler.equalsIgnoreCase(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); super.beforeTest(); } diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerDefragmentationTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerDefragmentationTest.java index f250b3d6c064d..5e80455d8dba4 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerDefragmentationTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerDefragmentationTest.java @@ -34,7 +34,6 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.IgniteNodeAttributes; import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; import org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationParameters; import org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory; @@ -188,7 +187,7 @@ public void testDefragmentationCancel() throws Exception { assertEquals(EXIT_CODE_OK, execute( cmd, "--port", - grid(0).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(), + connectorPort(grid(0)), "--defragmentation", "cancel" )); @@ -204,7 +203,7 @@ public void testDefragmentationCancel() throws Exception { assertEquals(EXIT_CODE_OK, execute( cmd, "--port", - grid(1).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(), + connectorPort(grid(1)), "--defragmentation", "cancel" )); @@ -242,7 +241,7 @@ public void testDefragmentationCancelInProgress() throws Exception { grid0ConsId )); - String port = grid(0).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(); + String port = connectorPort(grid(0)); stopGrid(0); @@ -354,7 +353,7 @@ public void testDefragmentationStatus() throws Exception { grid0ConsId )); - String port = grid(0).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(); + String port = connectorPort(grid(0)); stopGrid(0); diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerFactoryAbstractTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerFactoryAbstractTest.java index 2f979642d8b72..cedce0e4d7870 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerFactoryAbstractTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerFactoryAbstractTest.java @@ -56,10 +56,10 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_REST_TCP_PORT; import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_INVALID_ARGUMENTS; import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK; import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR; +import static org.apache.ignite.internal.commandline.CommandHandler.IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION; import static org.apache.ignite.internal.commandline.CommandHandler.setupJavaLogger; import static org.apache.ignite.internal.commandline.CommandLogger.errorMessage; import static org.apache.ignite.internal.management.api.CommandMBean.INVOKE; @@ -68,6 +68,7 @@ import static org.apache.ignite.internal.management.api.CommandUtils.isBoolean; import static org.apache.ignite.internal.management.api.CommandUtils.toFormattedCommandName; import static org.apache.ignite.internal.management.api.CommandUtils.visitCommandParams; +import static org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLIENT_LISTENER_PORT; /** Class to check command execution via all available handlers. */ @RunWith(Parameterized.class) @@ -75,6 +76,9 @@ public class GridCommandHandlerFactoryAbstractTest extends GridCommonAbstractTes /** @see JmxCommandHandler */ public static final String JMX_CMD_HND = "jmx"; + /** @see CliCommandHandler */ + public static final String CLI_GRID_CLIENT_CMD_HND = "cli_GridClient"; + /** @see CliCommandHandler */ public static final String CLI_CMD_HND = "cli"; @@ -120,6 +124,11 @@ protected TestCommandHandler newCommandHandler(@Nullable IgniteLogger log) { return CMD_HNDS.get(commandHandler).apply(log); } + /** */ + protected boolean cliCommandHandler() { + return commandHandler.equals(CLI_CMD_HND) || commandHandler.equals(CLI_GRID_CLIENT_CMD_HND); + } + /** */ public interface TestCommandHandler { /** */ @@ -135,6 +144,36 @@ public interface TestCommandHandler { public String name(); } + /** */ + public static class CliGridClientCommandHandler extends CliCommandHandler { + /** */ + public CliGridClientCommandHandler() { + super(); + } + + /** */ + public CliGridClientCommandHandler(@Nullable IgniteLogger log) { + super(log); + } + + /** {@inheritDoc} */ + @Override public int execute(List rawArgs) { + System.setProperty(IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION, "true"); + + try { + return super.execute(rawArgs); + } + finally { + System.clearProperty(IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION); + } + } + + /** {@inheritDoc} */ + @Override public String name() { + return CLI_GRID_CLIENT_CMD_HND; + } + } + /** */ public static class CliCommandHandler implements TestCommandHandler { /** */ @@ -281,7 +320,7 @@ private IgniteEx ignite(ConnectionAndSslParameters p) return ignite; for (Ignite node : IgnitionEx.allGrids()) { - Integer nodePort = ((IgniteEx)node).localNode().attribute(ATTR_REST_TCP_PORT); + Integer nodePort = ((IgniteEx)node).localNode().attribute(CLIENT_LISTENER_PORT); if (nodePort != null && port == nodePort) { this.port = port; @@ -333,6 +372,10 @@ private static String toString(Object val) { /** */ protected int commandHandlerExtraLines() { - return commandHandler.equals(CLI_CMD_HND) ? 11 : 0; + return CLI_CMD_HND.equals(commandHandler) + ? 11 + : CLI_GRID_CLIENT_CMD_HND.equals(commandHandler) + ? 12 // Deprecation message. + : 0; } } diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIncompatibleSslConfigTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIncompatibleSslConfigTest.java index d8fc8f3874311..d177243a416a0 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIncompatibleSslConfigTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIncompatibleSslConfigTest.java @@ -21,7 +21,7 @@ import org.junit.Assume; import org.junit.Test; -import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR; +import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_INVALID_ARGUMENTS; import static org.apache.ignite.testframework.GridTestUtils.assertContains; /** @@ -43,7 +43,7 @@ public class GridCommandHandlerIncompatibleSslConfigTest extends GridCommandHand /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - Assume.assumeTrue(commandHandler.equalsIgnoreCase(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); super.beforeTest(); } @@ -55,7 +55,7 @@ public void test() throws Exception { injectTestSystemOut(); - assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--set-state", "ACTIVE")); + assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--set-state", "ACTIVE")); assertContains(log, testOut.toString(), "Incorrect SSL configuration."); } diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexListTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexListTest.java index dd6e62b730d6e..6f6df903fa98f 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexListTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexListTest.java @@ -87,7 +87,7 @@ public void testCacheIndexList() { String outStr = testOut.toString(); - String typePattern = commandHandler.equals(CLI_CMD_HND) ? "ArrayList" : "LinkedKeySet"; + String typePattern = cliCommandHandler() ? "ArrayList" : "LinkedKeySet"; assertTrue(outStr.contains("grpName=" + GROUP_NAME + ", cacheName=" + CACHE_NAME + ", idxName=PERSON_ORGID_ASC_IDX, " + "colsNames=" + typePattern + " [ORGID, _KEY], tblName=PERSON")); @@ -139,7 +139,7 @@ public void tesAllArgs() { "--cache-name", CACHE_NAME, "--index-name", idxName)); - String typePattern = commandHandler.equals(CLI_CMD_HND) ? "ArrayList" : "LinkedKeySet"; + String typePattern = cliCommandHandler() ? "ArrayList" : "LinkedKeySet"; assertTrue(testOut.toString().contains("grpName=" + GROUP_NAME + ", cacheName=" + CACHE_NAME + ", idxName=PERSON_ORGID_ASC_IDX, colsNames=" + typePattern + " [ORGID, _KEY], tblName=PERSON")); diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingWithSSLTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingWithSSLTest.java index 178024460ea87..2921f7d5c6e2a 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingWithSSLTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingWithSSLTest.java @@ -30,7 +30,7 @@ public class GridCommandHandlerIndexingWithSSLTest extends GridCommandHandlerInd /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - Assume.assumeTrue(commandHandler.equalsIgnoreCase(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); super.beforeTest(); } diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerInterruptCommandTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerInterruptCommandTest.java index 3235e8e470a45..75ce8c41a765a 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerInterruptCommandTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerInterruptCommandTest.java @@ -67,7 +67,7 @@ public class GridCommandHandlerInterruptCommandTest extends GridCommandHandlerAb /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(commandHandler.equals(CLI_GRID_CLIENT_CMD_HND)); super.beforeTest(); diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerLegacyClientTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerLegacyClientTest.java new file mode 100644 index 0000000000000..9e95efdaee33d --- /dev/null +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerLegacyClientTest.java @@ -0,0 +1,148 @@ +/* + * 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.util; + +import org.apache.ignite.configuration.ClientConnectorConfiguration; +import org.apache.ignite.configuration.ConnectorConfiguration; +import org.apache.ignite.internal.commandline.CommandHandler; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.ListeningTestLogger; +import org.apache.ignite.testframework.LogListener; +import org.apache.ignite.testframework.junits.GridAbstractTest; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +import static org.apache.ignite.internal.commandline.CommandHandler.IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION; +import static org.apache.ignite.testframework.GridTestUtils.keyStorePassword; +import static org.apache.ignite.testframework.GridTestUtils.keyStorePath; +import static org.apache.ignite.testframework.GridTestUtils.sslTrustedFactory; + +/** */ +public class GridCommandHandlerLegacyClientTest extends GridCommonAbstractTest { + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + } + + /** */ + @Test + public void testDefaultConfiguration() throws Exception { + startGrid(); + + checkExecute("Cluster state: ACTIVE", "--state"); + } + + /** */ + @Test + public void testNonDefaultPort() throws Exception { + int port = 11212; + + startGrid(getConfiguration() + .setConnectorConfiguration(new ConnectorConfiguration() + .setPort(port))); + + checkExecute("Make sure you are connecting to the client connector", "--port", String.valueOf(port), "--state"); + + System.setProperty(IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION, "true"); + + try { + checkExecute("Cluster state: ACTIVE", "--port", String.valueOf(port), "--state"); + } + finally { + System.clearProperty(IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION); + } + + checkExecute("Cluster state: ACTIVE", "--state"); + } + + /** */ + @Test + public void testCustomSsl() throws Exception { + startGrid(getConfiguration() + .setClientConnectorConfiguration(new ClientConnectorConfiguration() + .setSslEnabled(true) + .setUseIgniteSslContextFactory(false) + .setSslContextFactory(sslTrustedFactory("thinServer", "trusttwo"))) + .setConnectorConfiguration(new ConnectorConfiguration() + .setSslEnabled(true) + .setSslFactory(sslTrustedFactory("connectorServer", "trustthree")))); + + checkExecute("Make sure you are connecting to the client connector", + "--keystore", GridTestUtils.keyStorePath("connectorClient"), + "--keystore-password", GridTestUtils.keyStorePassword(), + "--truststore", keyStorePath("trustthree"), + "--truststore-password", keyStorePassword(), + "--state"); + + System.setProperty(IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION, "true"); + + try { + checkExecute("Cluster state: ACTIVE", + "--keystore", GridTestUtils.keyStorePath("connectorClient"), + "--keystore-password", GridTestUtils.keyStorePassword(), + "--truststore", keyStorePath("trustthree"), + "--truststore-password", keyStorePassword(), + "--state"); + } + finally { + System.clearProperty(IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION); + } + + checkExecute("Cluster state: ACTIVE", + "--keystore", GridTestUtils.keyStorePath("thinClient"), + "--keystore-password", GridTestUtils.keyStorePassword(), + "--truststore", keyStorePath("trusttwo"), + "--truststore-password", keyStorePassword(), + "--state"); + } + + /** */ + @Test + public void testClientConnectorDisabled() throws Exception { + startGrid(getConfiguration() + .setClientConnectorConfiguration(null) + .setConnectorConfiguration(new ConnectorConfiguration())); + + checkExecute("Make sure you are connecting to the client connector", "--state"); + + System.setProperty(IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION, "true"); + + try { + checkExecute("Cluster state: ACTIVE", "--state"); + } + finally { + System.clearProperty(IGNITE_CONTROL_UTILITY_USE_CONNECTOR_CONNECTION); + } + } + + /** */ + private void checkExecute(String expMsg, String... params) { + ListeningTestLogger log = new ListeningTestLogger(GridAbstractTest.log); + + LogListener lsnr = LogListener.matches(expMsg).build(); + + log.registerListener(lsnr); + + new CommandHandler(log).execute(F.asList(params)); + + assertTrue(lsnr.check()); + } +} diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerMetadataTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerMetadataTest.java index c2938b75e9eb5..621937e18f9f1 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerMetadataTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerMetadataTest.java @@ -22,15 +22,9 @@ import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.sql.Statement; import java.time.LocalDate; import java.util.Collection; import java.util.Date; -import java.util.HashMap; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; @@ -38,13 +32,10 @@ import org.apache.ignite.IgniteBinary; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteLogger; -import org.apache.ignite.Ignition; import org.apache.ignite.binary.BinaryObject; import org.apache.ignite.binary.BinaryObjectBuilder; import org.apache.ignite.binary.BinaryObjectException; import org.apache.ignite.binary.BinaryType; -import org.apache.ignite.client.ClientCacheConfiguration; -import org.apache.ignite.client.IgniteClient; import org.apache.ignite.configuration.ClientConfiguration; import org.apache.ignite.internal.binary.BinarySchema; import org.apache.ignite.internal.binary.BinaryTypeImpl; @@ -354,95 +345,6 @@ public void testRemoveUpdate() throws Exception { } } - /** - * Check the all thin connections are dropped on the command '--meta remove' and '--meta update'. - * Steps: - * - opens thin client connection. - * - creates Type0 on thin client side. - * - removes type by cmd line util. - * - executes any command on thin client to detect disconnect. - * - creates Type0 on thin client side with other type of field (checks the type was removed). - */ - @Test - public void testDropThinConnectionsOnRemove() throws Exception { - Path typeFile = FS.getPath("type0.bin"); - - try (IgniteClient cli = Ignition.startClient(clientConfiguration())) { - createType(cli.binary(), "Type0", 1); - - assertEquals(EXIT_CODE_OK, execute("--meta", "remove", - "--typeName", "Type0", - "--out", typeFile.toString())); - - // Executes command to check disconnect / reconnect. - GridTestUtils.assertThrows(log, () -> - cli.createCache(new ClientCacheConfiguration().setName("test")), - Exception.class, null); - - createType(cli.binary(), "Type0", "str"); - } - finally { - if (Files.exists(typeFile)) - Files.delete(typeFile); - } - } - - /** - * Check the all thin connections are dropped on the command '--meta remove' and '--meta update'. - * Steps: - * - opens JDBC thin client connection. - * - executes: CREATE TABLE test(id INT PRIMARY KEY, objVal OTHER). - * - inserts the instance of the 'TestValue' class to the table. - * - removes the type 'TestValue' by cmd line. - * - executes any command on JDBC driver to detect disconnect. - * - checks metadata on client side. It must be empty. - */ - @Test - public void testDropJdbcThinConnectionsOnRemove() throws Exception { - Path typeFile = FS.getPath("type0.bin"); - - try (Connection conn = DriverManager.getConnection(jdbcThinUrl())) { - try (final Statement stmt = conn.createStatement()) { - stmt.execute("CREATE TABLE test(id INT PRIMARY KEY, objVal OTHER)"); - - try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO test(id, objVal) VALUES (?, ?)")) { - pstmt.setInt(1, 0); - pstmt.setObject(2, new TestValue()); - - pstmt.execute(); - } - - stmt.execute("DELETE FROM test WHERE id >= 0"); - } - - HashMap metasOld = GridTestUtils.getFieldValue(conn, "metaHnd", "cache", "metas"); - - assertFalse(metasOld.isEmpty()); - - assertEquals(EXIT_CODE_OK, execute("--meta", "remove", - "--typeName", TestValue.class.getName(), - "--out", typeFile.toString())); - - // Executes any command to check disconnect. - GridTestUtils.assertThrows(log, () -> { - try (Statement stmt = conn.createStatement()) { - stmt.execute("SELECT * FROM test"); - } - - return null; - }, SQLException.class, "Failed to communicate with Ignite cluster"); - - HashMap metas = GridTestUtils.getFieldValue(conn, "metaHnd", "cache", "metas"); - - assertNotSame(metasOld, metas); - assertTrue(metas.isEmpty()); - } - finally { - if (Files.exists(typeFile)) - Files.delete(typeFile); - } - } - /** * Check the type successfully merged after remove-recreate-update operations. * Steps: diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerPropertiesTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerPropertiesTest.java index c81733098d4fc..ea247e0fbce23 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerPropertiesTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerPropertiesTest.java @@ -61,7 +61,7 @@ public void clear() { */ @Test public void testHelp() { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); assertEquals(EXIT_CODE_OK, execute("--property", "help")); diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerSslTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerSslTest.java index d41a43377b598..c393f3bc81d8b 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerSslTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerSslTest.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.List; import org.apache.ignite.Ignite; +import org.apache.ignite.configuration.ClientConnectorConfiguration; import org.apache.ignite.configuration.ConnectorConfiguration; import org.apache.ignite.configuration.DataStorageConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; @@ -55,7 +56,7 @@ public class GridCommandHandlerSslTest extends GridCommandHandlerClusterPerMetho /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - Assume.assumeTrue(commandHandler.equalsIgnoreCase(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); super.beforeTest(); } @@ -68,10 +69,18 @@ public class GridCommandHandlerSslTest extends GridCommandHandlerClusterPerMetho cfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration().setMaxSize(100 * 1024 * 1024); cfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration().setPersistenceEnabled(true); - cfg.setConnectorConfiguration(new ConnectorConfiguration()); - cfg.getConnectorConfiguration().setSslEnabled(true); cfg.setSslContextFactory(createSslFactory()); + if (commandHandler.equals(CLI_GRID_CLIENT_CMD_HND)) { + cfg.setConnectorConfiguration(new ConnectorConfiguration() + .setSslEnabled(true)); + } + + if (commandHandler.equals(CLI_CMD_HND)) { + cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration() + .setSslEnabled(true)); + } + return cfg; } diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java index 51dd7ff9629f1..d489a67192d08 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java @@ -77,7 +77,6 @@ import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.IgniteInterruptedCheckedException; -import org.apache.ignite.internal.IgniteNodeAttributes; import org.apache.ignite.internal.TestRecordingCommunicationSpi; import org.apache.ignite.internal.client.GridClientFactory; import org.apache.ignite.internal.client.impl.GridClientImpl; @@ -271,7 +270,7 @@ public void testActivate() throws Exception { assertEquals(ACTIVE, ignite.cluster().state()); - if (commandHandler.equals(CLI_CMD_HND)) + if (cliCommandHandler()) assertContains(log, testOut.toString(), "Command deprecated. Use --set-state instead."); } @@ -282,7 +281,7 @@ public void testActivate() throws Exception { */ @Test public void testClientsLeakage() throws Exception { - Assume.assumeTrue(commandHandler.equalsIgnoreCase(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); startGrids(1); @@ -400,7 +399,7 @@ public void testPersistenceCleanSpecifiedCachesCommand() throws Exception { IgniteEx ig1 = startGrid(1); - String port = ig1.localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(); + String port = connectorPort(ig1); assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute( "--host", "localhost", "--port", port, @@ -466,7 +465,7 @@ public void testPersistenceCleanCorruptedCachesCommand() throws Exception { IgniteEx ig1 = startGrid(1); - String port = ig1.localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(); + String port = connectorPort(ig1); assertEquals(EXIT_CODE_OK, execute("--host", "localhost", "--port", port, "--persistence")); assertEquals(EXIT_CODE_OK, execute("--host", "localhost", "--port", port, "--persistence", "info")); @@ -510,9 +509,8 @@ public void testPersistenceCleanAllCachesCommand() throws Exception { IgniteEx ig1 = startGrid(1); - String port = ig1.localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(); - - assertEquals(EXIT_CODE_OK, execute("--host", "localhost", "--port", port, "--persistence", "clean", "all")); + assertEquals(EXIT_CODE_OK, execute("--host", "localhost", "--port", connectorPort(ig1), + "--persistence", "clean", "all")); boolean allEmpty = Arrays.stream(mntcNodeWorkDir.listFiles()) .filter(File::isDirectory) @@ -548,9 +546,8 @@ public void testPersistenceBackupAllCachesCommand() throws Exception { IgniteEx ig1 = startGrid(1); - String port = ig1.localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(); - - assertEquals(EXIT_CODE_OK, execute("--host", "localhost", "--port", port, "--persistence", "backup", "all")); + assertEquals(EXIT_CODE_OK, execute("--host", "localhost", "--port", connectorPort(ig1), + "--persistence", "backup", "all")); Set backedUpCacheDirs = Arrays.stream(mntcNodeWorkDir.listFiles()) .filter(File::isDirectory) @@ -589,9 +586,7 @@ public void testPersistenceBackupCorruptedCachesCommand() throws Exception { IgniteEx ig1 = startGrid(1); - String port = ig1.localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(); - - assertEquals(EXIT_CODE_OK, execute("--host", "localhost", "--port", port, + assertEquals(EXIT_CODE_OK, execute("--host", "localhost", "--port", connectorPort(ig1), "--persistence", "backup", "corrupted")); long backedUpCachesCnt = Arrays.stream(mntcNodeWorkDir.listFiles()) @@ -629,7 +624,7 @@ public void testPersistenceBackupSpecifiedCachesCommand() throws Exception { IgniteEx ig1 = startGrid(1); - String port = ig1.localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString(); + String port = connectorPort(ig1);; assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--host", "localhost", "--port", port, "--persistence", "backup", "caches", @@ -776,7 +771,7 @@ public void testDeactivate() throws Exception { assertFalse(ignite.cluster().state().active()); assertEquals(INACTIVE, ignite.cluster().state()); - if (commandHandler.equals(CLI_CMD_HND)) + if (cliCommandHandler()) assertContains(log, testOut.toString(), "Command deprecated. Use --set-state instead."); } @@ -904,7 +899,7 @@ private void deactivateWithCheckClusterNameInConfirmation(IgniteEx igniteEx, Str assertEquals(EXIT_CODE_OK, execute("--deactivate")); assertFalse(igniteEx.cluster().state().active()); - if (commandHandler.equals(CLI_CMD_HND)) { + if (cliCommandHandler()) { assertContains( log, testOut.toString(), @@ -1149,7 +1144,7 @@ public void testBaselineCollectCrd() throws Exception { injectTestSystemOut(); - assertEquals(EXIT_CODE_OK, execute("--port", "11212", "--baseline")); + assertEquals(EXIT_CODE_OK, execute("--port", connectorPort(grid(0)), "--baseline")); String crdStr = findCrdInfo(); @@ -1158,7 +1153,7 @@ public void testBaselineCollectCrd() throws Exception { stopGrid(0); - assertEquals(EXIT_CODE_OK, execute("--port", "11212", "--baseline")); + assertEquals(EXIT_CODE_OK, execute("--port", connectorPort(grid(1)), "--baseline")); crdStr = findCrdInfo(); @@ -1167,7 +1162,7 @@ public void testBaselineCollectCrd() throws Exception { startGrid(0); - assertEquals(EXIT_CODE_OK, execute("--port", "11212", "--baseline")); + assertEquals(EXIT_CODE_OK, execute("--port", connectorPort(grid(1)), "--baseline")); crdStr = findCrdInfo(); @@ -1176,7 +1171,7 @@ public void testBaselineCollectCrd() throws Exception { stopGrid(1); - assertEquals(EXIT_CODE_OK, execute("--port", "11211", "--baseline")); + assertEquals(EXIT_CODE_OK, execute("--port", connectorPort(grid(0)), "--baseline")); crdStr = findCrdInfo(); @@ -2086,7 +2081,7 @@ public void testBaselineAddOnNotActiveCluster() throws Exception { assertTrue(testOutStr, testOutStr.contains("Node not found for consistent ID:")); - if (commandHandler.equals(CLI_CMD_HND)) + if (cliCommandHandler()) assertFalse(testOutStr, isInstance1Found); } @@ -2147,7 +2142,7 @@ public void testIdleVerifyCheckCrcFailsOnNotIdleCluster() throws Exception { */ @Test public void testCacheIdleVerifyDumpWhenNodeFailing() throws Exception { - Assume.assumeTrue("CHECKME", CLI_CMD_HND.equalsIgnoreCase(commandHandler)); + Assume.assumeTrue("CHECKME", cliCommandHandler()); Ignite ignite = startGrids(3); @@ -2529,7 +2524,7 @@ public void testDiagnosticPageLocksTracker() throws Exception { ignite.cluster().state(ACTIVE); - if (commandHandler.equals(CLI_CMD_HND)) { + if (cliCommandHandler()) { assertEquals( EXIT_CODE_OK, execute("--diagnostic") @@ -3163,11 +3158,13 @@ public void testClusterSnapshotCreateSynchronously() throws Exception { public void testClusterCreateSnapshotWarning() throws Exception { IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(0)); cfg.getConnectorConfiguration().setHost("localhost"); + cfg.getClientConnectorConfiguration().setHost("localhost"); IgniteEx ig = startGrid(cfg); cfg = getConfiguration(getTestIgniteInstanceName(1)); cfg.getConnectorConfiguration().setHost("localhost"); + cfg.getClientConnectorConfiguration().setHost("localhost"); startGrid(cfg); @@ -3389,7 +3386,7 @@ public void testSnapshotRestoreSynchronously() throws Exception { // Cache exists. assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--snapshot", "restore", snpName, "--start", "--sync")); - if (commandHandler.equals(CLI_CMD_HND)) { + if (cliCommandHandler()) { assertContains(log, testOut.toString(), "Command option '--start' is redundant and must be avoided."); assertContains(log, testOut.toString(), "Unable to restore cache group - directory is not empty. " + "Cache group should be destroyed manually before perform restore operation [group=" + cacheName); @@ -3399,7 +3396,7 @@ public void testSnapshotRestoreSynchronously() throws Exception { awaitPartitionMapExchange(); assertEquals(EXIT_CODE_OK, execute("--snapshot", "restore", snpName, "--sync")); - if (commandHandler.equals(CLI_CMD_HND)) { + if (cliCommandHandler()) { assertNotContains(log, testOut.toString(), "Command option '--start' is redundant and must be avoided."); assertContains(log, testOut.toString(), "Snapshot cache group restore operation completed successfully"); } @@ -3519,7 +3516,7 @@ public void testSnapshotRestore() throws Exception { else assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName)); - if (commandHandler.equals(CLI_CMD_HND)) { + if (cliCommandHandler()) { String out = testOut.toString(); assertContains(log, out, "Warning: command will restore ALL USER-CREATED CACHE GROUPS from the snapshot"); assertContains(log, out, "Snapshot cache group restore operation started [name=" + snpName); @@ -3930,7 +3927,7 @@ public void testCleaningGarbageAfterCacheDestroyedAndNodeStop_ControlConsoleUtil */ @Test public void testSuccessStopWarmUp() throws Exception { - Assume.assumeTrue(CLI_CMD_HND.equalsIgnoreCase(commandHandler)); + Assume.assumeTrue(cliCommandHandler()); WarmUpTestPluginProvider provider = new WarmUpTestPluginProvider(); @@ -3938,6 +3935,7 @@ public void testSuccessStopWarmUp() throws Exception { cfg.getDataStorageConfiguration().setDefaultWarmUpConfiguration(new BlockedWarmUpConfiguration()); cfg.getConnectorConfiguration().setHost("localhost"); + cfg.getClientConnectorConfiguration().setHost("localhost"); IgniteInternalFuture fut = runAsync(() -> startGrid(cfg)); @@ -3970,7 +3968,7 @@ public void testSuccessStopWarmUp() throws Exception { */ @Test public void testFailStopWarmUp() throws Exception { - Assume.assumeTrue(commandHandler.equalsIgnoreCase(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); startGrid(0); @@ -4028,8 +4026,8 @@ private FindAndDeleteGarbageInPersistenceTaskResult executeTaskViaControlConsole ) { TestCommandHandler hnd = newCommandHandler(); - List args = new ArrayList<>(Arrays.asList("--yes", "--port", "11212", "--cache", "find_garbage", - ignite.localNode().id().toString())); + List args = new ArrayList<>(Arrays.asList("--yes", "--port", connectorPort(ignite), + "--cache", "find_garbage", ignite.localNode().id().toString())); if (delFoundGarbage) args.add("--delete"); diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerWithSslFactoryTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerWithSslFactoryTest.java index f16e7a886fa8f..0ffc6aae3fd45 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerWithSslFactoryTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerWithSslFactoryTest.java @@ -49,7 +49,7 @@ public class GridCommandHandlerWithSslFactoryTest extends GridCommandHandlerWith /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - Assume.assumeTrue(commandHandler.equalsIgnoreCase(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); super.beforeTest(); } @@ -63,7 +63,7 @@ public static void tearDown() { /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - Assume.assumeTrue(commandHandler.equalsIgnoreCase(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); super.afterTest(); diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerWithSslTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerWithSslTest.java index ba3c1467ba8d1..ac3100da60781 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerWithSslTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerWithSslTest.java @@ -30,7 +30,7 @@ public class GridCommandHandlerWithSslTest extends GridCommandHandlerTest { /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - Assume.assumeTrue(commandHandler.equalsIgnoreCase(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); super.beforeTest(); } diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/KillCommandsControlShTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/KillCommandsControlShTest.java index d57f8f8b15756..b7cc45dc9c622 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/KillCommandsControlShTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/KillCommandsControlShTest.java @@ -45,6 +45,7 @@ import org.junit.Test; import static java.util.Arrays.asList; +import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_CONNECTION_FAILED; import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_INVALID_ARGUMENTS; import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK; import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR; @@ -184,7 +185,14 @@ public void testCancelClientConnection() { if (nodeId != null) params.addAll(asList("--node-id", nodeId.toString())); - assertEquals(EXIT_CODE_OK, execute(params)); + if (connId == null && commandHandler.equals(CLI_CMD_HND)) { + injectTestSystemOut(); + + assertEquals(EXIT_CODE_CONNECTION_FAILED, execute(params)); + assertContains(log, testOut.toString(), "The command throws the expected 'ClientConnectionException'"); + } + else + assertEquals(EXIT_CODE_OK, execute(params)); }); } @@ -287,7 +295,7 @@ public void testCancelConsistencyTaskSequential() throws InterruptedException { * */ private void testCancelConsistencyTask(boolean parallel) throws InterruptedException { - Assume.assumeTrue(commandHandler.equals(CLI_CMD_HND)); + Assume.assumeTrue(cliCommandHandler()); String consistencyCacheName = "consistencyCache"; diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/MetricCommandTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/MetricCommandTest.java index 3197a041273f0..7450bad6783c4 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/MetricCommandTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/MetricCommandTest.java @@ -471,7 +471,7 @@ private String metric(IgniteEx node, String name) { * @return Metric values. */ private Map parseMetricCommandOutput(String out) { - if (commandHandler.equals(CLI_CMD_HND)) { + if (cliCommandHandler()) { String outStart = "--------------------------------------------------------------------------------"; String outEnd = "Command [METRIC] finished with code: " + EXIT_CODE_OK; diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/SystemViewCommandTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/SystemViewCommandTest.java index 95a8e79a84fcc..c3c2ed906194b 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/SystemViewCommandTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/SystemViewCommandTest.java @@ -364,7 +364,7 @@ public void testClientsConnections() throws Exception { IgniteClient ignored1 = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port)); Connection ignored2 = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties()) ) { - assertEquals(2, systemView(ignite0, CLI_CONN_VIEW).size()); + assertEquals(commandHandler.equals(CLI_CMD_HND) ? 3 : 2, systemView(ignite0, CLI_CONN_VIEW).size()); } } @@ -1282,7 +1282,7 @@ private Map>> systemView(Collection nodes, Str * @return System view values. */ private Map>> parseSystemViewCommandOutput(String out) { - if (commandHandler.equals(CLI_CMD_HND)) { + if (cliCommandHandler()) { String outStart = "--------------------------------------------------------------------------------"; String outEnd = "Command [SYSTEM-VIEW] finished with code: " + EXIT_CODE_OK; diff --git a/modules/control-utility/src/test/resources/META-INF/services/org.apache.ignite.util.GridCommandHandlerFactoryAbstractTest$TestCommandHandler b/modules/control-utility/src/test/resources/META-INF/services/org.apache.ignite.util.GridCommandHandlerFactoryAbstractTest$TestCommandHandler index adfad81101539..e9dc47698fe7c 100644 --- a/modules/control-utility/src/test/resources/META-INF/services/org.apache.ignite.util.GridCommandHandlerFactoryAbstractTest$TestCommandHandler +++ b/modules/control-utility/src/test/resources/META-INF/services/org.apache.ignite.util.GridCommandHandlerFactoryAbstractTest$TestCommandHandler @@ -1,2 +1,3 @@ org.apache.ignite.util.GridCommandHandlerFactoryAbstractTest$JmxCommandHandler -org.apache.ignite.util.GridCommandHandlerFactoryAbstractTest$CliCommandHandler \ No newline at end of file +org.apache.ignite.util.GridCommandHandlerFactoryAbstractTest$CliCommandHandler +org.apache.ignite.util.GridCommandHandlerFactoryAbstractTest$CliGridClientCommandHandler \ No newline at end of file diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/ActivateCommand.java b/modules/core/src/main/java/org/apache/ignite/internal/management/ActivateCommand.java index f87aa812085b1..8442afcd8cef7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/management/ActivateCommand.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/management/ActivateCommand.java @@ -19,6 +19,7 @@ import java.util.function.Consumer; import org.apache.ignite.Ignite; +import org.apache.ignite.client.IgniteClient; import org.apache.ignite.internal.client.GridClient; import org.apache.ignite.internal.client.GridClientClusterState; import org.apache.ignite.internal.client.GridClientException; @@ -44,6 +45,7 @@ public class ActivateCommand implements LocalCommand { /** {@inheritDoc} */ @Override public NoArg execute( @Nullable GridClient cli, + @Nullable IgniteClient client, @Nullable Ignite ignite, NoArg arg, Consumer printer @@ -53,6 +55,8 @@ public class ActivateCommand implements LocalCommand { state.state(ACTIVE, false); } + else if (client != null) + client.cluster().state(ACTIVE); else ignite.cluster().state(ACTIVE); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/DeactivateCommand.java b/modules/core/src/main/java/org/apache/ignite/internal/management/DeactivateCommand.java index 24e7c9c3ef83c..11b98852a77bd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/management/DeactivateCommand.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/management/DeactivateCommand.java @@ -17,16 +17,24 @@ package org.apache.ignite.internal.management; +import java.util.Collections; import java.util.function.Consumer; import org.apache.ignite.Ignite; +import org.apache.ignite.client.IgniteClient; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.client.GridClient; import org.apache.ignite.internal.client.GridClientClusterState; import org.apache.ignite.internal.client.GridClientException; +import org.apache.ignite.internal.client.GridClientNode; +import org.apache.ignite.internal.client.thin.ClientClusterImpl; import org.apache.ignite.internal.cluster.IgniteClusterEx; +import org.apache.ignite.internal.management.api.CommandUtils; import org.apache.ignite.internal.management.api.LocalCommand; import org.apache.ignite.internal.management.api.NoArg; import org.apache.ignite.internal.management.api.PreparableCommand; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.visor.misc.VisorIdAndTagViewTask; +import org.apache.ignite.internal.visor.misc.VisorIdAndTagViewTaskResult; import org.jetbrains.annotations.Nullable; import static org.apache.ignite.cluster.ClusterState.INACTIVE; @@ -52,6 +60,7 @@ public class DeactivateCommand implements LocalCommand printer @@ -61,6 +70,8 @@ public class DeactivateCommand implements LocalCommand printer - ) throws GridClientException { - arg.clusterName(cli != null ? cli.state().clusterName() : ((IgniteEx)ignite).context().cluster().clusterName()); + ) throws Exception { + String clusterName; + + if (cli != null) + clusterName = cli.state().clusterName(); + else if (ignite != null) + clusterName = ((IgniteEx)ignite).context().cluster().clusterName(); + else { + GridClientNode node = F.first(CommandUtils.nodes(cli, client, ignite)); + + VisorIdAndTagViewTaskResult idAndTag = CommandUtils.execute(cli, client, ignite, + VisorIdAndTagViewTask.class, null, Collections.singleton(node)); + + clusterName = idAndTag.clusterName(); + } + + arg.clusterName(clusterName); return true; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/SetStateCommand.java b/modules/core/src/main/java/org/apache/ignite/internal/management/SetStateCommand.java index f6ee5994cbd49..fde589fd4056c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/management/SetStateCommand.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/management/SetStateCommand.java @@ -19,9 +19,11 @@ import java.util.function.Consumer; import org.apache.ignite.Ignite; +import org.apache.ignite.client.IgniteClient; import org.apache.ignite.cluster.ClusterState; import org.apache.ignite.internal.client.GridClient; import org.apache.ignite.internal.client.GridClientException; +import org.apache.ignite.internal.client.thin.ClientClusterImpl; import org.apache.ignite.internal.cluster.IgniteClusterEx; import org.apache.ignite.internal.management.api.LocalCommand; import org.jetbrains.annotations.Nullable; @@ -41,11 +43,16 @@ public class SetStateCommand implements LocalCommand printer ) throws GridClientException { - ClusterState clusterState = cli != null ? cli.state().state() : ignite.cluster().state(); + ClusterState clusterState = cli != null + ? cli.state().state() + : client != null + ? client.cluster().state() + : ignite.cluster().state(); if (clusterState == arg.state()) { printer.accept("Cluster state is already " + arg.state() + '.'); @@ -55,8 +62,10 @@ public class SetStateCommand implements LocalCommand execute( @Nullable GridClient cli, + @Nullable IgniteClient client, @Nullable Ignite ignite, NoArg arg, Consumer printer @@ -61,6 +67,14 @@ public class StateCommand implements LocalCommand } /** {@inheritDoc} */ - @Override public Boolean execute(GridClientBeforeNodeStart cli, NoArg arg, Consumer printer) throws Exception { - cli.beforeStartState().stopWarmUp(); + @Override public Boolean execute(GridClientNodeStateBeforeStart beforeStart, NoArg arg, Consumer printer) throws Exception { + beforeStart.stopWarmUp(); return true; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/api/BeforeNodeStartCommand.java b/modules/core/src/main/java/org/apache/ignite/internal/management/api/BeforeNodeStartCommand.java index 9419acdcf317f..1018ad06d0e5f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/management/api/BeforeNodeStartCommand.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/management/api/BeforeNodeStartCommand.java @@ -19,6 +19,7 @@ import java.util.function.Consumer; import org.apache.ignite.internal.client.GridClientBeforeNodeStart; +import org.apache.ignite.internal.client.GridClientNodeStateBeforeStart; import org.apache.ignite.internal.dto.IgniteDataTransferObject; /** @@ -26,10 +27,10 @@ */ public interface BeforeNodeStartCommand extends Command { /** - * @param cli Grid client instance. + * @param beforeStart {@link GridClientBeforeNodeStart} client instance. * @param arg Command argument. * @param printer Results printer. * @return Command result. */ - public R execute(GridClientBeforeNodeStart cli, A arg, Consumer printer) throws Exception; + public R execute(GridClientNodeStateBeforeStart beforeStart, A arg, Consumer printer) throws Exception; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/api/CommandInvoker.java b/modules/core/src/main/java/org/apache/ignite/internal/management/api/CommandInvoker.java index 250db201128f5..01a77a0530cdf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/management/api/CommandInvoker.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/management/api/CommandInvoker.java @@ -19,6 +19,7 @@ import java.util.Collection; import java.util.function.Consumer; +import org.apache.ignite.client.IgniteClient; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.client.GridClient; import org.apache.ignite.internal.client.GridClientException; @@ -57,11 +58,11 @@ public CommandInvoker(Command cmd, A arg, @Nullable IgniteEx ignite) { * @return {@code True} of command successfully prepared and can be invoked, {@code false} otherwise. * @throws GridClientException If failed. */ - public boolean prepare(Consumer printer) throws GridClientException { + public boolean prepare(Consumer printer) throws Exception { if (!(cmd instanceof PreparableCommand)) return true; - return ((PreparableCommand)cmd).prepare(client(), ignite, arg, printer); + return ((PreparableCommand)cmd).prepare(client(), igniteClient(), ignite, arg, printer); } /** @@ -76,16 +77,21 @@ public R invoke(Consumer printer, boolean verbose) throws Exception R res; if (cmd instanceof LocalCommand) - res = ((LocalCommand)cmd).execute(client(), ignite, arg, printer); + res = ((LocalCommand)cmd).execute(client(), igniteClient(), ignite, arg, printer); else if (cmd instanceof ComputeCommand) { ComputeCommand cmd = (ComputeCommand)this.cmd; - Collection cmdNodes = cmd.nodes(CommandUtils.nodes(client(), ignite), arg); + Collection cmdNodes = cmd.nodes(CommandUtils.nodes(client(), igniteClient(), ignite), arg); if (cmdNodes == null) cmdNodes = singletonList(defaultNode()); - res = CommandUtils.execute(client(), ignite, cmd.taskClass(), arg, cmdNodes); + try { + res = CommandUtils.execute(client(), igniteClient(), ignite, cmd.taskClass(), arg, cmdNodes); + } + catch (Exception e) { + res = cmd.handleException(e, printer); + } cmd.printResult(arg, res, printer); } @@ -107,4 +113,9 @@ protected GridClientNode defaultNode() throws GridClientException { protected @Nullable GridClient client() throws GridClientException { return null; } + + /** @return Ignite client instance. */ + protected @Nullable IgniteClient igniteClient() { + return null; + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/api/CommandUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/management/api/CommandUtils.java index e4f3ed4fb0d0b..c0af3646e147f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/management/api/CommandUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/management/api/CommandUtils.java @@ -41,6 +41,7 @@ import java.util.stream.Collectors; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteException; +import org.apache.ignite.client.IgniteClient; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.internal.client.GridClient; import org.apache.ignite.internal.client.GridClientCacheMode; @@ -550,13 +551,18 @@ public static boolean executable(Command cmd) { * @param ignite Ignite node. * @return Collection of cluster nodes. */ - public static Collection nodes(@Nullable GridClient cli, @Nullable Ignite ignite) throws GridClientException { + public static Collection nodes( + @Nullable GridClient cli, + @Nullable IgniteClient client, + @Nullable Ignite ignite + ) throws GridClientException { if (cli != null) return cli.compute().nodes(); - return ignite.cluster().nodes().stream() - .map(CommandUtils::clusterToClientNode) - .collect(Collectors.toList()); + if (client != null) + return F.viewReadOnly(client.cluster().nodes(), CommandUtils::clusterToClientNode); + + return F.viewReadOnly(ignite.cluster().nodes(), CommandUtils::clusterToClientNode); } /** @@ -764,6 +770,7 @@ public static A argument( /** */ public static R execute( @Nullable GridClient cli, + @Nullable IgniteClient client, @Nullable Ignite ignite, Class> taskCls, A arg, @@ -790,6 +797,19 @@ public static R execute( )).result(); } + if (client != null) { + try { + return client.compute(client.cluster().forNodes(client.cluster().nodes())) + ., VisorTaskResult>execute( + taskCls.getName(), + new VisorTaskArgument<>(nodesIds, arg, false) + ).result(); + } + catch (InterruptedException e) { + throw new IgniteException(e); + } + } + return ignite .compute(ignite.cluster()) .execute(taskCls, new VisorTaskArgument<>(nodesIds, arg, false)) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/api/ComputeCommand.java b/modules/core/src/main/java/org/apache/ignite/internal/management/api/ComputeCommand.java index b773bfd3f4b40..25b6fa0b4917e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/management/api/ComputeCommand.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/management/api/ComputeCommand.java @@ -49,4 +49,13 @@ public default void printResult(A arg, R res, Consumer printer) { public default @Nullable Collection nodes(Collection nodes, A arg) { return null; } + + /** + * @param e Task execution exception to handle. + * @param printer Implementation specific printer. + * @return Result if the exception is suppressed. + */ + default R handleException(Exception e, Consumer printer) throws Exception { + throw e; + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/api/LocalCommand.java b/modules/core/src/main/java/org/apache/ignite/internal/management/api/LocalCommand.java index a878708fa72f9..42dca47fde0e1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/management/api/LocalCommand.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/management/api/LocalCommand.java @@ -19,6 +19,7 @@ import java.util.function.Consumer; import org.apache.ignite.Ignite; +import org.apache.ignite.client.IgniteClient; import org.apache.ignite.internal.client.GridClient; import org.apache.ignite.internal.dto.IgniteDataTransferObject; import org.jetbrains.annotations.Nullable; @@ -43,5 +44,11 @@ public interface LocalCommand extends Com * @param printer Results printer. * @return Command result. */ - R execute(@Nullable GridClient cli, @Nullable Ignite ignite, A arg, Consumer printer) throws Exception; + public R execute( + @Nullable GridClient cli, + @Nullable IgniteClient client, + @Nullable Ignite ignite, + A arg, + Consumer printer + ) throws Exception; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/api/PreparableCommand.java b/modules/core/src/main/java/org/apache/ignite/internal/management/api/PreparableCommand.java index 14ff4d0e8c4e6..9fc7855782f61 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/management/api/PreparableCommand.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/management/api/PreparableCommand.java @@ -19,8 +19,8 @@ import java.util.function.Consumer; import org.apache.ignite.Ignite; +import org.apache.ignite.client.IgniteClient; import org.apache.ignite.internal.client.GridClient; -import org.apache.ignite.internal.client.GridClientException; import org.apache.ignite.internal.dto.IgniteDataTransferObject; import org.jetbrains.annotations.Nullable; @@ -34,5 +34,11 @@ public interface PreparableCommand extend * @param printer Implementation specific printer. * @return {@code True} if command must be executed, {@code false} otherwise. */ - public boolean prepare(@Nullable GridClient cli, @Nullable Ignite ignite, A arg, Consumer printer) throws GridClientException; + public boolean prepare( + @Nullable GridClient cli, + @Nullable IgniteClient client, + @Nullable Ignite ignite, + A arg, + Consumer printer + ) throws Exception; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/cache/CacheDestroyCommand.java b/modules/core/src/main/java/org/apache/ignite/internal/management/cache/CacheDestroyCommand.java index 6853adc80a995..55ac4dacda086 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/management/cache/CacheDestroyCommand.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/management/cache/CacheDestroyCommand.java @@ -22,6 +22,7 @@ import java.util.TreeSet; import java.util.function.Consumer; import org.apache.ignite.Ignite; +import org.apache.ignite.client.IgniteClient; import org.apache.ignite.internal.client.GridClient; import org.apache.ignite.internal.client.GridClientException; import org.apache.ignite.internal.client.GridClientNode; @@ -53,6 +54,7 @@ public class CacheDestroyCommand /** {@inheritDoc} */ @Override public boolean prepare( @Nullable GridClient cli, + @Nullable IgniteClient client, @Nullable Ignite ignite, CacheDestroyCommandArg arg, Consumer printer @@ -64,6 +66,8 @@ public class CacheDestroyCommand for (GridClientNode node : cli.compute().nodes(GridClientNode::connectable)) caches.addAll(node.caches().keySet()); } + else if (client != null) + caches.addAll(client.cacheNames()); else caches.addAll(ignite.cacheNames()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/cache/CacheListCommand.java b/modules/core/src/main/java/org/apache/ignite/internal/management/cache/CacheListCommand.java index 3cff6b84c3ace..ef537435c87ff 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/management/cache/CacheListCommand.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/management/cache/CacheListCommand.java @@ -27,6 +27,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import org.apache.ignite.Ignite; +import org.apache.ignite.client.IgniteClient; import org.apache.ignite.internal.client.GridClient; import org.apache.ignite.internal.client.GridClientNode; import org.apache.ignite.internal.management.api.CommandUtils; @@ -60,6 +61,7 @@ public class CacheListCommand implements LocalCommand printer @@ -68,7 +70,7 @@ public class CacheListCommand implements LocalCommand node = nodes(cli, ignite) + Optional node = nodes(cli, client, ignite) .stream() .filter(FILTER.apply(arg)) .findFirst(); @@ -76,10 +78,11 @@ public class CacheListCommand implements LocalCommand future; - - /** Job result: metadata info for removed type (used for job continuation). */ - private transient MetadataMarshalled res; - /** * @param arg Argument. * @param debug Debug. @@ -100,38 +82,21 @@ protected MetadataRemoveJob(@Nullable MetaRemoveCommandArg arg, boolean debug) { /** {@inheritDoc} */ @Override protected MetadataMarshalled run(@Nullable MetaRemoveCommandArg arg) throws IgniteException { try { - if (future == null) { - assert Objects.nonNull(arg); - - int typeId = typeId(ignite.context(), arg.typeId(), arg.typeName()); - - BinaryMetadata meta = ((CacheObjectBinaryProcessorImpl)ignite.context().cacheObjects()) - .binaryMetadata(typeId); + assert Objects.nonNull(arg); - if (meta == null) - return new MetadataMarshalled(null, null); + int typeId = typeId(ignite.context(), arg.typeId(), arg.typeName()); - byte[] marshalled = U.marshal(ignite.context(), meta); + BinaryMetadata meta = ((CacheObjectBinaryProcessorImpl)ignite.context().cacheObjects()) + .binaryMetadata(typeId); - res = new MetadataMarshalled(marshalled, meta); + if (meta == null) + return new MetadataMarshalled(null, null); - ignite.context().cacheObjects().removeType(typeId); + byte[] marshalled = U.marshal(ignite.context(), meta); - future = ignite.context().closure().runAsync( - BROADCAST, - new DropAllThinSessionsJob(), - options(ignite.cluster().forServers().nodes()) - ); + MetadataMarshalled res = new MetadataMarshalled(marshalled, meta); - jobCtx.holdcc(); - - future.listen(() -> { - if (future.isDone()) - jobCtx.callcc(); - }); - - return null; - } + ignite.context().cacheObjects().removeType(typeId); return res; } @@ -140,22 +105,4 @@ protected MetadataRemoveJob(@Nullable MetaRemoveCommandArg arg, boolean debug) { } } } - - /** - * Job to drop all thin session. - */ - @GridInternal - private static class DropAllThinSessionsJob implements IgniteRunnable { - /** */ - private static final long serialVersionUID = 0L; - - /** Grid */ - @IgniteInstanceResource - private IgniteEx ignite; - - /** {@inheritDoc} */ - @Override public void run() throws IgniteException { - ignite.context().clientListener().closeAllSessions(); - } - } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/tx/TxInfoCommand.java b/modules/core/src/main/java/org/apache/ignite/internal/management/tx/TxInfoCommand.java index 6823cda9b7bb2..46b1a00df090f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/management/tx/TxInfoCommand.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/management/tx/TxInfoCommand.java @@ -25,6 +25,7 @@ import java.util.Set; import java.util.function.Consumer; import org.apache.ignite.Ignite; +import org.apache.ignite.client.IgniteClient; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.internal.client.GridClient; import org.apache.ignite.internal.client.GridClientNode; @@ -54,13 +55,14 @@ public class TxInfoCommand implements LocalCommand execute( @Nullable GridClient cli, + @Nullable IgniteClient client, @Nullable Ignite ignite, AbstractTxCommandArg arg0, Consumer printer ) throws Exception { TxInfoCommandArg arg = (TxInfoCommandArg)arg0; - Optional node = CommandUtils.nodes(cli, ignite).stream() + Optional node = CommandUtils.nodes(cli, client, ignite).stream() .filter(n -> !n.isClient()) .filter(GridClientNode::connectable) .findFirst(); @@ -70,6 +72,7 @@ public class TxInfoCommand implements LocalCommand res = CommandUtils.execute( cli, + client, ignite, TxTask.class, arg, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java index 7cfa7803df856..c4ee6c09d385f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java @@ -5726,6 +5726,9 @@ else if (start && log.isInfoEnabled()) * @throws IgniteCheckedException If there is an error when stopping warm-up. */ public boolean stopWarmUp() throws IgniteCheckedException { + if (!ctx.recoveryMode()) + throw new IgniteException("Node has already started."); + if (recovery.stopWarmUp.compareAndSet(false, true)) { WarmUpStrategy strat = recovery.curWarmUpStrat; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/compute/ClientComputeTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/compute/ClientComputeTask.java index fbc91b95ea0fb..377787a76b84e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/compute/ClientComputeTask.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/compute/ClientComputeTask.java @@ -68,15 +68,20 @@ class ClientComputeTask implements ClientCloseableResource { /** Task closed flag. */ private final AtomicBoolean closed = new AtomicBoolean(); + /** */ + private final boolean systemTask; + /** * Ctor. * * @param ctx Connection context. + * @param sysTask {@code True} if task is system. */ - ClientComputeTask(ClientConnectionContext ctx) { + ClientComputeTask(ClientConnectionContext ctx, boolean sysTask) { assert ctx != null; this.ctx = ctx; + this.systemTask = sysTask; log = ctx.kernalContext().log(getClass()); } @@ -148,7 +153,8 @@ else if (taskFut.isCancelled()) finally { // If task was explicitly closed before, resource is already released. if (closed.compareAndSet(false, true)) { - ctx.decrementActiveTasksCount(); + if (!systemTask) + ctx.decrementActiveTasksCount(); ctx.resources().release(taskId); } @@ -168,7 +174,8 @@ long taskId() { */ @Override public void close() { if (closed.compareAndSet(false, true)) { - ctx.decrementActiveTasksCount(); + if (!systemTask) + ctx.decrementActiveTasksCount(); try { if (taskFut != null) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/compute/ClientExecuteTaskRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/compute/ClientExecuteTaskRequest.java index ee01a1e9c25ab..8071ad2712e7e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/compute/ClientExecuteTaskRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/compute/ClientExecuteTaskRequest.java @@ -19,13 +19,14 @@ import java.util.Set; import java.util.UUID; - import org.apache.ignite.binary.BinaryObject; +import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.binary.BinaryRawReaderEx; import org.apache.ignite.internal.processors.platform.client.ClientConnectionContext; import org.apache.ignite.internal.processors.platform.client.ClientRequest; import org.apache.ignite.internal.processors.platform.client.ClientResponse; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.internal.visor.VisorMultiNodeTask; /** * Request to execute compute task. @@ -72,9 +73,12 @@ public ClientExecuteTaskRequest(BinaryRawReaderEx reader) { /** {@inheritDoc} */ @Override public ClientResponse process(ClientConnectionContext ctx) { - ClientComputeTask task = new ClientComputeTask(ctx); + boolean sysTask = systemTask(ctx.kernalContext(), taskName); + + ClientComputeTask task = new ClientComputeTask(ctx, sysTask); - ctx.incrementActiveTasksCount(); + if (!sysTask) + ctx.incrementActiveTasksCount(); long taskId = ctx.resources().put(task); @@ -96,4 +100,21 @@ public ClientExecuteTaskRequest(BinaryRawReaderEx reader) { return new ClientExecuteTaskResponse(requestId(), task); } + + /** */ + private boolean systemTask(GridKernalContext ctx, String taskName) { + Class cls; + + try { + cls = U.forName(taskName, U.gridClassLoader()); + } + catch (ClassNotFoundException ignored) { + return false; + } + + if (ctx.security().enabled()) + return ctx.security().isSystemType(cls); + else + return VisorMultiNodeTask.class.isAssignableFrom(cls); + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorIdAndTagViewTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorIdAndTagViewTask.java index 1a8768d75dae6..0e2819b35016b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorIdAndTagViewTask.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorIdAndTagViewTask.java @@ -64,7 +64,7 @@ private static class IdAndTagViewJob extends VisorJob... cls) { EXT_SYS_CLASSES.addAll(Arrays.asList(cls)); } + /** */ + public static void clearExternalSystemTypes() { + EXT_SYS_CLASSES.clear(); + } + /** */ public static boolean contains(SecurityPermissionSet userPerms, String name, SecurityPermission perm) { boolean dfltAllowAll = userPerms.defaultAllowAll(); diff --git a/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassTest_help.output b/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassTest_help.output index 6be8a41e0e9bc..3533fd4d95b79 100644 --- a/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassTest_help.output +++ b/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassTest_help.output @@ -469,7 +469,7 @@ Use --yes option to disable it. Default values: HOST_OR_IP=127.0.0.1 - PORT=11211 + PORT=10800 PING_INTERVAL=5000 PING_TIMEOUT=30000 SSL_PROTOCOL=TLS diff --git a/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassWithSSLTest_help.output b/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassWithSSLTest_help.output index 15ea52c27ceff..3a0c4a683e6fa 100644 --- a/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassWithSSLTest_help.output +++ b/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassWithSSLTest_help.output @@ -469,7 +469,7 @@ Use --yes option to disable it. Default values: HOST_OR_IP=127.0.0.1 - PORT=11211 + PORT=10800 PING_INTERVAL=5000 PING_TIMEOUT=30000 SSL_PROTOCOL=TLS diff --git a/modules/extdata/pluggable/src/test/java/org/apache/ignite/internal/commandline/CommandsProviderExtImpl.java b/modules/extdata/pluggable/src/test/java/org/apache/ignite/internal/commandline/CommandsProviderExtImpl.java index f47659b6e1a03..bc40018e984e0 100644 --- a/modules/extdata/pluggable/src/test/java/org/apache/ignite/internal/commandline/CommandsProviderExtImpl.java +++ b/modules/extdata/pluggable/src/test/java/org/apache/ignite/internal/commandline/CommandsProviderExtImpl.java @@ -21,15 +21,22 @@ import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.Collection; -import java.util.Collections; import java.util.function.Consumer; import org.apache.ignite.Ignite; +import org.apache.ignite.client.IgniteClient; import org.apache.ignite.internal.client.GridClient; import org.apache.ignite.internal.dto.IgniteDataTransferObject; import org.apache.ignite.internal.management.api.Argument; import org.apache.ignite.internal.management.api.Command; +import org.apache.ignite.internal.management.api.ComputeCommand; import org.apache.ignite.internal.management.api.LocalCommand; +import org.apache.ignite.internal.processors.task.GridInternal; +import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.internal.visor.VisorJob; +import org.apache.ignite.internal.visor.VisorMultiNodeTask; +import org.apache.ignite.internal.visor.VisorOneNodeTask; +import org.jetbrains.annotations.Nullable; /** * Additional commands provider for control utility. @@ -38,6 +45,9 @@ public class CommandsProviderExtImpl implements CommandsProvider { /** */ public static final Command TEST_COMMAND = new TestCommandCommand(); + /** */ + public static final Command TEST_COMPUTE_COMMAND = new TestComputeCommand(); + /** */ public static final String TEST_COMMAND_OUTPUT = "Test command executed"; @@ -49,7 +59,7 @@ public class CommandsProviderExtImpl implements CommandsProvider { /** {@inheritDoc} */ @Override public Collection> commands() { - return Collections.singleton(TEST_COMMAND); + return F.asList(TEST_COMMAND, TEST_COMPUTE_COMMAND); } /** */ @@ -65,7 +75,8 @@ public static class TestCommandCommand implements LocalCommand printer) { + @Override public Void execute(@Nullable GridClient cli, @Nullable IgniteClient client, @Nullable Ignite ignite, + TestCommandCommandArg arg, Consumer printer) { printer.accept(TEST_COMMAND_OUTPUT + ": " + arg.testPrint); return null; @@ -101,4 +112,55 @@ public String testPrint() { return testPrint; } } + + /** */ + private static class TestComputeCommand implements ComputeCommand { + /** {@inheritDoc} */ + @Override public Class> taskClass() { + return TestTask.class; + } + + /** {@inheritDoc} */ + @Override public void printResult(TestCommandCommandArg arg, String res, Consumer printer) { + printer.accept(res); + } + + /** {@inheritDoc} */ + @Override public String description() { + return "Test compute command."; + } + + /** {@inheritDoc} */ + @Override public Class argClass() { + return TestCommandCommandArg.class; + } + } + + /** */ + @GridInternal + public static class TestTask extends VisorOneNodeTask { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override protected TestJob job(TestCommandCommandArg arg) { + return new TestJob(arg, debug); + } + + /** */ + private static class TestJob extends VisorJob { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + protected TestJob(TestCommandCommandArg arg, boolean debug) { + super(arg, debug); + } + + /** {@inheritDoc} */ + @Override protected String run(TestCommandCommandArg arg) { + return arg.testPrint(); + } + } + } } diff --git a/modules/extdata/pluggable/src/test/java/org/apache/ignite/internal/commandline/ExtendedControlUtilityTest.java b/modules/extdata/pluggable/src/test/java/org/apache/ignite/internal/commandline/ExtendedControlUtilityTest.java index b16389667de85..5c228b6e7682d 100644 --- a/modules/extdata/pluggable/src/test/java/org/apache/ignite/internal/commandline/ExtendedControlUtilityTest.java +++ b/modules/extdata/pluggable/src/test/java/org/apache/ignite/internal/commandline/ExtendedControlUtilityTest.java @@ -17,16 +17,27 @@ package org.apache.ignite.internal.commandline; +import java.security.Permissions; import org.apache.ignite.Ignite; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.processors.security.impl.TestSecurityData; +import org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider; import org.apache.ignite.util.GridCommandHandlerAbstractTest; import org.junit.Test; + import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_INVALID_ARGUMENTS; import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK; import static org.apache.ignite.internal.commandline.CommandsProviderExtImpl.TEST_COMMAND; import static org.apache.ignite.internal.commandline.CommandsProviderExtImpl.TEST_COMMAND_ARG; import static org.apache.ignite.internal.commandline.CommandsProviderExtImpl.TEST_COMMAND_OUTPUT; import static org.apache.ignite.internal.commandline.CommandsProviderExtImpl.TEST_COMMAND_USAGE; +import static org.apache.ignite.internal.commandline.CommandsProviderExtImpl.TEST_COMPUTE_COMMAND; +import static org.apache.ignite.internal.commandline.SecurityCommandHandlerPermissionsTest.DEFAULT_PWD; +import static org.apache.ignite.internal.commandline.SecurityCommandHandlerPermissionsTest.TEST_LOGIN; import static org.apache.ignite.internal.management.api.CommandUtils.cmdText; +import static org.apache.ignite.internal.processors.security.impl.TestSecurityProcessor.clearExternalSystemTypes; +import static org.apache.ignite.internal.processors.security.impl.TestSecurityProcessor.registerExternalSystemTypes; +import static org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.ALL_PERMISSIONS; import static org.apache.ignite.testframework.GridTestUtils.assertContains; /** @@ -70,4 +81,43 @@ public void testAdditionalCommandHelp() { assertContains(log, testOutStr, TEST_COMMAND_USAGE); assertContains(log, testOutStr, TEST_COMMAND_ARG); } + + /** */ + @Test + public void testAdditionalComputeCommand() throws Exception { + try (Ignite grid = startGrid(0)) { + injectTestSystemOut(); + + String testVal = "test value"; + + assertEquals(EXIT_CODE_OK, execute(cmdText(TEST_COMPUTE_COMMAND), TEST_COMMAND_ARG, testVal)); + + assertContains(log, testOut.toString(), testVal); + } + } + + /** */ + @Test + public void testAdditionalComputeCommandSecurityEnabled() throws Exception { + IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(0)); + + cfg.setPluginProviders(new TestSecurityPluginProvider(cfg.getIgniteInstanceName(), "", ALL_PERMISSIONS, false, + new TestSecurityData(TEST_LOGIN, DEFAULT_PWD, ALL_PERMISSIONS, new Permissions()))); + + registerExternalSystemTypes(CommandsProviderExtImpl.TestTask.class); + + try (Ignite grid = startGrid(cfg)) { + injectTestSystemOut(); + + String testVal = "test value"; + + assertEquals(EXIT_CODE_OK, execute("--user", TEST_LOGIN, "--password", DEFAULT_PWD, + cmdText(TEST_COMPUTE_COMMAND), TEST_COMMAND_ARG, testVal)); + + assertContains(log, testOut.toString(), testVal); + } + finally { + clearExternalSystemTypes(); + } + } }