Commit 088131dc authored by aninhacostaribeiro's avatar aninhacostaribeiro
Browse files

Started to implement OpenNebula Plugin

parent e9a49dc6
...@@ -79,6 +79,31 @@ ...@@ -79,6 +79,31 @@
<artifactId>openstack4j</artifactId> <artifactId>openstack4j</artifactId>
<version>2.0.2</version> <version>2.0.2</version>
</dependency> </dependency>
<dependency>
<groupId>org.opennebula</groupId>
<artifactId>client</artifactId>
<version>4.8</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0-alpha4</version>
</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-client</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-common</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.util</groupId>
<artifactId>ws-commons-util</artifactId>
<version>1.0.2</version>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
......
...@@ -19,7 +19,7 @@ public class DefaultGreenStrategy implements GreenStrategy { ...@@ -19,7 +19,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
private static final Logger LOGGER = Logger private static final Logger LOGGER = Logger
.getLogger(DefaultGreenStrategy.class); .getLogger(DefaultGreenStrategy.class);
private CloudInfoPlugin openStackPlugin; private CloudInfoPlugin cloudInfoPlugin;
private List<Host> hostsAwake = new LinkedList<Host>(); private List<Host> hostsAwake = new LinkedList<Host>();
/* /*
* The List hosts in grace period is used to keep those hosts which are not * The List hosts in grace period is used to keep those hosts which are not
...@@ -50,7 +50,7 @@ public class DefaultGreenStrategy implements GreenStrategy { ...@@ -50,7 +50,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
.newScheduledThreadPool(1); .newScheduledThreadPool(1);
public DefaultGreenStrategy(Properties prop) { public DefaultGreenStrategy(Properties prop) {
this.openStackPlugin = new OpenStackInfoPlugin(prop this.cloudInfoPlugin = new OpenStackInfoPlugin(prop
.getProperty("openstack.endpoint").toString(), prop .getProperty("openstack.endpoint").toString(), prop
.getProperty("openstack.username").toString(), prop .getProperty("openstack.username").toString(), prop
.get("openstack.password").toString(), prop .get("openstack.password").toString(), prop
...@@ -74,7 +74,7 @@ public class DefaultGreenStrategy implements GreenStrategy { ...@@ -74,7 +74,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
*/ */
protected DefaultGreenStrategy(CloudInfoPlugin openStackPlugin, protected DefaultGreenStrategy(CloudInfoPlugin openStackPlugin,
long graceTime) { long graceTime) {
this.openStackPlugin = openStackPlugin; this.cloudInfoPlugin = openStackPlugin;
this.graceTime = graceTime; this.graceTime = graceTime;
} }
...@@ -121,7 +121,7 @@ public class DefaultGreenStrategy implements GreenStrategy { ...@@ -121,7 +121,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
LOGGER.info("Updating host info at the local cloud..."); LOGGER.info("Updating host info at the local cloud...");
List<? extends Host> cloudInfo = this.openStackPlugin.getHostInformation(); List<? extends Host> cloudInfo = this.cloudInfoPlugin.getHostInformation();
/* /*
* Solution for not loosing data when it is updated * Solution for not loosing data when it is updated
...@@ -132,8 +132,8 @@ public class DefaultGreenStrategy implements GreenStrategy { ...@@ -132,8 +132,8 @@ public class DefaultGreenStrategy implements GreenStrategy {
host.setAvailableCPU(hostCloudInfo.getAvailableCPU()); host.setAvailableCPU(hostCloudInfo.getAvailableCPU());
host.setAvailableRAM(hostCloudInfo.getAvailableRAM()); host.setAvailableRAM(hostCloudInfo.getAvailableRAM());
host.setRunningVM(hostCloudInfo.getRunningVM()); host.setRunningVM(hostCloudInfo.getRunningVM());
host.setNovaRunning(hostCloudInfo.isNovaRunning()); host.setNovaRunning(hostCloudInfo.isComputeComponentRunning());
host.setNovaEnable(hostCloudInfo.isNovaEnable()); host.setEnabled(hostCloudInfo.isEnabled());
host.setCloudUpdatedTime(dateWrapper.getTime()); host.setCloudUpdatedTime(dateWrapper.getTime());
} }
} }
...@@ -167,7 +167,7 @@ public class DefaultGreenStrategy implements GreenStrategy { ...@@ -167,7 +167,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
LOGGER.info("Will send idle hosts to bed. Hosts' status: " LOGGER.info("Will send idle hosts to bed. Hosts' status: "
+ this.hostsAwake); + this.hostsAwake);
for (Host host : this.hostsAwake) { for (Host host : this.hostsAwake) {
if (host.isNovaEnable() && host.isNovaRunning() if (host.isEnabled() && host.isComputeComponentRunning()
&& (host.getRunningVM() == 0)) { && (host.getRunningVM() == 0)) {
if (!this.getHostsInGracePeriod().contains(host)) { if (!this.getHostsInGracePeriod().contains(host)) {
host.setNappingSince(this.dateWrapper.getTime()); host.setNappingSince(this.dateWrapper.getTime());
...@@ -240,5 +240,4 @@ public class DefaultGreenStrategy implements GreenStrategy { ...@@ -240,5 +240,4 @@ public class DefaultGreenStrategy implements GreenStrategy {
executorService.scheduleWithFixedDelay(this.runnable, 0, threadTime, TimeUnit.SECONDS); executorService.scheduleWithFixedDelay(this.runnable, 0, threadTime, TimeUnit.SECONDS);
} }
} }
...@@ -6,8 +6,8 @@ public class Host implements Comparable<Host> { ...@@ -6,8 +6,8 @@ public class Host implements Comparable<Host> {
// Cloud related attributes // Cloud related attributes
private int runningVM; private int runningVM;
private boolean novaRunning; private boolean computeComponentRunning;
private boolean novaEnable; private boolean enabled;
private long cloudUpdatedTime; private long cloudUpdatedTime;
private int availableCPU; private int availableCPU;
private int availableRAM; private int availableRAM;
...@@ -19,13 +19,13 @@ public class Host implements Comparable<Host> { ...@@ -19,13 +19,13 @@ public class Host implements Comparable<Host> {
private long lastSeen = 0; private long lastSeen = 0;
private long nappingSince = 0; private long nappingSince = 0;
public Host(String name, int runningVM, boolean novaRunning, public Host(String name, int runningVM, boolean computeComponentRunning,
boolean novaEnable, long updateTime, int availableCPU, boolean enabled, long updateTime, int availableCPU,
int availableRAM) { int availableRAM) {
this.name = name; this.name = name;
this.runningVM = runningVM; this.runningVM = runningVM;
this.novaRunning = novaRunning; this.computeComponentRunning = computeComponentRunning;
this.novaEnable = novaEnable; this.enabled = enabled;
this.cloudUpdatedTime = updateTime; this.cloudUpdatedTime = updateTime;
this.availableCPU = availableCPU; this.availableCPU = availableCPU;
this.availableRAM = availableRAM; this.availableRAM = availableRAM;
...@@ -55,16 +55,16 @@ public class Host implements Comparable<Host> { ...@@ -55,16 +55,16 @@ public class Host implements Comparable<Host> {
return cloudUpdatedTime; return cloudUpdatedTime;
} }
public boolean isNovaEnable() { public boolean isEnabled() {
return novaEnable; return enabled;
} }
public void setNovaEnable(boolean novaEnable) { public void setEnabled(boolean novaEnable) {
this.novaEnable = novaEnable; this.enabled = novaEnable;
} }
public boolean isNovaRunning() { public boolean isComputeComponentRunning() {
return novaRunning; return computeComponentRunning;
} }
public void setAvailableCPU(int availableCPU) { public void setAvailableCPU(int availableCPU) {
...@@ -76,7 +76,7 @@ public class Host implements Comparable<Host> { ...@@ -76,7 +76,7 @@ public class Host implements Comparable<Host> {
} }
public void setNovaRunning(boolean novaRunning) { public void setNovaRunning(boolean novaRunning) {
this.novaRunning = novaRunning; this.computeComponentRunning = novaRunning;
} }
public void setCloudUpdatedTime(long updateTime) { public void setCloudUpdatedTime(long updateTime) {
...@@ -154,7 +154,7 @@ public class Host implements Comparable<Host> { ...@@ -154,7 +154,7 @@ public class Host implements Comparable<Host> {
@Override @Override
public String toString() { public String toString() {
return "Host [name=" + name + ", runningVM=" + runningVM return "Host [name=" + name + ", runningVM=" + runningVM
+ ", novaRunning=" + novaRunning + ", novaEnable=" + novaEnable + ", novaRunning=" + computeComponentRunning + ", novaEnable=" + enabled
+ ", cloudUpdatedTime=" + cloudUpdatedTime + ", availableCPU=" + ", cloudUpdatedTime=" + cloudUpdatedTime + ", availableCPU="
+ availableCPU + ", availableRAM=" + availableRAM + ", ip=" + availableCPU + ", availableRAM=" + availableRAM + ", ip="
+ ip + ", jid=" + jid + ", macAddress=" + macAddress + ip + ", jid=" + jid + ", macAddress=" + macAddress
......
package org.fogbowcloud.green.server.core.plugins.opennebula;
import java.util.LinkedList;
import java.util.List;
import org.apache.log4j.Logger;
import org.fogbowcloud.green.server.core.greenStrategy.DateWrapper;
import org.fogbowcloud.green.server.core.greenStrategy.Host;
import org.fogbowcloud.green.server.core.plugins.CloudInfoPlugin;
import org.opennebula.client.Client;
import org.opennebula.client.ClientConfigurationException;
import org.opennebula.client.host.HostPool;
public class OpenNebulaInfoPlugin implements CloudInfoPlugin {
private String userPasswordTuple;
private String endPoint;
private static final Logger LOGGER = Logger
.getLogger(OpenNebulaInfoPlugin.class);
public OpenNebulaInfoPlugin(String user, String password, String endPoint) {
this.endPoint = endPoint;
this.userPasswordTuple = user + ":" + password;
}
protected Client createOneClient() throws ClientConfigurationException {
return new Client(userPasswordTuple, endPoint);
}
protected Host openNebulaHostToGreenSitterHost(
org.opennebula.client.host.Host openNebulaHost) {
openNebulaHost.info();
String hostName = openNebulaHost.getName();
int runningVM = Integer.parseInt(openNebulaHost
.xpath("HOST_SHARE/RUNNING_VMS"));
boolean computeComponentRunning = true;
boolean enabled;
if (openNebulaHost.state() == 1 || openNebulaHost.state() == 2) {
enabled = true;
} else {
enabled = false;
}
DateWrapper datew = new DateWrapper();
int availableCPU = Integer.parseInt(openNebulaHost
.xpath("HOST_SHARE/FREE_CPU"));
int availableRAM = Integer.parseInt(openNebulaHost
.xpath("HOST_SHARE/FREE_MEM"));
return new Host(hostName, runningVM, computeComponentRunning, enabled,
datew.getTime(), availableCPU, availableRAM);
}
protected HostPool initializeHostPool() {
Client oneClient;
try {
oneClient = createOneClient();
HostPool hostPool = new HostPool(oneClient);
return hostPool;
} catch (ClientConfigurationException e) {
LOGGER.fatal("Authentication failed", e);
}
return null;
}
@Override
public List<? extends Host> getHostInformation() {
List<Host> greenSitterHosts = new LinkedList<Host>();
HostPool hostPool = initializeHostPool();
if (hostPool != null) {
hostPool.info();
for (int i = 0; i < hostPool.getLength(); i++) {
org.opennebula.client.host.Host openNebulaHost = (org.opennebula.client.host.Host) hostPool
.item(i);
greenSitterHosts
.add(openNebulaHostToGreenSitterHost(openNebulaHost));
}
}
return greenSitterHosts;
}
}
\ No newline at end of file
package org.fogbowcloud.green.server.core.plugins.opennebula;
import static org.junit.Assert.*;
import org.junit.Test;
import org.mockito.Mockito;
import org.opennebula.client.host.Host;
public class TestOpenNebulaPlugin {
private Host createONHostMock(String name, String runningVM, int state,
String freeCPU, String freeRAM) {
Host host = Mockito.mock(Host.class);
Mockito.when(host.getName()).thenReturn(name);
Mockito.when(host.xpath("HOST_SHARE/RUNNING_VMS")).thenReturn(runningVM);
Mockito.when(host.state()).thenReturn(state);
Mockito.when(host.xpath("HOST_SHARE/FREE_CPU")).thenReturn(freeCPU);
Mockito.when(host.xpath("HOST_SHARE/FREE_MEM")).thenReturn(freeRAM);
return host;
}
@Test
public void testNoHosts() {
OpenNebulaInfoPlugin onip =
new OpenNebulaInfoPlugin("user", "password", "localhost/");
assertEquals(0, onip.getHostInformation().size());
}
@Test
public void testConvertingHost() {
OpenNebulaInfoPlugin onip =
new OpenNebulaInfoPlugin("user", "password", "localhost/");
Host hostON = createONHostMock("host1", "1", 1, "2", "1024");
org.fogbowcloud.green.server.core.greenStrategy.Host hostGS =
onip.openNebulaHostToGreenSitterHost(hostON);
assertEquals("host1", hostGS.getName());
assertEquals(1, hostGS.getRunningVM());
assertEquals(2, hostGS.getAvailableCPU());
assertEquals(1024, hostGS.getAvailableRAM());
}
@Test
public void testHostsInThePool() {
OpenNebulaInfoPlugin onip =
new OpenNebulaInfoPlugin("user", "password", "localhost/");
Host hostON = createONHostMock("host1", "1", 1, "2", "1024");
org.fogbowcloud.green.server.core.greenStrategy.Host hostGS =
onip.openNebulaHostToGreenSitterHost(hostON);
assertEquals("host1", hostGS.getName());
assertEquals(1, hostGS.getRunningVM());
assertEquals(2, hostGS.getAvailableCPU());
assertEquals(1024, hostGS.getAvailableRAM());
}
}
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