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