use of org.apache.geode.management.internal.cli.util.RegionPath in project geode by apache.
the class CreateAlterDestroyRegionCommands method validateRegionPathAndParent.
private void validateRegionPathAndParent(InternalCache cache, String regionPath) {
if (StringUtils.isEmpty(regionPath)) {
throw new IllegalArgumentException(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_REGION_PATH);
}
// If a region path indicates a sub-region, check whether the parent region exists
RegionPath regionPathData = new RegionPath(regionPath);
String parentRegionPath = regionPathData.getParent();
if (parentRegionPath != null && !Region.SEPARATOR.equals(parentRegionPath)) {
if (!regionExists(cache, parentRegionPath)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__PARENT_REGION_FOR_0_DOESNOT_EXIST, new Object[] { regionPath }));
}
}
}
use of org.apache.geode.management.internal.cli.util.RegionPath in project geode by apache.
the class RegionAlterFunction method alterRegion.
private <K, V> Region<?, ?> alterRegion(Cache cache, RegionFunctionArgs regionAlterArgs) {
final String regionPathString = regionAlterArgs.getRegionPath();
RegionPath regionPath = new RegionPath(regionPathString);
AbstractRegion region = (AbstractRegion) cache.getRegion(regionPathString);
if (region == null) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.ALTER_REGION__MSG__REGION_DOESNT_EXIST_0, new Object[] { regionPath }));
}
AttributesMutator mutator = region.getAttributesMutator();
if (regionAlterArgs.isCloningEnabled() != null) {
mutator.setCloningEnabled(regionAlterArgs.isCloningEnabled());
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - cloning");
}
}
if (regionAlterArgs.getEvictionMax() != null) {
mutator.getEvictionAttributesMutator().setMaximum(regionAlterArgs.getEvictionMax());
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - eviction attributes max");
}
}
// Alter expiration attributes
final RegionFunctionArgs.ExpirationAttrs newEntryExpirationIdleTime = regionAlterArgs.getEntryExpirationIdleTime();
if (newEntryExpirationIdleTime != null) {
mutator.setEntryIdleTimeout(parseExpirationAttributes(newEntryExpirationIdleTime, region.getEntryIdleTimeout()));
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - entry idle timeout");
}
}
final RegionFunctionArgs.ExpirationAttrs newEntryExpirationTTL = regionAlterArgs.getEntryExpirationTTL();
if (newEntryExpirationTTL != null) {
mutator.setEntryTimeToLive(parseExpirationAttributes(newEntryExpirationTTL, region.getEntryTimeToLive()));
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - entry TTL");
}
}
final RegionFunctionArgs.ExpirationAttrs newRegionExpirationIdleTime = regionAlterArgs.getRegionExpirationIdleTime();
if (newRegionExpirationIdleTime != null) {
mutator.setRegionIdleTimeout(parseExpirationAttributes(newRegionExpirationIdleTime, region.getRegionIdleTimeout()));
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - region idle timeout");
}
}
final RegionFunctionArgs.ExpirationAttrs newRegionExpirationTTL = regionAlterArgs.getRegionExpirationTTL();
if (newRegionExpirationTTL != null) {
mutator.setRegionTimeToLive(parseExpirationAttributes(newRegionExpirationTTL, region.getRegionTimeToLive()));
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - region TTL");
}
}
// Alter Gateway Sender Ids
final Set<String> newGatewaySenderIds = regionAlterArgs.getGatewaySenderIds();
if (newGatewaySenderIds != null) {
// Remove old gateway sender ids that aren't in the new list
Set<String> oldGatewaySenderIds = region.getGatewaySenderIds();
if (!oldGatewaySenderIds.isEmpty()) {
for (String gatewaySenderId : oldGatewaySenderIds) {
if (!newGatewaySenderIds.contains(gatewaySenderId)) {
mutator.removeGatewaySenderId(gatewaySenderId);
}
}
}
// Add new gateway sender ids that don't already exist
for (String gatewaySenderId : newGatewaySenderIds) {
if (!oldGatewaySenderIds.contains(gatewaySenderId)) {
mutator.addGatewaySenderId(gatewaySenderId);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - gateway sender IDs");
}
}
// Alter Async Queue Ids
final Set<String> newAsyncEventQueueIds = regionAlterArgs.getAsyncEventQueueIds();
if (newAsyncEventQueueIds != null) {
// Remove old async event queue ids that aren't in the new list
Set<String> oldAsyncEventQueueIds = region.getAsyncEventQueueIds();
if (!oldAsyncEventQueueIds.isEmpty()) {
for (String asyncEventQueueId : oldAsyncEventQueueIds) {
if (!newAsyncEventQueueIds.contains(asyncEventQueueId)) {
mutator.removeAsyncEventQueueId(asyncEventQueueId);
}
}
}
// Add new async event queue ids that don't already exist
for (String asyncEventQueueId : newAsyncEventQueueIds) {
if (!oldAsyncEventQueueIds.contains(asyncEventQueueId)) {
mutator.addAsyncEventQueueId(asyncEventQueueId);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - async event queue IDs");
}
}
// Alter Cache Listeners
final Set<String> newCacheListenerNames = regionAlterArgs.getCacheListeners();
if (newCacheListenerNames != null) {
// Remove old cache listeners that aren't in the new list
CacheListener[] oldCacheListeners = region.getCacheListeners();
for (CacheListener oldCacheListener : oldCacheListeners) {
if (!newCacheListenerNames.contains(oldCacheListener.getClass().getName())) {
mutator.removeCacheListener(oldCacheListener);
}
}
// Add new cache listeners that don't already exist
for (String newCacheListenerName : newCacheListenerNames) {
if (newCacheListenerName.isEmpty()) {
continue;
}
boolean nameFound = false;
for (CacheListener oldCacheListener : oldCacheListeners) {
if (oldCacheListener.getClass().getName().equals(newCacheListenerName)) {
nameFound = true;
break;
}
}
if (!nameFound) {
Class<CacheListener<K, V>> cacheListenerKlass = forName(newCacheListenerName, CliStrings.ALTER_REGION__CACHELISTENER);
mutator.addCacheListener(newInstance(cacheListenerKlass, CliStrings.ALTER_REGION__CACHELISTENER));
}
}
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - cache listeners");
}
}
final String cacheLoader = regionAlterArgs.getCacheLoader();
if (cacheLoader != null) {
if (cacheLoader.isEmpty()) {
mutator.setCacheLoader(null);
} else {
Class<CacheLoader<K, V>> cacheLoaderKlass = forName(cacheLoader, CliStrings.ALTER_REGION__CACHELOADER);
mutator.setCacheLoader(newInstance(cacheLoaderKlass, CliStrings.ALTER_REGION__CACHELOADER));
}
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - cache loader");
}
}
final String cacheWriter = regionAlterArgs.getCacheWriter();
if (cacheWriter != null) {
if (cacheWriter.isEmpty()) {
mutator.setCacheWriter(null);
} else {
Class<CacheWriter<K, V>> cacheWriterKlass = forName(cacheWriter, CliStrings.ALTER_REGION__CACHEWRITER);
mutator.setCacheWriter(newInstance(cacheWriterKlass, CliStrings.ALTER_REGION__CACHEWRITER));
}
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - cache writer");
}
}
return region;
}
use of org.apache.geode.management.internal.cli.util.RegionPath in project geode by apache.
the class RegionCreateFunction method createRegion.
public static <K, V> Region<?, ?> createRegion(Cache cache, RegionFunctionArgs regionCreateArgs) {
Region<K, V> createdRegion = null;
final String regionPath = regionCreateArgs.getRegionPath();
final RegionShortcut regionShortcut = regionCreateArgs.getRegionShortcut();
final String useAttributesFrom = regionCreateArgs.getUseAttributesFrom();
// If a region path indicates a sub-region, check whether the parent region exists
RegionPath regionPathData = new RegionPath(regionPath);
String parentRegionPath = regionPathData.getParent();
Region<?, ?> parentRegion = null;
if (parentRegionPath != null && !Region.SEPARATOR.equals(parentRegionPath)) {
parentRegion = cache.getRegion(parentRegionPath);
if (parentRegion == null) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__PARENT_REGION_FOR_0_DOESNOT_EXIST, new Object[] { regionPath }));
}
if (parentRegion.getAttributes().getPartitionAttributes() != null) {
// For a PR, sub-regions are not supported.
throw new CreateSubregionException(CliStrings.format(CliStrings.CREATE_REGION__MSG__0_IS_A_PR_CANNOT_HAVE_SUBREGIONS, parentRegion.getFullPath()));
}
}
// One of Region Shortcut OR Use Attributes From has to be given
if (regionShortcut == null && useAttributesFrom == null) {
throw new IllegalArgumentException(CliStrings.CREATE_REGION__MSG__ONE_OF_REGIONSHORTCUT_AND_USEATTRIBUESFROM_IS_REQUIRED);
}
boolean isPartitioned = false;
RegionFactory<K, V> factory = null;
RegionAttributes<K, V> regionAttributes = null;
if (regionShortcut != null) {
regionAttributes = cache.getRegionAttributes(regionShortcut.toString());
if (logger.isDebugEnabled()) {
logger.debug("Using shortcut {} for {} region attributes : {}", regionShortcut, regionPath, regionAttributes);
}
if (regionAttributes == null) {
if (logger.isDebugEnabled()) {
logger.debug("Shortcut {} doesn't have attributes in {}", regionShortcut, cache.listRegionAttributes());
}
throw new IllegalStateException(CliStrings.format(CliStrings.CREATE_REGION__MSG__COULDNOT_LOAD_REGION_ATTRIBUTES_FOR_SHORTCUT_0, regionShortcut));
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Using Manager's region attributes for {}", regionPath);
}
regionAttributes = regionCreateArgs.getRegionAttributes();
if (logger.isDebugEnabled()) {
logger.debug("Using Attributes : {}", regionAttributes);
}
}
isPartitioned = regionAttributes.getPartitionAttributes() != null;
factory = cache.createRegionFactory(regionAttributes);
if (!isPartitioned && regionCreateArgs.hasPartitionAttributes()) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__OPTION_0_CAN_BE_USED_ONLY_FOR_PARTITIONEDREGION, regionCreateArgs.getPartitionArgs().getUserSpecifiedPartitionAttributes()));
}
if (isPartitioned) {
PartitionAttributes<K, V> partitionAttributes = extractPartitionAttributes(cache, regionAttributes, regionCreateArgs);
DataPolicy originalDataPolicy = regionAttributes.getDataPolicy();
factory.setPartitionAttributes(partitionAttributes);
// We have to do this because AttributesFactory.setPartitionAttributes()
// checks RegionAttributes.hasDataPolicy() which is set only when the data
// policy is set explicitly
factory.setDataPolicy(originalDataPolicy);
}
// Set Constraints
final String keyConstraint = regionCreateArgs.getKeyConstraint();
final String valueConstraint = regionCreateArgs.getValueConstraint();
if (keyConstraint != null && !keyConstraint.isEmpty()) {
Class<K> keyConstraintClass = CliUtil.forName(keyConstraint, CliStrings.CREATE_REGION__KEYCONSTRAINT);
factory.setKeyConstraint(keyConstraintClass);
}
if (valueConstraint != null && !valueConstraint.isEmpty()) {
Class<V> valueConstraintClass = CliUtil.forName(valueConstraint, CliStrings.CREATE_REGION__VALUECONSTRAINT);
factory.setValueConstraint(valueConstraintClass);
}
// Expiration attributes
final RegionFunctionArgs.ExpirationAttrs entryExpirationIdleTime = regionCreateArgs.getEntryExpirationIdleTime();
if (entryExpirationIdleTime != null) {
factory.setEntryIdleTimeout(entryExpirationIdleTime.convertToExpirationAttributes());
}
final RegionFunctionArgs.ExpirationAttrs entryExpirationTTL = regionCreateArgs.getEntryExpirationTTL();
if (entryExpirationTTL != null) {
factory.setEntryTimeToLive(entryExpirationTTL.convertToExpirationAttributes());
}
final RegionFunctionArgs.ExpirationAttrs regionExpirationIdleTime = regionCreateArgs.getRegionExpirationIdleTime();
if (regionExpirationIdleTime != null) {
factory.setEntryIdleTimeout(regionExpirationIdleTime.convertToExpirationAttributes());
}
final RegionFunctionArgs.ExpirationAttrs regionExpirationTTL = regionCreateArgs.getRegionExpirationTTL();
if (regionExpirationTTL != null) {
factory.setEntryTimeToLive(regionExpirationTTL.convertToExpirationAttributes());
}
// Associate a Disk Store
final String diskStore = regionCreateArgs.getDiskStore();
if (diskStore != null && !diskStore.isEmpty()) {
factory.setDiskStoreName(diskStore);
}
if (regionCreateArgs.isSetDiskSynchronous()) {
factory.setDiskSynchronous(regionCreateArgs.isDiskSynchronous());
}
if (regionCreateArgs.isSetOffHeap()) {
factory.setOffHeap(regionCreateArgs.isOffHeap());
}
// Set stats enabled
if (regionCreateArgs.isSetStatisticsEnabled()) {
factory.setStatisticsEnabled(regionCreateArgs.isStatisticsEnabled());
}
// Set conflation
if (regionCreateArgs.isSetEnableAsyncConflation()) {
factory.setEnableAsyncConflation(regionCreateArgs.isEnableAsyncConflation());
}
if (regionCreateArgs.isSetEnableSubscriptionConflation()) {
factory.setEnableSubscriptionConflation(regionCreateArgs.isEnableSubscriptionConflation());
}
// Gateway Sender Ids
final Set<String> gatewaySenderIds = regionCreateArgs.getGatewaySenderIds();
if (gatewaySenderIds != null && !gatewaySenderIds.isEmpty()) {
for (String gatewaySenderId : gatewaySenderIds) {
factory.addGatewaySenderId(gatewaySenderId);
}
}
// Async Queue Ids
final Set<String> asyncEventQueueIds = regionCreateArgs.getAsyncEventQueueIds();
if (asyncEventQueueIds != null && !asyncEventQueueIds.isEmpty()) {
for (String asyncEventQueueId : asyncEventQueueIds) {
factory.addAsyncEventQueueId(asyncEventQueueId);
}
}
// concurrency check enabled & concurrency level
if (regionCreateArgs.isSetConcurrencyChecksEnabled()) {
factory.setConcurrencyChecksEnabled(regionCreateArgs.isConcurrencyChecksEnabled());
}
if (regionCreateArgs.isSetConcurrencyLevel()) {
factory.setConcurrencyLevel(regionCreateArgs.getConcurrencyLevel());
}
// cloning enabled for delta
if (regionCreateArgs.isSetCloningEnabled()) {
factory.setCloningEnabled(regionCreateArgs.isCloningEnabled());
}
// multicast enabled for replication
if (regionCreateArgs.isSetMcastEnabled()) {
factory.setMulticastEnabled(regionCreateArgs.isMcastEnabled());
}
// Set plugins
final Set<String> cacheListeners = regionCreateArgs.getCacheListeners();
if (cacheListeners != null && !cacheListeners.isEmpty()) {
for (String cacheListener : cacheListeners) {
Class<CacheListener<K, V>> cacheListenerKlass = CliUtil.forName(cacheListener, CliStrings.CREATE_REGION__CACHELISTENER);
factory.addCacheListener(CliUtil.newInstance(cacheListenerKlass, CliStrings.CREATE_REGION__CACHELISTENER));
}
}
// Compression provider
if (regionCreateArgs.isSetCompressor()) {
Class<Compressor> compressorKlass = CliUtil.forName(regionCreateArgs.getCompressor(), CliStrings.CREATE_REGION__COMPRESSOR);
factory.setCompressor(CliUtil.newInstance(compressorKlass, CliStrings.CREATE_REGION__COMPRESSOR));
}
final String cacheLoader = regionCreateArgs.getCacheLoader();
if (cacheLoader != null) {
Class<CacheLoader<K, V>> cacheLoaderKlass = CliUtil.forName(cacheLoader, CliStrings.CREATE_REGION__CACHELOADER);
factory.setCacheLoader(CliUtil.newInstance(cacheLoaderKlass, CliStrings.CREATE_REGION__CACHELOADER));
}
final String cacheWriter = regionCreateArgs.getCacheWriter();
if (cacheWriter != null) {
Class<CacheWriter<K, V>> cacheWriterKlass = CliUtil.forName(cacheWriter, CliStrings.CREATE_REGION__CACHEWRITER);
factory.setCacheWriter(CliUtil.newInstance(cacheWriterKlass, CliStrings.CREATE_REGION__CACHEWRITER));
}
String regionName = regionPathData.getName();
if (parentRegion != null) {
createdRegion = factory.createSubregion(parentRegion, regionName);
} else {
createdRegion = factory.create(regionName);
}
return createdRegion;
}
Aggregations