Search in sources :

Example 11 with Gfsh

use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.

the class ShellCommands method executeClearHistory.

Result executeClearHistory() {
    try {
        Gfsh gfsh = Gfsh.getCurrentInstance();
        gfsh.clearHistory();
    } catch (Exception e) {
        LogWrapper.getInstance().info(CliUtil.stackTraceAsString(e));
        return ResultBuilder.createGemFireErrorResult("Exception occurred while clearing history " + e.getMessage());
    }
    return ResultBuilder.createInfoResult(CliStrings.HISTORY__MSG__CLEARED_HISTORY);
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 12 with Gfsh

use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.

the class RegionPathConverter method getAllRegionPaths.

public Set<String> getAllRegionPaths() {
    Set<String> regionPathSet = Collections.emptySet();
    Gfsh gfsh = Gfsh.getCurrentInstance();
    if (gfsh != null && gfsh.isConnectedAndReady()) {
        String[] regionPaths = gfsh.getOperationInvoker().getDistributedSystemMXBean().listAllRegionPaths();
        if (regionPaths != null && regionPaths.length > 0) {
            regionPathSet = new TreeSet<String>();
            for (String regionPath : regionPaths) {
                if (regionPath != null) {
                    // Not needed after 46387/46502 are addressed
                    regionPathSet.add(regionPath);
                }
            }
        }
    }
    return regionPathSet;
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh)

Example 13 with Gfsh

use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.

the class LocatorDiscoveryConfigConverter method getLocatorIdAndNames.

private Set<String> getLocatorIdAndNames() {
    final Set<String> locatorIdsAndNames = new TreeSet<String>();
    final Gfsh gfsh = Gfsh.getCurrentInstance();
    if (gfsh != null && gfsh.isConnectedAndReady()) {
        final String[] locatorIds = gfsh.getOperationInvoker().getDistributedSystemMXBean().listLocators();
        if (locatorIds != null && locatorIds.length != 0) {
            locatorIdsAndNames.addAll(Arrays.asList(locatorIds));
        }
    }
    return locatorIdsAndNames;
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) TreeSet(java.util.TreeSet)

Example 14 with Gfsh

use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.

the class MemberGroupConverter method getMemberGroups.

public Set<String> getMemberGroups() {
    final Gfsh gfsh = Gfsh.getCurrentInstance();
    final Set<String> memberGroups = new TreeSet<String>();
    if (gfsh != null && gfsh.isConnectedAndReady()) {
        final String[] memberGroupsArray = gfsh.getOperationInvoker().getDistributedSystemMXBean().listGroups();
        memberGroups.addAll(Arrays.asList(memberGroupsArray));
    }
    return memberGroups;
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) TreeSet(java.util.TreeSet)

Example 15 with Gfsh

use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.

the class Launcher method parseCommandLineCommand.

private int parseCommandLineCommand(final String... args) {
    Gfsh gfsh = null;
    try {
        gfsh = Gfsh.getInstance(false, args, new GfshConfig());
        this.startupTimeLogHelper.logStartupTime();
    } catch (ClassNotFoundException cnfex) {
        log(cnfex, gfsh);
    } catch (IOException ioex) {
        log(ioex, gfsh);
    } catch (IllegalStateException isex) {
        System.err.println("ERROR : " + isex.getMessage());
    }
    ExitShellRequest exitRequest = ExitShellRequest.NORMAL_EXIT;
    if (gfsh != null) {
        final String commandLineCommand = combineStrings(args);
        if (commandLineCommand.startsWith(HELP)) {
            if (commandLineCommand.equals(HELP)) {
                printUsage(gfsh, System.out);
            } else {
                // help is also available for commands which are not available under
                // allowedCommandLineCommands
                gfsh.executeCommand(commandLineCommand);
            }
        } else {
            boolean commandIsAllowed = false;
            for (String allowedCommandLineCommand : this.allowedCommandLineCommands) {
                if (commandLineCommand.startsWith(allowedCommandLineCommand)) {
                    commandIsAllowed = true;
                    break;
                }
            }
            if (!commandIsAllowed) {
                System.err.println(CliStrings.format(MSG_INVALID_COMMAND_OR_OPTION, CliUtil.arrayToString(args)));
                exitRequest = ExitShellRequest.FATAL_EXIT;
            } else {
                if (!gfsh.executeScriptLine(commandLineCommand)) {
                    if (gfsh.getLastExecutionStatus() != 0)
                        exitRequest = ExitShellRequest.FATAL_EXIT;
                } else if (gfsh.getLastExecutionStatus() != 0) {
                    exitRequest = ExitShellRequest.FATAL_EXIT;
                }
            }
        }
    }
    return exitRequest.getExitCode();
}
Also used : GfshConfig(org.apache.geode.management.internal.cli.shell.GfshConfig) Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) IOException(java.io.IOException) ExitShellRequest(org.springframework.shell.core.ExitShellRequest)

Aggregations

Gfsh (org.apache.geode.management.internal.cli.shell.Gfsh)40 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)14 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)13 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)13 Test (org.junit.Test)13 IOException (java.io.IOException)11 CliMetaData (org.apache.geode.management.cli.CliMetaData)7 CliCommand (org.springframework.shell.core.annotation.CliCommand)7 TreeSet (java.util.TreeSet)6 ConnectToLocatorResult (org.apache.geode.management.internal.cli.domain.ConnectToLocatorResult)6 File (java.io.File)5 MalformedURLException (java.net.MalformedURLException)5 Result (org.apache.geode.management.cli.Result)5 AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)5 ConverterHint (org.apache.geode.management.cli.ConverterHint)3 JmxOperationInvoker (org.apache.geode.management.internal.cli.shell.JmxOperationInvoker)3 ConnectionEndpoint (org.apache.geode.management.internal.cli.util.ConnectionEndpoint)3 HttpOperationInvoker (org.apache.geode.management.internal.web.shell.HttpOperationInvoker)3 RestHttpOperationInvoker (org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker)3 ExitShellRequest (org.springframework.shell.core.ExitShellRequest)3