Search in sources :

Example 1 with MBeanJMXAdapter

use of org.apache.geode.management.internal.MBeanJMXAdapter in project geode by apache.

the class ManagementAdapter method handleManagerStart.

/**
   * Handles all the distributed mbean creation part when a Manager is started
   */
public void handleManagerStart() throws ManagementException {
    if (!isServiceInitialised("handleManagerStart")) {
        return;
    }
    MBeanJMXAdapter jmxAdapter = service.getJMXAdapter();
    Map<ObjectName, Object> registeredMBeans = jmxAdapter.getLocalGemFireMBean();
    DistributedSystemBridge dsBridge = new DistributedSystemBridge(service);
    this.aggregator = new MBeanAggregator(dsBridge);
    // register the aggregator for Federation framework to use
    service.addProxyListener(aggregator);
    /*
     * get the local member mbean as it need to be provided to aggregator first
     */
    MemberMXBean localMember = service.getMemberMXBean();
    ObjectName memberObjectName = MBeanJMXAdapter.getMemberMBeanName(InternalDistributedSystem.getConnectedInstance().getDistributedMember());
    FederationComponent addedComp = service.getLocalManager().getFedComponents().get(memberObjectName);
    service.afterCreateProxy(memberObjectName, MemberMXBean.class, localMember, addedComp);
    for (ObjectName objectName : registeredMBeans.keySet()) {
        if (objectName.equals(memberObjectName)) {
            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 newObj = service.getLocalManager().getFedComponents().get(objectName);
            for (Type intfTyp1 : intfTyps) {
                Class intfTyp = (Class) intfTyp1;
                service.afterCreateProxy(objectName, intfTyp, object, newObj);
            }
        } catch (InstanceNotFoundException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed in Registering distributed mbean ");
            }
            throw new ManagementException(e);
        } catch (ClassNotFoundException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed in Registering distributed mbean");
            }
            throw new ManagementException(e);
        }
    }
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName) MemberMXBean(org.apache.geode.management.MemberMXBean) Type(java.lang.reflect.Type) JMXNotificationType(org.apache.geode.management.JMXNotificationType) ManagementException(org.apache.geode.management.ManagementException) MBeanJMXAdapter(org.apache.geode.management.internal.MBeanJMXAdapter) FederationComponent(org.apache.geode.management.internal.FederationComponent)

Example 2 with MBeanJMXAdapter

use of org.apache.geode.management.internal.MBeanJMXAdapter in project geode by apache.

the class MBeanSecurityJUnitTest method testLocalCalls.

/**
   * These calls does not go through the MBeanServerWrapper authentication, therefore is not
   * throwing the SecurityExceptions
   */
@Test
public void testLocalCalls() throws Exception {
    MBeanServer server = MBeanJMXAdapter.mbeanServer;
    assertThatThrownBy(() -> server.createMBean("FakeClassName", new ObjectName("GemFire", "name", "foo"))).isInstanceOf(ReflectionException.class);
    MBeanJMXAdapter adapter = new MBeanJMXAdapter();
    assertThatThrownBy(() -> adapter.registerMBean(mock(DynamicMBean.class), new ObjectName("MockDomain", "name", "mock"), false)).isInstanceOf(ManagementException.class);
}
Also used : DynamicMBean(javax.management.DynamicMBean) MBeanJMXAdapter(org.apache.geode.management.internal.MBeanJMXAdapter) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with MBeanJMXAdapter

use of org.apache.geode.management.internal.MBeanJMXAdapter 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)

Aggregations

ObjectName (javax.management.ObjectName)3 MBeanJMXAdapter (org.apache.geode.management.internal.MBeanJMXAdapter)3 Type (java.lang.reflect.Type)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 ObjectInstance (javax.management.ObjectInstance)2 JMXNotificationType (org.apache.geode.management.JMXNotificationType)2 ManagementException (org.apache.geode.management.ManagementException)2 MemberMXBean (org.apache.geode.management.MemberMXBean)2 FederationComponent (org.apache.geode.management.internal.FederationComponent)2 DynamicMBean (javax.management.DynamicMBean)1 MBeanServer (javax.management.MBeanServer)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)1 Test (org.junit.Test)1