Search in sources :

Example 1 with OperationInvoker

use of org.apache.geode.management.internal.cli.shell.OperationInvoker 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 2 with OperationInvoker

use of org.apache.geode.management.internal.cli.shell.OperationInvoker 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 3 with OperationInvoker

use of org.apache.geode.management.internal.cli.shell.OperationInvoker 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)

Aggregations

IOException (java.io.IOException)3 CliMetaData (org.apache.geode.management.cli.CliMetaData)3 OperationInvoker (org.apache.geode.management.internal.cli.shell.OperationInvoker)3 CliCommand (org.springframework.shell.core.annotation.CliCommand)3 MalformedURLException (java.net.MalformedURLException)2 Result (org.apache.geode.management.cli.Result)2 ConnectToLocatorResult (org.apache.geode.management.internal.cli.domain.ConnectToLocatorResult)2 Gfsh (org.apache.geode.management.internal.cli.shell.Gfsh)2 JmxOperationInvoker (org.apache.geode.management.internal.cli.shell.JmxOperationInvoker)2 HttpOperationInvoker (org.apache.geode.management.internal.web.shell.HttpOperationInvoker)2 RestHttpOperationInvoker (org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker)2 AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)2 ObjectName (javax.management.ObjectName)1 ErrorResultData (org.apache.geode.management.internal.cli.result.ErrorResultData)1 InfoResultData (org.apache.geode.management.internal.cli.result.InfoResultData)1 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)1