[rhq] modules/plugins
Heiko W. Rupp
pilhuhn at fedoraproject.org
Wed Aug 1 20:34:39 UTC 2012
modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/ObjectNameQueryUtility.java | 75 +++++++
modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/ParentDefinedJMXServerNamingUtility.java | 40 +++
modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/ObjectNameQueryUtilityDelegateTest.java | 106 ++++++++++
3 files changed, 221 insertions(+)
New commits:
commit 4f60260d2afe019943f23c64cdaf14f1f11c3d53
Author: Heiko W. Rupp <hwr at redhat.com>
Date: Wed Aug 1 16:34:02 2012 -0400
BZ 845118 provide delegates for the tow classes that were moved to util/ as other plugins may still rely on the old package structure.
diff --git a/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/ObjectNameQueryUtility.java b/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/ObjectNameQueryUtility.java
new file mode 100644
index 0000000..bc4b264
--- /dev/null
+++ b/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/ObjectNameQueryUtility.java
@@ -0,0 +1,75 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.plugins.jmx;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.rhq.core.domain.configuration.Configuration;
+
+/**
+ * Delegate for the old version of the class which got moved to util package
+ * @author Heiko W. Rupp
+ * @deprecated Use the version in the util package
+ */
+public class ObjectNameQueryUtility {
+
+ private org.rhq.plugins.jmx.util.ObjectNameQueryUtility onu;
+
+ public ObjectNameQueryUtility(String objectNameQueryTemplate) {
+ onu = new org.rhq.plugins.jmx.util.ObjectNameQueryUtility(objectNameQueryTemplate);
+ }
+
+ public ObjectNameQueryUtility(String objectNameQueryTemplate, Configuration parentConfiguration) {
+ onu = new org.rhq.plugins.jmx.util.ObjectNameQueryUtility(objectNameQueryTemplate,parentConfiguration);
+ }
+
+ public boolean setMatchedKeyValues(Map<String, String> keyProperties) {
+ return onu.setMatchedKeyValues(keyProperties);
+ }
+
+ public String formatMessage(String message) {
+ return onu.formatMessage(message);
+ }
+
+ public void resetVariables() {
+ onu.resetVariables();
+ }
+
+ public String getQueryTemplate() {
+ return onu.getQueryTemplate();
+ }
+
+ public Map<String, String> getVariableProperties() {
+ return onu.getVariableProperties();
+ }
+
+ public Map<String, String> getVariableValues() {
+ return onu.getVariableValues();
+ }
+
+ public String getTranslatedQuery() {
+ return onu.getTranslatedQuery();
+ }
+
+ public boolean isContainsExtraKeyProperties(Set<String> strings) {
+ return onu.isContainsExtraKeyProperties(strings);
+ }
+}
diff --git a/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/ParentDefinedJMXServerNamingUtility.java b/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/ParentDefinedJMXServerNamingUtility.java
new file mode 100644
index 0000000..fccb0ab
--- /dev/null
+++ b/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/ParentDefinedJMXServerNamingUtility.java
@@ -0,0 +1,40 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.plugins.jmx;
+
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+
+/**
+ * Delegate for the original version of this
+ * class that got moved to util/
+ * @deprecated Use the version of the class in the util Package
+ * @see org.rhq.plugins.jmx.util.ParentDefinedJMXServerNamingUtility
+ * @author Heiko W. Rupp
+ */
+ at Deprecated
+public class ParentDefinedJMXServerNamingUtility {
+ public static final String PROPERTY_CHILD_JMX_SERVER_NAME = "childJmxServerName";
+
+ /** @deprecated use the version in util package instead */
+ @Deprecated
+ public static String getJVMName(ResourceDiscoveryContext<?> context) {
+ return org.rhq.plugins.jmx.util.ParentDefinedJMXServerNamingUtility.getJVMName(context);
+ }
+}
diff --git a/modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/ObjectNameQueryUtilityDelegateTest.java b/modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/ObjectNameQueryUtilityDelegateTest.java
new file mode 100644
index 0000000..58d11a1
--- /dev/null
+++ b/modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/ObjectNameQueryUtilityDelegateTest.java
@@ -0,0 +1,106 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.plugins.jmx.test;
+
+import java.util.Collections;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.testng.annotations.Test;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.plugins.jmx.ObjectNameQueryUtility;
+
+/**
+ * This test explicitly tests the delegate for the ObjectNameQueryUtility.
+ * The Utility itself got moved into the util package. To be backward compatible,
+ * we need to have a delegate
+ */
+public class ObjectNameQueryUtilityDelegateTest {
+ @Test
+ public void testObjectNameQueryUtility() throws MalformedObjectNameException {
+ ObjectNameQueryUtility onqu = null;
+ onqu = new ObjectNameQueryUtility("java.lang:type=MemoryPool,name=Code Cache");
+ assert onqu.getQueryTemplate().equals("java.lang:type=MemoryPool,name=Code Cache");
+
+ onqu = new ObjectNameQueryUtility("java.lang:type=MemoryPool,name=%name%");
+ assert onqu.getTranslatedQuery().equals("java.lang:type=MemoryPool,*");
+ assert onqu.getVariableProperties().size() == 1;
+ assert onqu.getVariableProperties().get("name").equals("name");
+
+ onqu = new ObjectNameQueryUtility("java.lang:type=Threading");
+
+ onqu = new ObjectNameQueryUtility("java.lang:type=%foo%");
+ assert onqu.getTranslatedQuery().equals("java.lang:*");
+ assert onqu.getVariableProperties().size() == 1;
+ assert onqu.getVariableProperties().get("type").equals("foo");
+
+ onqu = new ObjectNameQueryUtility("jboss.esb.*:service=Queue,name=%name%");
+ assert onqu.getTranslatedQuery().equals("jboss.esb.*:service=Queue,*");
+ assert onqu.getVariableProperties().size() == 1;
+ assert onqu.getVariableProperties().get("name").equals("name");
+ ObjectName testON = new ObjectName(
+ "jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw");
+ onqu.setMatchedKeyValues(testON.getKeyPropertyList());
+ String formulatedMessageTemplate = "Name of queue: {name}";
+ assert onqu.formatMessage(formulatedMessageTemplate).equals("Name of queue: quickstart_helloworld_Request_gw");
+
+ onqu = new ObjectNameQueryUtility("java.lang:type=%MyType%,name=%MyName%,app=%MyApp%,foo=%MyFoo%");
+ assert onqu.getTranslatedQuery().equals("java.lang:*");
+ assert onqu.getVariableProperties().size() == 4;
+ testON = new ObjectName("java.lang:type=A,name=B,app=C,foo=D");
+ onqu.setMatchedKeyValues(testON.getKeyPropertyList());
+ formulatedMessageTemplate = "Type: {MyType}, Name: {MyName}, App: {MyApp}, Foo: {MyFoo}";
+ assert onqu.formatMessage(formulatedMessageTemplate).equals("Type: A, Name: B, App: C, Foo: D");
+
+ Configuration c = new Configuration();
+ c.put(new PropertySimple("e", "foo"));
+ c.put(new PropertySimple("g", "bar"));
+ onqu = new ObjectNameQueryUtility("a:b=c,d={e},f={g}", c);
+ System.out.println("Template: " + onqu.getQueryTemplate());
+ assert onqu.getQueryTemplate().equals("a:b=c,d=foo,f=bar");
+
+ // Test some very long replacement tokens inspired by BZ 828596
+ onqu = new ObjectNameQueryUtility("*:type=HttpMetricInspector,name=%name%");
+ assert onqu.getQueryTemplate().equals("*:type=HttpMetricInspector,name=%name%");
+ assert onqu.getVariableProperties().size() == 1;
+ assert onqu.getVariableProperties().get("name").equals("name");
+ testON = new ObjectName("FooBarABCDEFGHIJKLMNOPQRSTUVWXYZ:type=HttpMetricInspector,name=ABCDEFGHIJKLMNOPQRSTUVWXYZöABCDEFGHIJKLMNOPQRSTUVWXYZ");
+ onqu.setMatchedKeyValues(testON.getKeyPropertyList());
+ formulatedMessageTemplate = "Http metrics for endpoint {name}";
+ String res = onqu.formatMessage(formulatedMessageTemplate);
+ assert res.equals("Http metrics for endpoint ABCDEFGHIJKLMNOPQRSTUVWXYZöABCDEFGHIJKLMNOPQRSTUVWXYZ") : res;
+
+
+ }
+
+ @Test
+ public void testObjectNameQueryUtilityFiltering() throws MalformedObjectNameException {
+ ObjectNameQueryUtility onqu = null;
+
+ onqu = new ObjectNameQueryUtility("java.lang:type=MemoryPool,name=%foo%");
+ assert !onqu.isContainsExtraKeyProperties(Collections.singleton("type"));
+ assert !onqu.isContainsExtraKeyProperties(Collections.singleton("name"));
+ assert onqu.isContainsExtraKeyProperties(Collections.singleton("splat"));
+
+ }
+
+}
\ No newline at end of file
More information about the rhq-commits
mailing list