ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pallav...@apache.org
Subject ambari git commit: AMBARI-16957. Zeppelin views : UI broken when service is not running (Renjith Kamath via pallavkul)
Date Wed, 01 Jun 2016 11:01:56 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 2426d02d0 -> f1e7d1707


AMBARI-16957. Zeppelin views : UI broken when service is not running (Renjith Kamath via pallavkul)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f1e7d170
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f1e7d170
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f1e7d170

Branch: refs/heads/trunk
Commit: f1e7d1707b26b21e4def3ce19d5f235029a78783
Parents: 2426d02
Author: Pallav Kulshreshtha <pallav.kul@gmail.com>
Authored: Wed Jun 1 16:30:57 2016 +0530
Committer: Pallav Kulshreshtha <pallav.kul@gmail.com>
Committed: Wed Jun 1 16:30:57 2016 +0530

----------------------------------------------------------------------
 contrib/views/zeppelin/pom.xml                  | 12 ++++
 .../view/zeppelin/ZeppelinServiceCheck.java     | 64 ++++++++++++++++++++
 .../src/main/resources/WEB-INF/index.jsp        | 38 ++++++++++--
 .../zeppelin/src/main/resources/WEB-INF/web.xml | 13 +++-
 4 files changed, 121 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f1e7d170/contrib/views/zeppelin/pom.xml
----------------------------------------------------------------------
diff --git a/contrib/views/zeppelin/pom.xml b/contrib/views/zeppelin/pom.xml
index 3d0161c..6dd17f3 100644
--- a/contrib/views/zeppelin/pom.xml
+++ b/contrib/views/zeppelin/pom.xml
@@ -86,6 +86,18 @@
       <artifactId>ambari-views-utils</artifactId>
       <version>2.0.0.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.json</groupId>
+      <artifactId>json</artifactId>
+      <version>20160212</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>4.3.6</version>
+    </dependency>
+
 
   </dependencies>
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f1e7d170/contrib/views/zeppelin/src/main/java/org/apache/ambari/view/zeppelin/ZeppelinServiceCheck.java
----------------------------------------------------------------------
diff --git a/contrib/views/zeppelin/src/main/java/org/apache/ambari/view/zeppelin/ZeppelinServiceCheck.java
b/contrib/views/zeppelin/src/main/java/org/apache/ambari/view/zeppelin/ZeppelinServiceCheck.java
new file mode 100644
index 0000000..e80f884
--- /dev/null
+++ b/contrib/views/zeppelin/src/main/java/org/apache/ambari/view/zeppelin/ZeppelinServiceCheck.java
@@ -0,0 +1,64 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+
+package org.apache.ambari.view.zeppelin;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.json.JSONObject;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+
+public class ZeppelinServiceCheck extends HttpServlet {
+    @Override
+    public void init(ServletConfig config) throws ServletException {
+        super.init(config);
+    }
+
+    @Override
+    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException {
+        String url = "http:" + request.getParameter("url");
+        PrintWriter printwriter = response.getWriter();
+        JSONObject json = new JSONObject();
+        response.setContentType("application/json");
+        response.setStatus(HttpServletResponse.SC_OK);
+
+        try {
+            HttpClient httpclient = HttpClientBuilder.create().build();
+            HttpGet httpget = new HttpGet(url);
+            HttpResponse httpresponse = httpclient.execute(httpget);
+            if (httpresponse.getStatusLine().getStatusCode() == 200) {
+                json.put("status", "SUCCESS");
+                json.put("message", "Zeppelin is running");
+            }
+        } catch (Exception e) {
+            json.put("status", "ERROR");
+            json.put("message", "Zeppelin is not running");
+        }
+        printwriter.print(json.toString());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f1e7d170/contrib/views/zeppelin/src/main/resources/WEB-INF/index.jsp
----------------------------------------------------------------------
diff --git a/contrib/views/zeppelin/src/main/resources/WEB-INF/index.jsp b/contrib/views/zeppelin/src/main/resources/WEB-INF/index.jsp
index 9247b8b..493473e 100644
--- a/contrib/views/zeppelin/src/main/resources/WEB-INF/index.jsp
+++ b/contrib/views/zeppelin/src/main/resources/WEB-INF/index.jsp
@@ -19,16 +19,29 @@
 <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 port = "${port}";
-    var publicName = "${publicname}";
-
 
     $.getJSON('/api/v1/clusters', function (data) {
         $.getJSON('/api/v1/clusters/' +
@@ -39,8 +52,7 @@
                         for (var j = 0; j < data['items'][i]['host_components'].length;
j++) {
                             if (data['items'][i]['host_components'][j]['HostRoles']['component_name']
== 'ZEPPELIN_MASTER') {
                                 var url = '//' + data['items'][i]['host_components'][j]['HostRoles']['host_name']
+ ':' + port;
-                                iframe.src = url;
-                                iframe.height = window.innerHeight;
+                                validateAndLoadZeppelinUI(iframe, url);
                                 return;
                             }
                         }
@@ -51,6 +63,22 @@
     $(window).resize(function () {
         iframe.height = window.innerHeight;
     });
+
+    function validateAndLoadZeppelinUI(iframe, url) {
+        $.get(location.href + "zeppelin-service-check?url=" + url, function (response) {
+            if (response.status === "SUCCESS") {
+                messageContainer.style.display = "none";
+                iframe.style.display = "block";
+                iframe.src = url;
+                iframe.height = window.innerHeight;
+            } else {
+                messageContainer.style.display = "block";
+                iframe.style.display = "none";
+            }
+        });
+
+
+    }
 </script>
 </body>
-</html>
\ No newline at end of file
+</html>

http://git-wip-us.apache.org/repos/asf/ambari/blob/f1e7d170/contrib/views/zeppelin/src/main/resources/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/contrib/views/zeppelin/src/main/resources/WEB-INF/web.xml b/contrib/views/zeppelin/src/main/resources/WEB-INF/web.xml
index cb0bcd9..2ca5664 100644
--- a/contrib/views/zeppelin/src/main/resources/WEB-INF/web.xml
+++ b/contrib/views/zeppelin/src/main/resources/WEB-INF/web.xml
@@ -27,6 +27,16 @@ limitations under the License. Kerberos, LDAP, Custom. Binary/Htt
     This is the Zeppelin view servlet application.
   </description>
   <servlet>
+    <servlet-name>ZeppelinServiceCheck</servlet-name>
+    <servlet-class>org.apache.ambari.view.zeppelin.ZeppelinServiceCheck</servlet-class>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>ZeppelinServiceCheck</servlet-name>
+    <url-pattern>/zeppelin-service-check</url-pattern>
+  </servlet-mapping>
+
+  <servlet>
     <servlet-name>ZeppelinServlet</servlet-name>
     <servlet-class>org.apache.ambari.view.zeppelin.ZeppelinServlet</servlet-class>
   </servlet>
@@ -35,4 +45,5 @@ limitations under the License. Kerberos, LDAP, Custom. Binary/Htt
     <servlet-name>ZeppelinServlet</servlet-name>
     <url-pattern>/</url-pattern>
   </servlet-mapping>
-</web-app>
\ No newline at end of file
+
+</web-app>


Mime
View raw message