From a16885831eb11d282108b3c2f6091c966c471ca4 Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Wed, 10 Aug 2011 12:55:56 +0200 Subject: verschiedene Korrekturen --- .../controllerWorker/ControllerWorker/Boot.java | 153 ++++++++++++++------- .../ControllerWorker/StatusWorker.java | 25 +++- 2 files changed, 123 insertions(+), 55 deletions(-) (limited to 'gearman') 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 whoJobs; private HashMap checkStatusJobs; private HashMap restartJobs; + private HashMap pingRestartJobs; private HashMap status; - private HashMap errors; + private HashMap errors; private HashMap pingWolTime; + private HashMap pingRestartTime; private Vector> clients; @@ -58,9 +60,11 @@ public class Boot extends Thread { this.whoJobs = new HashMap(); this.checkStatusJobs = new HashMap(); this.restartJobs = new HashMap(); + this.pingRestartJobs = new HashMap(); this.status = new HashMap(); - this.errors = new HashMap(); + this.errors = new HashMap(); this.pingWolTime = new HashMap(); + this.pingRestartTime = new HashMap(); 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 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 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 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> getClients() { return clients; } - - public GearmanClient getGearmanClient() { - return gearmanClient; - } - - public GearmanJobServerConnection getGearmanConnection() { - return gearmanConnection; - } - - public HashMap getPingJobs() { - return pingJobs; - } - - public HashMap getWolJobs() { - return wolJobs; - } - - public HashMap getOsJobs() { - return osJobs; - } - - public HashMap getWhoJobs() { - return whoJobs; - } - - public HashMap getCheckstatusJobs() { - return checkStatusJobs; - } - - public HashMap getRestartJobs() { - return restartJobs; - } - - public HashMap getErrors() { - return errors; - } } diff --git a/gearman/controllerWorker/ControllerWorker/StatusWorker.java b/gearman/controllerWorker/ControllerWorker/StatusWorker.java index c8b9b57..7343ba5 100644 --- a/gearman/controllerWorker/ControllerWorker/StatusWorker.java +++ b/gearman/controllerWorker/ControllerWorker/StatusWorker.java @@ -39,24 +39,39 @@ public class StatusWorker extends AbstractGearmanFunction { if (type.equals("boot")) { for (String event : events) { Boot boot = BOOTTHREADS.get(event); + Vector> clients = boot.getClients(); if (boot.isFinished()) { res[count] = "Booting of " + event + " finished!"; + boot = null; } else if (boot.isFinishedWithErrors()) { res[count] = "Booting of " + event + " finished with errors!"; + String[] clientErrors = new String[clients.size()]; + int statusCount = 0; + for (HashMap client : clients) { + String ipAddress = client.get("ip"); + String errorText = boot.getError(client); + clientErrors[statusCount] = "Error of the client with the ip " + + ipAddress + ": " + errorText; + statusCount++; + } + String jsonClientErrors = JSONValue + .toJSONString(clientErrors); + res[count] += jsonClientErrors; } else { res[count] = "Booting of " + event + " not yet finished!"; - Vector> clients = boot.getClients(); - String[] clientStatus = new String[clients.size()]; + String[] clientStatus = new String[clients.size()]; int statusCount = 0; - for(HashMap client: clients) { + for (HashMap client : clients) { String ipAddress = client.get("ip"); String statusText = boot.getStatusText(client); - clientStatus[statusCount] = "Status of the client with the ip " + ipAddress + ": " + statusText; + clientStatus[statusCount] = "Status of the client with the ip " + + ipAddress + ": " + statusText; statusCount++; } - String jsonClientStatus = JSONValue.toJSONString(clientStatus); + String jsonClientStatus = JSONValue + .toJSONString(clientStatus); res[count] += jsonClientStatus; } -- cgit v1.2.3-55-g7522