summaryrefslogtreecommitdiffstats
path: root/gearman/controllerWorker
diff options
context:
space:
mode:
authorSebastian Wagner2011-09-01 16:04:07 +0200
committerSebastian Wagner2011-09-01 16:04:07 +0200
commit22aa7077f02e777def7ccfa64a1d335023fc5e0b (patch)
tree5eb40312a454692967c8a67bdee1998f4ab61d30 /gearman/controllerWorker
parentShutdown nun auch vollständig umgestellt, noch nicht getestet (diff)
downloadpoolctrl-22aa7077f02e777def7ccfa64a1d335023fc5e0b.tar.gz
poolctrl-22aa7077f02e777def7ccfa64a1d335023fc5e0b.tar.xz
poolctrl-22aa7077f02e777def7ccfa64a1d335023fc5e0b.zip
log4j implemented
Diffstat (limited to 'gearman/controllerWorker')
-rw-r--r--gearman/controllerWorker/ControllerWorker/Boot.java92
-rw-r--r--gearman/controllerWorker/ControllerWorker/BootWorker.java5
-rw-r--r--gearman/controllerWorker/ControllerWorker/Client.java4
-rw-r--r--gearman/controllerWorker/ControllerWorker/ClientState.java2
-rwxr-xr-xgearman/controllerWorker/ControllerWorker/ControllerWorkerMain.java3
-rw-r--r--gearman/controllerWorker/ControllerWorker/Shutdown.java227
-rw-r--r--gearman/controllerWorker/ControllerWorker/ShutdownWorker.java6
-rw-r--r--gearman/controllerWorker/ControllerWorker/SomePingWorker.java5
-rw-r--r--gearman/controllerWorker/library/log4j-1.2.15.jarbin0 -> 391834 bytes
9 files changed, 156 insertions, 188 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() {
diff --git a/gearman/controllerWorker/ControllerWorker/BootWorker.java b/gearman/controllerWorker/ControllerWorker/BootWorker.java
index 572c5dd..e32a8d2 100644
--- a/gearman/controllerWorker/ControllerWorker/BootWorker.java
+++ b/gearman/controllerWorker/ControllerWorker/BootWorker.java
@@ -11,7 +11,10 @@ import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
+import org.apache.log4j.Logger;
+
public class BootWorker extends AbstractGearmanFunction {
+ static final Logger logger = Logger.getLogger(BootWorker.class);
@Override
public String getName() {
return "boot";
@@ -57,7 +60,7 @@ public class BootWorker extends AbstractGearmanFunction {
psWhitelist, psBlacklist, gearmanServerHost, gearmanServerPort);
StatusWorker.BOOTTHREADS.put(event, boot);
boot.start();
- System.out.println("Booting of " + event + " started");
+ logger.info("Booting of " + event + " started");
String res = "Booting started";
byte[] warnings = new byte[0];
diff --git a/gearman/controllerWorker/ControllerWorker/Client.java b/gearman/controllerWorker/ControllerWorker/Client.java
index e891d02..319abd2 100644
--- a/gearman/controllerWorker/ControllerWorker/Client.java
+++ b/gearman/controllerWorker/ControllerWorker/Client.java
@@ -43,6 +43,10 @@ public class Client {
return state.getId();
}
+ public void setState(ClientState state_) {
+ state = state_;
+ }
+
public void changeState(int stateID, String stateName, String stateText) {
state = new ClientState(stateID, stateName, stateText);
}
diff --git a/gearman/controllerWorker/ControllerWorker/ClientState.java b/gearman/controllerWorker/ControllerWorker/ClientState.java
index 614e4d2..af71162 100644
--- a/gearman/controllerWorker/ControllerWorker/ClientState.java
+++ b/gearman/controllerWorker/ControllerWorker/ClientState.java
@@ -22,4 +22,4 @@ public class ClientState {
public String getText() {
return text;
}
-} \ No newline at end of file
+}
diff --git a/gearman/controllerWorker/ControllerWorker/ControllerWorkerMain.java b/gearman/controllerWorker/ControllerWorker/ControllerWorkerMain.java
index dd8b0cc..3a6bc5f 100755
--- a/gearman/controllerWorker/ControllerWorker/ControllerWorkerMain.java
+++ b/gearman/controllerWorker/ControllerWorker/ControllerWorkerMain.java
@@ -5,6 +5,8 @@ import org.gearman.common.GearmanNIOJobServerConnection;
import org.gearman.worker.GearmanWorker;
import org.gearman.worker.GearmanWorkerImpl;
+import org.apache.log4j.BasicConfigurator;
+
public class ControllerWorkerMain {
public static void main(String[] args) {
final GearmanJobServerConnection connection = new GearmanNIOJobServerConnection(
@@ -15,6 +17,7 @@ public class ControllerWorkerMain {
worker.registerFunction(ShutdownWorker.class);
worker.registerFunction(StatusWorker.class);
worker.addServer(connection);
+ BasicConfigurator.configure();
worker.work();
}
} \ No newline at end of file
diff --git a/gearman/controllerWorker/ControllerWorker/Shutdown.java b/gearman/controllerWorker/ControllerWorker/Shutdown.java
index 723e592..0973491 100644
--- a/gearman/controllerWorker/ControllerWorker/Shutdown.java
+++ b/gearman/controllerWorker/ControllerWorker/Shutdown.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 Shutdown extends Thread {
private static final int CLIENT_INITIALIZED = 0;
private static final int PING_INITIALIZED = 1;
@@ -38,6 +40,8 @@ public class Shutdown extends Thread {
private static final int ERROR = 12;
private static final int SUCCESS = 13;
+ static final Logger logger = Logger.getLogger(Shutdown.class);
+
private String eventName;
private Vector<Client> clients;
private final int updateRate;
@@ -57,17 +61,16 @@ public class Shutdown extends Thread {
private Boolean error;
public Shutdown(String eventName, Vector<Client> clients, int updateRate,
- long waitTime, Vector<String> psWhitelist,
- Vector<String> psBlacklist, String gearmanServerAddress,
- int gearmanServerPort) {
+ long waitTime, Vector<String> psWhitelist, Vector<String> psBlacklist,
+ String gearmanServerAddress, int gearmanServerPort) {
this.eventName = eventName;
this.clients = clients;
this.updateRate = updateRate; // updates per second
this.waitTime = waitTime * 1000;
this.psWhitelist = psWhitelist;
this.psBlacklist = psBlacklist;
- gearmanConnection = new GearmanNIOJobServerConnection(
- gearmanServerAddress, gearmanServerPort);
+ gearmanConnection = new GearmanNIOJobServerConnection(gearmanServerAddress,
+ gearmanServerPort);
gearmanClient = new GearmanClientImpl();
gearmanClient.addJobServer(gearmanConnection);
pingJobs = new HashMap<Integer, GearmanJob>();
@@ -105,9 +108,9 @@ public class Shutdown extends Thread {
}
finished = true;
if (error) {
- System.out.println("Shutdown of " + eventName + " failed");
+ logger.info("Shutdown of " + eventName + " failed");
} else {
- System.out.println("Shutdown of " + eventName + " finished");
+ logger.info("Shutdown of " + eventName + " finished");
}
}
@@ -125,44 +128,35 @@ public class Shutdown extends Thread {
GearmanJob pingJob = pingJobs.get(client.getId());
if (pingJob != null) {
- GearmanJobStatus jobStatus = gearmanClient
- .getJobStatus(pingJob);
+ GearmanJobStatus jobStatus = gearmanClient.getJobStatus(pingJob);
if (!jobStatus.isKnown() && pingJob.isDone()) {
GearmanJobResult pingJobRes = pingJob.get();
- String result = ByteUtils.fromUTF8Bytes(pingJobRes
- .getResults());
+ String result = ByteUtils.fromUTF8Bytes(pingJobRes.getResults());
if (!result.isEmpty()) {
- JSONObject resultObj = (JSONObject) JSONValue
- .parse(result);
+ JSONObject resultObj = (JSONObject) JSONValue.parse(result);
if (!resultObj.containsKey("err")) {
- String alive = resultObj.get("alive")
- .toString();
+ String alive = resultObj.get("alive").toString();
if (alive.equals("true")) {
- System.out.println(client.getIp()
- + " alive");
- client.changeState(CLIENT_IS_ALIVE,
- "CLIENT_IS_ALIVE",
- "The client is alive.");
+ logger.info(client.getIp() + " alive");
+ //client.changeState(CLIENT_IS_ALIVE, "CLIENT_IS_ALIVE",
+ // "The client is alive.");
+ client.setState(States.FOO);
// check
// Users
pingJobs.remove(client.getId());
} else if (alive.equals("false")) {
- System.out.println(client.getIp()
- + " not alive");
+ logger.info(client.getIp() + " not alive");
// not alive, go in successState
- client
- .changeState(SUCCESS, "SUCCESS",
- "Shutdown of the client has been finished.");
+ client.changeState(SUCCESS, "SUCCESS",
+ "Shutdown of the client has been finished.");
pingJobs.remove(client.getId());
}
} else {
- System.out.println(client.getIp()
- + " Cannot send the ping message.");
- client
- .setError("Sending the ping message has been failed.");
+ logger.error(client.getIp() + " Cannot send the ping message.");
+ client.setError("Sending the ping message has been failed.");
// sending the ping message has been failed
client
.changeState(ERROR, "ERROR",
@@ -184,53 +178,42 @@ public class Shutdown extends Thread {
GearmanJob whoJob = whoJobs.get(client.getId());
if (whoJob != null) {
- GearmanJobStatus jobStatus = gearmanClient
- .getJobStatus(whoJob);
+ GearmanJobStatus jobStatus = gearmanClient.getJobStatus(whoJob);
if (!jobStatus.isKnown() && whoJob.isDone()) {
GearmanJobResult whoJobRes = whoJob.get();
- String result = ByteUtils.fromUTF8Bytes(whoJobRes
- .getResults());
+ String result = ByteUtils.fromUTF8Bytes(whoJobRes.getResults());
if (!result.isEmpty()) {
- JSONObject resultObj = (JSONObject) JSONValue
- .parse(result);
+ JSONObject resultObj = (JSONObject) JSONValue.parse(result);
if (!resultObj.containsKey("err")) {
- String rawoutput = resultObj.get("rawoutput")
- .toString();
- StringTokenizer str = new StringTokenizer(
- rawoutput, " ");
+ String rawoutput = resultObj.get("rawoutput").toString();
+ StringTokenizer str = new StringTokenizer(rawoutput, " ");
String user = "";
if (str.hasMoreTokens()) {
user = str.nextToken();
}
if (user.isEmpty()) {
- System.out.println(client.getIp()
- + " no user is logged in");
+ logger.info(client.getIp() + " no user is logged in");
// no user is logged in
- client.changeState(SHUTDOWN_CLIENT,
- "SHUTDOWN_CLIENT",
+ client.changeState(SHUTDOWN_CLIENT, "SHUTDOWN_CLIENT",
"No user is logged in.");
whoJobs.remove(client.getId());
} else {
- System.out.println(client.getIp()
- + " a user is logged in");
+ logger.info(client.getIp() + " a user is logged in");
// a user is logged in
- client.changeState(USER_IS_LOGGED_IN,
- "USER_IS_LOGGED_IN",
+ client.changeState(USER_IS_LOGGED_IN, "USER_IS_LOGGED_IN",
"A user is logged in.");
whoJobs.remove(client.getId());
}
} else {
- System.out
- .println(client.getIp()
- + " Cannot check if a user is logged in.");
+ 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.");
/*
- * cannot check if a user is logged in, go in
- * errorState
+ * cannot check if a user is logged in, go in errorState
*/
client
.changeState(ERROR, "ERROR",
@@ -256,26 +239,21 @@ public class Shutdown extends Thread {
if (!jobStatus.isKnown() && doShutdownJob.isDone()) {
GearmanJobResult wolJobRes = doShutdownJob.get();
- String result = ByteUtils.fromUTF8Bytes(wolJobRes
- .getResults());
+ String result = ByteUtils.fromUTF8Bytes(wolJobRes.getResults());
if (!result.isEmpty()) {
- JSONObject resultObj = (JSONObject) JSONValue
- .parse(result);
+ JSONObject resultObj = (JSONObject) JSONValue.parse(result);
if (!resultObj.containsKey("err")) {
- System.out.println(client.getIp()
- + " Shutdown command sent");
+ logger.info(client.getIp() + " Shutdown command sent");
client.changeState(SHUTDOWN_COMMAND_SENT,
"SHUTDOWN_COMMAND_SENT",
"The shutdown command has been sent.");
doShutdownJobs.remove(client.getId());
} else {
- System.out.println(client.getIp()
- + " Cannot send shutdown command");
+ logger.error(client.getIp() + " Cannot send shutdown command");
client
.setError("Sending the shutdown command has been failed.");
/*
- * cannot send shutdown command, go in /
- * errorState
+ * cannot send shutdown command, go in / errorState
*/
client
.changeState(ERROR, "ERROR",
@@ -302,59 +280,44 @@ public class Shutdown extends Thread {
break;
case PING_SHUTDOWN_INITIALIZED:
- GearmanJob pingJobShutdown = pingShutdownJobs.get(client
- .getId());
+ GearmanJob pingJobShutdown = pingShutdownJobs.get(client.getId());
if (pingJobShutdown != null) {
Date currentDate = new Date();
Long currentTimestamp = currentDate.getTime();
// wait 2 min until shutdown
- Long expectedTimestamp = pingShutdownTime.get(client
- .getId())
+ Long expectedTimestamp = pingShutdownTime.get(client.getId())
+ waitTime;
if (expectedTimestamp >= currentTimestamp) {
GearmanJobStatus jobStatus = gearmanClient
.getJobStatus(pingJobShutdown);
if (!jobStatus.isKnown() && pingJobShutdown.isDone()) {
GearmanJobResult pingJobRes = pingJobShutdown.get();
- String result = ByteUtils.fromUTF8Bytes(pingJobRes
- .getResults());
+ String result = ByteUtils.fromUTF8Bytes(pingJobRes.getResults());
if (!result.isEmpty()) {
- JSONObject resultObj = (JSONObject) JSONValue
- .parse(result);
+ JSONObject resultObj = (JSONObject) JSONValue.parse(result);
if (!resultObj.containsKey("err")) {
- String alive = resultObj.get("alive")
- .toString();
+ String alive = resultObj.get("alive").toString();
if (alive.equals("false")) {
- System.out.println(client.getIp()
- + " is not alive anymore");
+ logger.info(client.getIp() + " is not alive anymore");
// not alive, go in successState
- client
- .changeState(SUCCESS,
- "SUCCESS",
- "Shutdown of the client has been finished.");
+ client.changeState(SUCCESS, "SUCCESS",
+ "Shutdown of the client has been finished.");
pingShutdownJobs.remove(client.getId());
} else if (alive.equals("true")) {
- System.out
- .println(client.getIp()
- + " is still alive after shutdown command");
- client
- .changeState(
- PING_SHUTDOWN_AGAIN,
- "PING_SHUTDOWN_AGAIN",
- "Doing ping after shutdown again and again, until client is not alive or "
- + waitTime
- / 60
- + " minutes has been elapsed");
+ logger.info(client.getIp()
+ + " is still alive after shutdown command");
+ client.changeState(PING_SHUTDOWN_AGAIN,
+ "PING_SHUTDOWN_AGAIN",
+ "Doing ping after shutdown again and again, until client is not alive or "
+ + waitTime / 60 + " minutes has been elapsed");
}
} else {
- System.out
- .println(client.getIp()
- + " Cannot send the ping after shutdown message.");
+ logger.error(client.getIp()
+ + " Cannot send the ping after shutdown message.");
client
.setError("Sending the ping after shutdown message has been failed.");
/*
- * sending the ping after shutdown message
- * has been failed
+ * sending the ping after shutdown message has been failed
*/
client
.changeState(ERROR, "ERROR",
@@ -364,10 +327,8 @@ public class Shutdown extends Thread {
}
}
} else {
- System.out.println(client.getIp()
- + " is alive after shutdown");
- client
- .setError("Client is still alive after shutdown.");
+ logger.error(client.getIp() + " is alive after shutdown");
+ client.setError("Client is still alive after shutdown.");
// still alive, go in errorState
client
.changeState(ERROR, "ERROR",
@@ -387,17 +348,14 @@ public class Shutdown extends Thread {
GearmanJob psJob = psJobs.get(client.getId());
if (psJob != null) {
- GearmanJobStatus jobStatus = gearmanClient
- .getJobStatus(psJob);
+ GearmanJobStatus jobStatus = gearmanClient.getJobStatus(psJob);
if (!jobStatus.isKnown() && psJob.isDone()) {
GearmanJobResult whoJobRes = psJob.get();
- String result = ByteUtils.fromUTF8Bytes(whoJobRes
- .getResults());
+ String result = ByteUtils.fromUTF8Bytes(whoJobRes.getResults());
if (!result.isEmpty()) {
- JSONObject resultObj = (JSONObject) JSONValue
- .parse(result);
+ JSONObject resultObj = (JSONObject) JSONValue.parse(result);
if (!resultObj.containsKey("err")) {
JSONArray ps = (JSONArray) resultObj.get("ps");
// boolean whitelistFound = false;
@@ -411,42 +369,37 @@ public class Shutdown extends Thread {
/*
* for (String whiteEntry : psWhitelist) { if
- * (ps.toString().contains(whiteEntry)) {
- * whitelistFound = true; } }
+ * (ps.toString().contains(whiteEntry)) { whitelistFound = true;
+ * } }
*/
if (blacklistFound) {
/*
- * if (whitelistFound) {
- * System.out.println(client.getIp() +
+ * if (whitelistFound) { logger.info(client.getIp() +
* " is not working"); // is not working
* status.put(client.getId(), 4);
* psJobs.remove(client.getId());
*
* } else {
*/
- client.changeState(USER_IS_WORKING,
- "USER_IS_WORKING",
+ client.changeState(USER_IS_WORKING, "USER_IS_WORKING",
"The user is working.");
psJobs.remove(client.getId());
// }
} else {
- System.out.println(client.getIp()
- + " is not working");
+ logger.info(client.getIp() + " is not working");
// is not working
- client.changeState(SHUTDOWN_CLIENT,
- "SHUTDOWN_CLIENT",
+ client.changeState(SHUTDOWN_CLIENT, "SHUTDOWN_CLIENT",
"The User is not working.");
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.");
/*
- * cannot check if user is working, go in
- * errorState
+ * cannot check if user is working, go in errorState
*/
client
.changeState(ERROR, "ERROR",
@@ -460,18 +413,17 @@ public class Shutdown 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
- .changeState(ERROR, "ERROR",
- "Shutdown of the client has not been finished, due to an error.");
+ client.changeState(ERROR, "ERROR",
+ "Shutdown of the client has not been finished, due to an error.");
break;
case ERROR:
if (!client.isFinished()) {
- System.out.println(client.getIp() + " Shutdown failed"); // errorState
+ logger.info(client.getIp() + " Shutdown failed"); // errorState
client.finish();
error = true;
}
@@ -480,7 +432,7 @@ public class Shutdown extends Thread {
case SUCCESS:
if (!client.isFinished()) {
- System.out.println(client.getIp() + " Shutdown finished"); // successState
+ logger.info(client.getIp() + " Shutdown finished"); // successState
client.finish();
}
@@ -507,23 +459,23 @@ public class Shutdown extends Thread {
}
private void ping(Client client) {
- GearmanJob job = GearmanJobImpl.createJob("ping", client.getIp()
- .getBytes(), "ping" + client.getId());
+ GearmanJob job = GearmanJobImpl.createJob("ping",
+ client.getIp().getBytes(), "ping" + client.getId());
gearmanClient.submit(job);
client.changeState(PING_INITIALIZED, "PING_INITIALIZED",
"The ping has been intialized.");
pingJobs.put(client.getId(), job);
- System.out.println("ping " + client.getIp());
+ logger.info("ping " + client.getIp());
}
private void who(Client client) {
- GearmanJob job = GearmanJobImpl.createJob("who", client.getIp()
- .getBytes(), "who" + client.getId());
+ GearmanJob job = GearmanJobImpl.createJob("who", client.getIp().getBytes(),
+ "who" + client.getId());
gearmanClient.submit(job);
client.changeState(WHO_INITIALIZED, "WHO_INITIALIZED",
"The check if a user is logged in has been intialized.");
whoJobs.put(client.getId(), job);
- System.out.println("who " + client.getIp());
+ logger.info("who " + client.getIp());
}
private void doShutdown(Client client) {
@@ -533,28 +485,27 @@ public class Shutdown extends Thread {
client.changeState(SHUTDOWN_INITIALIZED, "SHUTDOWN_INITIALIZED",
"A shutdown of the client has been triggered.");
doShutdownJobs.put(client.getId(), job);
- System.out.println("doShutdown " + client.getIp());
+ logger.info("doShutdown " + client.getIp());
}
private void pingShutdown(Client client) {
- GearmanJob job = GearmanJobImpl.createJob("ping", client.getIp()
- .getBytes(), "ping" + client.getId());
+ GearmanJob job = GearmanJobImpl.createJob("ping",
+ client.getIp().getBytes(), "ping" + client.getId());
gearmanClient.submit(job);
- client.changeState(PING_SHUTDOWN_INITIALIZED,
- "PING_SHUTDOWN_INITIALIZED",
+ client.changeState(PING_SHUTDOWN_INITIALIZED, "PING_SHUTDOWN_INITIALIZED",
"The ping after shutdown has been intialized.");
pingShutdownJobs.put(client.getId(), job);
- System.out.println("ping " + client.getIp());
+ logger.info("ping " + client.getIp());
}
private void ps(Client client) {
- GearmanJob job = GearmanJobImpl.createJob("ps", client.getIp()
- .getBytes(), "ps" + client.getId());
+ GearmanJob job = GearmanJobImpl.createJob("ps", client.getIp().getBytes(),
+ "ps" + client.getId());
gearmanClient.submit(job);
client.changeState(PS_INITIALIZED, "PS_INITIALIZED",
"The check if the user is working has been intialized.");
psJobs.put(client.getId(), job);
- System.out.println("ps " + client.getIp());
+ logger.info("ps " + client.getIp());
}
public Boolean isFinished() {
diff --git a/gearman/controllerWorker/ControllerWorker/ShutdownWorker.java b/gearman/controllerWorker/ControllerWorker/ShutdownWorker.java
index d3d9ae7..62ffee0 100644
--- a/gearman/controllerWorker/ControllerWorker/ShutdownWorker.java
+++ b/gearman/controllerWorker/ControllerWorker/ShutdownWorker.java
@@ -11,7 +11,10 @@ import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
+import org.apache.log4j.Logger;
+
public class ShutdownWorker extends AbstractGearmanFunction {
+ static final Logger logger = Logger.getLogger(ShutdownWorker.class);
@Override
public String getName() {
return "shutdown";
@@ -19,6 +22,7 @@ public class ShutdownWorker extends AbstractGearmanFunction {
@Override
public GearmanJobResult executeFunction() {
+
String data = ByteUtils.fromUTF8Bytes((byte[]) this.data);
Vector<Client> clients = new Vector<Client>();
JSONObject jsonObject = (JSONObject) JSONValue.parse(data);
@@ -55,7 +59,7 @@ public class ShutdownWorker extends AbstractGearmanFunction {
psWhitelist, psBlacklist, gearmanServerHost, gearmanServerPort);
StatusWorker.SHUTDOWNTHREADS.put(event, shutdown);
shutdown.start();
- System.out.println("Shutdown of " + event + " started");
+ logger.info("Shutdown of " + event + " started");
String res = "Shutdown started";
byte[] warnings = new byte[0];
diff --git a/gearman/controllerWorker/ControllerWorker/SomePingWorker.java b/gearman/controllerWorker/ControllerWorker/SomePingWorker.java
index f3f6fe6..afe221a 100644
--- a/gearman/controllerWorker/ControllerWorker/SomePingWorker.java
+++ b/gearman/controllerWorker/ControllerWorker/SomePingWorker.java
@@ -21,7 +21,10 @@ import org.gearman.worker.AbstractGearmanFunction;
import org.json.simple.JSONArray;
import org.json.simple.JSONValue;
+import org.apache.log4j.Logger;
+
public class SomePingWorker extends AbstractGearmanFunction {
+ static final Logger logger = Logger.getLogger(SomePingWorker.class);
@Override
public String getName() {
return "somePing";
@@ -41,7 +44,7 @@ public class SomePingWorker extends AbstractGearmanFunction {
for (Object ipObj : jsonArray) {
String ip = ipObj.toString();
- System.out.println("Ping " + ip);
+ logger.info("Ping " + ip);
GearmanJob job = GearmanJobImpl.createJob("ping", ip.getBytes(),
"ping" + count);
client.submit(job);
diff --git a/gearman/controllerWorker/library/log4j-1.2.15.jar b/gearman/controllerWorker/library/log4j-1.2.15.jar
new file mode 100644
index 0000000..c930a6a
--- /dev/null
+++ b/gearman/controllerWorker/library/log4j-1.2.15.jar
Binary files differ