summaryrefslogtreecommitdiffstats
path: root/gearman/controllerWorker/ControllerWorker
diff options
context:
space:
mode:
authorSebastian Wagner2011-08-16 17:03:43 +0200
committerSebastian Wagner2011-08-16 17:03:43 +0200
commitd8edfcbb8ccc8e678794e00f4928964915aa8146 (patch)
tree6af56572b6b155486d5339b4793d70e788872dea /gearman/controllerWorker/ControllerWorker
parentminor (diff)
downloadpoolctrl-d8edfcbb8ccc8e678794e00f4928964915aa8146.tar.gz
poolctrl-d8edfcbb8ccc8e678794e00f4928964915aa8146.tar.xz
poolctrl-d8edfcbb8ccc8e678794e00f4928964915aa8146.zip
reboot changes
Diffstat (limited to 'gearman/controllerWorker/ControllerWorker')
-rw-r--r--gearman/controllerWorker/ControllerWorker/Boot.java210
1 files changed, 158 insertions, 52 deletions
diff --git a/gearman/controllerWorker/ControllerWorker/Boot.java b/gearman/controllerWorker/ControllerWorker/Boot.java
index f004366..2fe7879 100644
--- a/gearman/controllerWorker/ControllerWorker/Boot.java
+++ b/gearman/controllerWorker/ControllerWorker/Boot.java
@@ -40,11 +40,13 @@ public class Boot extends Thread {
private HashMap<Integer, GearmanJob> whoJobs;
private HashMap<Integer, GearmanJob> psJobs;
private HashMap<Integer, GearmanJob> restartJobs;
- private HashMap<Integer, GearmanJob> pingRestartJobs;
+ private HashMap<Integer, GearmanJob> pingRestartShutdownJobs;
+ private HashMap<Integer, GearmanJob> pingRestartBootJobs;
private HashMap<Integer, Integer> status;
private HashMap<Integer, String> errors;
private HashMap<Integer, Long> pingWolTime;
- private HashMap<Integer, Long> pingRestartTime;
+ private HashMap<Integer, Long> pingRestartShutdownTime;
+ private HashMap<Integer, Long> pingRestartBootTime;
private Vector<HashMap<String, String>> clients;
@@ -61,11 +63,13 @@ public class Boot extends Thread {
this.whoJobs = new HashMap<Integer, GearmanJob>();
this.psJobs = new HashMap<Integer, GearmanJob>();
this.restartJobs = new HashMap<Integer, GearmanJob>();
- this.pingRestartJobs = new HashMap<Integer, GearmanJob>();
+ this.pingRestartShutdownJobs = new HashMap<Integer, GearmanJob>();
+ this.pingRestartBootJobs = new HashMap<Integer, GearmanJob>();
this.status = new HashMap<Integer, Integer>();
this.errors = new HashMap<Integer, String>();
this.pingWolTime = new HashMap<Integer, Long>();
- this.pingRestartTime = new HashMap<Integer, Long>();
+ this.pingRestartShutdownTime = new HashMap<Integer, Long>();
+ this.pingRestartBootTime = new HashMap<Integer, Long>();
this.updateRate = updateRate; // updates per second
this.updatePeriod = 1000000000L / this.updateRate; // nanoseconds
this.gearmanConnection = new GearmanNIOJobServerConnection(
@@ -81,7 +85,7 @@ public class Boot extends Thread {
this.finished = false;
this.error = false;
this.bootOS = bootOS;
- this.statusText = new String[21];
+ this.statusText = new String[31];
this.statusText[0] = "The booting process of the client has been started.";
this.statusText[1] = "The ping has been started.";
this.statusText[2] = "The client is alive.";
@@ -98,11 +102,14 @@ public class Boot extends Thread {
this.statusText[13] = "The user is not working.";
this.statusText[14] = "A restart of the client has been triggered.";
this.statusText[15] = "The restart command has been sent.";
- this.statusText[16] = "The ping after restart has been started.";
- this.statusText[17] = "Doing ping after restart again and again, until client is alive or two minutes has been elapsed";
+ this.statusText[16] = "The ping after shutdown has been started.";
+ this.statusText[17] = "Doing ping after shutdown again and again, until client is not alive or two minutes has been elapsed";
this.statusText[18] = "The user is working.";
- this.statusText[19] = "Booting of the client has not been finished, due to an error.";
- this.statusText[20] = "Booting of the client has been finished.";
+ this.statusText[19] = "The client has been shutted down.";
+ this.statusText[20] = "The ping after reboot has been started.";
+ this.statusText[21] = "Doing ping after reboot again and again, until client is not alive or two minutes has been elapsed";
+ this.statusText[29] = "Booting of the client has not been finished, due to an error.";
+ this.statusText[30] = "Booting of the client has been finished.";
}
public void run() {
@@ -166,7 +173,7 @@ public class Boot extends Thread {
System.out.println(ipAddress + " alive");
status.put(clientID, 2); // alive
pingJobs.remove(clientID);
- } else {
+ } else if (alive.equals("false")) {
System.out
.println(ipAddress + " not alive");
status.put(clientID, 3); // not alive
@@ -179,7 +186,7 @@ public class Boot extends Thread {
.put(clientID,
"Sending the ping message has been failed.");
// sending the ping message has been failed
- status.put(clientID, 19);
+ status.put(clientID, 29);
pingJobs.remove(clientID);
}
}
@@ -221,7 +228,7 @@ public class Boot extends Thread {
.put(clientID,
"Sending the magic packet has been failed.");
// cannot send magic packet, go in errorState
- status.put(clientID, 19);
+ status.put(clientID, 29);
wolJobs.remove(clientID);
}
}
@@ -267,9 +274,9 @@ public class Boot extends Thread {
System.out.println(ipAddress
+ " is alive after WoL");
// alive, go in successState
- status.put(clientID, 20);
+ status.put(clientID, 30);
pingWoLJobs.remove(clientID);
- } else {
+ } else if (alive.equals("false")) {
System.out.println("ping again "
+ ipAddress);
status.put(clientID, 6); // again ping
@@ -286,7 +293,7 @@ public class Boot extends Thread {
* sending the ping after wake on LAN
* message has been failed
*/
- status.put(clientID, 19);
+ status.put(clientID, 29);
pingWoLJobs.remove(clientID);
}
}
@@ -296,7 +303,7 @@ public class Boot extends Thread {
+ " is not alive after WoL");
this.errors.put(clientID,
"The wake on LAN has been failed.");
- status.put(clientID, 19); // not alive, go in errorState
+ status.put(clientID, 29); // not alive, go in errorState
pingWoLJobs.remove(clientID);
}
}
@@ -330,7 +337,7 @@ public class Boot extends Thread {
if (description.equals(this.bootOS)) {
System.out.println(ipAddress + " right OS");
- status.put(clientID, 20); // right os
+ status.put(clientID, 30); // right os
osJobs.remove(clientID);
} else {
System.out.println(ipAddress + " wrong OS");
@@ -344,7 +351,7 @@ public class Boot extends Thread {
.put(clientID,
"The check for correct operating system has been failed.");
// cannot check os, go in errorState
- status.put(clientID, 19);
+ status.put(clientID, 29);
osJobs.remove(clientID);
}
}
@@ -407,7 +414,7 @@ public class Boot extends Thread {
* cannot check if a user is logged in, go in
* errorState
*/
- status.put(clientID, 19);
+ status.put(clientID, 29);
whoJobs.remove(clientID);
}
}
@@ -460,7 +467,7 @@ public class Boot extends Thread {
"The check if a user is working has been failed.");
// cannot check if user is working, go in
// errorState
- status.put(clientID, 19);
+ status.put(clientID, 29);
psJobs.remove(clientID);
}
}
@@ -501,7 +508,7 @@ public class Boot extends Thread {
"Sending the restart command has been failed.");
// cannot send restart command, go in
// errorState
- status.put(clientID, 19);
+ status.put(clientID, 29);
restartJobs.remove(clientID);
}
}
@@ -513,29 +520,32 @@ public class Boot extends Thread {
case 15:
date = new Date();
timestamp = date.getTime();
- pingRestartTime.put(clientID, timestamp);
- status.put(clientID, 16); // ping after restart
+ pingRestartShutdownTime.put(clientID, timestamp);
+ status.put(clientID, 16); // ping after restart shutdown
break;
case 16:
- pingRestart(client);
+ pingRestartShutdown(client);
break;
case 17:
- GearmanJob pingJobRestart = pingRestartJobs.get(clientID);
- if (pingJobRestart != null) {
+ GearmanJob pingJobRestartShutdown = pingRestartShutdownJobs
+ .get(clientID);
+ if (pingJobRestartShutdown != null) {
Date currentDate = new Date();
Long currentTimestamp = currentDate.getTime();
// wait 2 min until Restart - Failed
- Long expectedTimestamp = this.pingRestartTime.get(clientID)
+ Long expectedTimestamp = this.pingRestartShutdownTime
+ .get(clientID)
+ waitTime;
if (expectedTimestamp >= currentTimestamp) {
GearmanJobStatus jobStatus = gearmanClient
- .getJobStatus(pingJobRestart);
- if (!jobStatus.isKnown() && pingJobRestart.isDone()) {
- GearmanJobResult pingJobRestartRes = pingJobRestart
+ .getJobStatus(pingJobRestartShutdown);
+ if (!jobStatus.isKnown()
+ && pingJobRestartShutdown.isDone()) {
+ GearmanJobResult pingJobRestartRes = pingJobRestartShutdown
.get();
String result = ByteUtils
.fromUTF8Bytes(pingJobRestartRes
@@ -548,15 +558,18 @@ public class Boot extends Thread {
.toString();
if (alive.equals("true")) {
System.out.println(ipAddress
- + " is alive after restart");
- // alive, go in successState
- status.put(clientID, 20);
- pingRestartJobs.remove(clientID);
- } else {
- System.out.println("ping again "
- + ipAddress);
- status.put(clientID, 16); // again ping
- pingRestartJobs.remove(clientID);
+ + " is still alive");
+ // alive, ping again
+ status.put(clientID, 16);
+ pingRestartShutdownJobs
+ .remove(clientID);
+ } else if (alive.equals("false")) {
+ System.out.println(ipAddress
+ + " is down");
+ // not alive, ping again
+ status.put(clientID, 19); // is down
+ pingRestartShutdownJobs
+ .remove(clientID);
}
} else {
System.out
@@ -569,18 +582,18 @@ public class Boot extends Thread {
* sending the ping after restart message
* has been failed
*/
- status.put(clientID, 19);
- pingRestartJobs.remove(clientID);
+ status.put(clientID, 29);
+ pingRestartShutdownJobs.remove(clientID);
}
}
}
} else {
- System.out.println(ipAddress
- + " is not alive after restart");
+ System.out.println(ipAddress + " shutdown failed");
this.errors.put(clientID,
- "The restart has been failed.");
- status.put(clientID, 19); // not alive, go in errorState
- pingRestartJobs.remove(clientID);
+ "The shutdown has been failed.");
+ status.put(clientID, 29); // still alive, go in
+ // errorState
+ pingRestartShutdownJobs.remove(clientID);
}
}
@@ -592,20 +605,99 @@ public class Boot extends Thread {
break;
case 19:
- System.out.println("Boot failed"); // errorState
+ date = new Date();
+ timestamp = date.getTime();
+ pingRestartBootTime.put(clientID, timestamp);
+ status.put(clientID, 20); // ping after restart boot
break;
case 20:
+ pingRestartBoot(client);
+
+ break;
+
+ case 21:
+ GearmanJob pingJobRestartBoot = pingRestartBootJobs
+ .get(clientID);
+ if (pingJobRestartBoot != null) {
+ Date currentDate = new Date();
+ Long currentTimestamp = currentDate.getTime();
+ // wait 2 min until Restart - Failed
+ Long expectedTimestamp = this.pingRestartBootTime
+ .get(clientID)
+ + waitTime;
+ if (expectedTimestamp >= currentTimestamp) {
+ GearmanJobStatus jobStatus = gearmanClient
+ .getJobStatus(pingJobRestartBoot);
+ if (!jobStatus.isKnown() && pingJobRestartBoot.isDone()) {
+ GearmanJobResult pingJobRestartRes = pingJobRestartBoot
+ .get();
+ String result = ByteUtils
+ .fromUTF8Bytes(pingJobRestartRes
+ .getResults());
+ if (!result.isEmpty()) {
+ JSONObject resultObj = (JSONObject) JSONValue
+ .parse(result);
+ if (!resultObj.containsKey("err")) {
+ String alive = resultObj.get("alive")
+ .toString();
+ if (alive.equals("true")) {
+ System.out.println(ipAddress
+ + " is alive after restart");
+ // alive, go to success state
+ status.put(clientID, 30);
+ pingRestartBootJobs.remove(clientID);
+ } else if (alive.equals("false")) {
+ System.out.println("ping again "
+ + ipAddress);
+ // not alive, ping again
+ status.put(clientID, 20); // again ping
+ pingRestartBootJobs.remove(clientID);
+ }
+ } else {
+ System.out
+ .println(ipAddress
+ + " Cannot send the ping after restart message.");
+ this.errors
+ .put(clientID,
+ "Sending the ping after restart message has been failed.");
+ /*
+ * sending the ping after restart message
+ * has been failed
+ */
+ status.put(clientID, 29);
+ pingRestartBootJobs.remove(clientID);
+ }
+ }
+ }
+ } else {
+ System.out.println(ipAddress
+ + " is not alive after reboot");
+ this.errors
+ .put(clientID, "The reboot has been failed.");
+ status.put(clientID, 29); // not alive, go in errorState
+ pingRestartBootJobs.remove(clientID);
+ }
+ }
+
+ break;
+
+ case 29:
+ System.out.println("Boot failed"); // errorState
+
+ break;
+
+ case 30:
System.out.println("Boot successful"); // successState
break;
}
- if (clientStatus == 20) {
+ if (clientStatus == 30) {
allFinished = true;
- } else if (clientStatus == 19) {
+ } else if (clientStatus == 29) {
allFinished = true;
this.error = true;
} else {
@@ -648,7 +740,21 @@ public class Boot extends Thread {
System.out.println("ping " + ipAddress);
}
- private void pingRestart(HashMap<String, String> client) {
+ private void pingRestartShutdown(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, 17); // pingRestartShutdown started
+ pingRestartShutdownJobs.put(clientID, job);
+
+ System.out.println("ping " + ipAddress);
+ }
+
+ private void pingRestartBoot(HashMap<String, String> client) {
String ipAddress = client.get("ip");
int clientID = Integer.parseInt(client.get("id"));
@@ -656,8 +762,8 @@ public class Boot extends Thread {
"ping" + clientID);
gearmanClient.submit(job);
- status.put(clientID, 17); // pingRestart started
- pingRestartJobs.put(clientID, job);
+ status.put(clientID, 21); // pingRestartBoot started
+ pingRestartBootJobs.put(clientID, job);
System.out.println("ping " + ipAddress);
}