summaryrefslogtreecommitdiffstats
path: root/gearman/controllerWorker/ControllerWorker
diff options
context:
space:
mode:
authorBjörn Geiger2011-08-24 13:56:27 +0200
committerBjörn Geiger2011-08-24 13:56:27 +0200
commit88c3105d9bee90653a1327062183a0726377e9ad (patch)
tree70032ee8e0e9ca33ec3e382de20c580e3424dc3e /gearman/controllerWorker/ControllerWorker
parentminor (diff)
downloadpoolctrl-88c3105d9bee90653a1327062183a0726377e9ad.tar.gz
poolctrl-88c3105d9bee90653a1327062183a0726377e9ad.tar.xz
poolctrl-88c3105d9bee90653a1327062183a0726377e9ad.zip
verschiedene Korrekturen
Diffstat (limited to 'gearman/controllerWorker/ControllerWorker')
-rw-r--r--gearman/controllerWorker/ControllerWorker/Boot.java229
-rw-r--r--gearman/controllerWorker/ControllerWorker/BootWorker.java12
-rw-r--r--gearman/controllerWorker/ControllerWorker/Shutdown.java177
-rw-r--r--gearman/controllerWorker/ControllerWorker/ShutdownWorker.java12
4 files changed, 235 insertions, 195 deletions
diff --git a/gearman/controllerWorker/ControllerWorker/Boot.java b/gearman/controllerWorker/ControllerWorker/Boot.java
index 81ea279..dfbe3a0 100644
--- a/gearman/controllerWorker/ControllerWorker/Boot.java
+++ b/gearman/controllerWorker/ControllerWorker/Boot.java
@@ -2,8 +2,8 @@ package ControllerWorker;
import java.io.IOException;
import java.lang.Thread;
-import java.util.Date;
import java.util.concurrent.ExecutionException;
+import java.util.Date;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -23,17 +23,16 @@ import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
public class Boot extends Thread {
- private long beginTime;
- private long timeTaken;
- private long timeLeft;
- private Boolean finished;
- private Boolean error;
+ private String eventName;
+ private Vector<HashMap<String, String>> clients;
+ private String bootOS;
private final int updateRate;
- private final long updatePeriod;
private long waitTime;
- private String bootOS;
- private String[] statusText;
+ private Vector<String> psWhitelist;
+ private Vector<String> psBlacklist;
+ private final GearmanJobServerConnection gearmanConnection;
+ private GearmanClient gearmanClient;
private HashMap<Integer, GearmanJob> pingJobs;
private HashMap<Integer, GearmanJob> wolJobs;
private HashMap<Integer, GearmanJob> pingWoLJobs;
@@ -43,79 +42,81 @@ public class Boot extends Thread {
private HashMap<Integer, GearmanJob> restartJobs;
private HashMap<Integer, GearmanJob> pingRestartShutdownJobs;
private HashMap<Integer, GearmanJob> pingRestartBootJobs;
- private HashMap<Integer, Integer> status;
- private HashMap<Integer, String> errors;
private HashMap<Integer, Long> pingWolTime;
private HashMap<Integer, Long> pingRestartShutdownTime;
private HashMap<Integer, Long> pingRestartBootTime;
- private Vector<String> psWhitelist;
- private Vector<String> psBlacklist;
-
- private Vector<HashMap<String, String>> clients;
-
- private final GearmanJobServerConnection gearmanConnection;
- private GearmanClient gearmanClient;
+ 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 serverAddress, int port,
- Vector<HashMap<String, String>> clients, int updateRate,
- long waitTime, String bootOS, Vector<String> psWhitelist,
- Vector<String> psBlacklist) {
- this.pingJobs = new HashMap<Integer, GearmanJob>();
- this.pingWoLJobs = new HashMap<Integer, GearmanJob>();
- this.wolJobs = new HashMap<Integer, GearmanJob>();
- this.osJobs = new HashMap<Integer, GearmanJob>();
- this.whoJobs = new HashMap<Integer, GearmanJob>();
- this.psJobs = new HashMap<Integer, GearmanJob>();
- this.restartJobs = new HashMap<Integer, GearmanJob>();
- this.pingRestartShutdownJobs = new HashMap<Integer, GearmanJob>();
- this.pingRestartBootJobs = new HashMap<Integer, GearmanJob>();
- this.status = new HashMap<Integer, Integer>();
- this.errors = new HashMap<Integer, String>();
- this.pingWolTime = new HashMap<Integer, Long>();
- this.pingRestartShutdownTime = new HashMap<Integer, Long>();
- this.pingRestartBootTime = new HashMap<Integer, Long>();
+ 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) {
+ this.eventName = eventName;
+ this.clients = clients;
+ this.bootOS = bootOS;
+ this.waitTime = waitTime * 1000;
+ this.updateRate = updateRate; // updates per second
this.psWhitelist = psWhitelist;
this.psBlacklist = psBlacklist;
- this.updateRate = updateRate; // updates per second
- this.updatePeriod = 1000000000L / this.updateRate; // nanoseconds
- this.gearmanConnection = new GearmanNIOJobServerConnection(
- serverAddress, port);
- this.gearmanClient = new GearmanClientImpl();
+ gearmanConnection = new GearmanNIOJobServerConnection(
+ gearmanServerAddress, gearmanServerPort);
+ gearmanClient = new GearmanClientImpl();
gearmanClient.addJobServer(this.gearmanConnection);
- this.clients = clients;
- this.waitTime = waitTime * 1000;
+ 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>();
+ 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);
}
- this.finished = false;
- this.error = false;
- this.bootOS = bootOS;
- this.statusText = new String[31];
- this.statusText[0] = "The booting process of the client has been started.";
- this.statusText[1] = "The ping has been started.";
- this.statusText[2] = "The client is alive.";
- this.statusText[3] = "The client is not alive.";
- this.statusText[4] = "The wake on LAN has been started.";
- this.statusText[5] = "The Magic packet has been sent.";
- this.statusText[6] = "The ping after wake on LAN has been started.";
- this.statusText[7] = "Doing ping after wake on LAN again and again, until client is alive or two minutes has been elapsed";
- this.statusText[8] = "The check for the correct operating system has been started.";
- this.statusText[9] = "The wrong operating system is running.";
- this.statusText[10] = "The check if a user is logged in has been started.";
- this.statusText[11] = "A user is logged in.";
- this.statusText[12] = "The check if the user is working has been started.";
- this.statusText[13] = "The user is not working.";
- this.statusText[14] = "A restart of the client has been triggered.";
- this.statusText[15] = "The restart command has been sent.";
- this.statusText[16] = "The ping after shutdown has been started.";
- this.statusText[17] = "Doing ping after shutdown again and again, until client is not alive or two minutes has been elapsed";
- this.statusText[18] = "The user is working.";
- this.statusText[19] = "The client has been shutted down.";
- this.statusText[20] = "The ping after reboot has been started.";
- this.statusText[21] = "Doing ping after reboot again and again, until client is not alive or two minutes has been elapsed";
- this.statusText[29] = "Booting of the client has not been finished, due to an error.";
- this.statusText[30] = "Booting of the client has been finished.";
}
public void run() {
@@ -123,6 +124,10 @@ public class Boot extends Thread {
}
private void workerLoop() {
+ long beginTime;
+ long timeTaken;
+ long timeLeft;
+ long updatePeriod = 1000000000L / updateRate; // nanoseconds
Boolean run = true;
while (run) {
try {
@@ -137,12 +142,16 @@ public class Boot extends Thread {
e.printStackTrace();
}
}
- this.finished = true;
+ finished = true;
+ if (error) {
+ System.out.println("Booting of " + eventName + " failed");
+ } else {
+ System.out.println("Booting of " + eventName + " finished");
+ }
}
private Boolean update() throws IllegalStateException, IOException,
InterruptedException, ExecutionException {
- Boolean allFinished = false;
Date date;
long timestamp;
@@ -187,7 +196,7 @@ public class Boot extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot send the ping message.");
- this.errors
+ errors
.put(clientID,
"Sending the ping message has been failed.");
// sending the ping message has been failed
@@ -229,7 +238,7 @@ public class Boot extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot send magic packet.");
- this.errors
+ errors
.put(clientID,
"Sending the magic packet has been failed.");
// cannot send magic packet, go in errorState
@@ -260,7 +269,7 @@ public class Boot extends Thread {
Date currentDate = new Date();
Long currentTimestamp = currentDate.getTime();
// wait 2 min until WoL - Failed
- Long expectedTimestamp = this.pingWolTime.get(clientID)
+ Long expectedTimestamp = pingWolTime.get(clientID)
+ waitTime;
if (expectedTimestamp >= currentTimestamp) {
GearmanJobStatus jobStatus = gearmanClient
@@ -291,7 +300,7 @@ public class Boot extends Thread {
System.out
.println(ipAddress
+ " Cannot send the ping after wake on LAN message.");
- this.errors
+ errors
.put(clientID,
"Sending the ping after wake on LAN message has been failed.");
/*
@@ -306,8 +315,9 @@ public class Boot extends Thread {
} else {
System.out.println(ipAddress
+ " is not alive after WoL");
- this.errors.put(clientID,
- "The wake on LAN has been failed.");
+ errors
+ .put(clientID,
+ "The wake on LAN has been failed.");
status.put(clientID, 29); // not alive, go in errorState
pingWoLJobs.remove(clientID);
}
@@ -340,7 +350,7 @@ public class Boot extends Thread {
String description = resultObj.get(
"Description").toString();
- if (description.equals(this.bootOS)) {
+ if (description.equals(bootOS)) {
System.out.println(ipAddress + " right OS");
status.put(clientID, 30); // right os
osJobs.remove(clientID);
@@ -352,7 +362,7 @@ public class Boot extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot check os");
- this.errors
+ errors
.put(clientID,
"The check for correct operating system has been failed.");
// cannot check os, go in errorState
@@ -412,7 +422,7 @@ public class Boot extends Thread {
System.out
.println(ipAddress
+ " Cannot check if a user is logged in.");
- this.errors
+ errors
.put(clientID,
"The check if a user is logged in has been failed.");
/*
@@ -480,7 +490,7 @@ public class Boot extends Thread {
System.out
.println(ipAddress
+ " Cannot check if user is working.");
- this.errors
+ errors
.put(clientID,
"The check if a user is working has been failed.");
/*
@@ -493,7 +503,7 @@ public class Boot extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot check if user is working.");
- this.errors
+ errors
.put(clientID,
"The check if a user is working has been failed.");
/*
@@ -536,7 +546,7 @@ public class Boot extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot send restart command");
- this.errors
+ errors
.put(clientID,
"Sending the restart command has been failed.");
// cannot send restart command, go in errorState
@@ -569,7 +579,7 @@ public class Boot extends Thread {
Date currentDate = new Date();
Long currentTimestamp = currentDate.getTime();
// wait 2 min until Restart - Failed
- Long expectedTimestamp = this.pingRestartShutdownTime
+ Long expectedTimestamp = pingRestartShutdownTime
.get(clientID)
+ waitTime;
if (expectedTimestamp >= currentTimestamp) {
@@ -607,7 +617,7 @@ public class Boot extends Thread {
System.out
.println(ipAddress
+ " Cannot send the ping after restart message.");
- this.errors
+ errors
.put(clientID,
"Sending the ping after restart message has been failed.");
/*
@@ -621,8 +631,7 @@ public class Boot extends Thread {
}
} else {
System.out.println(ipAddress + " shutdown failed");
- this.errors.put(clientID,
- "The shutdown has been failed.");
+ errors.put(clientID, "The shutdown has been failed.");
// still alive, go in errorState
status.put(clientID, 29);
pingRestartShutdownJobs.remove(clientID);
@@ -632,9 +641,9 @@ public class Boot extends Thread {
break;
case 18:
- System.out.println("User has worked");
- this.errors.put(clientID, "The user has worked.");
- // user has worked, go in errorState
+ System.out.println("User has been working");
+ errors.put(clientID, "The user has been working.");
+ // user has been working, go in errorState
status.put(clientID, 29);
break;
@@ -659,8 +668,7 @@ public class Boot extends Thread {
Date currentDate = new Date();
Long currentTimestamp = currentDate.getTime();
// wait 2 min until Restart - Failed
- Long expectedTimestamp = this.pingRestartBootTime
- .get(clientID)
+ Long expectedTimestamp = pingRestartBootTime.get(clientID)
+ waitTime;
if (expectedTimestamp >= currentTimestamp) {
GearmanJobStatus jobStatus = gearmanClient
@@ -694,7 +702,7 @@ public class Boot extends Thread {
System.out
.println(ipAddress
+ " Cannot send the ping after shutdown message.");
- this.errors
+ errors
.put(clientID,
"Sending the ping after shutdown message has been failed.");
/*
@@ -709,8 +717,7 @@ public class Boot extends Thread {
} else {
System.out.println(ipAddress
+ " is not alive after reboot");
- this.errors
- .put(clientID, "The reboot has been failed.");
+ errors.put(clientID, "The reboot has been failed.");
status.put(clientID, 29); // not alive, go in errorState
pingRestartBootJobs.remove(clientID);
}
@@ -719,22 +726,30 @@ public class Boot extends Thread {
break;
case 29:
- System.out.println("Booting failed"); // errorState
+ if (!finishedClients.get(clientID)) {
+ System.out.println(ipAddress + " booting failed"); // errorState
+ finishedClients.put(clientID, true);
+ error = true;
+ }
break;
case 30:
- System.out.println("Booting finished"); // successState
+ if (!finishedClients.get(clientID)) {
+ System.out.println(ipAddress + " booting finished"); // successState
+ finishedClients.put(clientID, true);
+ }
break;
}
+ }
- if (clientStatus == 30) {
- allFinished = true;
- } else if (clientStatus == 29) {
+ boolean allFinished = false;
+ for (HashMap<String, String> client : clients) {
+ int clientID = Integer.parseInt(client.get("id"));
+ if (finishedClients.get(clientID)) {
allFinished = true;
- error = true;
} else {
allFinished = false;
}
@@ -875,8 +890,8 @@ public class Boot extends Thread {
public String getStatusText(HashMap<String, String> client) {
int clientID = Integer.parseInt(client.get("id"));
- int clientStatus = this.status.get(clientID);
- return this.statusText[clientStatus];
+ int clientStatus = status.get(clientID);
+ return statusText[clientStatus];
}
public String getError(HashMap<String, String> client) {
@@ -896,4 +911,8 @@ public class Boot extends Thread {
public Vector<HashMap<String, String>> getClients() {
return clients;
}
+
+ public String getEventName() {
+ return eventName;
+ }
}
diff --git a/gearman/controllerWorker/ControllerWorker/BootWorker.java b/gearman/controllerWorker/ControllerWorker/BootWorker.java
index 22d1e91..5256730 100644
--- a/gearman/controllerWorker/ControllerWorker/BootWorker.java
+++ b/gearman/controllerWorker/ControllerWorker/BootWorker.java
@@ -25,8 +25,10 @@ public class BootWorker extends AbstractGearmanFunction {
JSONObject jsonObject = (JSONObject) JSONValue.parse(data);
String event = jsonObject.get("eventName").toString();
String eventOS = jsonObject.get("eventOS").toString();
- String host = jsonObject.get("host").toString();
- int port = Integer.parseInt(jsonObject.get("port").toString());
+ String gearmanServerHost = jsonObject.get("gearmanServerHost")
+ .toString();
+ int gearmanServerPort = Integer.parseInt(jsonObject.get(
+ "gearmanServerPort").toString());
int updateRate = Integer.parseInt(jsonObject.get("updateRate")
.toString());
long waitTime = Long.parseLong(jsonObject.get("waitTime").toString());
@@ -54,11 +56,11 @@ public class BootWorker extends AbstractGearmanFunction {
psBlacklist.add(blackEntry.toString());
}
- Boot boot = new Boot(host, port, clients, updateRate, waitTime,
- eventOS, psWhitelist, psBlacklist);
+ Boot boot = new Boot(event, clients, eventOS, updateRate, waitTime,
+ psWhitelist, psBlacklist, gearmanServerHost, gearmanServerPort);
StatusWorker.BOOTTHREADS.put(event, boot);
boot.start();
- System.out.println("Booting started");
+ System.out.println("Booting of " + event + " started");
String res = "Booting started";
byte[] warnings = new byte[0];
diff --git a/gearman/controllerWorker/ControllerWorker/Shutdown.java b/gearman/controllerWorker/ControllerWorker/Shutdown.java
index 368efb0..ba0e722 100644
--- a/gearman/controllerWorker/ControllerWorker/Shutdown.java
+++ b/gearman/controllerWorker/ControllerWorker/Shutdown.java
@@ -23,75 +23,74 @@ import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
public class Shutdown extends Thread {
- private long beginTime;
- private long timeTaken;
- private long timeLeft;
- private Boolean finished;
- private Boolean error;
+ private String eventName;
+ private Vector<HashMap<String, String>> clients;
private final int updateRate;
- private final long updatePeriod;
private long waitTime;
- private String[] statusText;
+ private Vector<String> psWhitelist;
+ private Vector<String> psBlacklist;
+ private final GearmanJobServerConnection gearmanConnection;
+ private GearmanClient gearmanClient;
private HashMap<Integer, GearmanJob> pingJobs;
private HashMap<Integer, GearmanJob> whoJobs;
private HashMap<Integer, GearmanJob> doShutdownJobs;
private HashMap<Integer, GearmanJob> pingShutdownJobs;
private HashMap<Integer, GearmanJob> psJobs;
+ private HashMap<Integer, Long> pingShutdownTime;
private HashMap<Integer, Integer> status;
private HashMap<Integer, String> errors;
- private HashMap<Integer, Long> pingShutdownTime;
- private Vector<String> psWhitelist;
- private Vector<String> psBlacklist;
-
- private Vector<HashMap<String, String>> clients;
-
- private final GearmanJobServerConnection gearmanConnection;
- private GearmanClient gearmanClient;
+ private HashMap<Integer, Boolean> finishedClients;
+ private Boolean finished;
+ private Boolean error;
+ private String[] statusText;
- public Shutdown(String serverAddress, int port,
- Vector<HashMap<String, String>> clients, int updateRate,
- long waitTime, Vector<String> psWhitelist,
- Vector<String> psBlacklist) {
- this.pingJobs = new HashMap<Integer, GearmanJob>();
- this.whoJobs = new HashMap<Integer, GearmanJob>();
- this.doShutdownJobs = new HashMap<Integer, GearmanJob>();
- this.pingShutdownJobs = new HashMap<Integer, GearmanJob>();
- this.psJobs = new HashMap<Integer, GearmanJob>();
- this.status = new HashMap<Integer, Integer>();
- this.errors = new HashMap<Integer, String>();
- this.pingShutdownTime = new HashMap<Integer, Long>();
- this.psWhitelist = psWhitelist;
- this.psBlacklist = psBlacklist;
+ public Shutdown(String eventName, Vector<HashMap<String, String>> clients,
+ int updateRate, 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.updatePeriod = 1000000000L / this.updateRate; // nanoseconds
- this.gearmanConnection = new GearmanNIOJobServerConnection(
- serverAddress, port);
- this.gearmanClient = new GearmanClientImpl();
- gearmanClient.addJobServer(this.gearmanConnection);
this.waitTime = waitTime * 1000;
- this.clients = clients;
+ this.psWhitelist = psWhitelist;
+ this.psBlacklist = psBlacklist;
+ gearmanConnection = new GearmanNIOJobServerConnection(
+ gearmanServerAddress, gearmanServerPort);
+ gearmanClient = new GearmanClientImpl();
+ gearmanClient.addJobServer(gearmanConnection);
+ pingJobs = new HashMap<Integer, GearmanJob>();
+ whoJobs = new HashMap<Integer, GearmanJob>();
+ doShutdownJobs = new HashMap<Integer, GearmanJob>();
+ pingShutdownJobs = new HashMap<Integer, GearmanJob>();
+ 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.";
+ statusText[4] = "No user is logged in.";
+ statusText[5] = "A shutdown of the client has been triggered.";
+ statusText[6] = "The shutdown command has been sent.";
+ statusText[7] = "The ping after shutdown has been started.";
+ statusText[8] = "Doing ping after shutdown again and again, until client is not alive or "
+ + waitTime / 60 + " minutes has been elapsed";
+ statusText[9] = "A user is logged in.";
+ statusText[10] = "The check if the user is working has been started.";
+ 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);
}
- this.finished = false;
- this.error = false;
- this.statusText = new String[14];
- this.statusText[0] = "The shutdown process of the client has been started.";
- this.statusText[1] = "The ping has been started.";
- this.statusText[2] = "The client is alive.";
- this.statusText[3] = "The check if a user is logged in has been started.";
- this.statusText[4] = "No user is logged in.";
- this.statusText[5] = "A shutdown of the client has been triggered.";
- this.statusText[6] = "The shutdown command has been sent.";
- this.statusText[7] = "The ping after shutdown has been started.";
- this.statusText[8] = "Doing ping after shutdown again and again, until client is not alive or two minutes has been elapsed";
- this.statusText[9] = "A user is logged in.";
- this.statusText[10] = "The check if the user is working has been started.";
- this.statusText[11] = "The user is working.";
- this.statusText[12] = "Shutdown of the client has not been finished, due to an error.";
- this.statusText[13] = "Shutdown of the client has been finished.";
}
public void run() {
@@ -99,6 +98,10 @@ public class Shutdown extends Thread {
}
private void workerLoop() {
+ long beginTime;
+ long timeTaken;
+ long timeLeft;
+ final long updatePeriod = 1000000000L / updateRate; // nanoseconds;
Boolean run = true;
while (run) {
try {
@@ -113,13 +116,16 @@ public class Shutdown extends Thread {
e.printStackTrace();
}
}
- this.finished = true;
+ finished = true;
+ if (error) {
+ System.out.println("Shutdown of " + eventName + " failed");
+ } else {
+ System.out.println("Shutdown of " + eventName + " finished");
+ }
}
private Boolean update() throws IllegalStateException, IOException,
InterruptedException, ExecutionException {
- Boolean allFinished = false;
-
for (HashMap<String, String> client : clients) {
String ipAddress = client.get("ip");
int clientID = Integer.parseInt(client.get("id"));
@@ -166,7 +172,7 @@ public class Shutdown extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot send the ping message.");
- this.errors
+ errors
.put(clientID,
"Sending the ping message has been failed.");
// sending the ping message has been failed
@@ -226,7 +232,7 @@ public class Shutdown extends Thread {
System.out
.println(ipAddress
+ " Cannot check if a user is logged in.");
- this.errors
+ errors
.put(clientID,
"The check if a user is logged in has been failed.");
/*
@@ -269,7 +275,7 @@ public class Shutdown extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot send shutdown command");
- this.errors
+ errors
.put(clientID,
"Sending the shutdown command has been failed.");
/*
@@ -304,8 +310,7 @@ public class Shutdown extends Thread {
Date currentDate = new Date();
Long currentTimestamp = currentDate.getTime();
// wait 2 min until shutdown
- Long expectedTimestamp = this.pingShutdownTime
- .get(clientID)
+ Long expectedTimestamp = pingShutdownTime.get(clientID)
+ waitTime;
if (expectedTimestamp >= currentTimestamp) {
GearmanJobStatus jobStatus = gearmanClient
@@ -321,16 +326,15 @@ public class Shutdown extends Thread {
String alive = resultObj.get("alive")
.toString();
if (alive.equals("false")) {
- System.out
- .println(ipAddress
- + " is not alive after shutdown");
+ System.out.println(ipAddress
+ + " is not alive anymore");
// not alive, go in successState
status.put(clientID, 13);
pingShutdownJobs.remove(clientID);
} else if (alive.equals("true")) {
System.out
.println(ipAddress
- + " is still alive after shutdown");
+ + " is still alive after shutdown command");
// still alive, ping again
status.put(clientID, 7);
}
@@ -338,7 +342,7 @@ public class Shutdown extends Thread {
System.out
.println(ipAddress
+ " Cannot send the ping after shutdown message.");
- this.errors
+ errors
.put(clientID,
"Sending the ping after shutdown message has been failed.");
/*
@@ -353,7 +357,7 @@ public class Shutdown extends Thread {
} else {
System.out.println(ipAddress
+ " is alive after shutdown");
- this.errors.put(clientID,
+ errors.put(clientID,
"Client is still alive after shutdown.");
// still alive, go in errorState
status.put(clientID, 12);
@@ -414,7 +418,7 @@ public class Shutdown extends Thread {
System.out
.println(ipAddress
+ " Cannot check if user is working.");
- this.errors
+ errors
.put(clientID,
"The check if a user is working has been failed.");
/*
@@ -427,7 +431,7 @@ public class Shutdown extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot check if user is working.");
- this.errors
+ errors
.put(clientID,
"The check if a user is working has been failed.");
/*
@@ -444,29 +448,38 @@ public class Shutdown extends Thread {
break;
case 11:
- System.out.println("User has worked");
- this.errors.put(clientID, "The user has worked.");
- // user has worked, go in errorState
+ System.out.println("User has been working");
+ errors.put(clientID, "The user has been working.");
+ // user has been working, go in errorState
status.put(clientID, 12);
break;
case 12:
- System.out.println(ipAddress + " Shutdown failed"); // errorState
+ if (!finishedClients.get(clientID)) {
+ System.out.println(ipAddress + " shutdown failed"); // errorState
+ finishedClients.put(clientID, true);
+ error = true;
+ }
break;
case 13:
- System.out.println(ipAddress + " Shutdown finished"); // successState
+ if (!finishedClients.get(clientID)) {
+ System.out.println(ipAddress + " shutdown finished"); // successState
+ finishedClients.put(clientID, true);
+ }
break;
}
- if (clientStatus == 12) {
- allFinished = true;
- } else if (clientStatus == 13) {
+ }
+
+ boolean allFinished = false;
+ for (HashMap<String, String> client : clients) {
+ int clientID = Integer.parseInt(client.get("id"));
+ if (finishedClients.get(clientID)) {
allFinished = true;
- this.error = true;
} else {
allFinished = false;
}
@@ -551,13 +564,13 @@ public class Shutdown extends Thread {
public String getStatusText(HashMap<String, String> client) {
int clientID = Integer.parseInt(client.get("id"));
- int clientStatus = this.status.get(clientID);
- return this.statusText[clientStatus];
+ int clientStatus = status.get(clientID);
+ return statusText[clientStatus];
}
public String getError(HashMap<String, String> client) {
int clientID = Integer.parseInt(client.get("id"));
- String clientError = this.errors.get(clientID);
+ String clientError = errors.get(clientID);
return clientError;
}
@@ -572,4 +585,8 @@ public class Shutdown extends Thread {
public Vector<HashMap<String, String>> getClients() {
return clients;
}
+
+ public String getEventName() {
+ return eventName;
+ }
} \ No newline at end of file
diff --git a/gearman/controllerWorker/ControllerWorker/ShutdownWorker.java b/gearman/controllerWorker/ControllerWorker/ShutdownWorker.java
index 5bbc165..2eea21b 100644
--- a/gearman/controllerWorker/ControllerWorker/ShutdownWorker.java
+++ b/gearman/controllerWorker/ControllerWorker/ShutdownWorker.java
@@ -24,8 +24,10 @@ public class ShutdownWorker extends AbstractGearmanFunction {
Vector<HashMap<String, String>> clients = new Vector<HashMap<String, String>>();
JSONObject jsonObject = (JSONObject) JSONValue.parse(data);
String event = jsonObject.get("eventName").toString();
- String host = jsonObject.get("host").toString();
- int port = Integer.parseInt(jsonObject.get("port").toString());
+ String gearmanServerHost = jsonObject.get("gearmanServerHost")
+ .toString();
+ int gearmanServerPort = Integer.parseInt(jsonObject.get(
+ "gearmanServerPort").toString());
int updateRate = Integer.parseInt(jsonObject.get("updateRate")
.toString());
long waitTime = Long.parseLong(jsonObject.get("waitTime").toString());
@@ -53,11 +55,11 @@ public class ShutdownWorker extends AbstractGearmanFunction {
psBlacklist.add(blackEntry.toString());
}
- Shutdown shutdown = new Shutdown(host, port, clients, updateRate,
- waitTime, psWhitelist, psBlacklist);
+ Shutdown shutdown = new Shutdown(event, clients, updateRate, waitTime,
+ psWhitelist, psBlacklist, gearmanServerHost, gearmanServerPort);
StatusWorker.SHUTDOWNTHREADS.put(event, shutdown);
shutdown.start();
- System.out.println("Shutdown started");
+ System.out.println("Shutdown of " + event + " started");
String res = "Shutdown started";
byte[] warnings = new byte[0];