use of org.apache.geode.management.MemberMXBean in project geode by apache.
the class DistributedSystemBridge method listCacheServers.
/**
* @return list of members hosting cache server
*/
public String[] listCacheServers() {
Iterator<MemberMXBean> memberIterator = mapOfMembers.values().iterator();
if (memberIterator != null) {
List<String> listOfServer = new ArrayList<>();
while (memberIterator.hasNext()) {
MemberMXBean bean = memberIterator.next();
if (bean.isCacheServer()) {
listOfServer.add(bean.getMember());
}
}
String[] members = new String[listOfServer.size()];
return listOfServer.toArray(members);
}
return ManagementConstants.NO_DATA_STRING;
}
use of org.apache.geode.management.MemberMXBean in project geode by apache.
the class DistributedSystemBridge method fetchRegionObjectNames.
public ObjectName[] fetchRegionObjectNames(ObjectName memberMBeanName) throws Exception {
List<ObjectName> list = new ArrayList<>();
if (mapOfMembers.get(memberMBeanName) != null) {
MemberMXBean bean = mapOfMembers.get(memberMBeanName);
String member = memberMBeanName.getKeyProperty(ManagementConstants.OBJECTNAME_MEMBER_APPENDER);
String[] regions = bean.listRegions();
for (String region : regions) {
ObjectName regionMBeanName = MBeanJMXAdapter.getRegionMBeanName(member, region);
list.add(regionMBeanName);
}
ObjectName[] objNames = new ObjectName[list.size()];
return list.toArray(objNames);
} else {
throw new Exception(ManagementStrings.MEMBER_MBEAN_NOT_FOUND_IN_DS.toString());
}
}
use of org.apache.geode.management.MemberMXBean in project geode by apache.
the class MXBeanProvider method getMemberMXBean.
public static MemberMXBean getMemberMXBean(final String serviceName, final String member) throws IOException {
assertState(Gfsh.isCurrentInstanceConnectedAndReady(), "Gfsh must be connected in order to get proxy to a GemFire Member MBean.");
MemberMXBean memberBean = null;
try {
String objectNamePattern = ManagementConstants.OBJECTNAME__PREFIX;
objectNamePattern += (org.apache.geode.internal.lang.StringUtils.isBlank(serviceName) ? org.apache.geode.internal.lang.StringUtils.EMPTY : "service=" + serviceName + org.apache.geode.internal.lang.StringUtils.COMMA_DELIMITER);
objectNamePattern += "type=Member,*";
// NOTE throws a MalformedObjectNameException, however, this should not happen since the
// ObjectName is constructed
// here in a conforming pattern
final ObjectName objectName = ObjectName.getInstance(objectNamePattern);
final QueryExp query = Query.or(Query.eq(Query.attr("Name"), Query.value(member)), Query.eq(Query.attr("Id"), Query.value(member)));
final Set<ObjectName> memberObjectNames = Gfsh.getCurrentInstance().getOperationInvoker().queryNames(objectName, query);
if (!memberObjectNames.isEmpty()) {
memberBean = Gfsh.getCurrentInstance().getOperationInvoker().getMBeanProxy(memberObjectNames.iterator().next(), MemberMXBean.class);
}
} catch (MalformedObjectNameException e) {
Gfsh.getCurrentInstance().logSevere(e.getMessage(), e);
}
return memberBean;
}
use of org.apache.geode.management.MemberMXBean in project geode by apache.
the class StatusLocatorCommand method statusLocator.
@CliCommand(value = CliStrings.STATUS_LOCATOR, help = CliStrings.STATUS_LOCATOR__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_LOCATOR, CliStrings.TOPIC_GEODE_LIFECYCLE })
public Result statusLocator(@CliOption(key = CliStrings.STATUS_LOCATOR__MEMBER, optionContext = ConverterHint.LOCATOR_MEMBER_IDNAME, help = CliStrings.STATUS_LOCATOR__MEMBER__HELP) final String member, @CliOption(key = CliStrings.STATUS_LOCATOR__HOST, help = CliStrings.STATUS_LOCATOR__HOST__HELP) final String locatorHost, @CliOption(key = CliStrings.STATUS_LOCATOR__PORT, help = CliStrings.STATUS_LOCATOR__PORT__HELP) final Integer locatorPort, @CliOption(key = CliStrings.STATUS_LOCATOR__PID, help = CliStrings.STATUS_LOCATOR__PID__HELP) final Integer pid, @CliOption(key = CliStrings.STATUS_LOCATOR__DIR, help = CliStrings.STATUS_LOCATOR__DIR__HELP) final String workingDirectory) {
try {
if (StringUtils.isNotBlank(member)) {
if (isConnectedAndReady()) {
final MemberMXBean locatorProxy = getMemberMXBean(member);
if (locatorProxy != null) {
LocatorLauncher.LocatorState state = LocatorLauncher.LocatorState.fromJson(locatorProxy.status());
return createStatusLocatorResult(state);
} else {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STATUS_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE, member));
}
} else {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STATUS_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, LOCATOR_TERM_NAME));
}
} else {
final LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STATUS).setBindAddress(locatorHost).setDebug(isDebugging()).setPid(pid).setPort(locatorPort).setWorkingDirectory(workingDirectory).build();
final LocatorLauncher.LocatorState state = locatorLauncher.status();
return createStatusLocatorResult(state);
}
} catch (IllegalArgumentException | IllegalStateException e) {
return ResultBuilder.createUserErrorResult(e.getMessage());
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable t) {
SystemFailure.checkFailure();
return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.STATUS_LOCATOR__GENERAL_ERROR_MESSAGE, getLocatorId(locatorHost, locatorPort), StringUtils.defaultIfBlank(workingDirectory, SystemUtils.CURRENT_DIRECTORY), toString(t, getGfsh().getDebug())));
}
}
use of org.apache.geode.management.MemberMXBean in project geode by apache.
the class DistributedSystemStatsDUnitTest method testDistributedSystemStats.
@Test
public void testDistributedSystemStats() throws Exception {
this.managerVM.invoke("verifyMBeans", () -> {
DistributedSystemMXBean distributedSystemMXBean = awaitDistributedSystemMXBean();
// next block awaits all memberMXBeanName to refresh (getLastUpdateTime)
SystemManagementService service = this.managementTestRule.getSystemManagementService();
Set<DistributedMember> otherMemberSet = this.managementTestRule.getOtherNormalMembers();
assertEquals(3, otherMemberSet.size());
for (DistributedMember member : otherMemberSet) {
MemberMXBean memberMXBean = awaitMemberMXBeanProxy(member);
ObjectName memberMXBeanName = service.getMemberMBeanName(member);
long lastRefreshTime = service.getLastUpdateTime(memberMXBeanName);
await().until(() -> assertTrue(service.getLastUpdateTime(memberMXBeanName) > lastRefreshTime));
}
// TODO: add assertions for distributedSystemMXBean stats?
});
}
Aggregations