Search in sources :

Example 96 with CliCommand

use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.

the class StartJConsoleCommand method startJConsole.

@CliCommand(value = CliStrings.START_JCONSOLE, help = CliStrings.START_JCONSOLE__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_MANAGER, CliStrings.TOPIC_GEODE_JMX, CliStrings.TOPIC_GEODE_M_AND_M })
public Result startJConsole(@CliOption(key = CliStrings.START_JCONSOLE__INTERVAL, unspecifiedDefaultValue = "4", help = CliStrings.START_JCONSOLE__INTERVAL__HELP) final int interval, @CliOption(key = CliStrings.START_JCONSOLE__NOTILE, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.START_JCONSOLE__NOTILE__HELP) final boolean notile, @CliOption(key = CliStrings.START_JCONSOLE__PLUGINPATH, help = CliStrings.START_JCONSOLE__PLUGINPATH__HELP) final String pluginpath, @CliOption(key = CliStrings.START_JCONSOLE__VERSION, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.START_JCONSOLE__VERSION__HELP) final boolean version, @CliOption(key = CliStrings.START_JCONSOLE__J, optionContext = GfshParser.J_OPTION_CONTEXT, help = CliStrings.START_JCONSOLE__J__HELP) final String[] jvmArgs) {
    try {
        String[] jconsoleCommandLine = createJConsoleCommandLine(null, interval, notile, pluginpath, version, jvmArgs);
        if (isDebugging()) {
            getGfsh().printAsInfo(String.format("JConsole command-line ($1%s)", Arrays.toString(jconsoleCommandLine)));
        }
        Process jconsoleProcess = Runtime.getRuntime().exec(jconsoleCommandLine);
        StringBuilder message = new StringBuilder();
        if (version) {
            jconsoleProcess.waitFor();
            BufferedReader reader = new BufferedReader(new InputStreamReader(jconsoleProcess.getErrorStream()));
            for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                message.append(line);
                message.append(StringUtils.LINE_SEPARATOR);
            }
            IOUtils.close(reader);
        } else {
            getGfsh().printAsInfo(CliStrings.START_JCONSOLE__RUN);
            String jconsoleProcessOutput = waitAndCaptureProcessStandardErrorStream(jconsoleProcess);
            if (StringUtils.isNotBlank(jconsoleProcessOutput)) {
                message.append(StringUtils.LINE_SEPARATOR);
                message.append(jconsoleProcessOutput);
            }
        }
        return ResultBuilder.createInfoResult(message.toString());
    } catch (GemFireException | IllegalStateException | IllegalArgumentException e) {
        return ResultBuilder.createShellClientErrorResult(e.getMessage());
    } catch (IOException e) {
        return ResultBuilder.createShellClientErrorResult(CliStrings.START_JCONSOLE__IO_EXCEPTION_MESSAGE);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.START_JCONSOLE__CATCH_ALL_ERROR_MESSAGE, toString(t, false)));
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) GemFireException(org.apache.geode.GemFireException) BufferedReader(java.io.BufferedReader) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 97 with CliCommand

use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.

the class StartJVisualVMCommand method startJVisualVM.

@CliCommand(value = CliStrings.START_JVISUALVM, help = CliStrings.START_JVISUALVM__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_MANAGER, CliStrings.TOPIC_GEODE_JMX, CliStrings.TOPIC_GEODE_M_AND_M })
public Result startJVisualVM(@CliOption(key = CliStrings.START_JCONSOLE__J, optionContext = GfshParser.J_OPTION_CONTEXT, help = CliStrings.START_JCONSOLE__J__HELP) final String[] jvmArgs) {
    try {
        String[] jvisualvmCommandLine = createJVisualVMCommandLine(jvmArgs);
        if (isDebugging()) {
            getGfsh().printAsInfo(String.format("JVisualVM command-line (%1$s)", Arrays.toString(jvisualvmCommandLine)));
        }
        Process jvisualvmProcess = Runtime.getRuntime().exec(jvisualvmCommandLine);
        getGfsh().printAsInfo(CliStrings.START_JVISUALVM__RUN);
        String jvisualvmProcessOutput = waitAndCaptureProcessStandardErrorStream(jvisualvmProcess);
        InfoResultData infoResultData = ResultBuilder.createInfoResultData();
        if (StringUtils.isNotBlank(jvisualvmProcessOutput)) {
            infoResultData.addLine(StringUtils.LINE_SEPARATOR);
            infoResultData.addLine(jvisualvmProcessOutput);
        }
        return ResultBuilder.buildResult(infoResultData);
    } catch (GemFireException | IllegalStateException | IllegalArgumentException e) {
        return ResultBuilder.createShellClientErrorResult(e.getMessage());
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.START_JVISUALVM__ERROR_MESSAGE, toString(t, false)));
    }
}
Also used : GemFireException(org.apache.geode.GemFireException) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 98 with CliCommand

use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.

the class StartPulseCommand method startPulse.

@CliCommand(value = CliStrings.START_PULSE, help = CliStrings.START_PULSE__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_MANAGER, CliStrings.TOPIC_GEODE_JMX, CliStrings.TOPIC_GEODE_M_AND_M })
public Result startPulse(@CliOption(key = CliStrings.START_PULSE__URL, unspecifiedDefaultValue = "http://localhost:7070/pulse", help = CliStrings.START_PULSE__URL__HELP) final String url) {
    try {
        if (StringUtils.isNotBlank(url)) {
            browse(URI.create(url));
            return ResultBuilder.createInfoResult(CliStrings.START_PULSE__RUN);
        } else {
            if (isConnectedAndReady()) {
                OperationInvoker operationInvoker = getGfsh().getOperationInvoker();
                ObjectName managerObjectName = (ObjectName) operationInvoker.getAttribute(ManagementConstants.OBJECTNAME__DISTRIBUTEDSYSTEM_MXBEAN, "ManagerObjectName");
                String pulseURL = (String) operationInvoker.getAttribute(managerObjectName.toString(), "PulseURL");
                if (StringUtils.isNotBlank(pulseURL)) {
                    browse(URI.create(pulseURL));
                    return ResultBuilder.createInfoResult(CliStrings.START_PULSE__RUN + " with URL: " + pulseURL);
                } else {
                    String pulseMessage = (String) operationInvoker.getAttribute(managerObjectName.toString(), "StatusMessage");
                    return (StringUtils.isNotBlank(pulseMessage) ? ResultBuilder.createGemFireErrorResult(pulseMessage) : ResultBuilder.createGemFireErrorResult(CliStrings.START_PULSE__URL__NOTFOUND));
                }
            } else {
                return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.GFSH_MUST_BE_CONNECTED_FOR_LAUNCHING_0, "GemFire Pulse"));
            }
        }
    } catch (Exception e) {
        return ResultBuilder.createShellClientErrorResult(e.getMessage());
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.START_PULSE__ERROR, toString(t, false)));
    }
}
Also used : OperationInvoker(org.apache.geode.management.internal.cli.shell.OperationInvoker) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 99 with CliCommand

use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.

the class StatusLocatorCommand method statusLocator.

@CliCommand(value = CliStrings.STATUS_LOCATOR, help = CliStrings.STATUS_LOCATOR__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_LOCATOR, CliStrings.TOPIC_GEODE_LIFECYCLE })
public Result statusLocator(@CliOption(key = CliStrings.STATUS_LOCATOR__MEMBER, optionContext = ConverterHint.LOCATOR_MEMBER_IDNAME, help = CliStrings.STATUS_LOCATOR__MEMBER__HELP) final String member, @CliOption(key = CliStrings.STATUS_LOCATOR__HOST, help = CliStrings.STATUS_LOCATOR__HOST__HELP) final String locatorHost, @CliOption(key = CliStrings.STATUS_LOCATOR__PORT, help = CliStrings.STATUS_LOCATOR__PORT__HELP) final Integer locatorPort, @CliOption(key = CliStrings.STATUS_LOCATOR__PID, help = CliStrings.STATUS_LOCATOR__PID__HELP) final Integer pid, @CliOption(key = CliStrings.STATUS_LOCATOR__DIR, help = CliStrings.STATUS_LOCATOR__DIR__HELP) final String workingDirectory) {
    try {
        if (StringUtils.isNotBlank(member)) {
            if (isConnectedAndReady()) {
                final MemberMXBean locatorProxy = getMemberMXBean(member);
                if (locatorProxy != null) {
                    LocatorLauncher.LocatorState state = LocatorLauncher.LocatorState.fromJson(locatorProxy.status());
                    return createStatusLocatorResult(state);
                } else {
                    return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STATUS_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE, member));
                }
            } else {
                return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STATUS_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, LOCATOR_TERM_NAME));
            }
        } else {
            final LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STATUS).setBindAddress(locatorHost).setDebug(isDebugging()).setPid(pid).setPort(locatorPort).setWorkingDirectory(workingDirectory).build();
            final LocatorLauncher.LocatorState state = locatorLauncher.status();
            return createStatusLocatorResult(state);
        }
    } catch (IllegalArgumentException | IllegalStateException e) {
        return ResultBuilder.createUserErrorResult(e.getMessage());
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.STATUS_LOCATOR__GENERAL_ERROR_MESSAGE, getLocatorId(locatorHost, locatorPort), StringUtils.defaultIfBlank(workingDirectory, SystemUtils.CURRENT_DIRECTORY), toString(t, getGfsh().getDebug())));
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) MemberMXBean(org.apache.geode.management.MemberMXBean) MXBeanProvider.getMemberMXBean(org.apache.geode.management.internal.cli.shell.MXBeanProvider.getMemberMXBean) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 100 with CliCommand

use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.

the class ShellCommandsControllerJUnitTest method getCliCommands.

private List<String> getCliCommands() {
    try {
        Set<Class<?>> commandClasses = ClasspathScanLoadHelper.scanPackageForClassesImplementing("org.apache.geode.management.internal.cli.commands", CommandMarker.class);
        List<String> commands = new ArrayList<>(commandClasses.size());
        for (Class<?> commandClass : commandClasses) {
            for (Method method : commandClass.getMethods()) {
                if (method.isAnnotationPresent(CliCommand.class)) {
                    if (!(method.isAnnotationPresent(CliMetaData.class) && method.getAnnotation(CliMetaData.class).shellOnly())) {
                        CliCommand commandAnnotation = method.getAnnotation(CliCommand.class);
                        commands.addAll(Arrays.asList(commandAnnotation.value()));
                    }
                }
            }
        }
        return commands;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) BeforeClass(org.junit.BeforeClass) AfterClass(org.junit.AfterClass) CliCommand(org.springframework.shell.core.annotation.CliCommand) Method(java.lang.reflect.Method) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Aggregations

CliCommand (org.springframework.shell.core.annotation.CliCommand)100 CliMetaData (org.apache.geode.management.cli.CliMetaData)94 Result (org.apache.geode.management.cli.Result)66 DistributedMember (org.apache.geode.distributed.DistributedMember)60 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)58 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)42 InternalCache (org.apache.geode.internal.cache.InternalCache)37 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)35 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)31 ArrayList (java.util.ArrayList)29 List (java.util.List)24 ConverterHint (org.apache.geode.management.cli.ConverterHint)24 IOException (java.io.IOException)20 InfoResultData (org.apache.geode.management.internal.cli.result.InfoResultData)17 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)16 XmlEntity (org.apache.geode.management.internal.configuration.domain.XmlEntity)16 ExecutionException (java.util.concurrent.ExecutionException)15 GfshParseResult (org.apache.geode.management.internal.cli.GfshParseResult)15 HashSet (java.util.HashSet)14 ObjectName (javax.management.ObjectName)14