Przeglądaj źródła

AMBARI-3593 Ambari ui works incorrect when we delete host which has last slave component on the cluster

aBabiichuk 11 lat temu
rodzic
commit
ac94d2779e

+ 27 - 3
ambari-web/app/controllers/main/host/details.js

@@ -659,9 +659,19 @@ App.MainHostDetailsController = Em.Controller.extend({
      var runningComponents = [];
      var unknownComponents = [];
      var nonDeletableComponents = [];
+     var lastComponents = [];
      var components = this.get('content.hostComponents');
      if (components!=null && components.get('length')>0){
-       components.forEach(function (cInstance) { 
+       components.forEach(function (cInstance) {
+         var numberOfComponents = 0;
+         var allComponents = cInstance.get('service.hostComponents');
+         allComponents.forEach(function(component) {
+           if (component.get('componentName') == cInstance.get('componentName')) numberOfComponents++;
+           if (numberOfComponents > 1) return;
+         });
+         if (numberOfComponents == 1) {
+           lastComponents.push(cInstance.get('displayName'));
+         }
          var workStatus = cInstance.get('workStatus');
          if (cInstance.get('isMaster') && !cInstance.get('isDeletable')) {
            masterComponents.push(cInstance.get('displayName'));
@@ -687,7 +697,7 @@ App.MainHostDetailsController = Em.Controller.extend({
        this.raiseDeleteComponentsError(runningComponents, 'runningList');
        return;
      }
-     this._doDeleteHost(unknownComponents);
+     this._doDeleteHost(unknownComponents,lastComponents);
   },
   
   raiseDeleteComponentsError: function (components, type) {
@@ -720,13 +730,26 @@ App.MainHostDetailsController = Em.Controller.extend({
   /**
    * show confirmation popup to delete host
    */
-  _doDeleteHost: function(unknownComponents) {
+  _doDeleteHost: function(unknownComponents,lastComponents) {
     var self = this;
     App.ModalPopup.show({
       header: Em.I18n.t('hosts.delete.popup.title'),
       deletePopupBody: function() {
         return Em.I18n.t('hosts.delete.popup.body').format(self.get('content.publicHostName'));
       }.property(),
+      lastComponent: function() {
+         if (lastComponents && lastComponents.length) {
+           this.set('enablePrimary',false);
+           return true;
+         } else {
+           this.set('enablePrimary',true);
+           return false;
+         }
+      }.property(),
+      enablePrimary: false,
+      lastComponentError:  Em.View.extend({
+        template: Ember.Handlebars.compile(Em.I18n.t('hosts.delete.popup.body.msg4').format(lastComponents))
+      }),
       unknownComponents: function() {
         if (unknownComponents && unknownComponents.length) {
           return unknownComponents.join(", ");
@@ -737,6 +760,7 @@ App.MainHostDetailsController = Em.Controller.extend({
         templateName: require('templates/main/host/details/doDeleteHostPopup')
       }),
       onPrimary: function() {
+        if (!this.get('enablePrimary')) return;
         var dialogSelf = this;
         var allComponents = self.get('content.hostComponents');
         var deleteError = null;

+ 2 - 0
ambari-web/app/mappers/status_mapper.js

@@ -194,6 +194,7 @@ App.statusMapper = App.QuickDataMapper.create({
   updateServicesStatus: function(services, servicesMap){
     services.forEach(function(_service){
       var service = servicesMap[_service.get('id')];
+      if (service) {
       var serviceName = _service.get('serviceName');
       var serviceSpecificObj = null;
       switch (serviceName) {
@@ -258,6 +259,7 @@ App.statusMapper = App.QuickDataMapper.create({
         serviceSpecificObj.set('isStopped', service.isRunning);
         serviceSpecificObj.set('toolTipContent', service.toolTipContent);
       }
+      }
     }, this);
   },
 

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

@@ -1295,6 +1295,7 @@ Em.I18n.translations = {
   'hosts.delete.popup.body.msg1':'This will remove the host from Ambari\'s management. Ambari will ignore any communications from this host.',
   'hosts.delete.popup.body.msg2':'Installed bits of service components will not be removed from the system. Individual service components should not be restarted later to join the cluster. This will introduce inconsistencies in monitoring data.',
   'hosts.delete.popup.body.msg3':'Nagios service should be restarted for alerts and notifications to work properly. ZooKeeper service should be restarted if any ZooKeeper components are removed. Go to the <i>Services</i> page to restart services.',
+  'hosts.delete.popup.body.msg4':'<b>WARNING!</b> Delete the last <i>{0}</i> component[s] in the cluster?</br>Deleting the last components in the cluster could result in permanent loss of service data.',
   'hosts.delete.popup.header':'Confirmation',
   'hosts.delete.popup.title':'Delete Host',
   'hosts.delete.popup.unknownComponents':'Components with unknown status:',

+ 8 - 0
ambari-web/app/styles/application.less

@@ -4355,6 +4355,10 @@ i.icon-asterisks {
     *width: 5.929714493544281%;
   }
 
+  .row-fluid .tinyspan {
+    width: 2%;
+  }
+
   .row-fluid .offset12 {
     margin-left: 105.12820512820512%;
     *margin-left: 105.02182214948171%;
@@ -4475,6 +4479,10 @@ i.icon-asterisks {
     *margin-left: 8.440625568285142%;
   }
 
+  .row-fluid .tinyoffset {
+    margin-left: 3%!important;
+  }
+
   input,
   textarea,
   .uneditable-input {

+ 7 - 1
ambari-web/app/templates/main/host/details/doDeleteHostPopup.hbs

@@ -25,4 +25,10 @@
 {{/if}}
 <p>{{t hosts.delete.popup.body.msg1}}</p>
 <p>{{t hosts.delete.popup.body.msg2}}</p>
-<p><span class="label label-important">{{t common.important}}</span> {{t hosts.delete.popup.body.msg3}}</p>
+<p><span class="label label-important">{{t common.important}}</span> {{t hosts.delete.popup.body.msg3}}</p>
+{{#if lastComponent}}
+  <div class="alert-error row-fluid">
+      <div class='tinyspan tinyoffset'>{{view Ember.Checkbox checkedBinding="enablePrimary"}}</div>
+      <div class='span10'>{{view lastComponentError}}</div>
+  </div>
+{{/if}}

+ 2 - 2
ambari-web/app/views/common/modal_popup.js

@@ -40,7 +40,7 @@ App.ModalPopup = Ember.View.extend({
     '{{else}}',
     '<div class="modal-footer">',
     '{{#if view.secondary}}<a class="btn" {{action onSecondary target="view"}}>{{view.secondary}}</a>{{/if}}',
-    '{{#if view.primary}}<a class="btn btn-success" {{action onPrimary target="view"}}>{{view.primary}}</a>{{/if}}',
+    '{{#if view.primary}}<a {{bindAttr class="view.enablePrimary::disabled :btn :btn-success"}} {{action onPrimary target="view"}}>{{view.primary}}</a>{{/if}}',
     '</div>',
     '{{/if}}',
     '{{/if}}',
@@ -55,7 +55,7 @@ App.ModalPopup = Ember.View.extend({
   primary: Em.I18n.t('ok'),
   secondary: Em.I18n.t('common.cancel'),
   autoHeight: true,
-
+  enablePrimary: true,
   onPrimary: function () {
     this.hide();
   },