Search in sources :

Example 1 with MultiStepCommand

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);
}
Also used : CLIStep(org.apache.geode.management.internal.cli.multistep.CLIStep) MultiStepCommand(org.apache.geode.management.internal.cli.multistep.MultiStepCommand) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 2 with MultiStepCommand

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;
}
Also used : MultiStepCommand(org.apache.geode.management.internal.cli.multistep.MultiStepCommand) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Method(java.lang.reflect.Method) NotAuthorizedException(org.apache.geode.security.NotAuthorizedException) CommandProcessingException(org.apache.geode.management.cli.CommandProcessingException) NotAuthorizedException(org.apache.geode.security.NotAuthorizedException) CommandProcessingException(org.apache.geode.management.cli.CommandProcessingException) ParseResult(org.springframework.shell.event.ParseResult) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) FileResult(org.apache.geode.management.internal.cli.result.FileResult)

Aggregations

MultiStepCommand (org.apache.geode.management.internal.cli.multistep.MultiStepCommand)2 Method (java.lang.reflect.Method)1 CliMetaData (org.apache.geode.management.cli.CliMetaData)1 CommandProcessingException (org.apache.geode.management.cli.CommandProcessingException)1 Result (org.apache.geode.management.cli.Result)1 GfshParseResult (org.apache.geode.management.internal.cli.GfshParseResult)1 CLIStep (org.apache.geode.management.internal.cli.multistep.CLIStep)1 FileResult (org.apache.geode.management.internal.cli.result.FileResult)1 NotAuthorizedException (org.apache.geode.security.NotAuthorizedException)1 CliCommand (org.springframework.shell.core.annotation.CliCommand)1 ParseResult (org.springframework.shell.event.ParseResult)1