Commit 56464432 authored by aninhacostaribeiro's avatar aninhacostaribeiro
Browse files

Merged Host and Agent

parent da6748fd
......@@ -9,4 +9,4 @@ host.macAddress = A1:B2:C3:D4:E5:67
host.name = agent
green.TurnOffCommand = pm-suspend
green.sleepingTime = 1800000
\ No newline at end of file
green.sleepingTime = 300000
\ No newline at end of file
......@@ -12,4 +12,4 @@ openstack.tenant = fogbow-project
greenstrategy.sleeptime = 1800000
greenstrategy.gracetime = 1800000
greenstrategy.lostAgentTime = 1500000
package org.fogbowcloud.green.server.communication;
public class Agent {
private String hostName;
private String ip;
private String jid;
private String macAddress;
public Agent(String hostName, String jid, String ip, String macAddress) {
this.hostName = hostName;
this.jid = jid;
this.ip = ip;
this.macAddress = macAddress;
}
public String getHostName() {
return hostName;
}
public String getIp() {
return ip;
}
public String getJid() {
return jid;
}
public String getMacAdress(){
return macAddress;
}
}
package org.fogbowcloud.green.server.communication;
import java.io.IOException;
import java.util.LinkedList;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.fogbowcloud.green.server.communication.Agent;
import org.fogbowcloud.green.server.core.greenStrategy.GreenStrategy;
import org.jamppa.component.XMPPComponent;
import org.xmpp.packet.IQ;
......@@ -15,7 +13,6 @@ import org.xmpp.packet.IQ.Type;
public class ServerCommunicationComponent extends XMPPComponent {
private GreenStrategy gs;
private LinkedList<Agent> listAgent = new LinkedList<Agent>();
public ServerCommunicationComponent(Properties prop, GreenStrategy gs) {
super(prop.getProperty("xmpp.jid"), prop.getProperty("xmpp.password"),
......@@ -25,12 +22,6 @@ public class ServerCommunicationComponent extends XMPPComponent {
addHandlers();
}
public void setAgentAddress(String hostName, String jid, String ip,
String macAddress) {
Agent agent = new Agent(hostName, jid, ip, macAddress);
listAgent.add(agent);
}
public void wakeUpHost(String macAddress) {
try {
ProcessBuilder pb = new ProcessBuilder("powerwake", macAddress);
......
......@@ -6,7 +6,7 @@ import org.xmpp.packet.IQ;
public class WakeUpRequestHandler extends AbstractQueryHandler {
private static final String NAMESPACE = "org.fogbowcloud.green.WakeUpRequest";
private static final String NAMESPACE = "org.fogbowcqueryloud.green.WakeUpRequest";
private final GreenStrategy gs;
public WakeUpRequestHandler(GreenStrategy gs) {
......@@ -17,7 +17,6 @@ public class WakeUpRequestHandler extends AbstractQueryHandler {
@Override
public IQ handle(IQ query) {
//expected content format: the minimum CPU and the RAM (in GigaBytes) capacity required (eg. "1 8")
int minCPU = Integer.parseInt(query.getElement().element("query").elementText("cpu"));
int minRAM = Integer.parseInt(query.getElement().element("query").elementText("ram"));
......
......@@ -26,7 +26,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
private long graceTime;
private long sleepingTime;
private ScheduledExecutorService executor = Executors
private ScheduledExecutorService executorSendIdleHostsToBed = Executors
.newScheduledThreadPool(1);
public DefaultGreenStrategy(Properties greenProperties) {
......@@ -78,7 +78,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
* if there is more than a half hour that the host is
* napping than put it in sleeping host list
*/
if (nowTime - host.getUpdateTime() > this.graceTime) {
if (nowTime - host.getClodUpdatedTime() > this.graceTime) {
scc.sendIdleHostToBed(host.getName());
this.getSleepingHosts().add(host);
this.getNappingHosts().remove(host);
......@@ -95,7 +95,13 @@ public class DefaultGreenStrategy implements GreenStrategy {
}
public void setAgentAddress(String hostName, String jid, String ip, String macAddress) {
this.scc.setAgentAddress(hostName, jid, ip, macAddress);
for (Host host : this.allHosts){
if (host.getName() == hostName){
host.setJid(jid);
host.setIp(ip);
host.setMacAddress(macAddress);
}
}
}
public void wakeUpSleepingHost(int minCPU, int minRAM) {
......@@ -114,7 +120,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
}
public void start() {
executor.scheduleWithFixedDelay(new Runnable() {
executorSendIdleHostsToBed.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
sendIdleHostsToBed();
......
......@@ -6,9 +6,13 @@ public class Host implements Comparable<Host> {
private int runningVM;
private boolean novaRunning;
private boolean novaEnable;
private long updateTime;
private long cloudUpdatedTime;
private int availableCPU;
private int availableRAM;
private String ip;
private String jid;
private String macAddress;
private long lastSeen;
public Host(String name, int runningVM, boolean novaRunning,
boolean novaEnable, long updateTime, int availableCPU,
......@@ -17,7 +21,7 @@ public class Host implements Comparable<Host> {
this.runningVM = runningVM;
this.novaRunning = novaRunning;
this.novaEnable = novaEnable;
this.updateTime = updateTime;
this.cloudUpdatedTime = updateTime;
this.availableCPU = availableCPU;
this.availableRAM = availableRAM;
}
......@@ -38,8 +42,8 @@ public class Host implements Comparable<Host> {
return runningVM;
}
public long getUpdateTime() {
return updateTime;
public long getClodUpdatedTime() {
return cloudUpdatedTime;
}
public boolean isNovaEnable() {
......@@ -54,10 +58,53 @@ public class Host implements Comparable<Host> {
this.availableCPU = availableCPU;
}
public void setRunningVM(int runningVM) {
this.runningVM = runningVM;
}
public void setNovaRunning(boolean novaRunning) {
this.novaRunning = novaRunning;
}
public void setCloudUpdatedTime(long updateTime) {
this.cloudUpdatedTime = updateTime;
}
public void setAvailableRAM(int availableRAM) {
this.availableRAM = availableRAM;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getJid() {
return jid;
}
public void setJid(String jid) {
this.jid = jid;
}
public String getMacAddress() {
return macAddress;
}
public void setMacAddress(String macAddress) {
this.macAddress = macAddress;
}
public long getLastSeen() {
return lastSeen;
}
public void setLastSeen(long lastSeen) {
this.lastSeen = lastSeen;
}
@Override
public int hashCode() {
final int prime = 31;
......@@ -83,23 +130,27 @@ public class Host implements Comparable<Host> {
return true;
}
@Override
public String toString() {
return "Host [name=" + name + ", runningVM=" + runningVM
+ ", novaRunning=" + novaRunning + ", novaEnable=" + novaEnable
+ ", updateTime=" + updateTime + ", availableCPU="
+ availableCPU + ", availableRAM=" + availableRAM + "]";
+ ", cloudUpdatedTime=" + cloudUpdatedTime + ", availableCPU="
+ availableCPU + ", availableRAM=" + availableRAM + ", ip="
+ ip + ", jid=" + jid + ", macAddress=" + macAddress
+ ", lastSeen=" + lastSeen + "]";
}
@Override
public int compareTo(Host host) {
if (this.availableCPU != host.availableCPU) {
return host.availableCPU - this.availableCPU;
return host.availableCPU - this.availableCPU;
}
/*
* if the hosts have the same CPU capacities, wake the
* one with the biggest RAM
* */
* if the hosts have the same CPU capacities, wake the one with the
* biggest RAM
*/
return host.availableRAM - this.availableRAM;
}
}
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