Search in sources :

Example 1 with CliFunctionResult

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

the class ConfigCommands method alterRuntimeConfig.

@CliCommand(value = { CliStrings.ALTER_RUNTIME_CONFIG }, help = CliStrings.ALTER_RUNTIME_CONFIG__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG }, interceptor = "org.apache.geode.management.internal.cli.commands.ConfigCommands$AlterRuntimeInterceptor")
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE)
public Result alterRuntimeConfig(@CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__MEMBER }, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.ALTER_RUNTIME_CONFIG__MEMBER__HELP) String[] memberNameOrId, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__GROUP }, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.ALTER_RUNTIME_CONFIG__MEMBER__HELP) String[] group, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT }, help = CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT__HELP) Integer archiveDiskSpaceLimit, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT }, help = CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT__HELP) Integer archiveFileSizeLimit, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT }, help = CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT__HELP) Integer logDiskSpaceLimit, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT }, help = CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT__HELP) Integer logFileSizeLimit, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL }, optionContext = ConverterHint.LOG_LEVEL, help = CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL__HELP) String logLevel, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE }, help = CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE__HELP) String statisticArchiveFile, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE }, help = CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE__HELP) Integer statisticSampleRate, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED }, help = CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED__HELP) Boolean statisticSamplingEnabled, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__COPY__ON__READ }, specifiedDefaultValue = "false", help = CliStrings.ALTER_RUNTIME_CONFIG__COPY__ON__READ__HELP) Boolean setCopyOnRead, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__LOCK__LEASE }, help = CliStrings.ALTER_RUNTIME_CONFIG__LOCK__LEASE__HELP) Integer lockLease, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__LOCK__TIMEOUT }, help = CliStrings.ALTER_RUNTIME_CONFIG__LOCK__TIMEOUT__HELP) Integer lockTimeout, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__MESSAGE__SYNC__INTERVAL }, help = CliStrings.ALTER_RUNTIME_CONFIG__MESSAGE__SYNC__INTERVAL__HELP) Integer messageSyncInterval, @CliOption(key = { CliStrings.ALTER_RUNTIME_CONFIG__SEARCH__TIMEOUT }, help = CliStrings.ALTER_RUNTIME_CONFIG__SEARCH__TIMEOUT__HELP) Integer searchTimeout) {
    Map<String, String> runTimeDistributionConfigAttributes = new HashMap<>();
    Map<String, String> rumTimeCacheAttributes = new HashMap<>();
    Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
    if (targetMembers.isEmpty()) {
        return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
    }
    if (archiveDiskSpaceLimit != null) {
        runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, archiveDiskSpaceLimit.toString());
    }
    if (archiveFileSizeLimit != null) {
        runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, archiveFileSizeLimit.toString());
    }
    if (logDiskSpaceLimit != null) {
        runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, logDiskSpaceLimit.toString());
    }
    if (logFileSizeLimit != null) {
        runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, logFileSizeLimit.toString());
    }
    if (logLevel != null && !logLevel.isEmpty()) {
        runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, logLevel);
    }
    if (statisticArchiveFile != null && !statisticArchiveFile.isEmpty()) {
        runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, statisticArchiveFile);
    }
    if (statisticSampleRate != null) {
        runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, statisticSampleRate.toString());
    }
    if (statisticSamplingEnabled != null) {
        runTimeDistributionConfigAttributes.put(STATISTIC_SAMPLING_ENABLED, statisticSamplingEnabled.toString());
    }
    // Attributes that are set on the cache.
    if (setCopyOnRead != null) {
        rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__COPY__ON__READ, setCopyOnRead.toString());
    }
    if (lockLease != null && lockLease > 0 && lockLease < Integer.MAX_VALUE) {
        rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__LOCK__LEASE, lockLease.toString());
    }
    if (lockTimeout != null && lockTimeout > 0 && lockTimeout < Integer.MAX_VALUE) {
        rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__LOCK__TIMEOUT, lockTimeout.toString());
    }
    if (messageSyncInterval != null && messageSyncInterval > 0 && messageSyncInterval < Integer.MAX_VALUE) {
        rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__MESSAGE__SYNC__INTERVAL, messageSyncInterval.toString());
    }
    if (searchTimeout != null && searchTimeout > 0 && searchTimeout < Integer.MAX_VALUE) {
        rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__SEARCH__TIMEOUT, searchTimeout.toString());
    }
    if (runTimeDistributionConfigAttributes.isEmpty() && rumTimeCacheAttributes.isEmpty()) {
        return ResultBuilder.createUserErrorResult(CliStrings.ALTER_RUNTIME_CONFIG__RELEVANT__OPTION__MESSAGE);
    }
    Map<String, String> allRunTimeAttributes = new HashMap<>();
    allRunTimeAttributes.putAll(runTimeDistributionConfigAttributes);
    allRunTimeAttributes.putAll(rumTimeCacheAttributes);
    ResultCollector<?, ?> rc = CliUtil.executeFunction(alterRunTimeConfigFunction, allRunTimeAttributes, targetMembers);
    List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
    Set<String> successfulMembers = new TreeSet<>();
    Set<String> errorMessages = new TreeSet<>();
    for (CliFunctionResult result : results) {
        if (result.getThrowable() != null) {
            logger.info("Function failed: " + result.getThrowable());
            errorMessages.add(result.getThrowable().getMessage());
        } else {
            successfulMembers.add(result.getMemberIdOrName());
        }
    }
    final String lineSeparator = System.getProperty("line.separator");
    if (!successfulMembers.isEmpty()) {
        StringBuilder successMessageBuilder = new StringBuilder();
        successMessageBuilder.append(CliStrings.ALTER_RUNTIME_CONFIG__SUCCESS__MESSAGE);
        successMessageBuilder.append(lineSeparator);
        for (String member : successfulMembers) {
            successMessageBuilder.append(member);
            successMessageBuilder.append(lineSeparator);
        }
        Properties properties = new Properties();
        properties.putAll(runTimeDistributionConfigAttributes);
        Result result = ResultBuilder.createInfoResult(successMessageBuilder.toString());
        // Set the Cache attributes to be modified
        final XmlEntity xmlEntity = XmlEntity.builder().withType(CacheXml.CACHE).withAttributes(rumTimeCacheAttributes).build();
        persistClusterConfiguration(result, () -> getSharedConfiguration().modifyXmlAndProperties(properties, xmlEntity, group));
        return result;
    } else {
        StringBuilder errorMessageBuilder = new StringBuilder();
        errorMessageBuilder.append("Following errors occurred while altering runtime config");
        errorMessageBuilder.append(lineSeparator);
        for (String errorMessage : errorMessages) {
            errorMessageBuilder.append(errorMessage);
            errorMessageBuilder.append(lineSeparator);
        }
        return ResultBuilder.createUserErrorResult(errorMessageBuilder.toString());
    }
}
Also used : HashMap(java.util.HashMap) Properties(java.util.Properties) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) 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) TreeSet(java.util.TreeSet) DistributedMember(org.apache.geode.distributed.DistributedMember) 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 CliFunctionResult

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

the class CreateAlterDestroyRegionCommands method destroyRegion.

@CliCommand(value = { CliStrings.DESTROY_REGION }, help = CliStrings.DESTROY_REGION__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result destroyRegion(@CliOption(key = CliStrings.DESTROY_REGION__REGION, optionContext = ConverterHint.REGION_PATH, mandatory = true, help = CliStrings.DESTROY_REGION__REGION__HELP) String regionPath) {
    if (regionPath == null) {
        return ResultBuilder.createInfoResult(CliStrings.DESTROY_REGION__MSG__SPECIFY_REGIONPATH_TO_DESTROY);
    }
    if (StringUtils.isBlank(regionPath) || regionPath.equals(Region.SEPARATOR)) {
        return ResultBuilder.createInfoResult(CliStrings.format(CliStrings.DESTROY_REGION__MSG__REGIONPATH_0_NOT_VALID, new Object[] { regionPath }));
    }
    Result result;
    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
    try {
        InternalCache cache = getCache();
        ManagementService managementService = ManagementService.getExistingManagementService(cache);
        String regionPathToUse = regionPath;
        if (!regionPathToUse.startsWith(Region.SEPARATOR)) {
            regionPathToUse = Region.SEPARATOR + regionPathToUse;
        }
        Set<DistributedMember> regionMembersList = findMembersForRegion(cache, managementService, regionPathToUse);
        if (regionMembersList.size() == 0) {
            return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.DESTROY_REGION__MSG__COULDNOT_FIND_REGIONPATH_0_IN_GEODE, new Object[] { regionPath, "jmx-manager-update-rate milliseconds" }));
        }
        CliFunctionResult destroyRegionResult;
        ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(RegionDestroyFunction.INSTANCE, regionPath, regionMembersList);
        List<CliFunctionResult> resultsList = (List<CliFunctionResult>) resultCollector.getResult();
        String message = CliStrings.format(CliStrings.DESTROY_REGION__MSG__REGION_0_1_DESTROYED, new Object[] { regionPath, "" });
        // Only if there is an error is this set to false
        boolean isRegionDestroyed = true;
        for (CliFunctionResult aResultsList : resultsList) {
            destroyRegionResult = aResultsList;
            if (destroyRegionResult.isSuccessful()) {
                xmlEntity.set(destroyRegionResult.getXmlEntity());
            } else if (destroyRegionResult.getThrowable() != null) {
                Throwable t = destroyRegionResult.getThrowable();
                LogWrapper.getInstance().info(t.getMessage(), t);
                message = CliStrings.format(CliStrings.DESTROY_REGION__MSG__ERROR_OCCURRED_WHILE_DESTROYING_0_REASON_1, new Object[] { regionPath, t.getMessage() });
                isRegionDestroyed = false;
            } else {
                message = CliStrings.format(CliStrings.DESTROY_REGION__MSG__UNKNOWN_RESULT_WHILE_DESTROYING_REGION_0_REASON_1, new Object[] { regionPath, destroyRegionResult.getMessage() });
                isRegionDestroyed = false;
            }
        }
        if (isRegionDestroyed) {
            result = ResultBuilder.createInfoResult(message);
        } else {
            result = ResultBuilder.createUserErrorResult(message);
        }
    } catch (IllegalStateException e) {
        result = ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.DESTROY_REGION__MSG__ERROR_WHILE_DESTROYING_REGION_0_REASON_1, new Object[] { regionPath, e.getMessage() }));
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESTROY_REGION__MSG__ERROR_WHILE_DESTROYING_REGION_0_REASON_1, new Object[] { regionPath, e.getMessage() }));
    }
    if (xmlEntity.get() != null) {
        persistClusterConfiguration(result, () -> getSharedConfiguration().deleteXmlEntity(xmlEntity.get(), null));
    }
    return result;
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) AtomicReference(java.util.concurrent.atomic.AtomicReference) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) MalformedObjectNameException(javax.management.MalformedObjectNameException) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) FetchRegionAttributesFunctionResult(org.apache.geode.management.internal.cli.functions.FetchRegionAttributesFunction.FetchRegionAttributesFunctionResult) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) ManagementService(org.apache.geode.management.ManagementService) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) List(java.util.List) ArrayList(java.util.ArrayList) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 3 with CliFunctionResult

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

the class ConfigCommands method exportConfig.

/**
   * Export the cache configuration in XML format.
   *
   * @param member Member for which to write the configuration
   * @param group Group or groups for which to write the configuration
   * @return Results of the attempt to write the configuration
   */
@CliCommand(value = { CliStrings.EXPORT_CONFIG }, help = CliStrings.EXPORT_CONFIG__HELP)
@CliMetaData(interceptor = "org.apache.geode.management.internal.cli.commands.ConfigCommands$Interceptor", relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result exportConfig(@CliOption(key = { CliStrings.EXPORT_CONFIG__MEMBER }, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.EXPORT_CONFIG__MEMBER__HELP) String[] member, @CliOption(key = { CliStrings.EXPORT_CONFIG__GROUP }, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.EXPORT_CONFIG__GROUP__HELP) String[] group, @CliOption(key = { CliStrings.EXPORT_CONFIG__DIR }, help = CliStrings.EXPORT_CONFIG__DIR__HELP) String dir) {
    InfoResultData infoData = ResultBuilder.createInfoResultData();
    Set<DistributedMember> targetMembers = CliUtil.findMembers(group, member);
    if (targetMembers.isEmpty()) {
        return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
    }
    try {
        ResultCollector<?, ?> rc = CliUtil.executeFunction(this.exportConfigFunction, null, targetMembers);
        List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
        for (CliFunctionResult result : results) {
            if (result.getThrowable() != null) {
                infoData.addLine(CliStrings.format(CliStrings.EXPORT_CONFIG__MSG__EXCEPTION, result.getMemberIdOrName(), result.getThrowable()));
            } else if (result.isSuccessful()) {
                String cacheFileName = result.getMemberIdOrName() + "-cache.xml";
                String propsFileName = result.getMemberIdOrName() + "-gf.properties";
                String[] fileContent = (String[]) result.getSerializables();
                infoData.addAsFile(cacheFileName, fileContent[0], "Downloading Cache XML file: {0}", false);
                infoData.addAsFile(propsFileName, fileContent[1], "Downloading properties file: {0}", false);
            }
        }
        return ResultBuilder.buildResult(infoData);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        th.printStackTrace(System.err);
        return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXPORT_CONFIG__MSG__EXCEPTION, th.getClass().getName() + ": " + th.getMessage()));
    }
}
Also used : CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) DistributedMember(org.apache.geode.distributed.DistributedMember) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 4 with CliFunctionResult

use of org.apache.geode.management.internal.cli.functions.CliFunctionResult 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 5 with CliFunctionResult

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

the class WanCommands method createGatewayReceiver.

@CliCommand(value = CliStrings.CREATE_GATEWAYRECEIVER, help = CliStrings.CREATE_GATEWAYRECEIVER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result createGatewayReceiver(@CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.CREATE_GATEWAYRECEIVER__GROUP__HELP) String[] onGroups, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CREATE_GATEWAYRECEIVER__MEMBER__HELP) String[] onMember, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__MANUALSTART, help = CliStrings.CREATE_GATEWAYRECEIVER__MANUALSTART__HELP) Boolean manualStart, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__STARTPORT, help = CliStrings.CREATE_GATEWAYRECEIVER__STARTPORT__HELP) Integer startPort, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__ENDPORT, help = CliStrings.CREATE_GATEWAYRECEIVER__ENDPORT__HELP) Integer endPort, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__BINDADDRESS, help = CliStrings.CREATE_GATEWAYRECEIVER__BINDADDRESS__HELP) String bindAddress, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__MAXTIMEBETWEENPINGS, help = CliStrings.CREATE_GATEWAYRECEIVER__MAXTIMEBETWEENPINGS__HELP) Integer maximumTimeBetweenPings, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__SOCKETBUFFERSIZE, help = CliStrings.CREATE_GATEWAYRECEIVER__SOCKETBUFFERSIZE__HELP) Integer socketBufferSize, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__GATEWAYTRANSPORTFILTER, help = CliStrings.CREATE_GATEWAYRECEIVER__GATEWAYTRANSPORTFILTER__HELP) String[] gatewayTransportFilters) {
    Result result = null;
    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
    try {
        GatewayReceiverFunctionArgs gatewayReceiverFunctionArgs = new GatewayReceiverFunctionArgs(manualStart, startPort, endPort, bindAddress, socketBufferSize, maximumTimeBetweenPings, gatewayTransportFilters);
        Set<DistributedMember> membersToCreateGatewayReceiverOn = CliUtil.findMembers(onGroups, onMember);
        if (membersToCreateGatewayReceiverOn.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(GatewayReceiverCreateFunction.INSTANCE, gatewayReceiverFunctionArgs, membersToCreateGatewayReceiverOn);
        @SuppressWarnings("unchecked") List<CliFunctionResult> gatewayReceiverCreateResults = (List<CliFunctionResult>) resultCollector.getResult();
        TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
        final String errorPrefix = "ERROR: ";
        for (CliFunctionResult gatewayReceiverCreateResult : gatewayReceiverCreateResults) {
            boolean success = gatewayReceiverCreateResult.isSuccessful();
            tabularResultData.accumulate("Member", gatewayReceiverCreateResult.getMemberIdOrName());
            tabularResultData.accumulate("Status", (success ? "" : errorPrefix) + gatewayReceiverCreateResult.getMessage());
            if (success && xmlEntity.get() == null) {
                xmlEntity.set(gatewayReceiverCreateResult.getXmlEntity());
            }
        }
        result = ResultBuilder.buildResult(tabularResultData);
    } catch (IllegalArgumentException e) {
        LogWrapper.getInstance().info(e.getMessage());
        result = ResultBuilder.createUserErrorResult(e.getMessage());
    }
    if (xmlEntity.get() != null) {
        persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), onGroups));
    }
    return result;
}
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) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) DistributedMember(org.apache.geode.distributed.DistributedMember) ArrayList(java.util.ArrayList) List(java.util.List) GatewayReceiverFunctionArgs(org.apache.geode.management.internal.cli.functions.GatewayReceiverFunctionArgs) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

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