Search in sources :

Example 21 with ManagementException

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

the class MBeanProxyFactory method createProxy.

/**
   * Creates a single proxy and adds a {@link ProxyInfo} to proxy repository
   * {@link MBeanProxyInfoRepository}
   * 
   * @param member {@link org.apache.geode.distributed.DistributedMember}
   * @param objectName {@link javax.management.ObjectName} of the Bean
   * @param monitoringRegion monitoring region containing the proxies
   * @throws ManagementException
   */
public void createProxy(DistributedMember member, ObjectName objectName, Region<String, Object> monitoringRegion, Object newVal) {
    try {
        if (remoteFilterChain.isFiltered(objectName, member, "")) {
            if (logger.isTraceEnabled()) {
                logger.trace("Returning from filter");
            }
            return;
        }
        Class interfaceClass = ClassLoadUtil.classFromName(((FederationComponent) monitoringRegion.get(objectName.toString())).getMBeanInterfaceClass());
        Object object = MBeanProxyInvocationHandler.newProxyInstance(member, monitoringRegion, objectName, interfaceClass);
        jmxAdapter.registerMBeanProxy(object, objectName);
        if (logger.isDebugEnabled()) {
            logger.debug("Registered ObjectName : {}", objectName);
        }
        ProxyInfo proxyInfo = new ProxyInfo(interfaceClass, object, objectName);
        proxyRepo.addProxyToRepository(member, proxyInfo);
        service.afterCreateProxy(objectName, interfaceClass, object, (FederationComponent) newVal);
        if (logger.isDebugEnabled()) {
            logger.debug("Proxy Created for : {}", objectName);
        }
    } catch (ClassNotFoundException e) {
        throw new ManagementException(e);
    } catch (IntrospectionException e) {
        throw new ManagementException(e);
    } catch (ManagementException e) {
        throw e;
    }
}
Also used : ManagementException(org.apache.geode.management.ManagementException) IntrospectionException(java.beans.IntrospectionException)

Example 22 with ManagementException

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

the class LocalManager method startLocalManagement.

/**
   * Managed Node side resources are created
   * 
   * Management Region : its a Replicated NO_ACK region Notification Region : its a Replicated Proxy
   * NO_ACK region
   */
private void startLocalManagement(Map<ObjectName, FederationComponent> federatedComponentMap) {
    synchronized (this) {
        if (repo.getLocalMonitoringRegion() != null) {
            return;
        } else {
            ThreadFactory tf = new ThreadFactory() {

                public Thread newThread(final Runnable command) {
                    final Runnable r = new Runnable() {

                        public void run() {
                            command.run();
                        }
                    };
                    final ThreadGroup group = LoggingThreadGroup.createThreadGroup(ManagementStrings.MANAGEMENT_TASK_THREAD_GROUP.toLocalizedString(), logger);
                    Thread thread = new Thread(group, r, ManagementStrings.MANAGEMENT_TASK.toLocalizedString());
                    thread.setDaemon(true);
                    return thread;
                }
            };
            singleThreadFederationScheduler = Executors.newSingleThreadScheduledExecutor(tf);
            if (logger.isDebugEnabled()) {
                logger.debug("Creating  Management Region :");
            }
            /*
         * Sharing the same Internal Argument for both notification region and monitoring region
         */
            InternalRegionArguments internalArgs = new InternalRegionArguments();
            internalArgs.setIsUsedForMetaRegion(true);
            // Create anonymous stats holder for Management Regions
            final HasCachePerfStats monitoringRegionStats = new HasCachePerfStats() {

                public CachePerfStats getCachePerfStats() {
                    return new CachePerfStats(cache.getDistributedSystem(), "managementRegionStats");
                }
            };
            internalArgs.setCachePerfStatsHolder(monitoringRegionStats);
            AttributesFactory<String, Object> monitorRegionAttributeFactory = new AttributesFactory<String, Object>();
            monitorRegionAttributeFactory.setScope(Scope.DISTRIBUTED_NO_ACK);
            monitorRegionAttributeFactory.setDataPolicy(DataPolicy.REPLICATE);
            monitorRegionAttributeFactory.setConcurrencyChecksEnabled(false);
            MonitoringRegionCacheListener localListener = new MonitoringRegionCacheListener(service);
            monitorRegionAttributeFactory.addCacheListener(localListener);
            RegionAttributes<String, Object> monitoringRegionAttrs = monitorRegionAttributeFactory.create();
            AttributesFactory<NotificationKey, Notification> notificationRegionAttributeFactory = new AttributesFactory<NotificationKey, Notification>();
            notificationRegionAttributeFactory.setScope(Scope.DISTRIBUTED_NO_ACK);
            notificationRegionAttributeFactory.setDataPolicy(DataPolicy.EMPTY);
            notificationRegionAttributeFactory.setConcurrencyChecksEnabled(false);
            RegionAttributes<NotificationKey, Notification> notifRegionAttrs = notificationRegionAttributeFactory.create();
            String appender = MBeanJMXAdapter.getUniqueIDForMember(cache.getDistributedSystem().getDistributedMember());
            boolean monitoringRegionCreated = false;
            boolean notifRegionCreated = false;
            try {
                repo.setLocalMonitoringRegion(cache.createVMRegion(ManagementConstants.MONITORING_REGION + "_" + appender, monitoringRegionAttrs, internalArgs));
                monitoringRegionCreated = true;
            } catch (TimeoutException e) {
                throw new ManagementException(e);
            } catch (RegionExistsException e) {
                throw new ManagementException(e);
            } catch (IOException e) {
                throw new ManagementException(e);
            } catch (ClassNotFoundException e) {
                throw new ManagementException(e);
            }
            try {
                repo.setLocalNotificationRegion(cache.createVMRegion(ManagementConstants.NOTIFICATION_REGION + "_" + appender, notifRegionAttrs, internalArgs));
                notifRegionCreated = true;
            } catch (TimeoutException e) {
                throw new ManagementException(e);
            } catch (RegionExistsException e) {
                throw new ManagementException(e);
            } catch (IOException e) {
                throw new ManagementException(e);
            } catch (ClassNotFoundException e) {
                throw new ManagementException(e);
            } finally {
                if (!notifRegionCreated && monitoringRegionCreated) {
                    repo.getLocalMonitoringRegion().localDestroyRegion();
                }
            }
            managementTask = new ManagementTask(federatedComponentMap);
            // call run to get us initialized immediately with a sync call
            managementTask.run();
            // All local resources are created for the ManagementTask
            // Now Management tasks can proceed.
            int updateRate = cache.getInternalDistributedSystem().getConfig().getJmxManagerUpdateRate();
            singleThreadFederationScheduler.scheduleAtFixedRate(managementTask, updateRate, updateRate, TimeUnit.MILLISECONDS);
            if (logger.isDebugEnabled()) {
                logger.debug("Management Region created with Name : {}", repo.getLocalMonitoringRegion().getName());
                logger.debug("Notification Region created with Name : {}", repo.getLocalNotificationRegion().getName());
            }
        }
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) RegionExistsException(org.apache.geode.cache.RegionExistsException) Notification(javax.management.Notification) ManagementException(org.apache.geode.management.ManagementException) AttributesFactory(org.apache.geode.cache.AttributesFactory) HasCachePerfStats(org.apache.geode.internal.cache.HasCachePerfStats) LoggingThreadGroup(org.apache.geode.internal.logging.LoggingThreadGroup) TimeoutException(org.apache.geode.cache.TimeoutException) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) HasCachePerfStats(org.apache.geode.internal.cache.HasCachePerfStats) IOException(java.io.IOException)

Example 23 with ManagementException

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

the class FederatingManager method startManagingActivity.

/**
   * This method will be invoked when a node transitions from managed node to managing node This
   * method will block for all GIIs to be completed But each GII is given a specific time frame.
   * After that the task will be marked as cancelled.
   */
public void startManagingActivity() throws Exception {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    Set<DistributedMember> members = cache.getDistributionManager().getOtherDistributionManagerIds();
    Iterator<DistributedMember> it = members.iterator();
    DistributedMember member;
    final List<Callable<DistributedMember>> giiTaskList = new ArrayList<>();
    List<Future<DistributedMember>> futureTaskList;
    while (it.hasNext()) {
        member = it.next();
        giiTaskList.add(new GIITask(member));
    }
    try {
        if (isDebugEnabled) {
            logger.debug("Management Resource creation started  : ");
        }
        futureTaskList = pooledMembershipExecutor.invokeAll(giiTaskList);
        for (Future<DistributedMember> futureTask : futureTaskList) {
            String memberId = null;
            try {
                DistributedMember returnedMember = futureTask.get();
                if (returnedMember != null) {
                    memberId = returnedMember.getId();
                }
                if (futureTask.isDone()) {
                    if (isDebugEnabled) {
                        logger.debug("Monitoring Resource Created for : {}", memberId);
                    }
                }
                if (futureTask.isCancelled()) {
                    // Retry mechanism can be added here after discussions
                    if (isDebugEnabled) {
                        logger.debug("Monitoring resource Creation Failed for : {}", memberId);
                    }
                }
            } catch (ExecutionException e) {
                if (isDebugEnabled) {
                    logger.debug("ExecutionException during Management GII: {}", e.getMessage(), e);
                }
            } catch (CancellationException e) {
                if (isDebugEnabled) {
                    ManagementException mgEx = new ManagementException(e.fillInStackTrace());
                    logger.debug("InterruptedException while creating Monitoring resource with error : {}", mgEx.getMessage(), mgEx);
                }
            }
        }
    } catch (InterruptedException e) {
        if (isDebugEnabled) {
            ManagementException mgEx = new ManagementException(e.fillInStackTrace());
            logger.debug("InterruptedException while creating Monitoring resource with error : ", mgEx.getMessage(), mgEx);
        }
    } finally {
        if (isDebugEnabled) {
            logger.debug("Management Resource creation completed");
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) ManagementException(org.apache.geode.management.ManagementException) CancellationException(java.util.concurrent.CancellationException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) Future(java.util.concurrent.Future) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 24 with ManagementException

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

the class FederatingManager method stopManagingActivity.

/**
   * This method will be invoked whenever a member stops being a managing node. The exception
   * Management exception has to be handled by the caller. *
   */
private void stopManagingActivity() {
    try {
        this.pooledMembershipExecutor.shutdownNow();
        Iterator<DistributedMember> it = repo.getMonitoringRegionMap().keySet().iterator();
        while (it.hasNext()) {
            removeMemberArtifacts(it.next(), false);
        }
    } catch (Exception e) {
        throw new ManagementException(e);
    }
}
Also used : ManagementException(org.apache.geode.management.ManagementException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) RegionExistsException(org.apache.geode.cache.RegionExistsException) TimeoutException(org.apache.geode.cache.TimeoutException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ManagementException(org.apache.geode.management.ManagementException) ExecutionException(java.util.concurrent.ExecutionException)

Example 25 with ManagementException

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

the class NotificationHub method addHubNotificationListener.

/**
   * Adds a NotificationHubListener
   * 
   * @param objectName
   */
public void addHubNotificationListener(String memberName, ObjectName objectName) {
    try {
        synchronized (listenerObjectMap) {
            NotificationHubListener listener = listenerObjectMap.get(objectName);
            if (listener == null) {
                listener = new NotificationHubListener(objectName);
                listener.incNumCounter();
                mbeanServer.addNotificationListener(objectName, listener, null, null);
                listenerObjectMap.put(objectName, listener);
            } else {
                listener.incNumCounter();
            }
        }
    } catch (InstanceNotFoundException e) {
        throw new ManagementException(e);
    }
}
Also used : ManagementException(org.apache.geode.management.ManagementException) InstanceNotFoundException(javax.management.InstanceNotFoundException)

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