Przeglądaj źródła

AMBARI-17295. Views in Ambari UI don't render when proxied by Knox-contrib views (pallavkul)

Pallav Kulshreshtha 9 lat temu
rodzic
commit
0d39d996cb

+ 7 - 7
contrib/views/capacity-scheduler/src/main/resources/ui/app/adapters.js

@@ -28,11 +28,11 @@ function _getCapacitySchedulerViewUri(adapter) {
     return "/data";
 
   var parts = window.location.pathname.match(/[^\/]*/g).filterBy('').removeAt(0),
-      view = parts[0],
-      version = parts[1],
-      instance = parts[2];
-  if (parts.length == 2) { // version is not present
-    instance = parts[1];
+      view = parts[parts.length - 3],
+      version = parts[parts.length - 2],
+      instance = parts[parts.length - 1];
+  if (!/^(\d+\.){2,3}\d+$/.test(parts[parts.length - 2])) { // version is not present
+    instance = parts[parts.length - 2];
     version = '';
   }
 
@@ -77,7 +77,7 @@ function _ajax(url, type, hash) {
 
 App.ConfigAdapter = DS.Adapter.extend({
   defaultSerializer:'config',
-  namespace: 'api/v1',
+  namespace: 'api/v1'.replace(/^\//, ''),
   findQuery : function(store, type, query){
     var adapter = this;
     var uri = [_getCapacitySchedulerViewUri(this),'getConfig'].join('/') + "?siteName=" + query.siteName + "&configName="+ query.configName;
@@ -99,7 +99,7 @@ App.ConfigAdapter = DS.Adapter.extend({
 App.QueueAdapter = DS.Adapter.extend({
   defaultSerializer:'queue',
   PREFIX: "yarn.scheduler.capacity",
-  namespace: 'api/v1',
+  namespace: 'api/v1'.replace(/^\//, ''),
   queues: [],
 
   createRecord: function(store, type, record) {

+ 10 - 7
contrib/views/files/src/main/resources/ui/app/adapters/application.js

@@ -21,15 +21,18 @@ import Ember from 'ember';
 
 export default DS.RESTAdapter.extend({
   namespace: Ember.computed(function() {
-    var parts = window.location.pathname.match(/\/[^\/]*/g);
-    var view = parts[1];
-    var version = '/versions' + parts[2];
-    var instance = parts[3];
-    if (parts.length === 4) { // version is not present
-      instance = parts[2];
+    var parts = window.location.pathname.split('/').filter(function(i) {
+      return i !== "";
+    });
+    var view = parts[parts.length - 3];
+    var version = '/versions/' + parts[parts.length - 2];
+    var instance = parts[parts.length - 1];
+
+    if (!/^(\d+\.){2,3}\d+$/.test(parts[parts.length - 2])) { // version is not present
+      instance = parts[parts.length - 2];
       version = '';
     }
-    return 'api/v1/views' + view + version + '/instances' + instance + '/resources/files/fileops';
+    return 'api/v1/views/' + view + version + '/instances/' + instance + '/resources/files/fileops';
   }),
 
   headers: {

+ 1 - 1
contrib/views/files/src/main/resources/ui/app/index.html

@@ -35,7 +35,7 @@
     {{content-for "body"}}
 
     <script src="assets/vendor.js"></script>
-    <script src="assets/files-view.js"></script>
+    <script src="assets/files-view.js" integrity=""></script>
 
     {{content-for "body-footer"}}
   </body>

+ 23 - 9
contrib/views/tez/src/main/resources/ui/ambari-scripts/init-view.js

@@ -18,17 +18,30 @@
 
 var PATH_PARAM_NAME = "viewPath";
 
+/**
+ * Returns view name, version and instance name from location.pathname
+ *
+ * @return {String[]} [view name, version, instance name]
+ */
+function getViewInfoFromPathname() {
+  return location.pathname.split('/').filter(function(i) {
+    return i !== "";
+  }).filter(function(i, index, arr) {
+    return index >= arr.length - 3;
+  });
+};
+
 /**
  * Constructs URL for fetching Ambari view instance parameters.
  * @return {String}
  */
 function getStatusURL() {
-  var urlParts = location.pathname.split('/');
+  var urlParts = getViewInfoFromPathname();
 
   return "/api/v1/views/%@/versions/%@/instances/%@/resources/status".fmt(
-    urlParts[2],
-    urlParts[3],
-    urlParts[4]
+    urlParts[0],
+    urlParts[1],
+    urlParts[2]
   );
 }
 
@@ -176,11 +189,12 @@ function getConfigs(parameters) {
       "//" +
       window.location.hostname +
       (window.location.port ? ':' + window.location.port: ''),
-      urlParts = location.pathname.split('/'),
-      resourcesPrefix = 'api/v1/views/%@/versions/%@/instances/%@/resources/'.fmt(
-        urlParts[2],
-        urlParts[3],
-        urlParts[4]
+      urlParts = getViewInfoFromPathname(),
+      // .replace() call is necessary to work properly behind the proxy
+      resourcesPrefix = '/api/v1/views/%@/versions/%@/instances/%@/resources/'.replace(/^\//, '').fmt(
+        urlParts[0],
+        urlParts[1],
+        urlParts[2]
       );
 
   parameters = parameters || {};