summaryrefslogtreecommitdiffstats
path: root/gearman
diff options
context:
space:
mode:
authorSebastian Wagner2011-08-04 16:02:42 +0200
committerSebastian Wagner2011-08-04 16:02:42 +0200
commit2136a119999e62b0ac74b4fb205fb86b75027412 (patch)
tree6e810973fd13a405c975bf8a4b186f4142fb7e87 /gearman
parentfinal ping after wol implemented (diff)
downloadpoolctrl-2136a119999e62b0ac74b4fb205fb86b75027412.tar.gz
poolctrl-2136a119999e62b0ac74b4fb205fb86b75027412.tar.xz
poolctrl-2136a119999e62b0ac74b4fb205fb86b75027412.zip
shutdown action implemented
Diffstat (limited to 'gearman')
-rw-r--r--gearman/controllerWorker/ControllerWorker/Boot.java12
-rw-r--r--gearman/controllerWorker/ControllerWorker/Shutdown.java106
2 files changed, 106 insertions, 12 deletions
diff --git a/gearman/controllerWorker/ControllerWorker/Boot.java b/gearman/controllerWorker/ControllerWorker/Boot.java
index 5259ed1..cef8193 100644
--- a/gearman/controllerWorker/ControllerWorker/Boot.java
+++ b/gearman/controllerWorker/ControllerWorker/Boot.java
@@ -184,7 +184,6 @@ public class Boot extends Thread {
case 7:
GearmanJob pingJobWoL = pingWoLJobs.get(clientID);
-
if (pingJobWoL != null) {
Date currentDate = new Date();
Long currentTimestamp = currentDate.getTime();
@@ -204,7 +203,7 @@ public class Boot extends Thread {
if (alive.equals("true")) {
System.out.println(ipAddress
+ " is alive after WoL");
- status.put(clientID, 9); // alive
+ status.put(clientID, 9); // alive, go in successState
pingWoLJobs.remove(clientID);
} else {
System.out.println("ping again "
@@ -216,18 +215,21 @@ public class Boot extends Thread {
} else {
System.out.println(ipAddress
+ " is not alive after WoL");
- status.put(clientID, 8); // go in errorState
+ status.put(clientID, 8); // not alive, go in errorState
pingWoLJobs.remove(clientID);
}
}
+
break;
case 8:
- System.out.println("WoL Error"); // errorState
+ System.out.println("WoL failed after 2min"); // errorState
+
break;
case 9:
- System.out.println("WoL Success"); // successState
+ System.out.println("WoL successful"); // successState
+
break;
}
diff --git a/gearman/controllerWorker/ControllerWorker/Shutdown.java b/gearman/controllerWorker/ControllerWorker/Shutdown.java
index 6cb8645..738ea68 100644
--- a/gearman/controllerWorker/ControllerWorker/Shutdown.java
+++ b/gearman/controllerWorker/ControllerWorker/Shutdown.java
@@ -29,7 +29,8 @@ public class Shutdown extends Thread {
private final long updatePeriod;
private HashMap<Integer, GearmanJob> pingJobs;
- private HashMap<Integer, GearmanJob> wolJobs;
+ private HashMap<Integer, GearmanJob> whoJobs;
+ private HashMap<Integer, GearmanJob> shutdownJobs;
private HashMap<Integer, GearmanJob> sshJobs;
private HashMap<Integer, Integer> status;
private HashMap<Integer, Integer> errors;
@@ -42,7 +43,8 @@ public class Shutdown extends Thread {
public Shutdown(String serverAddress, int port,
Vector<HashMap<String, String>> clients, int updateRate) {
this.pingJobs = new HashMap<Integer, GearmanJob>();
- this.wolJobs = new HashMap<Integer, GearmanJob>();
+ this.whoJobs = new HashMap<Integer, GearmanJob>();
+ this.shutdownJobs = new HashMap<Integer, GearmanJob>();
this.sshJobs = new HashMap<Integer, GearmanJob>();
this.status = new HashMap<Integer, Integer>();
this.errors = new HashMap<Integer, Integer>();
@@ -81,7 +83,7 @@ public class Shutdown extends Thread {
}
}
this.finished = true;
- System.out.println("Booting finished");
+ System.out.println("Shutdown finished");
}
private Boolean update() throws IllegalStateException, IOException,
@@ -95,6 +97,64 @@ public class Shutdown extends Thread {
int clientStatus = status.get(clientID);
switch (clientStatus) {
+
+ case 0:
+ ping(client);
+
+ break;
+
+ case 1:
+ GearmanJob pingJob = pingJobs.get(clientID);
+
+ if (pingJob != null) {
+ GearmanJobStatus jobStatus = gearmanClient
+ .getJobStatus(pingJob);
+
+ if (!jobStatus.isKnown() && pingJob.isDone()) {
+ GearmanJobResult pingJobRes = pingJob.get();
+ String result = ByteUtils.fromUTF8Bytes(pingJobRes
+ .getResults());
+
+ if (result != "") {
+ JSONObject resultObj = (JSONObject) JSONValue
+ .parse(result);
+ String alive = resultObj.get("alive").toString();
+
+ if (alive.equals("true")) {
+ System.out.println(ipAddress + " alive");
+ status.put(clientID, 3); // alive, check Users
+ pingJobs.remove(clientID);
+ } else {
+ System.out.println(ipAddress + " not alive");
+ status.put(clientID, 5); // not alive, not needed, go in successState
+ pingJobs.remove(clientID);
+ }
+ }
+ }
+ }
+
+ break;
+
+ case 2:
+ woh(client);
+
+ break;
+
+ case 3:
+ shutdown(client);
+
+ break;
+
+ case 4:
+ System.out.println("Shutdown failed after 2min"); // errorState
+
+ break;
+
+ case 5:
+ System.out.println("Shutdown successful"); // successState
+
+ break;
+
}
if (clientStatus == 20) {
allFinished = true;
@@ -126,6 +186,34 @@ public class Shutdown extends Thread {
System.out.println("ping " + ipAddress);
}
+
+ private void woh(HashMap<String, String> client) {
+ String ipAddress = client.get("ip");
+ int clientID = Integer.parseInt(client.get("id"));
+
+ GearmanJob job = GearmanJobImpl.createJob("who", ipAddress.getBytes(),
+ "who" + clientID);
+ gearmanClient.submit(job);
+
+ status.put(clientID, 1); // who started
+ pingJobs.put(clientID, job);
+
+ System.out.println("who " + ipAddress);
+ }
+
+ private void shutdown(HashMap<String, String> client) {
+ String ipAddress = client.get("ip");
+ int clientID = Integer.parseInt(client.get("id"));
+
+ GearmanJob job = GearmanJobImpl.createJob("shutdown", ipAddress.getBytes(),
+ "shutdown" + clientID);
+ gearmanClient.submit(job);
+
+ status.put(clientID, 5); // ping started
+ pingJobs.put(clientID, job);
+
+ System.out.println("shutdown " + ipAddress);
+ }
private void ssh(HashMap<String, String> client) {
String ipAddress = client.get("ip");
@@ -157,13 +245,17 @@ public class Shutdown extends Thread {
return pingJobs;
}
- public HashMap<Integer, GearmanJob> getWolJobs() {
- return wolJobs;
- }
-
public HashMap<Integer, GearmanJob> getSshJobs() {
return sshJobs;
}
+
+ public HashMap<Integer, GearmanJob> getWhoJobs() {
+ return whoJobs;
+ }
+
+ public HashMap<Integer, GearmanJob> getShutdownJobs() {
+ return shutdownJobs;
+ }
public HashMap<Integer, Integer> getStatus() {
return status;