Browse Source

AMBARI-5088 Maintenance Mode fixes. (ababiichuk)

aBabiichuk 11 years ago
parent
commit
63f263f4d5

+ 28 - 45
ambari-web/app/controllers/main/host/details.js

@@ -44,6 +44,10 @@ App.MainHostDetailsController = Em.Controller.extend({
     App.router.transitionTo('main.services.service.summary',service);
   },
 
+  serviceActiveComponents: function() {
+    return this.get('content.hostComponents').filterProperty('service.passiveState','OFF')
+  }.property('content.hostComponents'),
+
   /**
    * Send specific command to server
    * @param url
@@ -102,10 +106,10 @@ App.MainHostDetailsController = Em.Controller.extend({
    * @param component  When <code>null</code> all startable components are started. 
    * @param context  Context under which this command is beign sent. 
    */
-  sendStartComponentCommand: function(component, context) {
-    var url = component !== null ?
-        '/hosts/' + this.get('content.hostName') + '/host_components/' + component.get('componentName').toUpperCase() : 
-        '/hosts/' + this.get('content.hostName') + '/host_components?HostRoles/maintenance_state=OFF';
+  sendStartComponentCommand: function(components, context) {
+    var url = Em.isArray(components) ?
+        '/hosts/' + this.get('content.hostName') + '/host_components' :
+        '/hosts/' + this.get('content.hostName') + '/host_components/' + components.get('componentName').toUpperCase();
     var dataToSend = {
       RequestInfo : {
         "context" : context
@@ -116,17 +120,8 @@ App.MainHostDetailsController = Em.Controller.extend({
         }
       }
     };
-    if (component === null) {
-      var allComponents = this.get('content.hostComponents');
-      var startable = [];
-      allComponents.forEach(function (c) {
-        if (c.get('passiveState') == 'OFF') {
-          if (c.get('isMaster') || c.get('isSlave')) {
-            startable.push(c.get('componentName'));
-          }
-        }
-      });
-      dataToSend.RequestInfo.query = "HostRoles/component_name.in(" + startable.join(',') + ")";
+    if (Em.isArray(components)) {
+      dataToSend.RequestInfo.query = "HostRoles/component_name.in(" + components.mapProperty('componentName').join(',') + ")";
     }
     this.sendCommandToServer(url, dataToSend, 'PUT',
       function(requestId){
@@ -138,7 +133,7 @@ App.MainHostDetailsController = Em.Controller.extend({
       console.log('Send request for STARTING successfully');
 
       if (App.testMode) {
-        if(component === null){
+        if(Em.isArray(components)){
           var allComponents = this.get('content.hostComponents');
           allComponents.forEach(function(component){
             component.set('workStatus', App.HostComponentStatus.stopping);
@@ -147,9 +142,9 @@ App.MainHostDetailsController = Em.Controller.extend({
             },App.testModeDelayForActions);
           });
         } else {
-          component.set('workStatus', App.HostComponentStatus.starting);
+          components.set('workStatus', App.HostComponentStatus.starting);
           setTimeout(function(){
-            component.set('workStatus', App.HostComponentStatus.started);
+            components.set('workStatus', App.HostComponentStatus.started);
           },App.testModeDelayForActions);
         }
       } else {
@@ -315,10 +310,10 @@ App.MainHostDetailsController = Em.Controller.extend({
    * @param component  When <code>null</code> all components are stopped. 
    * @param context  Context under which this command is beign sent. 
    */
-  sendStopComponentCommand: function(component, context){
-    var url = component !== null ?
-        '/hosts/' + this.get('content.hostName') + '/host_components/' + component.get('componentName').toUpperCase() : 
-        '/hosts/' + this.get('content.hostName') + '/host_components?HostRoles/maintenance_state=OFF';
+  sendStopComponentCommand: function(components, context){
+    var url = Em.isArray(components) ?
+        '/hosts/' + this.get('content.hostName') + '/host_components' :
+        '/hosts/' + this.get('content.hostName') + '/host_components/' + components.get('componentName').toUpperCase();
     var dataToSend = {
       RequestInfo : {
         "context" : context
@@ -329,17 +324,8 @@ App.MainHostDetailsController = Em.Controller.extend({
         }
       }
     };
-    if (component === null) {
-      var allComponents = this.get('content.hostComponents');
-      var startable = [];
-      allComponents.forEach(function (c) {
-        if (c.get('passiveState') == 'OFF') {
-          if (c.get('isMaster') || c.get('isSlave')) {
-            startable.push(c.get('componentName'));
-          }
-        }
-      });
-      dataToSend.RequestInfo.query = "HostRoles/component_name.in(" + startable.join(',') + ")";
+    if (Em.isArray(components)) {
+      dataToSend.RequestInfo.query = "HostRoles/component_name.in(" + components.mapProperty('componentName').join(',') + ")";
     }
     this.sendCommandToServer( url, dataToSend, 'PUT',
       function(requestId){
@@ -350,18 +336,17 @@ App.MainHostDetailsController = Em.Controller.extend({
       console.log('Send request for STOPPING successfully');
 
       if (App.testMode) {
-        if(component === null){
-          var allComponents = this.get('content.hostComponents');
-          allComponents.forEach(function(component){
+        if(Em.isArray(components)){
+          components.forEach(function(component){
             component.set('workStatus', App.HostComponentStatus.stopping);
             setTimeout(function(){
               component.set('workStatus', App.HostComponentStatus.stopped);
             },App.testModeDelayForActions);
           });
         } else {
-          component.set('workStatus', App.HostComponentStatus.stopping);
+          components.set('workStatus', App.HostComponentStatus.stopping);
           setTimeout(function(){
-            component.set('workStatus', App.HostComponentStatus.stopped);
+            components.set('workStatus', App.HostComponentStatus.stopped);
           },App.testModeDelayForActions);
         }
 
@@ -1021,31 +1006,29 @@ App.MainHostDetailsController = Em.Controller.extend({
 
   doStartAllComponents: function() {
     var self = this;
-    var components = this.get('content.hostComponents');
+    var components = this.get('serviceActiveComponents');
     var componentsLength = components == null ? 0 : components.get('length');
     if (componentsLength > 0) {
       App.showConfirmationPopup(function() {
-        self.sendStartComponentCommand(null, 
-            Em.I18n.t('hosts.host.maintainance.startAllComponents.context'));
+        self.sendStartComponentCommand(components, Em.I18n.t('hosts.host.maintainance.startAllComponents.context'));
       });
     }
   },
   
   doStopAllComponents: function() {
     var self = this;
-    var components = this.get('content.hostComponents');
+    var components = this.get('serviceActiveComponents');
     var componentsLength = components == null ? 0 : components.get('length');
     if (componentsLength > 0) {
       App.showConfirmationPopup(function() {
-        self.sendStopComponentCommand(null, 
-            Em.I18n.t('hosts.host.maintainance.stopAllComponents.context'));
+        self.sendStopComponentCommand(components, Em.I18n.t('hosts.host.maintainance.stopAllComponents.context'));
       });
     }
   },
 
   doRestartAllComponents: function() {
     var self = this;
-    var components = this.get('content.hostComponents').filterProperty('passiveState','OFF');
+    var components = this.get('serviceActiveComponents');
     var componentsLength = components == null ? 0 : components.get('length');
     if (componentsLength > 0) {
       App.showConfirmationPopup(function() {

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

@@ -73,7 +73,7 @@ module.exports = {
     var service = App.Service.find(serviceName);
     var context = staleConfigsOnly ? Em.I18n.t('rollingrestart.context.allWithStaleConfigsForSelectedService').format(serviceName) : Em.I18n.t('rollingrestart.context.allForSelectedService').format(serviceName);
     if (service) {
-      var hostComponents = service.get('hostComponents');
+      var hostComponents = service.get('hostComponents').filterProperty('host.passiveState','OFF');
       if (staleConfigsOnly) {
         hostComponents = hostComponents.filterProperty('staleConfigs', true);
       }

+ 6 - 1
ambari-web/app/views/common/rolling_restart_view.js

@@ -146,7 +146,12 @@ App.RollingRestartView = Em.View.extend({
    * @type {Array}
    */
   restartHostComponents : function() {
-    var hostComponents = this.get('skipMaintenance') ? this.get('allHostComponents') : this.get('nonMaintainanceHostComponents');
+    var hostComponents = null;
+    if (this.get('skipMaintenance')) {
+      hostComponents = this.get('allHostComponents').filterProperty('host.passiveState','OFF');
+    } else {
+      hostComponents = this.get('nonMaintainanceHostComponents');
+    }
     if (this.get('staleConfigsOnly')) {
       hostComponents = hostComponents.filterProperty('staleConfigs', true);
     }