Modified:
trunk/src/com/flaptor/clusterfest/ClusterManager.java
trunk/src/com/flaptor/clusterfest/ClusterfestServlet.java
trunk/src/com/flaptor/clusterfest/monitoring/MonitorModule.java
trunk/src/com/flaptor/clusterfest/monitoring/MonitorNodeDescriptor.java
trunk/src/com/flaptor/clusterfest/monitoring/NodeState.java
trunk/src/com/flaptor/clusterfest/monitoring/node/Monitoreable.java
trunk/src/com/flaptor/clusterfest/monitoring/node/MonitoreableImplementation.java
trunk/test/com/flaptor/clusterfest/ClusterfestRpcTest.java
Log:
now out and err logs are not hardcoded any more
Modified: trunk/src/com/flaptor/clusterfest/ClusterManager.java
==============================================================================
--- trunk/src/com/flaptor/clusterfest/ClusterManager.java (original)
+++ trunk/src/com/flaptor/clusterfest/ClusterManager.java Thu Jul 10
13:22:19 2008
@@ -170,7 +170,7 @@
* updates all info of all nodes
*/
@SuppressWarnings("unchecked")
- public void updateAllInfoAllNodes() {
+ public void updateNodes() {
Execution<Void> execution = new Execution<Void>();
synchronized (nodes) {
for(final NodeDescriptor node: nodes) {
@@ -277,15 +277,4 @@
}
return null;
}
-
- /**
- * check to see if nodes that weren't alive came to live
- */
- private void updateNodes() {
- synchronized (nodes) {
- for (NodeDescriptor node: nodes) {
- updateAllInfo(node);
- }
- }
- }
}
Modified: trunk/src/com/flaptor/clusterfest/ClusterfestServlet.java
==============================================================================
--- trunk/src/com/flaptor/clusterfest/ClusterfestServlet.java (original)
+++ trunk/src/com/flaptor/clusterfest/ClusterfestServlet.java Thu Jul
10 13:22:19 2008
@@ -119,7 +119,7 @@
message += "OK : " + node.getHost() + ":" + node.getPort()
+ " unregistered.";
try {cluster.persistNodeList();} catch(IOException e)
{message+="\nWARNING: couldn't persist node list";}
} else if ("updateall".equals(action)) {
- cluster.updateAllInfoAllNodes();
+ cluster.updateNodes();
} else if ("update".equals(action)) { //this action updates
all states of the node: cluster, monitor,etc.
int idx = Integer.parseInt(request.getParameter("node"));
NodeDescriptor node = cluster.getNodes().get(idx);
//update node info
Modified: trunk/src/com/flaptor/clusterfest/monitoring/MonitorModule.java
==============================================================================
--- trunk/src/com/flaptor/clusterfest/monitoring/MonitorModule.java (original)
+++ trunk/src/com/flaptor/clusterfest/monitoring/MonitorModule.java Thu
Jul 10 13:22:19 2008
@@ -59,23 +59,27 @@
private static final Logger logger = Logger.getLogger(com.flaptor.util.Execute.whoAmI());
private final Map<String, PropertyFormatter> formatters = new
HashMap<String, PropertyFormatter>();
+ private List<String>initialLogs;
File statesDir;
public MonitorModule() {
+ Config cfg = Config.getConfig("clustering.properties");
try {
statesDir = FileUtil.createOrGetDir(
- new File(Config.getConfig("clustering.properties").getString("clustering.monitor.statesDir")).getAbsolutePath(),
+ new File(cfg.getString("clustering.monitor.statesDir")).getAbsolutePath(),
true, true);
} catch (IOException e) {
throw new RuntimeException(e);
}
+
+ initialLogs=Arrays.asList(cfg.getStringArray("clustering.monitor.logs.defaults"));
}
@Override
protected MonitorNodeDescriptor createModuleNode(NodeDescriptor node) {
- MonitorNodeDescriptor monitorNode = new MonitorNodeDescriptor(node, statesDir);
+ MonitorNodeDescriptor monitorNode = new MonitorNodeDescriptor(node,
statesDir, initialLogs);
try {
monitorNode.setChecker(getCheckerForType(node.getType()));
} catch (Exception e) {
@@ -253,7 +257,6 @@
if ("update".equals(action)) {
updateNodeInfo(monitorNode);
}
-
if (monitorNode != null) {
NodeState nodeState = null;
String stateNum = request.getParameter("stateNum");
@@ -264,7 +267,6 @@
}
request.setAttribute("nodeState", nodeState);
}
-
return "monitorNode.vm";
} else if (page.equals("monitorLog")){
String action = request.getParameter("action");
Modified: trunk/src/com/flaptor/clusterfest/monitoring/MonitorNodeDescriptor.java
==============================================================================
---
trunk/src/com/flaptor/clusterfest/monitoring/MonitorNodeDescriptor.java (original)
+++
trunk/src/com/flaptor/clusterfest/monitoring/MonitorNodeDescriptor.java
Thu Jul 10 13:22:19 2008
@@ -55,7 +55,7 @@
FileSerializer stateFileSerializer;
@SuppressWarnings("unchecked")
- public MonitorNodeDescriptor(NodeDescriptor node, File statesDir) {
+ public MonitorNodeDescriptor(NodeDescriptor node, File statesDir,
List<String> logNames) {
super(node);
stateFileSerializer = new FileSerializer(new File(statesDir, node.getHost()+"."+node.getPort()+".states"));
@@ -66,9 +66,9 @@
this.logs = new HashMap<String, Pair<String,Long>>();
this.monitoreable = MonitorModule.getModuleListener(node.getXmlrpcClient());
- //TODO hardcoded logs
- this.logs.put("out", null);
- this.logs.put("err", null);
+ for (String log : logNames) {
+ this.logs.put(log, null);
+ }
}
public List<NodeState> getStates() {
@@ -122,7 +122,7 @@
*/
public void updateLog(String logName) throws NodeException {
try {
- String log = monitoreable.getLog(logName);
+ String log = monitoreable.getLog(logName, 512*1024);
//retrieve only 500k
getNodeDescriptor().setReachable(true);
logs.put(logName, new Pair<String, Long>(log, System.currentTimeMillis()));
} catch (Throwable t) {
@@ -142,6 +142,7 @@
state = NodeState.createUnreachableState();
throw e;
} catch (NodeException e) {
+ logger.error("remote code exception", e.getCause());
state = NodeState.createErrorState(e.getCause());
throw e;
} finally {
Modified: trunk/src/com/flaptor/clusterfest/monitoring/NodeState.java
==============================================================================
--- trunk/src/com/flaptor/clusterfest/monitoring/NodeState.java (original)
+++ trunk/src/com/flaptor/clusterfest/monitoring/NodeState.java Thu Jul
10 13:22:19 2008
@@ -16,7 +16,9 @@
package com.flaptor.clusterfest.monitoring;
+import java.io.PrintWriter;
import java.io.Serializable;
+import java.io.StringWriter;
import java.util.Arrays;
import java.util.Map;
@@ -50,8 +52,15 @@
}
public static NodeState createErrorState(Throwable t) {
+ StringWriter stringWriter = new StringWriter();
+ PrintWriter printWriter = new PrintWriter(stringWriter);
+ t.printStackTrace(printWriter);
+ printWriter.flush();
+ stringWriter.flush();
+ String stacktrace = stringWriter.getBuffer().toString();
+
NodeState state = new NodeState(null, null);
- state.sanity = new
NodeChecker.Result(NodeChecker.Sanity.ERROR, Arrays.asList(new
String[]{"Node throwing exception in clusterfest code", t.getMessage()}));
+ state.sanity = new
NodeChecker.Result(NodeChecker.Sanity.ERROR, Arrays.asList(new
String[]{"Node throwing exception in clusterfest code", t.getMessage(), stacktrace}));
return state;
}
Modified: trunk/src/com/flaptor/clusterfest/monitoring/node/Monitoreable.java
==============================================================================
--- trunk/src/com/flaptor/clusterfest/monitoring/node/Monitoreable.java (original)
+++ trunk/src/com/flaptor/clusterfest/monitoring/node/Monitoreable.java
Thu Jul 10 13:22:19 2008
@@ -53,7 +53,8 @@
/**
* gets a log from the node
* @param logName the name of the log to be retrieved
+ * @param maxChars maximum size in chars to retrieve
* @return the log
*/
- public String getLog(String logName) throws Exception;
+ public String getLog(String logName, int maxChars) throws Exception;
}
Modified: trunk/src/com/flaptor/clusterfest/monitoring/node/MonitoreableImplementation.java
==============================================================================
---
trunk/src/com/flaptor/clusterfest/monitoring/node/MonitoreableImplementation.java (original)
+++
trunk/src/com/flaptor/clusterfest/monitoring/node/MonitoreableImplementation.java
Thu Jul 10 13:22:19 2008
@@ -17,6 +17,7 @@
package com.flaptor.clusterfest.monitoring.node;
import java.io.File;
+import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -69,24 +70,17 @@
* @param logName can be "out", "err" or the full path of a log
* @return the contents of the log
*/
- public String getLog(String logName) {
+ public String getLog(String logName, int maxChars) {
File logFile = null;
String errorMessage = "log " + logName + " not found";
try {
- if ("out".equals(logName) || "err".equals(logName)) {
- for (File file : FileUtil.getExistingFile("logs", true, false,
true).listFiles()) {
- if (file.getName().contains(logName)) logFile = file;
- }
- if (logFile == null) {
- logger.warn(errorMessage);
- return errorMessage;
- }
+ logFile = FileUtil.getExistingFile(logName, true, false, false);
+ if (maxChars > 0){
+ return new String(IOUtil.tail(logFile,maxChars)); //read max 500k
} else {
- logFile = FileUtil.getExistingFile(logName, true, false, false);
+ return IOUtil.readAll(new FileReader(logFile));
}
- return new String(IOUtil.tail(logFile, 1024 * 1024)); //read max 1 M
-// return IOUtil.readAll(new FileReader(logFile));
} catch (IOException e) {
logger.warn(errorMessage, e);
return errorMessage + " - " + e;
Modified: trunk/test/com/flaptor/clusterfest/ClusterfestRpcTest.java
==============================================================================
--- trunk/test/com/flaptor/clusterfest/ClusterfestRpcTest.java (original)
+++ trunk/test/com/flaptor/clusterfest/ClusterfestRpcTest.java Thu Jul
10 13:22:19 2008
@@ -16,6 +16,7 @@
package com.flaptor.clusterfest;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@@ -77,7 +78,7 @@
@TestInfo(testType = TestInfo.TestType.INTEGRATION)//,
requiresPort = {PORT})
public void testMonitoreable() throws Exception {
- MonitorNodeDescriptor mnode = new MonitorNodeDescriptor(node, FileUtil.createTempDir("tempStates", ""));
+ MonitorNodeDescriptor mnode = new MonitorNodeDescriptor(node,
FileUtil.createTempDir("tempStates", ""), new ArrayList<String>());
mnode.updateState();
NodeState nodeState = mnode.getLastState();
@@ -87,7 +88,7 @@
}
public static class MonitoreableImp implements Monitoreable{
- public String getLog(String logName) throws Exception {
+ public String getLog(String logName, int chars) throws Exception {
return "log";
}
public Map<String, Object> getProperties() throws Exception {