modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java | 30 +++++
modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java | 56 ++++++++--
modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ProxyInfoTest.java | 23 +++-
modules/plugins/mod-cluster/src/test/resources/proxy_config/proxy_config_2.txt | 16 ++
4 files changed, 111 insertions(+), 14 deletions(-)
New commits:
commit ae2f827b434bb95c2bcf76f7d5a3e1e07f910d90
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Mon Jul 11 13:23:22 2011 -0500
Added availability attribute for contexts. Also improved unit test and coverage.
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 922197a..8512ed5 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
@@ -21,6 +21,7 @@ package org.rhq.plugins.modcluster;
import org.mc4j.ems.connection.bean.EmsBean;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.plugins.jmx.MBeanResourceComponent;
@@ -36,18 +37,43 @@ public class ContextComponent extends MBeanResourceComponent<MBeanResourceCompon
}
@Override
+ public AvailabilityType getAvailability() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getEmsBean().getClass().getClassLoader());
+ String rawProxyInfo = (String) getEmsBean().getAttribute("proxyInfo").refresh().toString();
+ ProxyInfo proxyInfo = new ProxyInfo(rawProxyInfo);
+
+ ProxyInfo.Context context = ProxyInfo.Context.fromString(resourceContext.getResourceKey());
+
+ ProxyInfo.Context currentContext = proxyInfo.getAvailableContexts().get(
+ proxyInfo.getAvailableContexts().indexOf(context));
+
+ if (currentContext.isEnabled()) {
+ return AvailabilityType.UP;
+ }
+
+ return AvailabilityType.DOWN;
+ } catch (Exception e) {
+ log.info(e);
+ return AvailabilityType.DOWN;
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
+ }
+
+ @Override
public OperationResult invokeOperation(String name, Configuration parameters) throws Exception {
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());
Object resultObject = getEmsBean().getOperation(name).invoke(
- new Object[] { context.host, context.path });
+ new Object[] { context.getHost(), context.getPath() });
return new OperationResult(String.valueOf(resultObject));
} finally {
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 40b24f9..c517364 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
@@ -50,9 +50,7 @@ public class ProxyInfo {
String host = vhostPieces[1].trim();
host = host.substring(host.indexOf(":") + 1).trim();
- System.out.println(identifier + "--" + host);
availableVHosts.put(identifier, new Vhost(identifier, host));
-
}
Pattern contextPattern = Pattern.compile("Context.*[\n|}]");
@@ -65,9 +63,14 @@ public class ProxyInfo {
String identifier = contextPieces[0];
identifier = identifier.substring(identifier.indexOf("[") + 1, identifier.indexOf("]"));
identifier = identifier.substring(0, identifier.lastIndexOf(":"));
+
+ String rawIsEnabled = contextPieces[2];
+ rawIsEnabled = rawIsEnabled.substring(rawIsEnabled.indexOf(':') + 1).trim();
+ boolean isEnabled = rawIsEnabled.equals("ENABLED") ? true : false;
+
Vhost relatedVhost = availableVHosts.get(identifier);
- availableContexts.add(new Context(relatedVhost.getHost(), actualContext));
+ availableContexts.add(new Context(relatedVhost.getHost(), actualContext, isEnabled));
}
}
@@ -95,12 +98,18 @@ public class ProxyInfo {
}
public static class Context {
- String path;
- String host;
+ private String path;
+ private String host;
+ private boolean isEnabled;
public Context(String host, String path) {
+ this(path, host, false);
+ }
+
+ public Context(String host, String path, boolean isEnabled) {
this.path = path;
this.host = host;
+ this.isEnabled = isEnabled;
}
public String getPath() {
@@ -111,14 +120,49 @@ public class ProxyInfo {
return host;
}
+ public boolean isEnabled() {
+ return isEnabled;
+ }
+
@Override
public String toString() {
return host + ":" + path;
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((host == null) ? 0 : host.hashCode());
+ result = prime * result + ((path == null) ? 0 : path.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Context other = (Context) obj;
+ if (host == null) {
+ if (other.host != null)
+ return false;
+ } else if (!host.equals(other.host))
+ return false;
+ if (path == null) {
+ if (other.path != null)
+ return false;
+ } else if (!path.equals(other.path))
+ return false;
+ return true;
+ }
+
public static Context fromString(String stringRepresentation) {
String part[] = stringRepresentation.trim().split(":");
- return new Context(part[0], part[1]);
+ return new Context(part[1], part[0]);
}
}
}
\ No newline at end of file
diff --git a/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ProxyInfoTest.java b/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ProxyInfoTest.java
index be5e987..41bf26a 100644
--- a/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ProxyInfoTest.java
+++ b/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ProxyInfoTest.java
@@ -37,15 +37,26 @@ public class ProxyInfoTest {
@Test
public void testProxyInfo() throws IOException {
- String testConfiguration = readConfigFile("/proxy_config/proxy_config_1.txt");
+ String[] availableFiles = new String[] { "/proxy_config/proxy_config_1.txt", "/proxy_config/proxy_config_2.txt" };
- ProxyInfo proxyInfo = new ProxyInfo(testConfiguration);
+ for (String testConfigurationFile : availableFiles) {
+ String testConfiguration = readConfigFile(testConfigurationFile);
+ ProxyInfo proxyInfo = new ProxyInfo(testConfiguration);
- for (ProxyInfo.Context context : proxyInfo.getAvailableContexts()) {
- log.info(context.toString());
- }
+ for (ProxyInfo.Context context : proxyInfo.getAvailableContexts()) {
+ log.info(context.toString() + " - " + context.isEnabled());
+
+ log.info(proxyInfo.getAvailableContexts().indexOf(context));
+
+ assert (proxyInfo.getAvailableContexts().indexOf(context) != -1) : "Equals and hash functions not implemented correctly for "
+ + ProxyInfo.Context.class.getCanonicalName();
- assert (proxyInfo.getAvailableContexts().size() != 0) : "Raw proxy info parsing failed!";
+ assert (context.equals(ProxyInfo.Context.fromString(context.toString())) == true) : "fromString and toString are not equivalent for:"
+ + ProxyInfo.Context.class.getCanonicalName();
+ }
+
+ assert (proxyInfo.getAvailableContexts().size() != 0) : "Raw proxy info parsing failed!";
+ }
}
private String readConfigFile(String filePath) throws IOException {
diff --git a/modules/plugins/mod-cluster/src/test/resources/proxy_config/proxy_config_2.txt b/modules/plugins/mod-cluster/src/test/resources/proxy_config/proxy_config_2.txt
new file mode 100644
index 0000000..573967a
--- /dev/null
+++ b/modules/plugins/mod-cluster/src/test/resources/proxy_config/proxy_config_2.txt
@@ -0,0 +1,16 @@
+{mobile-work/192.168.1.40:6666=Node: [1],Name: 4e6189af-0502-3305-8ff3-fad7fee8b516,Balancer: mycluster,LBGroup: ,Host: 127.0.0.1,Port: 8009,Type: ajp,Flushpackets: Off,Flushwait: 10,Ping: 10,Smax: 26,Ttl: 60,Elected: 3690,Read: 27864911,Transfered: 0,Connected: 0,Load: 100
+Node: [2],Name: node2,Balancer: mycluster,LBGroup: ,Host: 127.0.0.1,Port: 8009,Type: ajp,Flushpackets: Off,Flushwait: 10,Ping: 10,Smax: 26,Ttl: 60,Elected: 148,Read: 57994,Transfered: 0,Connected: 0,Load: 100
+Vhost: [1:1:1], Alias: test-agent-1
+Vhost: [2:1:2], Alias: remote-agent-2
+Context: [1:1:1], Context: /invoker, Status: DISABLED
+Context: [1:1:2], Context: /loaddemo, Status: DISABLED
+Context: [1:1:3], Context: /jbossws, Status: DISABLED
+Context: [1:1:4], Context: /juddi, Status: DISABLED
+Context: [1:1:5], Context: /jbossmq-httpil, Status: DISABLED
+Context: [1:1:6], Context: /web-console, Status: DISABLED
+Context: [1:1:7], Context: /jmx-console, Status: DISABLED
+Context: [1:1:8], Context: /, Status: DISABLED
+Context: [2:1:9], Context: /, Status: ENABLED
+Context: [2:1:10], Context: /loaddemo, Status: ENABLED
+Context: [2:1:11], Context: /juddi, Status: ENABLED
+Context: [2:1:12], Context: /invoker, Status: ENABLED}
\ No newline at end of file