use of org.apache.geode.management.ManagementService in project geode by apache.
the class TestRemoteClusterDUnitTest method checkRemoteClusterStatus.
/**
* Checks Proxy GatewaySender
*
* @param vm reference to VM
*/
@SuppressWarnings("serial")
protected void checkRemoteClusterStatus(final VM vm, final DistributedMember senderMember) {
SerializableRunnable checkProxySender = new SerializableRunnable("DS Map Size") {
public void run() {
Cache cache = GemFireCacheImpl.getInstance();
final WaitCriterion waitCriteria2 = new WaitCriterion() {
@Override
public boolean done() {
Cache cache = GemFireCacheImpl.getInstance();
final ManagementService service = ManagementService.getManagementService(cache);
final DistributedSystemMXBean dsBean = service.getDistributedSystemMXBean();
if (dsBean != null) {
return true;
}
return false;
}
@Override
public String description() {
return "wait for getDistributedSystemMXBean to complete and get results";
}
};
Wait.waitForCriterion(waitCriteria2, 2 * 60 * 1000, 5000, true);
ManagementService service = ManagementService.getManagementService(cache);
final DistributedSystemMXBean dsBean = service.getDistributedSystemMXBean();
assertNotNull(dsBean);
Map<String, Boolean> dsMap = dsBean.viewRemoteClusterStatus();
LogWriterUtils.getLogWriter().info("Ds Map is: " + dsMap.size());
assertNotNull(dsMap);
assertEquals(true, dsMap.size() > 0 ? true : false);
}
};
vm.invoke(checkProxySender);
}
use of org.apache.geode.management.ManagementService in project geode by apache.
the class TestRemoteClusterDUnitTest method startGatewaySender.
/**
* start a gateway sender
*
* @param vm reference to VM
*/
@SuppressWarnings("serial")
protected void startGatewaySender(final VM vm) {
SerializableRunnable stopGatewaySender = new SerializableRunnable("Start Gateway Sender") {
public void run() {
Cache cache = GemFireCacheImpl.getInstance();
ManagementService service = ManagementService.getManagementService(cache);
GatewaySenderMXBean bean = service.getLocalGatewaySenderMXBean("pn");
assertNotNull(bean);
bean.start();
assertTrue(bean.isRunning());
}
};
vm.invoke(stopGatewaySender);
}
use of org.apache.geode.management.ManagementService in project geode by apache.
the class GemfireDataCommandsDUnitTest method setupForGetPutRemoveLocateEntry.
void setupForGetPutRemoveLocateEntry(String testName) {
final VM vm1 = Host.getHost(0).getVM(1);
final VM vm2 = Host.getHost(0).getVM(2);
Properties props = new Properties();
props.setProperty(NAME, testName + "Manager");
HeadlessGfsh gfsh = setUpJmxManagerOnVm0ThenConnect(props);
assertNotNull(gfsh);
assertEquals(true, gfsh.isConnectedAndReady());
vm1.invoke(new SerializableRunnable() {
public void run() {
InternalCache cache = getCache();
RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE);
Region dataRegion = regionFactory.create(DATA_REGION_NAME);
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
dataRegion = dataRegion.createSubregion(DATA_REGION_NAME_CHILD_1, dataRegion.getAttributes());
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
dataRegion = dataRegion.createSubregion(DATA_REGION_NAME_CHILD_1_2, dataRegion.getAttributes());
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
dataRegion = regionFactory.create(DATA_REGION_NAME_VM1);
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
PartitionAttributes partitionAttrs = new PartitionAttributesFactory().setRedundantCopies(2).create();
RegionFactory<Object, Object> partitionRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
partitionRegionFactory.setPartitionAttributes(partitionAttrs);
Region dataParRegion = partitionRegionFactory.create(DATA_PAR_REGION_NAME);
assertNotNull(dataParRegion);
getLogWriter().info("Created Region " + dataParRegion);
dataParRegion = partitionRegionFactory.create(DATA_PAR_REGION_NAME_VM1);
assertNotNull(dataParRegion);
getLogWriter().info("Created Region " + dataParRegion);
}
});
vm2.invoke(new SerializableRunnable() {
public void run() {
InternalCache cache = getCache();
RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE);
Region dataRegion = regionFactory.create(DATA_REGION_NAME);
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
dataRegion = dataRegion.createSubregion(DATA_REGION_NAME_CHILD_1, dataRegion.getAttributes());
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
dataRegion = dataRegion.createSubregion(DATA_REGION_NAME_CHILD_1_2, dataRegion.getAttributes());
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
dataRegion = regionFactory.create(DATA_REGION_NAME_VM2);
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
PartitionAttributes partitionAttrs = new PartitionAttributesFactory().setRedundantCopies(2).create();
RegionFactory<Object, Object> partitionRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
partitionRegionFactory.setPartitionAttributes(partitionAttrs);
Region dataParRegion = partitionRegionFactory.create(DATA_PAR_REGION_NAME);
assertNotNull(dataParRegion);
getLogWriter().info("Created Region " + dataParRegion);
dataParRegion = partitionRegionFactory.create(DATA_PAR_REGION_NAME_VM2);
assertNotNull(dataParRegion);
getLogWriter().info("Created Region " + dataParRegion);
}
});
final String vm1MemberId = vm1.invoke(() -> getMemberId());
final String vm2MemberId = vm2.invoke(() -> getMemberId());
getLogWriter().info("Vm1 ID : " + vm1MemberId);
getLogWriter().info("Vm2 ID : " + vm2MemberId);
final VM manager = Host.getHost(0).getVM(0);
SerializableRunnable checkRegionMBeans = new SerializableRunnable() {
@Override
public void run() {
InternalCache cache = getCache();
final ManagementService service = ManagementService.getManagementService(cache);
final WaitCriterion waitForMaangerMBean = new WaitCriterion() {
@Override
public boolean done() {
ManagerMXBean bean1 = service.getManagerMXBean();
DistributedRegionMXBean bean2 = service.getDistributedRegionMXBean(DATA_REGION_NAME_PATH);
if (bean1 == null) {
getLogWriter().info("Still probing for ManagerMBean");
return false;
} else {
getLogWriter().info("Still probing for DistributedRegionMXBean=" + bean2);
return (bean2 != null);
}
}
@Override
public String description() {
return "Probing for ManagerMBean";
}
};
waitForCriterion(waitForMaangerMBean, 30000, 2000, true);
assertNotNull(service.getMemberMXBean());
assertNotNull(service.getManagerMXBean());
DistributedRegionMXBean bean = service.getDistributedRegionMXBean(DATA_REGION_NAME_PATH);
assertNotNull(bean);
WaitCriterion waitForRegionMBeans = new WaitCriterion() {
@Override
public boolean done() {
DistributedRegionMXBean[] beans = new DistributedRegionMXBean[6];
beans[0] = service.getDistributedRegionMXBean(DATA_REGION_NAME_PATH);
beans[1] = service.getDistributedRegionMXBean(DATA_REGION_NAME_VM1_PATH);
beans[2] = service.getDistributedRegionMXBean(DATA_REGION_NAME_VM2_PATH);
beans[3] = service.getDistributedRegionMXBean(DATA_PAR_REGION_NAME_PATH);
beans[4] = service.getDistributedRegionMXBean(DATA_PAR_REGION_NAME_VM1_PATH);
beans[5] = service.getDistributedRegionMXBean(DATA_PAR_REGION_NAME_VM2_PATH);
// SubRegion Bug : Proxy creation has some issues.
// beans[6] = service.getDistributedRegionMXBean(DATA_REGION_NAME_CHILD_1_PATH);
// beans[7] = service.getDistributedRegionMXBean(DATA_REGION_NAME_CHILD_1_2_PATH);
boolean flag = true;
for (DistributedRegionMXBean b : beans) {
if (b == null) {
flag = false;
break;
}
}
if (!flag) {
getLogWriter().info("Still probing for regionMbeans " + DATA_REGION_NAME_PATH + "=" + beans[0] + " " + DATA_REGION_NAME_VM1_PATH + "=" + beans[1] + " " + DATA_REGION_NAME_VM2_PATH + "=" + beans[2] + " " + DATA_PAR_REGION_NAME_PATH + "=" + beans[3] + " " + DATA_PAR_REGION_NAME_VM1_PATH + "=" + beans[4] + " " + DATA_PAR_REGION_NAME_VM2_PATH + "=" + beans[5] + " ");
return false;
} else {
getLogWriter().info("Probing complete for regionMbeans " + DATA_REGION_NAME_PATH + "=" + beans[0] + " " + DATA_REGION_NAME_VM1_PATH + "=" + beans[1] + " " + DATA_REGION_NAME_VM2_PATH + "=" + beans[2] + " " + DATA_PAR_REGION_NAME_PATH + "=" + beans[3] + " " + DATA_PAR_REGION_NAME_VM1_PATH + "=" + beans[4] + " " + DATA_PAR_REGION_NAME_VM2_PATH + "=" + beans[5] + " ");
// bean1.getMemberCount()==1)
return true;
// else{
// getLogWriter().info("Still probing for regionMbeans for aggregation bean1=" +
// bean1.getMemberCount() + " bean2="+ bean2.getMemberCount() + " bean3" +
// bean3.getMemberCount());
// return false;
// }
}
}
@Override
public String description() {
return "Probing for regionMbeans";
}
};
waitForCriterion(waitForRegionMBeans, 30000, 2000, true);
String[] regions = { DATA_REGION_NAME_PATH, DATA_REGION_NAME_VM1_PATH, DATA_REGION_NAME_VM2_PATH, DATA_PAR_REGION_NAME_PATH, DATA_PAR_REGION_NAME_VM1_PATH, DATA_PAR_REGION_NAME_VM2_PATH };
for (String region : regions) {
bean = service.getDistributedRegionMXBean(region);
assertNotNull(bean);
String[] membersName = bean.getMembers();
getLogWriter().info("Members Array for region " + region + " : " + StringUtils.objectToString(membersName, true, 10));
if (bean.getMemberCount() < 1)
fail("Even after waiting mbean reports number of member hosting region " + DATA_REGION_NAME_VM1_PATH + " is less than one");
// assertIndexDetailsEquals(1, membersName.length); //exists in one members vm1
}
}
};
manager.invoke(checkRegionMBeans);
}
use of org.apache.geode.management.ManagementService in project geode by apache.
the class CreateAlterDestroyRegionCommandsDUnitTest method testCreateAlterDestroyUpdatesSharedConfig.
/**
* Asserts that creating, altering and destroying regions correctly updates the shared
* configuration.
*/
// GEODE-2009
@Category(FlakyTest.class)
@Test
public void testCreateAlterDestroyUpdatesSharedConfig() throws Exception {
disconnectAllFromDS();
final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
jmxPort = ports[0];
httpPort = ports[1];
try {
jmxHost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ignore) {
jmxHost = "localhost";
}
final String regionName = "testRegionSharedConfigRegion";
final String regionPath = "/" + regionName;
final String groupName = "testRegionSharedConfigGroup";
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
final Properties locatorProps = new Properties();
locatorProps.setProperty(NAME, "Locator");
locatorProps.setProperty(MCAST_PORT, "0");
locatorProps.setProperty(LOG_LEVEL, "fine");
locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
locatorProps.setProperty(JMX_MANAGER, "true");
locatorProps.setProperty(JMX_MANAGER_START, "true");
locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
Host.getHost(0).getVM(0).invoke(() -> {
final File locatorLogFile = new File("locator-" + locatorPort + ".log");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
waitAtMost(5, TimeUnit.SECONDS).until(() -> locator.isSharedConfigurationRunning());
ManagementService managementService = ManagementService.getExistingManagementService(GemFireCacheImpl.getInstance());
assertNotNull(managementService);
assertTrue(managementService.isManager());
assertTrue(checkIfCommandsAreLoadedOrNot());
} catch (IOException ioex) {
fail("Unable to create a locator with a shared configuration");
}
});
connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
VM vm = Host.getHost(0).getVM(1);
vm.invoke(() -> {
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
getSystem(localProps);
assertNotNull(getCache());
});
// Test creating the region
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, regionName);
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "REPLICATE");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__STATISTICSENABLED, "true");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__GROUP, groupName);
CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure that the region has been registered with the Manager MXBean
waitForRegionMBeanCreation(regionPath, 1);
// Make sure the region exists in the shared config
Host.getHost(0).getVM(0).invoke(() -> {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
assertTrue(sharedConfig.getConfiguration(groupName).getCacheXmlContent().contains(regionName));
} catch (Exception e) {
fail("Error in cluster configuration service", e);
}
});
// Restart the data vm to make sure the changes are in place
vm = Host.getHost(0).getVM(1);
vm.invoke(() -> {
Cache cache = getCache();
assertNotNull(cache);
cache.close();
assertTrue(cache.isClosed());
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
getSystem(localProps);
cache = getCache();
assertNotNull(cache);
Region region = cache.getRegion(regionName);
assertNotNull(region);
});
// Test altering the region
commandStringBuilder = new CommandStringBuilder(CliStrings.ALTER_REGION);
commandStringBuilder.addOption(CliStrings.ALTER_REGION__REGION, regionName);
commandStringBuilder.addOption(CliStrings.ALTER_REGION__GROUP, groupName);
commandStringBuilder.addOption(CliStrings.ALTER_REGION__ENTRYEXPIRATIONTIMETOLIVE, "45635");
commandStringBuilder.addOption(CliStrings.ALTER_REGION__ENTRYEXPIRATIONTTLACTION, "DESTROY");
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the region was altered in the shared config
Host.getHost(0).getVM(0).invoke(() -> {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
assertTrue(sharedConfig.getConfiguration(groupName).getCacheXmlContent().contains("45635"));
} catch (Exception e) {
fail("Error in cluster configuration service");
}
});
// Restart the data vm to make sure the changes are in place
vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableCallable() {
@Override
public Object call() {
Cache cache = getCache();
assertNotNull(cache);
cache.close();
assertTrue(cache.isClosed());
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
getSystem(localProps);
cache = getCache();
assertNotNull(cache);
Region region = cache.getRegion(regionName);
assertNotNull(region);
return null;
}
});
}
use of org.apache.geode.management.ManagementService in project geode by apache.
the class DistributedSystemStatsDUnitTest method awaitDistributedSystemMXBean.
private DistributedSystemMXBean awaitDistributedSystemMXBean() {
ManagementService service = this.managementTestRule.getManagementService();
await().until(() -> assertThat(service.getDistributedSystemMXBean()).isNotNull());
return service.getDistributedSystemMXBean();
}
Aggregations