Pārlūkot izejas kodu

AMBARI-6276 Prompt to put Service in Maintenance Mode when doing Rolling Restart / Service Stop. (ababiichuk)

aBabiichuk 11 gadi atpakaļ
vecāks
revīzija
9a8cdf910f

+ 26 - 30
ambari-web/app/controllers/main/service/item.js

@@ -90,36 +90,46 @@ App.MainServiceItemController = Em.Controller.extend({
     var serviceDisplayName = this.get('content.displayName');
     var isMaintenanceOFF = this.get('content.passiveState') === 'OFF';
     var bodyMessage = Em.Object.create({
+      putInMaintenance: (serviceHealth == 'INSTALLED' && isMaintenanceOFF) || (serviceHealth == 'STARTED' && !isMaintenanceOFF),
+      turnOnMmMsg: serviceHealth == 'INSTALLED' ? Em.I18n.t('passiveState.turnOnFor').format(serviceDisplayName) : Em.I18n.t('passiveState.turnOffFor').format(serviceDisplayName),
       confirmMsg: serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.confirmMsg').format(serviceDisplayName) : Em.I18n.t('question.sure'),
       confirmButton: serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.confirmButton') : Em.I18n.t('ok'),
       additionalWarningMsg:  isMaintenanceOFF && serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.warningMsg.turnOnMM').format(serviceDisplayName) : null
     });
 
-    return App.showConfirmationFeedBackPopup(function(query) {
+    return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
       self.set('isPending', true);
-      self.startStopPopupPrimary(serviceHealth, query);
+      self.startStopPopupPrimary(serviceHealth, query, runMmOperation);
     }, bodyMessage);
   },
 
-  startStopPopupPrimary: function (serviceHealth, query) {
+  startStopPopupPrimary: function (serviceHealth, query, runMmOperation) {
     var requestInfo = "";
+    var turnOnMM = "ON"
     if (serviceHealth == "STARTED") {
+      turnOnMM = "OFF"
       requestInfo = App.BackgroundOperationsController.CommandContexts.START_SERVICE.format(this.get('content.serviceName'));
     } else {
       requestInfo = App.BackgroundOperationsController.CommandContexts.STOP_SERVICE.format(this.get('content.serviceName'));
     }
 
+    var data = {
+      'requestInfo': requestInfo,
+      'serviceName': this.get('content.serviceName').toUpperCase(),
+      'ServiceInfo': {
+        'state': serviceHealth
+      },
+      'query': query
+    };
+    if (runMmOperation) {
+      data.ServiceInfo.maintenance_state = turnOnMM;
+    }
     App.ajax.send({
       'name': 'service.item.start_stop',
       'sender': this,
       'success': 'startStopPopupSuccessCallback',
       'error': 'startStopPopupErrorCallback',
-      'data': {
-        'requestInfo': requestInfo,
-        'serviceName': this.get('content.serviceName').toUpperCase(),
-        'state': serviceHealth,
-        'query': query
-      }
+      'data': data
     });
     this.set('isStopDisabled', true);
     this.set('isStartDisabled', true);
@@ -192,13 +202,15 @@ App.MainServiceItemController = Em.Controller.extend({
   restartAllHostComponents : function(serviceName) {
     var serviceDisplayName = this.get('content.displayName');
     var bodyMessage = Em.Object.create({
+      putInMaintenance: this.get('content.passiveState') === 'OFF',
+      turnOnMmMsg: Em.I18n.t('passiveState.turnOnFor').format(serviceDisplayName),
       confirmMsg: Em.I18n.t('services.service.restartAll.confirmMsg').format(serviceDisplayName),
       confirmButton: Em.I18n.t('services.service.restartAll.confirmButton'),
       additionalWarningMsg: this.get('content.passiveState') === 'OFF' ? Em.I18n.t('services.service.restartAll.warningMsg.turnOnMM').format(serviceDisplayName): null
      });
     var staleConfigsOnly = App.Service.find(serviceName).get('serviceTypes').contains('MONITORING');
-    return App.showConfirmationFeedBackPopup(function(query) {
-      batchUtils.restartAllServiceHostComponents(serviceName, staleConfigsOnly, query);
+    return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
+      batchUtils.restartAllServiceHostComponents(serviceName, staleConfigsOnly, query, runMmOperation);
     }, bodyMessage);
   },
 
@@ -207,7 +219,9 @@ App.MainServiceItemController = Em.Controller.extend({
     var state = this.get('content.passiveState') == 'OFF' ? 'ON' : 'OFF';
     var onOff = state === 'ON' ? "On" : "Off";
     return App.showConfirmationPopup(function() {
-          self.turnOnOffPassiveRequest(state, label)
+          batchUtils.turnOnOffPassiveRequest(state, label, self.get('content.serviceName').toUpperCase(), function(data, opt, params) {
+            self.set('content.passiveState', params.passive_state);
+            batchUtils.infoPassiveState(params.passive_state);})
         },
         Em.I18n.t('hosts.passiveMode.popup').format(onOff,self.get('content.displayName'))
     );
@@ -217,24 +231,6 @@ App.MainServiceItemController = Em.Controller.extend({
     batchUtils.launchHostComponentRollingRestart(hostComponentName, this.get('content.displayName'), this.get('content.passiveState') === "ON", false, this.get('content.passiveState') === "ON");
   },
 
-  turnOnOffPassiveRequest: function(state,message) {
-    App.ajax.send({
-      'name': 'service.item.passive',
-      'sender': this,
-      'data': {
-        'requestInfo': message,
-        'serviceName': this.get('content.serviceName').toUpperCase(),
-        'passive_state': state
-      },
-      'success':'updateService'
-    });
-  },
-
-  updateService: function(data, opt, params) {
-    this.set('content.passiveState', params.passive_state);
-    batchUtils.infoPassiveState(params.passive_state);
-  },
-
   runSmokeTestPrimary: function(query) {
     App.ajax.send({
       'name': 'service.item.smoke',

+ 3 - 0
ambari-web/app/templates/common/confirmation_feedback.hbs

@@ -24,4 +24,7 @@
     {{view.parentView.additionalWarningMsg}}
   </div>
 {{/if}}
+{{#if view.parentView.putInMaintenance}}
+  <label class="checkbox">{{view Ember.Checkbox checkedBinding="view.parentView.runMmOperation"}} {{view.parentView.turnOnMmMsg}}</label>
+{{/if}}
 

+ 10 - 0
ambari-web/app/templates/common/rolling_restart_view.hbs

@@ -56,6 +56,16 @@
           {{view.staleConfigsOnlyMessage}}
         </td>
       </tr>
+      <tr>
+        <td>&nbsp;</td>
+        <td colspan="2">
+          {{#unless view.isServiceInMM}}
+            {{view Ember.Checkbox checkedBinding="view.turnOnMm"}}
+            {{view.turnOnMmMsg}}
+          {{/unless}}
+        </td>
+      </tr>
+
     </table>
   {{else}}
     <div class="spinner"></div>

+ 1 - 3
ambari-web/app/utils/ajax/ajax.js

@@ -69,9 +69,7 @@ var urls = {
             }
           },
           Body: {
-            ServiceInfo: {
-              state: data.state
-            }
+            ServiceInfo: data.ServiceInfo
           }
         })
       };

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

@@ -69,11 +69,14 @@ module.exports = {
    * @param {String} serviceName for which service hostComponents should be restarted
    * @param {bool} staleConfigsOnly restart only hostComponents with <code>staleConfig</code> true
    */
-  restartAllServiceHostComponents: function(serviceName, staleConfigsOnly, query) {
+  restartAllServiceHostComponents: function(serviceName, staleConfigsOnly, query, runMmOperation) {
     var self = this;
     var context = staleConfigsOnly ? Em.I18n.t('rollingrestart.context.allWithStaleConfigsForSelectedService').format(serviceName) : Em.I18n.t('rollingrestart.context.allForSelectedService').format(serviceName);
     var services = (serviceName === 'HIVE' && App.Service.find('HCATALOG').get('isLoaded')) ? ['HIVE', 'HCATALOG'] : [serviceName];
 
+    if (runMmOperation) {
+      this.turnOnOffPassiveRequest('ON', Em.I18n.t('passiveState.turnOnFor').format(serviceName), serviceName);
+    }
     this.getComponentsFromServer({
       services: services,
       staleConfigs: staleConfigsOnly ? staleConfigsOnly : null,
@@ -263,6 +266,22 @@ module.exports = {
     }
     return operationLevel;
   },
+
+  turnOnOffPassiveRequest: function(state, message, serviceName, callback) {
+    App.ajax.send({
+      'name': 'service.item.passive',
+      'sender': {
+        'successCallback': callback || defaultSuccessCallback,
+        'errorCallback': defaultErrorCallback
+      },
+      'data': {
+        'requestInfo': message,
+        'serviceName': serviceName,
+        'passive_state': state
+      },
+      'success': 'successCallback'
+    });
+  },
   /**
    * Makes a REST call to the server requesting the rolling restart of the
    * provided host components.
@@ -374,6 +393,8 @@ module.exports = {
     }
     var title = Em.I18n.t('rollingrestart.dialog.title').format(componentDisplayName);
     var viewExtend = {
+      turnOnMmMsg: Em.I18n.t('passiveState.turnOnFor').format(serviceName),
+      turnOnMm: false,
       staleConfigsOnly : staleConfigsOnly,
       hostComponentName : hostComponentName,
       skipMaintenance: skipMaintenance,
@@ -431,6 +452,9 @@ module.exports = {
         var batchSize = this.get('innerView.batchSize');
         var waitTime = this.get('innerView.interBatchWaitTimeSeconds');
         var tolerateSize = this.get('innerView.tolerateSize');
+        if (this.get('innerView.turnOnMm')) {
+          self.turnOnOffPassiveRequest('ON', Em.I18n.t('passiveState.turnOnFor').format(serviceName), serviceName);
+        }
         self._doPostBatchRollingRestartRequest(restartComponents, batchSize, waitTime, tolerateSize, function(data, ajaxOptions, params) {
           dialog.hide();
           defaultSuccessCallback(data, ajaxOptions, params);

+ 8 - 1
ambari-web/app/views/common/modal_popup.js

@@ -176,7 +176,7 @@ App.showConfirmationFeedBackPopup = function (primary, bodyMessage, secondary) {
       this.set('disableSecondary', true);
       this.set('statusMessage', Em.I18n.t('popup.confirmationFeedBack.sending'));
       this.hide();
-      primary(this.get('query'));
+      primary(this.get('query'), this.get('runMmOperation'));
     },
     statusMessage: function () {
       return bodyMessage? bodyMessage.confirmMsg : Em.I18n.t('question.sure');
@@ -184,6 +184,13 @@ App.showConfirmationFeedBackPopup = function (primary, bodyMessage, secondary) {
     additionalWarningMsg: function () {
       return bodyMessage? bodyMessage.additionalWarningMsg : null;
     }.property('bodyMessage'),
+    putInMaintenance: function () {
+      return bodyMessage ? bodyMessage.putInMaintenance : null;
+    }.property('bodyMessage'),
+    runMmOperation: false,
+    turnOnMmMsg: function () {
+      return bodyMessage ? bodyMessage.turnOnMmMsg : null;
+    }.property('bodyMessage'),
     watchStatus: function() {
       if (this.get('query.status') === "SUCCESS") {
         this.hide();

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

@@ -44,6 +44,12 @@ App.RollingRestartView = Em.View.extend({
    */
   isServiceInMM: false,
 
+  /**
+   * If true service will be put in Maintenance mode before rolling restart
+   * @type {bool}
+   */
+  turnOnMm: false,
+
 
   /**
    * Restart only components with <code>staleConfigs</code>