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);
}
}
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;
}
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());
}
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());
}
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);
}
Aggregations