You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2014/02/28 21:13:08 UTC
git commit: AMBARI-4791. API call to restart all components on one or
more hosts should result in one request. (onechiporenko via yusaku)
Repository: ambari
Updated Branches:
refs/heads/trunk 778f59e97 -> a8be41bf7
AMBARI-4791. API call to restart all components on one or more hosts should result in one request. (onechiporenko via yusaku)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a8be41bf
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a8be41bf
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a8be41bf
Branch: refs/heads/trunk
Commit: a8be41bf7210c050c10354e633d127e6680d491d
Parents: 778f59e
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Fri Feb 28 12:12:38 2014 -0800
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Fri Feb 28 12:13:02 2014 -0800
----------------------------------------------------------------------
ambari-web/app/utils/ajax.js | 28 +++----
.../app/utils/batch_scheduled_requests.js | 38 ++++++----
.../test/utils/batch_scheduled_requests_test.js | 78 ++++++++++++++++++++
3 files changed, 114 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/a8be41bf/ambari-web/app/utils/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax.js b/ambari-web/app/utils/ajax.js
index 6a17f41..02ceb25 100644
--- a/ambari-web/app/utils/ajax.js
+++ b/ambari-web/app/utils/ajax.js
@@ -1186,7 +1186,7 @@ var urls = {
'wizard.step9.installer.get_host_status': {
'real': '/clusters/{cluster}/hosts?fields=Hosts/host_state,host_components/HostRoles/state',
'mock': '/data/wizard/deploy/5_hosts/get_host_status.json',
- 'format': function (data, opt) {
+ 'format': function () {
return {
async: false
};
@@ -1404,22 +1404,18 @@ var urls = {
'real': '/clusters/{clusterName}/request_schedules/{request_schedule_id}',
'mock': ''
},
- 'restart.service.hostComponents' : {
- 'real' : '/clusters/{clusterName}/requests',
- 'mock' : '',
- 'format' : function(data) {
- var componentDisplayName = App.format.role(data.componentName);
- var serviceDisplayName = App.Service.DisplayNames[data.serviceName];
+ 'restart.hostComponents': {
+ 'real':'/clusters/{clusterName}/requests',
+ 'mock':'',
+ 'format': function(data) {
return {
type : 'POST',
data : JSON.stringify({
- "RequestInfo" : {
- "context" : Em.I18n.t('restart.service.rest.context').format(componentDisplayName),
- "command" : "RESTART",
- "service_name" : data.serviceName,
- "component_name" : data.componentName,
- "hosts" : data.hosts
- }
+ "RequestInfo": {
+ "command": "RESTART",
+ "context": data.context
+ },
+ "Requests/resource_filters": data.resource_filters
})
}
}
@@ -1511,7 +1507,7 @@ var urls = {
'mock': '/data/mirroring/succeeded.json',
'apiPrefix': '',
'type': 'DELETE',
- 'format': function (data) {
+ 'format': function () {
return {
dataType: 'xml'
}
@@ -1536,7 +1532,7 @@ var urls = {
'mock': '/data/mirroring/succeeded.json',
'apiPrefix': '',
'type': 'POST',
- 'format': function (data) {
+ 'format': function () {
return {
dataType: 'xml'
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/a8be41bf/ambari-web/app/utils/batch_scheduled_requests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/batch_scheduled_requests.js b/ambari-web/app/utils/batch_scheduled_requests.js
index c8cd2dd..c87f4e8 100644
--- a/ambari-web/app/utils/batch_scheduled_requests.js
+++ b/ambari-web/app/utils/batch_scheduled_requests.js
@@ -80,7 +80,7 @@ module.exports = {
/**
* Restart list of host components
- * @param {Array} hostComponentsList list of host components should be restarted
+ * @param {*} hostComponentsList list of host components should be restarted
*/
restartHostComponents: function(hostComponentsList) {
/**
@@ -100,22 +100,32 @@ module.exports = {
}
componentToHostsMap[componentName].push(hc.get('host.hostName'));
});
+ var resource_filters = [];
for (var componentName in componentToHostsMap) {
- App.ajax.send({
- name: 'restart.service.hostComponents',
- sender: {
- successCallback: defaultSuccessCallback,
- errorCallback: defaultErrorCallback
- },
- data: {
- serviceName: componentServiceMap[componentName],
- componentName: componentName,
+ if (componentToHostsMap.hasOwnProperty(componentName)) {
+ resource_filters.push({
+ service_name: componentServiceMap[componentName],
+ component_name: componentName,
hosts: componentToHostsMap[componentName].join(",")
- },
- success: 'successCallback',
- error: 'errorCallback'
- });
+ });
+ }
+ }
+ if (!resource_filters.length) {
+ return;
}
+ App.ajax.send({
+ name: 'restart.hostComponents',
+ sender: {
+ successCallback: defaultSuccessCallback,
+ errorCallback: defaultErrorCallback
+ },
+ data: {
+ context: 'RESTART ' + Em.keys(componentToHostsMap).map(function(componentName) {return App.format.components[componentName];}).join(', '),
+ resource_filters: resource_filters
+ },
+ success: 'successCallback',
+ error: 'errorCallback'
+ });
},
/**
http://git-wip-us.apache.org/repos/asf/ambari/blob/a8be41bf/ambari-web/test/utils/batch_scheduled_requests_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/utils/batch_scheduled_requests_test.js b/ambari-web/test/utils/batch_scheduled_requests_test.js
index 1964696..714b8c6 100644
--- a/ambari-web/test/utils/batch_scheduled_requests_test.js
+++ b/ambari-web/test/utils/batch_scheduled_requests_test.js
@@ -118,4 +118,82 @@ describe('batch_scheduled_requests', function() {
});
+ describe('#restartHostComponents', function() {
+
+ beforeEach(function() {
+ sinon.spy($, 'ajax');
+ App.testMode = true;
+ });
+
+ afterEach(function() {
+ $.ajax.restore();
+ App.testMode = false;
+ });
+
+ var tests = Em.A([
+ {
+ hostComponentList: Em.A([
+ Em.Object.create({
+ componentName: 'n1',
+ host: Em.Object.create({
+ hostName: 'h1'
+ })
+ }),
+ Em.Object.create({
+ componentName: 'n1',
+ host: Em.Object.create({
+ hostName: 'h2'
+ })
+ })
+ ]),
+ e: {
+ ajaxCalledOnce: true,
+ resource_filters: [{"component_name":"n1","hosts":"h1,h2"}]
+ },
+ m: '1 component on 2 hosts'
+ },
+ {
+ hostComponentList: Em.A([
+ Em.Object.create({
+ componentName: 'n1',
+ host: Em.Object.create({
+ hostName: 'h1'
+ })
+ }),
+ Em.Object.create({
+ componentName: 'n1',
+ host: Em.Object.create({
+ hostName: 'h2'
+ })
+ }),
+ Em.Object.create({
+ componentName: 'n2',
+ host: Em.Object.create({
+ hostName: 'h2'
+ })
+ })
+ ]),
+ e: {
+ ajaxCalledOnce: true,
+ resource_filters: [{"component_name":"n1","hosts":"h1,h2"},{"component_name":"n2","hosts":"h2"}]
+ },
+ m: '1 component on 2 hosts, 1 on 1 host'
+ }
+ ]);
+
+ tests.forEach(function(test) {
+ it(test.m, function() {
+ batchUtils.restartHostComponents(test.hostComponentList);
+ expect($.ajax.calledOnce).to.equal(test.e.ajaxCalledOnce);
+ expect( JSON.parse($.ajax.args[0][0].data)['Requests/resource_filters']).to.eql(test.e.resource_filters);
+ });
+ });
+
+ it('Empty data', function() {
+ batchUtils.restartHostComponents([]);
+ expect($.ajax.called).to.equal(false);
+ });
+
+ });
+
});