modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/CassandraNodeComponent.java
| 38 +++++++++-
1 file changed, 36 insertions(+), 2 deletions(-)
New commits:
commit bac87d4800260b79c0398291d3909aa1b383b5e2
Author: Thomas Segismont <tsegismo(a)redhat.com>
Date: Thu Jul 25 16:50:06 2013 +0200
Make CassandraNodeComponent shutdown operation wait for server to go down (unless
running on OSX)
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 37aa425..3e55a93 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
@@ -68,6 +68,7 @@ import org.rhq.core.pluginapi.util.ProcessExecutionUtility;
import org.rhq.core.system.ProcessExecution;
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;
@@ -140,7 +141,6 @@ public class CassandraNodeComponent extends
JMXServerComponent<ResourceComponent
if (isStorageServiceReachable()) {
return AvailabilityType.UP;
}
-
return AvailabilityType.DOWN;
} finally {
long totalTimeMillis = NANOSECONDS.toMillis(System.nanoTime() - start);
@@ -190,6 +190,7 @@ public class CassandraNodeComponent extends
JMXServerComponent<ResourceComponent
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();
@@ -238,7 +239,7 @@ public class CassandraNodeComponent extends
JMXServerComponent<ResourceComponent
protected OperationResult stopNode() {
ProcessInfo process = getResourceContext().getNativeProcess();
- if (processInfo == null) {
+ if (process == null) {
LOG.warn("Failed to obtain process info. It appears Cassandra is already
shutdown.");
return new OperationResult("Failed to obtain process info. It appears
Cassandra is already shutdown.");
}
@@ -265,6 +266,39 @@ public class CassandraNodeComponent extends
JMXServerComponent<ResourceComponent
}
}
+ private void waitForNodeToGoDown() throws InterruptedException {
+ if (OperatingSystem.getInstance().getName().equals(OperatingSystem.NAME_MACOSX))
{
+ // See this thread on VMWare forum:
http://communities.vmware.com/message/2187972#2187972
+ // Unfortunately there is no work around for this failure on Mac OSX so the
method will silently return on
+ // this platform.
+ return;
+ }
+ for (ProcessInfoSnapshot processInfoSnapshot = getProcessInfoSnapshot();;
processInfoSnapshot = getProcessInfoSnapshot()) {
+ if (processInfoSnapshot == null || !processInfoSnapshot.isRunning()) {
+ // Process not found, so it died, that's fine
+ // OR
+ // Process info says process is no longer running, that's fine as
well
+ break;
+ }
+ if (getResourceContext().getComponentInvocationContext().isInterrupted()) {
+ // Operation canceled or timed out
+ throw new InterruptedException();
+ }
+ // Process is still running, wait a second and check again
+ Thread.sleep(SECONDS.toMillis(2));
+ }
+ }
+
+ private ProcessInfoSnapshot getProcessInfoSnapshot() {
+ ProcessInfoSnapshot processInfoSnapshot = (processInfo == null) ? null :
processInfo.freshSnapshot();
+ if (processInfoSnapshot == null || !processInfoSnapshot.isRunning()) {
+ processInfo = getResourceContext().getNativeProcess();
+ // Safe to get prior snapshot here, we've just recreated the process info
instance
+ processInfoSnapshot = (processInfo == null) ? null :
processInfo.priorSnaphot();
+ }
+ return processInfoSnapshot;
+ }
+
protected OperationResult startNode() {
Configuration pluginConfig = getResourceContext().getPluginConfiguration();
String baseDir = pluginConfig.getSimpleValue("baseDir");