modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/ColumnFamilyDiscoveryComponent.java | 32 +--
modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/KeyspaceComponent.java | 102 ++++++++++
modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/KeyspaceDiscoveryComponent.java | 57 +++++
modules/plugins/cassandra/src/main/resources/META-INF/rhq-plugin.xml | 33 ++-
4 files changed, 195 insertions(+), 29 deletions(-)
New commits:
commit addd875822e1fbb74aa06f62fe597cb02e7d1c0a
Author: John Sanda <jsanda(a)redhat.com>
Date: Thu Sep 13 21:44:05 2012 -0400
Adding Keyspace resource type
This commit introduces a Keyspace resource type. The ColumnFamily type has been
moved and made a child type of the Keyspace type. This provides a nice, logical
view of column families in a keyspace.
diff --git a/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/ColumnFamilyDiscoveryComponent.java b/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/ColumnFamilyDiscoveryComponent.java
index 67196c8..53b6d62 100644
--- a/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/ColumnFamilyDiscoveryComponent.java
+++ b/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/ColumnFamilyDiscoveryComponent.java
@@ -28,10 +28,6 @@ package org.rhq.plugins.cassandra;
import java.util.HashSet;
import java.util.Set;
-import org.mc4j.ems.connection.EmsConnection;
-import org.mc4j.ems.connection.bean.EmsBean;
-import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
-
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
@@ -50,26 +46,20 @@ public class ColumnFamilyDiscoveryComponent implements ResourceDiscoveryComponen
@Override
public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext context) throws Exception {
- CassandraNodeComponent parent = (CassandraNodeComponent) context.getParentResourceComponent();
- EmsConnection emsConnection = parent.getEmsConnection();
- EmsBean emsBean = emsConnection.getBean("org.apache.cassandra.db:type=StorageService");
-
- EmsAttribute attribute = emsBean.getAttribute("keyspaces");
-
Cluster cluster = HFactory.getOrCreateCluster("rhq", "localhost:9160");
Set<DiscoveredResourceDetails> details = new HashSet<DiscoveredResourceDetails>();
- for (KeyspaceDefinition keyspaceDef : cluster.describeKeyspaces()) {
- for (ColumnFamilyDefinition columnFamilyDef : keyspaceDef.getCfDefs()) {
- String resourceKey = keyspaceDef.getName() + "." + columnFamilyDef.getName();
- Configuration pluginConfig = new Configuration();
- // org.apache.cassandra.db:type=ColumnFamilies,keyspace=test,columnfamily=users
- pluginConfig.put(new PropertySimple("objectName",
- "org.apache.cassandra.db:type=ColumnFamilies,keyspace=" + keyspaceDef.getName() +
- ",columnfamily=" + columnFamilyDef.getName()));
- details.add(new DiscoveredResourceDetails(context.getResourceType(), resourceKey,
- columnFamilyDef.getName(), null, null, pluginConfig, null));
- }
+ String keyspace = context.getParentResourceContext().getResourceKey();
+ KeyspaceDefinition keyspaceDef = cluster.describeKeyspace(keyspace);
+
+ for (ColumnFamilyDefinition columnFamilyDef : keyspaceDef.getCfDefs()) {
+ String resourceKey = keyspace + "." + columnFamilyDef.getName();
+ Configuration pluginConfig = new Configuration();
+ pluginConfig.put(new PropertySimple("objectName",
+ "org.apache.cassandra.db:type=ColumnFamilies,keyspace=" + keyspaceDef.getName() +
+ ",columnfamily=" + columnFamilyDef.getName()));
+ details.add(new DiscoveredResourceDetails(context.getResourceType(), resourceKey,
+ columnFamilyDef.getName(), null, null, pluginConfig, null));
}
return details;
diff --git a/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/KeyspaceComponent.java b/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/KeyspaceComponent.java
new file mode 100644
index 0000000..4e9097f
--- /dev/null
+++ b/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/KeyspaceComponent.java
@@ -0,0 +1,102 @@
+/*
+ *
+ * * RHQ Management Platform
+ * * Copyright (C) 2005-2012 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, version 2, as
+ * * published by the Free Software Foundation, and/or the GNU Lesser
+ * * General Public License, version 2.1, also as published by the Free
+ * * Software Foundation.
+ * *
+ * * 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 and the GNU Lesser General Public License
+ * * for more details.
+ * *
+ * * You should have received a copy of the GNU General Public License
+ * * and the GNU Lesser General Public License along with this program;
+ * * if not, write to the Free Software Foundation, Inc.,
+ * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+package org.rhq.plugins.cassandra;
+
+import java.util.Map;
+
+import org.mc4j.ems.connection.EmsConnection;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.plugins.jmx.JMXComponent;
+
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
+import me.prettyprint.hector.api.factory.HFactory;
+
+/**
+ * @author John Sanda
+ */
+public class KeyspaceComponent implements ResourceComponent, ConfigurationFacet, JMXComponent {
+
+ private ResourceContext context;
+
+ @Override
+ public void start(ResourceContext context) throws Exception {
+ this.context = context;
+ }
+
+ @Override
+ public void stop() {
+ }
+
+ @Override
+ public AvailabilityType getAvailability() {
+ return AvailabilityType.UP;
+ }
+
+ @Override
+ public EmsConnection getEmsConnection() {
+ JMXComponent parent = (JMXComponent) context.getParentResourceComponent();
+ return parent.getEmsConnection();
+ }
+
+ @Override
+ public Configuration loadResourceConfiguration() throws Exception {
+ Cluster cluster = HFactory.getOrCreateCluster("rhq", "localhost:9160");
+ KeyspaceDefinition keyspaceDef = cluster.describeKeyspace(context.getResourceKey());
+
+ Configuration config = new Configuration();
+ config.put(new PropertySimple("name", keyspaceDef.getName()));
+ config.put(new PropertySimple("replicationFactor", keyspaceDef.getReplicationFactor()));
+ config.put(new PropertySimple("strategyClass", keyspaceDef.getStrategyClass()));
+ config.put(new PropertySimple("durableWrites", keyspaceDef.isDurableWrites()));
+
+ PropertyList list = new PropertyList("strategyOptions");
+ Map<String, String> strategyOptions = keyspaceDef.getStrategyOptions();
+ for (String optionName : strategyOptions.keySet()) {
+ PropertyMap map = new PropertyMap("strategyOptionsMap");
+ map.put(new PropertySimple("strategyOptionName", optionName));
+ map.put(new PropertySimple("strategyOptionValue", strategyOptions.get(optionName)));
+ list.add(map);
+ }
+ config.put(list);
+
+ return config;
+ }
+
+ @Override
+ public void updateResourceConfiguration(ConfigurationUpdateReport report) {
+ }
+
+}
diff --git a/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/KeyspaceDiscoveryComponent.java b/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/KeyspaceDiscoveryComponent.java
new file mode 100644
index 0000000..5e3cece
--- /dev/null
+++ b/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/KeyspaceDiscoveryComponent.java
@@ -0,0 +1,57 @@
+/*
+ *
+ * * RHQ Management Platform
+ * * Copyright (C) 2005-2012 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, version 2, as
+ * * published by the Free Software Foundation, and/or the GNU Lesser
+ * * General Public License, version 2.1, also as published by the Free
+ * * Software Foundation.
+ * *
+ * * 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 and the GNU Lesser General Public License
+ * * for more details.
+ * *
+ * * You should have received a copy of the GNU General Public License
+ * * and the GNU Lesser General Public License along with this program;
+ * * if not, write to the Free Software Foundation, Inc.,
+ * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+package org.rhq.plugins.cassandra;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
+import me.prettyprint.hector.api.factory.HFactory;
+
+/**
+ * @author John Sanda
+ */
+public class KeyspaceDiscoveryComponent implements ResourceDiscoveryComponent {
+
+ @Override
+ public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext context)
+ throws Exception {
+ Cluster cluster = HFactory.getOrCreateCluster("rhq", "localhost:9160");
+ Set<DiscoveredResourceDetails> details = new HashSet<DiscoveredResourceDetails>();
+
+ for (KeyspaceDefinition keyspaceDef : cluster.describeKeyspaces()) {
+ details.add(new DiscoveredResourceDetails(context.getResourceType(), keyspaceDef.getName(),
+ keyspaceDef.getName(), null, null, null, null));
+ }
+
+ return details;
+ }
+}
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 0abed08..0d4e885 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
@@ -81,15 +81,32 @@
</operation>
</service>
- <service name="ColumnFamily"
- discovery="org.rhq.plugins.cassandra.ColumnFamilyDiscoveryComponent"
- class="org.rhq.plugins.cassandra.ColumnFamilyComponent">
- <plugin-configuration>
- <c:simple-property name="objectName" readOnly="true"/>
- </plugin-configuration>
- <!--<resource-configuration>-->
+ <service name="Keyspace"
+ discovery="org.rhq.plugins.cassandra.KeyspaceDiscoveryComponent"
+ class="org.rhq.plugins.cassandra.KeyspaceComponent">
+ <resource-configuration>
+ <c:simple-property name="name" type="string" description="The keyspace name" readOnly="true"/>
+ <c:simple-property name="replicationFactor" type="integer" readOnly="true"/>
+ <c:simple-property name="strategyClass" type="string" readOnly="true"/>
+ <c:simple-property name="durableWrites" type="boolean" readOnly="true"/>
+ <c:list-property name="strategyOptions" readOnly="true">
+ <c:map-property name="strategyOptionsMap">
+ <c:simple-property name="strategyOptionName" type="string" readOnly="true"/>
+ <c:simple-property name="strategyOptionValue" type="string" readOnly="true"/>
+ </c:map-property>
+ </c:list-property>
+ </resource-configuration>
+
+ <service name="ColumnFamily"
+ discovery="org.rhq.plugins.cassandra.ColumnFamilyDiscoveryComponent"
+ class="org.rhq.plugins.cassandra.ColumnFamilyComponent">
+ <plugin-configuration>
+ <c:simple-property name="objectName" readOnly="true" type="string"/>
+ </plugin-configuration>
+ <!--<resource-configuration>-->
<!--<c:simple-property name="columnFamilyName" type="string" readOnly="true"/>-->
- <!--</resource-configuration>-->
+ <!--</resource-configuration>-->
+ </service>
</service>
</server>
</plugin>
\ No newline at end of file