You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2013/11/13 14:43:59 UTC

git commit: AMBARI-3757 Unable to delete host or host-components without warning. (atkach)

Updated Branches:
  refs/heads/trunk 5d9960243 -> d639a7f06


AMBARI-3757 Unable to delete host or host-components without warning. (atkach)


Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/d639a7f0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/d639a7f0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/d639a7f0

Branch: refs/heads/trunk
Commit: d639a7f061dcbe2ea287b9d32bf8602ad34223f8
Parents: 5d99602
Author: atkach <an...@gmail.com>
Authored: Wed Nov 13 15:43:54 2013 +0200
Committer: atkach <an...@gmail.com>
Committed: Wed Nov 13 15:43:54 2013 +0200

----------------------------------------------------------------------
 ambari-web/app/controllers/main/host/details.js | 110 ++++++++-----------
 1 file changed, 48 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/d639a7f0/ambari-web/app/controllers/main/host/details.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/host/details.js b/ambari-web/app/controllers/main/host/details.js
index 13fb3e8..916c971 100644
--- a/ambari-web/app/controllers/main/host/details.js
+++ b/ambari-web/app/controllers/main/host/details.js
@@ -169,18 +169,9 @@ App.MainHostDetailsController = Em.Controller.extend({
   deleteComponent: function (event) {
     var self = this;
     var component = event.context;
-    var componentName = component.get('componentName').toUpperCase().toString();
+    var componentName = component.get('componentName');
     var displayName = component.get('displayName');
-    var numberOfComponents = 0;
-    var isLastComponent = false;
-    var allComponents = component.get('service.hostComponents');
-    allComponents.forEach(function(component) {
-      if (component.get('componentName') == componentName) numberOfComponents++;
-      if (numberOfComponents > 1) return;
-    });
-    if (numberOfComponents == 1) {
-      isLastComponent = true;
-    }
+    var isLastComponent = (App.HostComponent.find().filterProperty('componentName', componentName).get('length') === 1);
     App.ModalPopup.show({
       header: Em.I18n.t('popup.confirmation.commonHeader'),
       bodyClass: Ember.View.extend({
@@ -711,57 +702,52 @@ App.MainHostDetailsController = Em.Controller.extend({
   /**
    * Deletion of hosts not supported for this version
    */
-   validateAndDeleteHost: function () {
-     if (!App.supports.deleteHost) {
-       return;
-     }
-     var stoppedStates = [App.HostComponentStatus.stopped, 
-                          App.HostComponentStatus.install_failed, 
-                          App.HostComponentStatus.upgrade_failed,
-                          App.HostComponentStatus.unknown];
-     var masterComponents = [];
-     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) {
-         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'));
-         }
-         if (stoppedStates.indexOf(workStatus) < 0) {
-           runningComponents.push(cInstance.get('displayName'));
-         }
-         if (!cInstance.get('isDeletable')) {
-           nonDeletableComponents.push(cInstance.get('displayName'));
-         }
-         if (workStatus === App.HostComponentStatus.unknown) {
-           unknownComponents.push(cInstance.get('displayName'));
-         }
-       });
-     }
-     if (masterComponents.length > 0) {
-       this.raiseDeleteComponentsError(masterComponents, 'masterList');
-       return;
-     } else if (nonDeletableComponents.length > 0) {
-       this.raiseDeleteComponentsError(nonDeletableComponents, 'nonDeletableList');
-       return;
-     } else if(runningComponents.length > 0) {
-       this.raiseDeleteComponentsError(runningComponents, 'runningList');
-       return;
-     }
-     this._doDeleteHost(unknownComponents,lastComponents);
+  validateAndDeleteHost: function () {
+    if (!App.supports.deleteHost) {
+      return;
+    }
+    var stoppedStates = [App.HostComponentStatus.stopped,
+                         App.HostComponentStatus.install_failed,
+                         App.HostComponentStatus.upgrade_failed,
+                         App.HostComponentStatus.unknown];
+    var masterComponents = [];
+    var runningComponents = [];
+    var unknownComponents = [];
+    var nonDeletableComponents = [];
+    var lastComponents = [];
+    var componentsOnHost = this.get('content.hostComponents');
+    var allComponents = App.HostComponent.find();
+    if (componentsOnHost && componentsOnHost.get('length') > 0) {
+      componentsOnHost.forEach(function (cInstance) {
+        if (allComponents.filterProperty('componentName', cInstance.get('componentName')).get('length') === 1) {
+          lastComponents.push(cInstance.get('displayName'));
+        }
+        var workStatus = cInstance.get('workStatus');
+        if (cInstance.get('isMaster') && !cInstance.get('isDeletable')) {
+          masterComponents.push(cInstance.get('displayName'));
+        }
+        if (stoppedStates.indexOf(workStatus) < 0) {
+          runningComponents.push(cInstance.get('displayName'));
+        }
+        if (!cInstance.get('isDeletable')) {
+          nonDeletableComponents.push(cInstance.get('displayName'));
+        }
+        if (workStatus === App.HostComponentStatus.unknown) {
+          unknownComponents.push(cInstance.get('displayName'));
+        }
+      });
+    }
+    if (masterComponents.length > 0) {
+      this.raiseDeleteComponentsError(masterComponents, 'masterList');
+      return;
+    } else if (nonDeletableComponents.length > 0) {
+      this.raiseDeleteComponentsError(nonDeletableComponents, 'nonDeletableList');
+      return;
+    } else if (runningComponents.length > 0) {
+      this.raiseDeleteComponentsError(runningComponents, 'runningList');
+      return;
+    }
+    this._doDeleteHost(unknownComponents, lastComponents);
   },
   
   raiseDeleteComponentsError: function (components, type) {