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
80849d22
Commit
80849d22
authored
Mar 24, 2015
by
aninhacostaribeiro
Browse files
Now wakeUpHosts throws exceptions.
parent
e7a0d1de
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/fogbowcloud/green/server/communication/ServerCommunicationComponent.java
View file @
80849d22
...
...
@@ -3,7 +3,6 @@ package org.fogbowcloud.green.server.communication;
import
java.io.IOException
;
import
java.util.Properties
;
import
org.apache.log4j.Logger
;
import
org.fogbowcloud.green.server.core.greenStrategy.GreenStrategy
;
import
org.jamppa.component.XMPPComponent
;
import
org.xmpp.packet.IQ
;
...
...
@@ -11,8 +10,6 @@ import org.xmpp.packet.IQ.Type;
public
class
ServerCommunicationComponent
extends
XMPPComponent
{
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
ServerCommunicationComponent
.
class
);
private
GreenStrategy
gs
;
public
ServerCommunicationComponent
(
Properties
prop
,
GreenStrategy
gs
)
{
...
...
@@ -23,13 +20,9 @@ public class ServerCommunicationComponent extends XMPPComponent {
addHandlers
();
}
public
void
wakeUpHost
(
String
macAddress
)
{
try
{
ProcessBuilder
pb
=
new
ProcessBuilder
(
"powerwake"
,
macAddress
);
pb
.
start
();
}
catch
(
IOException
e
)
{
LOGGER
.
warn
(
"It was not possible to wake "
+
macAddress
+
e
);
}
public
void
wakeUpHost
(
String
macAddress
)
throws
IOException
{
ProcessBuilder
pb
=
new
ProcessBuilder
(
"powerwake"
,
macAddress
);
pb
.
start
();
}
public
void
sendIdleHostToBed
(
String
hostJID
)
{
...
...
src/main/java/org/fogbowcloud/green/server/core/greenStrategy/DefaultGreenStrategy.java
View file @
80849d22
package
org.fogbowcloud.green.server.core.greenStrategy
;
import
java.io.IOException
;
import
java.util.Date
;
import
java.util.LinkedList
;
import
java.util.List
;
...
...
@@ -219,22 +220,30 @@ public class DefaultGreenStrategy implements GreenStrategy {
public
void
wakeUpSleepingHost
(
int
minCPU
,
int
minRAM
)
{
Host
host
=
this
.
sleepingHosts
.
peek
();
try
{
if
(
host
.
getAvailableCPU
()
<
minCPU
)
{
LOGGER
.
info
(
"Tried to wake hosts but no hosts were found"
);
return
;
}
if
(
host
.
getAvailableRAM
()
>=
minRAM
)
{
this
.
scc
.
wakeUpHost
(
host
.
getName
());
this
.
sleepingHosts
.
remove
(
host
);
LOGGER
.
info
(
"Waked "
+
host
);
}
if
(
host
.
getAvailableCPU
()
<
minCPU
)
{
return
;
}
if
(
host
.
getAvailableRAM
()
>=
minRAM
)
{
this
.
scc
.
wakeUpHost
(
host
.
getName
());
this
.
sleepingHosts
.
remove
(
host
);
}
catch
(
IOException
e
)
{
LOGGER
.
warn
(
"It was not possible to wake "
+
host
+
"it may be lost or there is a network problem"
+
e
);
}
}
public
void
start
()
{
executorVerifyLastTimeSeen
.
scheduleWithFixedDelay
(
new
Runnable
()
{
@Override
public
void
run
()
{
checkHostsLastSeen
();
LOGGER
.
info
(
"Checked when hosts were seen"
);
LOGGER
.
info
(
"Checked when hosts were seen"
+
" Lost Hosts now"
);
}
},
0
,
lostHostTime
,
TimeUnit
.
MILLISECONDS
);
...
...
@@ -242,7 +251,8 @@ public class DefaultGreenStrategy implements GreenStrategy {
@Override
public
void
run
()
{
sendIdleHostsToBed
();
LOGGER
.
info
(
"Sent idle hosts to bed"
);
LOGGER
.
info
(
"Sent idle hosts to bed: "
+
"Sleeping Hosts now "
+
sleepingHosts
);
}
},
0
,
sleepingTime
,
TimeUnit
.
MILLISECONDS
);
}
...
...
src/test/java/org/fogbowcloud/green/server/core/greenStrategy/TestDefaultGreenStrategy.java
View file @
80849d22
package
org.fogbowcloud.green.server.core.greenStrategy
;
import
java.io.IOException
;
import
java.util.Date
;
import
java.util.LinkedList
;
import
java.util.List
;
...
...
@@ -109,7 +110,12 @@ public class TestDefaultGreenStrategy {
Date
date
=
this
.
createDateMock
(
3600001
);
ServerCommunicationComponent
gscc
=
Mockito
.
mock
(
ServerCommunicationComponent
.
class
);
Mockito
.
doNothing
().
when
(
gscc
).
wakeUpHost
(
h1
.
getMacAddress
());
try
{
Mockito
.
doNothing
().
when
(
gscc
).
wakeUpHost
(
h1
.
getMacAddress
());
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
OpenStackInfoPlugin
osip
=
this
.
createOpenStackInfoPluginMock
(
hosts
);
DefaultGreenStrategy
dgs
=
new
DefaultGreenStrategy
(
osip
,
1800000
);
dgs
.
setDate
(
date
);
...
...
@@ -170,10 +176,15 @@ public class TestDefaultGreenStrategy {
dgs
.
setDate
(
date
);
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
());
try
{
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
());
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
dgs
.
setCommunicationComponent
(
gscc
);
dgs
.
sendIdleHostsToBed
();
...
...
@@ -215,7 +226,12 @@ public class TestDefaultGreenStrategy {
Date
date
=
this
.
createDateMock
(
3600001
);
ServerCommunicationComponent
gscc
=
Mockito
.
mock
(
ServerCommunicationComponent
.
class
);
Mockito
.
doNothing
().
when
(
gscc
).
wakeUpHost
(
"wake"
);
try
{
Mockito
.
doNothing
().
when
(
gscc
).
wakeUpHost
(
"wake"
);
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
OpenStackInfoPlugin
osip
=
this
.
createOpenStackInfoPluginMock
(
hosts
);
DefaultGreenStrategy
dgs
=
new
DefaultGreenStrategy
(
osip
,
1800000
);
...
...
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