Search in sources :

Example 16 with ManagementException

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;
}
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 17 with ManagementException

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

Example 18 with ManagementException

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();
}
Also used : ManagementException(org.apache.geode.management.ManagementException) AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) BindException(java.net.BindException) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServer(org.apache.geode.cache.server.CacheServer) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 19 with ManagementException

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);
    }
}
Also used : ManagementException(org.apache.geode.management.ManagementException) ManagementException(org.apache.geode.management.ManagementException) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(java.beans.IntrospectionException)

Example 20 with ManagementException

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;
}
Also used : ManagementException(org.apache.geode.management.ManagementException) MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Aggregations

ManagementException (org.apache.geode.management.ManagementException)26 IOException (java.io.IOException)8 ObjectName (javax.management.ObjectName)8 InstanceNotFoundException (javax.management.InstanceNotFoundException)6 MalformedObjectNameException (javax.management.MalformedObjectNameException)5 Notification (javax.management.Notification)4 InternalCache (org.apache.geode.internal.cache.InternalCache)4 IntrospectionException (java.beans.IntrospectionException)3 Type (java.lang.reflect.Type)3 CancellationException (java.util.concurrent.CancellationException)3 ExecutionException (java.util.concurrent.ExecutionException)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)3 MBeanRegistrationException (javax.management.MBeanRegistrationException)3 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)3 ObjectInstance (javax.management.ObjectInstance)3 RegionExistsException (org.apache.geode.cache.RegionExistsException)3 TimeoutException (org.apache.geode.cache.TimeoutException)3 DistributedMember (org.apache.geode.distributed.DistributedMember)3 BytesToString (org.apache.geode.management.internal.cli.util.BytesToString)3