Search in sources :

Example 1 with Container

use of com.sun.appserv.management.base.Container 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 2 with Container

use of com.sun.appserv.management.base.Container in project Payara by payara.

the class AMXTest method checkMaps.

/**
 *     Verify that a proxy getAbcMap(...) Attribute or operation has an appropriate
 *     MBean getAbcObjectNameMap() method.
 */
public void checkMaps(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();
        for (int methodIdx = 0; methodIdx < methods.length; ++methodIdx) {
            final Method method = methods[methodIdx];
            final String methodName = method.getName();
            if (isMapGetter(method)) {
                if (methodName.endsWith(OBJECTNAME_MAP_SUFFIX)) {
                    warning("method should exist in MBeanInfo, not interface: " + methodName);
                    continue;
                }
                // verify that a corresponding peer method exists and
                // has the right return type and same number and type of parameters
                final String peerMethodName = StringUtil.replaceSuffix(methodName, MAP_SUFFIX, OBJECTNAME_MAP_SUFFIX);
                checkCompatibleOperationExists(Util.getObjectName(proxy), method, peerMethodName, mbeanInfo);
            } else if (isMapGetterName(methodName)) {
                warning("operation " + methodName + " does not return a Map!");
            }
        }
    }
}
Also used : Container(com.sun.appserv.management.base.Container) MBeanInfo(javax.management.MBeanInfo) Method(java.lang.reflect.Method) AMX(com.sun.appserv.management.base.AMX)

Example 3 with Container

use of com.sun.appserv.management.base.Container in project Payara by payara.

the class AMXTest method checkContainerChild.

/**
 *     Verify that each child's Container actually claims the child as a child.
 */
public void checkContainerChild(final String childJ2EEType) {
    final QueryMgr queryMgr = getQueryMgr();
    final Set children = queryMgr.queryJ2EETypeSet(childJ2EEType);
    final Iterator iter = children.iterator();
    while (iter.hasNext()) {
        final AMX containee = Util.asAMX(iter.next());
        Container container = null;
        final ObjectName objectName = Util.getObjectName(containee);
        if (!shouldTest(objectName)) {
            continue;
        }
        try {
            container = (Container) containee.getContainer();
        } catch (Exception e) {
            trace("Can't get container for: " + objectName);
        }
        if (container == null) {
            assert (containee.getJ2EEType().equals(XTypes.DOMAIN_ROOT)) : "container is null for: " + objectName;
            continue;
        }
        final Set<AMX> containeeSet = container.getContaineeSet(childJ2EEType);
        final Set<ObjectName> containeeObjectNameSet = Util.toObjectNames(containeeSet);
        assert (containeeObjectNameSet.contains(Util.getExtra(containee).getObjectName()));
    }
}
Also used : QueryMgr(com.sun.appserv.management.base.QueryMgr) Container(com.sun.appserv.management.base.Container) HashSet(java.util.HashSet) Set(java.util.Set) Iterator(java.util.Iterator) AMX(com.sun.appserv.management.base.AMX) AttributeNotFoundException(javax.management.AttributeNotFoundException) IOException(java.io.IOException) JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Example 4 with Container

use of com.sun.appserv.management.base.Container in project Payara by payara.

the class ContainerTest method checkContainerContainsChild.

public void checkContainerContainsChild(final ObjectName containeeObjectName) throws Exception {
    final MBeanServerConnection conn = getMBeanServerConnection();
    assert (containeeObjectName != null);
    assert (conn.isRegistered(containeeObjectName));
    final AMX containedProxy = getProxyFactory().getProxy(containeeObjectName, AMX.class);
    if (containedProxy instanceof DomainRoot) {
        // DomainRoot has no Container
        return;
    }
    final ObjectName containerObjectName = (ObjectName) conn.getAttribute(containeeObjectName, "ContainerObjectName");
    if (!conn.isRegistered(containerObjectName)) {
        warning("Container " + StringUtil.quote(containerObjectName) + " for " + StringUtil.quote(containeeObjectName) + " is not registered.");
        return;
    }
    final AMX parentProxy = containedProxy.getContainer();
    if (parentProxy instanceof Container) {
        if (!(parentProxy instanceof Container)) {
            trace("WARNING: proxy is instance of Container, but not Container: " + Util.getExtra(parentProxy).getObjectName());
        } else {
            final Container container = (Container) parentProxy;
            if (container != null) {
                final Set<AMX> containees = container.getContaineeSet();
                final Set<ObjectName> containeeObjectNames = Util.toObjectNames(containees);
                if (!containeeObjectNames.contains(Util.getExtra(containedProxy).getObjectName())) {
                    trace("ERROR: Container " + Util.getExtra(parentProxy).getObjectName() + " does not contain its child: " + containeeObjectName);
                    assertTrue(false);
                }
            }
        }
    }
}
Also used : Container(com.sun.appserv.management.base.Container) DomainRoot(com.sun.appserv.management.DomainRoot) AMX(com.sun.appserv.management.base.AMX) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 5 with Container

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

Aggregations

Container (com.sun.appserv.management.base.Container)7 AMX (com.sun.appserv.management.base.AMX)6 ObjectName (javax.management.ObjectName)4 AMXConfig (com.sun.appserv.management.config.AMXConfig)3 Method (java.lang.reflect.Method)2 MBeanInfo (javax.management.MBeanInfo)2 MBeanOperationInfo (javax.management.MBeanOperationInfo)2 DomainRoot (com.sun.appserv.management.DomainRoot)1 Extra (com.sun.appserv.management.base.Extra)1 QueryMgr (com.sun.appserv.management.base.QueryMgr)1 ProxyFactory (com.sun.appserv.management.client.ProxyFactory)1 SecurityMapConfig (com.sun.appserv.management.config.SecurityMapConfig)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 AttributeNotFoundException (javax.management.AttributeNotFoundException)1 JMException (javax.management.JMException)1 MBeanServerConnection (javax.management.MBeanServerConnection)1 CreateRemoveListener (org.glassfish.admin.amxtest.support.CreateRemoveListener)1