Search in sources :

Example 11 with Role

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

the class SystemMemberImpl method getRoles.

public String[] getRoles() {
    Set roles = this.internalId.getRoles();
    String[] roleNames = new String[roles.size()];
    Iterator iter = roles.iterator();
    for (int i = 0; i < roleNames.length; i++) {
        Role role = (Role) iter.next();
        roleNames[i] = role.getName();
    }
    return roleNames;
}
Also used : Role(org.apache.geode.distributed.Role)

Example 12 with Role

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

the class DistributedRegion method isNoDistributionOk.

/**
   * Called when we do a distributed operation and don't have anyone to distributed it too. Since
   * this is only called when no distribution was done (i.e. no recipients) we do not check
   * isMissingRequiredRoles because it might not longer be true due to race conditions
   * 
   * @return false if this region has at least one required role and queuing is configured. Returns
   *         true if sending to no one is ok.
   * @throws RoleException if a required role is missing and the LossAction is either NO_ACCESS or
   *         LIMITED_ACCESS.
   * @since GemFire 5.0
   */
boolean isNoDistributionOk() {
    if (this.requiresReliabilityCheck) {
        MembershipAttributes ra = getMembershipAttributes();
        Set<Role> failedRoles = ra.getRequiredRoles();
        throw new RegionDistributionException(LocalizedStrings.DistributedRegion_OPERATION_DISTRIBUTION_WAS_NOT_DONE_TO_THESE_REQUIRED_ROLES_0.toLocalizedString(failedRoles), getFullPath(), failedRoles);
    }
    return true;
}
Also used : Role(org.apache.geode.distributed.Role) RegionDistributionException(org.apache.geode.cache.RegionDistributionException) MembershipAttributes(org.apache.geode.cache.MembershipAttributes)

Example 13 with Role

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

the class RoleEventImpl method fromData.

@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
    super.fromData(in);
    String[] requiredRoleNames = DataSerializer.readStringArray(in);
    Set requiredRolesSet = new HashSet(requiredRoleNames.length);
    for (int i = 0; i < requiredRoleNames.length; i++) {
        Role role = InternalRole.getRole(requiredRoleNames[i]);
        requiredRolesSet.add(role);
    }
    this.requiredRoles = Collections.unmodifiableSet(requiredRolesSet);
}
Also used : InternalRole(org.apache.geode.distributed.internal.membership.InternalRole) Role(org.apache.geode.distributed.Role)

Example 14 with Role

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

the class RoleEventImpl method toData.

@Override
public void toData(DataOutput out) throws IOException {
    super.toData(out);
    String[] requiredRoleNames = new String[this.requiredRoles.size()];
    Iterator iter = this.requiredRoles.iterator();
    for (int i = 0; i < requiredRoleNames.length; i++) {
        Role role = (Role) iter.next();
        requiredRoleNames[i] = role.getName();
    }
    DataSerializer.writeStringArray(requiredRoleNames, out);
}
Also used : InternalRole(org.apache.geode.distributed.internal.membership.InternalRole) Role(org.apache.geode.distributed.Role)

Example 15 with Role

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

the class RequiredRolesDUnitTest method testRequiredRolesInLoss.

/**
   * Tests that RequiredRoles detects missing roles.
   */
@Test
public void testRequiredRolesInLoss() throws Exception {
    String name = this.getUniqueName();
    final String roleA = name + "-A";
    final String roleC = name + "-C";
    final String roleD = name + "-D";
    // assign names to 4 vms...
    final String[] requiredRoles = { roleA, roleC, roleD };
    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);
    // create region in controller...
    MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.FULL_ACCESS, ResumptionAction.NONE);
    AttributesFactory fac = new AttributesFactory();
    fac.setMembershipAttributes(ra);
    fac.setScope(Scope.DISTRIBUTED_ACK);
    RegionAttributes attr = fac.create();
    Region region = createRootRegion(name, attr);
    RegionAttributes rattr = region.getAttributes();
    assertEquals(true, rattr.getMembershipAttributes().hasRequiredRoles());
    Set roles = rattr.getMembershipAttributes().getRequiredRoles();
    assertNotNull(roles);
    assertEquals(false, roles.isEmpty());
    assertEquals(requiredRolesSet.size(), roles.size());
    assertEquals(true, roles.containsAll(requiredRolesSet));
    // wait for memberTimeout to expire
    waitForMemberTimeout();
    // assert all are missing according to RequiredRoles...
    Set missingRoles = RequiredRoles.checkForRequiredRoles(region);
    assertNotNull(missingRoles);
    assertEquals(requiredRolesSet.size(), missingRoles.size());
    assertEquals(true, missingRoles.containsAll(requiredRolesSet));
    // assert isPresent is false on each missing role...
    for (Iterator iter = missingRoles.iterator(); iter.hasNext(); ) {
        Role role = (Role) iter.next();
        assertEquals(false, role.isPresent());
    }
}
Also used : InternalRole(org.apache.geode.distributed.internal.membership.InternalRole) Role(org.apache.geode.distributed.Role) HashSet(java.util.HashSet) Set(java.util.Set) AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) HashSet(java.util.HashSet) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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