Search in sources :

Example 66 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData in project geode by apache.

the class ShellCommands method connect.

@CliCommand(value = { CliStrings.CONNECT }, help = CliStrings.CONNECT__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GFSH, CliStrings.TOPIC_GEODE_JMX, CliStrings.TOPIC_GEODE_MANAGER })
public Result connect(@CliOption(key = { CliStrings.CONNECT__LOCATOR }, unspecifiedDefaultValue = ConnectionEndpointConverter.DEFAULT_LOCATOR_ENDPOINTS, optionContext = ConnectionEndpoint.LOCATOR_OPTION_CONTEXT, help = CliStrings.CONNECT__LOCATOR__HELP) ConnectionEndpoint locatorTcpHostPort, @CliOption(key = { CliStrings.CONNECT__JMX_MANAGER }, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConnectionEndpoint.JMXMANAGER_OPTION_CONTEXT, help = CliStrings.CONNECT__JMX_MANAGER__HELP) ConnectionEndpoint memberRmiHostPort, @CliOption(key = { CliStrings.CONNECT__USE_HTTP }, mandatory = false, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.CONNECT__USE_HTTP__HELP) boolean useHttp, @CliOption(key = { CliStrings.CONNECT__URL }, mandatory = false, unspecifiedDefaultValue = CliStrings.CONNECT__DEFAULT_BASE_URL, help = CliStrings.CONNECT__URL__HELP) String url, @CliOption(key = { CliStrings.CONNECT__USERNAME }, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONNECT__USERNAME__HELP) String userName, @CliOption(key = { CliStrings.CONNECT__PASSWORD }, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONNECT__PASSWORD__HELP) String password, @CliOption(key = { CliStrings.CONNECT__KEY_STORE }, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONNECT__KEY_STORE__HELP) String keystore, @CliOption(key = { CliStrings.CONNECT__KEY_STORE_PASSWORD }, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONNECT__KEY_STORE_PASSWORD__HELP) String keystorePassword, @CliOption(key = { CliStrings.CONNECT__TRUST_STORE }, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONNECT__TRUST_STORE__HELP) String truststore, @CliOption(key = { CliStrings.CONNECT__TRUST_STORE_PASSWORD }, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONNECT__TRUST_STORE_PASSWORD__HELP) String truststorePassword, @CliOption(key = { CliStrings.CONNECT__SSL_CIPHERS }, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONNECT__SSL_CIPHERS__HELP) String sslCiphers, @CliOption(key = { CliStrings.CONNECT__SSL_PROTOCOLS }, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONNECT__SSL_PROTOCOLS__HELP) String sslProtocols, @CliOption(key = CliStrings.CONNECT__SECURITY_PROPERTIES, optionContext = ConverterHint.FILE_PATH, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONNECT__SECURITY_PROPERTIES__HELP) final String gfSecurityPropertiesPath, @CliOption(key = { CliStrings.CONNECT__USE_SSL }, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.CONNECT__USE_SSL__HELP) final boolean useSsl) {
    Result result;
    String passwordToUse = decrypt(password);
    String keystoreToUse = keystore;
    String keystorePasswordToUse = keystorePassword;
    String truststoreToUse = truststore;
    String truststorePasswordToUse = truststorePassword;
    String sslCiphersToUse = sslCiphers;
    String sslProtocolsToUse = sslProtocols;
    Gfsh gfsh = getGfsh();
    if (gfsh != null && gfsh.isConnectedAndReady()) {
        return ResultBuilder.createInfoResult("Already connected to: " + getGfsh().getOperationInvoker().toString());
    }
    Map<String, String> sslConfigProps = null;
    try {
        if (userName != null && userName.length() > 0) {
            if (passwordToUse == null || passwordToUse.length() == 0) {
                passwordToUse = gfsh.readPassword(CliStrings.CONNECT__PASSWORD + ": ");
            }
            if (passwordToUse == null || passwordToUse.length() == 0) {
                return ResultBuilder.createConnectionErrorResult(CliStrings.CONNECT__MSG__JMX_PASSWORD_MUST_BE_SPECIFIED);
            }
        }
        sslConfigProps = this.readSSLConfiguration(useSsl, keystoreToUse, keystorePasswordToUse, truststoreToUse, truststorePasswordToUse, sslCiphersToUse, sslProtocolsToUse, gfSecurityPropertiesPath);
    } catch (IOException e) {
        return handleExcpetion(e, null);
    }
    if (useHttp) {
        result = httpConnect(sslConfigProps, useSsl, url, userName, passwordToUse);
    } else {
        result = jmxConnect(sslConfigProps, memberRmiHostPort, locatorTcpHostPort, useSsl, userName, passwordToUse, gfSecurityPropertiesPath, false);
    }
    return result;
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) 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 67 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData in project geode by apache.

the class ShellCommands method echo.

@CliCommand(value = { CliStrings.ECHO }, help = CliStrings.ECHO__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GFSH })
public Result echo(@CliOption(key = { CliStrings.ECHO__STR, "" }, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = "", mandatory = true, help = CliStrings.ECHO__STR__HELP) String stringToEcho) {
    Result result = null;
    if (stringToEcho.equals("$*")) {
        Gfsh gfshInstance = getGfsh();
        Map<String, String> envMap = gfshInstance.getEnv();
        Set<Entry<String, String>> setEnvMap = envMap.entrySet();
        TabularResultData resultData = buildResultForEcho(setEnvMap);
        result = ResultBuilder.buildResult(resultData);
    } else {
        result = ResultBuilder.createInfoResult(stringToEcho);
    }
    return result;
}
Also used : Entry(java.util.Map.Entry) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) 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 68 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData in project geode by apache.

the class ShellCommands method executeScript.

@CliCommand(value = { CliStrings.RUN }, help = CliStrings.RUN__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GFSH })
public Result executeScript(@CliOption(key = CliStrings.RUN__FILE, optionContext = ConverterHint.FILE, mandatory = true, help = CliStrings.RUN__FILE__HELP) File file, @CliOption(key = { CliStrings.RUN__QUIET }, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.RUN__QUIET__HELP) boolean quiet, @CliOption(key = { CliStrings.RUN__CONTINUEONERROR }, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.RUN__CONTINUEONERROR__HELP) boolean continueOnError) {
    Result result = null;
    Gfsh gfsh = Gfsh.getCurrentInstance();
    try {
        result = gfsh.executeScript(file, quiet, continueOnError);
    } catch (IllegalArgumentException e) {
        result = ResultBuilder.createShellClientErrorResult(e.getMessage());
    }
    return result;
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) 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 69 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData in project geode by apache.

the class WanCommands method pauseGatewaySender.

@CliCommand(value = CliStrings.PAUSE_GATEWAYSENDER, help = CliStrings.PAUSE_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result pauseGatewaySender(@CliOption(key = CliStrings.PAUSE_GATEWAYSENDER__ID, mandatory = true, optionContext = ConverterHint.GATEWAY_SENDER_ID, help = CliStrings.PAUSE_GATEWAYSENDER__ID__HELP) String senderId, @CliOption(key = CliStrings.PAUSE_GATEWAYSENDER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.PAUSE_GATEWAYSENDER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.PAUSE_GATEWAYSENDER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.PAUSE_GATEWAYSENDER__MEMBER__HELP) String[] onMember) {
    Result result = null;
    if (senderId != null) {
        senderId = senderId.trim();
    }
    try {
        InternalCache cache = getCache();
        SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
        GatewaySenderMXBean bean = null;
        TabularResultData resultData = ResultBuilder.createTabularResultData();
        Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
        if (dsMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        for (DistributedMember member : dsMembers) {
            if (cache.getDistributedSystem().getDistributedMember().getId().equals(member.getId())) {
                bean = service.getLocalGatewaySenderMXBean(senderId);
            } else {
                ObjectName objectName = service.getGatewaySenderMBeanName(member, senderId);
                bean = service.getMBeanProxy(objectName, GatewaySenderMXBean.class);
            }
            if (bean != null) {
                if (bean.isRunning()) {
                    if (bean.isPaused()) {
                        accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_ALREADY_PAUSED_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
                    } else {
                        bean.pause();
                        accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_OK, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_PAUSED_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
                    }
                } else {
                    accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_NOT_RUNNING_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
                }
            } else {
                accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_NOT_AVAILABLE_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
            }
        }
        result = ResultBuilder.buildResult(resultData);
    } catch (Exception e) {
        LogWrapper.getInstance().warning(CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
        result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR + e.getMessage());
    }
    return result;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) GatewaySenderMXBean(org.apache.geode.management.GatewaySenderMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ExecutionException(java.util.concurrent.ExecutionException) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) ObjectName(javax.management.ObjectName) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 70 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData in project geode by apache.

the class WanCommands method startGatewayReceiver.

@CliCommand(value = CliStrings.START_GATEWAYRECEIVER, help = CliStrings.START_GATEWAYRECEIVER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result startGatewayReceiver(@CliOption(key = CliStrings.START_GATEWAYRECEIVER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.START_GATEWAYRECEIVER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.START_GATEWAYRECEIVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.START_GATEWAYRECEIVER__MEMBER__HELP) String[] onMember) {
    Result result = null;
    try {
        InternalCache cache = getCache();
        SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
        GatewayReceiverMXBean receieverBean = null;
        TabularResultData resultData = ResultBuilder.createTabularResultData();
        Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
        if (dsMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        for (DistributedMember member : dsMembers) {
            ObjectName gatewayReceiverObjectName = MBeanJMXAdapter.getGatewayReceiverMBeanName(member);
            if (gatewayReceiverObjectName != null) {
                receieverBean = service.getMBeanProxy(gatewayReceiverObjectName, GatewayReceiverMXBean.class);
                if (receieverBean != null) {
                    if (receieverBean.isRunning()) {
                        accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_ALREADY_STARTED_ON_MEMBER_0, new Object[] { member.getId() }));
                    } else {
                        receieverBean.start();
                        accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_OK, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_STARTED_ON_MEMBER_0, new Object[] { member.getId() }));
                    }
                } else {
                    accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_NOT_AVAILABLE_ON_MEMBER_0, new Object[] { member.getId() }));
                }
            } else {
                accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_NOT_AVAILABLE_ON_MEMBER_0, new Object[] { member.getId() }));
            }
        }
        result = ResultBuilder.buildResult(resultData);
    } catch (CommandResultException crex) {
        result = handleCommandResultException(crex);
    } catch (Exception e) {
        LogWrapper.getInstance().warning(CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
        result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR + e.getMessage());
    }
    return result;
}
Also used : GatewayReceiverMXBean(org.apache.geode.management.GatewayReceiverMXBean) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ExecutionException(java.util.concurrent.ExecutionException) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) ObjectName(javax.management.ObjectName) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

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