modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBean.java
| 48 ++++++----
modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeComponent.java
| 28 +++++
modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeConfigDelegate.java
| 26 +++--
modules/plugins/rhq-storage/src/main/resources/META-INF/rhq-plugin.xml
| 4
4 files changed, 80 insertions(+), 26 deletions(-)
New commits:
commit 76183b30be9694e81ed93239ff505f887c101f32
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Thu Jul 25 08:51:47 2013 -0500
Add support for updating the JMX Port. The process sends a restart to the resource
last to avoid putting the Server in maintenance mode.
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBean.java
index 1441785..7a7eda4 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBean.java
@@ -103,7 +103,7 @@ public class StorageNodeManagerBean implements
StorageNodeManagerLocal, StorageN
private static final String RHQ_STORAGE_ADDRESS_PROPERTY = "host";
private static final int OPERATION_QUERY_TIMEOUT = 20000;
- private static final int MAX_ITERATIONS = 6;
+ private static final int MAX_ITERATIONS = 10;
private static final String UPDATE_CONFIGURATION_OPERATION =
"updateConfiguration";
private static final String RESTART_OPERATION = "restart";
@@ -639,16 +639,45 @@ public class StorageNodeManagerBean implements
StorageNodeManagerLocal, StorageN
StorageNode storageNode =
findStorageNodeByAddress(storageNodeConfiguration.getStorageNode().getAddress());
if (storageNode != null && storageNode.getResource() != null) {
- Resource storageNodeResource = storageNode.getResource();
Configuration parameters = new Configuration();
parameters.setSimpleValue("jmxPort",
storageNodeConfiguration.getJmxPort() + "");
- parameters.setSimpleValue("heapSize",
storageNodeConfiguration.getHeapSize() + "");
- parameters.setSimpleValue("heapNewSize",
storageNodeConfiguration.getHeapNewSize() + "");
- parameters.setSimpleValue("threadStackSize",
storageNodeConfiguration.getThreadStackSize() + "");
- parameters.setSimpleValue("restartIfRequired", "true");
+ if (storageNodeConfiguration.getHeapSize() != null) {
+ parameters.setSimpleValue("heapSize",
storageNodeConfiguration.getHeapSize() + "");
+ }
+ if (storageNodeConfiguration.getHeapNewSize() != null) {
+ parameters.setSimpleValue("heapNewSize",
storageNodeConfiguration.getHeapNewSize() + "");
+ }
+ if (storageNodeConfiguration.getThreadStackSize() != null) {
+ parameters.setSimpleValue("threadStackSize",
storageNodeConfiguration.getThreadStackSize() + "");
+ }
+ parameters.setSimpleValue("restartIfRequired", "false");
- return runOperationAndWaitForResult(subject, storageNodeResource,
UPDATE_CONFIGURATION_OPERATION,
+ Resource storageNodeResource = storageNode.getResource();
+
+ boolean result = runOperationAndWaitForResult(subject, storageNodeResource,
UPDATE_CONFIGURATION_OPERATION,
parameters);
+
+ if (result) {
+ Configuration storageNodePluginConfig =
configurationManager.getPluginConfiguration(subject,
+ storageNodeResource.getId());
+
+ String existingJMXPort =
storageNodePluginConfig.getSimpleValue("jmxPort");
+ storageNodePluginConfig.setSimpleValue("jmxPort",
storageNodeConfiguration.getJmxPort() + "");
+
+ String existingConnectionURL =
storageNodePluginConfig.getSimpleValue("connectorAddress");
+ String newConnectionURL = existingConnectionURL.replace(":" +
existingJMXPort + "/", ":"
+ + storageNodeConfiguration.getJmxPort() + "/");
+ storageNodePluginConfig.setSimpleValue("connectorAddress",
newConnectionURL);
+
+ configurationManager.updatePluginConfiguration(subject,
storageNodeResource.getId(),
+ storageNodePluginConfig);
+
+ storageNode.setJmxPort(storageNodeConfiguration.getJmxPort());
+ entityManager.merge(storageNode);
+ entityManager.flush();
+
+ return runOperationAndWaitForResult(subject, storageNodeResource,
RESTART_OPERATION, null);
+ }
}
return false;
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 41a0c42..125f4d2 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
@@ -117,6 +117,7 @@ public class StorageNodeComponent extends CassandraNodeComponent
implements Oper
//update storage node jvm settings
Configuration config = new Configuration();
+ config.put(new PropertySimple("jmxPort",
params.getSimpleValue("jmxPort")));
config.put(new PropertySimple("minHeapSize",
params.getSimpleValue("heapSize")));
config.put(new PropertySimple("maxHeapSize",
params.getSimpleValue("heapSize")));
config.put(new PropertySimple("heapNewSize",
params.getSimpleValue("heapNewSize")));
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 1667877..dd5b8a2 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
@@ -148,11 +148,17 @@ public class StorageNodeConfigDelegate implements ConfigurationFacet
{
}
}
- private void updateCassandraJvmProps(Configuration config) throws IOException {
+ private void updateCassandraJvmProps(Configuration newConfig) throws IOException {
PropertiesFileUpdate propertiesUpdater = new
PropertiesFileUpdate(jvmOptsFile.getAbsolutePath());
Properties properties = propertiesUpdater.loadExistingProperties();
- String maxHeapSize = config.getSimpleValue("maxHeapSize");
+ String jmxPort = newConfig.getSimpleValue("jmxPort");
+ if (!StringUtil.isEmpty(jmxPort)) {
+ validateIntegerArg("jmx_port", jmxPort);
+ properties.setProperty("jmx_port", jmxPort);
+ }
+
+ String maxHeapSize = newConfig.getSimpleValue("maxHeapSize");
if (!StringUtil.isEmpty(maxHeapSize)) {
validateHeapArg("maxHeapSize", maxHeapSize);
// We want min and max heap to be the same
@@ -160,19 +166,19 @@ public class StorageNodeConfigDelegate implements ConfigurationFacet
{
properties.setProperty("heap_max", "-Xmx" +
maxHeapSize);
}
- String heapNewSize = config.getSimpleValue("heapNewSize");
+ String heapNewSize = newConfig.getSimpleValue("heapNewSize");
if (!StringUtil.isEmpty(heapNewSize)) {
validateHeapArg("heapNewSize", heapNewSize);
properties.setProperty("heap_new", "-Xmn" +
heapNewSize);
}
- String threadStackSize = config.getSimpleValue("threadStackSize");
+ String threadStackSize = newConfig.getSimpleValue("threadStackSize");
if (!StringUtil.isEmpty(threadStackSize)) {
- validateStackArg(threadStackSize);
+ validateIntegerArg("threadStackSize", threadStackSize);
properties.setProperty("thread_stack_size", "-Xss" +
threadStackSize + "k");
}
- PropertySimple heapDumpOnOMMError =
config.getSimple("heapDumpOnOOMError");
+ PropertySimple heapDumpOnOMMError =
newConfig.getSimple("heapDumpOnOOMError");
if (heapDumpOnOMMError != null) {
if (heapDumpOnOMMError.getBooleanValue()) {
properties.setProperty("heap_dump_on_OOMError",
"-XX:+HeapDumpOnOutOfMemoryError");
@@ -181,7 +187,7 @@ public class StorageNodeConfigDelegate implements ConfigurationFacet
{
}
}
- String heapDumpDir =
useForwardSlash(config.getSimpleValue("heapDumpDir"));
+ String heapDumpDir =
useForwardSlash(newConfig.getSimpleValue("heapDumpDir"));
if (!StringUtil.isEmpty(heapDumpDir)) {
properties.setProperty("heap_dump_dir", heapDumpDir);
}
@@ -209,7 +215,7 @@ public class StorageNodeConfigDelegate implements ConfigurationFacet
{
String threadStackSize = config.getSimpleValue("threadStackSize");
if (!StringUtil.isEmpty(threadStackSize)) {
- validateStackArg(threadStackSize);
+ validateIntegerArg("threadStackSize", threadStackSize);
properties.setProperty("set.thread_stack_size", "-Xss" +
threadStackSize + "k");
}
@@ -248,11 +254,11 @@ public class StorageNodeConfigDelegate implements ConfigurationFacet
{
}
}
- private void validateStackArg(String value) {
+ private void validateIntegerArg(String name, String value) {
try {
Integer.parseInt(value);
} catch (NumberFormatException e) {
- throw new IllegalArgumentException(value + " is not a legal value for
the property [threadStackSize]");
+ throw new IllegalArgumentException(value + " is not a legal value for
the property [" + name + "]");
}
}
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 aca3ba2..a42040d 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
@@ -32,6 +32,7 @@
<c:simple-property name="baseDir" displayName="Base
Directory" description="The base directory from which the Cassandra Daemon was
launched." required="false"/>
<c:simple-property name="yamlConfiguration" displayName="YAML
Configuration File" description="YAML Configuration File"/>
<c:simple-property name="nativeTransportPort" description="The
port on which Cassandra listens for CQL client connections." default="9042"
type="integer"/>
+ <c:simple-property name="jmxPort" description="The JMX port for
Cassandra" default="7299" type="integer"
readOnly="true"/>
<c:simple-property name="host" description="The host on which
cassandra listens to CQL client connections" default="localhost"/>
<c:simple-property name="clusterName" description="Cluster
name" default="localhost"/>
<c:simple-property name="authenticator" required="true"
default="org.apache.cassandra.auth.AllowAllAuthenticator"
description="Cassandra client authenticator">
@@ -131,11 +132,11 @@
<operation name="updateConfiguration" description="Updates the node
configuration. Will require a separate server restart for the settings to take
effect.">
<parameters>
+ <c:simple-property name="jmxPort" type="integer"
description="JMX port JVM option."/>
<c:simple-property name="heapSize" type="string"
description="The heap size to be used for both -Xms and -Xmx JVM options."/>
<c:simple-property name="heapNewSize" type="string"
description="The heap new size to be used be used with -Xmn JVM option."/>
<c:simple-property name="threadStackSize" type="integer"
description="The thread stack size. This memory is allocated to each thread off heap.
The
value
should be an integer that will be interpreted in kilobytes."/>
- <c:simple-property name="jmxPort" type="integer"
description="JMX port JVM option."/>
<c:simple-property name="restartIfRequired" type="boolean"
required="true" default="false" description="If [true] then
restart the server at the end of the update if and if only the updates made require a
restart. If [false] the server will not be restarted regardless of the updates
made."/>
</parameters>
<results>
commit c4c99241f2c2406b4b916865b0932d1df5e2af4f
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Tue Jul 23 16:43:29 2013 -0500
Move the restart operation to the plugin rather than server bean. This simplifies the
interface between the server bean and storage node plugin.
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBean.java
index 9416c67..1441785 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBean.java
@@ -645,21 +645,10 @@ public class StorageNodeManagerBean implements
StorageNodeManagerLocal, StorageN
parameters.setSimpleValue("heapSize",
storageNodeConfiguration.getHeapSize() + "");
parameters.setSimpleValue("heapNewSize",
storageNodeConfiguration.getHeapNewSize() + "");
parameters.setSimpleValue("threadStackSize",
storageNodeConfiguration.getThreadStackSize() + "");
+ parameters.setSimpleValue("restartIfRequired", "true");
- boolean updateConfigurationResult = runOperationAndWaitForResult(subject,
storageNodeResource,
- UPDATE_CONFIGURATION_OPERATION, parameters);
-
- if (updateConfigurationResult) {
- boolean restartResult = runOperationAndWaitForResult(subject,
storageNodeResource, RESTART_OPERATION,
- null);
-
- if (restartResult) {
- storageNode.setJmxPort(storageNodeConfiguration.getJmxPort());
- entityManager.persist(storageNode);
-
- return true;
- }
- }
+ return runOperationAndWaitForResult(subject, storageNodeResource,
UPDATE_CONFIGURATION_OPERATION,
+ parameters);
}
return false;
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 d9b35b9..41a0c42 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
@@ -111,6 +111,8 @@ public class StorageNodeComponent extends CassandraNodeComponent
implements Oper
}
private OperationResult updateConfiguration(Configuration params) {
+ boolean restartIsRequired = false;
+
OperationResult result = new OperationResult("Configuration
updated.");
//update storage node jvm settings
@@ -125,6 +127,31 @@ public class StorageNodeComponent extends CassandraNodeComponent
implements Oper
if (!configurationUpdate.getStatus().equals(ConfigurationUpdateStatus.SUCCESS))
{
result.setErrorMessage(configurationUpdate.getErrorMessage());
+ } else {
+ if (params.getSimpleValue("heapSize") != null
+ || params.getSimpleValue("heapNewSize") != null
+ || params.getSimpleValue("threadStackSize") != null) {
+ restartIsRequired = true;
+ }
+ }
+
+ //restart the server if:
+ //- requested by the user
+ //- the updates done require restart
+ boolean restartIfRequiredConfig = false;
+ if (params.getSimpleValue("restartIfRequired") != null) {
+ restartIfRequiredConfig =
Boolean.parseBoolean(params.getSimpleValue("restartIfRequired"));
+ }
+
+ if (restartIfRequiredConfig && restartIsRequired) {
+ try {
+ OperationResult restartResult = this.invokeOperation("restart",
null);
+ if (restartResult.getErrorMessage() != null) {
+ result.setErrorMessage(restartResult.getErrorMessage());
+ }
+ } catch (Exception e) {
+ result.setErrorMessage(e.getMessage());
+ }
}
return result;
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 cd84de6..aca3ba2 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
@@ -136,6 +136,7 @@
<c:simple-property name="threadStackSize" type="integer"
description="The thread stack size. This memory is allocated to each thread off heap.
The
value
should be an integer that will be interpreted in kilobytes."/>
<c:simple-property name="jmxPort" type="integer"
description="JMX port JVM option."/>
+ <c:simple-property name="restartIfRequired" type="boolean"
required="true" default="false" description="If [true] then
restart the server at the end of the update if and if only the updates made require a
restart. If [false] the server will not be restarted regardless of the updates
made."/>
</parameters>
<results>
<c:simple-property name="operationResult" description="Outcome
of updating the configuration."/>