use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class PDXCommands method configurePDX.
@CliCommand(value = CliStrings.CONFIGURE_PDX, help = CliStrings.CONFIGURE_PDX__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result configurePDX(@CliOption(key = CliStrings.CONFIGURE_PDX__READ__SERIALIZED, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__READ__SERIALIZED__HELP) Boolean readSerialized, @CliOption(key = CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS__HELP) Boolean ignoreUnreadFields, @CliOption(key = CliStrings.CONFIGURE_PDX__DISKSTORE, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = "", help = CliStrings.CONFIGURE_PDX__DISKSTORE__HELP) String diskStore, @CliOption(key = CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES__HELP) String[] patterns, @CliOption(key = CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES__HELP) String[] portablePatterns) {
Result result = null;
try {
InfoResultData ird = ResultBuilder.createInfoResultData();
CacheCreation cache = new CacheCreation(true);
if ((portablePatterns != null && portablePatterns.length > 0) && (patterns != null && patterns.length > 0)) {
return ResultBuilder.createUserErrorResult(CliStrings.CONFIGURE_PDX__ERROR__MESSAGE);
}
if (!CliUtil.getAllNormalMembers(CliUtil.getCacheIfExists()).isEmpty()) {
ird.addLine(CliStrings.CONFIGURE_PDX__NORMAL__MEMBERS__WARNING);
}
// Set persistent and the disk-store
if (diskStore != null) {
cache.setPdxPersistent(true);
ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent());
if (!diskStore.equals("")) {
cache.setPdxDiskStore(diskStore);
ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + cache.getPdxDiskStore());
} else {
ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + "DEFAULT");
}
} else {
cache.setPdxPersistent(CacheConfig.DEFAULT_PDX_PERSISTENT);
ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent());
}
// Set read-serialized
if (readSerialized != null) {
cache.setPdxReadSerialized(readSerialized);
} else {
cache.setPdxReadSerialized(CacheConfig.DEFAULT_PDX_READ_SERIALIZED);
}
ird.addLine(CliStrings.CONFIGURE_PDX__READ__SERIALIZED + " = " + cache.getPdxReadSerialized());
// Set ingoreUnreadFields
if (ignoreUnreadFields != null) {
cache.setPdxIgnoreUnreadFields(ignoreUnreadFields);
} else {
cache.setPdxIgnoreUnreadFields(CacheConfig.DEFAULT_PDX_IGNORE_UNREAD_FIELDS);
}
ird.addLine(CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS + " = " + cache.getPdxIgnoreUnreadFields());
if (portablePatterns != null) {
ReflectionBasedAutoSerializer autoSerializer = new ReflectionBasedAutoSerializer(portablePatterns);
cache.setPdxSerializer(autoSerializer);
ird.addLine("PDX Serializer " + cache.getPdxSerializer().getClass().getName());
ird.addLine("Portable classes " + Arrays.toString(portablePatterns));
}
if (patterns != null) {
ReflectionBasedAutoSerializer nonPortableAutoSerializer = new ReflectionBasedAutoSerializer(true, patterns);
cache.setPdxSerializer(nonPortableAutoSerializer);
ird.addLine("PDX Serializer : " + cache.getPdxSerializer().getClass().getName());
ird.addLine("Non portable classes :" + Arrays.toString(patterns));
}
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
CacheXmlGenerator.generate(cache, printWriter, true, false, false);
printWriter.close();
String xmlDefinition = stringWriter.toString();
// TODO jbarrett - shouldn't this use the same loadXmlDefinition that other constructors use?
XmlEntity xmlEntity = XmlEntity.builder().withType(CacheXml.PDX).withConfig(xmlDefinition).build();
result = ResultBuilder.buildResult(ird);
persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity, null));
} catch (Exception e) {
return ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testPARTITION_HEAP_LRU.
@Test
public void testPARTITION_HEAP_LRU() throws Exception {
CacheCreation cache = new CacheCreation();
RegionCreation root = (RegionCreation) cache.createRegion("partitionlru", "PARTITION_HEAP_LRU");
testXml(cache);
GemFireCacheImpl c = (GemFireCacheImpl) getCache();
Region r = c.getRegion("partitionlru");
assertNotNull(r);
RegionAttributes ra = r.getAttributes();
assertEquals(DataPolicy.PARTITION, ra.getDataPolicy());
assertNotNull(ra.getPartitionAttributes());
assertEquals(0, ra.getPartitionAttributes().getRedundantCopies());
assertEquals(EvictionAttributes.createLRUHeapAttributes(), ra.getEvictionAttributes());
assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, c.getResourceManager().getEvictionHeapPercentage(), 0);
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testMaxOplogSize.
@Test
public void testMaxOplogSize() throws Exception {
CacheCreation cache = new CacheCreation();
// Set properties for Asynch writes
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
RegionCreation root = (RegionCreation) cache.createRegion("root", attrs);
{
attrs = new RegionAttributesCreation(cache);
DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
dwaf.setSynchronous(true);
dwaf.setMaxOplogSize(1);
attrs.setDiskWriteAttributes(dwaf.create());
root.createSubregion("sync", attrs);
}
{
attrs = new RegionAttributesCreation(cache);
DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
dwaf.setTimeInterval(123L);
dwaf.setBytesThreshold(456L);
dwaf.setMaxOplogSize(1);
attrs.setDiskWriteAttributes(dwaf.create());
root.createSubregion("async", attrs);
}
testXml(cache);
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testExpirationAttriubutes.
/**
* Tests creating a cache with a various {@link ExpirationAttributes}.
*/
@Test
public void testExpirationAttriubutes() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setStatisticsEnabled(true);
{
ExpirationAttributes expire = new ExpirationAttributes(42, ExpirationAction.INVALIDATE);
attrs.setRegionTimeToLive(expire);
}
{
ExpirationAttributes expire = new ExpirationAttributes(43, ExpirationAction.DESTROY);
attrs.setRegionIdleTimeout(expire);
}
{
ExpirationAttributes expire = new ExpirationAttributes(44, ExpirationAction.LOCAL_INVALIDATE);
attrs.setEntryTimeToLive(expire);
}
{
ExpirationAttributes expire = new ExpirationAttributes(45, ExpirationAction.LOCAL_DESTROY);
attrs.setEntryIdleTimeout(expire);
}
cache.createRegion("root", attrs);
testXml(cache);
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testModifyRegionViaCacheXml.
/**
* Tests that loading cache XML can modify a region.
*/
@Test
public void testModifyRegionViaCacheXml() throws Exception {
CacheCreation creation = new CacheCreation();
int timeout1a = 123;
ExpirationAction action1a = ExpirationAction.LOCAL_DESTROY;
int timeout1b = 456;
ExpirationAction action1b = ExpirationAction.DESTROY;
RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout1a, action1a));
Region root = creation.createRegion("root", attrs);
attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout1b, action1b));
Region subregion = root.createSubregion("subregion", attrs);
testXml(creation);
Cache cache = getCache();
root = cache.getRegion("root");
assertEquals(timeout1a, root.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action1a, root.getAttributes().getEntryIdleTimeout().getAction());
subregion = root.getSubregion("subregion");
assertEquals(timeout1b, subregion.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action1b, subregion.getAttributes().getEntryIdleTimeout().getAction());
creation = new CacheCreation();
int timeout2a = 234;
ExpirationAction action2a = ExpirationAction.LOCAL_INVALIDATE;
int timeout2b = 567;
ExpirationAction action2b = ExpirationAction.INVALIDATE;
attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout2a, action2a));
attrs.setCacheListener(new MyTestCacheListener());
root = creation.createRegion("root", attrs);
attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout2b, action2b));
subregion = root.createSubregion("subregion", attrs);
cache.loadCacheXml(generate(creation));
root = cache.getRegion("root");
subregion = root.getSubregion("subregion");
assertEquals(timeout2a, root.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action2a, root.getAttributes().getEntryIdleTimeout().getAction());
assertTrue(root.getAttributes().getCacheListener() instanceof MyTestCacheListener);
assertEquals(timeout2b, subregion.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action2b, subregion.getAttributes().getEntryIdleTimeout().getAction());
}
Aggregations