Sfoglia il codice sorgente

AMBARI-6017 Load Hosts on demand for Security and High Availability wizards. (atkach)

atkach 11 anni fa
parent
commit
2d2daf4e44

+ 42 - 13
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 () {

+ 5 - 18
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.

+ 21 - 2
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');
   },

+ 46 - 1
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',
@@ -166,11 +168,54 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
     newWindow.focus();
   },
 
+  /**
+   * 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;

+ 7 - 3
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>

+ 31 - 26
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}}>&larr; {{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}} &rarr;</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>
+    <div class="btn-area">
+        <a class="btn" {{action back}}>&larr; {{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}} &rarr;</button>
+        </div>
+    </div>
+{{else}}
+    <div class="spinner"></div>
+{{/if}}

+ 26 - 0
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
+      }
+    }
   }
 };
 /**

+ 42 - 0
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) {

+ 3 - 2
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();
   }
 });