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;
}
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;
}
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);
}
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);
}
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());
}
}
Aggregations