Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fogbow
fogbow-green-sitter
Commits
088131dc
Commit
088131dc
authored
May 04, 2015
by
aninhacostaribeiro
Browse files
Started to implement OpenNebula Plugin
parent
e9a49dc6
Changes
5
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
088131dc
...
...
@@ -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>
...
...
src/main/java/org/fogbowcloud/green/server/core/greenStrategy/DefaultGreenStrategy.java
View file @
088131dc
...
...
@@ -19,7 +19,7 @@ public class DefaultGreenStrategy implements GreenStrategy {
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
DefaultGreenStrategy
.
class
);
private
CloudInfoPlugin
openStack
Plugin
;
private
CloudInfoPlugin
cloudInfo
Plugin
;
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
.
openStack
Plugin
=
new
OpenStackInfoPlugin
(
prop
this
.
cloudInfo
Plugin
=
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
.
openStack
Plugin
=
openStackPlugin
;
this
.
cloudInfo
Plugin
=
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
.
openStack
Plugin
.
getHostInformation
();
List
<?
extends
Host
>
cloudInfo
=
this
.
cloudInfo
Plugin
.
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
.
is
Nova
Running
());
host
.
set
Nova
Enable
(
hostCloudInfo
.
is
Nova
Enable
());
host
.
setNovaRunning
(
hostCloudInfo
.
is
ComputeComponent
Running
());
host
.
setEnable
d
(
hostCloudInfo
.
isEnable
d
());
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
.
is
Nova
Enable
()
&&
host
.
is
Nova
Running
()
if
(
host
.
isEnable
d
()
&&
host
.
is
ComputeComponent
Running
()
&&
(
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
);
}
}
src/main/java/org/fogbowcloud/green/server/core/greenStrategy/Host.java
View file @
088131dc
...
...
@@ -6,8 +6,8 @@ public class Host implements Comparable<Host> {
// Cloud related attributes
private
int
runningVM
;
private
boolean
nova
Running
;
private
boolean
novaE
nable
;
private
boolean
computeComponent
Running
;
private
boolean
e
nable
d
;
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
nova
Running
,
boolean
novaE
nable
,
long
updateTime
,
int
availableCPU
,
public
Host
(
String
name
,
int
runningVM
,
boolean
computeComponent
Running
,
boolean
e
nable
d
,
long
updateTime
,
int
availableCPU
,
int
availableRAM
)
{
this
.
name
=
name
;
this
.
runningVM
=
runningVM
;
this
.
novaRunning
=
nova
Running
;
this
.
novaE
nable
=
novaE
nable
;
this
.
computeComponentRunning
=
computeComponent
Running
;
this
.
e
nable
d
=
e
nable
d
;
this
.
cloudUpdatedTime
=
updateTime
;
this
.
availableCPU
=
availableCPU
;
this
.
availableRAM
=
availableRAM
;
...
...
@@ -55,16 +55,16 @@ public class Host implements Comparable<Host> {
return
cloudUpdatedTime
;
}
public
boolean
is
Nova
Enable
()
{
return
novaE
nable
;
public
boolean
isEnable
d
()
{
return
e
nable
d
;
}
public
void
set
Nova
Enable
(
boolean
novaEnable
)
{
this
.
novaE
nable
=
novaEnable
;
public
void
setEnable
d
(
boolean
novaEnable
)
{
this
.
e
nable
d
=
novaEnable
;
}
public
boolean
is
Nova
Running
()
{
return
nova
Running
;
public
boolean
is
ComputeComponent
Running
()
{
return
computeComponent
Running
;
}
public
void
setAvailableCPU
(
int
availableCPU
)
{
...
...
@@ -76,7 +76,7 @@ public class Host implements Comparable<Host> {
}
public
void
setNovaRunning
(
boolean
novaRunning
)
{
this
.
nova
Running
=
novaRunning
;
this
.
computeComponent
Running
=
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="
+
nova
Running
+
", novaEnable="
+
novaE
nable
+
", novaRunning="
+
computeComponent
Running
+
", novaEnable="
+
e
nable
d
+
", cloudUpdatedTime="
+
cloudUpdatedTime
+
", availableCPU="
+
availableCPU
+
", availableRAM="
+
availableRAM
+
", ip="
+
ip
+
", jid="
+
jid
+
", macAddress="
+
macAddress
...
...
src/main/java/org/fogbowcloud/green/server/core/plugins/opennebula/OpenNebulaInfoPlugin.java
0 → 100644
View file @
088131dc
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
src/test/java/org/fogbowcloud/green/server/core/plugins/opennebula/TestOpenNebulaPlugin.java
0 → 100644
View file @
088131dc
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
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment