Search in sources :

Example 21 with MemberMXBean

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;
}
Also used : ArrayList(java.util.ArrayList) MemberMXBean(org.apache.geode.management.MemberMXBean)

Example 22 with MemberMXBean

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());
    }
}
Also used : ArrayList(java.util.ArrayList) ManagementException(org.apache.geode.management.ManagementException) ListenerNotFoundException(javax.management.ListenerNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectName(javax.management.ObjectName) MemberMXBean(org.apache.geode.management.MemberMXBean)

Example 23 with MemberMXBean

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

Example 24 with MemberMXBean

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())));
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) MemberMXBean(org.apache.geode.management.MemberMXBean) MXBeanProvider.getMemberMXBean(org.apache.geode.management.internal.cli.shell.MXBeanProvider.getMemberMXBean) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 25 with MemberMXBean

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?
    });
}
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

MemberMXBean (org.apache.geode.management.MemberMXBean)25 ObjectName (javax.management.ObjectName)9 Test (org.junit.Test)6 CliMetaData (org.apache.geode.management.cli.CliMetaData)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 CliCommand (org.springframework.shell.core.annotation.CliCommand)5 InstanceNotFoundException (javax.management.InstanceNotFoundException)4 CacheFactory (org.apache.geode.cache.CacheFactory)4 ManagementException (org.apache.geode.management.ManagementException)4 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)4 MXBeanProvider.getMemberMXBean (org.apache.geode.management.internal.cli.shell.MXBeanProvider.getMemberMXBean)4 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 ManagementService (org.apache.geode.management.ManagementService)3 Type (java.lang.reflect.Type)2 ListenerNotFoundException (javax.management.ListenerNotFoundException)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 ObjectInstance (javax.management.ObjectInstance)2 DistributedMember (org.apache.geode.distributed.DistributedMember)2 LocatorLauncher (org.apache.geode.distributed.LocatorLauncher)2