Permalink
Browse files

made port configurable, fixed jetty errors, can now set PIG_HOME

  • Loading branch information...
1 parent b9ce4c7 commit 9f0b7e8d0fed5fb05b845639a60e96f9d4527d81 @billonahill billonahill committed Apr 20, 2012
@@ -30,7 +30,8 @@
ScriptStatusServer server;
public PigStatsDataVizCollector() {
- server = new ScriptStatusServer(this, 8080);
+ String port = System.getProperty("iris.port.number", "8080");
+ server = new ScriptStatusServer(this, Integer.parseInt(port));
server.start();
}
@@ -5,18 +5,17 @@
import org.apache.commons.logging.LogFactory;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
+import org.mortbay.jetty.HttpConnection;
+import org.mortbay.jetty.Request;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler;
-import org.mortbay.jetty.handler.ContextHandler;
import org.mortbay.jetty.webapp.WebAppContext;
-import org.mortbay.resource.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collection;
-import java.util.HashMap;
/**
* @author billg
@@ -36,6 +35,7 @@ public ScriptStatusServer(PigStatsDataVizCollector statsCollector, int port) {
public void start() {
try {
+ LOG.info("Starting iris web server on port " + port);
serverThread = new Thread(this);
serverThread.setDaemon(false);
serverThread.start();
@@ -46,12 +46,17 @@ public void start() {
@Override
public void run() {
- server = new Server(port);
- ContextHandler staticHandler = new ContextHandler();
+ String pigHome = System.getenv("PIG_HOME");
+ if (pigHome == null) {
+ LOG.warn("PIG_HOME must be set to run iris and $PIG_HOME/contrib/iris must exist. Exiting iris.");
+ return;
+ }
+
+ server = new Server(port);
WebAppContext webappcontext = new WebAppContext();
webappcontext.setContextPath("/");
- webappcontext.setWar("contrib/iris/client");
+ webappcontext.setWar(pigHome + "/contrib/iris/client");
server.addHandler(new APIHandler());
server.addHandler(webappcontext);
server.setStopAtShutdown(false);
@@ -77,28 +82,33 @@ public void handle(String target, HttpServletRequest request,
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_OK);
Collection<PigStatsDataVizCollector.DAGNode> nodes = statsCollector.getDagNodeNameMap().values();
- sendJson(response, nodes.toArray(new PigStatsDataVizCollector.DAGNode[nodes.size()]));
+ sendJson(request, response, nodes.toArray(new PigStatsDataVizCollector.DAGNode[nodes.size()]));
} else if (target.startsWith("/events")) {
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_OK);
Integer sinceId = request.getParameter("sinceId") != null ?
Integer.getInteger(request.getParameter("sinceId")) : -1;
Collection<PigStatsDataVizCollector.PigScriptEvent> events = statsCollector.getEventsSinceId(sinceId);
- sendJson(response, events.toArray(new PigStatsDataVizCollector.PigScriptEvent[events.size()]));
+ sendJson(request, response, events.toArray(new PigStatsDataVizCollector.PigScriptEvent[events.size()]));
}
else if (target.endsWith(".html")) {
response.setContentType("text/html");
- // this is because the next handler will be picked up here
+ // this is because the next handler will be picked up here and it doesn't seem to
+ // handle html well. This is jank.
}
}
}
- private static void sendJson(HttpServletResponse response, Object object) throws IOException {
+ private static void sendJson(HttpServletRequest request,
+ HttpServletResponse response, Object object) throws IOException {
ObjectMapper om = new ObjectMapper();
om.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
om.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
response.getWriter().println(om.writeValueAsString(object));
response.getWriter().flush();
response.getWriter().close();
+ Request base_request = (request instanceof Request) ?
+ (Request)request : HttpConnection.getCurrentConnection().getRequest();
+ base_request.setHandled(true);
}
}

0 comments on commit 9f0b7e8

Please sign in to comment.