瀏覽代碼

AMBARI-4309. Connect stale-config restarts to rolling restart dialog. (srimanth)

Srimanth Gunturi 11 年之前
父節點
當前提交
067b1b60ca

+ 5 - 71
ambari-web/app/controllers/main/host/details.js

@@ -17,6 +17,7 @@
  */
 
 var App = require('app');
+var batchUtils = require('utils/batch_scheduled_requests');
 
 App.MainHostDetailsController = Em.Controller.extend({
   name: 'mainHostDetailsController',
@@ -991,78 +992,11 @@ App.MainHostDetailsController = Em.Controller.extend({
     })
   },
 
-  restartComponents: function(e) {
-    var staleComponents = this.get('content.hostComponents').filterProperty('staleConfigs', true);
-    var commandName = "stop_component";
-    if(e.context) {
-      if(!staleComponents.findProperty('workStatus','STARTED')){
-        return;
-      }
-    } else {
-      commandName = "start_component";
-      if(!staleComponents.findProperty('workStatus','INSTALLED')){
-        return;
-      }
-    }
-
-    var nonClientRequestInfo = commandName == 'start_component' ? 'Start Components' : 'Stop Components';
-    var clientRequestInfo = 'Update Clients';
-    var desiredState = commandName == 'start_component' ? 'STARTED' : 'INSTALLED';
-
-    var content = this;
-    return App.ModalPopup.show({
-      primary: Em.I18n.t('ok'),
-      secondary: Em.I18n.t('common.cancel'),
-      header: Em.I18n.t('popup.confirmation.commonHeader'),
-      body: Em.I18n.t('question.sure'),
-      content: content,
-      onPrimary: function () {
-        var hostName = this.content.get('content.hostName');
-        var hostComponents = this.content.get('content.hostComponents');
-
-        // the action is to either 1) start stale components for the host or 2) stop stale components for the host
-        // start is done through two API calls:
-        //  * call to start non-client components
-        //  * call to update clients
-        // stop is done through one API call:
-        //  * call to stop non-client components
-
-        var nonClientComponentNames = hostComponents.filterProperty('isClient', false).mapProperty('componentName').uniq();
-        var clientComponentNames = hostComponents.filterProperty('isClient', true).mapProperty('componentName').uniq();
-
-        App.ajax.send({
-          name: 'host.stale_host_components.start_stop',
-          sender: this,
-          data: {
-            hostName: hostName,
-            context: nonClientRequestInfo,
-            componentNames: nonClientComponentNames,
-            state: desiredState
-          }
-        });
-
-        if (desiredState == 'STARTED') {
-          App.ajax.send({
-            name: 'host.stale_host_components.start_stop',
-            sender: this,
-            data: {
-              hostName: hostName,
-              context: clientRequestInfo,
-              componentNames: clientComponentNames,
-              state: 'INSTALLED'
-            }
-          });
-        }
-        this.hide();
-        // load data (if we need to show this background operations popup) from persist
-        App.router.get('applicationController').dataLoading().done(function (initValue) {
-          if (initValue) {
-            App.router.get('backgroundOperationsController').showPopup();
-          }
-        });
-      }
-    });
+  restartAllStaleConfigComponents: function() {
+    var staleComponents = this.get('content.componentsWithStaleConfigs');
+    batchUtils.restartHostComponents(staleComponents);
   },
+
   /**
    * open Reassign Master Wizard with selected component
    * @param event

+ 7 - 56
ambari-web/app/controllers/main/service/info/configs.js

@@ -18,6 +18,7 @@
 
 var App = require('app');
 require('controllers/wizard/slave_component_groups_controller');
+var batchUtils = require('utils/batch_scheduled_requests');
 
 App.MainServiceInfoConfigsController = Em.Controller.extend({
   name: 'mainServiceInfoConfigsController',
@@ -1751,18 +1752,7 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
     this.loadStep();
   },
 
-  restartComponents: function(e) {
-    var commandName = "stop_component";
-    if (e.context) {
-      if (!this.get('content.hostComponents').filterProperty('staleConfigs').findProperty('workStatus', 'STARTED')) {
-        return;
-      }
-    } else {
-      commandName = "start_component";
-      if (!this.get('content.hostComponents').filterProperty('staleConfigs').findProperty('workStatus', 'INSTALLED')) {
-        return;
-      }
-    }
+  restartAllStaleConfigComponents: function() {
     var content = this;
     return App.ModalPopup.show({
       primary: Em.I18n.t('ok'),
@@ -1772,55 +1762,16 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
       content: content,
       onPrimary: function () {
         var selectedService = this.content.get('content.id');
-        var hostComponents = App.HostComponent.find().filterProperty('service.id', selectedService);
-        var desiredState = commandName == 'start_component' ? 'STARTED' : 'INSTALLED';
-        var nonClientRequestInfo = commandName == 'start_component' ? 'Start Components' : 'Stop Components';
-        var clientRequestInfo = 'Update Clients';
-
-        // the action is to either 1) start stale components for the service or 2) stop stale components for the service
-        // start is done through two API calls:
-        //  * first call to start non-client components
-        //  * second call to update clients
-        // stop is done through one API call:
-        //  * call to stop non-client components
-
-        var nonClientComponentNames = hostComponents.filterProperty('isClient', false).mapProperty('componentName').uniq();
-        var clientComponentNames = hostComponents.filterProperty('isClient', true).mapProperty('componentName').uniq();
-
-        // start/stop stale non-client host components for the service
-        App.ajax.send({
-          name: 'service.stale_host_components.start_stop',
-          sender: this,
-          data: {
-            componentNames: nonClientComponentNames.join(','),
-            requestInfo: nonClientRequestInfo,
-            state: desiredState
-          }
-        });
-
-        // start only: update stale client host components for the service
-        if (desiredState == 'STARTED') {
-          App.ajax.send({
-            name: 'service.stale_host_components.start_stop',
-            sender: this,
-            data: {
-              componentNames: clientComponentNames.join(','),
-              requestInfo: clientRequestInfo,
-              state: 'INSTALLED'
-            }
-          });
-        }
         this.hide();
-        // load data (if we need to show this background operations popup) from persist
-        App.router.get('applicationController').dataLoading().done(function (initValue) {
-          if (initValue) {
-            App.router.get('backgroundOperationsController').showPopup();
-          }
-        });
+        batchUtils.restartAllServiceHostComponents(selectedService, true);
       }
     });
   },
 
+  rollingRestartStaleConfigSlaveComponents: function(componentName) {
+    batchUtils.launchHostComponentRollingRestart(componentName.context, true);
+  },
+
   showHostsShouldBeRestarted: function() {
     var hosts = [];
     for(var hostName in this.get('content.restartRequiredHostsAndComponents')) {

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

@@ -188,7 +188,7 @@ App.MainServiceItemController = Em.Controller.extend({
   },
 
   restartAllHostComponents : function(serviceName) {
-    batchUtils.doPostRestartAllServiceComponents(serviceName);
+    batchUtils.restartAllServiceHostComponents(serviceName, false);
   },
 
   rollingRestart: function(hostComponentName) {

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

@@ -1376,9 +1376,7 @@ Em.I18n.translations = {
 
   'hosts.host.details.hostActions':'Host Actions',
   'hosts.host.details.needToRestart':'Host needs {0} {1} restarted',
-  'hosts.host.details.needToRestart.button':'Restart components',
-  'hosts.host.details.needToRestart.stopButton':'Stop Components',
-  'hosts.host.details.needToRestart.startButton':'Start Components',
+  'hosts.host.details.needToRestart.button':'Restart',
   'hosts.host.details.deleteHost':'Delete Host',
   'hosts.host.details.startAllComponents':'Start All Components',
   'hosts.host.details.stopAllComponents':'Stop All Components',

+ 6 - 2
ambari-web/app/models/host.js

@@ -74,13 +74,17 @@ App.Host = DS.Model.extend({
     return 0;
   }.property('memTotal', 'memFree'),
 
+  componentsWithStaleConfigs: function () {
+    return this.get('hostComponents').filterProperty('staleConfigs', true);
+  }.property('hostComponents.@each.staleConfigs'),
+
   /**
    * Get count of host components with stale configs
    * @returns {Number}
    */
   componentsWithStaleConfigsCount: function() {
-    return this.get('hostComponents').filterProperty('staleConfigs', true).length;
-  }.property('hostComponents.@each.staleConfigs'),
+    return this.get('componentsWithStaleConfigs').length;
+  }.property('componentsWithStaleConfigs.length'),
 
   /**
    * Get count of host components in maintenance mode

+ 2 - 7
ambari-web/app/templates/main/host/summary.hbs

@@ -30,13 +30,8 @@
           {{#if view.content.componentsWithStaleConfigsCount}}
               <div class="alert alert-warning clearfix">
                 <i class="icon-refresh"></i> {{view.needToRestartMessage}}
-                <br/>
-                <button {{bindAttr class=":btn :restart-components :pull-left view.stopComponentsIsDisabled::btn-danger" disabled="view.stopComponentsIsDisabled"}} {{action restartComponents view.isStopCommand target="controller"}}>
-                  {{t hosts.host.details.needToRestart.stopButton}}
-                </button>
-                 <span class="restart-components  pull-left">&nbsp</span>
-                 <button {{bindAttr class=":btn :restart-components :pull-left view.startComponentsIsDisabled::btn-success" disabled="view.startComponentsIsDisabled"}} {{action restartComponents target="controller"}}>
-                  {{t hosts.host.details.needToRestart.startButton}}
+                 <button {{bindAttr class=":btn :restart-components :pull-right :btn-warning"}} {{action restartAllStaleConfigComponents target="controller"}}>
+                  {{t hosts.host.details.needToRestart.button}}
                  </button>
               </div>
           {{/if}}

+ 12 - 7
ambari-web/app/templates/main/service/info/configs.hbs

@@ -24,14 +24,19 @@
           <div>
             <div class="alert alert-warning clearfix">
               <i class="icon-refresh"></i> {{{view.needToRestartMessage}}} {{t services.service.config.restartService.needToRestart}}  <a href="#" {{action showComponentsShouldBeRestarted target="controller"}}>{{view.componentsCount}} {{pluralize view.componentsCount singular="t:common.component" plural="t:common.components"}}</a> {{t on}} <a href="#" {{action showHostsShouldBeRestarted target="controller"}}>{{view.hostsCount}} {{pluralize view.hostsCount singular="t:common.host" plural="t:common.hosts"}}</a>
-
-              <button {{bindAttr class=":btn :restart-components :pull-right view.startComponentsIsDisabled::btn-success view.startComponentsIsDisabled:disabled" }} {{action restartComponents target="controller"}}>
-                {{t hosts.host.details.needToRestart.startButton}}
-              </button>
               <span class="restart-components pull-right">&nbsp</span>
-              <button {{bindAttr class=":btn :restart-components :pull-right view.stopComponentsIsDisabled::btn-danger view.stopComponentsIsDisabled:disabled" }} {{action restartComponents view.isStopCommand target="controller"}}>
-                {{t hosts.host.details.needToRestart.stopButton}}
-              </button>
+              <div class="btn-group pull-right">
+                <button type="button" class="btn btn-default dropdown-toggle btn-warning" data-toggle="dropdown">
+                  {{t hosts.host.details.needToRestart.button}}
+                  <span class="caret"></span>
+                </button>
+                <ul class="dropdown-menu">
+                  <li><a href="#" {{action restartAllStaleConfigComponents target="controller"}}>{{t restart.service.all}}</a></li>
+                  {{#if view.rollingRestartSlaveComponentName}}
+                    <li><a href="#" {{action rollingRestartStaleConfigSlaveComponents view.rollingRestartSlaveComponentName target="controller"}}>{{view.rollingRestartActionName}}</a></li>
+                  {{/if}}
+                </ul>
+              </div>
             </div>
           </div>
         {{/if}}

+ 24 - 16
ambari-web/app/utils/batch_scheduled_requests.js

@@ -49,30 +49,38 @@ module.exports = {
     return rollingRestartComponent;
   },
 
-  doPostRestartAllServiceComponents : function(serviceName) {
-    var allHostComponents = App.HostComponent.find();
+  restartAllServiceHostComponents : function(serviceName, staleConfigsOnly) {
+    var service = App.Service.find(serviceName);
+    if (service) {
+      var hostComponents = service.get('hostComponents')
+      if (staleConfigsOnly) {
+        hostComponents = hostComponents.filterProperty('staleConfigs', true);
+      }
+      this.restartHostComponents(hostComponents);
+    }
+  },
+
+  restartHostComponents : function(hostComponentsList) {
     var componentToHostsMap = {};
-    var componentCount = 0;
-    allHostComponents.forEach(function(hc) {
-      if (serviceName == hc.get('service.serviceName')) {
-        var componentName = hc.get('componentName');
-        if (!componentToHostsMap[componentName]) {
-          componentToHostsMap[componentName] = [];
-          componentCount++;
-        }
-        componentToHostsMap[componentName].push(hc.get('host.hostName'));
+    var componentToServiceMap = {};
+    hostComponentsList.forEach(function(hc) {
+      var componentName = hc.get('componentName');
+      if (!componentToHostsMap[componentName]) {
+        componentToHostsMap[componentName] = [];
       }
+      componentToHostsMap[componentName].push(hc.get('host.hostName'));
+      componentToServiceMap[componentName] = hc.get('service.serviceName');
     });
     for ( var componentName in componentToHostsMap) {
       var hosts = componentToHostsMap[componentName].join(",");
       var data = {
-        serviceName : serviceName,
+        serviceName : componentToServiceMap[componentName],
         componentName : componentName,
         hosts : hosts
       }
       var sender = {
         successFunction : function() {
-          App.router.get('applicationController').dataLoading().done(function (initValue) {
+          App.router.get('applicationController').dataLoading().done(function(initValue) {
             if (initValue) {
               App.router.get('backgroundOperationsController').showPopup();
             }
@@ -96,7 +104,7 @@ module.exports = {
    * Makes a REST call to the server requesting the rolling restart of the
    * provided host components.
    */
-  doPostBatchRollingRestartRequest : function(restartHostComponents, batchSize, intervalTimeSeconds, tolerateSize, successCallback, errorCallback) {
+  _doPostBatchRollingRestartRequest : function(restartHostComponents, batchSize, intervalTimeSeconds, tolerateSize, successCallback, errorCallback) {
     var clusterName = App.get('clusterName');
     var data = {
       restartHostComponents : restartHostComponents,
@@ -175,9 +183,9 @@ module.exports = {
           var batchSize = this.get('innerView.batchSize');
           var waitTime = this.get('innerView.interBatchWaitTimeSeconds');
           var tolerateSize = this.get('innerView.tolerateSize');
-          self.doPostBatchRollingRestartRequest(restartComponents, batchSize, waitTime, tolerateSize, function() {
+          self._doPostBatchRollingRestartRequest(restartComponents, batchSize, waitTime, tolerateSize, function() {
             dialog.hide();
-            App.router.get('applicationController').dataLoading().done(function (initValue) {
+            App.router.get('applicationController').dataLoading().done(function(initValue) {
               if (initValue) {
                 App.router.get('backgroundOperationsController').showPopup();
               }

+ 0 - 18
ambari-web/app/views/main/host/summary.js

@@ -34,24 +34,6 @@ App.MainHostSummaryView = Em.View.extend({
     window.open(gangliaMobileUrl);
   },
 
-  stopComponentsIsDisabled: function () {
-    var staleComponents = this.get('content.hostComponents').filterProperty('staleConfigs', true);
-    if(!staleComponents.findProperty('workStatus','STARTED')){
-      return true;
-    } else {
-      return false;
-    }
-  }.property('content.hostComponents.@each.workStatus', 'content.hostComponents.@each.staleConfigs'),
-
-  startComponentsIsDisabled:function () {
-    var staleComponents = this.get('content.hostComponents').filterProperty('staleConfigs', true);
-    if(!staleComponents.findProperty('workStatus','INSTALLED')){
-      return true;
-    } else {
-      return false;
-    }
-  }.property('content.hostComponents.@each.workStatus', 'content.hostComponents.@each.staleConfigs'),
-
   needToRestartMessage: function() {
     var componentsCount, word;
     componentsCount = this.get('content.componentsWithStaleConfigsCount');

+ 16 - 21
ambari-web/app/views/main/service/info/configs.js

@@ -17,6 +17,7 @@
  */
 
 var App = require('app');
+var batchUtils = require('utils/batch_scheduled_requests');
 
 App.MainServiceInfoConfigsView = Em.View.extend({
   templateName: require('templates/main/service/info/configs'),
@@ -29,26 +30,7 @@ App.MainServiceInfoConfigsView = Em.View.extend({
   hostsCount: null,
   isStopCommand:true,
 
-
-  stopComponentsIsDisabled: function () {
-    var staleComponents = this.get('controller.content.hostComponents').filterProperty('staleConfigs', true);
-    if (!staleComponents.findProperty('workStatus', 'STARTED')) {
-      return true;
-    } else {
-      return false;
-    }
-  }.property('controller.content.hostComponents.@each.workStatus', 'controller.content.hostComponents.@each.staleConfigs'),
-
-  startComponentsIsDisabled: function () {
-    var staleComponents = this.get('controller.content.hostComponents').filterProperty('staleConfigs', true);
-    if (!staleComponents.findProperty('workStatus', 'INSTALLED')) {
-      return true;
-    } else {
-      return false;
-    }
-  }.property('controller.content.hostComponents.@each.workStatus', 'controller.content.hostComponents.@each.staleConfigs'),
-
-  calculateCounts: function() {
+  updateComponentInformation: function() {
     var hc = this.get('controller.content.restartRequiredHostsAndComponents');
     var hostsCount = 0;
     var componentsCount = 0;
@@ -58,5 +40,18 @@ App.MainServiceInfoConfigsView = Em.View.extend({
     }
     this.set('componentsCount', componentsCount);
     this.set('hostsCount', hostsCount);
-  }.observes('controller.content.restartRequiredHostsAndComponents')
+  }.observes('controller.content.restartRequiredHostsAndComponents'),
+
+  rollingRestartSlaveComponentName : function() {
+    return batchUtils.getRollingRestartComponentName(this.get('controller.content.serviceName'));
+  }.property('controller.content.serviceName'),
+
+  rollingRestartActionName : function() {
+    var label = null;
+    var componentName = this.get('rollingRestartSlaveComponentName');
+    if (componentName) {
+      label = Em.I18n.t('rollingrestart.dialog.title').format(App.format.role(componentName));
+    }
+    return label;
+  }.property('rollingRestartSlaveComponentName')
 });