Search in sources :

Example 21 with CliFunctionResult

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

the class IndexCommands method createIndex.

@CliCommand(value = CliStrings.CREATE_INDEX, help = CliStrings.CREATE_INDEX__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
public // TODO : Add optionContext for indexName
Result createIndex(@CliOption(key = CliStrings.CREATE_INDEX__NAME, mandatory = true, help = CliStrings.CREATE_INDEX__NAME__HELP) final String indexName, @CliOption(key = CliStrings.CREATE_INDEX__EXPRESSION, mandatory = true, help = CliStrings.CREATE_INDEX__EXPRESSION__HELP) final String indexedExpression, @CliOption(key = CliStrings.CREATE_INDEX__REGION, mandatory = true, optionContext = ConverterHint.REGION_PATH, help = CliStrings.CREATE_INDEX__REGION__HELP) String regionPath, @CliOption(key = CliStrings.CREATE_INDEX__MEMBER, mandatory = false, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.CREATE_INDEX__MEMBER__HELP) final String[] memberNameOrID, @CliOption(key = CliStrings.CREATE_INDEX__TYPE, mandatory = false, unspecifiedDefaultValue = "range", optionContext = ConverterHint.INDEX_TYPE, help = CliStrings.CREATE_INDEX__TYPE__HELP) final String indexType, @CliOption(key = CliStrings.CREATE_INDEX__GROUP, mandatory = false, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.CREATE_INDEX__GROUP__HELP) final String[] group) {
    Result result = null;
    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
    this.securityService.authorizeRegionManage(regionPath);
    try {
        final Cache cache = CacheFactory.getAnyInstance();
        int idxType = IndexInfo.RANGE_INDEX;
        // Index type check
        if ("range".equalsIgnoreCase(indexType)) {
            idxType = IndexInfo.RANGE_INDEX;
        } else if ("hash".equalsIgnoreCase(indexType)) {
            idxType = IndexInfo.HASH_INDEX;
        } else if ("key".equalsIgnoreCase(indexType)) {
            idxType = IndexInfo.KEY_INDEX;
        } else {
            return ResultBuilder.createUserErrorResult(CliStrings.CREATE_INDEX__INVALID__INDEX__TYPE__MESSAGE);
        }
        if (indexName == null || indexName.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.CREATE_INDEX__INVALID__INDEX__NAME);
        }
        if (indexedExpression == null || indexedExpression.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.CREATE_INDEX__INVALID__EXPRESSION);
        }
        if (StringUtils.isBlank(regionPath) || regionPath.equals(Region.SEPARATOR)) {
            return ResultBuilder.createUserErrorResult(CliStrings.CREATE_INDEX__INVALID__REGIONPATH);
        }
        if (!regionPath.startsWith(Region.SEPARATOR)) {
            regionPath = Region.SEPARATOR + regionPath;
        }
        IndexInfo indexInfo = new IndexInfo(indexName, indexedExpression, regionPath, idxType);
        final Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrID);
        if (targetMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        final ResultCollector<?, ?> rc = CliUtil.executeFunction(createIndexFunction, indexInfo, targetMembers);
        final List<Object> funcResults = (List<Object>) rc.getResult();
        final Set<String> successfulMembers = new TreeSet<String>();
        final Map<String, Set<String>> indexOpFailMap = new HashMap<String, Set<String>>();
        for (final Object funcResult : funcResults) {
            if (funcResult instanceof CliFunctionResult) {
                final CliFunctionResult cliFunctionResult = (CliFunctionResult) funcResult;
                if (cliFunctionResult.isSuccessful()) {
                    successfulMembers.add(cliFunctionResult.getMemberIdOrName());
                    if (xmlEntity.get() == null) {
                        xmlEntity.set(cliFunctionResult.getXmlEntity());
                    }
                } else {
                    final String exceptionMessage = cliFunctionResult.getMessage();
                    Set<String> failedMembers = indexOpFailMap.get(exceptionMessage);
                    if (failedMembers == null) {
                        failedMembers = new TreeSet<String>();
                    }
                    failedMembers.add(cliFunctionResult.getMemberIdOrName());
                    indexOpFailMap.put(exceptionMessage, failedMembers);
                }
            }
        }
        if (!successfulMembers.isEmpty()) {
            final InfoResultData infoResult = ResultBuilder.createInfoResultData();
            infoResult.addLine(CliStrings.CREATE_INDEX__SUCCESS__MSG);
            infoResult.addLine(CliStrings.format(CliStrings.CREATE_INDEX__NAME__MSG, indexName));
            infoResult.addLine(CliStrings.format(CliStrings.CREATE_INDEX__EXPRESSION__MSG, indexedExpression));
            infoResult.addLine(CliStrings.format(CliStrings.CREATE_INDEX__REGIONPATH__MSG, regionPath));
            infoResult.addLine(CliStrings.CREATE_INDEX__MEMBER__MSG);
            int num = 0;
            for (final String memberId : successfulMembers) {
                ++num;
                infoResult.addLine(CliStrings.format(CliStrings.CREATE_INDEX__NUMBER__AND__MEMBER, num, memberId));
            }
            result = ResultBuilder.buildResult(infoResult);
        } else {
            // Group members by the exception thrown.
            final ErrorResultData erd = ResultBuilder.createErrorResultData();
            erd.addLine(CliStrings.format(CliStrings.CREATE_INDEX__FAILURE__MSG, indexName));
            final Set<String> exceptionMessages = indexOpFailMap.keySet();
            for (final String exceptionMessage : exceptionMessages) {
                erd.addLine(exceptionMessage);
                erd.addLine(CliStrings.CREATE_INDEX__EXCEPTION__OCCURRED__ON);
                final Set<String> memberIds = indexOpFailMap.get(exceptionMessage);
                int num = 0;
                for (final String memberId : memberIds) {
                    ++num;
                    erd.addLine(CliStrings.format(CliStrings.CREATE_INDEX__NUMBER__AND__MEMBER, num, memberId));
                }
            }
            result = ResultBuilder.buildResult(erd);
        }
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    if (xmlEntity.get() != null) {
        persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), group));
    }
    return result;
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) IndexInfo(org.apache.geode.management.internal.cli.domain.IndexInfo) ConverterHint(org.apache.geode.management.cli.ConverterHint) 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) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) TreeSet(java.util.TreeSet) DistributedMember(org.apache.geode.distributed.DistributedMember) ArrayList(java.util.ArrayList) List(java.util.List) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) Cache(org.apache.geode.cache.Cache) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 22 with CliFunctionResult

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

the class IndexCommands method createDefinedIndexes.

@CliCommand(value = CliStrings.CREATE_DEFINED_INDEXES, help = CliStrings.CREATE_DEFINED__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public // TODO : Add optionContext for indexName
Result createDefinedIndexes(@CliOption(key = CliStrings.CREATE_DEFINED_INDEXES__MEMBER, mandatory = false, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.CREATE_DEFINED_INDEXES__MEMBER__HELP) final String[] memberNameOrID, @CliOption(key = CliStrings.CREATE_DEFINED_INDEXES__GROUP, mandatory = false, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.CREATE_DEFINED_INDEXES__GROUP__HELP) final String[] group) {
    Result result = null;
    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
    if (indexDefinitions.isEmpty()) {
        final InfoResultData infoResult = ResultBuilder.createInfoResultData();
        infoResult.addLine(CliStrings.DEFINE_INDEX__FAILURE__MSG);
        return ResultBuilder.buildResult(infoResult);
    }
    try {
        final Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrID);
        if (targetMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        final Cache cache = CacheFactory.getAnyInstance();
        final ResultCollector<?, ?> rc = CliUtil.executeFunction(createDefinedIndexesFunction, indexDefinitions, targetMembers);
        final List<Object> funcResults = (List<Object>) rc.getResult();
        final Set<String> successfulMembers = new TreeSet<String>();
        final Map<String, Set<String>> indexOpFailMap = new HashMap<String, Set<String>>();
        for (final Object funcResult : funcResults) {
            if (funcResult instanceof CliFunctionResult) {
                final CliFunctionResult cliFunctionResult = (CliFunctionResult) funcResult;
                if (cliFunctionResult.isSuccessful()) {
                    successfulMembers.add(cliFunctionResult.getMemberIdOrName());
                    if (xmlEntity.get() == null) {
                        xmlEntity.set(cliFunctionResult.getXmlEntity());
                    }
                } else {
                    final String exceptionMessage = cliFunctionResult.getMessage();
                    Set<String> failedMembers = indexOpFailMap.get(exceptionMessage);
                    if (failedMembers == null) {
                        failedMembers = new TreeSet<String>();
                    }
                    failedMembers.add(cliFunctionResult.getMemberIdOrName());
                    indexOpFailMap.put(exceptionMessage, failedMembers);
                }
            }
        }
        if (!successfulMembers.isEmpty()) {
            final InfoResultData infoResult = ResultBuilder.createInfoResultData();
            infoResult.addLine(CliStrings.CREATE_DEFINED_INDEXES__SUCCESS__MSG);
            int num = 0;
            for (final String memberId : successfulMembers) {
                ++num;
                infoResult.addLine(CliStrings.format(CliStrings.CREATE_DEFINED_INDEXES__NUMBER__AND__MEMBER, num, memberId));
            }
            result = ResultBuilder.buildResult(infoResult);
        } else {
            // Group members by the exception thrown.
            final ErrorResultData erd = ResultBuilder.createErrorResultData();
            final Set<String> exceptionMessages = indexOpFailMap.keySet();
            for (final String exceptionMessage : exceptionMessages) {
                erd.addLine(exceptionMessage);
                erd.addLine(CliStrings.CREATE_INDEX__EXCEPTION__OCCURRED__ON);
                final Set<String> memberIds = indexOpFailMap.get(exceptionMessage);
                int num = 0;
                for (final String memberId : memberIds) {
                    ++num;
                    erd.addLine(CliStrings.format(CliStrings.CREATE_DEFINED_INDEXES__NUMBER__AND__MEMBER, num, memberId));
                }
            }
            result = ResultBuilder.buildResult(erd);
        }
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    if (xmlEntity.get() != null) {
        persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), group));
    }
    return result;
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConverterHint(org.apache.geode.management.cli.ConverterHint) 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) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) TreeSet(java.util.TreeSet) DistributedMember(org.apache.geode.distributed.DistributedMember) ArrayList(java.util.ArrayList) List(java.util.List) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) Cache(org.apache.geode.cache.Cache) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 23 with CliFunctionResult

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

the class DiskStoreCommands method destroyDiskStore.

@CliCommand(value = CliStrings.DESTROY_DISK_STORE, help = CliStrings.DESTROY_DISK_STORE__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DISKSTORE })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result destroyDiskStore(@CliOption(key = CliStrings.DESTROY_DISK_STORE__NAME, mandatory = true, help = CliStrings.DESTROY_DISK_STORE__NAME__HELP) String name, @CliOption(key = CliStrings.DESTROY_DISK_STORE__GROUP, help = CliStrings.DESTROY_DISK_STORE__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) String[] groups) {
    try {
        TabularResultData tabularData = ResultBuilder.createTabularResultData();
        boolean accumulatedData = false;
        Set<DistributedMember> targetMembers = CliUtil.findMembers(groups, null);
        if (targetMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        ResultCollector<?, ?> rc = CliUtil.executeFunction(new DestroyDiskStoreFunction(), new Object[] { name }, targetMembers);
        List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
        AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
        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 if (result.getMessage() != null) {
                tabularData.accumulate("Member", result.getMemberIdOrName());
                tabularData.accumulate("Result", result.getMessage());
                accumulatedData = true;
                if (xmlEntity.get() == null) {
                    xmlEntity.set(result.getXmlEntity());
                }
            }
        }
        if (!accumulatedData) {
            return ResultBuilder.createInfoResult("No matching disk stores found.");
        }
        Result result = ResultBuilder.buildResult(tabularData);
        if (xmlEntity.get() != null) {
            persistClusterConfiguration(result, () -> getSharedConfiguration().deleteXmlEntity(xmlEntity.get(), groups));
        }
        return result;
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESTROY_DISK_STORE__ERROR_WHILE_DESTROYING_REASON_0, new Object[] { th.getMessage() }));
    }
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) DestroyDiskStoreFunction(org.apache.geode.management.internal.cli.functions.DestroyDiskStoreFunction) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 24 with CliFunctionResult

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

the class QueueCommands method createAsyncEventQueue.

@CliCommand(value = CliStrings.CREATE_ASYNC_EVENT_QUEUE, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__HELP)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result createAsyncEventQueue(@CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID, mandatory = true, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID__HELP) String id, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__GROUP, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__GROUP__HELP) String[] groups, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__PARALLEL, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__PARALLEL__HELP) Boolean parallel, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__ENABLEBATCHCONFLATION, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__ENABLEBATCHCONFLATION__HELP) Boolean enableBatchConflation, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCH_SIZE, unspecifiedDefaultValue = "100", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCH_SIZE__HELP) int batchSize, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCHTIMEINTERVAL, unspecifiedDefaultValue = "1000", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCHTIMEINTERVAL__HELP) int batchTimeInterval, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__PERSISTENT, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__PERSISTENT__HELP) boolean persistent, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISK_STORE, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISK_STORE__HELP) String diskStore, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISKSYNCHRONOUS, unspecifiedDefaultValue = "true", specifiedDefaultValue = "true", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISKSYNCHRONOUS__HELP) Boolean diskSynchronous, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__FORWARD_EXPIRATION_DESTROY, unspecifiedDefaultValue = "false", specifiedDefaultValue = "false", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__FORWARD_EXPIRATION_DESTROY__HELP) Boolean ignoreEvictionAndExpiration, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__MAXIMUM_QUEUE_MEMORY, unspecifiedDefaultValue = "100", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__MAXIMUM_QUEUE_MEMORY__HELP) int maxQueueMemory, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISPATCHERTHREADS, unspecifiedDefaultValue = "1", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISPATCHERTHREADS__HELP) Integer dispatcherThreads, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__ORDERPOLICY, unspecifiedDefaultValue = "KEY", help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__ORDERPOLICY__HELP) String orderPolicy, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__GATEWAYEVENTFILTER, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__GATEWAYEVENTFILTER__HELP) String[] gatewayEventFilters, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__SUBSTITUTION_FILTER, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__SUBSTITUTION_FILTER__HELP) String gatewaySubstitutionListener, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER, mandatory = true, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER__HELP) String listener, @CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER_PARAM_AND_VALUE, help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER_PARAM_AND_VALUE__HELP) String[] listenerParamsAndValues) {
    Properties listenerProperties = new Properties();
    try {
        if (listenerParamsAndValues != null) {
            for (int i = 0; i < listenerParamsAndValues.length; i++) {
                final int hashPosition = listenerParamsAndValues[i].indexOf('#');
                if (hashPosition == -1) {
                    listenerProperties.put(listenerParamsAndValues[i], "");
                } else {
                    listenerProperties.put(listenerParamsAndValues[i].substring(0, hashPosition), listenerParamsAndValues[i].substring(hashPosition + 1));
                }
            }
        }
        TabularResultData tabularData = ResultBuilder.createTabularResultData();
        boolean accumulatedData = false;
        Set<DistributedMember> targetMembers = CliUtil.findMembers(groups, null);
        if (targetMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        AsyncEventQueueFunctionArgs aeqArgs = new AsyncEventQueueFunctionArgs(id, parallel, enableBatchConflation, batchSize, batchTimeInterval, persistent, diskStore, diskSynchronous, maxQueueMemory, dispatcherThreads, orderPolicy, gatewayEventFilters, gatewaySubstitutionListener, listener, listenerProperties, ignoreEvictionAndExpiration);
        ResultCollector<?, ?> rc = CliUtil.executeFunction(new CreateAsyncEventQueueFunction(), aeqArgs, targetMembers);
        List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
        AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
        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 if (result.isSuccessful()) {
                tabularData.accumulate("Member", result.getMemberIdOrName());
                tabularData.accumulate("Result", result.getMessage());
                accumulatedData = true;
                if (xmlEntity.get() == null) {
                    xmlEntity.set(result.getXmlEntity());
                }
            }
        }
        if (!accumulatedData) {
            return ResultBuilder.createInfoResult("Unable to create async event queue(s).");
        }
        Result result = ResultBuilder.buildResult(tabularData);
        if (xmlEntity.get() != null) {
            persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), groups));
        }
        return result;
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ERROR_WHILE_CREATING_REASON_0, new Object[] { th.getMessage() }));
    }
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) AsyncEventQueueFunctionArgs(org.apache.geode.management.internal.cli.functions.AsyncEventQueueFunctionArgs) AtomicReference(java.util.concurrent.atomic.AtomicReference) Properties(java.util.Properties) CreateAsyncEventQueueFunction(org.apache.geode.management.internal.cli.functions.CreateAsyncEventQueueFunction) ConverterHint(org.apache.geode.management.cli.ConverterHint) 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) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) DistributedMember(org.apache.geode.distributed.DistributedMember) CliCommand(org.springframework.shell.core.annotation.CliCommand) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 25 with CliFunctionResult

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

the class ExportImportClusterConfigurationCommands method reCreateCache.

private CliFunctionResult reCreateCache(DistributedMember server) {
    ResultCollector rc = CliUtil.executeFunction(new RecreateCacheFunction(), null, server);
    List<CliFunctionResult> results = (List<CliFunctionResult>) rc.getResult();
    return results.get(0);
}
Also used : CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) RecreateCacheFunction(org.apache.geode.management.internal.configuration.functions.RecreateCacheFunction)

Aggregations

CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)45 DistributedMember (org.apache.geode.distributed.DistributedMember)25 XmlEntity (org.apache.geode.management.internal.configuration.domain.XmlEntity)24 CliCommand (org.springframework.shell.core.annotation.CliCommand)22 CliMetaData (org.apache.geode.management.cli.CliMetaData)20 ArrayList (java.util.ArrayList)19 Result (org.apache.geode.management.cli.Result)19 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)17 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)17 List (java.util.List)14 InternalCache (org.apache.geode.internal.cache.InternalCache)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 Cache (org.apache.geode.cache.Cache)10 ResultCollector (org.apache.geode.cache.execute.ResultCollector)10 ConverterHint (org.apache.geode.management.cli.ConverterHint)10 HashSet (java.util.HashSet)7 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)7 UnitTest (org.apache.geode.test.junit.categories.UnitTest)7 Test (org.junit.Test)7 Set (java.util.Set)6