Search in sources :

Example 71 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project graphdb by neo4j-attic.

the class Neo4jManager method getConfiguration.

public Map<String, Object> getConfiguration() {
    final String[] keys;
    final AttributeList attributes;
    try {
        MBeanAttributeInfo[] keyInfo = server.getMBeanInfo(config).getAttributes();
        keys = new String[keyInfo.length];
        for (int i = 0; i < keys.length; i++) {
            keys[i] = keyInfo[i].getName();
        }
        attributes = server.getAttributes(config, keys);
    } catch (Exception e) {
        throw new IllegalStateException("Could not access the configuration bean", e);
    }
    Map<String, Object> configuration = new HashMap<String, Object>();
    for (int i = 0; i < keys.length; i++) {
        configuration.put(keys[i], attributes.get(i));
    }
    return configuration;
}
Also used : HashMap(java.util.HashMap) AttributeList(javax.management.AttributeList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) AttributeNotFoundException(javax.management.AttributeNotFoundException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException)

Example 72 with MBeanAttributeInfo

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

the class JMXJsonServlet method listBeans.

// --------------------------------------------------------- Private Methods
private void listBeans(JsonGenerator jg, ObjectName qry, String attribute, HttpServletResponse response) throws IOException {
    LOG.debug("Listing beans for " + qry);
    Set<ObjectName> names = null;
    names = mBeanServer.queryNames(qry, null);
    jg.writeArrayFieldStart("beans");
    Iterator<ObjectName> it = names.iterator();
    while (it.hasNext()) {
        ObjectName oname = it.next();
        MBeanInfo minfo;
        String code = "";
        Object attributeinfo = null;
        try {
            minfo = mBeanServer.getMBeanInfo(oname);
            code = minfo.getClassName();
            String prs = "";
            try {
                if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) {
                    prs = "modelerType";
                    code = (String) mBeanServer.getAttribute(oname, prs);
                }
                if (attribute != null) {
                    prs = attribute;
                    attributeinfo = mBeanServer.getAttribute(oname, prs);
                }
            } catch (AttributeNotFoundException e) {
                // If the modelerType attribute was not found, the class name is used
                // instead.
                LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
            } catch (MBeanException e) {
                // The code inside the attribute getter threw an exception so log it,
                // and fall back on the class name
                LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
            } catch (RuntimeException e) {
                // For some reason even with an MBeanException available to them
                // Runtime exceptionscan still find their way through, so treat them
                // the same as MBeanException
                LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
            } catch (ReflectionException e) {
                // This happens when the code inside the JMX bean (setter?? from the
                // java docs) threw an exception, so log it and fall back on the 
                // class name
                LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
            }
        } catch (InstanceNotFoundException e) {
            //Ignored for some reason the bean was not found so don't output it
            continue;
        } catch (IntrospectionException e) {
            // This is an internal error, something odd happened with reflection so
            // log it and don't output the bean.
            LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e);
            continue;
        } catch (ReflectionException e) {
            // This happens when the code inside the JMX bean threw an exception, so
            // log it and don't output the bean.
            LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e);
            continue;
        }
        jg.writeStartObject();
        jg.writeStringField("name", oname.toString());
        jg.writeStringField("modelerType", code);
        if ((attribute != null) && (attributeinfo == null)) {
            jg.writeStringField("result", "ERROR");
            jg.writeStringField("message", "No attribute with name " + attribute + " was found.");
            jg.writeEndObject();
            jg.writeEndArray();
            jg.close();
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        if (attribute != null) {
            writeAttribute(jg, attribute, attributeinfo);
        } else {
            MBeanAttributeInfo[] attrs = minfo.getAttributes();
            for (int i = 0; i < attrs.length; i++) {
                writeAttribute(jg, oname, attrs[i]);
            }
        }
        jg.writeEndObject();
    }
    jg.writeEndArray();
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) RuntimeMBeanException(javax.management.RuntimeMBeanException) MBeanException(javax.management.MBeanException)

Example 73 with MBeanAttributeInfo

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

the class TestMetricsSourceAdapter method testPurgeOldMetrics.

@Test
public void testPurgeOldMetrics() throws Exception {
    // create test source with a single metric counter of value 1
    PurgableSource source = new PurgableSource();
    MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source);
    final MetricsSource s = sb.build();
    List<MetricsTag> injectedTags = new ArrayList<MetricsTag>();
    MetricsSourceAdapter sa = new MetricsSourceAdapter("tst", "tst", "testdesc", s, injectedTags, null, null, 1, false);
    MBeanInfo info = sa.getMBeanInfo();
    boolean sawIt = false;
    for (MBeanAttributeInfo mBeanAttributeInfo : info.getAttributes()) {
        sawIt |= mBeanAttributeInfo.getName().equals(source.lastKeyName);
    }
    ;
    assertTrue("The last generated metric is not exported to jmx", sawIt);
    // skip JMX cache TTL
    Thread.sleep(1000);
    info = sa.getMBeanInfo();
    sawIt = false;
    for (MBeanAttributeInfo mBeanAttributeInfo : info.getAttributes()) {
        sawIt |= mBeanAttributeInfo.getName().equals(source.lastKeyName);
    }
    ;
    assertTrue("The last generated metric is not exported to jmx", sawIt);
}
Also used : MetricsSource(org.apache.hadoop.metrics2.MetricsSource) MBeanInfo(javax.management.MBeanInfo) MetricsSourceBuilder(org.apache.hadoop.metrics2.lib.MetricsSourceBuilder) ArrayList(java.util.ArrayList) MetricsTag(org.apache.hadoop.metrics2.MetricsTag) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) Test(org.junit.Test)

Example 74 with MBeanAttributeInfo

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

the class JMXGet method printAllValues.

/**
   * print all attributes' values
   */
public void printAllValues() throws Exception {
    err("List of all the available keys:");
    Object val = null;
    for (ObjectName oname : hadoopObjectNames) {
        err(">>>>>>>>jmx name: " + oname.getCanonicalKeyPropertyListString());
        MBeanInfo mbinfo = mbsc.getMBeanInfo(oname);
        MBeanAttributeInfo[] mbinfos = mbinfo.getAttributes();
        for (MBeanAttributeInfo mb : mbinfos) {
            val = mbsc.getAttribute(oname, mb.getName());
            System.out.format(format, mb.getName(), (val == null) ? "" : val.toString());
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName)

Example 75 with MBeanAttributeInfo

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

the class JMXGet method printAllMatchedAttributes.

public void printAllMatchedAttributes(String attrRegExp) throws Exception {
    err("List of the keys matching " + attrRegExp + " :");
    Object val = null;
    Pattern p = Pattern.compile(attrRegExp);
    for (ObjectName oname : hadoopObjectNames) {
        err(">>>>>>>>jmx name: " + oname.getCanonicalKeyPropertyListString());
        MBeanInfo mbinfo = mbsc.getMBeanInfo(oname);
        MBeanAttributeInfo[] mbinfos = mbinfo.getAttributes();
        for (MBeanAttributeInfo mb : mbinfos) {
            if (p.matcher(mb.getName()).lookingAt()) {
                val = mbsc.getAttribute(oname, mb.getName());
                System.out.format(format, mb.getName(), (val == null) ? "" : val.toString());
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) MBeanInfo(javax.management.MBeanInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName)

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