Skip to content

Commit

Permalink
AMBARI-19351. ambari-web action to download all client configs of hos…
Browse files Browse the repository at this point in the history
…t. (jaimin)
  • Loading branch information
Jetly-Jaimin committed Jan 4, 2017
1 parent e96dee0 commit 4253a61
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 21 deletions.
13 changes: 12 additions & 1 deletion ambari-web/app/controllers/main/host/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -2592,7 +2592,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
});
},

Expand Down
2 changes: 1 addition & 1 deletion ambari-web/app/controllers/main/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
},

/**
Expand Down
2 changes: 1 addition & 1 deletion ambari-web/app/controllers/main/service/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,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
});
},

Expand Down
1 change: 1 addition & 0 deletions ambari-web/app/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,7 @@ Em.I18n.translations = {
'host.host.details.installClients': 'Install clients',
'host.host.details.reinstallClients': 'Reinstall clients',
'host.host.details.checkHost': 'Check host',
'host.host.details.downloadAllClients': 'All Clients On Host',

'host.host.componentFilter.master':'Master Components',
'host.host.componentFilter.slave':'Slave Components',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,60 @@ 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;
}

});
5 changes: 5 additions & 0 deletions ambari-web/app/templates/main/host/details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=":glyphicon :glyphicon-download-alt"}}></i>
{{t services.service.downloadAllClientConfigs}}
Expand Down
2 changes: 2 additions & 0 deletions ambari-web/app/views/main/host/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
25 changes: 22 additions & 3 deletions ambari-web/test/controllers/main/host/details_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2439,14 +2439,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;
});
});
Expand Down
4 changes: 2 additions & 2 deletions ambari-web/test/controllers/main/service/item_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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;
});
});
Expand Down

0 comments on commit 4253a61

Please sign in to comment.