Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

FLUME-667/FLUME-668: Restored stacks applet to master and node / Add …

…logs webapp to master and node
  • Loading branch information...
commit 26fe804c2aeb27b64b90cd26bea8b1a1f306f948 1 parent 61e33c1
@jmhsieh jmhsieh authored
View
9 flume-core/src/main/java/com/cloudera/flume/agent/FlumeNode.java
@@ -63,6 +63,7 @@
import com.cloudera.util.InternalHttpServer;
import com.cloudera.util.NetUtils;
import com.cloudera.util.Pair;
+import com.cloudera.util.StatusHttpServer.StackServlet;
import com.google.common.base.Preconditions;
/**
@@ -260,9 +261,15 @@ public ReportEvent getMetrics() {
try {
http = new InternalHttpServer();
+ http.addHandler(InternalHttpServer.createLogAppContext());
+
+ http.addHandler(InternalHttpServer.createServletContext(
+ StackServlet.class, "/stacks", "/*", "stacks"));
+
http.setBindAddress("0.0.0.0");
http.setPort(conf.getNodeStatusPort());
- http.setWebappDir(new File(conf.getNodeWebappRoot()));
+ String webAppRoot = FlumeConfiguration.get().getNodeWebappRoot();
+ http.setWebappDir(new File(webAppRoot));
http.setScanForApps(true);
http.start();
View
12 flume-core/src/main/java/com/cloudera/flume/conf/FlumeConfiguration.java
@@ -1000,14 +1000,22 @@ public String getDefaultFlowName() {
* Returns the webapp root for the master.
*/
public String getMasterWebappRoot() {
- return getFlumeHome() + File.separator + get(WEBAPP_ROOT_MASTER, null);
+ String home = getFlumeHome();
+ if (home == null) {
+ home = ".";
+ }
+ return home + File.separator + get(WEBAPP_ROOT_MASTER, null);
}
/**
* Returns the webapp root for the node (i.e. agent or collector).
*/
public String getNodeWebappRoot() {
- return getFlumeHome() + File.separator + get(WEBAPP_ROOT_NODE, null);
+ String home = getFlumeHome();
+ if (home == null) {
+ home = ".";
+ }
+ return home + File.separator + get(WEBAPP_ROOT_NODE, null);
}
/**
View
23 flume-core/src/main/java/com/cloudera/flume/master/FlumeMaster.java
@@ -54,6 +54,7 @@
import com.cloudera.util.CheckJavaVersion;
import com.cloudera.util.InternalHttpServer;
import com.cloudera.util.NetUtils;
+import com.cloudera.util.StatusHttpServer.StackServlet;
/**
* This is a first cut at a server for distributing configurations to different
@@ -248,18 +249,17 @@ public void serve() throws IOException {
ReportManager.get().add(sysInfo);
if (doHttp) {
- String webPath = FlumeNode.getWebPath(cfg);
-
http = new InternalHttpServer();
- /*
- this.http = new StatusHttpServer("flumeconfig", webPath, "0.0.0.0", cfg
- .getMasterHttpPort(), false);
- http.addServlet(jerseyMasterServlet(), "/master/*");
- */
+ http.addHandler(InternalHttpServer.createLogAppContext());
+ http.addHandler(InternalHttpServer.createServletContext(
+ StackServlet.class, "/stacks", "/*", "stacks"));
+
http.setBindAddress("0.0.0.0");
http.setPort(cfg.getMasterHttpPort());
- http.setWebappDir(new File(FlumeConfiguration.get().getMasterWebappRoot()));
+ String webAppRoot = FlumeConfiguration.get().getMasterWebappRoot();
+ http.setWebappDir(new File(webAppRoot));
+ LOG.info("Webserver root directory: " + webAppRoot);
http.start();
}
@@ -282,7 +282,7 @@ public void serve() throws IOException {
* Start the Avro/Thrift ReportServer based on the flag set in the
* configuration file.
*/
- if (cfg.getReportServerRPC() == cfg.RPC_TYPE_AVRO) {
+ if (cfg.getReportServerRPC() == FlumeConfiguration.RPC_TYPE_AVRO) {
avroReportServer.serve();
} else {
thriftReportServer.serve();
@@ -344,7 +344,7 @@ public void shutdown() {
/*
* Close the reportserver which started.
*/
- if (cfg.getReportServerRPC() == cfg.RPC_TYPE_AVRO) {
+ if (cfg.getReportServerRPC() == FlumeConfiguration.RPC_TYPE_AVRO) {
if (avroReportServer != null) {
avroReportServer.stop();
avroReportServer = null;
@@ -481,8 +481,7 @@ public static void main(String[] argv) {
FlumeNode.logEnvironment(LOG);
// Make sure the Java version is not older than 1.6
if (!CheckJavaVersion.isVersionOk()) {
- LOG
- .error("Exiting because of an old Java version or Java version in bad format");
+ LOG.error("Exiting because of an old Java version or Java version in bad format");
System.exit(-1);
}
FlumeConfiguration.hardExitLoadConfig(); // if config file is bad hardexit.
View
43 flume-core/src/main/java/com/cloudera/util/InternalHttpServer.java
@@ -4,11 +4,16 @@
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
+import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.DefaultServlet;
+import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.jetty.webapp.WebAppContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.cloudera.util.StatusHttpServer.StackServlet;
import com.google.common.base.Preconditions;
/**
@@ -89,11 +94,13 @@
private int port;
private String bindAddress;
private boolean scanForApps;
+ private ContextHandlerCollection handlers;
public InternalHttpServer() {
port = 0;
bindAddress = "0.0.0.0";
scanForApps = true;
+ handlers = new ContextHandlerCollection();
}
public void initialize() {
@@ -106,6 +113,7 @@ public void initialize() {
connector.setHost(bindAddress);
server.addConnector(connector);
+ server.addHandler(handlers);
}
}
@@ -140,11 +148,12 @@ private boolean tryRegisterApplication(Server server, File path) {
logger.debug("creating context {} -> {}", name, path);
+ // WebAppContext is for loading war files.
WebAppContext handler = new WebAppContext(path.getPath(), "/" + name);
handler.setParentLoaderPriority(true);
- server.addHandler(handler);
+ handlers.addHandler(handler);
return true;
}
@@ -278,4 +287,36 @@ public InternalHttpServerException(Throwable t) {
}
+ public void addHandler(Context ctx) {
+ if (ctx == null) {
+ logger.warn("Attempting to add null webapp context");
+ return;
+ }
+ handlers.addHandler(ctx);
+ }
+
+ public static Context createLogAppContext() {
+ Context ctx = new Context();
+ // logs applet
+ String logDir = System.getProperty("flume.log.dir");
+ if (logDir != null) {
+ ctx.setContextPath("/logs");
+ ctx.setResourceBase(logDir);
+ ctx.addServlet(DefaultServlet.class, "/*");
+ ctx.setDisplayName("logs");
+ }
+ return ctx;
+ }
+
+ public static Context createServletContext(Class<?> sltClz, String contextPath,
+ String pathSpec, String name) {
+ Context ctx = new Context();
+ ServletHolder holder = new ServletHolder(StackServlet.class);
+ ctx.setContextPath("/stacks");
+ ctx.addServlet(holder, "/*");
+ ctx.setDisplayName("stacks");
+
+ return ctx;
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.