Repository: ambari
Updated Branches:
  refs/heads/trunk 6a148b76c -> 154f678d8


 AMBARI-20791: Storm Ambari view doesn't work for non-admin users. (Sanket Shah 
via Sriharsha Chintalapani).


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

Branch: refs/heads/trunk
Commit: 154f678d8f92cc7fb7213f9dae5e3d20d66be44c
Parents: 6a148b7
Author: Sriharsha Chintalapani <har...@hortonworks.com>
Authored: Wed May 3 10:42:46 2017 -0700
Committer: Sriharsha Chintalapani <har...@hortonworks.com>
Committed: Wed May 3 10:42:46 2017 -0700

----------------------------------------------------------------------
 .../org/apache/ambari/storm/ProxyServlet.java   | 12 ++++++++--
 .../src/main/resources/scripts/router/Router.js |  6 ++---
 .../src/main/resources/scripts/utils/Utils.js   | 25 --------------------
 contrib/views/storm/src/main/resources/view.xml |  8 +++----
 4 files changed, 17 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/154f678d/contrib/views/storm/src/main/java/org/apache/ambari/storm/ProxyServlet.java
----------------------------------------------------------------------
diff --git 
a/contrib/views/storm/src/main/java/org/apache/ambari/storm/ProxyServlet.java 
b/contrib/views/storm/src/main/java/org/apache/ambari/storm/ProxyServlet.java
index 6e6bea2..f87b29f 100644
--- 
a/contrib/views/storm/src/main/java/org/apache/ambari/storm/ProxyServlet.java
+++ 
b/contrib/views/storm/src/main/java/org/apache/ambari/storm/ProxyServlet.java
@@ -38,6 +38,10 @@ import java.io.*;
 public class ProxyServlet extends HttpServlet {
 
   private ViewContext viewContext;
+  private static final String STORM_HOST = "storm.host";
+  private static final String STORM_PORT = "storm.port";
+  private static final String STORM_SSL_ENABLED = "storm.sslEnabled";
+  private String stormURL;
 
   @Override
   public void init(ServletConfig config) throws ServletException {
@@ -45,12 +49,16 @@ public class ProxyServlet extends HttpServlet {
 
     ServletContext context = config.getServletContext();
     viewContext = (ViewContext) 
context.getAttribute(ViewContext.CONTEXT_ATTRIBUTE);
+    String sslEnabled = viewContext.getProperties().get(STORM_SSL_ENABLED);
+    String hostname = viewContext.getProperties().get(STORM_HOST);
+    String port = viewContext.getProperties().get(STORM_PORT);
+    stormURL = (sslEnabled.equals("true") ? "https" : "http") + "://" + 
hostname + ":" + port;
   }
 
   @Override
   protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
     InputStream body = null;
-    String urlToRead = URLDecoder.decode(request.getParameter("url"));
+    String urlToRead = stormURL + 
URLDecoder.decode(request.getParameter("url"));
     HashMap<String,String> headersMap = this.getHeaders(request);
     InputStream resultStream = 
viewContext.getURLStreamProvider().readAsCurrent(urlToRead, "GET", body, 
headersMap);
     this.setResponse(request, response, resultStream);
@@ -59,7 +67,7 @@ public class ProxyServlet extends HttpServlet {
   @Override
   protected void doPost(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
     InputStream stream = request.getInputStream();
-    String urlToRead = URLDecoder.decode(request.getParameter("url"));
+    String urlToRead = stormURL + 
URLDecoder.decode(request.getParameter("url"));
     HashMap<String,String> headersMap = this.getHeaders(request);
     InputStream resultStream = 
viewContext.getURLStreamProvider().readAsCurrent(urlToRead, "POST", stream, 
headersMap);
     this.setResponse(request, response, resultStream);

http://git-wip-us.apache.org/repos/asf/ambari/blob/154f678d/contrib/views/storm/src/main/resources/scripts/router/Router.js
----------------------------------------------------------------------
diff --git a/contrib/views/storm/src/main/resources/scripts/router/Router.js 
b/contrib/views/storm/src/main/resources/scripts/router/Router.js
index cd498c0..be6943e 100644
--- a/contrib/views/storm/src/main/resources/scripts/router/Router.js
+++ b/contrib/views/storm/src/main/resources/scripts/router/Router.js
@@ -22,7 +22,7 @@ define([
        'react',
        'react-dom',
        'utils/Utils'
-], function(require, Backbone, React, ReactDOM, Utils) {       
+], function(require, Backbone, React, ReactDOM, Utils) {
        'use strict';
        var rRender;
        var AppRouter = Backbone.Router.extend({
@@ -37,7 +37,7 @@ define([
                        '*actions'                                              
                                        : 'defaultAction'
                },
                initialize: function() {
-                       App.baseURL = Utils.getStormHostDetails();
+                        App.baseURL = location.pathname+'proxy?url=';
                        this.showRegions();
                        this.listenTo(this, "route", this.postRouteExecute, 
this);
                },
@@ -82,7 +82,7 @@ define([
                /**
                 * Define route handlers here
                 */
-               
+
                dashboardAction: function(){
                        require(['jsx!views/Dashboard'], 
function(DashboardView){
                                
ReactDOM.render(React.createElement(DashboardView), App.Container);

http://git-wip-us.apache.org/repos/asf/ambari/blob/154f678d/contrib/views/storm/src/main/resources/scripts/utils/Utils.js
----------------------------------------------------------------------
diff --git a/contrib/views/storm/src/main/resources/scripts/utils/Utils.js 
b/contrib/views/storm/src/main/resources/scripts/utils/Utils.js
index 05f992b..d9a9dd6 100644
--- a/contrib/views/storm/src/main/resources/scripts/utils/Utils.js
+++ b/contrib/views/storm/src/main/resources/scripts/utils/Utils.js
@@ -25,31 +25,6 @@ define(['require',
     'use strict';
     var Utils = {};
 
-    Utils.getStormHostDetails = function() {
-        var url = location.pathname+'proxy?url=';
-        var urlParts = location.pathname.split('/');
-        var apiUrl = 
'/api/v1/'+urlParts[1]+'/'+urlParts[2]+'/versions/'+urlParts[3]+'/instances/'+urlParts[4];
-        $.ajax({
-            url: apiUrl,
-            cache: false,
-            type: 'GET',
-            async: false,
-            dataType: 'json',
-            success: function(response){
-                var props = response.ViewInstanceInfo.properties;
-                if(props['storm.host'] && props['storm.port']){
-                    url += (props['storm.sslEnabled'] === "true" ? "https://"; 
: "http://";)+props['storm.host']+":"+props['storm.port'];
-                } else {
-                    Utils.notifyError("Failed to get storm hostname and 
port.");
-                }
-            },
-            error: function(error){
-                Utils.notifyError("Failed to get storm hostname and port.");
-            }
-        });
-        return url;
-    };
-
     Utils.ArrayToCollection = function(array, collection){
         if(array.length){
             array.map(function(obj){

http://git-wip-us.apache.org/repos/asf/ambari/blob/154f678d/contrib/views/storm/src/main/resources/view.xml
----------------------------------------------------------------------
diff --git a/contrib/views/storm/src/main/resources/view.xml 
b/contrib/views/storm/src/main/resources/view.xml
index 0e83ec2..105b3eb 100644
--- a/contrib/views/storm/src/main/resources/view.xml
+++ b/contrib/views/storm/src/main/resources/view.xml
@@ -22,15 +22,15 @@ limitations under the License. Kerberos, LDAP, Custom. 
Binary/Htt
   <description>Ambari view for Apache Storm</description>
   <parameter>
        <name>storm.host</name>
-       <description>Enter the Storm host name for accessing Storm. Host must 
be accessible from Ambari Server.</description>
-       <label>Storm Hostname</label>
+        <description>Enter the Storm UI Server hostname for accessing Storm. 
Host must be accessible from Ambari Server.</description>
+        <label>Storm UI Server Hostname</label>
        <placeholder>storm-host.example.com</placeholder>
        <required>true</required>
   </parameter>
   <parameter>
        <name>storm.port</name>
-       <description>Enter the Storm port for accessing Storm.</description>
-       <label>Storm Port</label>
+        <description>Enter the Storm UI Server port for accessing 
Storm.</description>
+        <label>Storm UI Server Port</label>
        <placeholder>8744</placeholder>
        <required>true</required>
   </parameter>

Reply via email to