|
@@ -29,42 +29,85 @@ import javax.servlet.http.HttpServlet;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.PrintWriter;
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
public class ZeppelinServlet extends HttpServlet {
|
|
|
- private ViewContext viewContext;
|
|
|
- private final static Logger LOG = LoggerFactory.getLogger(ZeppelinServlet.class);
|
|
|
+ private ViewContext viewContext;
|
|
|
+ private final static Logger LOG = LoggerFactory.getLogger(ZeppelinServlet.class);
|
|
|
|
|
|
- @Override
|
|
|
- public void init(ServletConfig config) throws ServletException {
|
|
|
- super.init(config);
|
|
|
+ @Override
|
|
|
+ public void init(ServletConfig config) throws ServletException {
|
|
|
+ super.init(config);
|
|
|
|
|
|
- ServletContext context = config.getServletContext();
|
|
|
- viewContext = (ViewContext) context.getAttribute(ViewContext.CONTEXT_ATTRIBUTE);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
|
|
- response.setContentType("text/html");
|
|
|
- response.setStatus(HttpServletResponse.SC_OK);
|
|
|
- String publicName = "";
|
|
|
- String port = "";
|
|
|
- try {
|
|
|
- port = viewContext.getProperties().get("zeppelin.server.port");
|
|
|
- if (viewContext.getCluster() != null) {
|
|
|
- List<String> hostsForServiceComponents = viewContext.getCluster().getHostsForServiceComponent("ZEPPELIN", "ZEPPELIN_MASTER");
|
|
|
- publicName = hostsForServiceComponents.get(0);
|
|
|
- } else {
|
|
|
- publicName = viewContext.getProperties().get("zeppelin.host.publicname");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- LOG.error("Zeppelin view servlet failed", e);
|
|
|
- }
|
|
|
+ ServletContext context = config.getServletContext();
|
|
|
+ viewContext = (ViewContext) context.getAttribute(ViewContext.CONTEXT_ATTRIBUTE);
|
|
|
+ }
|
|
|
|
|
|
- String serviceCheckResponse = ZeppelinServiceCheck.check(publicName, port);
|
|
|
- request.setAttribute("serviceCheckResponse", serviceCheckResponse);
|
|
|
-
|
|
|
- request.getRequestDispatcher("WEB-INF/index.jsp").forward(request, response);
|
|
|
+ public void service(HttpServletRequest req,
|
|
|
+ HttpServletResponse res) throws IOException {
|
|
|
+ res.setContentType("text/html");
|
|
|
+ PrintWriter out = res.getWriter();
|
|
|
+ String publicName = "";
|
|
|
+ String port = "";
|
|
|
+ try {
|
|
|
+ port = viewContext.getProperties().get("zeppelin.server.port");
|
|
|
+ if (viewContext.getCluster() != null) {
|
|
|
+ List<String> hostsForServiceComponents = viewContext.getCluster().getHostsForServiceComponent
|
|
|
+ ("ZEPPELIN", "ZEPPELIN_MASTER");
|
|
|
+ publicName = hostsForServiceComponents.get(0);
|
|
|
+ } else {
|
|
|
+ publicName = viewContext.getProperties().get("zeppelin.host.publicname");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOG.error("Zeppelin view servlet failed", e);
|
|
|
}
|
|
|
+ out.println("<html lang=\"en\">" +
|
|
|
+ "<head>" +
|
|
|
+ " <meta charset=\"utf-8\"/>" +
|
|
|
+ " <link rel=\"stylesheet\" href=\"/stylesheets/vendor.css\">" +
|
|
|
+ "</head>" +
|
|
|
+ "<body>" +
|
|
|
+ "" +
|
|
|
+ "<div class=\"container-fluid\" id=\"messageContainer\" style=\"display:none;\">" +
|
|
|
+ " <h1>Welcome to the Zeppelin View</h1>" +
|
|
|
+ " <h3>Service check failed</h3>" +
|
|
|
+ "" +
|
|
|
+ " <table class=\"table\">" +
|
|
|
+ " <tbody>" +
|
|
|
+ " <tr>" +
|
|
|
+ " <td>zeppelin service is not running</td>" +
|
|
|
+ " </tr>" +
|
|
|
+ " </tbody>" +
|
|
|
+ " </table>" +
|
|
|
+ "" +
|
|
|
+ "</div>" +
|
|
|
+ "" +
|
|
|
+ "<iframe id='zeppelinIFrame' width=\"100%\" seamless=\"seamless\" style=\"border: 0px;\"></iframe>" +
|
|
|
+ "<script>" +
|
|
|
+ "var $ = jQuery = parent.jQuery;" +
|
|
|
+ "var iframe = document.querySelector('#zeppelinIFrame');" +
|
|
|
+ "var messageContainer = document.querySelector('#messageContainer');" +
|
|
|
+ "" +
|
|
|
+ "var serviceCheckResponse = $.parseJSON(' " + ZeppelinServiceCheck.check(publicName, port) + "');" +
|
|
|
+ "" +
|
|
|
+ "if (serviceCheckResponse.status === \"SUCCESS\") {" +
|
|
|
+ " messageContainer.style.display = \"none\";" +
|
|
|
+ " iframe.style.display = \"block\";" +
|
|
|
+ " iframe.src = serviceCheckResponse.url;" +
|
|
|
+ " iframe.height = window.innerHeight;" +
|
|
|
+ "} else {" +
|
|
|
+ " messageContainer.style.display = \"block\";" +
|
|
|
+ " iframe.style.display = \"none\";" +
|
|
|
+ "}" +
|
|
|
+ "" +
|
|
|
+ "$(window).resize(function () {" +
|
|
|
+ " iframe.height = window.innerHeight;" +
|
|
|
+ "});" +
|
|
|
+ "</script>" +
|
|
|
+ "</body>" +
|
|
|
+ "</html>");
|
|
|
+ }
|
|
|
+
|
|
|
}
|