Repository: ambari Updated Branches: refs/heads/branch-2.4 f271f2cfb -> 0d39d996c
AMBARI-17295. Views in Ambari UI don't render when proxied by Knox-contrib views (pallavkul) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0d39d996 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0d39d996 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0d39d996 Branch: refs/heads/branch-2.4 Commit: 0d39d996cb6fc0008f237746a42ac63103a0d032 Parents: f271f2c Author: Pallav Kulshreshtha <[email protected]> Authored: Fri Jul 22 00:10:37 2016 +0530 Committer: Pallav Kulshreshtha <[email protected]> Committed: Fri Jul 22 00:12:04 2016 +0530 ---------------------------------------------------------------------- .../src/main/resources/ui/app/adapters.js | 14 ++++----- .../resources/ui/app/adapters/application.js | 17 ++++++----- .../files/src/main/resources/ui/app/index.html | 2 +- .../resources/ui/ambari-scripts/init-view.js | 32 ++++++++++++++------ 4 files changed, 41 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/0d39d996/contrib/views/capacity-scheduler/src/main/resources/ui/app/adapters.js ---------------------------------------------------------------------- diff --git a/contrib/views/capacity-scheduler/src/main/resources/ui/app/adapters.js b/contrib/views/capacity-scheduler/src/main/resources/ui/app/adapters.js index 5c92ac7..86c1484 100644 --- a/contrib/views/capacity-scheduler/src/main/resources/ui/app/adapters.js +++ b/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) { http://git-wip-us.apache.org/repos/asf/ambari/blob/0d39d996/contrib/views/files/src/main/resources/ui/app/adapters/application.js ---------------------------------------------------------------------- diff --git a/contrib/views/files/src/main/resources/ui/app/adapters/application.js b/contrib/views/files/src/main/resources/ui/app/adapters/application.js index a7ccbf4..4042851 100644 --- a/contrib/views/files/src/main/resources/ui/app/adapters/application.js +++ b/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: { http://git-wip-us.apache.org/repos/asf/ambari/blob/0d39d996/contrib/views/files/src/main/resources/ui/app/index.html ---------------------------------------------------------------------- diff --git a/contrib/views/files/src/main/resources/ui/app/index.html b/contrib/views/files/src/main/resources/ui/app/index.html index 51d1839..4c3a786 100644 --- a/contrib/views/files/src/main/resources/ui/app/index.html +++ b/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> http://git-wip-us.apache.org/repos/asf/ambari/blob/0d39d996/contrib/views/tez/src/main/resources/ui/ambari-scripts/init-view.js ---------------------------------------------------------------------- diff --git a/contrib/views/tez/src/main/resources/ui/ambari-scripts/init-view.js b/contrib/views/tez/src/main/resources/ui/ambari-scripts/init-view.js index 8bbcf01..0e0bdee 100644 --- a/contrib/views/tez/src/main/resources/ui/ambari-scripts/init-view.js +++ b/contrib/views/tez/src/main/resources/ui/ambari-scripts/init-view.js @@ -19,16 +19,29 @@ 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 || {};
