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