use of org.apache.geode.management.ManagementException 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;
}
use of org.apache.geode.management.ManagementException in project geode by apache.
the class ManagementAdapter method handleRegionRemoval.
/**
* Handles particular region destroy or close operation it will remove the corresponding MBean
*
* @param region
*/
public void handleRegionRemoval(Region region) throws ManagementException {
if (!isServiceInitialised("handleRegionRemoval")) {
return;
}
synchronized (regionOpLock) {
ObjectName regionMBeanName = MBeanJMXAdapter.getRegionMBeanName(internalCache.getDistributedSystem().getDistributedMember(), region.getFullPath());
RegionMBean bean;
try {
bean = (RegionMBean) service.getLocalRegionMBean(region.getFullPath());
} catch (ManagementException e) {
// which does a compensatory close region
if (logger.isDebugEnabled()) {
logger.debug(e.getMessage(), e);
}
return;
}
if (bean != null) {
bean.stopMonitor();
}
service.unregisterMBean(regionMBeanName);
Notification notification = new Notification(JMXNotificationType.REGION_CLOSED, memberSource, SequenceNumber.next(), System.currentTimeMillis(), ManagementConstants.REGION_CLOSED_PREFIX + region.getFullPath());
memberLevelNotifEmitter.sendNotification(notification);
memberMBeanBridge.removeRegion(region);
}
}
use of org.apache.geode.management.ManagementException in project geode by apache.
the class RestAPIsWithSSLDUnitTest method startManager.
private int startManager(final String locators, final String[] regions, final Properties sslProperties) throws IOException {
IgnoredException.addIgnoredException("java.net.BindException");
IgnoredException.addIgnoredException("java.rmi.server.ExportException");
IgnoredException.addIgnoredException("org.apache.geode.management.ManagementException");
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, locators);
props.setProperty(JMX_MANAGER, "true");
props.setProperty(JMX_MANAGER_START, "true");
Cache cache = null;
configureSSL(props, sslProperties, false);
while (true) {
try {
DistributedSystem ds = getSystem(props);
System.out.println("Creating cache with http-service-port " + props.getProperty(HTTP_SERVICE_PORT, "7070") + " and jmx-manager-port " + props.getProperty(JMX_MANAGER_PORT, "1099"));
cache = CacheFactory.create(ds);
System.out.println("Successfully created cache.");
break;
} catch (ManagementException ex) {
if ((ex.getCause() instanceof BindException) || (ex.getCause() != null && ex.getCause().getCause() instanceof BindException)) {
// close cache and disconnect
InternalCache existingInstance = GemFireCacheImpl.getInstance();
if (existingInstance != null) {
existingInstance.close();
}
InternalDistributedSystem ids = InternalDistributedSystem.getConnectedInstance();
if (ids != null) {
ids.disconnect();
}
// try a different port
int httpServicePort = AvailablePortHelper.getRandomAvailableTCPPort();
int jmxManagerPort = AvailablePortHelper.getRandomAvailableTCPPort();
props.setProperty(HTTP_SERVICE_PORT, Integer.toString(httpServicePort));
props.setProperty(JMX_MANAGER_PORT, Integer.toString(jmxManagerPort));
System.out.println("Try a different http-service-port " + httpServicePort);
System.out.println("Try a different jmx-manager-port " + jmxManagerPort);
} else {
throw ex;
}
}
}
AttributesFactory factory = new AttributesFactory();
factory.setEnableBridgeConflation(true);
factory.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes attrs = factory.create();
for (int i = 0; i < regions.length; i++) {
cache.createRegion(regions[i], attrs);
}
CacheServer server = cache.addCacheServer();
server.setPort(0);
server.start();
return server.getPort();
}
use of org.apache.geode.management.ManagementException in project geode by apache.
the class MBeanProxyFactory method updateProxy.
public void updateProxy(ObjectName objectName, ProxyInfo proxyInfo, Object newObject, Object oldObject) {
try {
if (proxyInfo != null) {
Class interfaceClass = proxyInfo.getProxyInterface();
service.afterUpdateProxy(objectName, interfaceClass, proxyInfo.getProxyInstance(), (FederationComponent) newObject, (FederationComponent) oldObject);
}
} catch (Exception e) {
throw new ManagementException(e);
}
}
use of org.apache.geode.management.ManagementException in project geode by apache.
the class MBeanJMXAdapter method registerMBean.
/**
* This method will register an MBean in GemFire domain. Even if the client provides a domain name
* it will be ignored and GemFire domain name will be used.
*
* This method checks the local Filter for registering the MBean. If filtered the MBean wont be
* registered. Although the filter will remember the filtered MBean and register it once the
* filter is removed.
*
* @param object
* @param objectName
* @return modifed ObjectName
*/
public ObjectName registerMBean(Object object, ObjectName objectName, boolean isGemFireMBean) {
ObjectName newObjectName = objectName;
try {
if (!isGemFireMBean) {
String member = getMemberNameOrId(distMember);
String objectKeyProperty = objectName.getKeyPropertyListString();
newObjectName = ObjectName.getInstance(OBJECTNAME__PREFIX + objectKeyProperty + KEYVAL_SEPARATOR + "member=" + member);
}
mbeanServer.registerMBean(object, newObjectName);
this.localGemFireMBean.put(newObjectName, object);
} catch (InstanceAlreadyExistsException e) {
throw new ManagementException(e);
} catch (MBeanRegistrationException e) {
throw new ManagementException(e);
} catch (NotCompliantMBeanException e) {
throw new ManagementException(e);
} catch (MalformedObjectNameException e) {
throw new ManagementException(e);
} catch (NullPointerException e) {
throw new ManagementException(e);
}
return newObjectName;
}
Aggregations