Search in sources :

Example 71 with CliCommand

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

the class DataCommands method rebalance.

@CliCommand(value = CliStrings.REBALANCE, help = CliStrings.REBALANCE__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result rebalance(@CliOption(key = CliStrings.REBALANCE__INCLUDEREGION, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.REBALANCE__INCLUDEREGION__HELP) String[] includeRegions, @CliOption(key = CliStrings.REBALANCE__EXCLUDEREGION, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.REBALANCE__EXCLUDEREGION__HELP) String[] excludeRegions, @CliOption(key = CliStrings.REBALANCE__TIMEOUT, unspecifiedDefaultValue = "-1", help = CliStrings.REBALANCE__TIMEOUT__HELP) long timeout, @CliOption(key = CliStrings.REBALANCE__SIMULATE, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.REBALANCE__SIMULATE__HELP) boolean simulate) {
    ExecutorService commandExecutors = Executors.newSingleThreadExecutor();
    List<Future<Result>> commandResult = new ArrayList<>();
    Result result;
    try {
        commandResult.add(commandExecutors.submit(new ExecuteRebalanceWithTimeout(includeRegions, excludeRegions, simulate)));
        Future<Result> fs = commandResult.get(0);
        if (timeout > 0) {
            result = fs.get(timeout, TimeUnit.SECONDS);
        } else {
            result = fs.get();
        }
    } catch (TimeoutException timeoutException) {
        result = ResultBuilder.createInfoResult(CliStrings.REBALANCE__MSG__REBALANCE_WILL_CONTINUE);
    } catch (Exception ex) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.REBALANCE__MSG__EXCEPTION_OCCRED_WHILE_REBALANCING_0, ex.getMessage()));
    }
    LogWrapper.getInstance().info("Rebalance returning result >>>" + result);
    return result;
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) TimeoutException(java.util.concurrent.TimeoutException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) Result(org.apache.geode.management.cli.Result) DataCommandResult(org.apache.geode.management.internal.cli.domain.DataCommandResult) TimeoutException(java.util.concurrent.TimeoutException) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 72 with CliCommand

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

the class ShellCommands method exit.

@CliCommand(value = { CliStrings.EXIT, "quit" }, help = CliStrings.EXIT__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GFSH })
public ExitShellRequest exit() throws IOException {
    Gfsh gfshInstance = getGfsh();
    gfshInstance.stop();
    ExitShellRequest exitShellRequest = gfshInstance.getExitShellRequest();
    if (exitShellRequest == null) {
        // shouldn't really happen, but we'll fallback to this anyway
        exitShellRequest = ExitShellRequest.NORMAL_EXIT;
    }
    return exitShellRequest;
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) ExitShellRequest(org.springframework.shell.core.ExitShellRequest) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 73 with CliCommand

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

the class ShellCommands method describeConnection.

@CliCommand(value = { CliStrings.DESCRIBE_CONNECTION }, help = CliStrings.DESCRIBE_CONNECTION__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GFSH, CliStrings.TOPIC_GEODE_JMX })
public Result describeConnection() {
    Result result = null;
    try {
        TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
        Gfsh gfshInstance = getGfsh();
        if (gfshInstance.isConnectedAndReady()) {
            OperationInvoker operationInvoker = gfshInstance.getOperationInvoker();
            // tabularResultData.accumulate("Monitored GemFire DS", operationInvoker.toString());
            tabularResultData.accumulate("Connection Endpoints", operationInvoker.toString());
        } else {
            tabularResultData.accumulate("Connection Endpoints", "Not connected");
        }
        result = ResultBuilder.buildResult(tabularResultData);
    } catch (Exception e) {
        ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
        result = ResultBuilder.buildResult(errorResultData);
    }
    return result;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) RestHttpOperationInvoker(org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker) OperationInvoker(org.apache.geode.management.internal.cli.shell.OperationInvoker) HttpOperationInvoker(org.apache.geode.management.internal.web.shell.HttpOperationInvoker) JmxOperationInvoker(org.apache.geode.management.internal.cli.shell.JmxOperationInvoker) Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Result(org.apache.geode.management.cli.Result) ConnectToLocatorResult(org.apache.geode.management.internal.cli.domain.ConnectToLocatorResult) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 74 with CliCommand

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

the class ShellCommands method disconnect.

@CliCommand(value = { CliStrings.DISCONNECT }, help = CliStrings.DISCONNECT__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GFSH, CliStrings.TOPIC_GEODE_JMX, CliStrings.TOPIC_GEODE_MANAGER })
public Result disconnect() {
    Result result = null;
    if (getGfsh() != null && !getGfsh().isConnectedAndReady()) {
        result = ResultBuilder.createInfoResult("Not connected.");
    } else {
        InfoResultData infoResultData = ResultBuilder.createInfoResultData();
        try {
            Gfsh gfshInstance = getGfsh();
            if (gfshInstance.isConnectedAndReady()) {
                OperationInvoker operationInvoker = gfshInstance.getOperationInvoker();
                Gfsh.println("Disconnecting from: " + operationInvoker);
                operationInvoker.stop();
                infoResultData.addLine(CliStrings.format(CliStrings.DISCONNECT__MSG__DISCONNECTED, operationInvoker.toString()));
                LogWrapper.getInstance().info(CliStrings.format(CliStrings.DISCONNECT__MSG__DISCONNECTED, operationInvoker.toString()));
                gfshInstance.setPromptPath(org.apache.geode.management.internal.cli.converters.RegionPathConverter.DEFAULT_APP_CONTEXT_PATH);
            } else {
                infoResultData.addLine(CliStrings.DISCONNECT__MSG__NOTCONNECTED);
            }
            result = ResultBuilder.buildResult(infoResultData);
        } catch (Exception e) {
            result = ResultBuilder.createConnectionErrorResult(CliStrings.format(CliStrings.DISCONNECT__MSG__ERROR, e.getMessage()));
        }
    }
    return result;
}
Also used : InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) RestHttpOperationInvoker(org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker) OperationInvoker(org.apache.geode.management.internal.cli.shell.OperationInvoker) HttpOperationInvoker(org.apache.geode.management.internal.web.shell.HttpOperationInvoker) JmxOperationInvoker(org.apache.geode.management.internal.cli.shell.JmxOperationInvoker) Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Result(org.apache.geode.management.cli.Result) ConnectToLocatorResult(org.apache.geode.management.internal.cli.domain.ConnectToLocatorResult) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 75 with CliCommand

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

the class StatusCommands method statusSharedConfiguration.

@SuppressWarnings("unchecked")
@CliCommand(value = CliStrings.STATUS_SHARED_CONFIG, help = CliStrings.STATUS_SHARED_CONFIG_HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_LOCATOR)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result statusSharedConfiguration() {
    final InternalCache cache = GemFireCacheImpl.getInstance();
    final Set<DistributedMember> locators = new HashSet<DistributedMember>(cache.getDistributionManager().getAllHostedLocatorsWithSharedConfiguration().keySet());
    if (locators.isEmpty()) {
        return ResultBuilder.createInfoResult(CliStrings.NO_LOCATORS_WITH_SHARED_CONFIG);
    } else {
        return ResultBuilder.buildResult(getSharedConfigurationStatus(locators));
    }
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) HashSet(java.util.HashSet) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

CliCommand (org.springframework.shell.core.annotation.CliCommand)112 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)25 ConverterHint (org.apache.geode.management.cli.ConverterHint)24 IOException (java.io.IOException)20 File (java.io.File)17 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