Repository: ambari Updated Branches: refs/heads/branch-2.5 9d791119c -> e1ec5e95c
AMBARI-19351. ambai-web action to download all client configs of host. (jaimin) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e1ec5e95 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e1ec5e95 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e1ec5e95 Branch: refs/heads/branch-2.5 Commit: e1ec5e95cb99d64d14db53f3742ec0667491a9aa Parents: 9d79111 Author: Jaimin Jetly <[email protected]> Authored: Wed Jan 4 11:35:13 2017 -0800 Committer: Jaimin Jetly <[email protected]> Committed: Wed Jan 4 11:35:13 2017 -0800 ---------------------------------------------------------------------- ambari-web/app/controllers/main/host/details.js | 13 +++++- ambari-web/app/controllers/main/service.js | 2 +- ambari-web/app/controllers/main/service/item.js | 2 +- ambari-web/app/messages.js | 1 + .../details/support_client_configs_download.js | 49 +++++++++++++++----- ambari-web/app/templates/main/host/details.hbs | 5 ++ .../main/service/all_services_actions.hbs | 2 +- ambari-web/app/views/main/host/details.js | 2 + .../test/controllers/main/host/details_test.js | 25 ++++++++-- .../test/controllers/main/service/item_test.js | 4 +- 10 files changed, 84 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/e1ec5e95/ambari-web/app/controllers/main/host/details.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/host/details.js b/ambari-web/app/controllers/main/host/details.js index ca033f2..a17ef70 100644 --- a/ambari-web/app/controllers/main/host/details.js +++ b/ambari-web/app/controllers/main/host/details.js @@ -2391,7 +2391,18 @@ App.MainHostDetailsController = Em.Controller.extend(App.SupportClientConfigsDow this.downloadClientConfigsCall({ hostName: event.context.get('hostName'), componentName: event.context.get('componentName'), - displayName: event.context.get('displayName') + resourceType: this.resourceTypeEnum.HOST_COMPONENT + }); + }, + + /** + * This controller action is called from the template when user clicks to download configs for "All Clients On Host" + */ + downloadAllClientConfigs: function () { + var self = this; + this.downloadClientConfigsCall({ + hostName: self.get('content.hostName'), + resourceType: this.resourceTypeEnum.HOST }); }, http://git-wip-us.apache.org/repos/asf/ambari/blob/e1ec5e95/ambari-web/app/controllers/main/service.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service.js b/ambari-web/app/controllers/main/service.js index e4d751d..6e68ec5 100644 --- a/ambari-web/app/controllers/main/service.js +++ b/ambari-web/app/controllers/main/service.js @@ -147,7 +147,7 @@ App.MainServiceController = Em.ArrayController.extend(App.SupportClientConfigsDo * Download client configs for all services */ downloadAllClientConfigs: function() { - this.downloadClientConfigsCall({downloadAll: true}); + this.downloadClientConfigsCall({resourceType: this.resourceTypeEnum.CLUSTER}); }, /** http://git-wip-us.apache.org/repos/asf/ambari/blob/e1ec5e95/ambari-web/app/controllers/main/service/item.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/item.js b/ambari-web/app/controllers/main/service/item.js index 18a121f..be3fac1 100644 --- a/ambari-web/app/controllers/main/service/item.js +++ b/ambari-web/app/controllers/main/service/item.js @@ -1091,7 +1091,7 @@ App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDow this.downloadClientConfigsCall({ serviceName: this.get('content.serviceName'), componentName: (event && event.name) || component.get('componentName'), - displayName: (event && event.label) || component.get('displayName') + resourceType: this.resourceTypeEnum.SERVICE_COMPONENT }); }, http://git-wip-us.apache.org/repos/asf/ambari/blob/e1ec5e95/ambari-web/app/messages.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js index a37b1c6..3642e5a 100644 --- a/ambari-web/app/messages.js +++ b/ambari-web/app/messages.js @@ -2615,6 +2615,7 @@ Em.I18n.translations = { 'hosts.host.details.setRackId':'Set Rack', 'host.host.details.installClients': 'Install clients', 'host.host.details.reinstallClients': 'Reinstall clients', + 'host.host.details.downloadAllClients': 'All Clients On Host', 'host.host.componentFilter.master':'Master Components', 'host.host.componentFilter.slave':'Slave Components', http://git-wip-us.apache.org/repos/asf/ambari/blob/e1ec5e95/ambari-web/app/mixins/main/host/details/support_client_configs_download.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mixins/main/host/details/support_client_configs_download.js b/ambari-web/app/mixins/main/host/details/support_client_configs_download.js index 58460f0..0b880b4 100644 --- a/ambari-web/app/mixins/main/host/details/support_client_configs_download.js +++ b/ambari-web/app/mixins/main/host/details/support_client_configs_download.js @@ -20,34 +20,59 @@ var App = require('app'); App.SupportClientConfigsDownload = Em.Mixin.create({ /** + * This object is supposed to be used as an enum for resource types supported by ambari + */ + resourceTypeEnum: Object.freeze({ + CLUSTER: "ClusterResource", + HOST: "HostResource", + SERVICE: "ServiceResource", + SERVICE_COMPONENT: "ServiceComponentResource", + HOST_COMPONENT: "HostComponentResource" + }), + + /** * - * @param {{hostName: string, componentName: string, displayName: string, serviceName: string}} data + * @param {{hostName: string, componentName: string, displayName: string, serviceName: string, resourceType: resourceTypeEnum}} data */ downloadClientConfigsCall: function (data) { - var url = this._getUrl(data.hostName, data.serviceName, data.componentName, data.downloadAll); + var url = this._getUrl(data.hostName, data.serviceName, data.componentName, data.resourceType); var newWindow = window.open(url); newWindow.focus(); }, - _getDownloadAllUrl: function () { - return App.get('apiPrefix') + '/clusters/' + App.router.getClusterName() + '/components?format=client_config_tar'; - }, /** * * @param {string|null} hostName * @param {string} serviceName * @param {string} componentName + * @param {string} resourceType * @returns {string} * @private */ - _getUrl: function (hostName, serviceName, componentName, downloadAll) { - if (downloadAll) { - return this._getDownloadAllUrl(); + _getUrl: function (hostName, serviceName, componentName, resourceType) { + var result; + var prefix = App.get('apiPrefix') + '/clusters/' + App.router.getClusterName() + '/'; + + switch (resourceType) { + case this.resourceTypeEnum.SERVICE_COMPONENT: + result = prefix + 'services/' + serviceName + '/components/' + componentName; + break; + case this.resourceTypeEnum.HOST_COMPONENT: + result = prefix + 'hosts/' + hostName + '/host_components/' + componentName; + break; + case this.resourceTypeEnum.HOST: + result = prefix + 'hosts/' + hostName + '/host_components'; + break; + case this.resourceTypeEnum.SERVICE: + result = prefix + 'services/' + serviceName + '/components'; + break; + case this.resourceTypeEnum.CLUSTER: + default: + result = prefix + 'components'; } - var isForHost = !Em.isNone(hostName); - return App.get('apiPrefix') + '/clusters/' + App.router.getClusterName() + '/' + - (isForHost ? 'hosts/' + hostName + '/host_components/' : 'services/' + serviceName + '/components/') + - componentName + '?format=client_config_tar'; + + result += '?format=client_config_tar'; + return result; } }); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/e1ec5e95/ambari-web/app/templates/main/host/details.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/host/details.hbs b/ambari-web/app/templates/main/host/details.hbs index f709612..99afcb3 100644 --- a/ambari-web/app/templates/main/host/details.hbs +++ b/ambari-web/app/templates/main/host/details.hbs @@ -51,6 +51,11 @@ <div class="dropdown-menu-wrap"> <ul class="dropdown-menu"> + {{#if view.hasManyClientsWithConfigs}} + <li> + <a id="all-clients-on-host-link" {{action "downloadAllClientConfigs" target="controller" href=true}}>{{t host.host.details.downloadAllClients}}</a> + </li> + {{/if}} {{#each client in view.clientsWithConfigs}} <li> <a {{action "downloadClientConfigs" client target="controller" href=true}}>{{client.displayName}}</a> http://git-wip-us.apache.org/repos/asf/ambari/blob/e1ec5e95/ambari-web/app/templates/main/service/all_services_actions.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/service/all_services_actions.hbs b/ambari-web/app/templates/main/service/all_services_actions.hbs index 80fd916..0ca1cd5 100644 --- a/ambari-web/app/templates/main/service/all_services_actions.hbs +++ b/ambari-web/app/templates/main/service/all_services_actions.hbs @@ -59,7 +59,7 @@ </li> {{/isAuthorized}} <li> - <a href="#" + <a href="#" id="all-clients-of-cluster-link" {{action "downloadAllClientConfigs" target="view.serviceController"}}> <i {{bindAttr class=":icon-download-alt"}}></i> {{t services.service.downloadAllClientConfigs}} http://git-wip-us.apache.org/repos/asf/ambari/blob/e1ec5e95/ambari-web/app/views/main/host/details.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/host/details.js b/ambari-web/app/views/main/host/details.js index 784e63c..dc39959 100644 --- a/ambari-web/app/views/main/host/details.js +++ b/ambari-web/app/views/main/host/details.js @@ -36,6 +36,8 @@ App.MainHostDetailsView = Em.View.extend({ }); }.property('content.hostComponents.@each'), + hasManyClientsWithConfigs: Em.computed.gt('clientsWithConfigs.length', 1), + isActive: Em.computed.equal('controller.content.passiveState', 'OFF'), maintenance: function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/e1ec5e95/ambari-web/test/controllers/main/host/details_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/host/details_test.js b/ambari-web/test/controllers/main/host/details_test.js index 154d0b2..3fde582 100644 --- a/ambari-web/test/controllers/main/host/details_test.js +++ b/ambari-web/test/controllers/main/host/details_test.js @@ -2497,14 +2497,33 @@ describe('App.MainHostDetailsController', function () { controller.downloadClientConfigs({ context: Em.Object.create({ componentName: 'name', - hostName: 'host1', - displayName: 'dName' + hostName: 'host1' }) }); expect(controller.downloadClientConfigsCall.calledWith({ componentName: 'name', hostName: 'host1', - displayName: 'dName' + resourceType: controller.resourceTypeEnum.HOST_COMPONENT + })).to.be.true; + }); + }); + + describe('#downloadAllClientConfigs', function () { + + beforeEach(function () { + sinon.stub(controller, 'downloadClientConfigsCall', Em.K); + sinon.stub(controller, 'get').withArgs('content.hostName').returns('host1'); + }); + afterEach(function () { + controller.downloadClientConfigsCall.restore(); + controller.get.restore(); + }); + + it('should launch controller.downloadClientConfigsCall method', function () { + controller.downloadAllClientConfigs(); + expect(controller.downloadClientConfigsCall.calledWith({ + hostName: 'host1', + resourceType: controller.resourceTypeEnum.HOST })).to.be.true; }); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/e1ec5e95/ambari-web/test/controllers/main/service/item_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/service/item_test.js b/ambari-web/test/controllers/main/service/item_test.js index 082fbd9..78ed0a6 100644 --- a/ambari-web/test/controllers/main/service/item_test.js +++ b/ambari-web/test/controllers/main/service/item_test.js @@ -1214,7 +1214,7 @@ describe('App.MainServiceItemController', function () { expect(mainServiceItemController.downloadClientConfigsCall.calledWith({ serviceName: 'S1', componentName: 'C1', - displayName: 'd1' + resourceType: mainServiceItemController.resourceTypeEnum.SERVICE_COMPONENT })).to.be.true; }); it('should launch $.fileDownload method, event passed', function () { @@ -1226,7 +1226,7 @@ describe('App.MainServiceItemController', function () { expect(mainServiceItemController.downloadClientConfigsCall.calledWith({ serviceName: 'S1', componentName: 'name1', - displayName: 'label1' + resourceType: mainServiceItemController.resourceTypeEnum.SERVICE_COMPONENT })).to.be.true; }); });
