summaryrefslogtreecommitdiffstats
path: root/gearman/controllerWorker/ControllerWorker/Boot.java
diff options
context:
space:
mode:
Diffstat (limited to 'gearman/controllerWorker/ControllerWorker/Boot.java')
-rw-r--r--gearman/controllerWorker/ControllerWorker/Boot.java92
1 files changed, 46 insertions, 46 deletions
diff --git a/gearman/controllerWorker/ControllerWorker/Boot.java b/gearman/controllerWorker/ControllerWorker/Boot.java
index 7857e9b..6a90e2c 100644
--- a/gearman/controllerWorker/ControllerWorker/Boot.java
+++ b/gearman/controllerWorker/ControllerWorker/Boot.java
@@ -22,6 +22,8 @@ import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
+import org.apache.log4j.Logger;
+
public class Boot extends Thread {
private static final int CLIENT_INITIALIZED = 0;
private static final int PING_INITIALIZED = 1;
@@ -47,6 +49,8 @@ public class Boot extends Thread {
private static final int PING_RESTART_BOOT_INITIALIZED = 21;
private static final int ERROR = 22;
private static final int SUCCESS = 23;
+
+ static final Logger logger = Logger.getLogger(Boot.class);
private String eventName;
private Vector<Client> clients;
@@ -129,9 +133,9 @@ public class Boot extends Thread {
}
finished = true;
if (error) {
- System.out.println("Booting of " + eventName + " failed");
+ logger.error("Booting of " + eventName + " failed");
} else {
- System.out.println("Booting of " + eventName + " finished");
+ logger.info("Booting of " + eventName + " finished");
}
}
@@ -164,14 +168,14 @@ public class Boot extends Thread {
String alive = resultObj.get("alive")
.toString();
if (alive.equals("true")) {
- System.out.println(client.getIp()
+ logger.info(client.getIp()
+ " alive");
client.changeState(CLIENT_ALIVE,
"CLIENT_ALIVE",
"The client is alive.");
pingJobs.remove(client.getId());
} else if (alive.equals("false")) {
- System.out.println(client.getIp()
+ logger.info(client.getIp()
+ " not alive");
client.changeState(CLIENT_NOT_ALIVE,
"CLIENT_NOT_ALIVE",
@@ -179,7 +183,7 @@ public class Boot extends Thread {
pingJobs.remove(client.getId());
}
} else {
- System.out.println(client.getIp()
+ logger.error(client.getIp()
+ " Cannot send the ping message.");
client
.setError("Sending the ping message has been failed.");
@@ -217,14 +221,14 @@ public class Boot extends Thread {
String result = ByteUtils.fromUTF8Bytes(wolJobRes
.getResults());
if (result.equals("Magic packet send.")) {
- System.out.println(client.getMac()
+ logger.info(client.getMac()
+ " Magic packet sent.");
client.changeState(MAGIC_PACKET_SENT,
"MAGIC_PACKET_SENT",
"The Magic packet has been sent.");
wolJobs.remove(client.getId());
} else {
- System.out.println(client.getIp()
+ logger.error(client.getIp()
+ " Cannot send magic packet.");
client
.setError("Sending the magic packet has been failed.");
@@ -274,7 +278,7 @@ public class Boot extends Thread {
String alive = resultObj.get("alive")
.toString();
if (alive.equals("true")) {
- System.out.println(client.getIp()
+ logger.info(client.getIp()
+ " is alive after WoL");
// alive, go in successState
client
@@ -283,7 +287,7 @@ public class Boot extends Thread {
"Booting of the client has been finished.");
pingWoLJobs.remove(client.getId());
} else if (alive.equals("false")) {
- System.out.println("ping again "
+ logger.info("ping again "
+ client.getIp());
client
.changeState(
@@ -296,8 +300,7 @@ public class Boot extends Thread {
pingWoLJobs.remove(client.getId());
}
} else {
- System.out
- .println(client.getIp()
+ logger.error(client.getIp()
+ " Cannot send the ping after wake on LAN message.");
client
.setError("Sending the ping after wake on LAN message has been failed.");
@@ -313,7 +316,7 @@ public class Boot extends Thread {
}
}
} else {
- System.out.println(client.getIp()
+ logger.error(client.getIp()
+ " is not alive after WoL");
client.setError("The wake on LAN has been failed.");
// not alive, go in errorState
@@ -352,7 +355,7 @@ public class Boot extends Thread {
"Description").toString();
if (description.equals(bootOS)) {
- System.out.println(client.getIp()
+ logger.info(client.getIp()
+ " right OS");
// right os, go to successState
client
@@ -360,7 +363,7 @@ public class Boot extends Thread {
"Booting of the client has been finished.");
osJobs.remove(client.getId());
} else {
- System.out.println(client.getIp()
+ logger.info(client.getIp()
+ " wrong OS");
client
.changeState(WRONG_OS, "WRONG_OS",
@@ -368,7 +371,7 @@ public class Boot extends Thread {
osJobs.remove(client.getId());
}
} else {
- System.out.println(client.getIp()
+ logger.error(client.getIp()
+ " Cannot check os");
client
.setError("The check for correct operating system has been failed.");
@@ -415,7 +418,7 @@ public class Boot extends Thread {
}
if (user.isEmpty()) {
- System.out.println(client.getIp()
+ logger.info(client.getIp()
+ " no user is logged in");
// no user is logged in, doing restart
client.changeState(RESTART_CLIENT,
@@ -423,7 +426,7 @@ public class Boot extends Thread {
"No user is logged in.");
whoJobs.remove(client.getId());
} else {
- System.out.println(client.getIp()
+ logger.info(client.getIp()
+ " a user is logged in");
client.changeState(A_USER_IS_LOGGED_IN,
"A_USER_IS_LOGGED_IN",
@@ -431,8 +434,7 @@ public class Boot extends Thread {
whoJobs.remove(client.getId());
}
} else {
- System.out
- .println(client.getIp()
+ logger.error(client.getIp()
+ " Cannot check if a user is logged in.");
client
.setError("The check if a user is logged in has been failed.");
@@ -491,12 +493,12 @@ public class Boot extends Thread {
if (blacklistFound) {
/*
* if (whitelistFound) {
- * System.out.println(client.getIp() +
+ * logger.info(client.getIp() +
* " is not working"); // is not working
* status.put(client.getId(), 13);
* psJobs.remove(client.getId()); } else {
*/
- System.out.println(client.getIp()
+ logger.info(client.getIp()
+ " is working");
client.changeState(USER_IS_WORKING,
"USER_IS_WORKING",
@@ -511,7 +513,7 @@ public class Boot extends Thread {
psJobs.remove(client.getId());
}
} else {
- System.out.println(client.getIp()
+ logger.error(client.getIp()
+ " Cannot check if user is working.");
client
.setError("The check if a user is working has been failed.");
@@ -549,14 +551,14 @@ public class Boot extends Thread {
JSONObject resultObj = (JSONObject) JSONValue
.parse(result);
if (!resultObj.containsKey("err")) {
- System.out.println(client.getIp()
+ logger.info(client.getIp()
+ " Restart command sent");
client.changeState(RESTART_COMMAND_SENT,
"RESTART_COMMAND_SENT",
"The restart command has been sent.");
restartJobs.remove(client.getId());
} else {
- System.out.println(client.getIp()
+ logger.error(client.getIp()
+ " Cannot send restart command");
client
.setError("Sending the restart command has been failed.");
@@ -612,7 +614,7 @@ public class Boot extends Thread {
String alive = resultObj.get("alive")
.toString();
if (alive.equals("true")) {
- System.out.println(client.getIp()
+ logger.info(client.getIp()
+ " is still alive");
// still alive, ping again
client
@@ -626,7 +628,7 @@ public class Boot extends Thread {
pingRestartShutdownJobs.remove(client
.getId());
} else if (alive.equals("false")) {
- System.out.println(client.getIp()
+ logger.info(client.getIp()
+ " is down");
// not alive, ping again
client
@@ -637,8 +639,7 @@ public class Boot extends Thread {
.getId());
}
} else {
- System.out
- .println(client.getIp()
+ logger.error(client.getIp()
+ " Cannot send the ping after restart message.");
client
.setError("Sending the ping after restart message has been failed.");
@@ -655,7 +656,7 @@ public class Boot extends Thread {
}
}
} else {
- System.out.println(client.getIp() + " shutdown failed");
+ logger.error(client.getIp() + " shutdown failed");
client.setError("The shutdown has been failed.");
// still alive, go in errorState
client
@@ -668,7 +669,7 @@ public class Boot extends Thread {
break;
case USER_IS_WORKING:
- System.out.println(client.getIp() + " User has been working");
+ logger.error(client.getIp() + " User has been working");
client.setError("The user has been working.");
// user has been working, go in errorState
client
@@ -716,7 +717,7 @@ public class Boot extends Thread {
String alive = resultObj.get("alive")
.toString();
if (alive.equals("true")) {
- System.out.println(client.getIp()
+ logger.info(client.getIp()
+ " is alive after restart");
// alive, go to success state
client
@@ -726,7 +727,7 @@ public class Boot extends Thread {
pingRestartBootJobs.remove(client
.getId());
} else if (alive.equals("false")) {
- System.out.println("ping again "
+ logger.info("ping again "
+ client.getIp());
// not alive, ping again
client
@@ -741,8 +742,7 @@ public class Boot extends Thread {
.getId());
}
} else {
- System.out
- .println(client.getIp()
+ logger.error(client.getIp()
+ " Cannot send the ping after shutdown message.");
client
.setError("Sending the ping after shutdown message has been failed.");
@@ -757,7 +757,7 @@ public class Boot extends Thread {
}
}
} else {
- System.out.println(client.getIp()
+ logger.error(client.getIp()
+ " is not alive after reboot");
client.setError("The reboot has been failed.");
// not alive, go in errorState
@@ -772,7 +772,7 @@ public class Boot extends Thread {
case ERROR:
if (!client.isFinished()) {
- System.out.println(client.getIp() + " Booting failed"); // errorState
+ logger.error(client.getIp() + " Booting failed"); // errorState
client.finish();
error = true;
}
@@ -781,7 +781,7 @@ public class Boot extends Thread {
case SUCCESS:
if (!client.isFinished()) {
- System.out.println(client.getIp() + " Booting finished"); // successState
+ logger.info(client.getIp() + " Booting finished"); // successState
client.finish();
}
@@ -813,7 +813,7 @@ public class Boot extends Thread {
client.changeState(PING_INITIALIZED, "PING_INITIALIZED",
"The ping has been initialized.");
pingJobs.put(client.getId(), job);
- System.out.println("ping " + client.getIp());
+ logger.info("ping " + client.getIp());
}
private void pingWakeOnLan(Client client) {
@@ -823,7 +823,7 @@ public class Boot extends Thread {
client.changeState(PING_WOL_INITIALIZED, "PING_WOL_INITIALIZED",
"The ping after wake on LAN has been initialized.");
pingWoLJobs.put(client.getId(), job);
- System.out.println("ping " + client.getIp());
+ logger.info("ping " + client.getIp());
}
private void pingRestartShutdown(Client client) {
@@ -834,7 +834,7 @@ public class Boot extends Thread {
"PING_RESTART_SHUTDOWN_INITIALIZED",
"The ping after shutdown has been initialized.");
pingRestartShutdownJobs.put(client.getId(), job);
- System.out.println("ping " + client.getIp());
+ logger.info("ping " + client.getIp());
}
private void pingRestartBoot(Client client) {
@@ -845,7 +845,7 @@ public class Boot extends Thread {
"PING_RESTART_BOOT_INITIALIZED",
"The ping after reboot has been initialized.");
pingRestartBootJobs.put(client.getId(), job);
- System.out.println("ping " + client.getIp());
+ logger.info("ping " + client.getIp());
}
private void wakeOnLan(Client client) {
@@ -855,7 +855,7 @@ public class Boot extends Thread {
client.changeState(WAKE_ON_LAN_INITIALIZED, "WAKE_ON_LAN_INITIALIZED",
"The wake on LAN has been initialized.");
wolJobs.put(client.getId(), job);
- System.out.println("wake on lan" + client.getMac());
+ logger.info("wake on lan " + client.getMac());
}
private void checkOS(Client client) {
@@ -866,7 +866,7 @@ public class Boot extends Thread {
.changeState(CHECKOS_INITIALIZED, "CHECKOS_INITIALIZED",
"The check for the correct operating system has been initialized.");
osJobs.put(client.getId(), job);
- System.out.println("check OS " + client.getIp());
+ logger.info("check OS " + client.getIp());
}
private void who(Client client) {
@@ -876,7 +876,7 @@ public class Boot extends Thread {
client.changeState(WHO_INITIALIZED, "WHO_INITIALIZED",
"The check if a user is logged in has been initialized.");
whoJobs.put(client.getId(), job);
- System.out.println("who " + client.getIp());
+ logger.info("who " + client.getIp());
}
private void ps(Client client) {
@@ -886,7 +886,7 @@ public class Boot extends Thread {
client.changeState(PS_INITIALIZED, "PS_INITIALIZED",
"The check if the user is working has been initialized.");
psJobs.put(client.getId(), job);
- System.out.println("ps " + client.getIp());
+ logger.info("ps " + client.getIp());
}
private void restart(Client client) {
@@ -896,7 +896,7 @@ public class Boot extends Thread {
client.changeState(RESTART_INITIALIZED, "RESTART_INITIALIZED",
"A restart of the client has been initialized.");
restartJobs.put(client.getId(), job);
- System.out.println("restart " + client.getIp());
+ logger.info("restart " + client.getIp());
}
public Boolean isFinished() {