Search in sources :

Example 1 with Monitoring

use of com.sun.appserv.management.monitor.Monitoring in project Payara by payara.

the class J2EETest method testJ2EE.

public void testJ2EE() throws ClassNotFoundException {
    final QueryMgr queryMgr = getQueryMgr();
    final Set<J2EEManagedObject> j2eeAll = queryMgr.queryInterfaceSet(J2EEManagedObject.class.getName(), null);
    final Set<ObjectName> failedSet = new HashSet<ObjectName>();
    final Set<ObjectName> noPeerSet = new HashSet<ObjectName>();
    for (final J2EEManagedObject item : j2eeAll) {
        final ObjectName objectName = Util.getObjectName(item);
        assert (objectName.equals(Util.newObjectName(item.getobjectName())));
        final String j2eeType = item.getJ2EEType();
        if (item.isstateManageable()) {
            assert (item instanceof StateManageable);
            final StateManageable sm = (StateManageable) item;
            final int state = sm.getstate();
            assert (state == StateManageable.STATE_STARTING || state == StateManageable.STATE_RUNNING || state == StateManageable.STATE_STOPPING || state == StateManageable.STATE_STOPPED || state == StateManageable.STATE_FAILED);
            if (state == StateManageable.STATE_RUNNING) {
                try {
                    final long startTime = sm.getstartTime();
                    // assume it was started less than 30 days ago
                    final long MILLIS_PER_DAY = 24L * 60L * 60L * 1000L;
                    final long days30 = 30L * MILLIS_PER_DAY;
                    if (startTime < now() - days30) {
                        warning("MBean " + quote(objectName) + " claims a start time of " + new Date(startTime) + ", which is more than 30 days prior to now = " + new Date(now()));
                        failedSet.add(objectName);
                    }
                } catch (Exception e) {
                    final Throwable rootCause = ExceptionUtil.getRootCause(e);
                    warning("MBean " + quote(objectName) + " is 'stateManageable' and in 'STATE_RUNNING', but could not supply Attribute 'startTime', " + "threw an exception of class " + rootCause.getClass().getName());
                    failedSet.add(objectName);
                }
            }
        }
        if (item.iseventProvider()) {
            assert (item instanceof EventProvider);
            final EventProvider ep = (EventProvider) item;
            final String[] types = ep.gettypes();
            assert types != null : "Item claims to be EventProvider, but provides null 'types': " + toString(objectName);
        }
        /*
                    monitoring was enabled so monitoring peers should exist
                    Can't just call isStatisticProvider(), since it will be false
                    if the monitoring peer is null (correctly or incorrectly).
                */
        final String monitoringPeerJ2EEType = getMonitoringPeerJ2EEType(j2eeType);
        final Monitoring monitoringPeer = item.getMonitoringPeer();
        if (monitoringPeerJ2EEType != null) {
            // See if there actually is a monitoring peer, but null is being returned.
            if (monitoringPeer == null) {
                final String props = getMonitoringPeerProps(item);
                final Set<Monitoring> monitors = getQueryMgr().queryPropsSet(props);
                if (monitors.size() != 0) {
                    warning("MBean " + quote(objectName) + " returned null for its monitoring peer, but found the following:" + NEWLINE + CollectionUtil.toString(Util.toObjectNames(monitors), NEWLINE));
                    failedSet.add(objectName);
                }
            } else {
                // statistics
                if (!HasNoStats.contains(j2eeType)) {
                    assert item.isstatisticProvider() && item.isstatisticsProvider();
                }
            }
        } else {
            // it has a monitoring peer
            if (item.isstatisticProvider() || item.isstatisticsProvider()) {
                warning("MBean " + quote(objectName) + " should not have its statisticProvider set to true");
                failedSet.add(objectName);
            }
        }
        if (item.isConfigProvider()) {
            final AMXConfig config = item.getConfigPeer();
            if (config == null) {
                // Some auto-generated items do not have config.  See if it's there
                final String props = Util.makeRequiredProps(getConfigPeerJ2EEType(j2eeType), item.getName());
                if (getQueryMgr().queryPropsSet(props).size() != 0) {
                    warning("MBean " + quote(objectName) + " has existing config peer, but returned null");
                    failedSet.add(objectName);
                }
            }
        }
    }
    if (noPeerSet.size() != 0) {
        warning("The following MBeans do not have a Monitoring peer:" + NEWLINE + toString(noPeerSet));
    }
    if (failedSet.size() != 0) {
        failure("Failures in the following " + failedSet.size() + " MBeans:\n" + toString(failedSet));
    }
}
Also used : QueryMgr(com.sun.appserv.management.base.QueryMgr) AMXConfig(com.sun.appserv.management.config.AMXConfig) Date(java.util.Date) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) J2EEManagedObject(com.sun.appserv.management.j2ee.J2EEManagedObject) StateManageable(com.sun.appserv.management.j2ee.StateManageable) EventProvider(com.sun.appserv.management.j2ee.EventProvider) Monitoring(com.sun.appserv.management.monitor.Monitoring) HashSet(java.util.HashSet)

Aggregations

QueryMgr (com.sun.appserv.management.base.QueryMgr)1 AMXConfig (com.sun.appserv.management.config.AMXConfig)1 EventProvider (com.sun.appserv.management.j2ee.EventProvider)1 J2EEManagedObject (com.sun.appserv.management.j2ee.J2EEManagedObject)1 StateManageable (com.sun.appserv.management.j2ee.StateManageable)1 Monitoring (com.sun.appserv.management.monitor.Monitoring)1 IOException (java.io.IOException)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 ObjectName (javax.management.ObjectName)1