Search in sources :

Example 1 with ListAsyncEventQueuesFunction

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

the class QueueCommands method listAsyncEventQueues.

@CliCommand(value = CliStrings.LIST_ASYNC_EVENT_QUEUES, help = CliStrings.LIST_ASYNC_EVENT_QUEUES__HELP)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listAsyncEventQueues() {
    try {
        TabularResultData tabularData = ResultBuilder.createTabularResultData();
        boolean accumulatedData = false;
        Set<DistributedMember> targetMembers = CliUtil.findMembers(null, null);
        if (targetMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        ResultCollector<?, ?> rc = CliUtil.executeFunction(new ListAsyncEventQueuesFunction(), new Object[] {}, targetMembers);
        List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
        for (CliFunctionResult result : results) {
            if (result.getThrowable() != null) {
                tabularData.accumulate("Member", result.getMemberIdOrName());
                tabularData.accumulate("Result", "ERROR: " + result.getThrowable().getClass().getName() + ": " + result.getThrowable().getMessage());
                accumulatedData = true;
                tabularData.setStatus(Status.ERROR);
            } else {
                AsyncEventQueueDetails[] details = (AsyncEventQueueDetails[]) result.getSerializables();
                for (int i = 0; i < details.length; i++) {
                    tabularData.accumulate("Member", result.getMemberIdOrName());
                    tabularData.accumulate("ID", details[i].getId());
                    tabularData.accumulate("Batch Size", details[i].getBatchSize());
                    tabularData.accumulate("Persistent", details[i].isPersistent());
                    tabularData.accumulate("Disk Store", details[i].getDiskStoreName());
                    tabularData.accumulate("Max Memory", details[i].getMaxQueueMemory());
                    Properties listenerProperties = details[i].getListenerProperties();
                    if (listenerProperties == null || listenerProperties.size() == 0) {
                        tabularData.accumulate("Listener", details[i].getListener());
                    } else {
                        StringBuilder propsStringBuilder = new StringBuilder();
                        propsStringBuilder.append('(');
                        boolean firstProperty = true;
                        for (Map.Entry<Object, Object> property : listenerProperties.entrySet()) {
                            if (!firstProperty) {
                                propsStringBuilder.append(',');
                            } else {
                                firstProperty = false;
                            }
                            propsStringBuilder.append(property.getKey()).append('=').append(property.getValue());
                        }
                        propsStringBuilder.append(')');
                        tabularData.accumulate("Listener", details[i].getListener() + propsStringBuilder.toString());
                    }
                    accumulatedData = true;
                }
            }
        }
        if (!accumulatedData) {
            return ResultBuilder.createInfoResult(CliStrings.LIST_ASYNC_EVENT_QUEUES__NO_QUEUES_FOUND_MESSAGE);
        }
        return ResultBuilder.buildResult(tabularData);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_ASYNC_EVENT_QUEUES__ERROR_WHILE_LISTING_REASON_0, new Object[] { th.getMessage() }));
    }
}
Also used : ListAsyncEventQueuesFunction(org.apache.geode.management.internal.cli.functions.ListAsyncEventQueuesFunction) AsyncEventQueueDetails(org.apache.geode.management.internal.cli.domain.AsyncEventQueueDetails) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) Properties(java.util.Properties) ConverterHint(org.apache.geode.management.cli.ConverterHint) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) DistributedMember(org.apache.geode.distributed.DistributedMember) Map(java.util.Map) CliCommand(org.springframework.shell.core.annotation.CliCommand) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

Map (java.util.Map)1 Properties (java.util.Properties)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 ConverterHint (org.apache.geode.management.cli.ConverterHint)1 AsyncEventQueueDetails (org.apache.geode.management.internal.cli.domain.AsyncEventQueueDetails)1 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)1 ListAsyncEventQueuesFunction (org.apache.geode.management.internal.cli.functions.ListAsyncEventQueuesFunction)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