This is an automated email from the ASF dual-hosted git repository.
mpochatkin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 6327943a711 IGNITE-25022 CLI: Support profiles in REPL (#7464)
6327943a711 is described below
commit 6327943a711a461841ce9c41632c90a7a24cb367
Author: Vadim Pakhnushev <[email protected]>
AuthorDate: Thu Jan 29 15:17:20 2026 +0300
IGNITE-25022 CLI: Support profiles in REPL (#7464)
---
.../cli/commands/cluster/ClusterUrlMixin.java | 33 ++++++-
.../commands/cluster/ClusterUrlProfileMixin.java | 16 ++-
.../internal/cli/commands/node/NodeUrlMixin.java | 17 ++++
.../ignite/internal/cli/commands/MixinTest.java | 108 ++++++++++++++++++++-
.../internal/cli/commands/ProfileOptionTest.java | 19 ++--
5 files changed, 166 insertions(+), 27 deletions(-)
diff --git
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/ClusterUrlMixin.java
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/ClusterUrlMixin.java
index 0125dc64875..d1fd342a8f9 100644
---
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/ClusterUrlMixin.java
+++
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/ClusterUrlMixin.java
@@ -21,12 +21,19 @@ import static
org.apache.ignite.internal.cli.commands.CommandConstants.CLUSTER_U
import static
org.apache.ignite.internal.cli.commands.Options.Constants.CLUSTER_URL_OPTION;
import static
org.apache.ignite.internal.cli.commands.Options.Constants.CLUSTER_URL_OPTION_DESC;
+import jakarta.inject.Inject;
import java.net.URL;
+import org.apache.ignite.internal.cli.commands.ProfileMixin;
+import org.apache.ignite.internal.cli.config.CliConfigKeys;
+import org.apache.ignite.internal.cli.config.ConfigManager;
+import org.apache.ignite.internal.cli.config.ConfigManagerProvider;
import org.apache.ignite.internal.cli.core.converters.RestEndpointUrlConverter;
+import org.jetbrains.annotations.Nullable;
+import picocli.CommandLine.Mixin;
import picocli.CommandLine.Option;
/**
- * Mixin class for cluster URL option.
+ * Mixin class for cluster URL and profile options in REPL mode.
*/
public class ClusterUrlMixin {
/** Cluster endpoint URL option. */
@@ -38,7 +45,29 @@ public class ClusterUrlMixin {
)
private URL clusterUrl;
+ /** Profile to get default values from. */
+ @Mixin
+ private ProfileMixin profile;
+
+ @Inject
+ private ConfigManagerProvider configManagerProvider;
+
+ /**
+ * Gets cluster URL from either the command line or from the specified
profile in the config.
+ *
+ * @return cluster URL
+ */
+ @Nullable
public String getClusterUrl() {
- return clusterUrl != null ? clusterUrl.toString() : null;
+ if (clusterUrl != null) {
+ return clusterUrl.toString();
+ } else {
+ String profileName = profile.getProfileName();
+ if (profileName != null) {
+ ConfigManager configManager = configManagerProvider.get();
+ return
configManager.getProperty(CliConfigKeys.CLUSTER_URL.value(), profileName);
+ }
+ }
+ return null;
}
}
diff --git
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/ClusterUrlProfileMixin.java
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/ClusterUrlProfileMixin.java
index c91f62d005d..dc46561a8cc 100644
---
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/ClusterUrlProfileMixin.java
+++
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/cluster/ClusterUrlProfileMixin.java
@@ -18,38 +18,34 @@
package org.apache.ignite.internal.cli.commands.cluster;
import jakarta.inject.Inject;
-import org.apache.ignite.internal.cli.commands.ProfileMixin;
import org.apache.ignite.internal.cli.config.CliConfigKeys;
import org.apache.ignite.internal.cli.config.ConfigManager;
import org.apache.ignite.internal.cli.config.ConfigManagerProvider;
import picocli.CommandLine.Mixin;
/**
- * Mixin class to combine cluster URL and profile options.
+ * Mixin class for cluster URL and profile options.
*/
public class ClusterUrlProfileMixin {
/** Cluster endpoint URL option. */
@Mixin
private ClusterUrlMixin clusterUrl;
- /** Profile to get default values from. */
- @Mixin
- private ProfileMixin profileName;
-
@Inject
private ConfigManagerProvider configManagerProvider;
/**
- * Gets cluster URL from either the command line or from the config with
specified or default profile.
+ * Gets cluster URL from either the command line or from the default
profile in the config.
*
* @return cluster URL
*/
public String getClusterUrl() {
- if (clusterUrl.getClusterUrl() != null) {
- return clusterUrl.getClusterUrl();
+ String clusterUrlFromOptions = clusterUrl.getClusterUrl();
+ if (clusterUrlFromOptions != null) {
+ return clusterUrlFromOptions;
} else {
ConfigManager configManager = configManagerProvider.get();
- return
configManager.getProperty(CliConfigKeys.CLUSTER_URL.value(),
profileName.getProfileName());
+ return
configManager.getCurrentProperty(CliConfigKeys.CLUSTER_URL.value());
}
}
}
diff --git
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/NodeUrlMixin.java
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/NodeUrlMixin.java
index 75fe92b7e55..e221ee94ad8 100644
---
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/NodeUrlMixin.java
+++
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/NodeUrlMixin.java
@@ -25,11 +25,16 @@ import static
org.apache.ignite.internal.cli.commands.Options.Constants.NODE_URL
import jakarta.inject.Inject;
import java.net.URL;
+import org.apache.ignite.internal.cli.commands.ProfileMixin;
+import org.apache.ignite.internal.cli.config.CliConfigKeys;
+import org.apache.ignite.internal.cli.config.ConfigManager;
+import org.apache.ignite.internal.cli.config.ConfigManagerProvider;
import org.apache.ignite.internal.cli.core.converters.RestEndpointUrlConverter;
import org.apache.ignite.internal.cli.core.exception.IgniteCliException;
import org.apache.ignite.internal.cli.core.repl.registry.NodeNameRegistry;
import org.jetbrains.annotations.Nullable;
import picocli.CommandLine.ArgGroup;
+import picocli.CommandLine.Mixin;
import picocli.CommandLine.Option;
/**
@@ -40,6 +45,13 @@ public class NodeUrlMixin {
@ArgGroup
private Options options;
+ /** Profile to get default values from. */
+ @Mixin
+ private ProfileMixin profile;
+
+ @Inject
+ private ConfigManagerProvider configManagerProvider;
+
@Inject
private NodeNameRegistry nodeNameRegistry;
@@ -84,6 +96,11 @@ public class NodeUrlMixin {
+ " not found. Provide a valid name or use a
URL"));
}
}
+ String profileName = profile.getProfileName();
+ if (profileName != null) {
+ ConfigManager configManager = configManagerProvider.get();
+ return
configManager.getProperty(CliConfigKeys.CLUSTER_URL.value(), profileName);
+ }
return null;
}
}
diff --git
a/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/MixinTest.java
b/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/MixinTest.java
index b89ef3ac0b9..8d1be430d98 100644
---
a/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/MixinTest.java
+++
b/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/MixinTest.java
@@ -44,9 +44,11 @@ import jakarta.inject.Inject;
import java.util.Optional;
import java.util.Set;
import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlMixin;
+import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlProfileMixin;
import org.apache.ignite.internal.cli.commands.cluster.init.ClusterInitOptions;
import org.apache.ignite.internal.cli.commands.connect.ConnectOptions;
import org.apache.ignite.internal.cli.commands.node.NodeUrlMixin;
+import org.apache.ignite.internal.cli.commands.node.NodeUrlProfileMixin;
import
org.apache.ignite.internal.cli.commands.recovery.cluster.reset.ResetClusterMixin;
import
org.apache.ignite.internal.cli.commands.recovery.partitions.states.PartitionStatesMixin;
import org.apache.ignite.internal.cli.core.repl.registry.NodeNameRegistry;
@@ -64,7 +66,7 @@ class MixinTest {
@Test
void doubleInvocationNodeName() {
- NodeCommand command = new NodeCommand();
+ NodeReplCommand command = new NodeReplCommand();
CommandLine commandLine = new CommandLine(command, new
MicronautFactory(context));
String nodeName = "test";
@@ -78,7 +80,7 @@ class MixinTest {
@Test
void doubleInvocationNodeUrl() {
- NodeCommand command = new NodeCommand();
+ NodeReplCommand command = new NodeReplCommand();
CommandLine commandLine = new CommandLine(command, new
MicronautFactory(context));
String nodeUrl = "http://test";
@@ -92,7 +94,7 @@ class MixinTest {
@Test
void doubleInvocationClusterUrl() {
- ClusterCommand command = new ClusterCommand();
+ ClusterReplCommand command = new ClusterReplCommand();
CommandLine commandLine = new CommandLine(command, new
MicronautFactory(context));
String clusterUrl = "http://test";
@@ -104,6 +106,94 @@ class MixinTest {
assertThat(command.clusterUrl.getClusterUrl(), is(nullValue()));
}
+ @Test
+ void clusterUrlDefaultValue() {
+ ClusterCommand command = new ClusterCommand();
+ CommandLine commandLine = new CommandLine(command, new
MicronautFactory(context));
+
+ // Default value is taken from the config
+ commandLine.parseArgs();
+ assertThat(command.clusterUrl.getClusterUrl(),
is("http://localhost:10300"));
+
+ // Value is taken from the option
+ commandLine.parseArgs("--url=http://test");
+ assertThat(command.clusterUrl.getClusterUrl(), is("http://test"));
+
+ // Value is taken from the profile
+ commandLine.parseArgs("--profile=test");
+ assertThat(command.clusterUrl.getClusterUrl(),
is("http://localhost:10301"));
+
+ // Option overrides profiles
+ commandLine.parseArgs("--url=http://test", "--profile=test");
+ assertThat(command.clusterUrl.getClusterUrl(), is("http://test"));
+ }
+
+ @Test
+ void clusterUrlDefaultValueRepl() {
+ ClusterReplCommand command = new ClusterReplCommand();
+ CommandLine commandLine = new CommandLine(command, new
MicronautFactory(context));
+
+ // Default value is null
+ commandLine.parseArgs();
+ assertThat(command.clusterUrl.getClusterUrl(), is(nullValue()));
+
+ // Value is taken from the option
+ commandLine.parseArgs("--url=http://test");
+ assertThat(command.clusterUrl.getClusterUrl(), is("http://test"));
+
+ // Value is taken from the profile
+ commandLine.parseArgs("--profile=test");
+ assertThat(command.clusterUrl.getClusterUrl(),
is("http://localhost:10301"));
+
+ // Option overrides profiles
+ commandLine.parseArgs("--url=http://test", "--profile=test");
+ assertThat(command.clusterUrl.getClusterUrl(), is("http://test"));
+ }
+
+ @Test
+ void nodeUrlDefaultValue() {
+ NodeCommand command = new NodeCommand();
+ CommandLine commandLine = new CommandLine(command, new
MicronautFactory(context));
+
+ // Default value is taken from the config
+ commandLine.parseArgs();
+ assertThat(command.nodeUrl.getNodeUrl(), is("http://localhost:10300"));
+
+ // Value is taken from the option
+ commandLine.parseArgs("--url=http://test");
+ assertThat(command.nodeUrl.getNodeUrl(), is("http://test"));
+
+ // Value is taken from the profile
+ commandLine.parseArgs("--profile=test");
+ assertThat(command.nodeUrl.getNodeUrl(), is("http://localhost:10301"));
+
+ // Option overrides profiles
+ commandLine.parseArgs("--url=http://test", "--profile=test");
+ assertThat(command.nodeUrl.getNodeUrl(), is("http://test"));
+ }
+
+ @Test
+ void nodeUrlDefaultValueRepl() {
+ NodeReplCommand command = new NodeReplCommand();
+ CommandLine commandLine = new CommandLine(command, new
MicronautFactory(context));
+
+ // Default value is null
+ commandLine.parseArgs();
+ assertThat(command.nodeUrl.getNodeUrl(), is(nullValue()));
+
+ // Value is taken from the option
+ commandLine.parseArgs("--url=http://test");
+ assertThat(command.nodeUrl.getNodeUrl(), is("http://test"));
+
+ // Value is taken from the profile
+ commandLine.parseArgs("--profile=test");
+ assertThat(command.nodeUrl.getNodeUrl(), is("http://localhost:10301"));
+
+ // Option overrides profiles
+ commandLine.parseArgs("--url=http://test", "--profile=test");
+ assertThat(command.nodeUrl.getNodeUrl(), is("http://test"));
+ }
+
@Test
void doubleInvocationUnitList() {
UnitCommand command = new UnitCommand();
@@ -183,12 +273,24 @@ class MixinTest {
@Command
private static class NodeCommand {
+ @Mixin
+ private NodeUrlProfileMixin nodeUrl;
+ }
+
+ @Command
+ private static class NodeReplCommand {
@Mixin
private NodeUrlMixin nodeUrl;
}
@Command
private static class ClusterCommand {
+ @Mixin
+ private ClusterUrlProfileMixin clusterUrl;
+ }
+
+ @Command
+ private static class ClusterReplCommand {
@Mixin
private ClusterUrlMixin clusterUrl;
}
diff --git
a/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/ProfileOptionTest.java
b/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/ProfileOptionTest.java
index c08fd36dff0..656577cf747 100644
---
a/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/ProfileOptionTest.java
+++
b/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/ProfileOptionTest.java
@@ -20,7 +20,6 @@ package org.apache.ignite.internal.cli.commands;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
import io.micronaut.configuration.picocli.MicronautFactory;
import io.micronaut.context.ApplicationContext;
@@ -32,7 +31,8 @@ import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import picocli.CommandLine;
import picocli.CommandLine.Model.OptionSpec;
@@ -49,18 +49,13 @@ class ProfileOptionTest {
System.setProperty("org.jline.terminal.dumb", "true");
}
- @Test
- void nonReplCommands() {
- CommandLine cmd = new CommandLine(TopLevelCliCommand.class, new
MicronautFactory(context));
+ @ParameterizedTest
+ @ValueSource(classes = {TopLevelCliCommand.class,
TopLevelCliReplCommand.class})
+ void everyCommandWithUrlOptionHasProfileOption(Class<?> cmdClass) {
+ CommandLine cmd = new CommandLine(cmdClass, new
MicronautFactory(context));
assertThat(subCommands(cmd),
everyItem(profileOption(notNullValue(OptionSpec.class))));
}
- @Test
- void replCommands() {
- CommandLine cmd = new CommandLine(TopLevelCliReplCommand.class, new
MicronautFactory(context));
- assertThat(subCommands(cmd),
everyItem(profileOption(nullValue(OptionSpec.class))));
- }
-
private static Matcher<CommandLine> profileOption(Matcher<OptionSpec>
optionMatcher) {
return new TypeSafeMatcher<>() {
@Override
@@ -76,7 +71,7 @@ class ProfileOptionTest {
@Override
protected void describeMismatchSafely(CommandLine item,
Description mismatchDescription) {
-
mismatchDescription.appendText(item.getCommandSpec().qualifiedName())
+
mismatchDescription.appendValue(item.getCommandSpec().qualifiedName())
.appendText(" has --profile option
").appendValue(item.getCommandSpec().findOption("--profile"));
}
};