Repository: ambari Updated Branches: refs/heads/trunk e37f9657e -> 2d2daf4e4
AMBARI-6017 Load Hosts on demand for Security and High Availability wizards. (atkach) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2d2daf4e Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2d2daf4e Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2d2daf4e Branch: refs/heads/trunk Commit: 2d2daf4e4445ba5c7af58eacf86e903f63471f22 Parents: e37f965 Author: atkach <[email protected]> Authored: Wed Jun 4 15:30:09 2014 +0300 Committer: atkach <[email protected]> Committed: Wed Jun 4 15:34:13 2014 +0300 ---------------------------------------------------------------------- .../highAvailability/progress_controller.js | 55 ++++++++++++++----- .../admin/highAvailability/wizard_controller.js | 23 ++------ .../main/admin/highAvailability_controller.js | 23 +++++++- .../main/admin/security/add/step3.js | 47 +++++++++++++++- .../main/admin/highAvailability/wizard.hbs | 10 ++-- .../templates/main/admin/security/add/step3.hbs | 57 +++++++++++--------- ambari-web/app/utils/ajax/ajax.js | 26 +++++++++ .../main/admin/highAvailability/wizard_view.js | 42 +++++++++++++++ .../app/views/main/admin/security/add/step3.js | 5 +- 9 files changed, 223 insertions(+), 65 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/2d2daf4e/ambari-web/app/controllers/main/admin/highAvailability/progress_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/admin/highAvailability/progress_controller.js b/ambari-web/app/controllers/main/admin/highAvailability/progress_controller.js index 5875533..a5481f8 100644 --- a/ambari-web/app/controllers/main/admin/highAvailability/progress_controller.js +++ b/ambari-web/app/controllers/main/admin/highAvailability/progress_controller.js @@ -17,6 +17,7 @@ */ var App = require('app'); +var installedComponents = []; App.HighAvailabilityProgressPageController = App.HighAvailabilityWizardController.extend({ @@ -252,31 +253,59 @@ App.HighAvailabilityProgressPageController = App.HighAvailabilityWizardControlle this.setTaskStatus(this.get('currentTaskId'), 'COMPLETED'); }, + /** + * check whether component installed on specified hosts + * @param componentName + * @param hostNames + * @return {Array} + */ + checkInstalledComponents: function (componentName, hostNames) { + var result = []; + + App.ajax.send({ + name: 'host_component.installed.on_hosts', + sender: this, + data: { + componentName: componentName, + hostNames: hostNames.join(',') + }, + success: 'checkInstalledComponentsSuccessCallback' + }); + hostNames.forEach(function (hostName) { + result.push({ + componentName: componentName, + hostName: hostName, + hasComponent: installedComponents.someProperty('HostRoles.host_name', hostName) + }); + }); + return result; + }, + + checkInstalledComponentsSuccessCallback: function (data, opt, params) { + installedComponents = data.items; + }, + createComponent: function (componentName, hostName) { - console.warn('func: createComponent'); - if (!(hostName instanceof Array)) { - hostName = [hostName]; - } - var hostComponents = []; - for (var i = 0; i < hostName.length; i++) { - hostComponents = App.HostComponent.find().filterProperty('componentName', componentName); - if (!hostComponents.length || !hostComponents.mapProperty('host.hostName').contains(hostName[i])) { + var hostNames = (Array.isArray(hostName)) ? hostName : [hostName]; + + this.checkInstalledComponents(componentName, hostNames).forEach(function (host, index, array) { + if (!host.hasComponent) { App.ajax.send({ name: 'admin.high_availability.create_component', sender: this, data: { - hostName: hostName[i], - componentName: componentName, - taskNum: hostName.length + hostName: host.hostName, + componentName: host.componentName, + taskNum: array.length }, success: 'onCreateComponent', error: 'onCreateComponentError' }); } else { // Simulates format returned from ajax.send - this.onCreateComponent(null, null, {hostName: hostName[i], componentName: componentName, taskNum: hostName.length}); + this.onCreateComponent(null, null, {hostName: host.hostName, componentName: host.componentName, taskNum: array.length}); } - } + }, this) }, onCreateComponent: function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/2d2daf4e/ambari-web/app/controllers/main/admin/highAvailability/wizard_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/admin/highAvailability/wizard_controller.js b/ambari-web/app/controllers/main/admin/highAvailability/wizard_controller.js index 47f0c5f..1a0ca4a 100644 --- a/ambari-web/app/controllers/main/admin/highAvailability/wizard_controller.js +++ b/ambari-web/app/controllers/main/admin/highAvailability/wizard_controller.js @@ -80,26 +80,13 @@ App.HighAvailabilityWizardController = App.WizardController.extend({ * Load confirmed hosts. * Will be used at <code>Assign Masters(step5)</code> step */ - loadConfirmedHosts: function(){ + loadConfirmedHosts: function () { var hosts = App.db.getHosts(); - if(!hosts || !hosts.length){ - var hosts = {}; - - App.Host.find().forEach(function(item){ - hosts[item.get('id')] = { - name: item.get('id'), - cpu: item.get('cpu'), - memory: item.get('memory'), - disk_info: item.get('diskInfo'), - bootStatus: "REGISTERED", - isInstalled: true - }; - }); - App.db.setHosts(hosts); - } - this.set('content.hosts', hosts); - console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts); + if (hosts) { + this.set('content.hosts', hosts); + console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts); + } }, /** * save status of the cluster. http://git-wip-us.apache.org/repos/asf/ambari/blob/2d2daf4e/ambari-web/app/controllers/main/admin/highAvailability_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/admin/highAvailability_controller.js b/ambari-web/app/controllers/main/admin/highAvailability_controller.js index 8d3d195..cbc42bf 100644 --- a/ambari-web/app/controllers/main/admin/highAvailability_controller.js +++ b/ambari-web/app/controllers/main/admin/highAvailability_controller.js @@ -17,6 +17,7 @@ */ var App = require('app'); +var totalHosts = 0; App.MainAdminHighAvailabilityController = Em.Controller.extend({ name: 'mainAdminHighAvailabilityController', @@ -39,14 +40,14 @@ App.MainAdminHighAvailabilityController = Em.Controller.extend({ this.showErrorPopup(Em.I18n.t('admin.highAvailability.error.security')); return false; } else { - if (hostComponents.findProperty('componentName', 'NAMENODE').get('workStatus') !== 'STARTED') { + if (hostComponents.findProperty('componentName', 'NAMENODE').get('workStatus') !== 'STARTED') { message.push(Em.I18n.t('admin.highAvailability.error.namenodeStarted')); } if (hostComponents.filterProperty('componentName', 'ZOOKEEPER_SERVER').length < 3) { message.push(Em.I18n.t('admin.highAvailability.error.zooKeeperNum')); } - if (App.Host.find().content.length < 3) { + if (this.getTotalHosts() < 3) { message.push(Em.I18n.t('admin.highAvailability.error.hostsNum')); } if (message.length > 0) { @@ -58,6 +59,24 @@ App.MainAdminHighAvailabilityController = Em.Controller.extend({ return true; }, + /** + * get total hosts count from cluster API + * @return {Number} + */ + getTotalHosts: function () { + App.ajax.send({ + name: 'hosts.total_count', + data: {}, + sender: this, + success: 'getTotalHostsSuccessCallback' + }); + return totalHosts; + }, + + getTotalHostsSuccessCallback: function (data, opt, params) { + totalHosts = data.Clusters.total_hosts; + }, + disableHighAvailability: function () { App.router.transitionTo('rollbackHighAvailability'); }, http://git-wip-us.apache.org/repos/asf/ambari/blob/2d2daf4e/ambari-web/app/controllers/main/admin/security/add/step3.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/admin/security/add/step3.js b/ambari-web/app/controllers/main/admin/security/add/step3.js index 1966e60..0b0969f 100644 --- a/ambari-web/app/controllers/main/admin/security/add/step3.js +++ b/ambari-web/app/controllers/main/admin/security/add/step3.js @@ -22,6 +22,8 @@ var stringUtils = require('utils/string_utils'); App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({ name: 'mainAdminSecurityAddStep3Controller', hostComponents: [], + hosts: [], + isLoaded: false, componentToUserMap: { 'NAMENODE': 'hdfs_user', @@ -167,10 +169,53 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({ }, /** + * load hosts from server + */ + loadHosts: function () { + App.ajax.send({ + name: 'hosts.security.wizard', + sender: this, + data: {}, + error: 'loadHostsErrorCallback', + success: 'loadHostsSuccessCallback' + }) + }, + + loadHostsSuccessCallback: function (data, opt, params) { + var hosts = []; + + data.items.forEach(function (item) { + var hostComponents = []; + + item.host_components.forEach(function (hostComponent) { + hostComponents.push(Em.Object.create({ + componentName: hostComponent.HostRoles.component_name, + service: Em.Object.create({ + serviceName: hostComponent.HostRoles.service_name + }), + displayName: App.format.role(hostComponent.HostRoles.component_name) + })); + }); + hosts.push(Em.Object.create({ + hostName: item.Hosts.host_name, + hostComponents: hostComponents + })); + }); + this.set('isLoaded', true); + this.set('hosts', hosts); + this.loadStep(); + }, + loadHostsErrorCallback: function () { + this.set('isLoaded', true); + this.set('hosts', []); + this.loadStep(); + }, + + /** * load step info */ loadStep: function () { - var hosts = App.Host.find(); + var hosts = this.get('hosts'); var result = []; var securityUsers = this.getSecurityUsers(); var hadoopGroupId = securityUsers.findProperty('name', 'user_group').value; http://git-wip-us.apache.org/repos/asf/ambari/blob/2d2daf4e/ambari-web/app/templates/main/admin/highAvailability/wizard.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/admin/highAvailability/wizard.hbs b/ambari-web/app/templates/main/admin/highAvailability/wizard.hbs index 294a4cb..826e553 100644 --- a/ambari-web/app/templates/main/admin/highAvailability/wizard.hbs +++ b/ambari-web/app/templates/main/admin/highAvailability/wizard.hbs @@ -37,9 +37,13 @@ </ul> </div> </div> - <div class="wizard-content well span9"> - {{outlet}} - </div> + <div class="wizard-content well span9"> + {{#if view.isLoaded}} + {{outlet}} + {{else}} + <div class="spinner"></div> + {{/if}} + </div> </div> </div> </div> http://git-wip-us.apache.org/repos/asf/ambari/blob/2d2daf4e/ambari-web/app/templates/main/admin/security/add/step3.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/admin/security/add/step3.hbs b/ambari-web/app/templates/main/admin/security/add/step3.hbs index fd3e4d0..684137a 100644 --- a/ambari-web/app/templates/main/admin/security/add/step3.hbs +++ b/ambari-web/app/templates/main/admin/security/add/step3.hbs @@ -18,32 +18,37 @@ <h2>{{t admin.security.step3.header}}</h2> <div class="alert alert-info">{{t admin.security.step3.notice}}</div> -<div class="step3"> - <table class="table table-bordered table-striped"> - <thead> - <tr> - <th>{{t common.host}}</th> - <th>{{t common.component}}</th> - <th>{{t admin.security.step3.table.principal}}</th> - <th>{{t admin.security.step3.table.keytab}}</th> - </tr> - </thead> - <tbody> - {{#each hostComponent in hostComponents}} +{{#if isLoaded}} + <div class="step3"> + <table class="table table-bordered table-striped"> + <thead> <tr> - <td>{{hostComponent.host}}</td> - <td>{{hostComponent.component}}</td> - <td>{{hostComponent.principal}}</td> - <td>{{hostComponent.keytab}}</td> + <th>{{t common.host}}</th> + <th>{{t common.component}}</th> + <th>{{t admin.security.step3.table.principal}}</th> + <th>{{t admin.security.step3.table.keytab}}</th> </tr> - {{/each}} - </tbody> - </table> -</div> -<div class="btn-area"> - <a class="btn" {{action back}}>← {{t common.back}}</a> - <div class="pull-right"> - <button class="btn btn-info" {{action doDownloadCsv target="controller"}}>{{t admin.security.step3.downloadCSV}}</button> - <button class="btn btn-success" {{bindAttr disabled="isSubmitDisabled"}} {{action next}}>{{t common.apply}} →</button> + </thead> + <tbody> + {{#each hostComponent in hostComponents}} + <tr> + <td>{{hostComponent.host}}</td> + <td>{{hostComponent.component}}</td> + <td>{{hostComponent.principal}}</td> + <td>{{hostComponent.keytab}}</td> + </tr> + {{/each}} + </tbody> + </table> </div> -</div> \ No newline at end of file + <div class="btn-area"> + <a class="btn" {{action back}}>← {{t common.back}}</a> + + <div class="pull-right"> + <button class="btn btn-info" {{action doDownloadCsv target="controller"}}>{{t admin.security.step3.downloadCSV}}</button> + <button class="btn btn-success" {{bindAttr disabled="isSubmitDisabled"}} {{action next}}>{{t common.apply}} →</button> + </div> + </div> +{{else}} + <div class="spinner"></div> +{{/if}} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/2d2daf4e/ambari-web/app/utils/ajax/ajax.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/ajax/ajax.js b/ambari-web/app/utils/ajax/ajax.js index 0f48fac..e8c05cb 100644 --- a/ambari-web/app/utils/ajax/ajax.js +++ b/ambari-web/app/utils/ajax/ajax.js @@ -2184,6 +2184,32 @@ var urls = { taskId: data.taskId || '' } } + }, + 'hosts.total_count': { + 'real': '/clusters/{clusterName}?fields=Clusters/total_hosts&minimal_response=true', + 'mock': '', + 'format': function() { + return { + async: false + } + } + }, + 'hosts.high_availability.wizard': { + 'real': '/clusters/{clusterName}/hosts?fields=Hosts/cpu_count,Hosts/disk_info,Hosts/total_mem&minimal_response=true', + 'mock': '' + }, + 'hosts.security.wizard': { + 'real': '/clusters/{clusterName}/hosts?fields=host_components/HostRoles/service_name&minimal_response=true', + 'mock': '' + }, + 'host_component.installed.on_hosts': { + 'real': '/clusters/{clusterName}/host_components?HostRoles/component_name={componentName}&HostRoles/host_name.in({hostNames})&fields=HostRoles/host_name&minimal_response=true', + 'mock': '', + 'format': function() { + return { + async: false + } + } } }; /** http://git-wip-us.apache.org/repos/asf/ambari/blob/2d2daf4e/ambari-web/app/views/main/admin/highAvailability/wizard_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/admin/highAvailability/wizard_view.js b/ambari-web/app/views/main/admin/highAvailability/wizard_view.js index 998d79a..09d9b75 100644 --- a/ambari-web/app/views/main/admin/highAvailability/wizard_view.js +++ b/ambari-web/app/views/main/admin/highAvailability/wizard_view.js @@ -21,6 +21,48 @@ var App = require('app'); App.HighAvailabilityWizardView = Em.View.extend({ + isLoaded: false, + + willInsertElement: function() { + this.set('isLoaded', false); + this.loadHosts(); + }, + + /** + * load hosts from server + */ + loadHosts: function () { + App.ajax.send({ + name: 'hosts.high_availability.wizard', + data: {}, + sender: this, + success: 'loadHostsSuccessCallback', + error: 'loadHostsErrorCallback' + }); + }, + + loadHostsSuccessCallback: function (data, opt, params) { + var hosts = {}; + + data.items.forEach(function (item) { + hosts[item.Hosts.host_name] = { + name: item.Hosts.host_name, + cpu: item.Hosts.cpu_count, + memory: item.Hosts.total_mem, + disk_info: item.Hosts.disk_info, + bootStatus: "REGISTERED", + isInstalled: true + }; + }); + App.db.setHosts(hosts); + this.set('controller.content.hosts', hosts); + this.set('isLoaded', true); + }, + + loadHostsErrorCallback: function(){ + this.set('isLoaded', true); + }, + didInsertElement: function() { var currentStep = this.get('controller.currentStep'); if (currentStep > 4) { http://git-wip-us.apache.org/repos/asf/ambari/blob/2d2daf4e/ambari-web/app/views/main/admin/security/add/step3.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/admin/security/add/step3.js b/ambari-web/app/views/main/admin/security/add/step3.js index 8f3a4c7..b7ad4fc 100644 --- a/ambari-web/app/views/main/admin/security/add/step3.js +++ b/ambari-web/app/views/main/admin/security/add/step3.js @@ -20,8 +20,9 @@ var App = require('app'); App.MainAdminSecurityAddStep3View = Em.View.extend({ templateName: require('templates/main/admin/security/add/step3'), - didInsertElement: function(){ - this.get('controller').loadStep(); + didInsertElement: function() { + this.set('controller.isLoaded', false); + this.get('controller').loadHosts(); } });
