modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/CatalinaServiceComponent.java
| 93 ++++++++++
modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/LoadMetricDiscoveryComponent.java
| 24 +-
modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/config/JBossWebServerFile.java
| 51 ++++-
modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/config/ModClusterBeanFile.java
| 9
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/ServerConfigTest.java
| 24 ++
6 files changed, 178 insertions(+), 25 deletions(-)
New commits:
commit dc131685f088d8915bf2516e25a37cf916cf07e3
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Thu Aug 25 17:50:23 2011 -0500
All the node lists are zero based index. Fixing for the incorrect indexing of lists.
diff --git
a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/config/ModClusterBeanFile.java
b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/config/ModClusterBeanFile.java
index 8cff302..c2cf3a8 100644
---
a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/config/ModClusterBeanFile.java
+++
b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/config/ModClusterBeanFile.java
@@ -75,9 +75,10 @@ public class ModClusterBeanFile extends AbstractConfigurationFile {
*/
public void setPropertyValue(String propertyName, String value) {
boolean propertyFound = false;
+ NodeList nodeList = beanNode.getChildNodes();
- for (int i = 0; i < beanNode.getChildNodes().getLength(); i++) {
- Node currentNode = beanNode.getChildNodes().item(i);
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node currentNode = nodeList.item(i);
if (currentNode.getNodeName().equals("property")
&& currentNode.getAttributes().getNamedItem("name") !=
null
@@ -131,7 +132,7 @@ public class ModClusterBeanFile extends AbstractConfigurationFile {
private Node getBeanNodeByClass(String className) {
NodeList nodeList = this.getDocument().getElementsByTagName("bean");
- for (int i = 1; i < nodeList.getLength(); i++) {
+ for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getAttributes().getNamedItem("class") != null
@@ -150,7 +151,7 @@ public class ModClusterBeanFile extends AbstractConfigurationFile {
private Node getBeanNodeByName(String beanName) {
NodeList nodeList = this.getDocument().getElementsByTagName("bean");
- for (int i = 1; i < nodeList.getLength(); i++) {
+ for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getAttributes().getNamedItem("name") != null
commit d1e6d46e89fb5876446fcfe42c04cf4c48a11bce
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Thu Aug 25 17:43:08 2011 -0500
Add property persistance functionality to catalina JMX listener for mod_cluster by
saving the configuration directly into the server.xml file.
diff --git
a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/CatalinaServiceComponent.java
b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/CatalinaServiceComponent.java
new file mode 100644
index 0000000..1b390c5
--- /dev/null
+++
b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/CatalinaServiceComponent.java
@@ -0,0 +1,93 @@
+/*
+ * 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 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.modcluster;
+
+import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
+import org.rhq.core.util.exception.ThrowableUtil;
+import org.rhq.plugins.jmx.MBeanResourceComponent;
+import org.rhq.plugins.modcluster.config.JBossWebServerFile;
+
+@SuppressWarnings({ "rawtypes", "deprecation" })
+public class CatalinaServiceComponent extends MBeanResourceComponent {
+ private static final String SERVER_HOME_DIR = "serverHomeDir";
+ private static final String CONFIGURATION_FILE_RELATIVE_PATH =
"/deploy/jboss-web.deployer/server.xml";
+
+ @Override
+ public void updateResourceConfiguration(ConfigurationUpdateReport report) {
+ super.updateResourceConfiguration(report);
+
+ try {
+ saveResouceConfigurationToFile(report, true);
+ } catch (Exception e) {
+ }
+ }
+
+ private void saveResouceConfigurationToFile(ConfigurationUpdateReport report, boolean
ignoreReadOnly) {
+ ConfigurationDefinition configurationDefinition =
this.getResourceContext().getResourceType()
+ .getResourceConfigurationDefinition();
+
+ // assume we succeed - we'll set to failure if we can't set all
properties
+ report.setStatus(ConfigurationUpdateStatus.SUCCESS);
+
+ try {
+ JBossWebServerFile jbossWebServerFile = getJBossWebServerFileInstance();
+
+ for (String key : report.getConfiguration().getSimpleProperties().keySet())
{
+ PropertySimple property = report.getConfiguration().getSimple(key);
+ if (property != null) {
+ try {
+ PropertyDefinitionSimple def =
configurationDefinition.getPropertyDefinitionSimple(property
+ .getName());
+ if (!(ignoreReadOnly && def.isReadOnly())) {
+ jbossWebServerFile.setPropertyValue(property.getName(),
property.getStringValue());
+ }
+ } catch (Exception e) {
+ property.setErrorMessage(ThrowableUtil.getStackAsString(e));
+ report
+ .setErrorMessage("Failed setting resource configuration
- see property error messages for details");
+ log.info("Failure setting MBean Resource configuration value
for " + key, e);
+ }
+ }
+ }
+
+ jbossWebServerFile.saveConfigurationFile();
+ } catch (Exception e) {
+ log.debug("Unable to save mod_cluster configuration file.", e);
+ }
+ }
+
+ private JBossWebServerFile getJBossWebServerFileInstance() throws Exception {
+ ModClusterServerComponent modClusterComponent = (ModClusterServerComponent)
this.resourceContext
+ .getParentResourceComponent();
+
+ PropertySimple property =
modClusterComponent.getResourceContext().getPluginConfiguration()
+ .getSimple(SERVER_HOME_DIR);
+
+ if (property != null) {
+ String fileName = property.getStringValue() +
CONFIGURATION_FILE_RELATIVE_PATH;
+ return new JBossWebServerFile(fileName);
+ }
+
+ return null;
+ }
+}
diff --git
a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/config/JBossWebServerFile.java
b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/config/JBossWebServerFile.java
index 354fa99..45204e1 100644
---
a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/config/JBossWebServerFile.java
+++
b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/config/JBossWebServerFile.java
@@ -23,6 +23,11 @@ import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
+import org.apache.commons.lang.NotImplementedException;
+import org.w3c.dom.Attr;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/**
@@ -31,20 +36,52 @@ import org.xml.sax.SAXException;
*/
public class JBossWebServerFile extends AbstractConfigurationFile {
- public JBossWebServerFile(String fileName) throws ParserConfigurationException,
SAXException, IOException {
- super(fileName);
- // TODO Auto-generated constructor stub
+ private static final String CATALINA_LISTENER_CLASS_NAME =
"org.jboss.modcluster.catalina.ModClusterListener";
+
+ private Node listenerNode;
+
+ public JBossWebServerFile(String configurationFileName) throws
ParserConfigurationException, SAXException,
+ IOException {
+ super(configurationFileName);
+
+ listenerNode = this.getListenerNode();
}
@Override
- void setPropertyValue(String propertyName, String value) {
- // TODO Auto-generated method stub
+ public void setPropertyValue(String propertyName, String value) {
+ NamedNodeMap attributeList = listenerNode.getAttributes();
+ if (attributeList.getNamedItem(propertyName) != null && value != null) {
+ Node attributeNode = attributeList.getNamedItem(propertyName);
+ attributeNode.setTextContent(value);
+ } else if (attributeList.getNamedItem(propertyName) != null && value ==
null) {
+ attributeList.removeNamedItem(propertyName);
+ } else if (attributeList.getNamedItem(propertyName) == null && value !=
null) {
+ Attr property = this.getDocument().createAttribute(propertyName);
+ property.setValue(propertyName);
+ property.setTextContent(value);
+ attributeList.setNamedItem(property);
+ }
}
@Override
- String getPropertyValue(String propertyName) {
- // TODO Auto-generated method stub
+ public String getPropertyValue(String propertyName) {
+ throw new NotImplementedException(
+ "Property values should be retrieved from the JMX interface not from the
configuration file.");
+ }
+
+ private Node getListenerNode() {
+ NodeList nodeList =
this.getDocument().getElementsByTagName("Listener");
+
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+
+ if (node.getAttributes().getNamedItem("className") != null
+ &&
CATALINA_LISTENER_CLASS_NAME.equals(node.getAttributes().getNamedItem("className").getTextContent()))
{
+ return node;
+ }
+ }
+
return null;
}
}
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 3e523f7..dafb18f 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
@@ -325,7 +325,7 @@
</service>
<!-- End - Configuration for ModClusterService -->
- <service name="Catalina Service"
discovery="org.rhq.plugins.jmx.MBeanResourceDiscoveryComponent"
class="ModclusterServerComponent" supportsManualAdd="true"
description="Catalina Service Listener" singleton="true">
+ <service name="Catalina Service"
discovery="org.rhq.plugins.jmx.MBeanResourceDiscoveryComponent"
class="CatalinaServiceComponent" supportsManualAdd="true"
description="Catalina Service Listener" singleton="true">
<plugin-configuration>
<c:simple-property name="objectName" readOnly="true"
default="Catalina:type=ModClusterListener,*" />
diff --git
a/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ServerConfigTest.java
b/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ServerConfigTest.java
index cba5672..b8fca4c 100644
---
a/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ServerConfigTest.java
+++
b/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ServerConfigTest.java
@@ -20,12 +20,13 @@ package org.rhq.plugins.modcluster.test;
import org.testng.annotations.Test;
+import org.rhq.plugins.modcluster.config.JBossWebServerFile;
import org.rhq.plugins.modcluster.config.ModClusterBeanFile;
public class ServerConfigTest {
@Test
- public void TestConfig() {
+ public void TestModClusterConfig() {
try {
//Test simple bean configuration
@@ -57,4 +58,25 @@ public class ServerConfigTest {
}
}
+ @Test
+ public void TestJBossWebConfig() {
+
+ try {
+ //Test simple bean configuration
+ JBossWebServerFile config = new JBossWebServerFile(
+
"/home/snegrea/Downloads/jboss42/server/all/deploy/jboss-web.deployer/server.xml");
+ config.setPropertyValue("processStatusFrequency", "4");
+ config.setPropertyValue("test", "5");
+ config.setPropertyValue("test", "123");
+
+ config.setPropertyValue("test", null);
+ config.setPropertyValue("processStatusFrequency", null);
+
+ config.saveConfigurationFile();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
}
commit 616b14c59c03a04144e887c73e2c290a149c202d
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Thu Aug 25 17:35:02 2011 -0500
Moved private method at the bottom fo the file to follow standard java file
structure.
diff --git
a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/LoadMetricDiscoveryComponent.java
b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/LoadMetricDiscoveryComponent.java
index 3eb7cbe..31530d7 100644
---
a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/LoadMetricDiscoveryComponent.java
+++
b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/LoadMetricDiscoveryComponent.java
@@ -57,18 +57,6 @@ public class LoadMetricDiscoveryComponent extends
MBeanResourceDiscoveryComponen
}
/**
- * @param context
- * @param objectName
- * @return
- */
- public String getBeanConfiguredClassName(ResourceDiscoveryContext<JMXComponent>
context, String objectName) {
- EmsConnection connection =
context.getParentResourceComponent().getEmsConnection();
- EmsBean emsBean = loadBean(connection, objectName);
-
- return emsBean.getClassTypeName();
- }
-
- /**
* Loads the bean with the given object name.
*
* Subclasses are free to override this method in order to load the bean.
@@ -89,4 +77,16 @@ public class LoadMetricDiscoveryComponent extends
MBeanResourceDiscoveryComponen
}
return bean;
}
+
+ /**
+ * @param context
+ * @param objectName
+ * @return
+ */
+ private String
getBeanConfiguredClassName(ResourceDiscoveryContext<JMXComponent> context, String
objectName) {
+ EmsConnection connection =
context.getParentResourceComponent().getEmsConnection();
+ EmsBean emsBean = loadBean(connection, objectName);
+
+ return emsBean.getClassTypeName();
+ }
}