Kaynağa Gözat

AMBARI-18918: Zeppelin view doesn't work with JDK 1.8_91+ (Prabhjyot Singh)

Renjith Kamath 8 yıl önce
ebeveyn
işleme
0c5850a2e5

+ 73 - 30
contrib/views/zeppelin/src/main/java/org/apache/ambari/view/zeppelin/ZeppelinServlet.java

@@ -29,42 +29,85 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.List;
 import java.util.List;
 
 
 
 
 public class ZeppelinServlet extends HttpServlet {
 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>");
+  }
+
 }
 }

+ 0 - 63
contrib/views/zeppelin/src/main/resources/WEB-INF/index.jsp

@@ -1,63 +0,0 @@
-<!DOCTYPE html>
-<%--
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements.  See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership.  The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
---%>
-<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('<%= request.getAttribute("serviceCheckResponse") %>');
-
-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>