Browse Source

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

Sriharsha Chintalapani 8 years ago
parent
commit
2407751072

+ 10 - 2
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);

+ 3 - 3
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);

+ 0 - 25
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){

+ 4 - 4
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>