Search in sources :

Example 1 with GatewaySenderDestroyFunctionArgs

use of org.apache.geode.management.internal.cli.functions.GatewaySenderDestroyFunctionArgs in project geode by apache.

the class WanCommands method destroyGatewaySender.

@CliCommand(value = CliStrings.DESTROY_GATEWAYSENDER, help = CliStrings.DESTROY_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result destroyGatewaySender(@CliOption(key = CliStrings.DESTROY_GATEWAYSENDER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.DESTROY_GATEWAYSENDER__GROUP__HELP) String[] onGroups, @CliOption(key = CliStrings.DESTROY_GATEWAYSENDER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.DESTROY_GATEWAYSENDER__MEMBER__HELP) String[] onMember, @CliOption(key = CliStrings.DESTROY_GATEWAYSENDER__ID, mandatory = true, optionContext = ConverterHint.GATEWAY_SENDER_ID, help = CliStrings.DESTROY_GATEWAYSENDER__ID__HELP) String id) {
    Result result = null;
    try {
        GatewaySenderDestroyFunctionArgs gatewaySenderDestroyFunctionArgs = new GatewaySenderDestroyFunctionArgs(id);
        Set<DistributedMember> membersToDestroyGatewaySenderOn = CliUtil.findMembers(onGroups, onMember);
        if (membersToDestroyGatewaySenderOn.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(GatewaySenderDestroyFunction.INSTANCE, gatewaySenderDestroyFunctionArgs, membersToDestroyGatewaySenderOn);
        @SuppressWarnings("unchecked") List<CliFunctionResult> gatewaySenderDestroyResults = (List<CliFunctionResult>) resultCollector.getResult();
        TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
        final String errorPrefix = "ERROR: ";
        for (CliFunctionResult gatewaySenderDestroyResult : gatewaySenderDestroyResults) {
            boolean success = gatewaySenderDestroyResult.isSuccessful();
            tabularResultData.accumulate("Member", gatewaySenderDestroyResult.getMemberIdOrName());
            tabularResultData.accumulate("Status", (success ? "" : errorPrefix) + gatewaySenderDestroyResult.getMessage());
        }
        result = ResultBuilder.buildResult(tabularResultData);
    } catch (IllegalArgumentException e) {
        LogWrapper.getInstance().info(e.getMessage());
        result = ResultBuilder.createUserErrorResult(e.getMessage());
    }
    return result;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) GatewaySenderDestroyFunctionArgs(org.apache.geode.management.internal.cli.functions.GatewaySenderDestroyFunctionArgs) DistributedMember(org.apache.geode.distributed.DistributedMember) ArrayList(java.util.ArrayList) List(java.util.List) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 CliMetaData (org.apache.geode.management.cli.CliMetaData)1 Result (org.apache.geode.management.cli.Result)1 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)1 GatewaySenderDestroyFunctionArgs (org.apache.geode.management.internal.cli.functions.GatewaySenderDestroyFunctionArgs)1 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)1 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)1 CliCommand (org.springframework.shell.core.annotation.CliCommand)1