modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java | 61 ++-------- modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java | 8 - modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java | 33 ++++- modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml | 2 modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java | 19 ++- 5 files changed, 64 insertions(+), 59 deletions(-)
New commits: commit 060cf8983b9230adf3f26c936d0fe6c8d1966bd1 Author: Stefan Negrea snegrea@redhat.com Date: Tue Jul 5 23:31:24 2011 -0500
All the context dependent operations are now passed for execution to the parent MBean. The operation arguments are parsed from the proxyInfo MBean property.
diff --git a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java index f73a151..922197a 100644 --- a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java +++ b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java @@ -1,24 +1,20 @@ /* - * Jopr Management Platform + * RHQ Management Platform * Copyright (C) 2005-2008 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, version 2, as - * published by the Free Software Foundation, and/or the GNU Lesser - * General Public License, version 2.1, also as published by the Free - * Software Foundation. + * 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 and the GNU Lesser General Public License - * for more details. + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * and the GNU Lesser General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.rhq.plugins.modcluster;
@@ -29,10 +25,9 @@ import org.rhq.core.pluginapi.operation.OperationResult; import org.rhq.plugins.jmx.MBeanResourceComponent;
/** - * Manages a Hibernate Entity. + * Manages a mod_cluster context entity. * - * @author Greg Hinkle - * @author John Mazzitelli + * @author Stefan Negrea */ public class ContextComponent extends MBeanResourceComponent<MBeanResourceComponent> { @Override @@ -42,46 +37,24 @@ public class ContextComponent extends MBeanResourceComponent<MBeanResourceCompon
@Override public OperationResult invokeOperation(String name, Configuration parameters) throws Exception { - if ("enableContext".equals(name)) { - //String[] queryStrings = (String[]) getEmsBean().getAttribute("Queries").refresh(); - OperationResult result = new OperationResult(); - result.setSimpleResult("This works!"); - /*PropertyList queries = new PropertyList("queries"); - result.getComplexResults().put(queries);*/ + if ("enableContext".equals(name) || "disableContext".equals(name) || "stopContext".equals(name)) { + + ProxyInfo.Context context = ProxyInfo.Context.fromString(resourceContext.getResourceKey()); + System.out.println(context.toString());
ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { - /*Thread.currentThread().setContextClassLoader(getEmsBean().getClass().getClassLoader()); - for (String queryString : queryStrings) { - Object queryStatistics = getEmsBean().getOperation("getQueryStatistics").invoke( - new Object[] { queryString }); - - Long executionCount = (Long) queryStatistics.getClass().getMethod("getExecutionCount") - .invoke(queryStatistics); - Long executionRowCount = (Long) queryStatistics.getClass().getMethod("getExecutionRowCount") - .invoke(queryStatistics); - Long executionMinTime = (Long) queryStatistics.getClass().getMethod("getExecutionMinTime") - .invoke(queryStatistics); - Long executionMaxTime = (Long) queryStatistics.getClass().getMethod("getExecutionMaxTime") - .invoke(queryStatistics); - Long executionAvgTime = (Long) queryStatistics.getClass().getMethod("getExecutionAvgTime") - .invoke(queryStatistics); - - PropertyMap query = new PropertyMap("query", new PropertySimple("query", queryString), - new PropertySimple("executionCount", executionCount), new PropertySimple("executionRowCount", - executionRowCount), new PropertySimple("executionMinTime", executionMinTime), - new PropertySimple("executionMaxTime", executionMaxTime), new PropertySimple( - "executionAvgTime", executionAvgTime)); + Thread.currentThread().setContextClassLoader(getEmsBean().getClass().getClassLoader());
- queries.add(query); - }*/ + Object resultObject = getEmsBean().getOperation(name).invoke( + new Object[] { context.host, context.path });
- return result; + return new OperationResult(String.valueOf(resultObject)); } finally { Thread.currentThread().setContextClassLoader(cl); } }
- return super.invokeOperation(name, parameters); + throw new Exception("Operation " + name + " not available mod_cluster_context service"); } } \ No newline at end of file diff --git a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java index 90e5c6b..4b3adcd 100644 --- a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java +++ b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java @@ -33,11 +33,15 @@ import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext; import org.rhq.plugins.jmx.MBeanResourceComponent;
/** - * Discovers hibernate entities from a hibernate stats mbean + * Discovers mod_cluster contexts from the proxyInfo mbean property. * - * @author Greg Hinkle + * @author Stefan Negrea */ public class ContextDiscoveryComponent implements ResourceDiscoveryComponent<MBeanResourceComponent> { + + /* (non-Javadoc) + * @see org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent#discoverResources(org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext) + */ public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<MBeanResourceComponent> context) { Set<DiscoveredResourceDetails> entities = new HashSet<DiscoveredResourceDetails>();
diff --git a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java index 15a9a68..9cb6b86 100644 --- a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java +++ b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java @@ -16,7 +16,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - package org.rhq.plugins.modcluster;
import java.util.ArrayList; @@ -25,16 +24,17 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;
+/** + * Simple parser for the raw proxy information provided by mod_cluster. + * + * @author Stefan Negrea + */ public class ProxyInfo {
private List<Context> availableContexts = new ArrayList<ProxyInfo.Context>();
public ProxyInfo(String rawProxyInfo) {
- System.out.println("--------------------------------------"); - System.out.println(rawProxyInfo); - System.out.println("--------------------------------------"); - Pattern test = Pattern.compile("Context.*\n"); Matcher m = test.matcher(rawProxyInfo); while (m.find()) { @@ -42,7 +42,7 @@ public class ProxyInfo { String[] contextPieces = rawContext.split(","); String actualContext = contextPieces[1].substring(contextPieces[1].indexOf("/")).trim();
- availableContexts.add(new Context(actualContext, "localHost")); + availableContexts.add(new Context(actualContext, "localhost")); } }
@@ -50,12 +50,11 @@ public class ProxyInfo { return Collections.unmodifiableList(availableContexts); }
- public class Context { + public static class Context { String path; String host;
public Context(String path, String host) { - super(); this.path = path; this.host = host; } @@ -80,5 +79,23 @@ public class ProxyInfo { public String toString() { return "Context [path=" + path + ", host=" + host + "]"; } + + public static Context fromString(String stringRepresentation) { + stringRepresentation = stringRepresentation.substring(stringRepresentation.indexOf('[') + 1); + stringRepresentation = stringRepresentation.substring(0, stringRepresentation.indexOf(']')); + stringRepresentation = stringRepresentation.trim(); + + String host = null; + String path = null; + for (String part : stringRepresentation.split(",")) { + part = part.trim(); + if (part.startsWith("path=")) { + path = part.substring(5).trim(); + } else if (part.startsWith("host=")) { + host = part.substring(5).trim(); + } + } + return new Context(path, host); + } } } \ No newline at end of file diff --git a/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml index 084165e..be4b25b 100644 --- a/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml +++ b/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml @@ -45,6 +45,8 @@
<resource-configuration> <c:simple-property name="stickySessions" type="boolean" description="Enables sticky sessions."/> + <c:simple-property name="stickySessionRemove" type="boolean" description="Remove session when the request cannot be routed to the right node."/> + <c:simple-property name="advertise" type="boolean" description="Enable autodiscovery of httpd servers."/> </resource-configuration>
<service name="mod_cluster_context" diff --git a/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java b/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java index deceb70..0d16e92 100644 --- a/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java +++ b/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java @@ -140,8 +140,14 @@ public class ModclusterPluginTest { assert (resources.size() != 0) : "No mod_cluster or related instances found.";
if (resources.size() != 0) { - testResourceMeasurement((Resource) resources.toArray()[0]); - testContextOperations((Resource) resources.toArray()[1]); + for (Object objectResource : resources.toArray()) { + Resource resource = (Resource) objectResource; + if (resource.getResourceType().getName().equals("mod_cluster")) { + testResourceMeasurement(resource); + } else { + testContextOperations(resource); + } + } } }
@@ -175,9 +181,12 @@ public class ModclusterPluginTest { .getResourceComponent(resource);
if (resourceComponent instanceof OperationFacet) { - OperationResult result = ((OperationFacet) resourceComponent).invokeOperation("enableContext", null); - log.info("Result of operation " + "enableContext" + " was: " + result.getSimpleResult()); - + try { + OperationResult result = ((OperationFacet) resourceComponent).invokeOperation("enableContext", null); + log.info("Result of operation " + "enableContext" + " was: " + result.getSimpleResult()); + } catch (Exception e) { + log.info("Operation failed"); + } /*result = ((OperationFacet) resourceComponent).invokeOperation("disable", null); log.info("Result of operation test was: " + result.getSimpleResult());*/ }
rhq-commits@lists.fedorahosted.org