summaryrefslogtreecommitdiffstats
path: root/gearman/controllerWorker/ControllerWorker/Boot.java
diff options
context:
space:
mode:
authorBjörn Geiger2011-08-10 12:55:56 +0200
committerBjörn Geiger2011-08-10 12:55:56 +0200
commita16885831eb11d282108b3c2f6091c966c471ca4 (patch)
tree211d244a4cac4b45f680fbaba4adbc9b339e8385 /gearman/controllerWorker/ControllerWorker/Boot.java
parentcheckstatus actions (diff)
downloadpoolctrl-a16885831eb11d282108b3c2f6091c966c471ca4.tar.gz
poolctrl-a16885831eb11d282108b3c2f6091c966c471ca4.tar.xz
poolctrl-a16885831eb11d282108b3c2f6091c966c471ca4.zip
verschiedene Korrekturen
Diffstat (limited to 'gearman/controllerWorker/ControllerWorker/Boot.java')
-rw-r--r--gearman/controllerWorker/ControllerWorker/Boot.java153
1 files changed, 103 insertions, 50 deletions
diff --git a/gearman/controllerWorker/ControllerWorker/Boot.java b/gearman/controllerWorker/ControllerWorker/Boot.java
index 238ec99..462508e 100644
--- a/gearman/controllerWorker/ControllerWorker/Boot.java
+++ b/gearman/controllerWorker/ControllerWorker/Boot.java
@@ -39,9 +39,11 @@ public class Boot extends Thread {
private HashMap<Integer, GearmanJob> whoJobs;
private HashMap<Integer, GearmanJob> checkStatusJobs;
private HashMap<Integer, GearmanJob> restartJobs;
+ private HashMap<Integer, GearmanJob> pingRestartJobs;
private HashMap<Integer, Integer> status;
- private HashMap<Integer, Integer> errors;
+ private HashMap<Integer, String> errors;
private HashMap<Integer, Long> pingWolTime;
+ private HashMap<Integer, Long> pingRestartTime;
private Vector<HashMap<String, String>> clients;
@@ -58,9 +60,11 @@ public class Boot extends Thread {
this.whoJobs = new HashMap<Integer, GearmanJob>();
this.checkStatusJobs = new HashMap<Integer, GearmanJob>();
this.restartJobs = new HashMap<Integer, GearmanJob>();
+ this.pingRestartJobs = new HashMap<Integer, GearmanJob>();
this.status = new HashMap<Integer, Integer>();
- this.errors = new HashMap<Integer, Integer>();
+ this.errors = new HashMap<Integer, String>();
this.pingWolTime = new HashMap<Integer, Long>();
+ this.pingRestartTime = new HashMap<Integer, Long>();
this.updateRate = updateRate; // updates per second
this.updatePeriod = 1000000000L / this.updateRate; // nanoseconds
this.gearmanConnection = new GearmanNIOJobServerConnection(
@@ -83,7 +87,7 @@ public class Boot extends Thread {
this.statusText[4] = "Wake on LAN has been started.";
this.statusText[5] = "Magic packet has been send.";
this.statusText[6] = "Ping after wake on LAN has been started.";
- this.statusText[7] = "Doing ping again and again, until client is alive or two minutes has been elapsed";
+ this.statusText[7] = "Doing ping after wake on LAN again and again, until client is alive or two minutes has been elapsed";
this.statusText[8] = "The check for the correct operating system has been started.";
this.statusText[9] = "Wrong operating system is running.";
this.statusText[10] = "The check if a user is logged in has been started.";
@@ -91,9 +95,9 @@ public class Boot extends Thread {
this.statusText[12] = "The check if the user is working has been started.";
this.statusText[13] = "The user is not working.";
this.statusText[14] = "A restart of the client has been triggered.";
- this.statusText[15] = "The user is working.";
- this.statusText[16] = "";
- this.statusText[17] = "";
+ this.statusText[15] = "Ping after restart has been started.";
+ this.statusText[16] = "Doing ping after restart again and again, until client is alive or two minutes has been elapsed";
+ this.statusText[17] = "The user is working.";
this.statusText[18] = "Booting has not been finished, due to an error.";
this.statusText[19] = "Booting has been finished.";
}
@@ -196,6 +200,15 @@ public class Boot extends Thread {
+ " Magic packet send.");
status.put(clientID, 5); // magic packet send
wolJobs.remove(clientID);
+ } else {
+ System.out.println(ipAddress
+ + " is not alive after WoL");
+ this.errors
+ .put(clientID,
+ "Sending the magic packet has been failed.");
+ status.put(clientID, 18); // magic packet not send,
+ // go in errorState
+ wolJobs.remove(clientID);
}
}
}
@@ -250,6 +263,8 @@ public class Boot extends Thread {
} else {
System.out.println(ipAddress
+ " is not alive after WoL");
+ this.errors.put(clientID,
+ "The wake on LAN has been failed.");
status.put(clientID, 18); // not alive, go in errorState
pingWoLJobs.remove(clientID);
}
@@ -272,10 +287,12 @@ public class Boot extends Thread {
if (result != "") {
JSONObject resultObj = (JSONObject) JSONValue
.parse(result);
- String release = resultObj.get("Release")
- .toString();
- String distriputorID = resultObj.get(
- "Distributor ID").toString();
+ /*
+ * String release =
+ * resultObj.get("Release").toString(); String
+ * distriputorID =
+ * resultObj.get("Distributor ID").toString();
+ */
String description = resultObj.get("Description")
.toString();
@@ -323,13 +340,13 @@ public class Boot extends Thread {
user = str.nextToken();
}
- if (user.equals("root")) {
+ if (user.isEmpty()) {
System.out.println(ipAddress + " right User");
- status.put(clientID, 19); // go in successState
+ status.put(clientID, 13); // right user
pingJobs.remove(clientID);
} else {
System.out.println(ipAddress + " wrong User");
- status.put(clientID, 11); // check User
+ status.put(clientID, 11); // wrong user
pingJobs.remove(clientID);
}
}
@@ -354,11 +371,63 @@ public class Boot extends Thread {
break;
case 14:
- System.out.println("Restart Logik");
+ date = new Date();
+ timestamp = date.getTime();
+ pingRestartTime.put(clientID, timestamp);
+ status.put(clientID, 15); // ping after restart
break;
case 15:
+ pingRestart(client);
+
+ break;
+
+ case 16:
+ GearmanJob pingJobRestart = pingRestartJobs.get(clientID);
+ if (pingJobRestart != null) {
+ Date currentDate = new Date();
+ Long currentTimestamp = currentDate.getTime();
+ // wait 2 min until Restart - Failed
+ Long expectedTimestamp = this.pingRestartTime.get(clientID) + 120000L;
+ if (expectedTimestamp >= currentTimestamp) {
+ GearmanJobStatus jobStatus = gearmanClient
+ .getJobStatus(pingJobRestart);
+ if (!jobStatus.isKnown() && pingJobRestart.isDone()) {
+ GearmanJobResult pingJobRes = pingJobRestart.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
+ + " is alive after restart");
+ // alive, go in successState
+ status.put(clientID, 19);
+ pingWoLJobs.remove(clientID);
+ } else {
+ System.out.println("ping again "
+ + ipAddress);
+ status.put(clientID, 15); // again ping
+ }
+ }
+ }
+ } else {
+ System.out.println(ipAddress
+ + " is not alive after restart");
+ this.errors.put(clientID,
+ "The restart has been failed.");
+ status.put(clientID, 18); // not alive, go in errorState
+ pingWoLJobs.remove(clientID);
+ }
+ }
+
+ break;
+
+ case 17:
System.out.println("User is working Logik");
break;
@@ -420,6 +489,20 @@ public class Boot extends Thread {
System.out.println("ping " + ipAddress);
}
+ private void pingRestart(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, 16); // pingRestart started
+ pingRestartJobs.put(clientID, job);
+
+ System.out.println("ping " + ipAddress);
+ }
+
private void wakeOnLan(HashMap<String, String> client) {
String macAddress = client.get("mac");
int clientID = Integer.parseInt(client.get("id"));
@@ -496,6 +579,12 @@ public class Boot extends Thread {
return this.statusText[clientStatus];
}
+ public String getError(HashMap<String, String> client) {
+ int clientID = Integer.parseInt(client.get("id"));
+ String clientError = this.errors.get(clientID);
+ return clientError;
+ }
+
public Boolean isFinished() {
return finished;
}
@@ -507,40 +596,4 @@ public class Boot extends Thread {
public Vector<HashMap<String, String>> getClients() {
return clients;
}
-
- public GearmanClient getGearmanClient() {
- return gearmanClient;
- }
-
- public GearmanJobServerConnection getGearmanConnection() {
- return gearmanConnection;
- }
-
- public HashMap<Integer, GearmanJob> getPingJobs() {
- return pingJobs;
- }
-
- public HashMap<Integer, GearmanJob> getWolJobs() {
- return wolJobs;
- }
-
- public HashMap<Integer, GearmanJob> getOsJobs() {
- return osJobs;
- }
-
- public HashMap<Integer, GearmanJob> getWhoJobs() {
- return whoJobs;
- }
-
- public HashMap<Integer, GearmanJob> getCheckstatusJobs() {
- return checkStatusJobs;
- }
-
- public HashMap<Integer, GearmanJob> getRestartJobs() {
- return restartJobs;
- }
-
- public HashMap<Integer, Integer> getErrors() {
- return errors;
- }
}