modules/plugins/rhq-storage/pom.xml | 97 ---------- modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeComponent.java | 30 --- modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeConfigDelegate.java | 69 +++++++ modules/plugins/rhq-storage/src/main/resources/META-INF/rhq-plugin.xml | 3 modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeConfigDelegateTest.java | 82 ++++++++ 5 files changed, 159 insertions(+), 122 deletions(-)
New commits: commit 1130a8be9a9a44c6e4670053bd7347aed4e01f30 Author: John Sanda jsanda@redhat.com Date: Sun Jul 14 09:44:04 2013 -0400
adding initial support for resource config updates of StorageNodeComponent
Also making minHeapSize read only as we also want it the same as maxHeapSize.
diff --git a/modules/plugins/rhq-storage/pom.xml b/modules/plugins/rhq-storage/pom.xml index ea3b9ea..a88f56e 100644 --- a/modules/plugins/rhq-storage/pom.xml +++ b/modules/plugins/rhq-storage/pom.xml @@ -39,103 +39,6 @@
<profiles> <profile> - <id>integration-tests</id> - <activation> - <property> - <name>maven.test.skip</name> - <value>!true</value> - </property> - </activation> - - <build> - <plugins> - - <plugin> - <artifactId>maven-antrun-plugin</artifactId> - <executions> - <execution> - <phase>pre-integration-test</phase> - <configuration> - <target> - <echo>Setting up plugin dependencies...</echo> - <property name="settings.localRepository" location="${user.home}/.m2/repository" /> - <mkdir dir="target/itest" /> - <mkdir dir="target/itest/plugins" /> - <mkdir dir="target/itest/lib" /> - <copy toDir="target/itest/plugins" flatten="true"> - <!-- Plugin dependencies on other plugins --> - <fileset dir="${settings.localRepository}/"> - <include name="org/rhq/rhq-platform-plugin/${project.version}/rhq-platform-plugin-${project.version}.jar" /> - <include name="org/rhq/rhq-jmx-plugin/${project.version}/rhq-jmx-plugin-${project.version}.jar" /> - <include name="org/rhq/rhq-jboss-as-7-jmx-plugin/${project.version}/rhq-jboss-as-7-jmx-plugin-${project.version}.jar" /> - </fileset> - <fileset dir="${project.build.directory}"> - <include name="rhq-rhqserver-plugin-${project.version}.jar" /> - </fileset> - </copy> - <unzip dest="target/itest/lib"> - <fileset dir="${settings.localRepository}/org/hyperic/sigar-dist/${sigar.version}" includes="*.zip" /> - <patternset> - <include name="**/lib/sigar.jar" /> - <include name="**/lib/bcel*.jar" /> - <include name="**/lib/*.so" /> - <include name="**/lib/*.sl" /> - <include name="**/lib/*.dll" /> - <include name="**/lib/*.dylib" /> - </patternset> - </unzip> - <move todir="target/itest/lib" flatten="true"> - <fileset dir="target/itest/lib"> - <include name="**/lib/*" /> - </fileset> - </move> - <delete dir="target/itest/lib/hyperic-sigar-${sigar.version}" /> - </target> - </configuration> - <goals> - <goal>run</goal> - </goals> - </execution> - </executions> - </plugin> - - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <skip>true</skip> - </configuration> - <executions> - <execution> - <id>surefire-it</id> - <phase>integration-test</phase> - <goals> - <goal>test</goal> - </goals> - <configuration> - <skip>${maven.test.skip}</skip> - <excludedGroups>${rhq.testng.excludedGroups}</excludedGroups> - <useSystemClassLoader>false</useSystemClassLoader> - <argLine>${jacoco.integration-test.args} -Dorg.hyperic.sigar.path=${basedir}/target/itest/lib</argLine> - <systemProperties> - <property> - <name>project.artifactId</name> - <value>${project.artifactId}</value> - </property> - <property> - <name>project.version</name> - <value>${project.version}</value> - </property> - </systemProperties> - </configuration> - </execution> - </executions> - </plugin> - - </plugins> - </build> - </profile> - - <profile> <id>dev</id>
<properties> diff --git a/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeComponent.java b/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeComponent.java index 737dded..6194146 100644 --- a/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeComponent.java +++ b/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeComponent.java @@ -26,9 +26,7 @@ package org.rhq.plugins.storage;
import java.io.File; -import java.io.FileInputStream; import java.util.List; -import java.util.Properties;
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -62,25 +60,13 @@ public class StorageNodeComponent extends CassandraNodeComponent implements Oper
@Override public Configuration loadResourceConfiguration() throws Exception { - File confDir = new File(getBasedir(), "conf"); - File jvmOptsFile = new File(confDir, "cassandra-jvm.properties"); - - Properties properties = new Properties(); - properties.load(new FileInputStream(jvmOptsFile)); - - Configuration config = new Configuration(); - - String heapMinProp = properties.getProperty("heap_min"); - String heapMaxProp = properties.getProperty("heap_max"); - String heapNewProp = properties.getProperty("heap_new"); - String threadStackSizeProp = properties.getProperty("thread_stack_size"); - - config.put(new PropertySimple("minHeapSize", heapMinProp.substring(4))); - config.put(new PropertySimple("maxHeapSize", heapMaxProp.substring(4))); - config.put(new PropertySimple("heapNewSize", heapNewProp.substring(4))); - config.put(new PropertySimple("threadStackSize", threadStackSizeProp.substring(4))); + return new StorageNodeConfigDelegate(getBasedir()).loadResourceConfiguration(); + }
- return config; + @Override + public void updateResourceConfiguration(ConfigurationUpdateReport configurationUpdateReport) { + StorageNodeConfigDelegate configDelegate = new StorageNodeConfigDelegate(getBasedir()); + configDelegate.updateResourceConfiguration(configurationUpdateReport); }
private File getBasedir() { @@ -89,10 +75,6 @@ public class StorageNodeComponent extends CassandraNodeComponent implements Oper }
@Override - public void updateResourceConfiguration(ConfigurationUpdateReport configurationUpdateReport) { - } - - @Override public OperationResult invokeOperation(String name, Configuration parameters) throws Exception { if (name.equals("addNodeMaintenance")) { return nodeAdded(parameters); diff --git a/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeConfigDelegate.java b/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeConfigDelegate.java new file mode 100644 index 0000000..99ba48b --- /dev/null +++ b/modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeConfigDelegate.java @@ -0,0 +1,69 @@ +package org.rhq.plugins.storage; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; + +import org.rhq.core.domain.configuration.Configuration; +import org.rhq.core.domain.configuration.ConfigurationUpdateStatus; +import org.rhq.core.domain.configuration.PropertySimple; +import org.rhq.core.pluginapi.configuration.ConfigurationFacet; +import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport; +import org.rhq.core.util.PropertiesFileUpdate; + +/** + * @author John Sanda + */ +public class StorageNodeConfigDelegate implements ConfigurationFacet { + + private File jvmOptsFile; + + public StorageNodeConfigDelegate(File basedir) { + File confDir = new File(basedir, "conf"); + jvmOptsFile = new File(confDir, "cassandra-jvm.properties"); + } + + @Override + public Configuration loadResourceConfiguration() throws Exception { + Properties properties = new Properties(); + properties.load(new FileInputStream(jvmOptsFile)); + + Configuration config = new Configuration(); + + String heapMinProp = properties.getProperty("heap_min"); + String heapMaxProp = properties.getProperty("heap_max"); + String heapNewProp = properties.getProperty("heap_new"); + String threadStackSizeProp = properties.getProperty("thread_stack_size"); + + config.put(new PropertySimple("minHeapSize", heapMinProp.substring(4))); + config.put(new PropertySimple("maxHeapSize", heapMaxProp.substring(4))); + config.put(new PropertySimple("heapNewSize", heapNewProp.substring(4))); + config.put(new PropertySimple("threadStackSize", threadStackSizeProp.substring(4))); + + return config; + } + + @Override + public void updateResourceConfiguration(ConfigurationUpdateReport configurationUpdateReport) { + try { + PropertiesFileUpdate propertiesUpdater = new PropertiesFileUpdate(jvmOptsFile.getAbsolutePath()); + Properties properties = propertiesUpdater.loadExistingProperties(); + + Configuration config = configurationUpdateReport.getConfiguration(); + + // We want min and max heap to be the same + properties.setProperty("heap_min", "-Xms" + config.getSimpleValue("maxHeapSize")); + properties.setProperty("heap_max", "-Xmx" + config.getSimpleValue("maxHeapSize")); + properties.setProperty("heap_new", "-Xmn" + config.getSimpleValue("heapNewSize")); + properties.setProperty("thread_stack_size", "-Xss" + config.getSimpleValue("threadStackSize")); + + propertiesUpdater.update(properties); + + configurationUpdateReport.setStatus(ConfigurationUpdateStatus.SUCCESS); + } catch (IOException e) { + configurationUpdateReport.setErrorMessageFromThrowable(e); + } + + } +} diff --git a/modules/plugins/rhq-storage/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/rhq-storage/src/main/resources/META-INF/rhq-plugin.xml index b012f1c..5713288 100644 --- a/modules/plugins/rhq-storage/src/main/resources/META-INF/rhq-plugin.xml +++ b/modules/plugins/rhq-storage/src/main/resources/META-INF/rhq-plugin.xml @@ -114,8 +114,9 @@ <resource-configuration> <c:group name="MemorySettings"> <c:simple-property name="minHeapSize" + readOnly="true" description="The minimum heap size. This value will be used with the -Xms JVM option. This - should always be the same as Max Heap Size."/> + is read only because it is automatically set to the same value as Max Heap Size."/> <c:simple-property name="maxHeapSize" description="The maximum heap size. This value will be used with the -Xmx JVM option."/> <c:simple-property name="heapNewSize" diff --git a/modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeConfigDelegateTest.java b/modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeConfigDelegateTest.java new file mode 100644 index 0000000..f8d7bdc --- /dev/null +++ b/modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeConfigDelegateTest.java @@ -0,0 +1,82 @@ +package org.rhq.plugins.storage; + +import static org.testng.Assert.assertEquals; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; + +import org.testng.annotations.Test; + +import org.rhq.core.domain.configuration.Configuration; +import org.rhq.core.domain.configuration.PropertySimple; +import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport; + +/** + * @author John Sanda + */ +public class StorageNodeConfigDelegateTest { + + + + @Test + public void loadValidConfig() throws Exception { + File dir = new File(getClass().getResource(".").toURI()); + File basedir = new File(dir, getClass().getSimpleName() + "/loadValidConfig"); + File confDir = new File(basedir, "conf"); + + confDir.mkdirs(); + createDefaultConfig(confDir); + + StorageNodeConfigDelegate configDelegate = new StorageNodeConfigDelegate(basedir); + Configuration config = configDelegate.loadResourceConfiguration(); + + assertEquals(config.getSimpleValue("minHeapSize"), "512M", "Failed to load property [minHeapSize]"); + assertEquals(config.getSimpleValue("maxHeapSize"), "512M", "Failed to load property [maxHepSize]"); + assertEquals(config.getSimpleValue("heapNewSize"), "128M", "Failed to load property [heapNewSize]"); + assertEquals(config.getSimpleValue("threadStackSize"), "180k", "Failed to load property [threadStackSize]"); + } + + @Test + public void updateValidConfig() throws Exception { + File dir = new File(getClass().getResource(".").toURI()); + File basedir = new File(dir, getClass().getSimpleName() + "/updateValidConfig"); + File confDir = new File(basedir, "conf"); + + confDir.mkdirs(); + createDefaultConfig(confDir); + + Configuration config = new Configuration(); + config.put(new PropertySimple("minHeapSize", "1024M")); + config.put(new PropertySimple("maxHeapSize", "1024M")); + config.put(new PropertySimple("heapNewSize", "256M")); + config.put(new PropertySimple("threadStackSize", "240k")); + + ConfigurationUpdateReport report = new ConfigurationUpdateReport(config); + + StorageNodeConfigDelegate configDelegate = new StorageNodeConfigDelegate(basedir); + configDelegate.updateResourceConfiguration(report); + + Properties properties = new Properties(); + properties.load(new FileInputStream(new File(confDir, "cassandra-jvm.properties"))); + + assertEquals(properties.getProperty("heap_min"), "-Xms1024M", "Failed to update property [minHeapSize]"); + assertEquals(properties.getProperty("heap_max"), "-Xmx1024M", "Failed to update property [maxHeapSize]"); + assertEquals(properties.getProperty("heap_new"), "-Xmn256M", "Failed to update property [heapNewSize]"); + assertEquals(properties.getProperty("thread_stack_size"), "-Xss240k", + "Failed to update property [threadStackSize]"); + } + + private void createDefaultConfig(File confDir) throws IOException { + Properties properties = new Properties(); + properties.setProperty("heap_min", "-Xms512M"); + properties.setProperty("heap_max", "-Xmx512M"); + properties.setProperty("heap_new", "-Xmn128M"); + properties.setProperty("thread_stack_size", "-Xss180k"); + + properties.store(new FileOutputStream(new File(confDir, "cassandra-jvm.properties")), ""); + } + +}