Commit 1c359cb8 authored by aninhacostaribeiro's avatar aninhacostaribeiro
Browse files

Changed sysout for Logger.log()

parent be8c12ee
package org.fogbowcloud.green.agent.core;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.dom4j.tree.DefaultElement;
......@@ -22,22 +23,24 @@ public class AgentCommunicationComponent {
this.prop = prop;
client = new XMPPClient(this.prop.getProperty("xmpp.jid"),
this.prop.getProperty("xmpp.password"),
this.prop.getProperty("xmpp.host"),
Integer.parseInt(this.prop.getProperty("xmpp.port")));
this.prop.getProperty("xmpp.host"), Integer.parseInt(this.prop
.getProperty("xmpp.port")));
}
public void init() {
public Boolean init() {
XEP0077 register = new XEP0077();
try {
this.client.registerPlugin(register);
client.connect();
register.createAccount(this.prop.getProperty("xmpp.jid"),
client.connect();
register.createAccount(this.prop.getProperty("xmpp.jid"),
this.prop.getProperty("xmpp.password"));
client.login();
client.process(false);
} catch (XMPPException e) {
Logger logger = Logger.getLogger("green.Agent");
logger.log(Level.SEVERE, "It was not possible to connect");
return false;
}
client.getConnection().addPacketListener(new PacketListener() {
@Override
......@@ -47,31 +50,36 @@ public class AgentCommunicationComponent {
}, new PacketFilter() {
@Override
public boolean accept(Packet packet) {
if (!packet.getFrom().toString().equals(
prop.getProperty("xmpp.component"))) {
if (!packet.getFrom().toString()
.equals(prop.getProperty("xmpp.component"))) {
return false;
}
String ns = packet.getElement().element("query").getNamespaceURI();
String ns = packet.getElement().element("query")
.getNamespaceURI();
if (!ns.equals("org.fogbowcloud.green.GoToBed")) {
return false;
}
return true;
}
});
return true;
}
public void sendIamAliveSignal(){
public void sendIamAliveSignal() {
IQ iq = new IQ(Type.get);
iq.setTo(this.prop.getProperty("xmpp.component"));
iq.getElement().addElement("query", "org.fogbowcloud.green.IAmAlive");
DefaultElement query = (DefaultElement) iq.getElement().elements("query").get(0);
DefaultElement query = (DefaultElement) iq.getElement()
.elements("query").get(0);
query.addElement("ip").setText(this.prop.getProperty("host.ip"));
query.addElement("macAddress").setText(this.prop.getProperty("host.macAddress"));
query.addElement("hostName").setText(this.prop.getProperty("host.name"));
query.addElement("macAddress").setText(
this.prop.getProperty("host.macAddress"));
query.addElement("hostName")
.setText(this.prop.getProperty("host.name"));
}
}
......@@ -19,6 +19,8 @@ public class Main {
try {
Properties prop = getProp(args[0]);
AgentCommunicationComponent acc = new AgentCommunicationComponent(prop);
if (!acc.init())
return;
acc.sendIamAliveSignal();
} catch (Exception e) {
Logger logger = Logger.getLogger("green.agent");
......
package org.fogbowcloud.green.agent.core;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class TurnOff {
public void hibernate(){
String hibernateCommand="";
public void hibernate() {
String hibernateCommand = "";
String operatingSystem = System.getProperty("os.name");
if ("Linux".equals(operatingSystem)
|| "Mac OS X".equals(operatingSystem)) {
//Suspend or hibernate?
// Suspend or hibernate?
hibernateCommand = "pm-suspend";
}
ProcessBuilder pb =
new ProcessBuilder("sudo","-S", hibernateCommand);
try {
ProcessBuilder pb = new ProcessBuilder("sudo", "-S", hibernateCommand);
try {
pb.start();
} catch (IOException e) {
System.err.println("It was not possible to turn down");
Logger logger = Logger.getLogger("green.agent");
logger.log(Level.WARNING,
"It was not possible to turn down this host");
}
}
}
......@@ -6,7 +6,7 @@ import org.xmpp.packet.IQ;
public class IAmAliveHandler extends AbstractQueryHandler {
private static final String NAMESPACE = "org.fogbowcloud.green.IAmAlive"; //Is this name actually good?
private static final String NAMESPACE = "org.fogbowcloud.green.IAmAlive";
private final GreenStrategy gs;
public IAmAliveHandler(GreenStrategy gs) {
......
......@@ -3,8 +3,9 @@ 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.dom4j.tree.DefaultElement;
import org.fogbowcloud.green.server.communication.Agent;
import org.fogbowcloud.green.server.core.greenStrategy.GreenStrategy;
import org.jamppa.component.XMPPComponent;
......@@ -35,7 +36,8 @@ public class ServerCommunicationComponent extends XMPPComponent {
ProcessBuilder pb = new ProcessBuilder("powerwake", macAddress);
pb.start();
} catch (IOException e) {
System.err.println("It was not possible to wake " + macAddress);
Logger logger = Logger.getLogger("green.server");
logger.log(Level.WARNING, "It was not possible to wake " + macAddress);
}
}
......
......@@ -3,6 +3,8 @@ package org.fogbowcloud.green.server.core;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.fogbowcloud.green.server.communication.ServerCommunicationComponent;
import org.fogbowcloud.green.server.core.greenStrategy.DefaultGreenStrategy;
......@@ -26,7 +28,8 @@ public class Main {
gs.start();
scc.process(true);
} catch (Exception e) {
System.err.println("You must provide as parameter the"
Logger logger = Logger.getLogger("green.server");
logger.log(Level.WARNING, "You must provide as parameter the"
+ " path for the configuration file");
}
}
......
......@@ -107,6 +107,7 @@ public class OpenStackInfoPlugin implements CloudInfoPlugin {
active.equals("true")));
}
} catch (Exception e) {
// Ignoring exceptions for hosts in unavailable zones
}
}
......
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