Search in sources :

Example 16 with MemberMXBean

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

the class MBeanSecurityJUnitTest method testServerSideCalls.

@Test
@ConnectionConfiguration(user = "stranger", password = "1234567")
public void testServerSideCalls() {
    // calls through ManagementService is not going through authorization checks
    ManagementService service = ManagementService.getManagementService(server.getCache());
    MemberMXBean bean = service.getMemberMXBean();
    bean.compactAllDiskStores();
}
Also used : ManagementService(org.apache.geode.management.ManagementService) MemberMXBean(org.apache.geode.management.MemberMXBean) ConnectionConfiguration(org.apache.geode.test.dunit.rules.ConnectionConfiguration) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 17 with MemberMXBean

use of org.apache.geode.management.MemberMXBean 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 18 with MemberMXBean

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

the class ManagementAdapter method handleManagerStop.

/**
   * Handles all the clean up activities when a Manager is stopped It clears the distributed mbeans
   * and underlying data structures
   */
public void handleManagerStop() throws ManagementException {
    if (!isServiceInitialised("handleManagerStop")) {
        return;
    }
    MBeanJMXAdapter jmxAdapter = service.getJMXAdapter();
    Map<ObjectName, Object> registeredMBeans = jmxAdapter.getLocalGemFireMBean();
    ObjectName aggregatemMBeanPattern;
    try {
        aggregatemMBeanPattern = new ObjectName(ManagementConstants.AGGREGATE_MBEAN_PATTERN);
    } catch (MalformedObjectNameException | NullPointerException e1) {
        throw new ManagementException(e1);
    }
    MemberMXBean localMember = service.getMemberMXBean();
    ObjectName memberObjectName = MBeanJMXAdapter.getMemberMBeanName(InternalDistributedSystem.getConnectedInstance().getDistributedMember());
    FederationComponent removedComp = service.getLocalManager().getFedComponents().get(memberObjectName);
    service.afterRemoveProxy(memberObjectName, MemberMXBean.class, localMember, removedComp);
    for (ObjectName objectName : registeredMBeans.keySet()) {
        if (objectName.equals(memberObjectName)) {
            continue;
        }
        if (aggregatemMBeanPattern.apply(objectName)) {
            continue;
        }
        Object object = registeredMBeans.get(objectName);
        ObjectInstance instance;
        try {
            instance = mbeanServer.getObjectInstance(objectName);
            String className = instance.getClassName();
            Class cls = ClassLoadUtil.classFromName(className);
            Type[] intfTyps = cls.getGenericInterfaces();
            FederationComponent oldObj = service.getLocalManager().getFedComponents().get(objectName);
            for (Type intfTyp1 : intfTyps) {
                Class intfTyp = (Class) intfTyp1;
                service.afterRemoveProxy(objectName, intfTyp, object, oldObj);
            }
        } catch (InstanceNotFoundException | ClassNotFoundException e) {
            logger.warn("Failed to invoke aggregator for {} with exception {}", objectName, e.getMessage(), e);
        }
    }
    service.removeProxyListener(this.aggregator);
    this.aggregator = null;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName) MemberMXBean(org.apache.geode.management.MemberMXBean) ManagementException(org.apache.geode.management.ManagementException) Type(java.lang.reflect.Type) JMXNotificationType(org.apache.geode.management.JMXNotificationType) MBeanJMXAdapter(org.apache.geode.management.internal.MBeanJMXAdapter) FederationComponent(org.apache.geode.management.internal.FederationComponent)

Example 19 with MemberMXBean

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

the class DistributedSystemBridge method showNetworkMetric.

public NetworkMetrics showNetworkMetric(String member) throws Exception {
    MemberMXBean bean = validateMember(member);
    NetworkMetrics nm = new NetworkMetrics();
    nm.setBytesReceivedRate(bean.getBytesReceivedRate());
    nm.setBytesSentRate(bean.getBytesSentRate());
    return nm;
}
Also used : NetworkMetrics(org.apache.geode.management.NetworkMetrics) MemberMXBean(org.apache.geode.management.MemberMXBean)

Example 20 with MemberMXBean

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

the class DistributedSystemBridge method listServers.

/**
   * @return list of members hosting servers, which are started from GFSH
   */
public String[] listServers() {
    Iterator<MemberMXBean> memberIterator = mapOfMembers.values().iterator();
    if (memberIterator != null) {
        List<String> listOfServer = new ArrayList<>();
        while (memberIterator.hasNext()) {
            MemberMXBean bean = memberIterator.next();
            if (bean.isServer()) {
                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)

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