modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/CassandraNodeComponent.java
| 52 ++++++++--
1 file changed, 46 insertions(+), 6 deletions(-)
New commits:
commit 067cb8cc2d2204e187f104ad7cb5b8de2220cc25
Author: John Sanda <jsanda(a)redhat.com>
Date: Wed Jul 24 23:07:53 2013 -0400
do availability check via jmx
CassandraNodeComponent previously was doing availability checks at the process
level. Results were some times inconsistent in large part due to different
behaviors on different platforms. Doing a JMX check is a more representative
check since we perform most of the managemeent via JMX. It also eliminates any
platform-specific issues.
The check is done via a direct JMX connection instead of EMS to avoid the
caching issues with EMS that could yield inaccurate results.
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 c41e8e7..70ba4b2 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
@@ -35,6 +35,12 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Cluster.Builder;
import com.datastax.driver.core.Session;
@@ -131,10 +137,11 @@ public class CassandraNodeComponent extends
JMXServerComponent<ResourceComponent
public AvailabilityType getAvailability() {
long start = System.nanoTime();
try {
- // Get a fresh snapshot of the process
- ProcessInfoSnapshot processInfoSnapshot = getProcessInfoSnapshot();
- return (processInfoSnapshot != null &&
processInfoSnapshot.isRunning()) ? AvailabilityType.UP
- : AvailabilityType.DOWN;
+ if (isStorageServiceReachable()) {
+ return AvailabilityType.UP;
+ }
+
+ return AvailabilityType.DOWN;
} finally {
long totalTimeMillis = NANOSECONDS.toMillis(System.nanoTime() - start);
if (LOG.isDebugEnabled()) {
@@ -146,6 +153,39 @@ public class CassandraNodeComponent extends
JMXServerComponent<ResourceComponent
}
}
+ private boolean isStorageServiceReachable() {
+ JMXConnector connector = null;
+ try {
+ Configuration pluginConfig = getResourceContext().getPluginConfiguration();
+ String url = pluginConfig.getSimpleValue("connectorAddress");
+ JMXServiceURL serviceURL = new JMXServiceURL(url);
+ connector = JMXConnectorFactory.connect(serviceURL, null);
+
+ MBeanServerConnection serverConnection =
connector.getMBeanServerConnection();
+ ObjectName storageService = new
ObjectName("org.apache.cassandra.db:type=StorageService");
+
+ // query an attribute to make sure it is in fact available
+ serverConnection.getAttribute(storageService,
"NativeTransportRunning");
+
+ return true;
+ } catch (Exception e) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Failed to make JMX connection to StorageService",
e);
+ }
+ return false;
+ } finally {
+ if (connector != null) {
+ try {
+ connector.close();
+ } catch (IOException e) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("An error occurred closing the JMX
connector", e);
+ }
+ }
+ }
+ }
+ }
+
private ProcessInfoSnapshot getProcessInfoSnapshot() {
ProcessInfoSnapshot processInfoSnapshot = (processInfo == null) ? null :
processInfo.freshSnapshot();
if (processInfoSnapshot == null || !processInfoSnapshot.isRunning()) {
@@ -158,10 +198,8 @@ public class CassandraNodeComponent extends
JMXServerComponent<ResourceComponent
@Override
public OperationResult invokeOperation(String name, Configuration parameters) throws
Exception {
-
if (name.equals("shutdown")) {
OperationResult operationResult = shutdownNode();
- waitForNodeToGoDown();
return operationResult;
} else if (name.equals("start")) {
return startNode();
@@ -234,6 +272,8 @@ public class CassandraNodeComponent extends
JMXServerComponent<ResourceComponent
long pid = process.getPid();
try {
+ getEmsConnection().close();
+
process.kill("KILL");
Configuration pluginConfig = getResourceContext().getPluginConfiguration();
Show replies by date