use of org.apache.geode.management.internal.cli.multistep.MultiStepCommand in project geode by apache.
the class DataCommands method query.
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION })
@MultiStepCommand
@CliCommand(value = { CliStrings.QUERY }, help = CliStrings.QUERY__HELP)
public Object query(@CliOption(key = CliStrings.QUERY__QUERY, help = CliStrings.QUERY__QUERY__HELP, mandatory = true) final String query, @CliOption(key = CliStrings.QUERY__STEPNAME, help = "Step name", unspecifiedDefaultValue = CliStrings.QUERY__STEPNAME__DEFAULTVALUE) String stepName, @CliOption(key = CliStrings.QUERY__INTERACTIVE, help = CliStrings.QUERY__INTERACTIVE__HELP, unspecifiedDefaultValue = "true") final boolean interactive) {
if (!CliUtil.isGfshVM() && stepName.equals(CliStrings.QUERY__STEPNAME__DEFAULTVALUE)) {
return ResultBuilder.createInfoResult(CliStrings.QUERY__MSG__NOT_SUPPORTED_ON_MEMBERS);
}
Object[] arguments = new Object[] { query, stepName, interactive };
CLIStep exec = new DataCommandFunction.SelectExecStep(arguments);
CLIStep display = new DataCommandFunction.SelectDisplayStep(arguments);
CLIStep move = new DataCommandFunction.SelectMoveStep(arguments);
CLIStep quit = new DataCommandFunction.SelectQuitStep(arguments);
CLIStep[] steps = { exec, display, move, quit };
return CLIMultiStepHelper.chooseStep(steps, stepName);
}
use of org.apache.geode.management.internal.cli.multistep.MultiStepCommand in project geode by apache.
the class GfshExecutionStrategy method execute.
//////////////// ExecutionStrategy interface Methods Start ///////////////////
///////////////////////// Implemented Methods ////////////////////////////////
/**
* Executes the method indicated by the {@link ParseResult} which would always be
* {@link GfshParseResult} for GemFire defined commands. If the command Method is decorated with
* {@link CliMetaData#shellOnly()} set to <code>false</code>, {@link OperationInvoker} is used to
* send the command for processing on a remote GemFire node.
*
* @param parseResult that should be executed (never presented as null)
* @return an object which will be rendered by the {@link Shell} implementation (may return null)
* @throws RuntimeException which is handled by the {@link Shell} implementation
*/
@Override
public Object execute(ParseResult parseResult) {
Result result = null;
Method method = parseResult.getMethod();
try {
// Check if it's a multi-step command
MultiStepCommand cmd = method.getAnnotation(MultiStepCommand.class);
if (cmd != null) {
return execCLISteps(logWrapper, shell, parseResult);
}
// check if it's a shell only command
if (isShellOnly(method)) {
Assert.notNull(parseResult, "Parse result required");
synchronized (mutex) {
Assert.isTrue(isReadyForCommands(), "ProcessManagerHostedExecutionStrategy not yet ready for commands");
return ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments());
}
}
// check if it's a GfshParseResult
if (!GfshParseResult.class.isInstance(parseResult)) {
throw new IllegalStateException("Configuration error!");
}
result = executeOnRemote((GfshParseResult) parseResult);
} catch (NotAuthorizedException e) {
result = ResultBuilder.createGemFireUnAuthorizedErrorResult("Unauthorized. Reason: " + e.getMessage());
} catch (JMXInvocationException | IllegalStateException e) {
Gfsh.getCurrentInstance().logWarning(e.getMessage(), e);
} catch (CommandProcessingException e) {
Gfsh.getCurrentInstance().logWarning(e.getMessage(), null);
Object errorData = e.getErrorData();
if (errorData != null && errorData instanceof Throwable) {
logWrapper.warning(e.getMessage(), (Throwable) errorData);
} else {
logWrapper.warning(e.getMessage());
}
} catch (Exception e) {
Gfsh.getCurrentInstance().logWarning("Unexpected exception occurred. " + e.getMessage(), e);
// Log other exceptions in gfsh log
logWrapper.warning("Unexpected error occurred while executing command : " + ((GfshParseResult) parseResult).getUserInput(), e);
}
return result;
}
Aggregations