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

Started to implement OpenNebula Plugin

parent e9a49dc6
......@@ -79,6 +79,31 @@
<artifactId>openstack4j</artifactId>
<version>2.0.2</version>
</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>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
......@@ -19,7 +19,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
private static final Logger LOGGER = Logger
.getLogger(DefaultGreenStrategy.class);
private CloudInfoPlugin openStackPlugin;
private CloudInfoPlugin cloudInfoPlugin;
private List<Host> hostsAwake = new LinkedList<Host>();
/*
* The List hosts in grace period is used to keep those hosts which are not
......@@ -50,7 +50,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
.newScheduledThreadPool(1);
public DefaultGreenStrategy(Properties prop) {
this.openStackPlugin = new OpenStackInfoPlugin(prop
this.cloudInfoPlugin = new OpenStackInfoPlugin(prop
.getProperty("openstack.endpoint").toString(), prop
.getProperty("openstack.username").toString(), prop
.get("openstack.password").toString(), prop
......@@ -74,7 +74,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
*/
protected DefaultGreenStrategy(CloudInfoPlugin openStackPlugin,
long graceTime) {
this.openStackPlugin = openStackPlugin;
this.cloudInfoPlugin = openStackPlugin;
this.graceTime = graceTime;
}
......@@ -121,7 +121,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
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
......@@ -132,8 +132,8 @@ public class DefaultGreenStrategy implements GreenStrategy {
host.setAvailableCPU(hostCloudInfo.getAvailableCPU());
host.setAvailableRAM(hostCloudInfo.getAvailableRAM());
host.setRunningVM(hostCloudInfo.getRunningVM());
host.setNovaRunning(hostCloudInfo.isNovaRunning());
host.setNovaEnable(hostCloudInfo.isNovaEnable());
host.setNovaRunning(hostCloudInfo.isComputeComponentRunning());
host.setEnabled(hostCloudInfo.isEnabled());
host.setCloudUpdatedTime(dateWrapper.getTime());
}
}
......@@ -167,7 +167,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
LOGGER.info("Will send idle hosts to bed. Hosts' status: "
+ this.hostsAwake);
for (Host host : this.hostsAwake) {
if (host.isNovaEnable() && host.isNovaRunning()
if (host.isEnabled() && host.isComputeComponentRunning()
&& (host.getRunningVM() == 0)) {
if (!this.getHostsInGracePeriod().contains(host)) {
host.setNappingSince(this.dateWrapper.getTime());
......@@ -240,5 +240,4 @@ public class DefaultGreenStrategy implements GreenStrategy {
executorService.scheduleWithFixedDelay(this.runnable, 0, threadTime, TimeUnit.SECONDS);
}
}
......@@ -6,8 +6,8 @@ public class Host implements Comparable<Host> {
// Cloud related attributes
private int runningVM;
private boolean novaRunning;
private boolean novaEnable;
private boolean computeComponentRunning;
private boolean enabled;
private long cloudUpdatedTime;
private int availableCPU;
private int availableRAM;
......@@ -19,13 +19,13 @@ public class Host implements Comparable<Host> {
private long lastSeen = 0;
private long nappingSince = 0;
public Host(String name, int runningVM, boolean novaRunning,
boolean novaEnable, long updateTime, int availableCPU,
public Host(String name, int runningVM, boolean computeComponentRunning,
boolean enabled, long updateTime, int availableCPU,
int availableRAM) {
this.name = name;
this.runningVM = runningVM;
this.novaRunning = novaRunning;
this.novaEnable = novaEnable;
this.computeComponentRunning = computeComponentRunning;
this.enabled = enabled;
this.cloudUpdatedTime = updateTime;
this.availableCPU = availableCPU;
this.availableRAM = availableRAM;
......@@ -55,16 +55,16 @@ public class Host implements Comparable<Host> {
return cloudUpdatedTime;
}
public boolean isNovaEnable() {
return novaEnable;
public boolean isEnabled() {
return enabled;
}
public void setNovaEnable(boolean novaEnable) {
this.novaEnable = novaEnable;
public void setEnabled(boolean novaEnable) {
this.enabled = novaEnable;
}
public boolean isNovaRunning() {
return novaRunning;
public boolean isComputeComponentRunning() {
return computeComponentRunning;
}
public void setAvailableCPU(int availableCPU) {
......@@ -76,7 +76,7 @@ public class Host implements Comparable<Host> {
}
public void setNovaRunning(boolean novaRunning) {
this.novaRunning = novaRunning;
this.computeComponentRunning = novaRunning;
}
public void setCloudUpdatedTime(long updateTime) {
......@@ -154,7 +154,7 @@ public class Host implements Comparable<Host> {
@Override
public String toString() {
return "Host [name=" + name + ", runningVM=" + runningVM
+ ", novaRunning=" + novaRunning + ", novaEnable=" + novaEnable
+ ", novaRunning=" + computeComponentRunning + ", novaEnable=" + enabled
+ ", cloudUpdatedTime=" + cloudUpdatedTime + ", availableCPU="
+ availableCPU + ", availableRAM=" + availableRAM + ", ip="
+ 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