Search in sources :

Example 76 with SystemManagementService

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;
}
Also used : InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) TimeoutException(java.util.concurrent.TimeoutException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) FunctionException(org.apache.geode.cache.execute.FunctionException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) NetstatFunctionResult(org.apache.geode.management.internal.cli.functions.NetstatFunction.NetstatFunctionResult) MemberMXBean(org.apache.geode.management.MemberMXBean) ObjectName(javax.management.ObjectName) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 77 with SystemManagementService

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);
            }
        });
    }
}
Also used : Notification(javax.management.Notification) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName) NotificationHubListener(org.apache.geode.management.internal.NotificationHub.NotificationHubListener) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) VM(org.apache.geode.test.dunit.VM) MemberMBean(org.apache.geode.management.internal.beans.MemberMBean) ListenerNotFoundException(javax.management.ListenerNotFoundException) NotificationBroadcasterSupport(javax.management.NotificationBroadcasterSupport) NotificationHub(org.apache.geode.management.internal.NotificationHub) NotificationListener(javax.management.NotificationListener) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 78 with SystemManagementService

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();
    });
}
Also used : SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName)

Example 79 with SystemManagementService

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());
        }
    });
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName)

Example 80 with SystemManagementService

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);
}
Also used : SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName)

Aggregations

SystemManagementService (org.apache.geode.management.internal.SystemManagementService)83 ObjectName (javax.management.ObjectName)56 DistributedMember (org.apache.geode.distributed.DistributedMember)31 CacheServerMXBean (org.apache.geode.management.CacheServerMXBean)15 InternalCache (org.apache.geode.internal.cache.InternalCache)14 VM (org.apache.geode.test.dunit.VM)14 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)13 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)12 ExecutionException (java.util.concurrent.ExecutionException)11 CliMetaData (org.apache.geode.management.cli.CliMetaData)11 Result (org.apache.geode.management.cli.Result)11 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)11 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)11 CliCommand (org.springframework.shell.core.annotation.CliCommand)11 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)10 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)8 Test (org.junit.Test)8 GatewaySenderMXBean (org.apache.geode.management.GatewaySenderMXBean)7 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)7 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7