in geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java [790:946]
public ResultModel preExecution(GfshParseResult parseResult) {
Integer localMaxMemory =
(Integer) parseResult.getParamValue(CliStrings.CREATE_REGION__LOCALMAXMEMORY);
if (localMaxMemory != null) {
if (localMaxMemory < 0) {
return ResultModel.createError(
"PartitionAttributes localMaxMemory must not be negative.");
}
}
Long totalMaxMemory =
(Long) parseResult.getParamValue(CliStrings.CREATE_REGION__TOTALMAXMEMORY);
if (totalMaxMemory != null) {
if (totalMaxMemory <= 0) {
return ResultModel.createError(
"Total size of partition region must be > 0.");
}
}
Integer redundantCopies =
(Integer) parseResult.getParamValue(CliStrings.CREATE_REGION__REDUNDANTCOPIES);
if (redundantCopies != null) {
if (redundantCopies < 0 || redundantCopies > 3) {
return ResultModel.createError(CliStrings.format(
CliStrings.CREATE_REGION__MSG__REDUNDANT_COPIES_SHOULD_BE_ONE_OF_0123,
new Object[] {redundantCopies}));
}
}
Integer concurrencyLevel =
(Integer) parseResult.getParamValue(CliStrings.CREATE_REGION__CONCURRENCYLEVEL);
if (concurrencyLevel != null) {
if (concurrencyLevel < 0) {
return ResultModel.createError(CliStrings.format(
CliStrings.CREATE_REGION__MSG__SPECIFY_POSITIVE_INT_FOR_CONCURRENCYLEVEL_0_IS_NOT_VALID,
new Object[] {concurrencyLevel}));
}
}
String keyConstraint =
parseResult.getParamValueAsString(CliStrings.CREATE_REGION__KEYCONSTRAINT);
if (keyConstraint != null && !isClassNameValid(keyConstraint)) {
return ResultModel.createError(CliStrings.format(
CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_KEYCONSTRAINT_0_IS_INVALID,
new Object[] {keyConstraint}));
}
String valueConstraint =
parseResult.getParamValueAsString(CliStrings.CREATE_REGION__VALUECONSTRAINT);
if (valueConstraint != null && !isClassNameValid(valueConstraint)) {
return ResultModel.createError(CliStrings.format(
CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_VALUECONSTRAINT_0_IS_INVALID,
new Object[] {valueConstraint}));
}
String compressor = parseResult.getParamValueAsString(CliStrings.CREATE_REGION__COMPRESSOR);
if (compressor != null && !isClassNameValid(compressor)) {
return ResultModel.createError(CliStrings
.format(CliStrings.CREATE_REGION__MSG__INVALID_COMPRESSOR, new Object[] {compressor}));
}
Boolean cloningEnabled =
(Boolean) parseResult.getParamValue(CliStrings.CREATE_REGION__CLONINGENABLED);
if (compressor != null && cloningEnabled != null && !cloningEnabled) {
return ResultModel.createError(CliStrings
.format(CliStrings.CREATE_REGION__MSG__CANNOT_DISABLE_CLONING_WITH_COMPRESSOR,
new Object[] {compressor}));
}
String diskStore = parseResult.getParamValueAsString(CliStrings.CREATE_REGION__DISKSTORE);
if (diskStore != null) {
String regionShortcut =
parseResult.getParamValueAsString(CliStrings.CREATE_REGION__REGIONSHORTCUT);
if (regionShortcut != null && !RegionCommandsUtils.PERSISTENT_OVERFLOW_SHORTCUTS
.contains(RegionShortcut.valueOf(regionShortcut))) {
String subMessage =
"Only regions with persistence or overflow to disk can specify DiskStore";
String message = subMessage + ". "
+ CliStrings.format(CliStrings.CREATE_REGION__MSG__USE_ONE_OF_THESE_SHORTCUTS_0,
new Object[] {String.valueOf(RegionCommandsUtils.PERSISTENT_OVERFLOW_SHORTCUTS)});
return ResultModel.createError(message);
}
}
// if any expiration value is set, statistics must be enabled
Boolean statisticsEnabled =
(Boolean) parseResult.getParamValue(CliStrings.CREATE_REGION__STATISTICSENABLED);
Integer entryIdle =
(Integer) parseResult.getParamValue(CliStrings.CREATE_REGION__ENTRYEXPIRATIONIDLETIME);
Integer entryTtl =
(Integer) parseResult.getParamValue(CliStrings.CREATE_REGION__ENTRYEXPIRATIONTIMETOLIVE);
Integer regionIdle =
(Integer) parseResult.getParamValue(CliStrings.CREATE_REGION__REGIONEXPIRATIONIDLETIME);
Integer regionTtl =
(Integer) parseResult.getParamValue(CliStrings.CREATE_REGION__REGIONEXPIRATIONTTL);
ExpirationAction entryIdleAction = (ExpirationAction) parseResult
.getParamValue(CliStrings.CREATE_REGION__ENTRYEXPIRATIONIDLETIMEACTION);
ExpirationAction entryTtlAction = (ExpirationAction) parseResult
.getParamValue(CliStrings.CREATE_REGION__ENTRYEXPIRATIONTTLACTION);
ExpirationAction regionIdleAction = (ExpirationAction) parseResult
.getParamValue(CliStrings.CREATE_REGION__REGIONEXPIRATIONIDLETIMEACTION);
ExpirationAction regionTtlAction = (ExpirationAction) parseResult
.getParamValue(CliStrings.CREATE_REGION__REGIONEXPIRATIONTTLACTION);
ClassName entryIdleExpiry =
(ClassName) parseResult.getParamValue(CliStrings.ENTRY_IDLE_TIME_CUSTOM_EXPIRY);
ClassName entryTTTLExpiry =
(ClassName) parseResult.getParamValue(CliStrings.ENTRY_TTL_CUSTOM_EXPIRY);
if ((entryIdle != null || entryTtl != null || regionIdle != null || regionTtl != null
|| entryIdleAction != null || entryTtlAction != null || regionIdleAction != null
|| regionTtlAction != null || entryIdleExpiry != null || entryTTTLExpiry != null)
&& (statisticsEnabled == null || !statisticsEnabled)) {
String message =
"Statistics must be enabled for expiration";
return ResultModel.createError(message + ".");
}
String maxMemory =
parseResult.getParamValueAsString(CliStrings.CREATE_REGION__EVICTION_MAX_MEMORY);
String maxEntry =
parseResult.getParamValueAsString(CliStrings.CREATE_REGION__EVICTION_ENTRY_COUNT);
String evictionAction =
parseResult.getParamValueAsString(CliStrings.CREATE_REGION__EVICTION_ACTION);
String evictionSizer =
parseResult.getParamValueAsString(CliStrings.CREATE_REGION__EVICTION_OBJECT_SIZER);
if (maxEntry != null && maxMemory != null) {
return ResultModel.createError(CliStrings.CREATE_REGION__MSG__BOTH_EVICTION_VALUES);
}
if ((maxEntry != null || maxMemory != null) && evictionAction == null) {
return ResultModel.createError(CliStrings.CREATE_REGION__MSG__MISSING_EVICTION_ACTION);
}
if (evictionSizer != null && maxEntry != null) {
return ResultModel.createError(
CliStrings.CREATE_REGION__MSG__INVALID_EVICTION_OBJECT_SIZER_AND_ENTRY_COUNT);
}
if (evictionAction != null
&& EvictionAction.parseAction(evictionAction) == EvictionAction.NONE) {
return ResultModel.createError(CliStrings.CREATE_REGION__MSG__INVALID_EVICTION_ACTION);
}
RegionAttributesScope scope =
(RegionAttributesScope) parseResult.getParamValue(CliStrings.CREATE_REGION__SCOPE);
RegionShortcut regionShortcut =
(RegionShortcut) parseResult.getParamValue(CliStrings.CREATE_REGION__REGIONSHORTCUT);
if (scope != null && regionShortcut == null) {
return ResultModel
.createError(CliStrings.CREATE_REGION__SCOPE__SCOPE_CANNOT_BE_SET_IF_TYPE_NOT_SET);
} else if (scope != null && !regionShortcut.isReplicate()) {
return ResultModel
.createError(
CliStrings.CREATE_REGION__MSG__SCOPE_CANNOT_BE_SET_ON_NON_REPLICATED_REGION);
}
return ResultModel.createInfo("");
}