Skip to content

Commit

Permalink
IGNITE-14823 Command abbrevation (#11093)
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov authored Dec 13, 2023
1 parent 1ed6d18 commit 99dfd02
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 58 deletions.
3 changes: 2 additions & 1 deletion modules/checkstyle/src/main/resources/abbrevations.csv
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ attribute,attr
attributes,attrs
buffer,buf
class,cls
#command,cmd
command,cmd
commands,cmds
#config,cfg
#context,ctx
#count,cnt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,21 @@ public void testRestProbeCommandGridNotStarted() throws Exception {
}
}).start();

Map<String, Object> probeRestCommandResponse;
Map<String, Object> probeRestCmdResponse;

log.info("awaiting plugin handler latch");
triggerPluginStartLatch.await();
log.info("starting rest command url call");
try {
probeRestCommandResponse = executeProbeRestRequest();
probeRestCmdResponse = executeProbeRestRequest();
log.info("finished rest command url call");
}
finally {
triggerRestCmdLatch.countDown(); //make sure the grid shuts down
}

assertTrue(probeRestCommandResponse.get("error").equals("grid has not started"));
assertEquals(GridRestResponse.SERVICE_UNAVAILABLE, probeRestCommandResponse.get("successStatus"));
assertTrue(probeRestCmdResponse.get("error").equals("grid has not started"));
assertEquals(GridRestResponse.SERVICE_UNAVAILABLE, probeRestCmdResponse.get("successStatus"));
}

/**
Expand All @@ -172,12 +172,12 @@ public void testRestProbeCommandGridNotStarted() throws Exception {
public void testRestProbeCommandGridStarted() throws Exception {
startGrid("regular");

Map<String, Object> probeRestCommandResponse;
Map<String, Object> probeRestCmdResponse;

probeRestCommandResponse = executeProbeRestRequest();
probeRestCmdResponse = executeProbeRestRequest();

assertTrue(probeRestCommandResponse.get("response").equals("grid has started"));
assertEquals(0, probeRestCommandResponse.get("successStatus"));
assertTrue(probeRestCmdResponse.get("response").equals("grid has started"));
assertEquals(0, probeRestCmdResponse.get("successStatus"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2807,7 +2807,7 @@ public void testTypedGet() throws Exception {
public void testCacheCommandsWithoutCacheName() throws Exception {
final String ERROR_MSG = "Failed to find mandatory parameter in request: cacheName";

EnumSet<GridRestCommand> cacheCommands = EnumSet.of(GridRestCommand.DESTROY_CACHE,
EnumSet<GridRestCommand> cacheCmds = EnumSet.of(GridRestCommand.DESTROY_CACHE,
GridRestCommand.GET_OR_CREATE_CACHE,
GridRestCommand.CACHE_CONTAINS_KEYS,
GridRestCommand.CACHE_CONTAINS_KEY,
Expand All @@ -2833,10 +2833,10 @@ public void testCacheCommandsWithoutCacheName() throws Exception {
GridRestCommand.CACHE_SIZE,
GridRestCommand.CACHE_METADATA);

for (GridRestCommand command : cacheCommands) {
String ret = content(null, command);
for (GridRestCommand cmd : cacheCmds) {
String ret = content(null, cmd);

if (command == GridRestCommand.CACHE_METADATA)
if (cmd == GridRestCommand.CACHE_METADATA)
validateJsonResponse(ret);
else {
JsonNode json = JSON_MAPPER.readTree(ret);
Expand All @@ -2861,23 +2861,23 @@ public void testCacheCommandsWithoutCacheName() throws Exception {
public void testQueryCommandsWithoutCacheName() throws Exception {
final String ERROR_MSG = "Failed to find mandatory parameter in request: cacheName";

EnumSet<GridRestCommand> qryCommands = EnumSet.of(GridRestCommand.EXECUTE_SQL_QUERY,
EnumSet<GridRestCommand> qryCmds = EnumSet.of(GridRestCommand.EXECUTE_SQL_QUERY,
GridRestCommand.EXECUTE_SQL_FIELDS_QUERY,
GridRestCommand.EXECUTE_SCAN_QUERY,
GridRestCommand.FETCH_SQL_QUERY,
GridRestCommand.CLOSE_SQL_QUERY);

for (GridRestCommand command : qryCommands) {
String ret = content(null, command,
for (GridRestCommand cmd : qryCmds) {
String ret = content(null, cmd,
"pageSize", "1",
"qry", "SELECT * FROM table");

JsonNode json = JSON_MAPPER.readTree(ret);
assertFalse(json.isNull());

if (command == GridRestCommand.EXECUTE_SQL_QUERY ||
command == GridRestCommand.EXECUTE_SCAN_QUERY ||
command == GridRestCommand.EXECUTE_SQL_FIELDS_QUERY)
if (cmd == GridRestCommand.EXECUTE_SQL_QUERY ||
cmd == GridRestCommand.EXECUTE_SCAN_QUERY ||
cmd == GridRestCommand.EXECUTE_SQL_FIELDS_QUERY)
assertTrue(json.get("error").asText().contains(ERROR_MSG));
else
assertFalse(json.get("error").asText().contains(ERROR_MSG));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ private static void downloadArtifact(String artifact) throws Exception {

String localProxyMavenSettingsFromEnv = System.getenv("LOCAL_PROXY_MAVEN_SETTINGS");

GridStringBuilder mavenCommandArgs = new SB(" ").a(MAVEN_DEPENDENCY_PLUGIN).a(":get -Dartifact=" + artifact);
GridStringBuilder mavenCmdArgs = new SB(" ").a(MAVEN_DEPENDENCY_PLUGIN).a(":get -Dartifact=" + artifact);

if (!isEmpty(localProxyMavenSettingsFromEnv))
localProxyMavenSettings = Paths.get(localProxyMavenSettingsFromEnv);

if (Files.exists(localProxyMavenSettings))
mavenCommandArgs.a(" -s " + localProxyMavenSettings.toString());
mavenCmdArgs.a(" -s " + localProxyMavenSettings.toString());
else {
Collection<String> repos = new ArrayList<>();

Expand All @@ -208,10 +208,10 @@ private static void downloadArtifact(String artifact) throws Exception {
repos.addAll(mavenProjectRepositories());

if (!repos.isEmpty())
mavenCommandArgs.a(" -DremoteRepositories=").a(String.join(",", repos));
mavenCmdArgs.a(" -DremoteRepositories=").a(String.join(",", repos));
}

exec(buildMvnCommand() + mavenCommandArgs.toString());
exec(buildMvnCommand() + mavenCmdArgs.toString());

X.println("Download is finished");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public <A extends IgniteDataTransferObject> int execute(List<String> rawArgs) {
logger.info("User: " + System.getProperty("user.name"));
logger.info("Time: " + startTime.format(formatter));

String commandName = "";
String cmdName = "";

Throwable err = null;
boolean verbose = false;
Expand All @@ -253,7 +253,7 @@ public <A extends IgniteDataTransferObject> int execute(List<String> rawArgs) {

ConnectionAndSslParameters<A> args = new ArgumentParser(logger, registry).parseAndValidate(rawArgs);

commandName = toFormattedCommandName(args.cmdPath().peekLast().getClass()).toUpperCase();
cmdName = toFormattedCommandName(args.cmdPath().peekLast().getClass()).toUpperCase();

try (CliCommandInvoker<A> invoker = new CliCommandInvoker<>(args.command(), args.commandArg(), getClientConfiguration(args))) {
int tryConnectMaxCount = 3;
Expand All @@ -275,7 +275,7 @@ public <A extends IgniteDataTransferObject> int execute(List<String> rawArgs) {
}
}

logger.info("Command [" + commandName + "] started");
logger.info("Command [" + cmdName + "] started");
logger.info("Arguments: " + argumentsToString(rawArgs));
logger.info(U.DELIM);

Expand Down Expand Up @@ -333,13 +333,13 @@ public <A extends IgniteDataTransferObject> int execute(List<String> rawArgs) {
}
}

logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_OK);
logger.info("Command [" + cmdName + "] finished with code: " + EXIT_CODE_OK);

return EXIT_CODE_OK;
}
catch (IllegalArgumentException e) {
logger.error("Check arguments. " + errorMessage(e));
logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_INVALID_ARGUMENTS);
logger.info("Command [" + cmdName + "] finished with code: " + EXIT_CODE_INVALID_ARGUMENTS);

if (verbose)
err = e;
Expand All @@ -349,7 +349,7 @@ public <A extends IgniteDataTransferObject> int execute(List<String> rawArgs) {
catch (Throwable e) {
if (isAuthError(e)) {
logger.error("Authentication error. " + errorMessage(e));
logger.info("Command [" + commandName + "] finished with code: " + ERR_AUTHENTICATION_FAILED);
logger.info("Command [" + cmdName + "] finished with code: " + ERR_AUTHENTICATION_FAILED);

if (verbose)
err = e;
Expand All @@ -371,7 +371,7 @@ public <A extends IgniteDataTransferObject> int execute(List<String> rawArgs) {

}

logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_CONNECTION_FAILED);
logger.info("Command [" + cmdName + "] finished with code: " + EXIT_CODE_CONNECTION_FAILED);

if (verbose)
err = e;
Expand All @@ -383,7 +383,7 @@ public <A extends IgniteDataTransferObject> int execute(List<String> rawArgs) {
IllegalArgumentException iae = X.cause(e, IllegalArgumentException.class);

logger.error("Check arguments. " + errorMessage(iae));
logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_INVALID_ARGUMENTS);
logger.info("Command [" + cmdName + "] finished with code: " + EXIT_CODE_INVALID_ARGUMENTS);

if (verbose)
err = e;
Expand All @@ -392,7 +392,7 @@ public <A extends IgniteDataTransferObject> int execute(List<String> rawArgs) {
}

logger.error(errorMessage(e));
logger.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_UNEXPECTED_ERROR);
logger.info("Command [" + cmdName + "] finished with code: " + EXIT_CODE_UNEXPECTED_ERROR);

err = e;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ public JmxCommandHandler(@Nullable IgniteLogger log) {

/** {@inheritDoc} */
@Override public int execute(List<String> value) {
String commandName = null;
String cmdName = null;

try {
ArgumentParser parser = new ArgumentParser(log, new IgniteCommandRegistry());

ConnectionAndSslParameters<IgniteDataTransferObject> p = parser.parseAndValidate(value);

commandName = toFormattedCommandName(p.cmdPath().peekLast().getClass()).toUpperCase();
cmdName = toFormattedCommandName(p.cmdPath().peekLast().getClass()).toUpperCase();

Deque<Command<?, ?>> cmdPath = new ArrayDeque<>(p.cmdPath());

Expand Down Expand Up @@ -257,7 +257,7 @@ public JmxCommandHandler(@Nullable IgniteLogger log) {
IllegalArgumentException iae = X.cause(e, IllegalArgumentException.class);

log.error("Check arguments. " + errorMessage(iae));
log.info("Command [" + commandName + "] finished with code: " + EXIT_CODE_INVALID_ARGUMENTS);
log.info("Command [" + cmdName + "] finished with code: " + EXIT_CODE_INVALID_ARGUMENTS);

return EXIT_CODE_INVALID_ARGUMENTS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ public static GridJavaProcess exec(String clsName, String params, @Nullable Igni
List<String> procParams = params == null || params.isEmpty() ?
Collections.<String>emptyList() : Arrays.asList(params.split(" "));

List<String> procCommands = new ArrayList<>();
List<String> procCmds = new ArrayList<>();

String javaBin = resolveJavaBin(javaHome);

procCommands.add(javaBin);
procCommands.addAll(jvmArgs == null ? U.jvmArgs() : jvmArgs);
procCmds.add(javaBin);
procCmds.addAll(jvmArgs == null ? U.jvmArgs() : jvmArgs);

if (jvmArgs == null || (!jvmArgs.contains("-cp") && !jvmArgs.contains("-classpath"))) {
String classpath = System.getProperty("java.class.path");
Expand All @@ -158,14 +158,14 @@ public static GridJavaProcess exec(String clsName, String params, @Nullable Igni
if (cp != null)
classpath += System.getProperty("path.separator") + cp;

procCommands.add("-cp");
procCommands.add(classpath);
procCmds.add("-cp");
procCmds.add(classpath);
}

procCommands.add(clsName);
procCommands.addAll(procParams);
procCmds.add(clsName);
procCmds.addAll(procParams);

ProcessBuilder builder = new ProcessBuilder(procCommands);
ProcessBuilder builder = new ProcessBuilder(procCmds);

builder.redirectErrorStream(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public class GridLogCommandHandlerTest extends GridCommonAbstractTest {
public void testSupportedCommands() throws Exception {
GridLogCommandHandler cmdHandler = new GridLogCommandHandler(newContext());

Collection<GridRestCommand> commands = cmdHandler.supportedCommands();
Collection<GridRestCommand> cmds = cmdHandler.supportedCommands();

assertEquals(1, commands.size());
assertTrue(commands.contains(GridRestCommand.LOG));
assertEquals(1, cmds.size());
assertTrue(cmds.contains(GridRestCommand.LOG));
}

/**
Expand All @@ -87,10 +87,10 @@ public void testSupportedCommands() throws Exception {
public void testUnSupportedCommands() throws Exception {
GridLogCommandHandler cmdHandler = new GridLogCommandHandler(newContext());

Collection<GridRestCommand> commands = cmdHandler.supportedCommands();
Collection<GridRestCommand> cmds = cmdHandler.supportedCommands();

assertEquals(1, commands.size());
assertFalse(commands.contains(GridRestCommand.VERSION));
assertEquals(1, cmds.size());
assertFalse(cmds.contains(GridRestCommand.VERSION));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public void testSupportedCommands() throws Exception {

QueryCommandHandler cmdHnd = new QueryCommandHandler(ctx);

Collection<GridRestCommand> commands = cmdHnd.supportedCommands();
Collection<GridRestCommand> cmds = cmdHnd.supportedCommands();

assertEquals(5, commands.size());
assertEquals(5, cmds.size());

assertTrue(commands.contains(GridRestCommand.EXECUTE_SQL_QUERY));
assertTrue(commands.contains(GridRestCommand.EXECUTE_SQL_FIELDS_QUERY));
assertTrue(commands.contains(GridRestCommand.EXECUTE_SCAN_QUERY));
assertTrue(commands.contains(GridRestCommand.FETCH_SQL_QUERY));
assertTrue(commands.contains(GridRestCommand.CLOSE_SQL_QUERY));
assertTrue(cmds.contains(GridRestCommand.EXECUTE_SQL_QUERY));
assertTrue(cmds.contains(GridRestCommand.EXECUTE_SQL_FIELDS_QUERY));
assertTrue(cmds.contains(GridRestCommand.EXECUTE_SCAN_QUERY));
assertTrue(cmds.contains(GridRestCommand.FETCH_SQL_QUERY));
assertTrue(cmds.contains(GridRestCommand.CLOSE_SQL_QUERY));
}

/**
Expand All @@ -81,9 +81,9 @@ public void testUnsupportedCommands() throws Exception {

QueryCommandHandler cmdHnd = new QueryCommandHandler(ctx);

Collection<GridRestCommand> commands = cmdHnd.supportedCommands();
Collection<GridRestCommand> cmds = cmdHnd.supportedCommands();

assertFalse(commands.contains(GridRestCommand.LOG));
assertFalse(cmds.contains(GridRestCommand.LOG));
}

/**
Expand Down

0 comments on commit 99dfd02

Please sign in to comment.