Browse Source

AMBARI-1031. Check for host registration at step3 of installer wizard and retrieve information for RAM and no. of cores. (Jaimin Jetly via yusaku)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1418968 13f79535-47bb-0310-9956-ffa450edef68
Yusaku Sako 12 years ago
parent
commit
435a7ca63d

+ 4 - 0
AMBARI-666-CHANGES.txt

@@ -12,6 +12,10 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-1031. Check for host registration at step3 of installer wizard 
+  and retrieve information for RAM and no. of cores. (Jaimin Jetly via
+  yusaku)
+
   AMBARI-1022. Integrate Heatmap UI to backend API. (Srimanth
   Gunturi via yusaku)
 

+ 8 - 5
ambari-web/app/controllers/installer.js

@@ -301,6 +301,7 @@ App.InstallerController = Em.Controller.extend({
    *   confirmPassphrase: '',
    *   localRepo: false,
    *   localRepoPath: ''
+   *   bootRequestId: ''
    * }
    */
   loadInstallOptions: function () {
@@ -327,11 +328,12 @@ App.InstallerController = Em.Controller.extend({
       hostsInfo.localRepo = false;
       hostsInfo.localRepoPath = '';
     }
-
+    hostsInfo.bootRequestId =  App.db.getBootRequestId() || null;
     hostsInfo.sshKey = '';
     hostsInfo.passphrase = '';
     hostsInfo.confirmPassphrase = '';
 
+
     this.set('content.hosts', hostsInfo);
     console.log("InstallerController:loadHosts: loaded data ", hostsInfo);
   },
@@ -345,6 +347,7 @@ App.InstallerController = Em.Controller.extend({
 
     //App.db.setBootStatus(false);
     App.db.setAllHostNames(stepController.get('hostNames'));
+    App.db.setBootRequestId(stepController.get('bootRequestId'));
     App.db.setHosts(stepController.getHostInfo());
     if (stepController.get('manualInstall') === false) {
       App.db.setInstallType({installType: 'ambari' });
@@ -811,10 +814,10 @@ App.InstallerController = Em.Controller.extend({
       },
 
       error: function (request, ajaxOptions, error) {
-        console.log("TRACE: STep8 -> In error function for the installService call");
-        console.log("TRACE: STep8 -> value of the url is: " + url);
-        console.log("TRACE: STep8 -> error code status is: " + request.status);
-        console.log('Step8: Error message is: ' + request.responseText);
+        console.log("TRACE: In error function for the installService call");
+        console.log("TRACE: value of the url is: " + url);
+        console.log("TRACE: error code status is: " + request.status);
+        console.log('Error message is: ' + request.responseText);
           var clusterStatus = {
             status: 'PENDING',
             isInstallError: false,

+ 5 - 1
ambari-web/app/controllers/wizard/step2_controller.js

@@ -21,6 +21,7 @@ var App = require('app');
 App.WizardStep2Controller = Em.Controller.extend({
   name: 'wizardStep2Controller',
   hostNameArr: [],
+  bootRequestId:  null,
   hasSubmitted: false,
 
   hostNames: function () {
@@ -145,6 +146,7 @@ App.WizardStep2Controller = Em.Controller.extend({
       return true;
     }
 
+    var self = this;
     var method = App.testMode ? 'GET' : 'POST';
     var url = App.testMode ? '/data/wizard/bootstrap/bootstrap.json' : App.apiPrefix + '/bootstrap';
 
@@ -154,8 +156,10 @@ App.WizardStep2Controller = Em.Controller.extend({
       data: bootStrapData,
       timeout: App.timeout,
       contentType: 'application/json',
-      success: function () {
+      success: function (data) {
         console.log("TRACE: POST bootstrap succeeded");
+        var requestId = data.requestId;
+        self.set('bootRequestId',requestId);
         App.router.send('next');
       },
       error: function () {

+ 113 - 6
ambari-web/app/controllers/wizard/step3_controller.js

@@ -23,7 +23,8 @@ App.WizardStep3Controller = Em.Controller.extend({
   hosts: [],
   content: [],
   bootHosts: [],
-  isSubmitDisabled: false,
+  registrationAttempt: 7,
+  isSubmitDisabled: true,
   categories: ['All Hosts', 'Success', 'Error'],
   category: 'All Hosts',
   allChecked: false,
@@ -42,7 +43,7 @@ App.WizardStep3Controller = Em.Controller.extend({
 
   navigateStep: function () {
     this.loadStep();
-    if (App.db.getInstallType().installType !== 'manual') {
+    if (this.get('content.hosts.manualInstall') !== true) {
       if (App.db.getBootStatus() === false) {
         this.startBootstrap();
       }
@@ -52,6 +53,8 @@ App.WizardStep3Controller = Em.Controller.extend({
         _host.set('bootStatus', 'DONE');
         _host.set('bootLog', 'Success');
       });
+      this.set('bootHosts', this.get('hosts'));
+      this.isHostsRegistered(this.getHostInfo);
     }
   },
 
@@ -196,21 +199,23 @@ App.WizardStep3Controller = Em.Controller.extend({
   doBootstrap: function () {
     this.numPolls++;
     var self = this;
-    var url = App.testMode ? '/data/wizard/bootstrap/poll_' + this.numPolls + '.json' : App.apiPrefix + '/bootstrap/1';
+    var url = App.testMode ? '/data/wizard/bootstrap/poll_' + this.numPolls + '.json' : App.apiPrefix + '/bootstrap/' + this.get('content.hosts.bootRequestId');
     $.ajax({
       type: 'GET',
       url: url,
       timeout: App.timeout,
       success: function (data) {
         if (data.hostsStatus !== null) {
-          // in case of bootstrapping just one server, the server returns an object rather than an array...
+          // in case of bootstrapping just one host, the server returns an object rather than an array...
           if (!(data.hostsStatus instanceof Array)) {
             data.hostsStatus = [ data.hostsStatus ];
           }
           console.log("TRACE: In success function for the GET bootstrap call");
           var result = self.parseHostInfo(data.hostsStatus);
           if (result) {
-            window.setTimeout(function () { self.doBootstrap() }, 3000);
+            window.setTimeout(function () {
+              self.doBootstrap()
+            }, 3000);
             return;
           }
         }
@@ -232,11 +237,113 @@ App.WizardStep3Controller = Em.Controller.extend({
     //TODO: uncomment following line after the hook up with the API call
     console.log('stopBootstrap() called');
     // this.set('isSubmitDisabled',false);
+    this.startRegistration();
   },
 
+  startRegistration: function () {
+    this.isHostsRegistered(this.getHostInfo);
+  },
+
+  isHostsRegistered: function (callback) {
+    var self = this;
+    var hosts = this.get('bootHosts');
+    var url = App.apiPrefix + '/hosts';
+    var method = 'GET';
+    $.ajax({
+      type: 'GET',
+      url: url,
+      timeout: App.timeout,
+      success: function (data) {
+        var jsonData = jQuery.parseJSON(data);
+        if (jsonData && jsonData.items.length === 0) {
+          if (self.get('registrationAttempt') !== 0) {
+            count--;
+            window.setTimeout(function () {
+              self.isHostsRegistered(callback);
+            }, 3000);
+          } else {
+            self.registerErrPopup(Em.I18n.t('installer.step3.hostRegister.popup.header'), Em.I18n.t('installer.step3.hostRegister.popup.body'));
+            return;
+          }
+        }
+        if (hosts.length === jsonData.items.length) {
+          callback.apply(self);
+        } else {
+          self.registerErrPopup(Em.I18n.t('installer.step3.hostRegister.popup.header'), Em.I18n.t('installer.step3.hostRegister.popup.body'));
+        }
+      },
+      error: function () {
+        console.log('Error: Getting registered host information from the server');
+        self.stopBootstrap();
+      },
+      statusCode: require('data/statusCodes')
+    });
+  },
+
+  registerErrPopup: function (header, message) {
+    App.ModalPopup.show({
+      header: header,
+      secondary: false,
+      onPrimary: function () {
+        this.hide();
+      },
+      bodyClass: Ember.View.extend({
+        template: Ember.Handlebars.compile(['<p>{{view.message}}</p>'].join('\n')),
+        message: message
+      })
+    });
+  },
+
+  /**
+   * Get disk info and cpu count of booted hosts from server
+   */
+
+
+  getHostInfo: function () {
+    var self = this;
+    var kbPerGb = 1024;
+    var hosts = this.get('bootHosts');
+    var url = App.apiPrefix + '/hosts?fields=Hosts/total_mem,Hosts/cpu_count';
+    var method = 'GET';
+    $.ajax({
+      type: 'GET',
+      url: url,
+      contentType: 'application/json',
+      timeout: App.timeout,
+      success: function (data) {
+        var jsonData = jQuery.parseJSON(data);
+        hosts.forEach(function (_host) {
+          if (jsonData.items.someProperty('Hosts.host_name', _host.name)) {
+            var host = jsonData.items.findProperty('Hosts.host_name', _host.name);
+            _host.cpu = host.Hosts.cpu_count;
+            _host.memory = ((parseInt(host.Hosts.total_mem)) / kbPerGb).toFixed(2);
+            console.log("The value of memory is: " + _host.memory);
+            alert ("The value of memory is: " + _host.memory);
+            debugger;
+          }
+        }, this);
+        self.set('bootHosts',hosts);
+        console.log("The value of hosts: " + JSON.stringify(hosts));
+        debugger;
+        self.stopRegistrataion();
+      },
+
+      error: function () {
+        console.log('INFO: Getting host information(cpu_count and total_mem) from the server failed');
+        self.registerErrPopup(Em.I18n.t('installer.step3.hostInformation.popup.header'), Em.I18n.t('installer.step3.hostInformation.popup.body'));
+      },
+      statusCode: require('data/statusCodes')
+    });
+  },
+
+  stopRegistrataion: function () {
+    this.set('isSubmitDisabled', false);
+  },
+
+
   submit: function () {
     if (!this.get('isSubmitDisabled')) {
-      this.set('content.hostsInfo', this.get('hosts'));
+      this.set('content.hostsInfo', this.get('bootHosts'));
       App.router.send('next');
     }
   },

+ 4 - 1
ambari-web/app/messages.js

@@ -93,7 +93,10 @@ Em.I18n.translations = {
   'installer.step3.hosts.remove.popup.body':'Are you sure you want to remove the selected host(s)?',
   'installer.step3.hosts.retry.popup.header':'Retry Host Discovery',
   'installer.step3.hosts.retry.popup.body':'Are you sure you want to retry discovery of the selected host(s)?',
-
+  'installer.step3.hostRegister.popup.header':'Error in Host Registration',
+  'installer.step3.hostRegister.popup.body':'All/Some hosts bootstrapped but unable to register with server',
+  'installer.step3.hostInformation.popup.header':'Error in retrieving host Information',
+  'installer.step3.hostInformation.popup.body' : 'All bootstrapped hosts registered but unable to retrieve cpu and memory related information',
   'installer.step4.header':'Choose Services',
   'installer.step4.body':'Choose which services you want to install on your cluster.<br>Note that some services have dependencies (e.g., HBase requires ZooKeeper.)',
   'installer.step4.mapreduceCheck.popup.header':'MapReduce Needed',

+ 2 - 2
ambari-web/app/models/hosts.js

@@ -21,8 +21,8 @@ var App = require('app');
 App.HostInfo = Ember.Object.extend({
   elementId: 'host',
   name: '',
-  cpu: 2,
-  memory: 4000000000,
+  cpu: null,
+  memory: null,
   message: 'Information',
   barColor: 'progress-info',
   isChecked: true,

+ 4 - 5
ambari-web/app/routes/installer.js

@@ -93,6 +93,9 @@ module.exports = Em.Route.extend({
     },
     back: Em.Router.transitionTo('step1'),
     next: function (router) {
+      var controller = router.get('installerController');
+      var wizardStep2Controller = router.get('wizardStep2Controller');
+      controller.saveHosts(wizardStep2Controller);
       router.transitionTo('step3');
       App.db.setBootStatus(false);
     },
@@ -102,15 +105,11 @@ module.exports = Em.Route.extend({
      * @param router
      */
     evaluateStep: function (router) {
-
-      var controller = router.get('installerController');
       var wizardStep2Controller = router.get('wizardStep2Controller');
-
       wizardStep2Controller.set('hasSubmitted', true);
 
       if (!wizardStep2Controller.get('isSubmitDisabled')) {
         App.db.setBootStatus(false);
-        controller.saveHosts(wizardStep2Controller);
         wizardStep2Controller.evaluateStep();
       }
     }
@@ -291,7 +290,7 @@ module.exports = Em.Route.extend({
       var controller = router.get('installerController');
       controller.setCurrentStep('10', false);
       controller.loadAllPriorSteps();
-      controller.connectOutlet('wizardStep10',controller.get('content'));
+      controller.connectOutlet('wizardStep10', controller.get('content'));
     },
     back: Em.Router.transitionTo('step9'),
     complete: function (router, context) {

+ 13 - 0
ambari-web/app/utils/db.js

@@ -141,6 +141,13 @@ App.db.setSoftRepo = function (softRepo) {
   localStorage.setObject('ambari', App.db.data);
 };
 
+App.db.setBootRequestId = function (requestId) {
+  console.log('TRACE: Entering db:setBootRequestId function');
+  App.db.data = localStorage.getObject('ambari');
+  App.db.data.Installer.bootRequestId = requestId;
+  localStorage.setObject('ambari', App.db.data);
+};
+
 App.db.setBootStatus = function (status) {
   console.log('TRACE: Entering db:setBootStatus function');
   App.db.data = localStorage.getObject('ambari');
@@ -315,6 +322,12 @@ App.db.getBootStatus = function () {
   return App.db.data.Installer.bootStatus;
 };
 
+App.db.getBootRequestId = function () {
+  console.log('TRACE: Entering db:getBootRequestId function');
+  App.db.data = localStorage.getObject('ambari');
+  return App.db.data.Installer.bootRequestId;
+};
+
 App.db.getService = function () {
   App.db.data = localStorage.getObject('ambari');
   return App.db.data.Installer.serviceInfo;