Search in sources :

Example 11 with QueryExp

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

the class ManagedResetIncludeProcessorsTest method testReset.

public void testReset() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    QueryExp queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("first"));
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    // send in 5 messages
    template.sendBody("direct:start", "A");
    template.sendBody("direct:start", "B");
    template.sendBody("direct:start", "C");
    template.sendBody("direct:start", "D");
    template.sendBody("direct:start", "E");
    // and 1 for the 2nd route
    template.sendBody("direct:baz", "F");
    assertMockEndpointsSatisfied();
    // should be 5 on the route
    Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(5, completed.longValue());
    // and on the processors as well
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
    assertEquals(3, set.size());
    for (ObjectName name : set) {
        completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
        assertEquals(5, completed.longValue());
    }
    // reset which should reset all processors also
    mbeanServer.invoke(on, "reset", new Object[] { true }, new String[] { "boolean" });
    // should be 0 on the route
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(0, completed.longValue());
    // and on the processors as well
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
    assertEquals(3, set.size());
    for (ObjectName name : set) {
        completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
        assertEquals(0, completed.longValue());
    }
    // test that the 2nd route is untouched, as we only reset the first route
    queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("second"));
    set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
    assertEquals(1, set.size());
    on = set.iterator().next();
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(1, completed.longValue());
    // and on the processors as well
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
    assertEquals(1, set.size());
    for (ObjectName name : set) {
        completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
        assertEquals(1, completed.longValue());
    }
}
Also used : QueryExp(javax.management.QueryExp) StringValueExp(javax.management.StringValueExp) AttributeValueExp(javax.management.AttributeValueExp) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 12 with QueryExp

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

the class ManagedResetIncludeRoutesTest method testReset.

public void testReset() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    QueryExp queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("first"));
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    // send in 5 messages
    template.sendBody("direct:start", "A");
    template.sendBody("direct:start", "B");
    template.sendBody("direct:start", "C");
    template.sendBody("direct:start", "D");
    template.sendBody("direct:start", "E");
    // and 1 for the 2nd route
    template.sendBody("direct:baz", "F");
    assertMockEndpointsSatisfied();
    // should be 5 on the route
    Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(5, completed.longValue());
    // and on the processors as well
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
    assertEquals(3, set.size());
    for (ObjectName name : set) {
        completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
        assertEquals(5, completed.longValue());
    }
    // reset which should reset all routes also
    ObjectName ctx = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
    mbeanServer.invoke(ctx, "reset", new Object[] { true }, new String[] { "boolean" });
    // should be 0 on the route
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(0, completed.longValue());
    // and on the processors as well
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
    assertEquals(3, set.size());
    for (ObjectName name : set) {
        completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
        assertEquals(0, completed.longValue());
    }
    // test that the 2nd route is also reset
    queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("second"));
    set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
    assertEquals(1, set.size());
    on = set.iterator().next();
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(0, completed.longValue());
    // and on the processors as well
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
    assertEquals(1, set.size());
    for (ObjectName name : set) {
        completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
        assertEquals(0, completed.longValue());
    }
}
Also used : QueryExp(javax.management.QueryExp) StringValueExp(javax.management.StringValueExp) AttributeValueExp(javax.management.AttributeValueExp) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 13 with QueryExp

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

the class MBeanServerConnectionRule method getProxyMBean.

/**
   * Retrieve a new proxy MBean
   *
   * @return A new proxy MBean of the same type with which the class was constructed
   */
public <T> T getProxyMBean(Class<T> proxyClass, String beanQueryName) throws MalformedObjectNameException, IOException {
    ObjectName name = null;
    QueryExp query = null;
    if (proxyClass != null) {
        query = Query.isInstanceOf(Query.value(proxyClass.getName()));
    }
    if (beanQueryName != null) {
        name = ObjectName.getInstance(beanQueryName);
    }
    Set<ObjectInstance> beans = con.queryMBeans(name, query);
    assertEquals("failed to find only one instance of type " + proxyClass.getName() + " with name " + beanQueryName, 1, beans.size());
    return JMX.newMXBeanProxy(con, ((ObjectInstance) beans.toArray()[0]).getObjectName(), proxyClass);
}
Also used : QueryExp(javax.management.QueryExp) ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName)

Example 14 with QueryExp

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

the class LauncherLifecycleCommandsDUnitTest method getMemberId.

protected static String getMemberId(final String jmxManagerHost, final int jmxManagerPort, final String memberName) throws Exception {
    JMXConnector connector = null;
    try {
        connector = JMXConnectorFactory.connect(new JMXServiceURL(String.format("service:jmx:rmi://%1$s/jndi/rmi://%1$s:%2$d/jmxrmi", jmxManagerHost, jmxManagerPort)));
        MBeanServerConnection connection = connector.getMBeanServerConnection();
        ObjectName objectNamePattern = ObjectName.getInstance("GemFire:type=Member,*");
        QueryExp query = Query.eq(Query.attr("Name"), Query.value(memberName));
        Set<ObjectName> objectNames = connection.queryNames(objectNamePattern, query);
        assertNotNull(objectNames);
        assertFalse(objectNames.isEmpty());
        assertEquals(1, objectNames.size());
        // final ObjectName objectName = ObjectName.getInstance("GemFire:type=Member,Name=" +
        // memberName);
        ObjectName objectName = objectNames.iterator().next();
        return ObjectUtils.toString(connection.getAttribute(objectName, "Id"));
    } finally {
        IOUtils.close(connector);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) QueryExp(javax.management.QueryExp) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 15 with QueryExp

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

the class MXBeanProvider method getMemberMXBean.

public static MemberMXBean getMemberMXBean(final String serviceName, final String member) throws IOException {
    assertState(Gfsh.isCurrentInstanceConnectedAndReady(), "Gfsh must be connected in order to get proxy to a GemFire Member MBean.");
    MemberMXBean memberBean = null;
    try {
        String objectNamePattern = ManagementConstants.OBJECTNAME__PREFIX;
        objectNamePattern += (org.apache.geode.internal.lang.StringUtils.isBlank(serviceName) ? org.apache.geode.internal.lang.StringUtils.EMPTY : "service=" + serviceName + org.apache.geode.internal.lang.StringUtils.COMMA_DELIMITER);
        objectNamePattern += "type=Member,*";
        // NOTE throws a MalformedObjectNameException, however, this should not happen since the
        // ObjectName is constructed
        // here in a conforming pattern
        final ObjectName objectName = ObjectName.getInstance(objectNamePattern);
        final QueryExp query = Query.or(Query.eq(Query.attr("Name"), Query.value(member)), Query.eq(Query.attr("Id"), Query.value(member)));
        final Set<ObjectName> memberObjectNames = Gfsh.getCurrentInstance().getOperationInvoker().queryNames(objectName, query);
        if (!memberObjectNames.isEmpty()) {
            memberBean = Gfsh.getCurrentInstance().getOperationInvoker().getMBeanProxy(memberObjectNames.iterator().next(), MemberMXBean.class);
        }
    } catch (MalformedObjectNameException e) {
        Gfsh.getCurrentInstance().logSevere(e.getMessage(), e);
    }
    return memberBean;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) QueryExp(javax.management.QueryExp) MemberMXBean(org.apache.geode.management.MemberMXBean) ObjectName(javax.management.ObjectName)

Aggregations

QueryExp (javax.management.QueryExp)21 ObjectName (javax.management.ObjectName)18 MBeanServer (javax.management.MBeanServer)7 Test (org.junit.Test)5 AttributeValueExp (javax.management.AttributeValueExp)3 StringValueExp (javax.management.StringValueExp)3 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 MBeanException (javax.management.MBeanException)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 ObjectInstance (javax.management.ObjectInstance)2 ReflectionException (javax.management.ReflectionException)2 JMXConnector (javax.management.remote.JMXConnector)2 JMXServiceURL (javax.management.remote.JMXServiceURL)2 JmxReporter (com.codahale.metrics.JmxReporter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 URI (java.net.URI)1