Search in sources :

Example 1 with RuntimeAdminException

use of org.apache.geode.admin.RuntimeAdminException in project geode by apache.

the class MBeanUtil method ensureMBeanIsRegistered.

/**
   * Ensures that an MBean is registered for the specified <code>ManagedResource</code>. If an MBean
   * cannot be found in the <code>MBeanServer</code>, then this creates and registers a
   * <code>ModelMBean</code>. State changing callbacks into the <code>ManagedResource</code> will
   * also be made.
   *
   * @param resource the ManagedResource to create a managing MBean for
   *
   * @return The object name of the MBean that manages the ManagedResource
   *
   * @see ManagedResource#setModelMBean
   */
static ObjectName ensureMBeanIsRegistered(ManagedResource resource) {
    try {
        ObjectName objName = ObjectName.getInstance(resource.getMBeanName());
        synchronized (MBeanUtil.class) {
            if (mbeanServer != null && !mbeanServer.isRegistered(objName)) {
                return createMBean(resource);
            }
        }
        raiseOnFailure(mbeanServer.isRegistered(objName), LocalizedStrings.MBeanUtil_COULDNT_FIND_MBEAN_REGISTERED_WITH_OBJECTNAME_0.toLocalizedString(new Object[] { objName.toString() }));
        return objName;
    } catch (java.lang.Exception e) {
        throw new RuntimeAdminException(e);
    }
}
Also used : RuntimeAdminException(org.apache.geode.admin.RuntimeAdminException) ObjectName(javax.management.ObjectName)

Example 2 with RuntimeAdminException

use of org.apache.geode.admin.RuntimeAdminException in project geode by apache.

the class MBeanUtil method createRegistry.

/**
   * Create and configure (if necessary) and return the Commons-Modeler registry of managed object
   * descriptions.
   *
   * @see org.apache.commons.modeler.Registry
   */
static synchronized Registry createRegistry() {
    if (registry == null) {
        try {
            registry = Registry.getRegistry(null, null);
            if (mbeanServer == null) {
                throw new IllegalStateException(LocalizedStrings.MBeanUtil_MBEAN_SERVER_NOT_INITIALIZED_YET.toLocalizedString());
            }
            registry.setMBeanServer(mbeanServer);
            String mbeansResource = getOSPath("/org/apache/geode/admin/jmx/mbeans-descriptors.xml");
            // System.out.println(LocalizedStrings.MBeanUtil_LOADING_RESOURCE_0.toLocalizedString(mbeansResource));
            URL url = ClassPathLoader.getLatest().getResource(MBeanUtil.class, mbeansResource);
            raiseOnFailure(url != null, LocalizedStrings.MBeanUtil_FAILED_TO_FIND_0.toLocalizedString(new Object[] { mbeansResource }));
            registry.loadMetadata(url);
            // simple test to make sure the xml was actually loaded and is valid...
            String[] test = registry.findManagedBeans();
            raiseOnFailure(test != null && test.length > 0, LocalizedStrings.MBeanUtil_FAILED_TO_LOAD_0.toLocalizedString(new Object[] { mbeansResource }));
        } catch (Exception e) {
            logStackTrace(Level.WARN, e);
            throw new RuntimeAdminException(LocalizedStrings.MBeanUtil_FAILED_TO_GET_MBEAN_REGISTRY.toLocalizedString(), e);
        }
    }
    return registry;
}
Also used : RuntimeAdminException(org.apache.geode.admin.RuntimeAdminException) URL(java.net.URL) RuntimeAdminException(org.apache.geode.admin.RuntimeAdminException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) JMRuntimeException(javax.management.JMRuntimeException) MalformedObjectNameException(javax.management.MalformedObjectNameException) JMException(javax.management.JMException) ListenerNotFoundException(javax.management.ListenerNotFoundException)

Example 3 with RuntimeAdminException

use of org.apache.geode.admin.RuntimeAdminException in project geode by apache.

the class MBeanUtil method createMBean.

/**
   * Creates and registers a <code>ModelMBean</code> for the specified <code>ManagedResource</code>.
   * State changing callbacks into the <code>ManagedResource</code> will also be made.
   *
   * @param resource the ManagedResource to create a managing MBean for
   * @param managed the ManagedBean definition to create the MBean with
   * @see ManagedResource#setModelMBean
   */
static ObjectName createMBean(ManagedResource resource, ManagedBean managed) {
    try {
        DynamicManagedBean mb = new DynamicManagedBean(managed);
        resource.setModelMBean(mb.createMBean(resource));
        // create the ObjectName and register the MBean...
        final ObjectName objName;
        try {
            objName = ObjectName.getInstance(resource.getMBeanName());
        } catch (MalformedObjectNameException e) {
            throw new MalformedObjectNameException(LocalizedStrings.MBeanUtil_0_IN_1.toLocalizedString(new Object[] { e.getMessage(), resource.getMBeanName() }));
        }
        synchronized (MBeanUtil.class) {
            if (mbeanServer != null && !mbeanServer.isRegistered(objName)) {
                mbeanServer.registerMBean(resource.getModelMBean(), objName);
                synchronized (managedResources) {
                    managedResources.put(objName, resource);
                }
            }
        }
        return objName;
    } catch (java.lang.Exception e) {
        throw new RuntimeAdminException(LocalizedStrings.MBeanUtil_FAILED_TO_CREATE_MBEAN_FOR_0.toLocalizedString(new Object[] { resource.getMBeanName() }), e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) RuntimeAdminException(org.apache.geode.admin.RuntimeAdminException) ObjectName(javax.management.ObjectName)

Example 4 with RuntimeAdminException

use of org.apache.geode.admin.RuntimeAdminException in project geode by apache.

the class AdminWaiters method sendAndWait.

// private static final long TIMEOUT = 10000L;
/**
   * Sends <code>msg</code> using <code>dm</code> and waits for the response.
   * 
   * @return the response.
   * @throws RuntimeAdminException if this method is interrupted, times out, cancelled
   *         ({@link #cancelWaiters}), or failed with an exception on the server side.
   */
public static AdminResponse sendAndWait(AdminRequest msg, DistributionManager dm) {
    // we have to handle admin messages sent to ourselves specially.
    if (dm.getId().equals(msg.getRecipient())) {
        // Sent from myself
        msg.setSender(dm.getId());
        return msg.createResponse(dm);
    }
    AdminResponse result = null;
    try {
        synchronized (msg) {
            Set failures = dm.putOutgoing(msg);
            if (failures != null && failures.size() > 0) {
                // didn't go out
                if (dm.getDistributionManagerIds().contains(msg.getRecipient())) {
                    // it's still in the view
                    String s = "";
                    if (logger.isTraceEnabled(LogMarker.DM)) {
                        s += " (" + msg + ")";
                    }
                    throw new RuntimeAdminException(LocalizedStrings.AdminWaiters_COULD_NOT_SEND_REQUEST_0.toLocalizedString(s));
                }
                throw new OperationCancelledException(LocalizedStrings.AdminWaiters_REQUEST_SENT_TO_0_FAILED_SINCE_MEMBER_DEPARTED_1.toLocalizedString(new Object[] { msg.getRecipient(), "" }));
            }
            // sent it
            long timeout = getWaitTimeout();
            boolean gotResponse = msg.waitForResponse(timeout);
            if (!gotResponse) {
                if (dm.isCurrentMember(msg.getRecipient())) {
                    // still here?
                    // no one ever replied
                    StringBuffer sb = new StringBuffer("Administration request ");
                    sb.append(msg);
                    sb.append(" sent to ");
                    sb.append(msg.getRecipient());
                    sb.append(" timed out after ");
                    sb.append((timeout / 1000));
                    sb.append(" seconds.");
                    throw new RuntimeAdminException(sb.toString());
                }
                // still here?
                // recipient vanished
                String s = "";
                if (logger.isTraceEnabled(LogMarker.DM)) {
                    s = " (" + msg + ")";
                }
                throw new OperationCancelledException(LocalizedStrings.AdminWaiters_REQUEST_SENT_TO_0_FAILED_SINCE_MEMBER_DEPARTED_1.toLocalizedString(new Object[] { msg.getRecipient(), s }));
            }
            // !gotResponse
            result = msg.getResponse();
        }
    // synchronized
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        dm.getCancelCriterion().checkCancelInProgress(ex);
        String s = LocalizedStrings.AdminWaiters_REQUEST_WAIT_WAS_INTERRUPTED.toLocalizedString();
        if (logger.isTraceEnabled(LogMarker.DM)) {
            s += " (" + msg + ")";
        }
        throw new RuntimeAdminException(s, ex);
    }
    if (result == null) {
        String s = "";
        if (logger.isTraceEnabled(LogMarker.DM)) {
            s += " (" + msg + ")";
        }
        throw new OperationCancelledException(LocalizedStrings.AdminWaiters_REQUEST_SEND_TO_0_WAS_CANCELLED_1.toLocalizedString(new Object[] { msg.getRecipient(), s }));
    } else if (result instanceof AdminFailureResponse) {
        throw new RuntimeAdminException(LocalizedStrings.AdminWaiters_REQUEST_FAILED.toLocalizedString(), ((AdminFailureResponse) result).getCause());
    }
    return result;
}
Also used : Set(java.util.Set) RuntimeAdminException(org.apache.geode.admin.RuntimeAdminException) OperationCancelledException(org.apache.geode.admin.OperationCancelledException)

Aggregations

RuntimeAdminException (org.apache.geode.admin.RuntimeAdminException)4 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 ObjectName (javax.management.ObjectName)2 URL (java.net.URL)1 Set (java.util.Set)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 JMException (javax.management.JMException)1 JMRuntimeException (javax.management.JMRuntimeException)1 ListenerNotFoundException (javax.management.ListenerNotFoundException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 OperationCancelledException (org.apache.geode.admin.OperationCancelledException)1