Commit 80849d22 authored by aninhacostaribeiro's avatar aninhacostaribeiro
Browse files

Now wakeUpHosts throws exceptions.

parent e7a0d1de
......@@ -3,7 +3,6 @@ package org.fogbowcloud.green.server.communication;
import java.io.IOException;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.fogbowcloud.green.server.core.greenStrategy.GreenStrategy;
import org.jamppa.component.XMPPComponent;
import org.xmpp.packet.IQ;
......@@ -11,8 +10,6 @@ import org.xmpp.packet.IQ.Type;
public class ServerCommunicationComponent extends XMPPComponent {
private static final Logger LOGGER = Logger
.getLogger(ServerCommunicationComponent.class);
private GreenStrategy gs;
public ServerCommunicationComponent(Properties prop, GreenStrategy gs) {
......@@ -23,13 +20,9 @@ public class ServerCommunicationComponent extends XMPPComponent {
addHandlers();
}
public void wakeUpHost(String macAddress) {
try {
ProcessBuilder pb = new ProcessBuilder("powerwake", macAddress);
pb.start();
} catch (IOException e) {
LOGGER.warn("It was not possible to wake " + macAddress + e);
}
public void wakeUpHost(String macAddress) throws IOException {
ProcessBuilder pb = new ProcessBuilder("powerwake", macAddress);
pb.start();
}
public void sendIdleHostToBed(String hostJID) {
......
package org.fogbowcloud.green.server.core.greenStrategy;
import java.io.IOException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
......@@ -219,22 +220,30 @@ public class DefaultGreenStrategy implements GreenStrategy {
public void wakeUpSleepingHost(int minCPU, int minRAM) {
Host host = this.sleepingHosts.peek();
try {
if (host.getAvailableCPU() < minCPU) {
LOGGER.info("Tried to wake hosts but no hosts were found");
return;
}
if (host.getAvailableRAM() >= minRAM) {
this.scc.wakeUpHost(host.getName());
this.sleepingHosts.remove(host);
LOGGER.info("Waked " + host);
}
if (host.getAvailableCPU() < minCPU) {
return;
}
if (host.getAvailableRAM() >= minRAM) {
this.scc.wakeUpHost(host.getName());
this.sleepingHosts.remove(host);
} catch (IOException e) {
LOGGER.warn("It was not possible to wake " + host +
"it may be lost or there is a network problem" + e);
}
}
public void start() {
executorVerifyLastTimeSeen.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
checkHostsLastSeen();
LOGGER.info("Checked when hosts were seen");
LOGGER.info("Checked when hosts were seen"
+ " Lost Hosts now");
}
}, 0, lostHostTime, TimeUnit.MILLISECONDS);
......@@ -242,7 +251,8 @@ public class DefaultGreenStrategy implements GreenStrategy {
@Override
public void run() {
sendIdleHostsToBed();
LOGGER.info("Sent idle hosts to bed");
LOGGER.info("Sent idle hosts to bed: "
+ "Sleeping Hosts now "+sleepingHosts);
}
}, 0, sleepingTime, TimeUnit.MILLISECONDS);
}
......
package org.fogbowcloud.green.server.core.greenStrategy;
import java.io.IOException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
......@@ -109,7 +110,12 @@ public class TestDefaultGreenStrategy {
Date date = this.createDateMock(3600001);
ServerCommunicationComponent gscc = Mockito
.mock(ServerCommunicationComponent.class);
Mockito.doNothing().when(gscc).wakeUpHost(h1.getMacAddress());
try {
Mockito.doNothing().when(gscc).wakeUpHost(h1.getMacAddress());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OpenStackInfoPlugin osip = this.createOpenStackInfoPluginMock(hosts);
DefaultGreenStrategy dgs = new DefaultGreenStrategy(osip, 1800000);
dgs.setDate(date);
......@@ -170,10 +176,15 @@ public class TestDefaultGreenStrategy {
dgs.setDate(date);
ServerCommunicationComponent gscc = Mockito
.mock(ServerCommunicationComponent.class);
Mockito.doNothing().when(gscc).wakeUpHost("wake");
Mockito.doNothing().when(gscc).wakeUpHost(mustWake.getMacAddress());
Mockito.doNothing().when(gscc).wakeUpHost(stilSleep.getMacAddress());
Mockito.doNothing().when(gscc).wakeUpHost(stilSleep2.getMacAddress());
try {
Mockito.doNothing().when(gscc).wakeUpHost("wake");
Mockito.doNothing().when(gscc).wakeUpHost(mustWake.getMacAddress());
Mockito.doNothing().when(gscc).wakeUpHost(stilSleep.getMacAddress());
Mockito.doNothing().when(gscc).wakeUpHost(stilSleep2.getMacAddress());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dgs.setCommunicationComponent(gscc);
dgs.sendIdleHostsToBed();
......@@ -215,7 +226,12 @@ public class TestDefaultGreenStrategy {
Date date = this.createDateMock(3600001);
ServerCommunicationComponent gscc = Mockito
.mock(ServerCommunicationComponent.class);
Mockito.doNothing().when(gscc).wakeUpHost("wake");
try {
Mockito.doNothing().when(gscc).wakeUpHost("wake");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OpenStackInfoPlugin osip = this.createOpenStackInfoPluginMock(hosts);
DefaultGreenStrategy dgs = new DefaultGreenStrategy(osip, 1800000);
......
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