Search in sources :

Example 1 with AsyncEventQueueDetails

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

Example 2 with AsyncEventQueueDetails

use of org.apache.geode.management.internal.cli.domain.AsyncEventQueueDetails in project geode by apache.

the class ListAsyncEventQueuesFunction method execute.

@Override
public void execute(final FunctionContext context) {
    // Declared here so that it's available when returning a Throwable
    String memberId = "";
    try {
        Cache cache = CacheFactory.getAnyInstance();
        DistributedMember member = cache.getDistributedSystem().getDistributedMember();
        memberId = member.getId();
        // If they set a name use it instead
        if (!member.getName().equals("")) {
            memberId = member.getName();
        }
        Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues();
        AsyncEventQueueDetails[] asyncEventQueueDetails = new AsyncEventQueueDetails[asyncEventQueues.size()];
        int i = 0;
        for (AsyncEventQueue queue : asyncEventQueues) {
            AsyncEventListener listener = queue.getAsyncEventListener();
            Properties listenerProperties = new Properties();
            if (listener instanceof Declarable2) {
                listenerProperties = ((Declarable2) listener).getConfig();
            }
            asyncEventQueueDetails[i++] = new AsyncEventQueueDetails(queue.getId(), queue.getBatchSize(), queue.isPersistent(), queue.getDiskStoreName(), queue.getMaximumQueueMemory(), listener.getClass().getName(), listenerProperties);
        }
        CliFunctionResult result = new CliFunctionResult(memberId, asyncEventQueueDetails);
        context.getResultSender().lastResult(result);
    } catch (CacheClosedException cce) {
        CliFunctionResult result = new CliFunctionResult(memberId, false, null);
        context.getResultSender().lastResult(result);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        logger.error("Could not list async event queues: {}", th.getMessage(), th);
        CliFunctionResult result = new CliFunctionResult(memberId, th, null);
        context.getResultSender().lastResult(result);
    }
}
Also used : AsyncEventQueueDetails(org.apache.geode.management.internal.cli.domain.AsyncEventQueueDetails) Declarable2(org.apache.geode.internal.cache.xmlcache.Declarable2) CacheClosedException(org.apache.geode.cache.CacheClosedException) Properties(java.util.Properties) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) DistributedMember(org.apache.geode.distributed.DistributedMember) Cache(org.apache.geode.cache.Cache) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Aggregations

Properties (java.util.Properties)2 DistributedMember (org.apache.geode.distributed.DistributedMember)2 AsyncEventQueueDetails (org.apache.geode.management.internal.cli.domain.AsyncEventQueueDetails)2 Map (java.util.Map)1 Cache (org.apache.geode.cache.Cache)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 AsyncEventListener (org.apache.geode.cache.asyncqueue.AsyncEventListener)1 AsyncEventQueue (org.apache.geode.cache.asyncqueue.AsyncEventQueue)1 Declarable2 (org.apache.geode.internal.cache.xmlcache.Declarable2)1 ConverterHint (org.apache.geode.management.cli.ConverterHint)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