Search in sources :

Example 1 with AMXConfig

use of com.sun.appserv.management.config.AMXConfig in project Payara by payara.

the class ConfigMgrTestBase method testIllegalCreate.

public final synchronized void testIllegalCreate() throws Exception {
    if (!checkNotOffline("testIllegalCreate")) {
        return;
    }
    final String name = getProgenyTestName() + "-Illegal";
    try {
        final AMXConfig proxy = createProgeny(name, ILLEGAL_OPTIONS);
        fail("Expecting failure from createProgenyIllegal for progeny type: " + getProgenyJ2EEType());
    } catch (final Exception e) {
        final Throwable rootCause = ExceptionUtil.getRootCause(e);
        if (!(rootCause instanceof IllegalArgumentException)) {
            warning("expecting IllegalArgumentException, got: " + rootCause.getClass().getName() + ", msg = " + rootCause.getMessage());
            rootCause.printStackTrace();
        }
    } catch (final Throwable t) {
        final Throwable rootCause = ExceptionUtil.getRootCause(t);
        warning("expecting IllegalArgumentException, got: " + ExceptionUtil.toString(rootCause));
        assert false;
    }
}
Also used : AMXConfig(com.sun.appserv.management.config.AMXConfig)

Example 2 with AMXConfig

use of com.sun.appserv.management.config.AMXConfig in project Payara by payara.

the class ConfigMgrTestBase method getProgeny.

public AMXConfig getProgeny(final String name) {
    final Container container = getProgenyContainer();
    final String progenyType = getProgenyJ2EEType();
    // trace( "getProgeny: " + progenyType + "=" + name );
    final Object progeny = container.getContainee(progenyType, name);
    if (progeny != null && !(progeny instanceof AMXConfig)) {
        assert (progeny instanceof AMX);
        failure("getProgeny: " + progenyType + "=" + name + " not an AMXConfig, interface = " + Util.getExtra(Util.asAMX(progeny)).getInterfaceName());
    }
    return ((AMXConfig) progeny);
}
Also used : Container(com.sun.appserv.management.base.Container) AMX(com.sun.appserv.management.base.AMX) AMXConfig(com.sun.appserv.management.config.AMXConfig)

Example 3 with AMXConfig

use of com.sun.appserv.management.config.AMXConfig 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)

Example 4 with AMXConfig

use of com.sun.appserv.management.config.AMXConfig in project Payara by payara.

the class AMXTest method checkCreateRemoveGet.

/**
 *     Verify:
 *     <ul>
 *     <li>each create() or createAbc() method ends in "Config" if it returns an AMXConfig subclass</li>
 *     <li>each remove() or removeAbc() method ends in "Config"</li>
 *     </ul>
 */
public void checkCreateRemoveGet(final ObjectName objectName) throws Exception {
    final AMX proxy = getProxyFactory().getProxy(objectName, AMX.class);
    if (proxy instanceof Container) {
        final Method[] methods = getInterfaceClass(proxy).getMethods();
        final MBeanInfo mbeanInfo = Util.getExtra(proxy).getMBeanInfo();
        final MBeanOperationInfo[] operations = mbeanInfo.getOperations();
        for (int methodIdx = 0; methodIdx < methods.length; ++methodIdx) {
            final Method method = methods[methodIdx];
            final String methodName = method.getName();
            if (methodName.startsWith("create") && !methodName.endsWith("Config")) {
                if (AMXConfig.class.isAssignableFrom(method.getReturnType()) && (!(proxy instanceof SecurityMapConfig))) {
                    trace("WARNING: method " + methodName + " does not end in 'Config': " + objectName);
                }
            } else if (methodName.startsWith("remove") && !methodName.endsWith("Config") && proxy instanceof AMXConfig) {
                if (// method.getReturnType() == Void.class &&
                method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == String.class && !method.getName().equals("removeProperty") && !method.getName().equals("removeSystemProperty") && (!(proxy instanceof SecurityMapConfig))) {
                    trace("WARNING: method " + methodName + " does not end in 'Config': " + methodName);
                }
            }
        }
    }
}
Also used : Container(com.sun.appserv.management.base.Container) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) SecurityMapConfig(com.sun.appserv.management.config.SecurityMapConfig) Method(java.lang.reflect.Method) AMX(com.sun.appserv.management.base.AMX) AMXConfig(com.sun.appserv.management.config.AMXConfig)

Example 5 with AMXConfig

use of com.sun.appserv.management.config.AMXConfig in project Payara by payara.

the class AMXTest method checkTemplateAttributes.

/**
 *     Look for Attributes that probably should be String and not int/long
 *     due to our template facility ${...}
 */
public void checkTemplateAttributes(final ObjectName objectName) {
    final AMX proxy = getProxyFactory().getProxy(objectName, AMX.class);
    if (proxy instanceof AMXConfig) {
        final AMXConfig config = (AMXConfig) proxy;
        final Set<String> s = new HashSet<String>();
        final MBeanInfo mbeanInfo = Util.getExtra(config).getMBeanInfo();
        final MBeanAttributeInfo[] attrInfos = mbeanInfo.getAttributes();
        for (int i = 0; i < attrInfos.length; ++i) {
            final MBeanAttributeInfo info = attrInfos[i];
            final String type = info.getType();
            if (type.equals("int") || type.equals("long")) {
                s.add(info.getName());
            }
        }
        if (s.size() != 0) {
            trace("\n" + objectName + " contains the following int/long Attributes which perhaps ought to be String" + " due to the templatizing of config: " + toString(s) + "\n");
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) AMX(com.sun.appserv.management.base.AMX) AMXConfig(com.sun.appserv.management.config.AMXConfig) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) HashSet(java.util.HashSet)

Aggregations

AMXConfig (com.sun.appserv.management.config.AMXConfig)7 AMX (com.sun.appserv.management.base.AMX)4 Container (com.sun.appserv.management.base.Container)3 HashSet (java.util.HashSet)2 MBeanInfo (javax.management.MBeanInfo)2 ObjectName (javax.management.ObjectName)2 QueryMgr (com.sun.appserv.management.base.QueryMgr)1 ProxyFactory (com.sun.appserv.management.client.ProxyFactory)1 SecurityMapConfig (com.sun.appserv.management.config.SecurityMapConfig)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 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 MBeanOperationInfo (javax.management.MBeanOperationInfo)1 CreateRemoveListener (org.glassfish.admin.amxtest.support.CreateRemoveListener)1