use of org.apache.geode.management.internal.SystemManagementService in project geode by apache.
the class MiscellaneousCommands method showLog.
@CliCommand(value = CliStrings.SHOW_LOG, help = CliStrings.SHOW_LOG_HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DEBUG_UTIL })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result showLog(@CliOption(key = CliStrings.SHOW_LOG_MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.SHOW_LOG_MEMBER_HELP, mandatory = true) String memberNameOrId, @CliOption(key = CliStrings.SHOW_LOG_LINE_NUM, unspecifiedDefaultValue = "0", help = CliStrings.SHOW_LOG_LINE_NUM_HELP, mandatory = false) int numberOfLines) {
Result result = null;
try {
InternalCache cache = getCache();
SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
MemberMXBean bean = null;
DistributedMember memberToBeInvoked = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
if (memberToBeInvoked != null) {
String memberId = memberToBeInvoked.getId();
if (cache.getDistributedSystem().getDistributedMember().getId().equals(memberId)) {
bean = service.getMemberMXBean();
} else {
ObjectName objectName = service.getMemberMBeanName(memberToBeInvoked);
bean = service.getMBeanProxy(objectName, MemberMXBean.class);
}
if (numberOfLines > ManagementConstants.MAX_SHOW_LOG_LINES) {
numberOfLines = ManagementConstants.MAX_SHOW_LOG_LINES;
}
if (numberOfLines == 0 || numberOfLines < 0) {
numberOfLines = ManagementConstants.DEFAULT_SHOW_LOG_LINES;
}
InfoResultData resultData = ResultBuilder.createInfoResultData();
if (bean != null) {
String log = bean.showLog(numberOfLines);
if (log != null) {
resultData.addLine(log);
} else {
resultData.addLine(CliStrings.SHOW_LOG_NO_LOG);
}
} else {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(memberNameOrId + CliStrings.SHOW_LOG_MSG_MEMBER_NOT_FOUND);
return (ResultBuilder.buildResult(errorResultData));
}
result = ResultBuilder.buildResult(resultData);
} else {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(memberNameOrId + CliStrings.SHOW_LOG_MSG_MEMBER_NOT_FOUND);
return (ResultBuilder.buildResult(errorResultData));
}
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.SHOW_LOG_ERROR + CliUtil.stackTraceAsString(e));
}
return result;
}
use of org.apache.geode.management.internal.SystemManagementService in project geode by apache.
the class DistributedSystemDUnitTest method testNotificationHub.
@Test
public void testNotificationHub() throws Exception {
this.managementTestRule.createMembers();
this.managementTestRule.createManagers();
class NotificationHubTestListener implements NotificationListener {
@Override
public synchronized void handleNotification(Notification notification, Object handback) {
logger.info("Notification received {}", notification);
notifications.add(notification);
}
}
this.managerVM.invoke("addListenerToMemberMXBean", () -> {
ManagementService service = this.managementTestRule.getManagementService();
DistributedSystemMXBean distributedSystemMXBean = service.getDistributedSystemMXBean();
await().until(() -> assertThat(distributedSystemMXBean.listMemberObjectNames()).hasSize(5));
for (ObjectName objectName : distributedSystemMXBean.listMemberObjectNames()) {
NotificationHubTestListener listener = new NotificationHubTestListener();
getPlatformMBeanServer().addNotificationListener(objectName, listener, null, null);
notificationListenerMap.put(objectName, listener);
}
});
for (VM memberVM : this.memberVMs) {
memberVM.invoke("checkNotificationHubListenerCount", () -> {
SystemManagementService service = this.managementTestRule.getSystemManagementService();
NotificationHub notificationHub = service.getNotificationHub();
Map<ObjectName, NotificationHubListener> listenerMap = notificationHub.getListenerObjectMap();
assertThat(listenerMap.keySet()).hasSize(1);
ObjectName memberMBeanName = getMemberMBeanName(this.managementTestRule.getDistributedMember());
NotificationHubListener listener = listenerMap.get(memberMBeanName);
/*
* Counter of listener should be 2 . One for default Listener which is added for each member
* mbean by distributed system mbean One for the added listener in test
*/
assertThat(listener.getNumCounter()).isEqualTo(2);
// Raise some notifications
NotificationBroadcasterSupport notifier = (MemberMBean) service.getMemberMXBean();
String memberSource = getMemberNameOrId(this.managementTestRule.getDistributedMember());
// Only a dummy notification , no actual region is created
Notification notification = new Notification(JMXNotificationType.REGION_CREATED, memberSource, SequenceNumber.next(), System.currentTimeMillis(), ManagementConstants.REGION_CREATED_PREFIX + "/test");
notifier.sendNotification(notification);
});
}
this.managerVM.invoke("checkNotificationsAndRemoveListeners", () -> {
await().until(() -> assertThat(notifications).hasSize(3));
notifications.clear();
for (ObjectName objectName : notificationListenerMap.keySet()) {
NotificationListener listener = notificationListenerMap.get(objectName);
getPlatformMBeanServer().removeNotificationListener(objectName, listener);
}
});
for (VM memberVM : this.memberVMs) {
memberVM.invoke("checkNotificationHubListenerCountAgain", () -> {
SystemManagementService service = this.managementTestRule.getSystemManagementService();
NotificationHub hub = service.getNotificationHub();
Map<ObjectName, NotificationHubListener> listenerObjectMap = hub.getListenerObjectMap();
assertThat(listenerObjectMap.keySet().size()).isEqualTo(1);
ObjectName memberMBeanName = getMemberMBeanName(this.managementTestRule.getDistributedMember());
NotificationHubListener listener = listenerObjectMap.get(memberMBeanName);
/*
* Counter of listener should be 1 for the default Listener which is added for each member
* mbean by distributed system mbean.
*/
assertThat(listener.getNumCounter()).isEqualTo(1);
});
}
this.managerVM.invoke("removeListenerFromMemberMXBean", () -> {
ManagementService service = this.managementTestRule.getManagementService();
DistributedSystemMXBean distributedSystemMXBean = service.getDistributedSystemMXBean();
await().until(() -> assertThat(distributedSystemMXBean.listMemberObjectNames()).hasSize(5));
for (ObjectName objectName : distributedSystemMXBean.listMemberObjectNames()) {
NotificationHubTestListener listener = new NotificationHubTestListener();
try {
// because new
getPlatformMBeanServer().removeNotificationListener(objectName, listener);
// instance!!
} catch (ListenerNotFoundException e) {
// TODO: [old] apparently there is never a notification listener on any these mbeans at
// this point [fix this]
// fix this test so it doesn't hit these unexpected exceptions -- getLogWriter().error(e);
}
}
});
for (VM memberVM : this.memberVMs) {
memberVM.invoke("verifyNotificationHubListenersWereRemoved", () -> {
SystemManagementService service = this.managementTestRule.getSystemManagementService();
NotificationHub notificationHub = service.getNotificationHub();
notificationHub.cleanUpListeners();
assertThat(notificationHub.getListenerObjectMap()).isEmpty();
for (ObjectName objectName : notificationListenerMap.keySet()) {
NotificationListener listener = notificationListenerMap.get(objectName);
assertThatThrownBy(() -> getPlatformMBeanServer().removeNotificationListener(objectName, listener)).isExactlyInstanceOf(ListenerNotFoundException.class);
}
});
}
}
use of org.apache.geode.management.internal.SystemManagementService in project geode by apache.
the class CompositeTypeTestDUnitTest method verifyMBeanWithCompositeTypeGetters.
private void verifyMBeanWithCompositeTypeGetters(final VM managerVM, final String memberId) {
managerVM.invoke("verifyMBeanWithCompositeTypeGetters", () -> {
SystemManagementService service = this.managementTestRule.getSystemManagementService();
ObjectName objectName = new ObjectName("GemFire:service=custom,type=composite,member=" + memberId);
await().until(() -> service.getMBeanInstance(objectName, CompositeTestMXBean.class) != null);
CompositeTestMXBean compositeTestMXBean = service.getMBeanInstance(objectName, CompositeTestMXBean.class);
assertThat(compositeTestMXBean).isNotNull();
CompositeStats listCompositeStatsData = compositeTestMXBean.listCompositeStats();
assertThat(listCompositeStatsData).isNotNull();
CompositeStats getCompositeStatsData = compositeTestMXBean.getCompositeStats();
assertThat(getCompositeStatsData).isNotNull();
CompositeStats[] getCompositeArrayData = compositeTestMXBean.getCompositeArray();
assertThat(getCompositeArrayData).isNotNull().isNotEmpty();
Integer[] getIntegerArrayData = compositeTestMXBean.getIntegerArray();
assertThat(getIntegerArrayData).isNotNull().isNotEmpty();
});
}
use of org.apache.geode.management.internal.SystemManagementService in project geode by apache.
the class DLockManagementDUnitTest method verifyProxyCleanupInManager.
private void verifyProxyCleanupInManager(final VM managerVM) {
managerVM.invoke("verifyProxyCleanupInManager", () -> {
Set<DistributedMember> otherMembers = this.managementTestRule.getOtherNormalMembers();
SystemManagementService service = this.managementTestRule.getSystemManagementService();
for (final DistributedMember member : otherMembers) {
ObjectName objectName = service.getRegionMBeanName(member, LOCK_SERVICE_NAME);
await().until(() -> assertThat(lockServiceMXBeanIsGone(service, objectName)).isTrue());
}
});
}
use of org.apache.geode.management.internal.SystemManagementService in project geode by apache.
the class ClientHealthStatsDUnitTest method awaitCacheServerMXBean.
private CacheServerMXBean awaitCacheServerMXBean(final DistributedMember serverMember, final int port) {
SystemManagementService service = this.managementTestRule.getSystemManagementService();
ObjectName objectName = service.getCacheServerMBeanName(port, serverMember);
await().until(() -> assertThat(service.getMBeanProxy(objectName, CacheServerMXBean.class)).isNotNull());
return service.getMBeanProxy(objectName, CacheServerMXBean.class);
}
Aggregations