Search in sources :

Example 1 with CommandResultException

use of org.apache.geode.management.internal.cli.result.CommandResultException in project geode by apache.

the class WanCommands method stopGatewayReceiver.

@CliCommand(value = CliStrings.STOP_GATEWAYRECEIVER, help = CliStrings.STOP_GATEWAYRECEIVER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result stopGatewayReceiver(@CliOption(key = CliStrings.STOP_GATEWAYRECEIVER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.STOP_GATEWAYRECEIVER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.STOP_GATEWAYRECEIVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.STOP_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()) {
                        receieverBean.stop();
                        accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_OK, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_STOPPED_ON_MEMBER_0, new Object[] { member.getId() }));
                    } else {
                        accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_NOT_RUNNING_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)

Example 2 with CommandResultException

use of org.apache.geode.management.internal.cli.result.CommandResultException in project geode by apache.

the class LuceneIndexCommands method createIndex.

@CliCommand(value = LuceneCliStrings.LUCENE_CREATE_INDEX, help = LuceneCliStrings.LUCENE_CREATE_INDEX__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
public // TODO : Add optionContext for indexName
Result createIndex(@CliOption(key = LuceneCliStrings.LUCENE__INDEX_NAME, mandatory = true, help = LuceneCliStrings.LUCENE_CREATE_INDEX__NAME__HELP) final String indexName, @CliOption(key = LuceneCliStrings.LUCENE__REGION_PATH, mandatory = true, optionContext = ConverterHint.REGION_PATH, help = LuceneCliStrings.LUCENE_CREATE_INDEX__REGION_HELP) final String regionPath, @CliOption(key = LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, mandatory = true, help = LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD_HELP) final String[] fields, @CliOption(key = LuceneCliStrings.LUCENE_CREATE_INDEX__ANALYZER, help = LuceneCliStrings.LUCENE_CREATE_INDEX__ANALYZER_HELP) final String[] analyzers) {
    Result result;
    XmlEntity xmlEntity = null;
    this.securityService.authorizeRegionManage(regionPath);
    try {
        final InternalCache cache = getCache();
        // trim fields for any leading trailing spaces.
        String[] trimmedFields = Arrays.stream(fields).map(field -> field.trim()).toArray(size -> new String[size]);
        LuceneIndexInfo indexInfo = new LuceneIndexInfo(indexName, regionPath, trimmedFields, analyzers);
        final ResultCollector<?, ?> rc = this.executeFunctionOnAllMembers(createIndexFunction, indexInfo);
        final List<CliFunctionResult> funcResults = (List<CliFunctionResult>) rc.getResult();
        final TabularResultData tabularResult = ResultBuilder.createTabularResultData();
        for (final CliFunctionResult cliFunctionResult : funcResults) {
            tabularResult.accumulate("Member", cliFunctionResult.getMemberIdOrName());
            if (cliFunctionResult.isSuccessful()) {
                tabularResult.accumulate("Status", "Successfully created lucene index");
            // if (xmlEntity == null) {
            // xmlEntity = cliFunctionResult.getXmlEntity();
            // }
            } else {
                tabularResult.accumulate("Status", "Failed: " + cliFunctionResult.getMessage());
            }
        }
        result = ResultBuilder.buildResult(tabularResult);
    } catch (IllegalArgumentException iae) {
        LogWrapper.getInstance().info(iae.getMessage());
        result = ResultBuilder.createUserErrorResult(iae.getMessage());
    } catch (CommandResultException crex) {
        result = crex.getResult();
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    return result;
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) StringUtils(org.apache.commons.lang.StringUtils) CliAvailabilityIndicator(org.springframework.shell.core.annotation.CliAvailabilityIndicator) Arrays(java.util.Arrays) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) Execution(org.apache.geode.cache.execute.Execution) CliMetaData(org.apache.geode.management.cli.CliMetaData) Function(org.apache.geode.cache.execute.Function) CliOption(org.springframework.shell.core.annotation.CliOption) ArrayList(java.util.ArrayList) LuceneListIndexFunction(org.apache.geode.cache.lucene.internal.cli.functions.LuceneListIndexFunction) HashSet(java.util.HashSet) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) LuceneDescribeIndexFunction(org.apache.geode.cache.lucene.internal.cli.functions.LuceneDescribeIndexFunction) CliStrings(org.apache.geode.management.internal.cli.i18n.CliStrings) Region(org.apache.geode.cache.Region) LuceneSearchIndexFunction(org.apache.geode.cache.lucene.internal.cli.functions.LuceneSearchIndexFunction) SystemFailure(org.apache.geode.SystemFailure) IntegratedSecurityService(org.apache.geode.internal.security.IntegratedSecurityService) Result(org.apache.geode.management.cli.Result) DistributedMember(org.apache.geode.distributed.DistributedMember) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) LinkedHashSet(java.util.LinkedHashSet) CliUtil(org.apache.geode.management.internal.cli.CliUtil) Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) CliCommand(org.springframework.shell.core.annotation.CliCommand) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) GfshCommand(org.apache.geode.management.internal.cli.commands.GfshCommand) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) SecurityService(org.apache.geode.internal.security.SecurityService) Set(java.util.Set) ResultCollector(org.apache.geode.cache.execute.ResultCollector) Collectors(java.util.stream.Collectors) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) List(java.util.List) LogWrapper(org.apache.geode.management.internal.cli.LogWrapper) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation) LuceneCreateIndexFunction(org.apache.geode.cache.lucene.internal.cli.functions.LuceneCreateIndexFunction) LuceneDestroyIndexFunction(org.apache.geode.cache.lucene.internal.cli.functions.LuceneDestroyIndexFunction) Resource(org.apache.geode.security.ResourcePermission.Resource) ConverterHint(org.apache.geode.management.cli.ConverterHint) Operation(org.apache.geode.security.ResourcePermission.Operation) ResultBuilder(org.apache.geode.management.internal.cli.result.ResultBuilder) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ArrayList(java.util.ArrayList) List(java.util.List) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 3 with CommandResultException

use of org.apache.geode.management.internal.cli.result.CommandResultException 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

DistributedMember (org.apache.geode.distributed.DistributedMember)3 InternalCache (org.apache.geode.internal.cache.InternalCache)3 CliMetaData (org.apache.geode.management.cli.CliMetaData)3 Result (org.apache.geode.management.cli.Result)3 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)3 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)3 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)3 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)3 CliCommand (org.springframework.shell.core.annotation.CliCommand)3 ExecutionException (java.util.concurrent.ExecutionException)2 ObjectName (javax.management.ObjectName)2 GatewayReceiverMXBean (org.apache.geode.management.GatewayReceiverMXBean)2 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1