modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeConfigDelegate.java | 24 ++++ modules/plugins/rhq-storage/src/main/resources/META-INF/rhq-plugin.xml | 5 modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeConfigDelegateTest.java | 55 +++++++--- 3 files changed, 69 insertions(+), 15 deletions(-)
New commits: commit 18c42dafe1e9e51a16a5ceba068a1e27cb8788c0 Author: John Sanda jsanda@redhat.com Date: Sun Jul 14 22:36:40 2013 -0400
adding heap dump properties to resource configuration
The heap dump directory defaults to <rhq-storage-basedir>/bin and we are generating heap dumps by default. Also refactoring and updating tests some.
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 index 99ba48b..e82f290 100644 --- 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 @@ -11,6 +11,7 @@ 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; +import org.rhq.core.util.StringUtil;
/** * @author John Sanda @@ -35,12 +36,27 @@ public class StorageNodeConfigDelegate implements ConfigurationFacet { String heapMaxProp = properties.getProperty("heap_max"); String heapNewProp = properties.getProperty("heap_new"); String threadStackSizeProp = properties.getProperty("thread_stack_size"); + String heapDumpOnOOMError = properties.getProperty("heap_dump_on_OOMError"); + String heapDumpDir = properties.getProperty("heap_dump_dir");
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)));
+ if (!StringUtil.isEmpty(heapDumpOnOOMError)) { + config.put(new PropertySimple("heapDumpOnOOMError", true)); + } else { + config.put(new PropertySimple("heapDumpOnOOMError", false)); + } + + if (!StringUtil.isEmpty(heapDumpDir)) { + config.put(new PropertySimple("heapDumpDir", heapDumpDir)); + } else { + File basedir = jvmOptsFile.getParentFile().getParentFile(); + config.put(new PropertySimple("heapDumpDir", new File(basedir, "bin").getAbsolutePath())); + } + return config; }
@@ -58,6 +74,14 @@ public class StorageNodeConfigDelegate implements ConfigurationFacet { properties.setProperty("heap_new", "-Xmn" + config.getSimpleValue("heapNewSize")); properties.setProperty("thread_stack_size", "-Xss" + config.getSimpleValue("threadStackSize"));
+ if (config.getSimple("heapDumpOnOOMError").getBooleanValue()) { + properties.setProperty("heap_dump_on_OOMError", "-XX:+HeapDumpOnOutOfMemoryError"); + } else { + properties.setProperty("heap_dump_on_OOMError", ""); + } + + properties.setProperty("heap_dump_dir", config.getSimpleValue("heapDumpDir")); + propertiesUpdater.update(properties);
configurationUpdateReport.setStatus(ConfigurationUpdateStatus.SUCCESS); 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 5713288..c700257 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 @@ -124,6 +124,11 @@ the -Xmn JVM option."/> <c:simple-property name="threadStackSize" description="The thread stack size. This memory is allocated to each thread off heap."/> + <c:simple-property name="heapDumpOnOOMError" displayName="Heap Dump on OutOfMemoryError" type="boolean" + default="true" + description="Generate a heap dump when an OutOfMemoryError occurs"/> + <c:simple-property name="heapDumpDir" displayName="Heap Dump Directory" required="false" + description="The directory in which heap dumps will be written."/> </c:group> </resource-configuration>
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 index f8d7bdc..5c5f089 100644 --- 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 @@ -6,8 +6,10 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.lang.reflect.Method; import java.util.Properties;
+import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test;
import org.rhq.core.domain.configuration.Configuration; @@ -19,16 +21,18 @@ import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport; */ public class StorageNodeConfigDelegateTest {
+ private File basedir; + + @BeforeMethod + public void initDirs(Method test) throws Exception { + File dir = new File(getClass().getResource(".").toURI()); + basedir = new File(dir, getClass().getSimpleName() + "/" + test.getName()); + }
@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); + createDefaultConfig();
StorageNodeConfigDelegate configDelegate = new StorageNodeConfigDelegate(basedir); Configuration config = configDelegate.loadResourceConfiguration(); @@ -37,22 +41,22 @@ public class StorageNodeConfigDelegateTest { 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]"); + assertEquals(config.getSimple("heapDumpOnOOMError").getBooleanValue(), (Boolean) true, + "Failed to load property [heapDumpOnOOMError]"); + assertEquals(new File(config.getSimpleValue("heapDumpDir")), binDir(), "Failed to load property [heapDumpDir]"); }
@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); + createDefaultConfig();
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")); + config.put(new PropertySimple("heapDumpOnOOMError", true)); + config.put(new PropertySimple("heapDumpDir", confDir()));
ConfigurationUpdateReport report = new ConfigurationUpdateReport(config);
@@ -60,23 +64,44 @@ public class StorageNodeConfigDelegateTest { configDelegate.updateResourceConfiguration(report);
Properties properties = new Properties(); - properties.load(new FileInputStream(new File(confDir, "cassandra-jvm.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]"); + assertEquals(properties.getProperty("heap_dump_on_OOMError"), "-XX:+HeapDumpOnOutOfMemoryError", + "Failed to update property [heap_dump_on_OOMError]"); + assertEquals(properties.getProperty("heap_dump_dir"), confDir().getAbsolutePath(), + "Failed to update property [heap_dump_dir]"); }
- private void createDefaultConfig(File confDir) throws IOException { + private void createDefaultConfig() 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.setProperty("heap_dump_on_OOMError", "-XX:+HeapDumpOnOutOfMemoryError"); + + properties.store(new FileOutputStream(new File(confDir(), "cassandra-jvm.properties")), ""); + } + + private File confDir() { + return mkdirIfNecessary(basedir, "conf"); + } + + private File binDir() { + return mkdirIfNecessary(basedir, "bin"); + }
- properties.store(new FileOutputStream(new File(confDir, "cassandra-jvm.properties")), ""); + private File mkdirIfNecessary(File parent, String path) { + File dir = new File(parent, path); + if (!dir.exists()) { + dir.mkdirs(); + } + return dir; }
}