Search in sources :

Example 26 with PartitionAttributesImpl

use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.

the class AttributesFactory method setPartitionAttributes.

/**
   * Sets the {@code PartitionAttributes} that describe how the region is partitioned among members
   * of the distributed system. This also establishes a data policy of {@link DataPolicy#PARTITION
   * PARTITION}, if the data policy has not already been set.
   *
   * @since GemFire 5.0
   */
public void setPartitionAttributes(PartitionAttributes partition) {
    if (partition != null) {
        if (!this.regionAttributes.hasDataPolicy()) {
            this.regionAttributes.dataPolicy = PartitionedRegionHelper.DEFAULT_DATA_POLICY;
        } else if (!PartitionedRegionHelper.ALLOWED_DATA_POLICIES.contains(this.regionAttributes.dataPolicy)) {
            throw new IllegalStateException(LocalizedStrings.AttributesFactory_DATA_POLICY_0_IS_NOT_ALLOWED_FOR_A_PARTITIONED_REGION_DATAPOLICIES_OTHER_THAN_1_ARE_NOT_ALLOWED.toLocalizedString(new Object[] { this.regionAttributes.dataPolicy, PartitionedRegionHelper.ALLOWED_DATA_POLICIES }));
        }
        if (this.regionAttributes.hasPartitionAttributes() && this.regionAttributes.partitionAttributes instanceof PartitionAttributesImpl && partition instanceof PartitionAttributesImpl) {
            // Make a copy and call merge on it to prevent bug 51616
            PartitionAttributesImpl copy = ((PartitionAttributesImpl) this.regionAttributes.partitionAttributes).copy();
            copy.merge((PartitionAttributesImpl) partition);
            this.regionAttributes.partitionAttributes = copy;
        } else {
            this.regionAttributes.partitionAttributes = partition;
            this.regionAttributes.setHasPartitionAttributes(true);
        }
        ((PartitionAttributesImpl) this.regionAttributes.partitionAttributes).setOffHeap(this.regionAttributes.offHeap);
    } else {
        this.regionAttributes.partitionAttributes = null;
        this.regionAttributes.setHasPartitionAttributes(false);
    }
}
Also used : PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl)

Example 27 with PartitionAttributesImpl

use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.

the class CacheXmlGenerator method generate.

/**
   * Generates XML for a <code>PartitionAttributes</code>
   */
private void generate(PartitionAttributes pa) throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    if (generateDefaults() || pa.getRedundantCopies() != 0)
        atts.addAttribute("", "", PARTITION_REDUNDANT_COPIES, "", String.valueOf(pa.getRedundantCopies()));
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) {
        if (generateDefaults() || pa.getLocalMaxMemory() != ((PartitionAttributesImpl) pa).getLocalMaxMemoryDefault())
            atts.addAttribute("", "", LOCAL_MAX_MEMORY, "", String.valueOf(pa.getLocalMaxMemory()));
        if (generateDefaults() || pa.getTotalMaxMemory() != PartitionAttributesFactory.GLOBAL_MAX_MEMORY_DEFAULT)
            atts.addAttribute("", "", TOTAL_MAX_MEMORY, "", String.valueOf(pa.getTotalMaxMemory()));
        if (generateDefaults() || pa.getTotalNumBuckets() != PartitionAttributesFactory.GLOBAL_MAX_BUCKETS_DEFAULT)
            atts.addAttribute("", "", TOTAL_NUM_BUCKETS, "", String.valueOf(pa.getTotalNumBuckets()));
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
        if (pa.getColocatedWith() != null)
            atts.addAttribute("", "", PARTITION_COLOCATED_WITH, "", pa.getColocatedWith());
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
        if (generateDefaults() || pa.getRecoveryDelay() != PartitionAttributesFactory.RECOVERY_DELAY_DEFAULT)
            atts.addAttribute("", "", RECOVERY_DELAY, "", String.valueOf(pa.getRecoveryDelay()));
        if (generateDefaults() || pa.getStartupRecoveryDelay() != PartitionAttributesFactory.STARTUP_RECOVERY_DELAY_DEFAULT)
            atts.addAttribute("", "", STARTUP_RECOVERY_DELAY, "", String.valueOf(pa.getStartupRecoveryDelay()));
    }
    if (!generateDefaults() && atts.getLength() == 0 && pa.getPartitionResolver() == null && pa.getPartitionListeners().length == 0 && (pa.getFixedPartitionAttributes() == null || pa.getFixedPartitionAttributes().isEmpty())) {
        return;
    }
    handler.startElement("", PARTITION_ATTRIBUTES, PARTITION_ATTRIBUTES, atts);
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
        PartitionResolver rr = pa.getPartitionResolver();
        if (rr != null) {
            generate(PARTITION_RESOLVER, rr);
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_1) >= 0) {
        PartitionListener[] listeners = pa.getPartitionListeners();
        for (int i = 0; i < listeners.length; i++) {
            PartitionListener listener = listeners[i];
            if (listener != null) {
                generate(PARTITION_LISTENER, listener);
            }
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
        List<FixedPartitionAttributes> staticAttrs = pa.getFixedPartitionAttributes();
        if (staticAttrs != null) {
            generateFixedPartitionAttributes(FIXED_PARTITION_ATTRIBUTES, staticAttrs);
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) < 0) {
        Properties p = pa.getLocalProperties();
        generate(p, LOCAL_PROPERTIES);
        p = pa.getGlobalProperties();
        generate(p, GLOBAL_PROPERTIES);
    }
    handler.endElement("", PARTITION_ATTRIBUTES, PARTITION_ATTRIBUTES);
}
Also used : PartitionListener(org.apache.geode.cache.partition.PartitionListener) DiskWriteAttributesImpl(org.apache.geode.internal.cache.DiskWriteAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) AttributesImpl(org.xml.sax.helpers.AttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) PartitionResolver(org.apache.geode.cache.PartitionResolver) Properties(java.util.Properties)

Example 28 with PartitionAttributesImpl

use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.

the class CacheXmlParser method endPartitionProperites.

/**
   * Process either the <code>local-properties</code> or <code>global-properties</code> for a
   * {@link org.apache.geode.internal.cache.PartitionedRegion}
   * 
   * @param globalOrLocal either the string {@link CacheXml#LOCAL_PROPERTIES} or
   *        {@link CacheXml#GLOBAL_PROPERTIES}
   */
private void endPartitionProperites(String globalOrLocal) {
    Properties props = new Properties();
    Object top = stack.pop();
    while (!top.equals(globalOrLocal)) {
        if (!(top instanceof Parameter)) {
            throw new CacheXmlException(LocalizedStrings.CacheXmlParser_ONLY_A_PARAMETER_IS_ALLOWED_IN_THE_CONTEXT_OF_0.toLocalizedString(globalOrLocal));
        }
        Parameter param = (Parameter) top;
        props.put(param.getName(), param.getValue());
        top = stack.pop();
    }
    if (globalOrLocal.equals(GLOBAL_PROPERTIES)) {
        PartitionAttributesImpl pai = peekPartitionAttributesImpl(GLOBAL_PROPERTIES);
        pai.setGlobalProperties(props);
    } else if (globalOrLocal.equals(LOCAL_PROPERTIES)) {
        PartitionAttributesImpl pai = peekPartitionAttributesImpl(LOCAL_PROPERTIES);
        pai.setLocalProperties(props);
    } else {
        Assert.assertTrue(false, "Argument globalOrLocal has unexpected value " + globalOrLocal);
    }
}
Also used : FixedPartitionAttributesImpl(org.apache.geode.internal.cache.FixedPartitionAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) CacheXmlException(org.apache.geode.cache.CacheXmlException) Properties(java.util.Properties)

Example 29 with PartitionAttributesImpl

use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.

the class RestAPIOnRegionFunctionExecutionDUnitTest method createPeerWithPR.

private boolean createPeerWithPR() {
    RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 10);
    AttributesFactory raf = new AttributesFactory(ra);
    PartitionAttributesImpl pa = new PartitionAttributesImpl();
    pa.setAll(ra.getPartitionAttributes());
    pa.setTotalNumBuckets(17);
    raf.setPartitionAttributes(pa);
    Region region = CacheFactory.getAnyInstance().createRegion(PR_REGION_NAME, raf.create());
    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Region Created :" + region);
    assertNotNull(region);
    return Boolean.TRUE;
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) RegionAttributes(org.apache.geode.cache.RegionAttributes) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Example 30 with PartitionAttributesImpl

use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.

the class CacheXmlParser method startFixedPartitionAttributes.

/**
   * When a <code>fixed-partition-attributes</code> element is encountered, we create an instance of
   * FixedPartitionAttributesImpl and add it to the PartitionAttributesImpl stack.
   */
private void startFixedPartitionAttributes(Attributes atts) {
    FixedPartitionAttributesImpl fpai = new FixedPartitionAttributesImpl();
    String partitionName = atts.getValue(PARTITION_NAME);
    if (partitionName != null) {
        fpai.setPartitionName(partitionName);
    }
    String isPrimary = atts.getValue(IS_PRIMARY);
    if (isPrimary != null) {
        fpai.isPrimary(parseBoolean(isPrimary));
    }
    String numBuckets = atts.getValue(NUM_BUCKETS);
    if (numBuckets != null) {
        fpai.setNumBuckets(parseInt(numBuckets));
    }
    Object a = stack.peek();
    if (a instanceof PartitionAttributesImpl) {
        ((PartitionAttributesImpl) a).addFixedPartitionAttributes(fpai);
    }
}
Also used : FixedPartitionAttributesImpl(org.apache.geode.internal.cache.FixedPartitionAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) FixedPartitionAttributesImpl(org.apache.geode.internal.cache.FixedPartitionAttributesImpl)

Aggregations

PartitionAttributesImpl (org.apache.geode.internal.cache.PartitionAttributesImpl)64 AttributesFactory (org.apache.geode.cache.AttributesFactory)56 RegionAttributes (org.apache.geode.cache.RegionAttributes)55 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)55 Host (org.apache.geode.test.dunit.Host)55 VM (org.apache.geode.test.dunit.VM)55 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)55 Test (org.junit.Test)55 HashSet (java.util.HashSet)54 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)54 Function (org.apache.geode.cache.execute.Function)51 TestFunction (org.apache.geode.internal.cache.functions.TestFunction)51 Execution (org.apache.geode.cache.execute.Execution)50 ArrayList (java.util.ArrayList)49 ResultCollector (org.apache.geode.cache.execute.ResultCollector)49 FunctionException (org.apache.geode.cache.execute.FunctionException)46 List (java.util.List)42 Iterator (java.util.Iterator)37 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)37 IgnoredException (org.apache.geode.test.dunit.IgnoredException)36