modules/plugins/cassandra/pom.xml
| 5
modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/CassandraNodeComponent.java
| 77 ++++++++++
modules/plugins/cassandra/src/main/resources/META-INF/rhq-plugin.xml
| 10 +
modules/plugins/rhq-storage/src/main/java/org/rhq/plugins/storage/StorageNodeComponent.java
| 2
modules/plugins/rhq-storage/src/main/resources/META-INF/rhq-plugin.xml
| 8 +
5 files changed, 102 insertions(+)
New commits:
commit d25eb453afc3ba1a06fa2d47b2129d7c0d4592ce
Author: John Sanda <jsanda(a)redhat.com>
Date: Sun Jun 2 22:15:24 2013 -0400
initial commit for resource operation to update seeds property in cassandra.yaml
Updating the seeds property is one of the tasks that needs to be performed when
a node is added to or removed from the cluster. Since this is a generally useful
operation, I have added it to the base, cassandra plugin.
diff --git a/modules/plugins/cassandra/pom.xml b/modules/plugins/cassandra/pom.xml
index 79cbe0f..4a938d0 100644
--- a/modules/plugins/cassandra/pom.xml
+++ b/modules/plugins/cassandra/pom.xml
@@ -30,6 +30,11 @@
<version>1.0.5-M3-p1</version>
</dependency>
<dependency>
+ <groupId>org.apache.cassandra</groupId>
+ <artifactId>cassandra-all</artifactId>
+ <version>${cassandra.version}</version>
+ </dependency>
+ <dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rhq-core-domain</artifactId>
<version>${project.version}</version>
diff --git
a/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/CassandraNodeComponent.java
b/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/CassandraNodeComponent.java
index a1636e7..b756f10 100644
---
a/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/CassandraNodeComponent.java
+++
b/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/CassandraNodeComponent.java
@@ -28,19 +28,34 @@ import static org.rhq.core.domain.measurement.AvailabilityType.UP;
import static org.rhq.core.system.OperatingSystemType.WINDOWS;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Cluster.Builder;
import com.datastax.driver.core.Session;
+import org.apache.cassandra.config.Config;
+import org.apache.cassandra.config.SeedProviderDef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hyperic.sigar.SigarException;
import org.mc4j.ems.connection.EmsConnection;
import org.mc4j.ems.connection.bean.EmsBean;
import org.mc4j.ems.connection.bean.operation.EmsOperation;
+import org.yaml.snakeyaml.DumperOptions;
+import org.yaml.snakeyaml.TypeDescription;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.representer.Representer;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
import org.rhq.core.pluginapi.inventory.ResourceContext;
@@ -52,6 +67,7 @@ import org.rhq.core.system.ProcessExecutionResults;
import org.rhq.core.system.ProcessInfo;
import org.rhq.core.system.ProcessInfo.ProcessInfoSnapshot;
import org.rhq.core.system.SystemInfo;
+import org.rhq.core.util.StringUtil;
import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.plugins.jmx.JMXServerComponent;
@@ -137,6 +153,8 @@ public class CassandraNodeComponent extends
JMXServerComponent<ResourceComponent
return startNode();
} else if (name.equals("restart")) {
return restartNode();
+ } else if (name.equals("updateSeedsList")) {
+ return updateSeedsList(parameters);
}
return null;
@@ -215,6 +233,65 @@ public class CassandraNodeComponent extends
JMXServerComponent<ResourceComponent
return result;
}
+ protected OperationResult updateSeedsList(Configuration params) {
+ List<String> addresses = new ArrayList<String>();
+ PropertyList list = params.getList("seedsList");
+ for (Property property : list.getList()) {
+ PropertySimple simple = (PropertySimple) property;
+ addresses.add(simple.getStringValue());
+ }
+
+ OperationResult result = new OperationResult();
+ try {
+ updateSeedsList(addresses);
+ } catch (Exception e) {
+ log.error("An error occurred while updating the seeds list
property", e);
+ Throwable rootCause = ThrowableUtil.getRootCause(e);
+ result.setErrorMessage(ThrowableUtil.getStackAsString(rootCause));
+ }
+ return result;
+ }
+
+ protected void updateSeedsList(List<String> addresses) throws IOException {
+ ResourceContext<?> context = getResourceContext();
+ Configuration pluginConfig = context.getPluginConfiguration();
+
+ String yamlProp = pluginConfig.getSimpleValue("yamlConfiguration");
+ if (yamlProp == null || yamlProp.isEmpty()) {
+ throw new IllegalStateException("Plugin configuration property
[yamlConfiguration] is undefined. This " +
+ "property must specify be set and specify the location of
cassandra.yaml in order to complete " +
+ "this operation");
+ }
+
+ File yamlFile = new File(yamlProp);
+ if (!yamlFile.exists()) {
+ throw new IllegalStateException("Plug configuration property
[yamlConfiguration] has as its value a " +
+ "non-existent file.");
+ }
+
+ org.yaml.snakeyaml.constructor.Constructor constructor = new
org.yaml.snakeyaml.constructor.Constructor(Config.class);
+ TypeDescription seedDesc = new TypeDescription(SeedProviderDef.class);
+ seedDesc.putMapPropertyType("parameters", String.class, String.class);
+ constructor.addTypeDescription(seedDesc);
+
+ DumperOptions options = new DumperOptions();
+ options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
+
+ Yaml yaml = new Yaml(constructor, new Representer(), options);
+ Config conf = (Config)yaml.load(new FileInputStream(yamlFile));
+
+ SeedProviderDef seedProviderDef = conf.seed_provider;
+ seedProviderDef.parameters.put("seeds",
StringUtil.listToString(addresses));
+ Map<String, String> params = seedProviderDef.parameters;
+
+ // remove the original file
+ // TODO create a backup first in case something goes wrong so we can rollback
+ yamlFile.delete();
+ FileWriter writer = new FileWriter(yamlFile);
+ yaml.dump(conf, writer);
+ writer.close();
+ }
+
private String getStartScript() {
ResourceContext<?> context = getResourceContext();
SystemInfo systemInfo = context.getSystemInformation();
diff --git a/modules/plugins/cassandra/src/main/resources/META-INF/rhq-plugin.xml
b/modules/plugins/cassandra/src/main/resources/META-INF/rhq-plugin.xml
index 8dfc156..8ec0c6d 100644
--- a/modules/plugins/cassandra/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/cassandra/src/main/resources/META-INF/rhq-plugin.xml
@@ -61,17 +61,27 @@
<c:simple-property name="shutdownResult" description="Shutdown
the Cassandra daemon"/>
</results>
</operation>
+
<operation name="start" description="Starts the Cassandra
daemon">
<results>
<c:simple-property name="startResult" description="Start the
Cassandra daemon"/>
</results>
</operation>
+
<operation name="restart" description="Restarts the Cassandra
daemon">
<results>
<c:simple-property name="startResult" description="Restart the
Cassandra daemon"/>
</results>
</operation>
+ <operation name="updateSeedsList" description="Updatess the
node's seeds property in cassandra.yaml">
+ <parameters>
+ <c:list-property name="seedsList">
+ <c:simple-property name="seed" type="string"/>
+ </c:list-property>
+ </parameters>
+ </operation>
+
<server name="Cassandra Server JVM"
sourcePlugin="JMX" sourceType="JMX Server"
discovery="org.rhq.plugins.jmx.EmbeddedJMXServerDiscoveryComponent"
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 2accf4a..88b76c1 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
@@ -98,6 +98,8 @@ public class StorageNodeComponent extends CassandraNodeComponent
implements Oper
}
resultsList.add(toPropertyMap(opResult));
+ // update seeds list...
+
resultConfig.put(resultsList);
if (hasErrors) {
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 21b4c6d..2457b0c 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
@@ -81,6 +81,14 @@
</results>
</operation>
+ <operation name="updateSeedsList" description="Updatess the
node's seeds property in cassandra.yaml">
+ <parameters>
+ <c:list-property name="seedsList">
+ <c:simple-property name="seed" type="string"/>
+ </c:list-property>
+ </parameters>
+ </operation>
+
<server name="Cassandra Server JVM"
sourcePlugin="JMX" sourceType="JMX Server"
discovery="org.rhq.plugins.jmx.EmbeddedJMXServerDiscoveryComponent"
Show replies by date