summaryrefslogtreecommitdiffstats
path: root/gearman
diff options
context:
space:
mode:
authorBjörn Geiger2011-09-12 16:24:57 +0200
committerBjörn Geiger2011-09-12 16:24:57 +0200
commit7f75096153a80823832351569e3bf0b710a945d3 (patch)
tree086e9473f962c70f1551332b5b5c89eaca8f2589 /gearman
parentMerge branch 'master' of git.openslx.org:lsfks/projekte/poolctrl (diff)
downloadpoolctrl-7f75096153a80823832351569e3bf0b710a945d3.tar.gz
poolctrl-7f75096153a80823832351569e3bf0b710a945d3.tar.xz
poolctrl-7f75096153a80823832351569e3bf0b710a945d3.zip
ClientJobs nun in eigener Klasse, Shutdown.java noch nicht umgestellt
Diffstat (limited to 'gearman')
-rwxr-xr-xgearman/controllerWorker/ControllerWorker/Boot.java139
-rw-r--r--gearman/controllerWorker/ControllerWorker/ClientJob.java34
-rwxr-xr-xgearman/controllerWorker/ControllerWorker/ControllerWorkerMain.java2
3 files changed, 109 insertions, 66 deletions
diff --git a/gearman/controllerWorker/ControllerWorker/Boot.java b/gearman/controllerWorker/ControllerWorker/Boot.java
index fb1d3aa..bbed8ae 100755
--- a/gearman/controllerWorker/ControllerWorker/Boot.java
+++ b/gearman/controllerWorker/ControllerWorker/Boot.java
@@ -37,15 +37,7 @@ public class Boot extends Thread {
private final GearmanJobServerConnection gearmanConnection;
private GearmanClient gearmanClient;
- private HashMap<Integer, GearmanJob> pingJobs;
- private HashMap<Integer, GearmanJob> wolJobs;
- private HashMap<Integer, GearmanJob> pingWoLJobs;
- private HashMap<Integer, GearmanJob> osJobs;
- private HashMap<Integer, GearmanJob> whoJobs;
- private HashMap<Integer, GearmanJob> psJobs;
- private HashMap<Integer, GearmanJob> restartJobs;
- private HashMap<Integer, GearmanJob> pingRestartShutdownJobs;
- private HashMap<Integer, GearmanJob> pingRestartBootJobs;
+ private Vector<ClientJob> jobs;
private HashMap<Integer, Long> pingWolTime;
private HashMap<Integer, Long> pingRestartShutdownTime;
private HashMap<Integer, Long> pingRestartBootTime;
@@ -67,15 +59,7 @@ public class Boot extends Thread {
gearmanServerAddress, gearmanServerPort);
gearmanClient = new GearmanClientImpl();
gearmanClient.addJobServer(this.gearmanConnection);
- pingJobs = new HashMap<Integer, GearmanJob>();
- pingWoLJobs = new HashMap<Integer, GearmanJob>();
- wolJobs = new HashMap<Integer, GearmanJob>();
- osJobs = new HashMap<Integer, GearmanJob>();
- whoJobs = new HashMap<Integer, GearmanJob>();
- psJobs = new HashMap<Integer, GearmanJob>();
- restartJobs = new HashMap<Integer, GearmanJob>();
- pingRestartShutdownJobs = new HashMap<Integer, GearmanJob>();
- pingRestartBootJobs = new HashMap<Integer, GearmanJob>();
+ jobs = new Vector<ClientJob>();
pingWolTime = new HashMap<Integer, Long>();
pingRestartShutdownTime = new HashMap<Integer, Long>();
pingRestartBootTime = new HashMap<Integer, Long>();
@@ -291,12 +275,13 @@ public class Boot extends Thread {
.getBytes(), "ping" + client.getId());
gearmanClient.submit(job);
client.setState(ClientState.CHECK_PING_PROGRESS);
- pingJobs.put(client.getId(), job);
+ addClientJob(client.getId(), ClientJob.PINGJOB, job);
logger.info("ping " + client.getIp());
}
private void checkPingProgress(Client client) throws Exception, IOException {
- GearmanJob pingJob = pingJobs.get(client.getId());
+ ClientJob job = getClientJob(client.getId(), ClientJob.PINGJOB);
+ GearmanJob pingJob = job.getGearmanJob();
if (pingJob != null) {
GearmanJobStatus jobStatus = gearmanClient.getJobStatus(pingJob);
@@ -311,11 +296,11 @@ public class Boot extends Thread {
if (alive.equals("true")) {
logger.info(client.getIp() + " alive");
client.setState(ClientState.CLIENT_IS_ALIVE);
- pingJobs.remove(client.getId());
+ removeClientJob(job);
} else if (alive.equals("false")) {
logger.info(client.getIp() + " not alive");
client.setState(ClientState.CLIENT_NOT_ALIVE);
- pingJobs.remove(client.getId());
+ removeClientJob(job);
}
} else {
logger.error(client.getIp()
@@ -323,7 +308,7 @@ public class Boot extends Thread {
client
.setError("Sending the ping message has been failed.");
client.setState(ClientState.BOOT_ERROR);
- pingJobs.remove(client.getId());
+ removeClientJob(job);
}
}
}
@@ -335,13 +320,14 @@ public class Boot extends Thread {
.getBytes(), "ping" + client.getId());
gearmanClient.submit(job);
client.setState(ClientState.CHECK_PING_WOL_PROGRESS);
- pingWoLJobs.put(client.getId(), job);
+ addClientJob(client.getId(), ClientJob.PINGJOB, job);
logger.info("ping " + client.getIp());
}
private void checkPingWolProgress(Client client) throws Exception,
IOException {
- GearmanJob pingJobWoL = pingWoLJobs.get(client.getId());
+ ClientJob job = getClientJob(client.getId(), ClientJob.PINGJOB);
+ GearmanJob pingJobWoL = job.getGearmanJob();
if (pingJobWoL != null) {
Date currentDate = new Date();
@@ -365,11 +351,11 @@ public class Boot extends Thread {
+ " is alive after WoL");
// alive, go in successState
client.setState(ClientState.BOOT_SUCCESS);
- pingWoLJobs.remove(client.getId());
+ removeClientJob(job);
} else if (alive.equals("false")) {
logger.info("ping again " + client.getIp());
client.setState(ClientState.PING_WOL_AGAIN);
- pingWoLJobs.remove(client.getId());
+ removeClientJob(job);
}
} else {
logger
@@ -382,7 +368,7 @@ public class Boot extends Thread {
* been failed, go to errorState
*/
client.setState(ClientState.BOOT_ERROR);
- pingWoLJobs.remove(client.getId());
+ removeClientJob(job);
}
}
}
@@ -391,7 +377,7 @@ public class Boot extends Thread {
client.setError("The wake on LAN has been failed.");
// not alive, go in errorState
client.setState(ClientState.BOOT_ERROR);
- pingWoLJobs.remove(client.getId());
+ removeClientJob(job);
}
}
}
@@ -401,14 +387,14 @@ public class Boot extends Thread {
.getBytes(), "ping" + client.getId());
gearmanClient.submit(job);
client.setState(ClientState.CHECK_PING_RESTART_SHUTDOWN_PROGRESS);
- pingRestartShutdownJobs.put(client.getId(), job);
+ addClientJob(client.getId(), ClientJob.PINGJOB, job);
logger.info("ping " + client.getIp());
}
private void checkPingRestartShutdownProgress(Client client)
throws Exception, IOException {
- GearmanJob pingJobRestartShutdown = pingRestartShutdownJobs.get(client
- .getId());
+ ClientJob job = getClientJob(client.getId(), ClientJob.PINGJOB);
+ GearmanJob pingJobRestartShutdown = job.getGearmanJob();
if (pingJobRestartShutdown != null) {
Date currentDate = new Date();
Long currentTimestamp = currentDate.getTime();
@@ -434,12 +420,12 @@ public class Boot extends Thread {
// still alive, ping again
client
.setState(ClientState.PING_RESTART_SHUTDOWN_AGAIN);
- pingRestartShutdownJobs.remove(client.getId());
+ removeClientJob(job);
} else if (alive.equals("false")) {
logger.info(client.getIp() + " is down");
// not alive, ping again
client.setState(ClientState.CLIENT_IS_DOWN);
- pingRestartShutdownJobs.remove(client.getId());
+ removeClientJob(job);
}
} else {
logger
@@ -452,7 +438,7 @@ public class Boot extends Thread {
* failed
*/
client.setState(ClientState.BOOT_ERROR);
- pingRestartShutdownJobs.remove(client.getId());
+ removeClientJob(job);
}
}
}
@@ -461,7 +447,7 @@ public class Boot extends Thread {
client.setError("The shutdown has been failed.");
// still alive, go in errorState
client.setState(ClientState.BOOT_ERROR);
- pingRestartShutdownJobs.remove(client.getId());
+ removeClientJob(job);
}
}
}
@@ -471,13 +457,14 @@ public class Boot extends Thread {
.getBytes(), "ping" + client.getId());
gearmanClient.submit(job);
client.setState(ClientState.CHECK_PING_RESTART_BOOT_PROGRESS);
- pingRestartBootJobs.put(client.getId(), job);
+ addClientJob(client.getId(), ClientJob.PINGJOB, job);
logger.info("ping " + client.getIp());
}
private void checkPingRestartBootProgress(Client client) throws Exception,
IOException {
- GearmanJob pingJobRestartBoot = pingRestartBootJobs.get(client.getId());
+ ClientJob job = getClientJob(client.getId(), ClientJob.PINGJOB);
+ GearmanJob pingJobRestartBoot = job.getGearmanJob();
if (pingJobRestartBoot != null) {
Date currentDate = new Date();
@@ -503,13 +490,13 @@ public class Boot extends Thread {
+ " is alive after restart");
// alive, go to success state
client.setState(ClientState.BOOT_SUCCESS);
- pingRestartBootJobs.remove(client.getId());
+ removeClientJob(job);
} else if (alive.equals("false")) {
logger.info("ping again " + client.getIp());
// not alive, ping again
client
.setState(ClientState.PING_RESTART_BOOT_AGAIN);
- pingRestartBootJobs.remove(client.getId());
+ removeClientJob(job);
}
} else {
logger
@@ -530,7 +517,7 @@ public class Boot extends Thread {
client.setError("The reboot has been failed.");
// not alive, go in errorState
client.setState(ClientState.BOOT_ERROR);
- pingRestartBootJobs.remove(client.getId());
+ removeClientJob(job);
}
}
}
@@ -540,13 +527,14 @@ public class Boot extends Thread {
.getBytes(), "wol" + client.getId());
gearmanClient.submit(job);
client.setState(ClientState.CHECK_WAKE_ON_LAN_PROGRESS);
- wolJobs.put(client.getId(), job);
+ addClientJob(client.getId(), ClientJob.WOLJOB, job);
logger.info("wake on lan " + client.getMac());
}
private void checkWakeOnLanProgress(Client client) throws Exception,
IOException {
- GearmanJob wolJob = wolJobs.get(client.getId());
+ ClientJob job = getClientJob(client.getId(), ClientJob.WOLJOB);
+ GearmanJob wolJob = job.getGearmanJob();
if (wolJob != null) {
GearmanJobStatus jobStatus = gearmanClient.getJobStatus(wolJob);
@@ -557,14 +545,14 @@ public class Boot extends Thread {
if (result.equals("Magic packet send.")) {
logger.info(client.getMac() + " Magic packet sent.");
client.setState(ClientState.MAGIC_PACKET_SENT);
- wolJobs.remove(client.getId());
+ removeClientJob(job);
} else {
logger.error(client.getIp() + " Cannot send magic packet.");
client
.setError("Sending the magic packet has been failed.");
// cannot send magic packet, go in errorState
client.setState(ClientState.BOOT_ERROR);
- wolJobs.remove(client.getId());
+ removeClientJob(job);
}
}
}
@@ -575,13 +563,14 @@ public class Boot extends Thread {
.getBytes(), "os" + client.getId());
gearmanClient.submit(job);
client.setState(ClientState.CHECK_CHECKOS_PROGRESS);
- osJobs.put(client.getId(), job);
+ addClientJob(client.getId(), ClientJob.OSJOB, job);
logger.info("check OS " + client.getIp());
}
private void checkCheckosProgress(Client client) throws Exception,
IOException {
- GearmanJob osJob = osJobs.get(client.getId());
+ ClientJob job = getClientJob(client.getId(), ClientJob.OSJOB);
+ GearmanJob osJob = job.getGearmanJob();
if (osJob != null) {
GearmanJobStatus jobStatus = gearmanClient.getJobStatus(osJob);
@@ -605,11 +594,11 @@ public class Boot extends Thread {
logger.info(client.getIp() + " right OS");
// right os, go to successState
client.setState(ClientState.BOOT_SUCCESS);
- osJobs.remove(client.getId());
+ removeClientJob(job);
} else {
logger.info(client.getIp() + " wrong OS");
client.setState(ClientState.WRONG_OS);
- osJobs.remove(client.getId());
+ removeClientJob(job);
}
} else {
logger.error(client.getIp() + " Cannot check os");
@@ -617,7 +606,7 @@ public class Boot extends Thread {
.setError("The check for correct operating system has been failed.");
// cannot check os, go in errorState
client.setState(ClientState.BOOT_ERROR);
- osJobs.remove(client.getId());
+ removeClientJob(job);
}
}
}
@@ -629,12 +618,13 @@ public class Boot extends Thread {
.getBytes(), "who" + client.getId());
gearmanClient.submit(job);
client.setState(ClientState.CHECK_WHO_PROGRESS);
- whoJobs.put(client.getId(), job);
+ addClientJob(client.getId(), ClientJob.WHOJOB, job);
logger.info("who " + client.getIp());
}
private void checkWhoProgress(Client client) throws Exception, IOException {
- GearmanJob whoJob = whoJobs.get(client.getId());
+ ClientJob job = getClientJob(client.getId(), ClientJob.WHOJOB);
+ GearmanJob whoJob = job.getGearmanJob();
if (whoJob != null) {
GearmanJobStatus jobStatus = gearmanClient.getJobStatus(whoJob);
@@ -662,13 +652,13 @@ public class Boot extends Thread {
// -----
// didn´t work in test-pool, check ps
client.setState(ClientState.A_USER_IS_LOGGED_IN);
- whoJobs.remove(client.getId());
+ removeClientJob(job);
} else {
logger
.info(client.getIp()
+ " a user is logged in");
client.setState(ClientState.A_USER_IS_LOGGED_IN);
- whoJobs.remove(client.getId());
+ removeClientJob(job);
}
} else {
logger.error(client.getIp()
@@ -680,7 +670,7 @@ public class Boot extends Thread {
*/
// client
client.setState(ClientState.BOOT_ERROR);
- whoJobs.remove(client.getId());
+ removeClientJob(job);
}
}
}
@@ -692,12 +682,13 @@ public class Boot extends Thread {
.getBytes(), "ps" + client.getId());
gearmanClient.submit(job);
client.setState(ClientState.CHECK_PS_PROGRESS);
- psJobs.put(client.getId(), job);
+ addClientJob(client.getId(), ClientJob.PSJOB, job);
logger.info("ps " + client.getIp());
}
private void checkPsProgress(Client client) throws Exception, IOException {
- GearmanJob psJob = psJobs.get(client.getId());
+ ClientJob job = getClientJob(client.getId(), ClientJob.PSJOB);
+ GearmanJob psJob = job.getGearmanJob();
if (psJob != null) {
GearmanJobStatus jobStatus = gearmanClient.getJobStatus(psJob);
@@ -730,16 +721,16 @@ public class Boot extends Thread {
* if (whitelistFound) { logger.info(client.getIp()
* + " is not working"); // is not working
* status.put(client.getId(), 13);
- * psJobs.remove(client.getId()); } else {
+ * removeClientJob(job); } else {
*/
logger.info(client.getIp() + " is working");
client.setState(ClientState.USER_IS_WORKING);
- psJobs.remove(client.getId());
+ removeClientJob(job);
// }
} else {
// user is not working, doing restart
client.setState(ClientState.RESTART_CLIENT);
- psJobs.remove(client.getId());
+ removeClientJob(job);
}
} else {
logger.error(client.getIp()
@@ -750,7 +741,7 @@ public class Boot extends Thread {
* cannot check if user is working, go in errorState
*/
client.setState(ClientState.BOOT_ERROR);
- psJobs.remove(client.getId());
+ removeClientJob(job);
}
}
}
@@ -762,13 +753,14 @@ public class Boot extends Thread {
.getBytes(), "restart" + client.getId());
gearmanClient.submit(job);
client.setState(ClientState.CHECK_RESTART_PROGRESS);
- restartJobs.put(client.getId(), job);
+ addClientJob(client.getId(), ClientJob.RESTARTJOB, job);
logger.info("restart " + client.getIp());
}
private void checkRestartProgress(Client client) throws Exception,
IOException {
- GearmanJob restartJob = restartJobs.get(client.getId());
+ ClientJob job = getClientJob(client.getId(), ClientJob.RESTARTJOB);
+ GearmanJob restartJob = job.getGearmanJob();
if (restartJob != null) {
GearmanJobStatus jobStatus = gearmanClient.getJobStatus(restartJob);
@@ -781,7 +773,7 @@ public class Boot extends Thread {
if (!resultObj.containsKey("err")) {
logger.info(client.getIp() + " Restart command sent");
client.setState(ClientState.RESTART_COMMAND_SENT);
- restartJobs.remove(client.getId());
+ removeClientJob(job);
} else {
logger.error(client.getIp()
+ " Cannot send restart command");
@@ -789,13 +781,30 @@ public class Boot extends Thread {
.setError("Sending the restart command has been failed.");
// cannot send restart command, go in errorState
client.setState(ClientState.BOOT_ERROR);
- restartJobs.remove(client.getId());
+ removeClientJob(job);
}
}
}
}
}
+ private ClientJob getClientJob(int clientID, int jobType) {
+ for (ClientJob job : jobs) {
+ if (job.getJobType() == jobType && job.getClientID() == clientID) {
+ return job;
+ }
+ }
+ return null;
+ }
+
+ private void addClientJob(int clientID, int jobType, GearmanJob gearmanJob) {
+ jobs.add(new ClientJob(clientID, jobType, gearmanJob));
+ }
+
+ private void removeClientJob(ClientJob clientJob) {
+ jobs.remove(clientJob);
+ }
+
public Boolean isFinished() {
return finished && !error;
}
diff --git a/gearman/controllerWorker/ControllerWorker/ClientJob.java b/gearman/controllerWorker/ControllerWorker/ClientJob.java
new file mode 100644
index 0000000..021ab91
--- /dev/null
+++ b/gearman/controllerWorker/ControllerWorker/ClientJob.java
@@ -0,0 +1,34 @@
+package ControllerWorker;
+
+import org.gearman.client.GearmanJob;
+
+public class ClientJob {
+ public static int WOLJOB = 0;
+ public static int PINGJOB = 1;
+ public static int OSJOB = 2;
+ public static int WHOJOB = 3;
+ public static int PSJOB = 4;
+ public static int RESTARTJOB = 5;
+
+ private int clientID;
+ private int JobType;
+ private GearmanJob gearmanJob;
+
+ public ClientJob(int clientID, int jobType, GearmanJob gearmanJob) {
+ this.clientID = clientID;
+ this.JobType = jobType;
+ this.gearmanJob = gearmanJob;
+ }
+
+ public int getClientID() {
+ return clientID;
+ }
+
+ public int getJobType() {
+ return JobType;
+ }
+
+ public GearmanJob getGearmanJob() {
+ return gearmanJob;
+ }
+} \ No newline at end of file
diff --git a/gearman/controllerWorker/ControllerWorker/ControllerWorkerMain.java b/gearman/controllerWorker/ControllerWorker/ControllerWorkerMain.java
index b326c72..88db8e7 100755
--- a/gearman/controllerWorker/ControllerWorker/ControllerWorkerMain.java
+++ b/gearman/controllerWorker/ControllerWorker/ControllerWorkerMain.java
@@ -9,6 +9,7 @@ import org.apache.log4j.BasicConfigurator;
public class ControllerWorkerMain {
public static void main(String[] args) {
+ BasicConfigurator.configure();
final GearmanJobServerConnection connection = new GearmanNIOJobServerConnection(
"127.0.0.1", 4730);
GearmanWorker worker = new GearmanWorkerImpl();
@@ -17,7 +18,6 @@ public class ControllerWorkerMain {
worker.registerFunction(ShutdownWorker.class);
worker.registerFunction(StatusWorker.class);
worker.addServer(connection);
- BasicConfigurator.configure();
PoolctrlRequest poolctrlRequest = new PoolctrlRequest();
poolctrlRequest.start();
worker.work();