summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gearman/controllerWorker/ControllerWorker/Boot.java490
-rw-r--r--gearman/controllerWorker/ControllerWorker/BootWorker.java11
-rw-r--r--gearman/controllerWorker/ControllerWorker/Shutdown.java127
-rw-r--r--gearman/controllerWorker/ControllerWorker/ShutdownWorker.java10
-rw-r--r--gearman/controllerWorker/ControllerWorker/StatusWorker.java35
5 files changed, 329 insertions, 344 deletions
diff --git a/gearman/controllerWorker/ControllerWorker/Boot.java b/gearman/controllerWorker/ControllerWorker/Boot.java
index e3d85e6..23f3f39 100644
--- a/gearman/controllerWorker/ControllerWorker/Boot.java
+++ b/gearman/controllerWorker/ControllerWorker/Boot.java
@@ -23,8 +23,33 @@ import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
public class Boot extends Thread {
+ private static final int INITIAL_STATE = 0;
+ private static final int PING_INITIALIZED = 1;
+ private static final int CLIENT_ALIVE = 2;
+ private static final int CLIENT_NOT_ALIVE = 3;
+ private static final int WAKE_ON_LAN_INITIALIZED = 4;
+ private static final int MAGIC_PACKET_SENT = 5;
+ private static final int PING_WOL_AGAIN = 6;
+ private static final int PING_WOL_INITIALIZED = 7;
+ private static final int CHECKOS_INITIALIZED = 8;
+ private static final int WRONG_OS = 9;
+ private static final int WHO_INITIALIZED = 10;
+ private static final int A_USER_IS_LOGGED_IN = 11;
+ private static final int PS_INITIALIZED = 12;
+ private static final int RESTART_CLIENT = 13;
+ private static final int RESTART_INITIALIZED = 14;
+ private static final int RESTART_COMMAND_SENT = 15;
+ private static final int PING_RESTART_SHUTDOWN_AGAIN = 16;
+ private static final int PING_RESTART_SHUTDOWN_INITIALIZED = 17;
+ private static final int USER_IS_WORKING = 18;
+ private static final int CLIENT_IS_DOWN = 19;
+ private static final int PING_RESTART_BOOT_AGAIN = 20;
+ private static final int PING_RESTART_BOOT_INITIALIZED = 21;
+ private static final int ERROR = 22;
+ private static final int SUCCESS = 23;
+
private String eventName;
- private Vector<HashMap<String, String>> clients;
+ private Vector<Client> clients;
private String bootOS;
private final int updateRate;
private long waitTime;
@@ -45,17 +70,13 @@ public class Boot extends Thread {
private HashMap<Integer, Long> pingWolTime;
private HashMap<Integer, Long> pingRestartShutdownTime;
private HashMap<Integer, Long> pingRestartBootTime;
- private HashMap<Integer, Integer> status;
- private HashMap<Integer, String> errors;
- private HashMap<Integer, Boolean> finishedClients;
private Boolean finished;
private Boolean error;
- private String[] statusText;
- public Boot(String eventName, Vector<HashMap<String, String>> clients,
- String bootOS, int updateRate, long waitTime,
- Vector<String> psWhitelist, Vector<String> psBlacklist,
- String gearmanServerAddress, int gearmanServerPort) {
+ public Boot(String eventName, Vector<Client> clients, String bootOS,
+ int updateRate, long waitTime, Vector<String> psWhitelist,
+ Vector<String> psBlacklist, String gearmanServerAddress,
+ int gearmanServerPort) {
this.eventName = eventName;
this.clients = clients;
this.bootOS = bootOS;
@@ -79,44 +100,8 @@ public class Boot extends Thread {
pingWolTime = new HashMap<Integer, Long>();
pingRestartShutdownTime = new HashMap<Integer, Long>();
pingRestartBootTime = new HashMap<Integer, Long>();
- status = new HashMap<Integer, Integer>();
- errors = new HashMap<Integer, String>();
- finishedClients = new HashMap<Integer, Boolean>();
finished = false;
error = false;
- statusText = new String[31];
- statusText[0] = "The booting process of the client has been started.";
- statusText[1] = "The ping has been started.";
- statusText[2] = "The client is alive.";
- statusText[3] = "The client is not alive.";
- statusText[4] = "The wake on LAN has been started.";
- statusText[5] = "The Magic packet has been sent.";
- statusText[6] = "The ping after wake on LAN has been started.";
- statusText[7] = "Doing ping after wake on LAN again and again, until client is alive or "
- + waitTime / 60 + " minutes has been elapsed";
- statusText[8] = "The check for the correct operating system has been started.";
- statusText[9] = "The wrong operating system is running.";
- statusText[10] = "The check if a user is logged in has been started.";
- statusText[11] = "A user is logged in.";
- statusText[12] = "The check if the user is working has been started.";
- statusText[13] = "The user is not working.";
- statusText[14] = "A restart of the client has been triggered.";
- statusText[15] = "The restart command has been sent.";
- statusText[16] = "The ping after shutdown has been started.";
- statusText[17] = "Doing ping after shutdown again and again, until client is not alive or "
- + waitTime / 60 + " minutes has been elapsed";
- statusText[18] = "The user is working.";
- statusText[19] = "The client has been shutted down.";
- statusText[20] = "The ping after reboot has been started.";
- statusText[21] = "Doing ping after reboot again and again, until client is not alive or "
- + waitTime / 60 + " minutes has been elapsed";
- statusText[29] = "Booting of the client has not been finished, due to an error.";
- statusText[30] = "Booting of the client has been finished.";
- for (HashMap<String, String> client : clients) {
- int clientID = Integer.parseInt(client.get("id"));
- status.put(clientID, 0); // no work
- finishedClients.put(clientID, false);
- }
}
public void run() {
@@ -155,20 +140,20 @@ public class Boot extends Thread {
Date date;
long timestamp;
- for (HashMap<String, String> client : clients) {
- String ipAddress = client.get("ip");
- String macAddress = client.get("mac");
- int clientID = Integer.parseInt(client.get("id"));
- int clientStatus = status.get(clientID);
+ for (Client client : clients) {
+ String ipAddress = client.getIp();
+ String macAddress = client.getMac();
+ int clientID = client.getId();
+ int clientState = client.getState();
- switch (clientStatus) {
+ switch (clientState) {
- case 0:
+ case INITIAL_STATE:
ping(client);
break;
- case 1:
+ case PING_INITIALIZED:
GearmanJob pingJob = pingJobs.get(clientID);
if (pingJob != null) {
GearmanJobStatus jobStatus = gearmanClient
@@ -185,22 +170,28 @@ public class Boot extends Thread {
.toString();
if (alive.equals("true")) {
System.out.println(ipAddress + " alive");
- status.put(clientID, 2); // alive
+ client.changeState(CLIENT_ALIVE,
+ "CLIENT_ALIVE",
+ "The client is alive.");
pingJobs.remove(clientID);
} else if (alive.equals("false")) {
System.out
.println(ipAddress + " not alive");
- status.put(clientID, 3); // not alive
+ client.changeState(CLIENT_NOT_ALIVE,
+ "CLIENT_NOT_ALIVE",
+ "The client is not alive.");
pingJobs.remove(clientID);
}
} else {
System.out.println(ipAddress
+ " Cannot send the ping message.");
- errors
- .put(clientID,
- "Sending the ping message has been failed.");
- // sending the ping message has been failed
- status.put(clientID, 29);
+ client
+ .setError("Sending the ping message has been failed.");
+ // sending the ping message has been failed, go
+ // to errorState
+ client
+ .changeState(ERROR, "ERROR",
+ "Booting of the client has not been finished, due to an error.");
pingJobs.remove(clientID);
}
}
@@ -209,17 +200,17 @@ public class Boot extends Thread {
break;
- case 2:
+ case CLIENT_ALIVE:
checkOS(client);
break;
- case 3:
+ case CLIENT_NOT_ALIVE:
wakeOnLan(client);
break;
- case 4:
+ case WAKE_ON_LAN_INITIALIZED:
GearmanJob wolJob = wolJobs.get(clientID);
if (wolJob != null) {
GearmanJobStatus jobStatus = gearmanClient
@@ -231,17 +222,20 @@ public class Boot extends Thread {
.getResults());
if (result.equals("Magic packet send.")) {
System.out.println(macAddress
- + " Magic packet send.");
- status.put(clientID, 5); // magic packet send
+ + " Magic packet sent.");
+ client.changeState(MAGIC_PACKET_SENT,
+ "MAGIC_PACKET_SENT",
+ "The Magic packet has been sent.");
wolJobs.remove(clientID);
} else {
System.out.println(ipAddress
+ " Cannot send magic packet.");
- errors
- .put(clientID,
- "Sending the magic packet has been failed.");
+ client
+ .setError("Sending the magic packet has been failed.");
// cannot send magic packet, go in errorState
- status.put(clientID, 29);
+ client
+ .changeState(ERROR, "ERROR",
+ "Booting of the client has not been finished, due to an error.");
wolJobs.remove(clientID);
}
}
@@ -249,20 +243,20 @@ public class Boot extends Thread {
break;
- case 5:
+ case MAGIC_PACKET_SENT:
date = new Date();
timestamp = date.getTime();
pingWolTime.put(clientID, timestamp);
- status.put(clientID, 6); // ping after wake on LAN
+ pingWakeOnLan(client);
break;
- case 6:
+ case PING_WOL_AGAIN:
pingWakeOnLan(client);
break;
- case 7:
+ case PING_WOL_INITIALIZED:
GearmanJob pingJobWoL = pingWoLJobs.get(clientID);
if (pingJobWoL != null) {
Date currentDate = new Date();
@@ -287,26 +281,37 @@ public class Boot extends Thread {
System.out.println(ipAddress
+ " is alive after WoL");
// alive, go in successState
- status.put(clientID, 30);
+ client
+ .changeState(SUCCESS,
+ "SUCCESS",
+ "Booting of the client has been finished.");
pingWoLJobs.remove(clientID);
} else if (alive.equals("false")) {
System.out.println("ping again "
+ ipAddress);
- status.put(clientID, 6); // again ping
+ client
+ .changeState(
+ PING_WOL_AGAIN,
+ "PING_WOL_AGAIN",
+ "Doing ping after wake on LAN again and again, until client is alive or "
+ + waitTime
+ / 60
+ + " minutes has been elapsed");
pingWoLJobs.remove(clientID);
}
} else {
System.out
.println(ipAddress
+ " Cannot send the ping after wake on LAN message.");
- errors
- .put(clientID,
- "Sending the ping after wake on LAN message has been failed.");
+ client
+ .setError("Sending the ping after wake on LAN message has been failed.");
/*
* sending the ping after wake on LAN
- * message has been failed
+ * message has been failed, go to errorState
*/
- status.put(clientID, 29);
+ client
+ .changeState(ERROR, "ERROR",
+ "Booting of the client has not been finished, due to an error.");
pingWoLJobs.remove(clientID);
}
}
@@ -314,17 +319,18 @@ public class Boot extends Thread {
} else {
System.out.println(ipAddress
+ " is not alive after WoL");
- errors
- .put(clientID,
- "The wake on LAN has been failed.");
- status.put(clientID, 29); // not alive, go in errorState
+ client.setError("The wake on LAN has been failed.");
+ // not alive, go in errorState
+ client
+ .changeState(ERROR, "ERROR",
+ "Booting of the client has not been finished, due to an error.");
pingWoLJobs.remove(clientID);
}
}
break;
- case 8:
+ case CHECKOS_INITIALIZED:
GearmanJob osJob = osJobs.get(clientID);
if (osJob != null) {
@@ -351,21 +357,27 @@ public class Boot extends Thread {
if (description.equals(bootOS)) {
System.out.println(ipAddress + " right OS");
- status.put(clientID, 30); // right os
+ // right os, go to successState
+ client
+ .changeState(SUCCESS, "SUCCESS",
+ "Booting of the client has been finished.");
osJobs.remove(clientID);
} else {
System.out.println(ipAddress + " wrong OS");
- status.put(clientID, 9); // wrong os
+ client
+ .changeState(WRONG_OS, "WRONG_OS",
+ "The wrong operating system is running.");
osJobs.remove(clientID);
}
} else {
System.out.println(ipAddress
+ " Cannot check os");
- errors
- .put(clientID,
- "The check for correct operating system has been failed.");
+ client
+ .setError("The check for correct operating system has been failed.");
// cannot check os, go in errorState
- status.put(clientID, 29);
+ client
+ .changeState(ERROR, "ERROR",
+ "Booting of the client has not been finished, due to an error.");
osJobs.remove(clientID);
}
}
@@ -374,12 +386,12 @@ public class Boot extends Thread {
break;
- case 9:
+ case WRONG_OS:
who(client);
break;
- case 10:
+ case WHO_INITIALIZED:
GearmanJob whoJob = whoJobs.get(clientID);
if (whoJob != null) {
@@ -407,28 +419,32 @@ public class Boot extends Thread {
if (user.isEmpty()) {
System.out.println(ipAddress
+ " no user is logged in");
- // no user is logged in
- status.put(clientID, 13);
+ // no user is logged in, doing restart
+ client.changeState(RESTART_CLIENT,
+ "RESTART_CLIENT",
+ "No user is logged in.");
whoJobs.remove(clientID);
} else {
System.out.println(ipAddress
+ " a user is logged in");
- // a user is logged in
- status.put(clientID, 11);
+ client.changeState(A_USER_IS_LOGGED_IN,
+ "A_USER_IS_LOGGED_IN",
+ "A user is logged in.");
whoJobs.remove(clientID);
}
} else {
System.out
.println(ipAddress
+ " Cannot check if a user is logged in.");
- errors
- .put(clientID,
- "The check if a user is logged in has been failed.");
+ client
+ .setError("The check if a user is logged in has been failed.");
/*
* cannot check if a user is logged in, go in
* errorState
*/
- status.put(clientID, 29);
+ client
+ .changeState(ERROR, "ERROR",
+ "Booting of the client has not been finished, due to an error.");
whoJobs.remove(clientID);
}
}
@@ -437,12 +453,12 @@ public class Boot extends Thread {
break;
- case 11:
+ case A_USER_IS_LOGGED_IN:
ps(client);
break;
- case 12:
+ case PS_INITIALIZED:
GearmanJob psJob = psJobs.get(clientID);
if (psJob != null) {
@@ -484,24 +500,30 @@ public class Boot extends Thread {
*/
System.out.println(ipAddress
+ " is working");
- status.put(clientID, 18); // is working
+ client.changeState(USER_IS_WORKING,
+ "USER_IS_WORKING",
+ "The user is working.");
psJobs.remove(clientID);
// }
} else {
- status.put(clientID, 13);
+ // user is not working, doing restart
+ client.changeState(RESTART_CLIENT,
+ "RESTART_CLIENT",
+ "The user is'nt working.");
psJobs.remove(clientID);
}
} else {
System.out.println(ipAddress
+ " Cannot check if user is working.");
- errors
- .put(clientID,
- "The check if a user is working has been failed.");
+ client
+ .setError("The check if a user is working has been failed.");
/*
* cannot check if user is working, go in
* errorState
*/
- status.put(clientID, 29);
+ client
+ .changeState(ERROR, "ERROR",
+ "Booting of the client has not been finished, due to an error.");
psJobs.remove(clientID);
}
}
@@ -510,12 +532,12 @@ public class Boot extends Thread {
break;
- case 13:
+ case RESTART_CLIENT:
restart(client);
break;
- case 14:
+ case RESTART_INITIALIZED:
GearmanJob restartJob = restartJobs.get(clientID);
if (restartJob != null) {
GearmanJobStatus jobStatus = gearmanClient
@@ -530,18 +552,20 @@ public class Boot extends Thread {
.parse(result);
if (!resultObj.containsKey("err")) {
System.out.println(ipAddress
- + " Restart command send");
- status.put(clientID, 15); // restart command
- // send
+ + " Restart command sent");
+ client.changeState(RESTART_COMMAND_SENT,
+ "RESTART_COMMAND_SENT",
+ "The restart command has been sent.");
restartJobs.remove(clientID);
} else {
System.out.println(ipAddress
+ " Cannot send restart command");
- errors
- .put(clientID,
- "Sending the restart command has been failed.");
+ client
+ .setError("Sending the restart command has been failed.");
// cannot send restart command, go in errorState
- status.put(clientID, 29);
+ client
+ .changeState(ERROR, "ERROR",
+ "Booting of the client has not been finished, due to an error.");
restartJobs.remove(clientID);
}
}
@@ -550,20 +574,20 @@ public class Boot extends Thread {
break;
- case 15:
+ case RESTART_COMMAND_SENT:
date = new Date();
timestamp = date.getTime();
pingRestartShutdownTime.put(clientID, timestamp);
- status.put(clientID, 16); // ping after restart shutdown
+ pingRestartShutdown(client);
break;
- case 16:
+ case PING_RESTART_SHUTDOWN_AGAIN:
pingRestartShutdown(client);
break;
- case 17:
+ case PING_RESTART_SHUTDOWN_INITIALIZED:
GearmanJob pingJobRestartShutdown = pingRestartShutdownJobs
.get(clientID);
if (pingJobRestartShutdown != null) {
@@ -592,15 +616,25 @@ public class Boot extends Thread {
if (alive.equals("true")) {
System.out.println(ipAddress
+ " is still alive");
- // alive, ping again
- status.put(clientID, 16);
+ // still alive, ping again
+ client
+ .changeState(
+ PING_RESTART_SHUTDOWN_AGAIN,
+ "PING_RESTART_SHUTDOWN_AGAIN",
+ "Doing ping after shutdown again and again, until client is not alive or "
+ + waitTime
+ / 60
+ + " minutes has been elapsed");
pingRestartShutdownJobs
.remove(clientID);
} else if (alive.equals("false")) {
System.out.println(ipAddress
+ " is down");
// not alive, ping again
- status.put(clientID, 19); // is down
+ client
+ .changeState(CLIENT_IS_DOWN,
+ "CLIENT_IS_DOWN",
+ "The client has been shutted down.");
pingRestartShutdownJobs
.remove(clientID);
}
@@ -608,51 +642,56 @@ public class Boot extends Thread {
System.out
.println(ipAddress
+ " Cannot send the ping after restart message.");
- errors
- .put(clientID,
- "Sending the ping after restart message has been failed.");
+ client
+ .setError("Sending the ping after restart message has been failed.");
/*
* sending the ping after restart message
* has been failed
*/
- status.put(clientID, 29);
+ client
+ .changeState(ERROR, "ERROR",
+ "Booting of the client has not been finished, due to an error.");
pingRestartShutdownJobs.remove(clientID);
}
}
}
} else {
System.out.println(ipAddress + " shutdown failed");
- errors.put(clientID, "The shutdown has been failed.");
+ client.setError("The shutdown has been failed.");
// still alive, go in errorState
- status.put(clientID, 29);
+ client
+ .changeState(ERROR, "ERROR",
+ "Booting of the client has not been finished, due to an error.");
pingRestartShutdownJobs.remove(clientID);
}
}
break;
- case 18:
+ case USER_IS_WORKING:
System.out.println(ipAddress + " User has been working");
- errors.put(clientID, "The user has been working.");
+ client.setError("The user has been working.");
// user has been working, go in errorState
- status.put(clientID, 29);
+ client
+ .changeState(ERROR, "ERROR",
+ "Booting of the client has not been finished, due to an error.");
break;
- case 19:
+ case CLIENT_IS_DOWN:
date = new Date();
timestamp = date.getTime();
pingRestartBootTime.put(clientID, timestamp);
- status.put(clientID, 20); // ping after restart boot
+ pingRestartBoot(client);
break;
- case 20:
+ case PING_RESTART_BOOT_AGAIN:
pingRestartBoot(client);
break;
- case 21:
+ case PING_RESTART_BOOT_INITIALIZED:
GearmanJob pingJobRestartBoot = pingRestartBootJobs
.get(clientID);
if (pingJobRestartBoot != null) {
@@ -680,67 +719,77 @@ public class Boot extends Thread {
System.out.println(ipAddress
+ " is alive after restart");
// alive, go to success state
- status.put(clientID, 30);
+ client
+ .changeState(SUCCESS,
+ "SUCCESS",
+ "Booting of the client has been finished.");
pingRestartBootJobs.remove(clientID);
} else if (alive.equals("false")) {
System.out.println("ping again "
+ ipAddress);
// not alive, ping again
- status.put(clientID, 20); // again ping
+ client
+ .changeState(
+ PING_RESTART_BOOT_AGAIN,
+ "PING_RESTART_BOOT_AGAIN",
+ "Doing ping after reboot again and again, until client is not alive or "
+ + waitTime
+ / 60
+ + " minutes has been elapsed");
pingRestartBootJobs.remove(clientID);
}
} else {
System.out
.println(ipAddress
+ " Cannot send the ping after shutdown message.");
- errors
- .put(clientID,
- "Sending the ping after shutdown message has been failed.");
+ client
+ .setError("Sending the ping after shutdown message has been failed.");
/*
* sending the ping after shutdown message
* has been failed
*/
- status.put(clientID, 29);
- pingRestartBootJobs.remove(clientID);
+ client
+ .changeState(ERROR, "ERROR",
+ "Booting of the client has not been finished, due to an error.");
}
}
}
} else {
System.out.println(ipAddress
+ " is not alive after reboot");
- errors.put(clientID, "The reboot has been failed.");
- status.put(clientID, 29); // not alive, go in errorState
+ client.setError("The reboot has been failed.");
+ // not alive, go in errorState
+ client
+ .changeState(0, "ERROR",
+ "Booting of the client has not been finished, due to an error.");
pingRestartBootJobs.remove(clientID);
}
}
break;
- case 29:
- if (!finishedClients.get(clientID)) {
+ case ERROR:
+ if (!client.isFinished()) {
System.out.println(ipAddress + " Booting failed"); // errorState
- finishedClients.put(clientID, true);
+ client.finish();
error = true;
}
break;
- case 30:
- if (!finishedClients.get(clientID)) {
+ case SUCCESS:
+ if (!client.isFinished()) {
System.out.println(ipAddress + " Booting finished"); // successState
- finishedClients.put(clientID, true);
+ client.finish();
}
break;
-
}
}
boolean allFinished = false;
- for (HashMap<String, String> client : clients) {
- int clientID = Integer.parseInt(client.get("id"));
- boolean clientFinished = finishedClients.get(clientID);
- if (clientFinished) {
+ for (Client client : clients) {
+ if (client.isFinished()) {
allFinished = true;
} else {
allFinished = false;
@@ -755,144 +804,117 @@ public class Boot extends Thread {
}
}
- private void ping(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
-
+ private void ping(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("ping", ipAddress.getBytes(),
"ping" + clientID);
gearmanClient.submit(job);
-
- status.put(clientID, 1); // ping started
+ client.changeState(PING_INITIALIZED, "PING_INITIALIZED",
+ "The ping has been initialized.");
pingJobs.put(clientID, job);
-
System.out.println("ping " + ipAddress);
}
- private void pingWakeOnLan(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
-
+ private void pingWakeOnLan(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("ping", ipAddress.getBytes(),
"ping" + clientID);
gearmanClient.submit(job);
-
- status.put(clientID, 7); // pingWol started
+ client.changeState(PING_WOL_INITIALIZED, "PING_WOL_INITIALIZED",
+ "The ping after wake on LAN has been initialized.");
pingWoLJobs.put(clientID, job);
-
System.out.println("ping " + ipAddress);
}
- private void pingRestartShutdown(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
-
+ private void pingRestartShutdown(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("ping", ipAddress.getBytes(),
"ping" + clientID);
gearmanClient.submit(job);
-
- status.put(clientID, 17); // pingRestartShutdown started
+ client.changeState(PING_RESTART_SHUTDOWN_INITIALIZED,
+ "PING_RESTART_SHUTDOWN_INITIALIZED",
+ "The ping after shutdown has been initialized.");
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"));
-
+ private void pingRestartBoot(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("ping", ipAddress.getBytes(),
"ping" + clientID);
gearmanClient.submit(job);
-
- status.put(clientID, 21); // pingRestartBoot started
+ client.changeState(PING_RESTART_BOOT_INITIALIZED,
+ "PING_RESTART_BOOT_INITIALIZED",
+ "The ping after reboot has been initialized.");
pingRestartBootJobs.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"));
-
+ private void wakeOnLan(Client client) {
+ String macAddress = client.getMac();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("wol", macAddress.getBytes(),
"wol" + clientID);
gearmanClient.submit(job);
-
- status.put(clientID, 4); // wake on lan started
+ client.changeState(WAKE_ON_LAN_INITIALIZED, "WAKE_ON_LAN_INITIALIZED",
+ "The wake on LAN has been initialized.");
wolJobs.put(clientID, job);
-
System.out.println("wake on lan");
}
- private void checkOS(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
-
+ private void checkOS(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("os", ipAddress.getBytes(),
"os" + clientID);
gearmanClient.submit(job);
-
- status.put(clientID, 8); // checkOS started
+ client
+ .changeState(CHECKOS_INITIALIZED, "CHECKOS_INITIALIZED",
+ "The check for the correct operating system has been initialized.");
osJobs.put(clientID, job);
-
System.out.println("check OS " + ipAddress);
}
- private void who(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
-
+ private void who(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("who", ipAddress.getBytes(),
"who" + clientID);
gearmanClient.submit(job);
-
- status.put(clientID, 10); // who started
+ client.changeState(WHO_INITIALIZED, "WHO_INITIALIZED",
+ "The check if a user is logged in has been initialized.");
whoJobs.put(clientID, job);
-
System.out.println("who " + ipAddress);
}
- private void ps(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
-
+ private void ps(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("ps", ipAddress.getBytes(),
"ps" + clientID);
gearmanClient.submit(job);
-
- status.put(clientID, 12); // ps started
+ client.changeState(PS_INITIALIZED, "PS_INITIALIZED",
+ "The check if the user is working has been initialized.");
psJobs.put(clientID, job);
-
System.out.println("ps " + ipAddress);
}
- private void restart(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
-
+ private void restart(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("restart", ipAddress
.getBytes(), "restart" + clientID);
gearmanClient.submit(job);
-
- status.put(clientID, 14); // restart started
+ client.changeState(RESTART_INITIALIZED, "RESTART_INITIALIZED",
+ "A restart of the client has been initialized.");
restartJobs.put(clientID, job);
-
System.out.println("restart " + ipAddress);
}
- public String getStatusText(HashMap<String, String> client) {
- int clientID = Integer.parseInt(client.get("id"));
- int clientStatus = status.get(clientID);
- return statusText[clientStatus];
- }
-
- public String getError(HashMap<String, String> client) {
- int clientID = Integer.parseInt(client.get("id"));
- String clientError = errors.get(clientID);
- return clientError;
- }
-
public Boolean isFinished() {
return finished && !error;
}
@@ -901,7 +923,7 @@ public class Boot extends Thread {
return finished && error;
}
- public Vector<HashMap<String, String>> getClients() {
+ public Vector<Client> getClients() {
return clients;
}
diff --git a/gearman/controllerWorker/ControllerWorker/BootWorker.java b/gearman/controllerWorker/ControllerWorker/BootWorker.java
index 5256730..572c5dd 100644
--- a/gearman/controllerWorker/ControllerWorker/BootWorker.java
+++ b/gearman/controllerWorker/ControllerWorker/BootWorker.java
@@ -1,6 +1,5 @@
package ControllerWorker;
-import java.util.HashMap;
import java.util.Vector;
import org.gearman.client.GearmanJobResult;
@@ -21,7 +20,7 @@ public class BootWorker extends AbstractGearmanFunction {
@Override
public GearmanJobResult executeFunction() {
String data = ByteUtils.fromUTF8Bytes((byte[]) this.data);
- Vector<HashMap<String, String>> clients = new Vector<HashMap<String, String>>();
+ Vector<Client> clients = new Vector<Client>();
JSONObject jsonObject = (JSONObject) JSONValue.parse(data);
String event = jsonObject.get("eventName").toString();
String eventOS = jsonObject.get("eventOS").toString();
@@ -36,11 +35,9 @@ public class BootWorker extends AbstractGearmanFunction {
for (Object clientObj : jsonArray) {
JSONObject clientJsonObj = (JSONObject) clientObj;
- HashMap<String, String> clientMap = new HashMap<String, String>();
- clientMap.put("id", clientJsonObj.get("id").toString());
- clientMap.put("ip", clientJsonObj.get("ip").toString());
- clientMap.put("mac", clientJsonObj.get("mac").toString());
- clients.add(clientMap);
+ Client client = new Client(clientJsonObj,
+ "The booting process of the client has been started.");
+ clients.add(client);
}
JSONArray whitelist = (JSONArray) jsonObject.get("whitelist");
diff --git a/gearman/controllerWorker/ControllerWorker/Shutdown.java b/gearman/controllerWorker/ControllerWorker/Shutdown.java
index 78ab144..8f10e68 100644
--- a/gearman/controllerWorker/ControllerWorker/Shutdown.java
+++ b/gearman/controllerWorker/ControllerWorker/Shutdown.java
@@ -24,7 +24,7 @@ import org.json.simple.JSONValue;
public class Shutdown extends Thread {
private String eventName;
- private Vector<HashMap<String, String>> clients;
+ private Vector<Client> clients;
private final int updateRate;
private long waitTime;
private Vector<String> psWhitelist;
@@ -39,14 +39,12 @@ public class Shutdown extends Thread {
private HashMap<Integer, GearmanJob> psJobs;
private HashMap<Integer, Long> pingShutdownTime;
private HashMap<Integer, Integer> status;
- private HashMap<Integer, String> errors;
- private HashMap<Integer, Boolean> finishedClients;
private Boolean finished;
private Boolean error;
private String[] statusText;
- public Shutdown(String eventName, Vector<HashMap<String, String>> clients,
- int updateRate, long waitTime, Vector<String> psWhitelist,
+ public Shutdown(String eventName, Vector<Client> clients, int updateRate,
+ long waitTime, Vector<String> psWhitelist,
Vector<String> psBlacklist, String gearmanServerAddress,
int gearmanServerPort) {
this.eventName = eventName;
@@ -66,12 +64,9 @@ public class Shutdown extends Thread {
psJobs = new HashMap<Integer, GearmanJob>();
pingShutdownTime = new HashMap<Integer, Long>();
status = new HashMap<Integer, Integer>();
- errors = new HashMap<Integer, String>();
- finishedClients = new HashMap<Integer, Boolean>();
finished = false;
error = false;
statusText = new String[14];
- statusText[0] = "The shutdown process of the client has been started.";
statusText[1] = "The ping has been started.";
statusText[2] = "The client is alive.";
statusText[3] = "The check if a user is logged in has been started.";
@@ -86,11 +81,6 @@ public class Shutdown extends Thread {
statusText[11] = "The user is working.";
statusText[12] = "Shutdown of the client has not been finished, due to an error.";
statusText[13] = "Shutdown of the client has been finished.";
- for (HashMap<String, String> client : clients) {
- int clientID = Integer.parseInt(client.get("id"));
- status.put(clientID, 0); // no work
- finishedClients.put(clientID, false);
- }
}
public void run() {
@@ -126,12 +116,12 @@ public class Shutdown extends Thread {
private Boolean update() throws IllegalStateException, IOException,
InterruptedException, ExecutionException {
- for (HashMap<String, String> client : clients) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
- int clientStatus = status.get(clientID);
+ for (Client client : clients) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
+ int clientState = client.getState();
- switch (clientStatus) {
+ switch (clientState) {
case 0:
ping(client);
@@ -172,9 +162,8 @@ public class Shutdown extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot send the ping message.");
- errors
- .put(clientID,
- "Sending the ping message has been failed.");
+ client
+ .setError("Sending the ping message has been failed.");
// sending the ping message has been failed
status.put(clientID, 12);
pingJobs.remove(clientID);
@@ -232,9 +221,8 @@ public class Shutdown extends Thread {
System.out
.println(ipAddress
+ " Cannot check if a user is logged in.");
- errors
- .put(clientID,
- "The check if a user is logged in has been failed.");
+ client
+ .setError("The check if a user is logged in has been failed.");
/*
* cannot check if a user is logged in, go in
* errorState
@@ -275,9 +263,8 @@ public class Shutdown extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot send shutdown command");
- errors
- .put(clientID,
- "Sending the shutdown command has been failed.");
+ client
+ .setError("Sending the shutdown command has been failed.");
/*
* cannot send shutdown command, go in /
* errorState
@@ -342,9 +329,8 @@ public class Shutdown extends Thread {
System.out
.println(ipAddress
+ " Cannot send the ping after shutdown message.");
- errors
- .put(clientID,
- "Sending the ping after shutdown message has been failed.");
+ client
+ .setError("Sending the ping after shutdown message has been failed.");
/*
* sending the ping after shutdown message
* has been failed
@@ -357,8 +343,8 @@ public class Shutdown extends Thread {
} else {
System.out.println(ipAddress
+ " is alive after shutdown");
- errors.put(clientID,
- "Client is still alive after shutdown.");
+ client
+ .setError("Client is still alive after shutdown.");
// still alive, go in errorState
status.put(clientID, 12);
pingShutdownJobs.remove(clientID);
@@ -389,7 +375,7 @@ public class Shutdown extends Thread {
.parse(result);
if (!resultObj.containsKey("err")) {
JSONArray ps = (JSONArray) resultObj.get("ps");
- //boolean whitelistFound = false;
+ // boolean whitelistFound = false;
boolean blacklistFound = false;
for (String blackEntry : psBlacklist) {
@@ -398,11 +384,11 @@ public class Shutdown extends Thread {
}
}
- /*for (String whiteEntry : psWhitelist) {
- if (ps.toString().contains(whiteEntry)) {
- whitelistFound = true;
- }
- }*/
+ /*
+ * for (String whiteEntry : psWhitelist) { if
+ * (ps.toString().contains(whiteEntry)) {
+ * whitelistFound = true; } }
+ */
if (blacklistFound) {
/*
@@ -427,9 +413,8 @@ public class Shutdown extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot check if user is working.");
- errors
- .put(clientID,
- "The check if a user is working has been failed.");
+ client
+ .setError("The check if a user is working has been failed.");
/*
* cannot check if user is working, go in
* errorState
@@ -445,25 +430,25 @@ public class Shutdown extends Thread {
case 11:
System.out.println(ipAddress + " User has been working");
- errors.put(clientID, "The user has been working.");
+ client.setError("The user has been working.");
// user has been working, go in errorState
status.put(clientID, 12);
break;
case 12:
- if (!finishedClients.get(clientID)) {
+ if (!client.isFinished()) {
System.out.println(ipAddress + " Shutdown failed"); // errorState
- finishedClients.put(clientID, true);
+ client.finish();
error = true;
}
break;
case 13:
- if (!finishedClients.get(clientID)) {
+ if (!client.isFinished()) {
System.out.println(ipAddress + " Shutdown finished"); // successState
- finishedClients.put(clientID, true);
+ client.finish();
}
break;
@@ -472,10 +457,8 @@ public class Shutdown extends Thread {
}
boolean allFinished = false;
- for (HashMap<String, String> client : clients) {
- int clientID = Integer.parseInt(client.get("id"));
- boolean clientFinished = finishedClients.get(clientID);
- if (clientFinished) {
+ for (Client client : clients) {
+ if (client.isFinished()) {
allFinished = true;
} else {
allFinished = false;
@@ -490,9 +473,9 @@ public class Shutdown extends Thread {
}
}
- private void ping(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
+ private void ping(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("ping", ipAddress.getBytes(),
"ping" + clientID);
@@ -504,9 +487,9 @@ public class Shutdown extends Thread {
System.out.println("ping " + ipAddress);
}
- private void who(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
+ private void who(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("who", ipAddress.getBytes(),
"who" + clientID);
@@ -518,9 +501,9 @@ public class Shutdown extends Thread {
System.out.println("who " + ipAddress);
}
- private void doShutdown(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
+ private void doShutdown(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("doShutdown", ipAddress
.getBytes(), "doShutdown" + clientID);
@@ -532,9 +515,9 @@ public class Shutdown extends Thread {
System.out.println("doShutdown " + ipAddress);
}
- private void pingShutdown(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
+ private void pingShutdown(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("ping", ipAddress.getBytes(),
"ping" + clientID);
@@ -546,9 +529,9 @@ public class Shutdown extends Thread {
System.out.println("ping " + ipAddress);
}
- private void ps(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
+ private void ps(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("ps", ipAddress.getBytes(),
"ps" + clientID);
@@ -560,18 +543,6 @@ public class Shutdown extends Thread {
System.out.println("ps " + ipAddress);
}
- public String getStatusText(HashMap<String, String> client) {
- int clientID = Integer.parseInt(client.get("id"));
- int clientStatus = status.get(clientID);
- return statusText[clientStatus];
- }
-
- public String getError(HashMap<String, String> client) {
- int clientID = Integer.parseInt(client.get("id"));
- String clientError = errors.get(clientID);
- return clientError;
- }
-
public Boolean isFinished() {
return finished && !error;
}
@@ -580,7 +551,7 @@ public class Shutdown extends Thread {
return finished && error;
}
- public Vector<HashMap<String, String>> getClients() {
+ public Vector<Client> getClients() {
return clients;
}
diff --git a/gearman/controllerWorker/ControllerWorker/ShutdownWorker.java b/gearman/controllerWorker/ControllerWorker/ShutdownWorker.java
index 2eea21b..d3d9ae7 100644
--- a/gearman/controllerWorker/ControllerWorker/ShutdownWorker.java
+++ b/gearman/controllerWorker/ControllerWorker/ShutdownWorker.java
@@ -1,6 +1,5 @@
package ControllerWorker;
-import java.util.HashMap;
import java.util.Vector;
import org.gearman.client.GearmanJobResult;
@@ -21,7 +20,7 @@ public class ShutdownWorker extends AbstractGearmanFunction {
@Override
public GearmanJobResult executeFunction() {
String data = ByteUtils.fromUTF8Bytes((byte[]) this.data);
- Vector<HashMap<String, String>> clients = new Vector<HashMap<String, String>>();
+ Vector<Client> clients = new Vector<Client>();
JSONObject jsonObject = (JSONObject) JSONValue.parse(data);
String event = jsonObject.get("eventName").toString();
String gearmanServerHost = jsonObject.get("gearmanServerHost")
@@ -35,11 +34,8 @@ public class ShutdownWorker extends AbstractGearmanFunction {
for (Object clientObj : jsonArray) {
JSONObject clientJsonObj = (JSONObject) clientObj;
- HashMap<String, String> clientMap = new HashMap<String, String>();
- clientMap.put("id", clientJsonObj.get("id").toString());
- clientMap.put("ip", clientJsonObj.get("ip").toString());
- clientMap.put("mac", clientJsonObj.get("mac").toString());
- clients.add(clientMap);
+ Client client = new Client(clientJsonObj, "The shutdown process of the client has been started.");
+ clients.add(client);
}
JSONArray whitelist = (JSONArray) jsonObject.get("whitelist");
diff --git a/gearman/controllerWorker/ControllerWorker/StatusWorker.java b/gearman/controllerWorker/ControllerWorker/StatusWorker.java
index dee1011..880b6aa 100644
--- a/gearman/controllerWorker/ControllerWorker/StatusWorker.java
+++ b/gearman/controllerWorker/ControllerWorker/StatusWorker.java
@@ -38,7 +38,7 @@ public class StatusWorker extends AbstractGearmanFunction {
for (String event : events) {
Boot boot = BOOTTHREADS.get(event);
if (BOOTTHREADS.containsKey(event)) {
- Vector<HashMap<String, String>> clients = boot.getClients();
+ Vector<Client> clients = boot.getClients();
if (boot.isFinished()) {
content.put("result shortcut", "succeeded");
content.put("result text", "Booting of " + event
@@ -51,9 +51,9 @@ public class StatusWorker extends AbstractGearmanFunction {
content.put("result text", "Booting of " + event
+ " has not been finished, due to errors!");
LinkedHashMap<String, String> clientErrors = new LinkedHashMap<String, String>();
- for (HashMap<String, String> client : clients) {
- String clientID = client.get("id");
- String errorText = boot.getError(client);
+ for (Client client : clients) {
+ String clientID = Integer.toString(client.getId());
+ String errorText = client.getError();
if (!errorText.isEmpty()) {
clientErrors.put(clientID, errorText);
}
@@ -67,12 +67,12 @@ public class StatusWorker extends AbstractGearmanFunction {
content.put("result text", "Booting of " + event
+ " has not yet been finished!");
LinkedHashMap<String, String> clientStatus = new LinkedHashMap<String, String>();
- for (HashMap<String, String> client : clients) {
- String clientID = client.get("id");
- String statusText = boot.getStatusText(client);
- clientStatus.put(clientID, statusText);
+ for (Client client : clients) {
+ String clientID = Integer.toString(client.getId());
+ String stateText = client.getStateText();
+ clientStatus.put(clientID, stateText);
}
- content.put("clients status", clientStatus);
+ content.put("clients states", clientStatus);
res.put(event, content);
}
} else {
@@ -87,8 +87,7 @@ public class StatusWorker extends AbstractGearmanFunction {
for (String event : events) {
if (SHUTDOWNTHREADS.containsKey(event)) {
Shutdown shutdown = SHUTDOWNTHREADS.get(event);
- Vector<HashMap<String, String>> clients = shutdown
- .getClients();
+ Vector<Client> clients = shutdown.getClients();
if (shutdown.isFinished()) {
content.put("result shortcut", "succeeded");
content.put("result text", "Shutdown of " + event
@@ -101,9 +100,9 @@ public class StatusWorker extends AbstractGearmanFunction {
content.put("result text", "Shutdown of " + event
+ " has not been finished, due to errors!");
LinkedHashMap<String, String> clientErrors = new LinkedHashMap<String, String>();
- for (HashMap<String, String> client : clients) {
- String clientID = client.get("id");
- String errorText = shutdown.getError(client);
+ for (Client client : clients) {
+ String clientID = Integer.toString(client.getId());
+ String errorText = client.getError();
if (!errorText.isEmpty()) {
clientErrors.put(clientID, errorText);
}
@@ -117,12 +116,12 @@ public class StatusWorker extends AbstractGearmanFunction {
content.put("result text", "Shutdown of " + event
+ " has not yet been finished!");
LinkedHashMap<String, String> clientStatus = new LinkedHashMap<String, String>();
- for (HashMap<String, String> client : clients) {
- String clientID = client.get("id");
- String statusText = shutdown.getStatusText(client);
+ for (Client client : clients) {
+ String clientID = Integer.toString(client.getId());
+ String statusText = client.getStateText();
clientStatus.put(clientID, statusText);
}
- content.put("clients status", clientStatus);
+ content.put("clients states", clientStatus);
res.put(event, content);
}
} else {