Search in sources :

Example 11 with ManagementException

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

the class MemberMBeanBridge method backupMember.

/**
   * backs up all the disk to the targeted directory
   * 
   * @param targetDirPath path of the directory where back up is to be taken
   * @return array of DiskBackup results which might get aggregated at Managing node Check the
   *         validity of this mbean call. When does it make sense to backup a single member of a
   *         gemfire system in isolation of the other members?
   */
public DiskBackupResult[] backupMember(String targetDirPath) {
    if (cache != null) {
        Collection<DiskStore> diskStores = cache.listDiskStoresIncludingRegionOwned();
        for (DiskStore store : diskStores) {
            store.flush();
        }
    }
    DiskBackupResult[] diskBackUpResult = null;
    File targetDir = new File(targetDirPath);
    if (cache == null) {
        return null;
    } else {
        try {
            BackupManager manager = cache.startBackup(cache.getInternalDistributedSystem().getDistributedMember());
            boolean abort = true;
            Set<PersistentID> existingDataStores;
            Set<PersistentID> successfulDataStores;
            try {
                existingDataStores = manager.prepareBackup();
                abort = false;
            } finally {
                successfulDataStores = manager.finishBackup(targetDir, null, /* TODO rishi */
                abort);
            }
            diskBackUpResult = new DiskBackupResult[existingDataStores.size()];
            int j = 0;
            for (PersistentID id : existingDataStores) {
                if (successfulDataStores.contains(id)) {
                    diskBackUpResult[j] = new DiskBackupResult(id.getDirectory(), false);
                } else {
                    diskBackUpResult[j] = new DiskBackupResult(id.getDirectory(), true);
                }
                j++;
            }
        } catch (IOException e) {
            throw new ManagementException(e);
        }
    }
    return diskBackUpResult;
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) DiskBackupResult(org.apache.geode.management.DiskBackupResult) ManagementException(org.apache.geode.management.ManagementException) IOException(java.io.IOException) File(java.io.File) BackupManager(org.apache.geode.internal.cache.persistence.BackupManager) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Example 12 with ManagementException

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

the class ManagementAdapter method handleAsyncEventQueueRemoval.

/**
   * Handles AsyncEventQueue Removal
   *
   * @param queue The AsyncEventQueue being removed
   */
public void handleAsyncEventQueueRemoval(AsyncEventQueue queue) throws ManagementException {
    if (!isServiceInitialised("handleAsyncEventQueueRemoval")) {
        return;
    }
    ObjectName asycnEventQueueMBeanName = MBeanJMXAdapter.getAsycnEventQueueMBeanName(internalCache.getDistributedSystem().getDistributedMember(), queue.getId());
    AsyncEventQueueMBean bean;
    try {
        bean = (AsyncEventQueueMBean) service.getLocalAsyncEventQueueMXBean(queue.getId());
        if (bean == null) {
            return;
        }
    } catch (ManagementException e) {
        // If no bean found its a NO-OP
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        return;
    }
    bean.stopMonitor();
    service.unregisterMBean(asycnEventQueueMBeanName);
    Notification notification = new Notification(JMXNotificationType.ASYNC_EVENT_QUEUE_CLOSED, memberSource, SequenceNumber.next(), System.currentTimeMillis(), ManagementConstants.ASYNC_EVENT_QUEUE_CLOSED_PREFIX + queue.getId());
    memberLevelNotifEmitter.sendNotification(notification);
}
Also used : ManagementException(org.apache.geode.management.ManagementException) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName)

Example 13 with ManagementException

use of org.apache.geode.management.ManagementException 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 14 with ManagementException

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

the class SizeExportLogsFunction method execute.

@Override
public void execute(final FunctionContext context) {
    try {
        InternalCache cache = GemFireCacheImpl.getInstance();
        DistributionConfig config = cache.getInternalDistributedSystem().getConfig();
        Args args = (Args) context.getArguments();
        long diskAvailable = getDiskAvailable(config);
        long estimatedSize = estimateLogFileSize(cache.getMyId(), config.getLogFile(), config.getStatisticArchiveFile(), args);
        BytesToString bytesToString = new BytesToString();
        if (estimatedSize == 0 || estimatedSize < diskAvailable) {
            context.getResultSender().lastResult(Arrays.asList(estimatedSize));
        } else {
            StringBuilder sb = new StringBuilder().append("Estimated disk space required (").append(bytesToString.of(estimatedSize)).append(") to consolidate logs on member ").append(cache.getName()).append(" will exceed available disk space (").append(bytesToString.of(diskAvailable)).append(")");
            // FileTooBigException
            context.getResultSender().sendException(new ManagementException(sb.toString()));
        }
    } catch (Exception e) {
        e.printStackTrace();
        LOGGER.error(e.getMessage());
        context.getResultSender().sendException(e);
    }
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) ManagementException(org.apache.geode.management.ManagementException) InternalCache(org.apache.geode.internal.cache.InternalCache) IOException(java.io.IOException) ManagementException(org.apache.geode.management.ManagementException) BytesToString(org.apache.geode.management.internal.cli.util.BytesToString)

Example 15 with ManagementException

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

the class ManagementAdapter method handleDiskRemoval.

/**
   * Handles DiskStore Removal
   * 
   * @param disk
   */
public void handleDiskRemoval(DiskStore disk) throws ManagementException {
    if (!isServiceInitialised("handleDiskRemoval")) {
        return;
    }
    ObjectName diskStoreMBeanName = MBeanJMXAdapter.getDiskStoreMBeanName(internalCache.getDistributedSystem().getDistributedMember(), disk.getName());
    DiskStoreMBean bean;
    try {
        bean = (DiskStoreMBean) service.getLocalDiskStoreMBean(disk.getName());
        if (bean == null) {
            return;
        }
    } catch (ManagementException e) {
        // If no bean found its a NO-OP
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        return;
    }
    bean.stopMonitor();
    service.unregisterMBean(diskStoreMBeanName);
    Notification notification = new Notification(JMXNotificationType.DISK_STORE_CLOSED, memberSource, SequenceNumber.next(), System.currentTimeMillis(), ManagementConstants.DISK_STORE_CLOSED_PREFIX + disk.getName());
    memberLevelNotifEmitter.sendNotification(notification);
    memberMBeanBridge.removeDiskStore(disk);
}
Also used : ManagementException(org.apache.geode.management.ManagementException) Notification(javax.management.Notification) 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