Repository: ambari Updated Branches: refs/heads/branch-2.5 5cd4d0ee9 -> a526a07cb
AMBARI-20442. Knox proxy - Navigating to Hive view from Hive Summary page is not working (Go to view link) (alexantonenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a526a07c Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a526a07c Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a526a07c Branch: refs/heads/branch-2.5 Commit: a526a07cb63155d6f3c218006f2932eb8b4ebebe Parents: 5cd4d0e Author: Alex Antonenko <hiv...@gmail.com> Authored: Tue Mar 14 14:46:53 2017 +0200 Committer: Alex Antonenko <hiv...@gmail.com> Committed: Tue Mar 14 17:35:53 2017 +0200 ---------------------------------------------------------------------- ambari-web/app/assets/test/tests.js | 1 + .../controllers/main/service/info/summary.js | 2 +- .../app/controllers/main/views_controller.js | 32 ++++---- ambari-web/app/models.js | 1 + ambari-web/app/models/view_instance.js | 81 ++++++++++++++++++++ .../templates/main/service/services/hive.hbs | 2 +- .../app/views/main/service/services/hive.js | 14 ++-- .../controllers/main/views_controller_test.js | 38 ++++++--- ambari-web/test/models/view_instance_test.js | 59 ++++++++++++++ 9 files changed, 193 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/a526a07c/ambari-web/app/assets/test/tests.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js index 11ab9a5..3fd3157 100644 --- a/ambari-web/app/assets/test/tests.js +++ b/ambari-web/app/assets/test/tests.js @@ -386,6 +386,7 @@ var files = [ 'test/models/stack_test', 'test/models/stack_service_test', 'test/models/user_test', + 'test/models/view_instance_test', 'test/models/widget_test', 'test/models/widget_property_test', 'test/models/host_stack_version_test', http://git-wip-us.apache.org/repos/asf/ambari/blob/a526a07c/ambari-web/app/controllers/main/service/info/summary.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/info/summary.js b/ambari-web/app/controllers/main/service/info/summary.js index 7327255..4d21b10 100644 --- a/ambari-web/app/controllers/main/service/info/summary.js +++ b/ambari-web/app/controllers/main/service/info/summary.js @@ -855,7 +855,7 @@ App.MainServiceInfoSummaryController = Em.Controller.extend(App.WidgetSectionMix }, goToView: function(event) { - App.router.route('main' + event.context.href); + App.router.route(event.context.get('internalAmbariUrl')); } }); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/a526a07c/ambari-web/app/controllers/main/views_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/views_controller.js b/ambari-web/app/controllers/main/views_controller.js index e2e9281..8af470a 100644 --- a/ambari-web/app/controllers/main/views_controller.js +++ b/ambari-web/app/controllers/main/views_controller.js @@ -78,19 +78,20 @@ App.MainViewsController = Em.Controller.extend({ data.items.forEach(function (view) { view.versions.forEach(function (version) { version.instances.forEach(function (instance) { - var current_instance = Em.Object.create({ - iconPath: instance.ViewInstanceInfo.icon_path || "/img/ambari-view-default.png", - label: instance.ViewInstanceInfo.label || version.ViewVersionInfo.label || instance.ViewInstanceInfo.view_name, - visible: instance.ViewInstanceInfo.visible || false, - version: instance.ViewInstanceInfo.version, - description: instance.ViewInstanceInfo.description || Em.I18n.t('views.main.instance.noDescription'), - viewName: instance.ViewInstanceInfo.view_name, - shortUrl:instance.ViewInstanceInfo.short_url, - instanceName: instance.ViewInstanceInfo.instance_name, - href: instance.ViewInstanceInfo.context_path + "/" + var info = instance.ViewInstanceInfo; + var currentInstance = App.ViewInstance.create({ + iconPath: info.icon_path || '/img/ambari-view-default.png', + label: info.label || version.ViewVersionInfo.label || info.view_name, + visible: info.visible || false, + version: info.version, + description: info.description || Em.I18n.t('views.main.instance.noDescription'), + viewName: info.view_name, + shortUrl:info.short_url, + instanceName: info.instance_name, + href: info.context_path + '/' }); - if (current_instance.visible) { - instances.push(current_instance); + if (currentInstance.visible) { + instances.push(currentInstance); } }, this); }, this); @@ -106,10 +107,7 @@ App.MainViewsController = Em.Controller.extend({ setView: function (event) { if (event.context) { - if(event.context.shortUrl){ - App.router.route('main/view/' + event.context.viewName + '/' + event.context.shortUrl); - } else { - App.router.route('main/views/' + event.context.viewName + '/' + event.context.version + '/' + event.context.instanceName); - }} + App.router.route(event.context.get('internalAmbariUrl')); + } } }); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/a526a07c/ambari-web/app/models.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models.js b/ambari-web/app/models.js index e0168a2..3b86782 100644 --- a/ambari-web/app/models.js +++ b/ambari-web/app/models.js @@ -78,6 +78,7 @@ require('models/configs/theme/config_action'); require('models/configs/objects/service_config'); require('models/configs/objects/service_config_category'); require('models/configs/objects/service_config_property'); +require('models/view_instance'); require('models/widget'); require('models/widget_property'); require('models/widget_layout'); http://git-wip-us.apache.org/repos/asf/ambari/blob/a526a07c/ambari-web/app/models/view_instance.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/view_instance.js b/ambari-web/app/models/view_instance.js new file mode 100644 index 0000000..d438640 --- /dev/null +++ b/ambari-web/app/models/view_instance.js @@ -0,0 +1,81 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +var App = require('app'); + +App.ViewInstance = Em.Object.extend({ + + /** + * @type {string} + */ + iconPath: '', + + /** + * @type {string} + */ + label: '', + + /** + * @type {boolean} + */ + visible: false, + + /** + * @type {string} + */ + version: '', + + /** + * @type {string} + */ + description: '', + + /** + * @type {string} + */ + viewName: '', + + /** + * @type {string} + */ + shortUrl: '', + + /** + * @type {string} + */ + instanceName: '', + + /** + * @type {string} + */ + href: '', + + /** + * @type {string} + */ + internalAmbariUrl: function () { + var shortUrl = this.get('shortUrl'); + var viewName = this.get('viewName'); + var version = this.get('version'); + var instanceName = this.get('instanceName'); + if(shortUrl) { + return 'main/view/' + viewName + '/' + shortUrl; + } + return 'main/views/' + viewName + '/' + version + '/' + instanceName; + }.property('shortUrl', 'viewName', 'version', 'instanceName') +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/a526a07c/ambari-web/app/templates/main/service/services/hive.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/service/services/hive.hbs b/ambari-web/app/templates/main/service/services/hive.hbs index 1b26091..252499c 100644 --- a/ambari-web/app/templates/main/service/services/hive.hbs +++ b/ambari-web/app/templates/main/service/services/hive.hbs @@ -40,7 +40,7 @@ <tr> <td class="summary-label">{{link.label}}</td> <td class="summary-value" > - <a href="#" target="_blank" {{action goToView link target="controller"}}>{{t app.goToView}}</a> + <a href="#" target="_blank" {{action goToView link.viewInstance target="controller"}}>{{t app.goToView}}</a> </td> </tr> {{/each}} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/a526a07c/ambari-web/app/views/main/service/services/hive.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/service/services/hive.js b/ambari-web/app/views/main/service/services/hive.js index e473c62..bcac2dd 100644 --- a/ambari-web/app/views/main/service/services/hive.js +++ b/ambari-web/app/views/main/service/services/hive.js @@ -30,15 +30,15 @@ App.MainDashboardServiceHiveView = App.MainDashboardServiceView.extend({ viewLinks: function() { var viewsToShow = this.get('viewsToShow'); var links = []; - App.router.get('mainViewsController.ambariViews').forEach(function(item) { - var view = viewsToShow[item.get('instanceName')]; - if (view) { + App.router.get('mainViewsController.ambariViews').forEach(function(viewInstance) { + var viewMeta = viewsToShow[viewInstance.get('instanceName')]; + if (viewMeta) { var link = { - href: item.href, - label: item.label + viewInstance: viewInstance, + label: viewInstance.get('label') }; - if (view.overwriteLabel) { - link.label = Em.I18n.t(view.overwriteLabel); + if (viewMeta.overwriteLabel) { + link.label = Em.I18n.t(viewMeta.overwriteLabel); } links.push(link); } http://git-wip-us.apache.org/repos/asf/ambari/blob/a526a07c/ambari-web/test/controllers/main/views_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/views_controller_test.js b/ambari-web/test/controllers/main/views_controller_test.js index 4242750..0ab7654 100644 --- a/ambari-web/test/controllers/main/views_controller_test.js +++ b/ambari-web/test/controllers/main/views_controller_test.js @@ -103,16 +103,32 @@ describe('MainViewsController', function () { ] }; - it("should parse view instance data", function () { + var viewInstanceFields = { + iconPath: 'icon_path1', + label: 'label1', + visible: true, + version: '1.0', + description: 'desc1', + href: 'path1/' + }; + + beforeEach(function () { mainViewsController.loadViewInstancesSuccess(data); - expect(JSON.parse(JSON.stringify(mainViewsController.get('ambariViews')))).to.be.eql([{ - "iconPath": "icon_path1", - "label": "label1", - "visible": true, - "version": "1.0", - "description": "desc1", - "href": "path1/" - }]); + }); + + it('one view instance is parsed', function () { + expect(mainViewsController.get('ambariViews.length')).to.be.equal(1); + }); + + + Object.keys(viewInstanceFields).forEach(function (fieldName) { + it(JSON.stringify(fieldName) + ' is set correctly', function () { + expect(mainViewsController.get('ambariViews.firstObject.' + fieldName)).to.be.equal(viewInstanceFields[fieldName]); + }); + }); + + + it('`isDataLoaded` is set `true` when view instances are parsed', function () { expect(mainViewsController.get('isDataLoaded')).to.be.true; }); }); @@ -142,11 +158,11 @@ describe('MainViewsController', function () { it("context exist", function () { mainViewsController.setView({ - context: { + context: App.ViewInstance.create({ viewName: 'view1', version: '1', instanceName: 'instance1' - } + }) }); expect(App.router.route.calledWith('main/views/view1/1/instance1')).to.be.true; }); http://git-wip-us.apache.org/repos/asf/ambari/blob/a526a07c/ambari-web/test/models/view_instance_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/view_instance_test.js b/ambari-web/test/models/view_instance_test.js new file mode 100644 index 0000000..0e977e3 --- /dev/null +++ b/ambari-web/test/models/view_instance_test.js @@ -0,0 +1,59 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +var model; + +describe('App.ViewInstance', function () { + + beforeEach(function () { + model = App.ViewInstance.create(); + }); + + describe('#internalAmbariUrl', function () { + + [ + { + props: { + shortUrl: '', + viewName: 'CAPACITY-SCHEDULER', + version: '1.0.0', + instanceName: 'AUTO_CS_INSTANCE' + }, + e: 'main/views/CAPACITY-SCHEDULER/1.0.0/AUTO_CS_INSTANCE', + m: '`shortUrl` does not exist' + }, + { + props: { + shortUrl: 'auto_cs_instance', + viewName: 'CAPACITY-SCHEDULER', + version: '1.0.0', + instanceName: 'AUTO_CS_INSTANCE' + }, + e: 'main/view/CAPACITY-SCHEDULER/auto_cs_instance', + m: '`shortUrl` exists' + } + ].forEach(function (test) { + it(test.m, function () { + model.setProperties(test.props); + expect(model.get('internalAmbariUrl')).to.be.equal(test.e); + }); + }); + + }); + +}); \ No newline at end of file