From d35a25831e6b370650f9b04ec279bfde6a8c7233 Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Wed, 10 Aug 2011 14:17:07 +0200 Subject: Fehler korrigiert --- .../ControllerWorker/StatusWorker.java | 121 ++++++++++++--------- 1 file changed, 69 insertions(+), 52 deletions(-) (limited to 'gearman') diff --git a/gearman/controllerWorker/ControllerWorker/StatusWorker.java b/gearman/controllerWorker/ControllerWorker/StatusWorker.java index f67eeb0..59f37d7 100644 --- a/gearman/controllerWorker/ControllerWorker/StatusWorker.java +++ b/gearman/controllerWorker/ControllerWorker/StatusWorker.java @@ -1,6 +1,7 @@ package ControllerWorker; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Vector; import org.gearman.client.GearmanJobResult; @@ -27,95 +28,111 @@ public class StatusWorker extends AbstractGearmanFunction { JSONObject jsonObject = (JSONObject) JSONValue.parse(data); String type = jsonObject.get("type").toString(); JSONArray jsonArray = (JSONArray) jsonObject.get("events"); - for (Object eventObj : jsonArray) { String event = eventObj.toString(); events.add(event); } - - String[] res = new String[jsonArray.size()]; + LinkedHashMap res = new LinkedHashMap(); int count = 0; - if (type.equals("boot")) { for (String event : events) { Boot boot = BOOTTHREADS.get(event); - if (boot != null) { + if (BOOTTHREADS.containsKey(event)) { Vector> clients = boot.getClients(); - if (boot.isFinished()) { - res[count] = "Booting of " + event - + " has been finished!"; + res.put(event, "Booting of " + event + + " has been finished!"); boot = null; } else if (boot.isFinishedWithErrors()) { - res[count] = "Booting of " + event - + " has not been finished, due to errors!"; - String[] clientErrors = new String[clients.size()]; - int statusCount = 0; + LinkedHashMap clientErrors = new LinkedHashMap(); for (HashMap client : clients) { String ipAddress = client.get("ip"); + String clientID = client.get("id"); String errorText = boot.getError(client); - clientErrors[statusCount] = "Error of the client with the ip " - + ipAddress + ": " + errorText; - statusCount++; + clientErrors.put("Client " + clientID, + "Error of the client with the ip " + + ipAddress + ": " + errorText); } String jsonClientErrors = JSONValue .toJSONString(clientErrors); - res[count] += jsonClientErrors; + res.put(event, "Booting of " + event + + " has not been finished, due to errors!" + + jsonClientErrors); + boot = null; } else { - res[count] = "Booting of " + event - + " has not yet been finished!"; - String[] clientStatus = new String[clients.size()]; - int statusCount = 0; + LinkedHashMap clientStatus = new LinkedHashMap(); for (HashMap client : clients) { String ipAddress = client.get("ip"); + String clientID = client.get("id"); String statusText = boot.getStatusText(client); - clientStatus[statusCount] = "Status of the client with the ip " - + ipAddress + ": " + statusText; - statusCount++; + clientStatus.put("Client " + clientID, + "Status of the client with the ip " + + ipAddress + ": " + statusText); } String jsonClientStatus = JSONValue .toJSONString(clientStatus); - res[count] += jsonClientStatus; - } + res.put(event, "Booting of " + event + + " has not yet been finished!" + + jsonClientStatus); + } } else { - + res + .put(event, + "The Boot process for the event has not been found."); } - count++; } } else if (type.equals("shutdown")) { for (String event : events) { - Shutdown shutdown = SHUTDOWNTHREADS.get(event); - Vector> clients = shutdown.getClients(); - - if (shutdown.isFinished()) { - res[count] = "Shutdown of " + event + " has been finished!"; - } else if (shutdown.isFinishedWithErrors()) { - res[count] = "Shutdown of " + event - + " finished with errors!"; - } else { - res[count] = "Shutdown of " + event - + " has not yet been finished!"; - String[] clientStatus = new String[clients.size()]; - int statusCount = 0; - for (HashMap client : clients) { - String ipAddress = client.get("ip"); - String statusText = shutdown.getStatusText(client); - clientStatus[statusCount] = "Status of the client with the ip " - + ipAddress + ": " + statusText; - statusCount++; + if (SHUTDOWNTHREADS.containsKey(event)) { + Shutdown shutdown = SHUTDOWNTHREADS.get(event); + Vector> clients = shutdown + .getClients(); + if (shutdown.isFinished()) { + res.put(event, "Shutdown of " + event + + " has been finished!"); + shutdown = null; + } else if (shutdown.isFinishedWithErrors()) { + LinkedHashMap clientErrors = new LinkedHashMap(); + for (HashMap client : clients) { + String ipAddress = client.get("ip"); + String clientID = client.get("id"); + String errorText = shutdown.getError(client); + clientErrors.put("Client " + clientID, + "Error of the client with the ip " + + ipAddress + ": " + errorText); + } + String jsonClientErrors = JSONValue + .toJSONString(clientErrors); + res.put(event, "Shutdown of " + event + + " has not been finished, due to errors!" + + jsonClientErrors); + shutdown = null; + } else { + LinkedHashMap clientStatus = new LinkedHashMap(); + for (HashMap client : clients) { + String ipAddress = client.get("ip"); + String clientID = client.get("id"); + String statusText = shutdown.getStatusText(client); + clientStatus.put("Client " + clientID, + "Status of the client with the ip " + + ipAddress + ": " + statusText); + } + String jsonClientStatus = JSONValue + .toJSONString(clientStatus); + res.put(event, "Shutdown of " + event + + " has not yet been finished!" + + jsonClientStatus); } - String jsonClientStatus = JSONValue - .toJSONString(clientStatus); - res[count] += jsonClientStatus; + } else { + res + .put(event, + "The Shutdown process for the event has not been found."); } - count++; } } - String jsonResult = JSONValue.toJSONString(res); - byte[] warnings = new byte[0]; byte[] exceptions = new byte[0]; int numerator = 0; -- cgit v1.2.3-55-g7522