Search in sources :

Example 1 with RegionAlterFunction

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

the class CreateAlterDestroyRegionCommands method alterRegion.

@CliCommand(value = CliStrings.ALTER_REGION, help = CliStrings.ALTER_REGION__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION)
public Result alterRegion(@CliOption(key = CliStrings.ALTER_REGION__REGION, mandatory = true, help = CliStrings.ALTER_REGION__REGION__HELP) String regionPath, @CliOption(key = CliStrings.ALTER_REGION__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.ALTER_REGION__GROUP__HELP) String[] groups, @CliOption(key = CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIME, specifiedDefaultValue = "-1", help = CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIME__HELP) Integer entryExpirationIdleTime, @CliOption(key = CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIMEACTION, specifiedDefaultValue = "INVALIDATE", help = CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIMEACTION__HELP) String entryExpirationIdleTimeAction, @CliOption(key = CliStrings.ALTER_REGION__ENTRYEXPIRATIONTIMETOLIVE, specifiedDefaultValue = "-1", help = CliStrings.ALTER_REGION__ENTRYEXPIRATIONTIMETOLIVE__HELP) Integer entryExpirationTTL, @CliOption(key = CliStrings.ALTER_REGION__ENTRYEXPIRATIONTTLACTION, specifiedDefaultValue = "INVALIDATE", help = CliStrings.ALTER_REGION__ENTRYEXPIRATIONTTLACTION__HELP) String entryExpirationTTLAction, @CliOption(key = CliStrings.ALTER_REGION__REGIONEXPIRATIONIDLETIME, specifiedDefaultValue = "-1", help = CliStrings.ALTER_REGION__REGIONEXPIRATIONIDLETIME__HELP) Integer regionExpirationIdleTime, @CliOption(key = CliStrings.ALTER_REGION__REGIONEXPIRATIONIDLETIMEACTION, specifiedDefaultValue = "INVALIDATE", help = CliStrings.ALTER_REGION__REGIONEXPIRATIONIDLETIMEACTION__HELP) String regionExpirationIdleTimeAction, @CliOption(key = CliStrings.ALTER_REGION__REGIONEXPIRATIONTTL, specifiedDefaultValue = "-1", help = CliStrings.ALTER_REGION__REGIONEXPIRATIONTTL__HELP) Integer regionExpirationTTL, @CliOption(key = CliStrings.ALTER_REGION__REGIONEXPIRATIONTTLACTION, specifiedDefaultValue = "INVALIDATE", help = CliStrings.ALTER_REGION__REGIONEXPIRATIONTTLACTION__HELP) String regionExpirationTTLAction, @CliOption(key = CliStrings.ALTER_REGION__CACHELISTENER, specifiedDefaultValue = "", help = CliStrings.ALTER_REGION__CACHELISTENER__HELP) String[] cacheListeners, @CliOption(key = CliStrings.ALTER_REGION__CACHELOADER, specifiedDefaultValue = "null", help = CliStrings.ALTER_REGION__CACHELOADER__HELP) String cacheLoader, @CliOption(key = CliStrings.ALTER_REGION__CACHEWRITER, specifiedDefaultValue = "null", help = CliStrings.ALTER_REGION__CACHEWRITER__HELP) String cacheWriter, @CliOption(key = CliStrings.ALTER_REGION__ASYNCEVENTQUEUEID, specifiedDefaultValue = "", help = CliStrings.ALTER_REGION__ASYNCEVENTQUEUEID__HELP) String[] asyncEventQueueIds, @CliOption(key = CliStrings.ALTER_REGION__GATEWAYSENDERID, specifiedDefaultValue = "", help = CliStrings.ALTER_REGION__GATEWAYSENDERID__HELP) String[] gatewaySenderIds, @CliOption(key = CliStrings.ALTER_REGION__CLONINGENABLED, specifiedDefaultValue = "false", help = CliStrings.ALTER_REGION__CLONINGENABLED__HELP) Boolean cloningEnabled, @CliOption(key = CliStrings.ALTER_REGION__EVICTIONMAX, specifiedDefaultValue = "0", help = CliStrings.ALTER_REGION__EVICTIONMAX__HELP) Integer evictionMax) {
    Result result;
    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
    this.securityService.authorizeRegionManage(regionPath);
    try {
        InternalCache cache = getCache();
        if (groups != null) {
            validateGroups(cache, groups);
        }
        RegionFunctionArgs.ExpirationAttrs entryIdle = null;
        if (entryExpirationIdleTime != null || entryExpirationIdleTimeAction != null) {
            if (entryExpirationIdleTime != null && entryExpirationIdleTime == -1) {
                entryExpirationIdleTime = ExpirationAttributes.DEFAULT.getTimeout();
            }
            if (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(entryExpirationIdleTimeAction)) {
                entryExpirationIdleTimeAction = ExpirationAttributes.DEFAULT.getAction().toString();
            }
            entryIdle = new RegionFunctionArgs.ExpirationAttrs(RegionFunctionArgs.ExpirationAttrs.ExpirationFor.ENTRY_IDLE, entryExpirationIdleTime, entryExpirationIdleTimeAction);
        }
        RegionFunctionArgs.ExpirationAttrs entryTTL = null;
        if (entryExpirationTTL != null || entryExpirationTTLAction != null) {
            if (entryExpirationTTL != null && entryExpirationTTL == -1) {
                entryExpirationTTL = ExpirationAttributes.DEFAULT.getTimeout();
            }
            if (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(entryExpirationTTLAction)) {
                entryExpirationTTLAction = ExpirationAttributes.DEFAULT.getAction().toString();
            }
            entryTTL = new RegionFunctionArgs.ExpirationAttrs(RegionFunctionArgs.ExpirationAttrs.ExpirationFor.ENTRY_TTL, entryExpirationTTL, entryExpirationTTLAction);
        }
        RegionFunctionArgs.ExpirationAttrs regionIdle = null;
        if (regionExpirationIdleTime != null || regionExpirationIdleTimeAction != null) {
            if (regionExpirationIdleTime != null && regionExpirationIdleTime == -1) {
                regionExpirationIdleTime = ExpirationAttributes.DEFAULT.getTimeout();
            }
            if (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(regionExpirationIdleTimeAction)) {
                regionExpirationIdleTimeAction = ExpirationAttributes.DEFAULT.getAction().toString();
            }
            regionIdle = new RegionFunctionArgs.ExpirationAttrs(RegionFunctionArgs.ExpirationAttrs.ExpirationFor.REGION_IDLE, regionExpirationIdleTime, regionExpirationIdleTimeAction);
        }
        RegionFunctionArgs.ExpirationAttrs regionTTL = null;
        if (regionExpirationTTL != null || regionExpirationTTLAction != null) {
            if (regionExpirationTTL != null && regionExpirationTTL == -1) {
                regionExpirationTTL = ExpirationAttributes.DEFAULT.getTimeout();
            }
            if (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(regionExpirationTTLAction)) {
                regionExpirationTTLAction = ExpirationAttributes.DEFAULT.getAction().toString();
            }
            regionTTL = new RegionFunctionArgs.ExpirationAttrs(RegionFunctionArgs.ExpirationAttrs.ExpirationFor.REGION_TTL, regionExpirationTTL, regionExpirationTTLAction);
        }
        cacheLoader = convertDefaultValue(cacheLoader, StringUtils.EMPTY);
        cacheWriter = convertDefaultValue(cacheWriter, StringUtils.EMPTY);
        RegionFunctionArgs regionFunctionArgs;
        regionFunctionArgs = new RegionFunctionArgs(regionPath, null, null, false, null, null, null, entryIdle, entryTTL, regionIdle, regionTTL, null, null, null, null, cacheListeners, cacheLoader, cacheWriter, asyncEventQueueIds, gatewaySenderIds, null, cloningEnabled, null, null, null, null, null, null, null, null, evictionMax, null, null, null, null);
        Set<String> cacheListenersSet = regionFunctionArgs.getCacheListeners();
        if (cacheListenersSet != null && !cacheListenersSet.isEmpty()) {
            for (String cacheListener : cacheListenersSet) {
                if (!isClassNameValid(cacheListener)) {
                    throw new IllegalArgumentException(CliStrings.format(CliStrings.ALTER_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELISTENER_0_IS_INVALID, new Object[] { cacheListener }));
                }
            }
        }
        if (cacheLoader != null && !isClassNameValid(cacheLoader)) {
            throw new IllegalArgumentException(CliStrings.format(CliStrings.ALTER_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELOADER_0_IS_INVALID, new Object[] { cacheLoader }));
        }
        if (cacheWriter != null && !isClassNameValid(cacheWriter)) {
            throw new IllegalArgumentException(CliStrings.format(CliStrings.ALTER_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHEWRITER_0_IS_INVALID, new Object[] { cacheWriter }));
        }
        if (evictionMax != null && evictionMax < 0) {
            throw new IllegalArgumentException(CliStrings.format(CliStrings.ALTER_REGION__MSG__SPECIFY_POSITIVE_INT_FOR_EVICTIONMAX_0_IS_NOT_VALID, new Object[] { evictionMax }));
        }
        Set<DistributedMember> targetMembers = CliUtil.findMembers(groups, null);
        if (targetMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(new RegionAlterFunction(), regionFunctionArgs, targetMembers);
        List<CliFunctionResult> regionAlterResults = (List<CliFunctionResult>) resultCollector.getResult();
        TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
        final String errorPrefix = "ERROR: ";
        for (CliFunctionResult regionAlterResult : regionAlterResults) {
            boolean success = regionAlterResult.isSuccessful();
            tabularResultData.accumulate("Member", regionAlterResult.getMemberIdOrName());
            if (success) {
                tabularResultData.accumulate("Status", regionAlterResult.getMessage());
                xmlEntity.set(regionAlterResult.getXmlEntity());
            } else {
                tabularResultData.accumulate("Status", errorPrefix + regionAlterResult.getMessage());
                tabularResultData.setStatus(Status.ERROR);
            }
        }
        result = ResultBuilder.buildResult(tabularResultData);
    } catch (IllegalArgumentException | IllegalStateException e) {
        LogWrapper.getInstance().info(e.getMessage());
        result = ResultBuilder.createUserErrorResult(e.getMessage());
    } catch (RuntimeException e) {
        LogWrapper.getInstance().info(e.getMessage(), e);
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    if (xmlEntity.get() != null) {
        persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), groups));
    }
    return result;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) AtomicReference(java.util.concurrent.atomic.AtomicReference) RegionAlterFunction(org.apache.geode.management.internal.cli.functions.RegionAlterFunction) 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) RegionFunctionArgs(org.apache.geode.management.internal.cli.functions.RegionFunctionArgs) 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)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 InternalCache (org.apache.geode.internal.cache.InternalCache)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 FetchRegionAttributesFunctionResult (org.apache.geode.management.internal.cli.functions.FetchRegionAttributesFunction.FetchRegionAttributesFunctionResult)1 RegionAlterFunction (org.apache.geode.management.internal.cli.functions.RegionAlterFunction)1 RegionFunctionArgs (org.apache.geode.management.internal.cli.functions.RegionFunctionArgs)1 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)1 XmlEntity (org.apache.geode.management.internal.configuration.domain.XmlEntity)1 CliCommand (org.springframework.shell.core.annotation.CliCommand)1