Jelajahi Sumber

AMBARI-2770. NameNode HA Wizard: prerequisite checks. (Aleksandr Kovalenko via yusaku)

Yusaku Sako 12 tahun lalu
induk
melakukan
3c092f84ad

+ 85 - 1
ambari-web/app/controllers/main/admin/highAvailability_controller.js

@@ -19,9 +19,93 @@
 var App = require('app');
 
 App.MainAdminHighAvailabilityController = Em.Controller.extend({
-  name:'mainAdminHighAvailabilityController',
+  name: 'mainAdminHighAvailabilityController',
+
+  securityEnabled: false,
+
+  dataIsLoaded: false,
 
   enableHighAvailability: function () {
+    //Prerequisite Checks
+    if (App.Host.find().content.length < 3) {
+      this.showErrorPopup(Em.I18n.t('admin.highAvailability.error.hostsNum'));
+      return;
+    }
+    if (App.HostComponent.find().filterProperty('componentName', 'ZOOKEEPER_SERVER').length < 3) {
+      this.showErrorPopup(Em.I18n.t('admin.highAvailability.error.zooKeeperNum'));
+      return;
+    }
+    if (this.get('securityEnabled')) {
+      this.showErrorPopup(Em.I18n.t('admin.highAvailability.error.security'));
+      return;
+    }
     App.router.transitionTo('enableHighAvailability');
+  },
+
+  setSecurityStatus: function () {
+    if (App.testMode) {
+      this.set('securityEnabled', !App.testEnableSecurity);
+      this.set('dataIsLoaded', true);
+    } else {
+      //get Security Status From Server
+      App.ajax.send({
+        name: 'admin.security_status',
+        sender: this,
+        success: 'getSecurityStatusFromServerSuccessCallback',
+        error: 'errorCallback'
+      });
+    }
+  },
+
+  errorCallback: function () {
+    this.showErrorPopup(Em.I18n.t('admin.security.status.error'));
+  },
+
+  getSecurityStatusFromServerSuccessCallback: function (data) {
+    var configs = data.Clusters.desired_configs;
+    if ('global' in configs) {
+      this.getServiceConfigsFromServer(configs['global'].tag);
+    }
+    else {
+      this.showErrorPopup(Em.I18n.t('admin.security.status.error'));
+    }
+  },
+
+  getServiceConfigsFromServer: function (tag) {
+    App.ajax.send({
+      name: 'admin.service_config',
+      sender: this,
+      data: {
+        siteName: 'global',
+        tagName: tag
+      },
+      success: 'getServiceConfigsFromServerSuccessCallback',
+      error: 'errorCallback'
+    });
+  },
+
+  getServiceConfigsFromServerSuccessCallback: function (data) {
+    var configs = data.items.findProperty('tag', this.get('tag')).properties;
+    if (configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true)) {
+      this.set('securityEnabled', true);
+      this.set('dataIsLoaded', true);
+    }
+    else {
+      this.set('securityEnabled', false);
+      this.set('dataIsLoaded', true);
+    }
+  },
+
+  showErrorPopup: function (message) {
+    App.ModalPopup.show({
+      header: Em.I18n.t('common.error'),
+      bodyClass: Ember.View.extend({
+        template: Ember.Handlebars.compile('<p>' + message + '</p>')
+      }),
+      onPrimary: function () {
+        this.hide();
+      },
+      secondary: false
+    });
   }
 });

+ 3 - 0
ambari-web/app/messages.js

@@ -636,6 +636,9 @@ Em.I18n.translations = {
   'admin.highAvailability.button.enable':'Enable NameNode HA',
   'admin.highAvailability.disabled':'NameNode HA is disabled',
   'admin.highAvailability.enabled':'NameNode HA is enabled',
+  'admin.highAvailability.error.hostsNum':'You must have at least 3 hosts in your cluster to enable NameNode HA',
+  'admin.highAvailability.error.zooKeeperNum':'You must have at least 3 ZooKeeper Servers in your cluster to enable NameNode HA',
+  'admin.highAvailability.error.security':'You cannot enable NameNode HA via this wizard as your cluster is already secured.  First, disable security by going to Admin > Security, and then run this Enable NameNode HA wizard again.  After NameNode HA is enabled, you can go back to Admin > Security to secure the cluster.',
   'admin.highAvailability.wizard.header':'Enable NameNode HA Wizard',
   'admin.highAvailability.wizard.step1.header':'Get Started',
   'admin.highAvailability.wizard.step2.header':'Select Hosts',

+ 8 - 4
ambari-web/app/templates/main/admin/highAvailability.hbs

@@ -22,9 +22,13 @@
       {{t admin.highAvailability.enabled}}
     </p>
   {{else}}
-    <p class="muted">
-      {{t admin.highAvailability.disabled}}
-      <a class="btn btn-padding btn-success" {{action enableHighAvailability target="controller"}}>{{t admin.highAvailability.button.enable}}</a>
-    </p>
+    {{#if controller.dataIsLoaded}}
+      <p class="muted">
+        {{t admin.highAvailability.disabled}}
+        <a class="btn btn-padding btn-success" {{action enableHighAvailability target="controller"}}>{{t admin.highAvailability.button.enable}}</a>
+      </p>
+    {{else}}
+      <div class="spinner"></div>
+    {{/if}}
   {{/if}}
 </div>

+ 1 - 1
ambari-web/app/utils/db.js

@@ -64,7 +64,7 @@ App.db.cleanUp = function () {
     'StackUpgrade' : {},
     'ReassignMaster' : {},
     'AddSecurity': {},
-    'HighAvailability': {}
+    'HighAvailabilityWizard': {}
 
   };
   console.log("In cleanup./..");

+ 4 - 0
ambari-web/app/views/main/admin/highAvailability_view.js

@@ -21,6 +21,10 @@ var App = require('app');
 App.MainAdminHighAvailabilityView = Em.View.extend({
   templateName: require('templates/main/admin/highAvailability'),
 
+  didInsertElement: function () {
+    this.get('controller').setSecurityStatus();
+  },
+
   isHighAvailabilityEnabled: false //todo: real check
 
 });