Commit f2f591b8 authored by aninhacostaribeiro's avatar aninhacostaribeiro
Browse files

Fixed bug

parent 8ffdf5a0
......@@ -46,42 +46,45 @@ public class DefaultGreenStrategy implements GreenStrategy {
.getProperty("greenstrategy.gracetime"));
this.lostHostTime = Long.parseLong(greenProperties
.getProperty("greenstrategy.lostAgentTime"));
this.allHosts = this.openStackPlugin.getHostInformation();
}
protected DefaultGreenStrategy(CloudInfoPlugin openStackPlugin,
long graceTime) {
this.openStackPlugin = openStackPlugin;
this.graceTime = graceTime;
this.allHosts = this.openStackPlugin.getHostInformation();
}
protected void setAllHosts() {
List<Host> nowHosts = new LinkedList<Host>();
nowHosts.addAll(this.allHosts);
this.allHosts = this.openStackPlugin.getHostInformation();
/*
* Solution for eliminating hosts that don't send an "I am alive signal"
* but still are in the cloud information
*/
for (Host host : this.allHosts) {
if (!nowHosts.contains(host)) {
this.lostHosts.add(host);
this.allHosts.remove(host);
List<Host> nowHosts = new LinkedList<Host>();
nowHosts.addAll(this.allHosts);
this.allHosts = this.openStackPlugin.getHostInformation();
/*
* Solution for eliminating hosts that don't send an
* "I am alive signal" but still are in the cloud information
*/
for (Host host : this.allHosts) {
if (!nowHosts.contains(host)) {
this.allHosts.remove(host);
if (!this.lostHosts.contains(host)) {
this.lostHosts.add(host);
}
}
}
}
/*
* Solution for not loosing data when it is updated
*/
for (Host host : this.allHosts){
Host fullHost = nowHosts.get(nowHosts.indexOf(host));
host.setIp(fullHost.getIp());
host.setJid(fullHost.getJid());
host.setMacAddress(fullHost.getMacAddress());
host.setNappingSince(fullHost.getNappingSince());
host.setLastSeen(fullHost.getLastSeen());
}
/*
* Solution for not loosing data when it is updated
*/
for (Host host : this.allHosts) {
Host fullHost = nowHosts.get(nowHosts.indexOf(host));
host.setIp(fullHost.getIp());
host.setJid(fullHost.getJid());
host.setMacAddress(fullHost.getMacAddress());
host.setNappingSince(fullHost.getNappingSince());
host.setLastSeen(fullHost.getLastSeen());
}
}
protected void setLostHostTime(long lostHostTime) {
......@@ -106,6 +109,14 @@ public class DefaultGreenStrategy implements GreenStrategy {
public void receiveIamAliveInfo(String hostName, String jid, String ip,
String macAddress) {
for (Host host : this.lostHosts) {
if (this.lostHosts.contains(host)) {
this.lostHosts.remove(host);
this.lostHosts.add(host);
}
}
for (Host host : this.allHosts) {
if (host.getName() == hostName) {
host.setJid(jid);
......
......@@ -12,7 +12,7 @@ public class Host implements Comparable<Host> {
private String ip = "";
private String jid = "";
private String macAddress = "";
private long lastSeen = 500000;
private long lastSeen = 0;
private long nappingSince = 0;
public Host(String name, int runningVM, boolean novaRunning,
......
......@@ -25,6 +25,11 @@ public class TestDefaultGreenStrategy {
Mockito.when(date.getTime()).thenReturn(Time);
return date;
}
@Test
public void testReceivingLostHostsFromCloud(){
}
@Test
public void testOneHostNapping(){
......@@ -72,42 +77,44 @@ public class TestDefaultGreenStrategy {
}
@Test
public void testWakeUp(){
Host mustWake = new Host ("wake", 0, true, true, 1800000, 3, 8);
Host stilSleep = new Host ("stil",0,true, true, 1800000, 3, 2);
Host stilSleep2 = new Host ("stil2",0,true, true, 1800000, 1, 2);
List <Host> hosts = new LinkedList <Host> ();
public void testWakeUp() {
Host mustWake = new Host("wake", 0, true, true, 1800000, 3, 8);
Host stilSleep = new Host("stil", 0, true, true, 1800000, 3, 2);
Host stilSleep2 = new Host("stil2", 0, true, true, 1800000, 1, 2);
List<Host> hosts = new LinkedList<Host>();
hosts.add(mustWake);
hosts.add(stilSleep);
hosts.add(stilSleep2);
Date date = this.createDateMock(3600001);
OpenStackInfoPlugin osip = this.createOpenStackInfoPluginMock(hosts);
DefaultGreenStrategy dgs = new DefaultGreenStrategy(osip, 1800000);
dgs.setDate(date);
ServerCommunicationComponent gscc = Mockito.mock(ServerCommunicationComponent.class);
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());
dgs.setCommunicationComponent(gscc);
dgs.sendIdleHostsToBed();
mustWake.setNappingSince(1800000);
stilSleep.setNappingSince(1800000);
stilSleep2.setNappingSince(1800000);
dgs.sendIdleHostsToBed();
dgs.wakeUpSleepingHost(2, 4);
List <Host> expetedResult = new LinkedList <Host> ();
List<Host> expetedResult = new LinkedList<Host>();
expetedResult.add(stilSleep);
expetedResult.add(stilSleep2);
Assert.assertArrayEquals(expetedResult.toArray(), dgs.getSleepingHosts().toArray());
Assert.assertArrayEquals(expetedResult.toArray(), dgs
.getSleepingHosts().toArray());
}
@Test
public void testNoHostSleeping(){
......
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