summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/controllers/GearmanController.php51
-rw-r--r--application/views/scripts/gearman/index.phtml5
-rw-r--r--gearman/controllerWorker/ControllerWorker/Boot.java12
-rw-r--r--gearman/controllerWorker/ControllerWorker/Shutdown.java106
4 files changed, 162 insertions, 12 deletions
diff --git a/application/controllers/GearmanController.php b/application/controllers/GearmanController.php
index 97b3c35..5b4c054 100644
--- a/application/controllers/GearmanController.php
+++ b/application/controllers/GearmanController.php
@@ -128,4 +128,55 @@ class GearmanController extends Zend_Controller_Action
}
$this->view->result = $result;
}
+
+ public function shutdownAction() {
+ $eventName = 'test';
+ $updateRate = 1;
+ $clients = array(
+ 'eventName' => $eventName,
+ 'updateRate' => $updateRate,
+ 'clients' => array(
+ 0 => array('id' => '1', 'ip' =>'132.230.4.24', 'mac' =>'00:13:72:C7:FD:A1'), //PC im HiWi-Raum rechts auf dem Tisch
+/* 1 => array('id' => '2', 'ip' =>'132.230.4.2', 'mac' =>''),
+ 2 => array('id' => '3', 'ip' =>'132.230.4.3', 'mac' =>''),
+ 3 => array('id' => '4', 'ip' =>'132.230.4.4', 'mac' =>''),
+ 4 => array('id' => '5', 'ip' =>'132.230.4.5', 'mac' =>''),
+ 5 => array('id' => '6', 'ip' =>'132.230.4.6', 'mac' =>''),
+ 6 => array('id' => '7', 'ip' =>'132.230.4.7', 'mac' =>''),
+ 7 => array('id' => '8', 'ip' =>'132.230.4.8', 'mac' =>''),
+ 8 => array('id' => '9', 'ip' =>'132.230.4.9', 'mac' =>''),
+ 9 => array('id' => '10', 'ip' =>'132.230.4.10', 'mac' =>''),
+ 10 => array('id' => '11', 'ip' =>'132.230.4.11', 'mac' =>''),
+ 11 => array('id' => '12', 'ip' =>'132.230.4.12', 'mac' =>''),
+ 12 => array('id' => '13', 'ip' =>'132.230.4.13', 'mac' =>''),
+ 13 => array('id' => '14', 'ip' =>'132.230.4.14', 'mac' =>''),
+ 14 => array('id' => '15', 'ip' =>'132.230.4.15', 'mac' =>''),
+ 15 => array('id' => '16', 'ip' =>'132.230.4.16', 'mac' =>''),
+ 16 => array('id' => '17', 'ip' =>'132.230.4.17', 'mac' =>''),
+ 17 => array('id' => '18', 'ip' =>'132.230.4.18', 'mac' =>''),
+ 18 => array('id' => '19', 'ip' =>'132.230.4.19', 'mac' =>''),
+ 19 => array('id' => '20', 'ip' =>'132.230.4.20', 'mac' =>''),
+ 20 => array('id' => '21', 'ip' =>'132.230.4.21', 'mac' =>''),
+ 21 => array('id' => '22', 'ip' =>'132.230.4.22', 'mac' =>''),
+ 22 => array('id' => '23', 'ip' =>'132.230.4.23', 'mac' =>''),
+ 23 => array('id' => '24', 'ip' =>'132.230.4.24', 'mac' =>''),
+ 24 => array('id' => '25', 'ip' =>'132.230.4.25', 'mac' =>''),
+ 25 => array('id' => '26', 'ip' =>'132.230.4.26', 'mac' =>''),
+ 26 => array('id' => '27', 'ip' =>'132.230.4.27', 'mac' =>''),
+ 27 => array('id' => '28', 'ip' =>'132.230.4.28', 'mac' =>''),
+ 28 => array('id' => '29', 'ip' =>'132.230.4.29', 'mac' =>''),
+ 29 => array('id' => '30', 'ip' =>'132.230.4.30', 'mac' =>''),*/
+ ),
+ );
+
+ $ipString = json_encode($clients);
+ $result = $this->gearmanClient->do("shutdown", $ipString, 'shutdown' . $eventName);
+ if (! $this->gearmanClient->runTasks())
+ {
+ echo "ERROR " . $gmc->error() . "\n";
+ exit;
+ }
+ $this->view->result = $result;
+ }
+
}
diff --git a/application/views/scripts/gearman/index.phtml b/application/views/scripts/gearman/index.phtml
index 89c289e..211372d 100644
--- a/application/views/scripts/gearman/index.phtml
+++ b/application/views/scripts/gearman/index.phtml
@@ -7,4 +7,9 @@
<?php echo $this->formButton('boot', 'BootTest', array(
'onclick' => 'self.location="/gearman/boot"'
))
+?>
+</br>
+<?php echo $this->formButton('shutdown', 'ShutdownTest', array(
+ 'onclick' => 'self.location="/gearman/shutdown"'
+ ))
?> \ No newline at end of file
diff --git a/gearman/controllerWorker/ControllerWorker/Boot.java b/gearman/controllerWorker/ControllerWorker/Boot.java
index 5259ed1..cef8193 100644
--- a/gearman/controllerWorker/ControllerWorker/Boot.java
+++ b/gearman/controllerWorker/ControllerWorker/Boot.java
@@ -184,7 +184,6 @@ public class Boot extends Thread {
case 7:
GearmanJob pingJobWoL = pingWoLJobs.get(clientID);
-
if (pingJobWoL != null) {
Date currentDate = new Date();
Long currentTimestamp = currentDate.getTime();
@@ -204,7 +203,7 @@ public class Boot extends Thread {
if (alive.equals("true")) {
System.out.println(ipAddress
+ " is alive after WoL");
- status.put(clientID, 9); // alive
+ status.put(clientID, 9); // alive, go in successState
pingWoLJobs.remove(clientID);
} else {
System.out.println("ping again "
@@ -216,18 +215,21 @@ public class Boot extends Thread {
} else {
System.out.println(ipAddress
+ " is not alive after WoL");
- status.put(clientID, 8); // go in errorState
+ status.put(clientID, 8); // not alive, go in errorState
pingWoLJobs.remove(clientID);
}
}
+
break;
case 8:
- System.out.println("WoL Error"); // errorState
+ System.out.println("WoL failed after 2min"); // errorState
+
break;
case 9:
- System.out.println("WoL Success"); // successState
+ System.out.println("WoL successful"); // successState
+
break;
}
diff --git a/gearman/controllerWorker/ControllerWorker/Shutdown.java b/gearman/controllerWorker/ControllerWorker/Shutdown.java
index 6cb8645..738ea68 100644
--- a/gearman/controllerWorker/ControllerWorker/Shutdown.java
+++ b/gearman/controllerWorker/ControllerWorker/Shutdown.java
@@ -29,7 +29,8 @@ public class Shutdown extends Thread {
private final long updatePeriod;
private HashMap<Integer, GearmanJob> pingJobs;
- private HashMap<Integer, GearmanJob> wolJobs;
+ private HashMap<Integer, GearmanJob> whoJobs;
+ private HashMap<Integer, GearmanJob> shutdownJobs;
private HashMap<Integer, GearmanJob> sshJobs;
private HashMap<Integer, Integer> status;
private HashMap<Integer, Integer> errors;
@@ -42,7 +43,8 @@ public class Shutdown extends Thread {
public Shutdown(String serverAddress, int port,
Vector<HashMap<String, String>> clients, int updateRate) {
this.pingJobs = new HashMap<Integer, GearmanJob>();
- this.wolJobs = new HashMap<Integer, GearmanJob>();
+ this.whoJobs = new HashMap<Integer, GearmanJob>();
+ this.shutdownJobs = new HashMap<Integer, GearmanJob>();
this.sshJobs = new HashMap<Integer, GearmanJob>();
this.status = new HashMap<Integer, Integer>();
this.errors = new HashMap<Integer, Integer>();
@@ -81,7 +83,7 @@ public class Shutdown extends Thread {
}
}
this.finished = true;
- System.out.println("Booting finished");
+ System.out.println("Shutdown finished");
}
private Boolean update() throws IllegalStateException, IOException,
@@ -95,6 +97,64 @@ public class Shutdown extends Thread {
int clientStatus = status.get(clientID);
switch (clientStatus) {
+
+ case 0:
+ ping(client);
+
+ break;
+
+ case 1:
+ GearmanJob pingJob = pingJobs.get(clientID);
+
+ if (pingJob != null) {
+ GearmanJobStatus jobStatus = gearmanClient
+ .getJobStatus(pingJob);
+
+ if (!jobStatus.isKnown() && pingJob.isDone()) {
+ GearmanJobResult pingJobRes = pingJob.get();
+ String result = ByteUtils.fromUTF8Bytes(pingJobRes
+ .getResults());
+
+ if (result != "") {
+ JSONObject resultObj = (JSONObject) JSONValue
+ .parse(result);
+ String alive = resultObj.get("alive").toString();
+
+ if (alive.equals("true")) {
+ System.out.println(ipAddress + " alive");
+ status.put(clientID, 3); // alive, check Users
+ pingJobs.remove(clientID);
+ } else {
+ System.out.println(ipAddress + " not alive");
+ status.put(clientID, 5); // not alive, not needed, go in successState
+ pingJobs.remove(clientID);
+ }
+ }
+ }
+ }
+
+ break;
+
+ case 2:
+ woh(client);
+
+ break;
+
+ case 3:
+ shutdown(client);
+
+ break;
+
+ case 4:
+ System.out.println("Shutdown failed after 2min"); // errorState
+
+ break;
+
+ case 5:
+ System.out.println("Shutdown successful"); // successState
+
+ break;
+
}
if (clientStatus == 20) {
allFinished = true;
@@ -126,6 +186,34 @@ public class Shutdown extends Thread {
System.out.println("ping " + ipAddress);
}
+
+ private void woh(HashMap<String, String> client) {
+ String ipAddress = client.get("ip");
+ int clientID = Integer.parseInt(client.get("id"));
+
+ GearmanJob job = GearmanJobImpl.createJob("who", ipAddress.getBytes(),
+ "who" + clientID);
+ gearmanClient.submit(job);
+
+ status.put(clientID, 1); // who started
+ pingJobs.put(clientID, job);
+
+ System.out.println("who " + ipAddress);
+ }
+
+ private void shutdown(HashMap<String, String> client) {
+ String ipAddress = client.get("ip");
+ int clientID = Integer.parseInt(client.get("id"));
+
+ GearmanJob job = GearmanJobImpl.createJob("shutdown", ipAddress.getBytes(),
+ "shutdown" + clientID);
+ gearmanClient.submit(job);
+
+ status.put(clientID, 5); // ping started
+ pingJobs.put(clientID, job);
+
+ System.out.println("shutdown " + ipAddress);
+ }
private void ssh(HashMap<String, String> client) {
String ipAddress = client.get("ip");
@@ -157,13 +245,17 @@ public class Shutdown extends Thread {
return pingJobs;
}
- public HashMap<Integer, GearmanJob> getWolJobs() {
- return wolJobs;
- }
-
public HashMap<Integer, GearmanJob> getSshJobs() {
return sshJobs;
}
+
+ public HashMap<Integer, GearmanJob> getWhoJobs() {
+ return whoJobs;
+ }
+
+ public HashMap<Integer, GearmanJob> getShutdownJobs() {
+ return shutdownJobs;
+ }
public HashMap<Integer, Integer> getStatus() {
return status;