Search in sources :

Example 16 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 17 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)

Example 18 with QueryExp

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

the class QueryParameterSourceJUnitTest method testSerialization.

@Test
public void testSerialization() throws ClassNotFoundException, IOException, MalformedObjectNameException {
    final ObjectName expectedObjectName = ObjectName.getInstance("GemFire:type=Member,*");
    final QueryExp expectedQueryExpression = Query.or(Query.eq(Query.attr("name"), Query.value("myName")), Query.eq(Query.attr("id"), Query.value("myId")));
    final QueryParameterSource expectedQuery = new QueryParameterSource(expectedObjectName, expectedQueryExpression);
    assertNotNull(expectedQuery);
    assertSame(expectedObjectName, expectedQuery.getObjectName());
    assertSame(expectedQueryExpression, expectedQuery.getQueryExpression());
    final byte[] queryBytes = IOUtils.serializeObject(expectedQuery);
    assertNotNull(queryBytes);
    assertTrue(queryBytes.length != 0);
    final Object queryObj = IOUtils.deserializeObject(queryBytes);
    assertTrue(queryObj instanceof QueryParameterSource);
    final QueryParameterSource actualQuery = (QueryParameterSource) queryObj;
    assertNotSame(expectedQuery, actualQuery);
    assertNotNull(actualQuery.getObjectName());
    assertEquals(expectedQuery.getObjectName().toString(), actualQuery.getObjectName().toString());
    assertNotNull(actualQuery.getQueryExpression());
    assertEquals(expectedQuery.getQueryExpression().toString(), actualQuery.getQueryExpression().toString());
}
Also used : QueryExp(javax.management.QueryExp) ObjectName(javax.management.ObjectName) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 19 with QueryExp

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

the class QueryParameterSourceJUnitTest method testCreateQueryParameterSource.

@Test
public void testCreateQueryParameterSource() throws MalformedObjectNameException {
    final ObjectName expectedObjectName = ObjectName.getInstance("GemFire:type=Member,*");
    final QueryExp expectedQueryExpression = Query.eq(Query.attr("id"), Query.value("12345"));
    final QueryParameterSource query = new QueryParameterSource(expectedObjectName, expectedQueryExpression);
    assertNotNull(query);
    assertSame(expectedObjectName, query.getObjectName());
    assertSame(expectedQueryExpression, query.getQueryExpression());
}
Also used : QueryExp(javax.management.QueryExp) ObjectName(javax.management.ObjectName) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 20 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)

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