Search in sources :

Example 16 with DistributedSystemMXBean

use of org.apache.geode.management.DistributedSystemMXBean in project geode by apache.

the class AbstractCommandsController method getManagingMemberMXBean.

/**
   * Lookup operation for the MemberMXBean representing the Manager in the GemFire cluster. This
   * method gets an instance fo the Platform MBeanServer for this JVM process and uses it to lookup
   * the MemberMXBean for the GemFire Manager based on the ObjectName declared in the
   * DistributedSystemMXBean.getManagerObjectName() operation.
   * 
   * @return a proxy instance to the MemberMXBean of the GemFire Manager.
   * @see #getMBeanServer()
   * @see #createMemberMXBeanForManagerUsingProxy(javax.management.MBeanServer,
   *      javax.management.ObjectName)
   * @see org.apache.geode.management.DistributedSystemMXBean
   * @see org.apache.geode.management.MemberMXBean
   */
protected synchronized MemberMXBean getManagingMemberMXBean() {
    if (managingMemberMXBeanProxy == null) {
        SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(getCache());
        MBeanServer mbs = getMBeanServer();
        final DistributedSystemMXBean distributedSystemMXBean = JMX.newMXBeanProxy(mbs, MBeanJMXAdapter.getDistributedSystemName(), DistributedSystemMXBean.class);
        managingMemberMXBeanProxy = createMemberMXBeanForManagerUsingProxy(mbs, distributedSystemMXBean.getMemberObjectName());
    }
    return managingMemberMXBeanProxy;
}
Also used : DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) MBeanServer(javax.management.MBeanServer)

Example 17 with DistributedSystemMXBean

use of org.apache.geode.management.DistributedSystemMXBean in project geode by apache.

the class AbstractCommandsController method getMemberObjectName.

protected synchronized ObjectName getMemberObjectName() {
    final MBeanServer platformMBeanServer = getMBeanServer();
    final DistributedSystemMXBean distributedSystemMXBean = JMX.newMXBeanProxy(platformMBeanServer, MBeanJMXAdapter.getDistributedSystemName(), DistributedSystemMXBean.class);
    return distributedSystemMXBean.getMemberObjectName();
}
Also used : DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean) MBeanServer(javax.management.MBeanServer)

Example 18 with DistributedSystemMXBean

use of org.apache.geode.management.DistributedSystemMXBean in project geode by apache.

the class WanCommands method listGateway.

@CliCommand(value = CliStrings.LIST_GATEWAY, help = CliStrings.LIST_GATEWAY__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listGateway(@CliOption(key = CliStrings.LIST_GATEWAY__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.LIST_GATEWAY__MEMBER__HELP) String[] onMember, @CliOption(key = CliStrings.LIST_GATEWAY__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.LIST_GATEWAY__GROUP__HELP) String[] onGroup) {
    Result result = null;
    InternalCache cache = getCache();
    try {
        SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
        Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
        if (dsMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        Map<String, Map<String, GatewaySenderMXBean>> gatewaySenderBeans = new TreeMap<String, Map<String, GatewaySenderMXBean>>();
        Map<String, GatewayReceiverMXBean> gatewayReceiverBeans = new TreeMap<String, GatewayReceiverMXBean>();
        DistributedSystemMXBean dsMXBean = service.getDistributedSystemMXBean();
        for (DistributedMember member : dsMembers) {
            String memberName = member.getName();
            String memberNameOrId = (memberName != null && !memberName.isEmpty()) ? memberName : member.getId();
            ObjectName[] gatewaySenderObjectNames = dsMXBean.listGatewaySenderObjectNames(memberNameOrId);
            // on it
            if (gatewaySenderObjectNames != null) {
                for (ObjectName name : gatewaySenderObjectNames) {
                    GatewaySenderMXBean senderBean = service.getMBeanProxy(name, GatewaySenderMXBean.class);
                    if (senderBean != null) {
                        if (gatewaySenderBeans.containsKey(senderBean.getSenderId())) {
                            Map<String, GatewaySenderMXBean> memberToBeanMap = gatewaySenderBeans.get(senderBean.getSenderId());
                            memberToBeanMap.put(member.getId(), senderBean);
                        } else {
                            Map<String, GatewaySenderMXBean> memberToBeanMap = new TreeMap<String, GatewaySenderMXBean>();
                            memberToBeanMap.put(member.getId(), senderBean);
                            gatewaySenderBeans.put(senderBean.getSenderId(), memberToBeanMap);
                        }
                    }
                }
            }
            // gateway receivers : a member can have only one gateway receiver
            ObjectName gatewayReceiverObjectName = MBeanJMXAdapter.getGatewayReceiverMBeanName(member);
            if (gatewayReceiverObjectName != null) {
                GatewayReceiverMXBean receieverBean = null;
                receieverBean = service.getMBeanProxy(gatewayReceiverObjectName, GatewayReceiverMXBean.class);
                if (receieverBean != null) {
                    gatewayReceiverBeans.put(member.getId(), receieverBean);
                }
            }
        }
        if (gatewaySenderBeans.isEmpty() && gatewayReceiverBeans.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.GATEWAYS_ARE_NOT_AVAILABLE_IN_CLUSTER);
        }
        CompositeResultData crd = ResultBuilder.createCompositeResultData();
        crd.setHeader(CliStrings.HEADER_GATEWAYS);
        accumulateListGatewayResult(crd, gatewaySenderBeans, gatewayReceiverBeans);
        result = ResultBuilder.buildResult(crd);
    } catch (Exception e) {
        LogWrapper.getInstance().warning(CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
        result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR + e.getMessage());
    }
    return result;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) TreeMap(java.util.TreeMap) GatewaySenderMXBean(org.apache.geode.management.GatewaySenderMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ExecutionException(java.util.concurrent.ExecutionException) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) ObjectName(javax.management.ObjectName) GatewayReceiverMXBean(org.apache.geode.management.GatewayReceiverMXBean) DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean) DistributedMember(org.apache.geode.distributed.DistributedMember) Map(java.util.Map) TreeMap(java.util.TreeMap) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 19 with DistributedSystemMXBean

use of org.apache.geode.management.DistributedSystemMXBean 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);
}
Also used : DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ManagementService(org.apache.geode.management.ManagementService) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Cache(org.apache.geode.cache.Cache)

Example 20 with DistributedSystemMXBean

use of org.apache.geode.management.DistributedSystemMXBean 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?
    });
}
Also used : DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean) DistributedMember(org.apache.geode.distributed.DistributedMember) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) MemberMXBean(org.apache.geode.management.MemberMXBean) ObjectName(javax.management.ObjectName) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

DistributedSystemMXBean (org.apache.geode.management.DistributedSystemMXBean)22 ManagementService (org.apache.geode.management.ManagementService)15 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)8 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)5 ObjectName (javax.management.ObjectName)4 DistributedMember (org.apache.geode.distributed.DistributedMember)4 InternalCache (org.apache.geode.internal.cache.InternalCache)3 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Entry (java.util.Map.Entry)2 MBeanServer (javax.management.MBeanServer)2 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2 DistributedRegionMXBean (org.apache.geode.management.DistributedRegionMXBean)2 ConverterHint (org.apache.geode.management.cli.ConverterHint)2 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)2 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1