Search in sources :

Example 86 with Attribute

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

the class MetricsLoggerTask method run.

/**
   * Write metrics to the metrics appender when invoked.
   */
@Override
public void run() {
    // Skip querying metrics if there are no known appenders.
    if (!metricsLog.isInfoEnabled() || !hasAppenders(metricsLog) || objectName == null) {
        return;
    }
    metricsLog.info(" >> Begin " + nodeName + " metrics dump");
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    // Iterate over each MBean.
    for (final ObjectName mbeanName : server.queryNames(objectName, null)) {
        try {
            MBeanInfo mBeanInfo = server.getMBeanInfo(mbeanName);
            final String mBeanNameName = MBeans.getMbeanNameName(mbeanName);
            final Set<String> attributeNames = getFilteredAttributes(mBeanInfo);
            final AttributeList attributes = server.getAttributes(mbeanName, attributeNames.toArray(new String[attributeNames.size()]));
            for (Object o : attributes) {
                final Attribute attribute = (Attribute) o;
                final Object value = attribute.getValue();
                final String valueStr = (value != null) ? value.toString() : "null";
                // Truncate the value if it is too long
                metricsLog.info(mBeanNameName + ":" + attribute.getName() + "=" + trimLine(valueStr));
            }
        } catch (Exception e) {
            metricsLog.error("Failed to get " + nodeName + " metrics for mbean " + mbeanName.toString(), e);
        }
    }
    metricsLog.info(" << End " + nodeName + " metrics dump");
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 87 with Attribute

use of javax.management.Attribute in project camel by apache.

the class ManagedErrorHandlerRedeliveryTest method testManagedErrorHandlerRedelivery.

public void testManagedErrorHandlerRedelivery() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    counter = 0;
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=errorhandlers,*"), null);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    Integer max = (Integer) mbeanServer.getAttribute(on, "MaximumRedeliveries");
    assertEquals(5, max.intValue());
    Long delay = (Long) mbeanServer.getAttribute(on, "MaximumRedeliveryDelay");
    assertEquals(60000, delay.longValue());
    delay = (Long) mbeanServer.getAttribute(on, "RedeliveryDelay");
    assertEquals(1000, delay.longValue());
    String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", camelId);
    Boolean dlc = (Boolean) mbeanServer.getAttribute(on, "DeadLetterChannel");
    assertEquals(Boolean.FALSE, dlc);
    Boolean dlcom = (Boolean) mbeanServer.getAttribute(on, "DeadLetterUseOriginalMessage");
    assertEquals(Boolean.FALSE, dlcom);
    Boolean tx = (Boolean) mbeanServer.getAttribute(on, "SupportTransactions");
    assertEquals(Boolean.FALSE, tx);
    String dlcUri = (String) mbeanServer.getAttribute(on, "DeadLetterChannelEndpointUri");
    assertNull(dlcUri);
    Double backoff = (Double) mbeanServer.getAttribute(on, "BackOffMultiplier");
    assertNotNull(backoff);
    Double cf = (Double) mbeanServer.getAttribute(on, "CollisionAvoidanceFactor");
    assertNotNull(cf);
    Double cp = (Double) mbeanServer.getAttribute(on, "CollisionAvoidancePercent");
    assertNotNull(cp);
    String dp = (String) mbeanServer.getAttribute(on, "DelayPattern");
    assertNull(dp);
    String ell = (String) mbeanServer.getAttribute(on, "RetriesExhaustedLogLevel");
    assertEquals(LoggingLevel.ERROR.name(), ell);
    String rll = (String) mbeanServer.getAttribute(on, "RetryAttemptedLogLevel");
    assertEquals(LoggingLevel.DEBUG.name(), rll);
    Boolean lst = (Boolean) mbeanServer.getAttribute(on, "LogStackTrace");
    assertEquals(true, lst.booleanValue());
    Boolean lrst = (Boolean) mbeanServer.getAttribute(on, "LogRetryStackTrace");
    assertEquals(false, lrst.booleanValue());
    Boolean uca = (Boolean) mbeanServer.getAttribute(on, "UseCollisionAvoidance");
    assertEquals(false, uca.booleanValue());
    Boolean uebf = (Boolean) mbeanServer.getAttribute(on, "UseExponentialBackOff");
    assertEquals(false, uebf.booleanValue());
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertEquals(3, counter);
    assertMockEndpointsSatisfied();
    // now change to 0 attempts and try again
    counter = 0;
    mock.reset();
    mock.expectedMessageCount(0);
    mbeanServer.setAttribute(on, new Attribute("MaximumRedeliveries", 0));
    try {
        template.sendBody("direct:start", "Bye World");
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertEquals("Forced", cause.getMessage());
    }
    assertEquals(1, counter);
    // and should now be 0
    max = (Integer) mbeanServer.getAttribute(on, "MaximumRedeliveries");
    assertEquals(0, max.intValue());
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Attribute(javax.management.Attribute) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 88 with Attribute

use of javax.management.Attribute in project camel by apache.

the class ManagedCamelContextTracerTest method testCamelContextTracing.

public void testCamelContextTracing() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName camel = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
    ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=Tracer");
    mbeanServer.isRegistered(camel);
    mbeanServer.isRegistered(on);
    // with tracing
    MockEndpoint traced = getMockEndpoint("mock:traced");
    traced.setExpectedMessageCount(2);
    MockEndpoint result = getMockEndpoint("mock:result");
    result.setExpectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    // should be enabled
    Boolean tracing = (Boolean) mbeanServer.getAttribute(camel, "Tracing");
    assertEquals("Tracing should be enabled", true, tracing.booleanValue());
    String destinationUri = (String) mbeanServer.getAttribute(on, "DestinationUri");
    assertEquals("mock:traced", destinationUri);
    String logLevel = (String) mbeanServer.getAttribute(on, "LogLevel");
    assertEquals(LoggingLevel.OFF.name(), logLevel);
    String logName = (String) mbeanServer.getAttribute(on, "LogName");
    assertNotNull(logName);
    Boolean logStackTrace = (Boolean) mbeanServer.getAttribute(on, "LogStackTrace");
    assertEquals(Boolean.FALSE, logStackTrace);
    Boolean traceInterceptors = (Boolean) mbeanServer.getAttribute(on, "TraceInterceptors");
    assertEquals(Boolean.FALSE, traceInterceptors);
    Boolean traceExceptions = (Boolean) mbeanServer.getAttribute(on, "TraceExceptions");
    assertEquals(Boolean.TRUE, traceExceptions);
    Boolean traceOutExchanges = (Boolean) mbeanServer.getAttribute(on, "TraceOutExchanges");
    assertEquals(Boolean.FALSE, traceOutExchanges);
    Boolean formatterShowBody = (Boolean) mbeanServer.getAttribute(on, "FormatterShowBody");
    assertEquals(Boolean.TRUE, formatterShowBody);
    Boolean formatterShowBodyType = (Boolean) mbeanServer.getAttribute(on, "FormatterShowBodyType");
    assertEquals(Boolean.TRUE, formatterShowBodyType);
    Boolean formatterShowOutBody = (Boolean) mbeanServer.getAttribute(on, "FormatterShowOutBody");
    assertEquals(Boolean.FALSE, formatterShowOutBody);
    Boolean formatterShowOutBodyType = (Boolean) mbeanServer.getAttribute(on, "FormatterShowOutBodyType");
    assertEquals(Boolean.FALSE, formatterShowOutBodyType);
    Boolean formatterShowBreadCrumb = (Boolean) mbeanServer.getAttribute(on, "FormatterShowBreadCrumb");
    assertEquals(Boolean.TRUE, formatterShowBreadCrumb);
    Boolean formatterShowExchangeId = (Boolean) mbeanServer.getAttribute(on, "FormatterShowExchangeId");
    assertEquals(Boolean.FALSE, formatterShowExchangeId);
    Boolean formatterShowHeaders = (Boolean) mbeanServer.getAttribute(on, "FormatterShowHeaders");
    assertEquals(Boolean.TRUE, formatterShowHeaders);
    Boolean formatterShowOutHeaders = (Boolean) mbeanServer.getAttribute(on, "FormatterShowOutHeaders");
    assertEquals(Boolean.FALSE, formatterShowOutHeaders);
    Boolean formatterShowProperties = (Boolean) mbeanServer.getAttribute(on, "FormatterShowProperties");
    assertEquals(Boolean.FALSE, formatterShowProperties);
    Boolean formatterShowNode = (Boolean) mbeanServer.getAttribute(on, "FormatterShowNode");
    assertEquals(Boolean.TRUE, formatterShowNode);
    Boolean formatterShowExchangePattern = (Boolean) mbeanServer.getAttribute(on, "FormatterShowExchangePattern");
    assertEquals(Boolean.TRUE, formatterShowExchangePattern);
    Boolean formatterShowException = (Boolean) mbeanServer.getAttribute(on, "FormatterShowException");
    assertEquals(Boolean.TRUE, formatterShowException);
    Boolean formatterShowShortExchangeId = (Boolean) mbeanServer.getAttribute(on, "FormatterShowShortExchangeId");
    assertEquals(Boolean.FALSE, formatterShowShortExchangeId);
    Integer formatterBreadCrumbLength = (Integer) mbeanServer.getAttribute(on, "FormatterBreadCrumbLength");
    assertEquals(0, formatterBreadCrumbLength.intValue());
    Integer formatterNodeLength = (Integer) mbeanServer.getAttribute(on, "FormatterNodeLength");
    assertEquals(0, formatterNodeLength.intValue());
    Integer formatterMaxChars = (Integer) mbeanServer.getAttribute(on, "FormatterMaxChars");
    assertEquals(10000, formatterMaxChars.intValue());
    // now disable tracing
    mbeanServer.setAttribute(camel, new Attribute("Tracing", Boolean.FALSE));
    // without tracing
    traced.reset();
    traced.setExpectedMessageCount(0);
    result.reset();
    result.setExpectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Attribute(javax.management.Attribute) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 89 with Attribute

use of javax.management.Attribute in project camel by apache.

the class ManagedCustomProcessorTest method testManageCustomProcessor.

public void testManageCustomProcessor() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"custom\"");
    getMockEndpoint("mock:result").expectedMessageCount(1);
    getMockEndpoint("mock:result").expectedHeaderReceived("foo", "hey");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    String foo = (String) mbeanServer.getAttribute(on, "Foo");
    assertEquals("hey", foo);
    // change foo
    mbeanServer.setAttribute(on, new Attribute("Foo", "changed"));
    resetMocks();
    getMockEndpoint("mock:result").expectedMessageCount(1);
    getMockEndpoint("mock:result").expectedHeaderReceived("foo", "changed");
    template.sendBody("direct:start", "Bye World");
    assertMockEndpointsSatisfied();
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Started", state);
}
Also used : Attribute(javax.management.Attribute) ManagedAttribute(org.apache.camel.api.management.ManagedAttribute) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 90 with Attribute

use of javax.management.Attribute in project camel by apache.

the class ManagedRouteContextTracerTest method testRouteTracing.

public void testRouteTracing() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on1 = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route1\"");
    ObjectName on2 = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route2\"");
    // with tracing
    MockEndpoint traced = getMockEndpoint("mock:traced");
    traced.setExpectedMessageCount(2);
    MockEndpoint result = getMockEndpoint("mock:result");
    result.setExpectedMessageCount(1);
    MockEndpoint foo = getMockEndpoint("mock:foo");
    foo.setExpectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    template.sendBody("direct:foo", "Hello World");
    assertMockEndpointsSatisfied();
    // should be enabled for route 1
    Boolean tracing = (Boolean) mbeanServer.getAttribute(on1, "Tracing");
    assertEquals("Tracing should be enabled for route 1", true, tracing.booleanValue());
    // should be disabled for route 2
    Boolean tracing2 = (Boolean) mbeanServer.getAttribute(on2, "Tracing");
    assertEquals("Tracing should be disabled for route 2", false, tracing2.booleanValue());
    // now enable tracing on route 2
    mbeanServer.setAttribute(on2, new Attribute("Tracing", Boolean.TRUE));
    // with tracing
    traced.reset();
    traced.setExpectedMessageCount(1);
    result.reset();
    result.setExpectedMessageCount(0);
    foo.reset();
    foo.setExpectedMessageCount(1);
    template.sendBody("direct:foo", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Attribute(javax.management.Attribute) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

Attribute (javax.management.Attribute)157 ObjectName (javax.management.ObjectName)94 MBeanServer (javax.management.MBeanServer)56 AttributeList (javax.management.AttributeList)46 Test (org.junit.Test)38 ReflectionException (javax.management.ReflectionException)29 MBeanException (javax.management.MBeanException)25 HashMap (java.util.HashMap)23 InstanceNotFoundException (javax.management.InstanceNotFoundException)22 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)21 AttributeNotFoundException (javax.management.AttributeNotFoundException)20 MBeanServerConnection (javax.management.MBeanServerConnection)15 MBeanInfo (javax.management.MBeanInfo)14 JMXConnector (javax.management.remote.JMXConnector)13 RuntimeOperationsException (javax.management.RuntimeOperationsException)12 List (java.util.List)10 BacklogTracerEventMessage (org.apache.camel.api.management.mbean.BacklogTracerEventMessage)10 IOException (java.io.IOException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ArrayList (java.util.ArrayList)9