Search in sources :

Example 76 with CacheCreation

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;
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) StringWriter(java.io.StringWriter) ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) Result(org.apache.geode.management.cli.Result) PrintWriter(java.io.PrintWriter) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 77 with CacheCreation

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);
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) RegionCreation(org.apache.geode.internal.cache.xmlcache.RegionCreation) Test(org.junit.Test)

Example 78 with CacheCreation

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);
}
Also used : RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) DiskWriteAttributesFactory(org.apache.geode.cache.DiskWriteAttributesFactory) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) RegionCreation(org.apache.geode.internal.cache.xmlcache.RegionCreation) Test(org.junit.Test)

Example 79 with CacheCreation

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);
}
Also used : RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Test(org.junit.Test)

Example 80 with CacheCreation

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());
}
Also used : ExpirationAction(org.apache.geode.cache.ExpirationAction) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Aggregations

CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)153 Test (org.junit.Test)143 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)114 RegionAttributesCreation (org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation)86 Region (org.apache.geode.cache.Region)62 LocalRegion (org.apache.geode.internal.cache.LocalRegion)57 Cache (org.apache.geode.cache.Cache)53 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)53 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)53 ClientCache (org.apache.geode.cache.client.ClientCache)42 RegionAttributes (org.apache.geode.cache.RegionAttributes)35 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)35 RegionCreation (org.apache.geode.internal.cache.xmlcache.RegionCreation)35 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)25 CacheServer (org.apache.geode.cache.server.CacheServer)17 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)16 File (java.io.File)15 DiskWriteAttributesFactory (org.apache.geode.cache.DiskWriteAttributesFactory)12 AttributesFactory (org.apache.geode.cache.AttributesFactory)9 FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)9