Commit 18e808f1 authored by aninhacostaribeiro's avatar aninhacostaribeiro
Browse files

Implemented wakeUpHost

parent 7e32c79c
package org.fogbowcloud.green.agent.core;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class TurnOff {
private static String executeCommand(String command) {
StringBuilder sb = new StringBuilder();
String[] commands = new String[] { "/bin/sh", "-c", command };
try {
Process proc = new ProcessBuilder(commands).start();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(
proc.getErrorStream()));
String s = null;
while ((s = stdInput.readLine()) != null) {
sb.append(s);
sb.append("\n");
}
while ((s = stdError.readLine()) != null) {
sb.append(s);
sb.append("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
public void hibernate() throws RuntimeException, IOException {
public void hibernate(){
String hibernateCommand="";
String operatingSystem = System.getProperty("os.name");
if ("Linux".equals(operatingSystem)
|| "Mac OS X".equals(operatingSystem)) {
hibernateCommand = "/usr/bin/dbus-send --system --print-reply --dest='org.freedesktop.UPower' "
+ "/org/freedesktop/UPower org.freedesktop.UPower.Suspend";
hibernateCommand = "pm-hibernate";
}
ProcessBuilder pb =
new ProcessBuilder("sudo","-S", hibernateCommand);
try {
pb.start();
} catch (IOException e) {
System.out.println("It was not possible to turn down");
}
}
......
package org.fogbowcloud.green.server.communication;
import java.io.IOException;
import java.util.LinkedList;
import java.util.Properties;
......@@ -24,12 +25,19 @@ public class GreenSitterCommunicationComponent extends XMPPComponent {
listAgent.add(agent);
}
public void sendHostToBed(String host){
public void wakeUpHost(String macAddress){
ProcessBuilder pb =
new ProcessBuilder("powerwake", macAddress);
try {
pb.start();
} catch (IOException e) {
System.out.println("It was not possible to wake "+macAddress);
}
}
public void wakeUpHost(String host){
public void sendIdleHostToBed(String host){
}
private void addHandlers() {
......
......@@ -79,7 +79,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
* napping than put it in sleeping host list
*/
if (nowTime - host.getUpdateTime() > this.graceTime) {
gscc.sendHostToBed(host.getName());
gscc.sendIdleHostToBed(host.getName());
this.getSleepingHosts().add(host);
this.getNappingHosts().remove(host);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment