summaryrefslogtreecommitdiffstats
path: root/gearman
diff options
context:
space:
mode:
authorSebastian Wagner2011-08-05 15:43:30 +0200
committerSebastian Wagner2011-08-05 15:43:30 +0200
commit5fa15f76261ed4f6ac2bd219ce117bf3d29cad0c (patch)
tree144afc009c72512dcb716d995fad815fe83b8f4a /gearman
parentminor (diff)
downloadpoolctrl-5fa15f76261ed4f6ac2bd219ce117bf3d29cad0c.tar.gz
poolctrl-5fa15f76261ed4f6ac2bd219ce117bf3d29cad0c.tar.xz
poolctrl-5fa15f76261ed4f6ac2bd219ce117bf3d29cad0c.zip
shutdown changes
Diffstat (limited to 'gearman')
-rw-r--r--gearman/controllerWorker/ControllerWorker/Shutdown.java66
1 files changed, 64 insertions, 2 deletions
diff --git a/gearman/controllerWorker/ControllerWorker/Shutdown.java b/gearman/controllerWorker/ControllerWorker/Shutdown.java
index 738ea68..203af00 100644
--- a/gearman/controllerWorker/ControllerWorker/Shutdown.java
+++ b/gearman/controllerWorker/ControllerWorker/Shutdown.java
@@ -3,6 +3,7 @@ package ControllerWorker;
import java.io.IOException;
import java.lang.Thread;
import java.util.concurrent.ExecutionException;
+import java.util.Date;
import java.util.HashMap;
import java.util.Vector;
@@ -31,9 +32,11 @@ public class Shutdown extends Thread {
private HashMap<Integer, GearmanJob> pingJobs;
private HashMap<Integer, GearmanJob> whoJobs;
private HashMap<Integer, GearmanJob> shutdownJobs;
+ private HashMap<Integer, GearmanJob> pingShutdownJobs;
private HashMap<Integer, GearmanJob> sshJobs;
private HashMap<Integer, Integer> status;
private HashMap<Integer, Integer> errors;
+ private HashMap<Integer, Long> pingShutdownTime;
private Vector<HashMap<String, String>> clients;
@@ -126,7 +129,7 @@ public class Shutdown extends Thread {
pingJobs.remove(clientID);
} else {
System.out.println(ipAddress + " not alive");
- status.put(clientID, 5); // not alive, not needed, go in successState
+ status.put(clientID, 7); // not alive, go in successState
pingJobs.remove(clientID);
}
}
@@ -146,11 +149,56 @@ public class Shutdown extends Thread {
break;
case 4:
+ pingShutdown(client);
+
+ break;
+
+ case 5:
+ GearmanJob pingJobShutdown = pingShutdownJobs.get(clientID);
+ if (pingJobShutdown != null) {
+ Date currentDate = new Date();
+ Long currentTimestamp = currentDate.getTime();
+ Long expectedTimestamp = this.pingShutdownTime.get(clientID) + 120000L; //wait 2 min until WoL-Failed
+ if (expectedTimestamp >= currentTimestamp) {
+ GearmanJobStatus jobStatus = gearmanClient
+ .getJobStatus(pingJobShutdown);
+ if (!jobStatus.isKnown() && pingJobShutdown.isDone()) {
+ GearmanJobResult pingJobRes = pingJobShutdown.get();
+ String result = ByteUtils.fromUTF8Bytes(pingJobRes
+ .getResults());
+ if (result != "") {
+ JSONObject resultObj = (JSONObject) JSONValue
+ .parse(result);
+ String alive = resultObj.get("alive")
+ .toString();
+ if (alive.equals("false")) {
+ System.out.println(ipAddress
+ + " is alive after shutdown. Ping again...");
+ status.put(clientID, 4); // alive, go in successState
+ pingShutdownJobs.remove(clientID);
+ } else {
+ System.out.println("not alive after shutdown"
+ +ipAddress);
+ status.put(clientID, 7); // again ping
+ }
+ }
+ }
+ } else {
+ System.out.println(ipAddress
+ + " is alive after shutdown");
+ status.put(clientID, 6); // not alive, go in errorState
+ pingShutdownJobs.remove(clientID);
+ }
+ }
+
+ break;
+
+ case 6:
System.out.println("Shutdown failed after 2min"); // errorState
break;
- case 5:
+ case 7:
System.out.println("Shutdown successful"); // successState
break;
@@ -214,6 +262,20 @@ public class Shutdown extends Thread {
System.out.println("shutdown " + ipAddress);
}
+
+ private void pingShutdown(HashMap<String, String> client) {
+ String ipAddress = client.get("ip");
+ int clientID = Integer.parseInt(client.get("id"));
+
+ GearmanJob job = GearmanJobImpl.createJob("ping", ipAddress.getBytes(),
+ "ping" + clientID);
+ gearmanClient.submit(job);
+
+ status.put(clientID, 7); // ping started
+ pingShutdownJobs.put(clientID, job);
+
+ System.out.println("ping " + ipAddress);
+ }
private void ssh(HashMap<String, String> client) {
String ipAddress = client.get("ip");