Search in sources :

Example 6 with Role

use of org.apache.geode.distributed.Role in project geode by apache.

the class RegionMBeanCompositeDataFactory method getMembershipAttributesData.

public static MembershipAttributesData getMembershipAttributesData(RegionAttributes regAttrs) {
    MembershipAttributes memAttrs = regAttrs.getMembershipAttributes();
    Set<String> requiredRoles = new HashSet<String>();
    Iterator<Role> it = memAttrs.getRequiredRoles().iterator();
    while (it.hasNext()) {
        requiredRoles.add(it.next().getName());
    }
    String lossAction = memAttrs.getLossAction().toString();
    String resumptionAction = memAttrs.getResumptionAction().toString();
    MembershipAttributesData membershipAttributesData = new MembershipAttributesData(requiredRoles, lossAction, resumptionAction);
    return membershipAttributesData;
}
Also used : Role(org.apache.geode.distributed.Role) MembershipAttributesData(org.apache.geode.management.MembershipAttributesData) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) HashSet(java.util.HashSet)

Example 7 with Role

use of org.apache.geode.distributed.Role in project geode by apache.

the class MembershipAttributes method toString.

/**
   * Returns a string representation of the object.
   * 
   * @return a string representation of the object
   */
@Override
public String toString() {
    if (!hasRequiredRoles()) {
        return "RequiredRoles(none)";
    } else {
        final StringBuffer sb = new StringBuffer();
        sb.append("RequiredRoles(");
        boolean comma = false;
        for (Iterator<Role> iter = this.requiredRoles.iterator(); iter.hasNext(); ) {
            if (comma)
                sb.append(",");
            Role role = iter.next();
            sb.append(role.getName());
            comma = true;
        }
        sb.append("); Policy:");
        sb.append(this.lossAction.toString());
        sb.append("; Action:");
        sb.append(this.resumptionAction.toString());
        return sb.toString();
    }
}
Also used : InternalRole(org.apache.geode.distributed.internal.membership.InternalRole) Role(org.apache.geode.distributed.Role)

Example 8 with Role

use of org.apache.geode.distributed.Role in project geode by apache.

the class CacheXmlGenerator method generate.

/**
   * Generates XML for a <code>MembershipAttributes</code>
   */
private void generate(MembershipAttributes ra) throws SAXException {
    Set roles = ra.getRequiredRoles();
    String laction = ra.getLossAction().toString().toLowerCase().replace('_', '-');
    String raction = ra.getResumptionAction().toString().toLowerCase().replace('_', '-');
    AttributesImpl raAtts = new AttributesImpl();
    raAtts.addAttribute("", "", LOSS_ACTION, "", laction);
    raAtts.addAttribute("", "", RESUMPTION_ACTION, "", raction);
    handler.startElement("", MEMBERSHIP_ATTRIBUTES, MEMBERSHIP_ATTRIBUTES, raAtts);
    for (Iterator iter = roles.iterator(); iter.hasNext(); ) {
        Role role = (Role) iter.next();
        AttributesImpl roleAtts = new AttributesImpl();
        roleAtts.addAttribute("", "", NAME, "", role.getName());
        handler.startElement("", REQUIRED_ROLE, REQUIRED_ROLE, roleAtts);
        handler.endElement("", REQUIRED_ROLE, REQUIRED_ROLE);
    }
    handler.endElement("", MEMBERSHIP_ATTRIBUTES, MEMBERSHIP_ATTRIBUTES);
}
Also used : Role(org.apache.geode.distributed.Role) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) DiskWriteAttributesImpl(org.apache.geode.internal.cache.DiskWriteAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) AttributesImpl(org.xml.sax.helpers.AttributesImpl) Iterator(java.util.Iterator)

Example 9 with Role

use of org.apache.geode.distributed.Role in project geode by apache.

the class RegionReliabilityTestCase method testNoAccess.

// -------------------------------------------------------------------------
// Tests to be run under every permutation of config options
// Valid configurations include scope D-ACK, D-NOACK, GLOBAL
// -------------------------------------------------------------------------
/**
   * Tests affect of NO_ACCESS on region operations.
   */
@Test
public void testNoAccess() throws Exception {
    final String name = this.getUniqueName();
    final String roleA = name + "-A";
    // assign names to 4 vms...
    final String[] requiredRoles = { roleA };
    Set requiredRolesSet = new HashSet();
    for (int i = 0; i < requiredRoles.length; i++) {
        requiredRolesSet.add(InternalRole.getRole(requiredRoles[i]));
    }
    assertEquals(requiredRoles.length, requiredRolesSet.size());
    // connect controller to system...
    Properties config = new Properties();
    config.setProperty(ROLES, "");
    getSystem(config);
    getCache();
    // create region in controller...
    MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.NO_ACCESS, ResumptionAction.NONE);
    AttributesFactory fac = new AttributesFactory();
    fac.setMembershipAttributes(ra);
    fac.setScope(getRegionScope());
    fac.setStatisticsEnabled(true);
    RegionAttributes attr = fac.create();
    Region region = createRootRegion(name, attr);
    // wait for memberTimeout to expire
    waitForMemberTimeout();
    // use vm0 for netsearch and netload
    Host.getHost(0).getVM(0).invoke(new CacheSerializableRunnable("Create Region") {

        public void run2() throws CacheException {
            createConnection(null);
            AttributesFactory fac = new AttributesFactory();
            fac.setScope(getRegionScope());
            fac.setCacheLoader(new CacheLoader() {

                public Object load(LoaderHelper helper) throws CacheLoaderException {
                    if ("netload".equals(helper.getKey())) {
                        return "netload";
                    } else {
                        return null;
                    }
                }

                public void close() {
                }
            });
            RegionAttributes attr = fac.create();
            Region region = createRootRegion(name, attr);
            Object netsearch = "netsearch";
            region.put(netsearch, netsearch);
        }
    });
    // test ops on Region that should throw
    assertNoAccessThrows(region);
    // use vm1 to create role
    Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Create Region") {

        public void run2() throws CacheException {
            createConnection(new String[] { roleA });
            AttributesFactory fac = new AttributesFactory();
            fac.setScope(getRegionScope());
            RegionAttributes attr = fac.create();
            createRootRegion(name, attr);
        }
    });
    Role role = (Role) requiredRolesSet.iterator().next();
    assertTrue(RequiredRoles.isRoleInRegionMembership(region, role));
    // retest ops on Region to assert no longer throw
    assertNoAccessDoesNotThrow(region);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheException(org.apache.geode.cache.CacheException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) LoaderHelper(org.apache.geode.cache.LoaderHelper) Role(org.apache.geode.distributed.Role) InternalRole(org.apache.geode.distributed.internal.membership.InternalRole) AttributesFactory(org.apache.geode.cache.AttributesFactory) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) CacheLoader(org.apache.geode.cache.CacheLoader) HashSet(java.util.HashSet) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 10 with Role

use of org.apache.geode.distributed.Role in project geode by apache.

the class RegionReliabilityTestCase method testReinitialization.

@Test
public void testReinitialization() throws Exception {
    final String name = this.getUniqueName();
    final String roleA = name + "-A";
    final String[] requiredRoles = { roleA };
    Set requiredRolesSet = new HashSet();
    for (int i = 0; i < requiredRoles.length; i++) {
        requiredRolesSet.add(InternalRole.getRole(requiredRoles[i]));
    }
    assertEquals(requiredRoles.length, requiredRolesSet.size());
    // connect controller to system...
    Properties config = new Properties();
    config.setProperty(ROLES, "");
    getSystem(config);
    getCache();
    // create region in controller...
    MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.NO_ACCESS, ResumptionAction.REINITIALIZE);
    AttributesFactory fac = new AttributesFactory();
    fac.setMembershipAttributes(ra);
    fac.setScope(getRegionScope());
    fac.setDataPolicy(DataPolicy.REPLICATE);
    RegionAttributes attr = fac.create();
    Region region = createRootRegion(name, attr);
    assertTrue(((AbstractRegion) region).requiresReliabilityCheck());
    assertFalse(RequiredRoles.checkForRequiredRoles(region).isEmpty());
    final String key = "KEY-testReinitialization";
    final String val = "VALUE-testReinitialization";
    Host.getHost(0).getVM(0).invoke(new CacheSerializableRunnable("Create Data") {

        public void run2() throws CacheException {
            createConnection(new String[] {});
            AttributesFactory fac = new AttributesFactory();
            fac.setScope(getRegionScope());
            fac.setDataPolicy(DataPolicy.REPLICATE);
            RegionAttributes attr = fac.create();
            Region region = createRootRegion(name, attr);
            region.put(key, val);
        }
    });
    final Region finalRegion = region;
    Thread thread = new Thread(new Runnable() {

        public void run() {
            try {
                RequiredRoles.waitForRequiredRoles(finalRegion, -1);
            } catch (InterruptedException e) {
                fail("interrupted");
            } catch (RegionReinitializedException e) {
            }
        }
    });
    thread.start();
    // create role and verify reinitialization took place
    Host.getHost(0).getVM(1).invokeAsync(new CacheSerializableRunnable("Create Role") {

        public void run2() throws CacheException {
            createConnection(new String[] { roleA });
            AttributesFactory fac = new AttributesFactory();
            fac.setScope(getRegionScope());
            RegionAttributes attr = fac.create();
            createRootRegion(name, attr);
        }
    });
    ThreadUtils.join(thread, 30 * 1000);
    assertTrue(region.isDestroyed());
    try {
        region.put("fee", "fi");
        fail("Should have thrown RegionReinitializedException");
    } catch (RegionReinitializedException e) {
    // pass
    }
    try {
        RequiredRoles.checkForRequiredRoles(region);
        fail("Should have thrown RegionReinitializedException");
    } catch (RegionReinitializedException e) {
    // pass
    }
    try {
        Role role = (Role) requiredRolesSet.iterator().next();
        RequiredRoles.isRoleInRegionMembership(region, role);
        fail("Should have thrown RegionReinitializedException");
    } catch (RegionReinitializedException e) {
    // pass
    }
    region = getRootRegion(name);
    assertNotNull(region);
    assertTrue(((AbstractRegion) region).requiresReliabilityCheck());
    assertTrue(RequiredRoles.checkForRequiredRoles(region).isEmpty());
    assertNotNull(region.getEntry(key));
    assertEquals(val, region.getEntry(key).getValue());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheException(org.apache.geode.cache.CacheException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Role(org.apache.geode.distributed.Role) InternalRole(org.apache.geode.distributed.internal.membership.InternalRole) AttributesFactory(org.apache.geode.cache.AttributesFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException) HashSet(java.util.HashSet) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

Role (org.apache.geode.distributed.Role)15 HashSet (java.util.HashSet)8 Set (java.util.Set)8 InternalRole (org.apache.geode.distributed.internal.membership.InternalRole)8 MembershipAttributes (org.apache.geode.cache.MembershipAttributes)7 Iterator (java.util.Iterator)6 Region (org.apache.geode.cache.Region)6 Properties (java.util.Properties)5 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 RegionAttributes (org.apache.geode.cache.RegionAttributes)5 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)5 Test (org.junit.Test)5 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 CacheException (org.apache.geode.cache.CacheException)2 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2 AbstractRegion (org.apache.geode.internal.cache.AbstractRegion)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)2 TreeSet (java.util.TreeSet)1