Repository: ambari Updated Branches: refs/heads/trunk 4ccf720aa -> 3b97791b0
AMBARI-5097. Retry failure after installation failure triggers start all services request. (jaimin) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/3b97791b Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3b97791b Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3b97791b Branch: refs/heads/trunk Commit: 3b97791b032a75c3be899b80a6a425983592bbf9 Parents: 4ccf720 Author: Jaimin Jetly <[email protected]> Authored: Fri Mar 14 17:53:48 2014 -0700 Committer: Jaimin Jetly <[email protected]> Committed: Fri Mar 14 17:54:17 2014 -0700 ---------------------------------------------------------------------- .../app/controllers/wizard/step9_controller.js | 57 ++++++++++------- ambari-web/app/utils/ajax.js | 2 +- ambari-web/test/installer/step9_test.js | 64 +++++++++++++++++++- 3 files changed, 100 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/3b97791b/ambari-web/app/controllers/wizard/step9_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/wizard/step9_controller.js b/ambari-web/app/controllers/wizard/step9_controller.js index d84ed93..40eb5d9 100644 --- a/ambari-web/app/controllers/wizard/step9_controller.js +++ b/ambari-web/app/controllers/wizard/step9_controller.js @@ -126,7 +126,9 @@ App.WizardStep9Controller = Em.Controller.extend({ * Observer function: Enables previous steps link if install task failed in installer wizard. */ togglePreviousSteps: function () { - if ('INSTALL FAILED' === this.get('content.cluster.status') && this.get('content.controllerName') == 'installerController') { + if (App.testMode) { + return; + } else if ('INSTALL FAILED' === this.get('content.cluster.status') && this.get('content.controllerName') == 'installerController') { App.router.get('installerController').setStepsEnable(); } else { App.router.get('installerController').setLowerStepsDisable(9); @@ -546,7 +548,7 @@ App.WizardStep9Controller = Em.Controller.extend({ isCompleted: false }; this.hostHasClientsOnly(false); - App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus); + this.saveClusterStatus(clusterStatus); } else { console.log('ERROR: Error occurred in parsing JSON data'); this.hostHasClientsOnly(true); @@ -555,7 +557,7 @@ App.WizardStep9Controller = Em.Controller.extend({ isStartError: false, isCompleted: true }; - App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus); + this.saveClusterStatus(clusterStatus); this.set('status', 'success'); this.set('progress', '100'); } @@ -603,11 +605,7 @@ App.WizardStep9Controller = Em.Controller.extend({ isStartError: false, isCompleted: false }; - if (App.testMode) { - this.set('content.cluster', clusterStatus); - } else { - App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus); - } + this.saveClusterStatus(clusterStatus); this.get('hosts').forEach(function (host) { host.set('progress', '100'); }); @@ -812,8 +810,8 @@ App.WizardStep9Controller = Em.Controller.extend({ } else { clusterStatus.status = 'START FAILED'; // 'START FAILED' implies to step10 that installation was successful but start failed } - App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus); - App.router.get(this.get('content.controllerName')).saveInstalledHosts(this); + this.saveClusterStatus(clusterStatus); + this.saveInstalledHosts(this); return true; } return false; @@ -833,14 +831,12 @@ App.WizardStep9Controller = Em.Controller.extend({ }; if (this.get('status') === 'failed') { clusterStatus.status = 'INSTALL FAILED'; + this.saveClusterStatus(clusterStatus); this.set('progress', '100'); this.get('hosts').forEach(function (host) { - if (host.get('status') !== 'failed' && host.get('status') !== 'warning') { - this.isAllComponentsInstalled(); - } host.set('progress', '100'); - }, this); - App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus); + }); + this.isAllComponentsInstalled(); } else { this.set('progress', '34'); if (this.get('content.controllerName') === 'installerController') { @@ -849,7 +845,7 @@ App.WizardStep9Controller = Em.Controller.extend({ this.launchStartServices(); } } - App.router.get(this.get('content.controllerName')).saveInstalledHosts(this); + this.saveInstalledHosts(this); return true; } return false; @@ -1133,7 +1129,6 @@ App.WizardStep9Controller = Em.Controller.extend({ isCompleted: false }; var hostsWithHeartbeatLost = []; - var hostComponents = jsonData.items.mapProperty('host_components'); jsonData.items.filterProperty('Hosts.host_state', 'HEARTBEAT_LOST').forEach(function (host) { var hostComponentObj = {hostName: host.Hosts.host_name}; var componentArr = []; @@ -1155,9 +1150,7 @@ App.WizardStep9Controller = Em.Controller.extend({ host.set('progress', '100'); }); this.set('progress', '100'); - if (!App.testMode) { - App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus); - } + this.saveClusterStatus(clusterStatus); } else if (this.get('content.cluster.status') === 'PENDING') { this.launchStartServices(); } @@ -1181,7 +1174,7 @@ App.WizardStep9Controller = Em.Controller.extend({ host.set('progress', '100'); } }); - App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus); + this.saveClusterStatus(clusterStatus); }, /** @@ -1203,5 +1196,27 @@ App.WizardStep9Controller = Em.Controller.extend({ } }, this); return label; + }, + + /** + * save cluster status in the parentController and localdb + * @param clusterStatus {Object} + */ + saveClusterStatus: function(clusterStatus) { + if (!App.testMode) { + App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus); + } else { + this.set('content.cluster',clusterStatus); + } + }, + + /** + * save cluster status in the parentController and localdb + * @param context + */ + saveInstalledHosts: function(context) { + if (!App.testMode) { + App.router.get(this.get('content.controllerName')).saveInstalledHosts(context) + } } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/3b97791b/ambari-web/app/utils/ajax.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/ajax.js b/ambari-web/app/utils/ajax.js index 6bed45b..98d0e83 100644 --- a/ambari-web/app/utils/ajax.js +++ b/ambari-web/app/utils/ajax.js @@ -1229,7 +1229,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', + 'mock': '/data/wizard/deploy/5_hosts/get_host_state.json', 'format': function () { return { async: false http://git-wip-us.apache.org/repos/asf/ambari/blob/3b97791b/ambari-web/test/installer/step9_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/installer/step9_test.js b/ambari-web/test/installer/step9_test.js index bd760e8..618de88 100644 --- a/ambari-web/test/installer/step9_test.js +++ b/ambari-web/test/installer/step9_test.js @@ -1121,7 +1121,69 @@ describe('App.InstallerStep9Controller', function () { }); }); }); - }) + }); + + // isServicesInstalled is called after every poll for "Install All Services" request. + // This function should result into a call to "Start All Services" request only if install request completed successfully. + describe('#isServicesInstalled', function () { + + var hostStateJsonData = { + "items" : [ + { + "Hosts" : { + "cluster_name" : "c1", + "host_name" : "ambari-1.c.apache.internal", + "host_state" : "HEALTHY" + }, + "host_components" : [ + { + "HostRoles" : { + "cluster_name" : "c1", + "component_name" : "GANGLIA_MONITOR", + "host_name" : "ambari-1.c.apache.internal", + "state" : "STARTED" + } + } + ] + } + ] + }; + var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), + Em.Object.create({name: 'host2', progress: '33', status: 'info'})]); + // polledData has all hosts with status completed to trigger transition from install->start request. + var polledData = Em.A([Em.Object.create({Tasks: {name: 'host1', status: 'COMPLETED'}}), + Em.Object.create({Tasks: {name: 'host2', status: 'COMPLETED'}})]); + var controller = App.WizardStep9Controller.create({hosts: hosts, content: {controllerName: 'installerController', + cluster: {status: 'PENDING',name: 'c1'}},launchStartServices: function() {return true;}}); + var tests = Em.A([ + // controller has "status" value as "info" initially. If no errors are encountered then wizard stages + // transition info->success, on error info->error, on warning info->warning + {status: 'info' , e:{startServicesCalled:true}, m:'If no failed tasks then start services request should be called'}, + {status: 'failed', e:{startServicesCalled:false}, m: 'If install request has failed tasks then start services call should not be called'} + ]); + + beforeEach(function() { + App.testMode = true; + sinon.spy(controller, 'launchStartServices'); + sinon.stub($, 'ajax').yieldsTo('success', hostStateJsonData); + }); + + afterEach(function() { + App.testMode = false; + controller.launchStartServices.restore(); + $.ajax.restore(); + }); + + tests.forEach(function(test){ + it(test.m, function() { + controller.set('status',test.status); + //Action + controller.isServicesInstalled(polledData); + //Validation + expect(controller.launchStartServices.called).to.equal(test.e.startServicesCalled); + }); + }); + }); // On completion of Start all services error callback function, // Cluster Status should be INSTALL FAILED
