Search in sources :

Example 41 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project geode by apache.

the class LocalProcessControllerJUnitTest method testProcessMBean.

@Test
public void testProcessMBean() throws Exception {
    // validate basics of the ProcessMBean
    Set<ObjectName> mbeanNames = this.server.queryNames(objectName, null);
    assertFalse("Zero matching mbeans", mbeanNames.isEmpty());
    assertEquals(1, mbeanNames.size());
    final ObjectName name = mbeanNames.iterator().next();
    final MBeanInfo info = this.server.getMBeanInfo(name);
    final MBeanOperationInfo[] operInfo = info.getOperations();
    assertEquals(1, operInfo.length);
    assertEquals("stop", operInfo[0].getName());
    final MBeanAttributeInfo[] attrInfo = info.getAttributes();
    assertEquals(2, attrInfo.length);
    // The order of these attributes is indeterminate
    assertTrue("Pid".equals(attrInfo[0].getName()) || "Process".equals(attrInfo[0].getName()));
    assertTrue("Pid".equals(attrInfo[1].getName()) || "Process".equals(attrInfo[1].getName()));
    assertNotNull(this.server.getAttribute(name, "Pid"));
    assertNotNull(this.server.getAttribute(name, "Process"));
    assertEquals(pid, this.server.getAttribute(name, "Pid"));
    assertEquals(true, this.server.getAttribute(name, "Process"));
    // validate query using only Pid attribute
    QueryExp constraint = Query.eq(Query.attr("Pid"), Query.value(pid));
    mbeanNames = this.server.queryNames(objectName, constraint);
    assertFalse("Zero matching mbeans", mbeanNames.isEmpty());
    // validate query with wrong Pid finds nothing
    constraint = Query.eq(Query.attr("Pid"), Query.value(pid + 1));
    mbeanNames = this.server.queryNames(objectName, constraint);
    assertTrue("Found matching mbeans", mbeanNames.isEmpty());
    // validate query using both attributes
    constraint = Query.and(Query.eq(Query.attr("Process"), Query.value(true)), Query.eq(Query.attr("Pid"), Query.value(pid)));
    mbeanNames = this.server.queryNames(objectName, constraint);
    assertFalse("Zero matching mbeans", mbeanNames.isEmpty());
    // validate query with wrong attribute finds nothing
    constraint = Query.and(Query.eq(Query.attr("Process"), Query.value(false)), Query.eq(Query.attr("Pid"), Query.value(pid)));
    mbeanNames = this.server.queryNames(objectName, constraint);
    assertTrue("Found matching mbeans", mbeanNames.isEmpty());
}
Also used : MBeanInfo(javax.management.MBeanInfo) QueryExp(javax.management.QueryExp) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 42 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project geode by apache.

the class MBeanUtil method printBeanDetails.

public static void printBeanDetails(ObjectName objName) throws Exception {
    MBeanAttributeInfo[] attributeInfos;
    MBeanInfo info = null;
    try {
        info = mbeanServer.getMBeanInfo(objName);
    } catch (IntrospectionException e1) {
        fail("Could not obtain Sender Proxy Details");
    } catch (InstanceNotFoundException e1) {
        fail("Could not obtain Sender Proxy Details");
    } catch (ReflectionException e1) {
        fail("Could not obtain Sender Proxy Details");
    }
    attributeInfos = info.getAttributes();
    for (MBeanAttributeInfo attributeInfo : attributeInfos) {
        Object propertyValue = null;
        String propertyName = null;
        try {
            propertyName = attributeInfo.getName();
            propertyValue = mbeanServer.getAttribute(objName, propertyName);
            LogWriterUtils.getLogWriter().info("<ExpectedString> " + propertyName + " = " + propertyValue + "</ExpectedString> ");
        } catch (Exception e) {
        }
    }
}
Also used : ReflectionException(javax.management.ReflectionException) MBeanInfo(javax.management.MBeanInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException)

Example 43 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project ignite by apache.

the class GridMBeanSelfTest method testCorrectMBeanInfo.

/**
     * Tests correct MBean interface.
     *
     * @throws Exception Thrown if test fails.
     */
public void testCorrectMBeanInfo() throws Exception {
    StandardMBean mbean = new IgniteStandardMXBean(new GridMBeanImplementation(), GridMBeanInterface.class);
    MBeanInfo info = mbean.getMBeanInfo();
    assert info.getDescription().equals("MBeanDescription.") == true;
    assert info.getOperations().length == 2;
    for (MBeanOperationInfo opInfo : info.getOperations()) {
        if (opInfo.getDescription().equals("MBeanOperation."))
            assert opInfo.getSignature().length == 2;
        else {
            assert opInfo.getDescription().equals("MBeanSuperOperation.") == true;
            assert opInfo.getSignature().length == 1;
        }
    }
    for (MBeanParameterInfo paramInfo : info.getOperations()[0].getSignature()) {
        if (paramInfo.getName().equals("ignored"))
            assert paramInfo.getDescription().equals("MBeanOperationParameter1.") == true;
        else {
            assert paramInfo.getName().equals("someData") == true;
            assert paramInfo.getDescription().equals("MBeanOperationParameter2.") == true;
        }
    }
    assert info.getAttributes().length == 4 : "Expected 4 attributes but got " + info.getAttributes().length;
    for (MBeanAttributeInfo attrInfo : info.getAttributes()) {
        if (attrInfo.isWritable() == false) {
            assert (attrInfo.getDescription().equals("MBeanReadonlyGetter.") == true || attrInfo.getDescription().equals("MBeanROGetter."));
        } else {
            assert (attrInfo.getDescription().equals("MBeanWritableGetter.") == true || attrInfo.getDescription().equals("MBeanWritableIsGetter."));
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) StandardMBean(javax.management.StandardMBean) IgniteStandardMXBean(org.apache.ignite.internal.mxbean.IgniteStandardMXBean) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 44 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project jackrabbit-oak by apache.

the class AnnotatedStandardMBeanTest method test.

@Test
public void test() throws Exception {
    MBeanInfo info = server.getMBeanInfo(objectName);
    assertEquals("MBean desc.", info.getDescription());
    MBeanAttributeInfo a0 = findAttribute(info, "Getter");
    assertEquals("getter", a0.getDescription());
    MBeanAttributeInfo a1 = findAttribute(info, "It");
    assertEquals("is", a1.getDescription());
    MBeanAttributeInfo a2 = findAttribute(info, "Setter");
    assertEquals("setter", a2.getDescription());
    MBeanOperationInfo op0 = info.getOperations()[0];
    assertEquals("run", op0.getDescription());
    assertEquals(MBeanOperationInfo.INFO, op0.getImpact());
    MBeanParameterInfo p0 = op0.getSignature()[0];
    assertEquals("timeout", p0.getName());
    assertEquals("how long?", p0.getDescription());
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo) Test(org.junit.Test)

Example 45 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project lucene-solr by apache.

the class MetricsMap method getMBeanInfo.

@Override
public MBeanInfo getMBeanInfo() {
    ArrayList<MBeanAttributeInfo> attrInfoList = new ArrayList<>();
    Map<String, Object> stats = getValue(true);
    if (useCachedStatsBetweenGetMBeanInfoCalls) {
        cachedValue = stats;
    }
    try {
        stats.forEach((k, v) -> {
            Class type = v.getClass();
            OpenType typeBox = determineType(type);
            if (type.equals(String.class) || typeBox == null) {
                attrInfoList.add(new MBeanAttributeInfo(k, String.class.getName(), null, true, false, false));
            } else {
                attrInfoList.add(new OpenMBeanAttributeInfoSupport(k, k, typeBox, true, false, false));
            }
        });
    } catch (Exception e) {
        // don't log issue if the core is closing
        if (!(SolrException.getRootCause(e) instanceof AlreadyClosedException))
            log.warn("Could not get attributes of MetricsMap: {}", this, e);
    }
    MBeanAttributeInfo[] attrInfoArr = attrInfoList.toArray(new MBeanAttributeInfo[attrInfoList.size()]);
    return new MBeanInfo(getClass().getName(), "MetricsMap", attrInfoArr, null, null, null);
}
Also used : OpenType(javax.management.openmbean.OpenType) MBeanInfo(javax.management.MBeanInfo) ArrayList(java.util.ArrayList) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) AttributeNotFoundException(javax.management.AttributeNotFoundException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) SolrException(org.apache.solr.common.SolrException) ReflectionException(javax.management.ReflectionException) OpenMBeanAttributeInfoSupport(javax.management.openmbean.OpenMBeanAttributeInfoSupport)

Aggregations

MBeanAttributeInfo (javax.management.MBeanAttributeInfo)106 MBeanInfo (javax.management.MBeanInfo)75 ObjectName (javax.management.ObjectName)45 MBeanOperationInfo (javax.management.MBeanOperationInfo)24 Test (org.junit.Test)21 MBeanServer (javax.management.MBeanServer)15 ArrayList (java.util.ArrayList)13 AttributeNotFoundException (javax.management.AttributeNotFoundException)12 ReflectionException (javax.management.ReflectionException)12 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)11 IOException (java.io.IOException)10 AttributeList (javax.management.AttributeList)10 Attribute (javax.management.Attribute)9 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 IntrospectionException (javax.management.IntrospectionException)9 MBeanParameterInfo (javax.management.MBeanParameterInfo)9 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)9 HashMap (java.util.HashMap)8 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)7 MBeanException (javax.management.MBeanException)7