Ver Fonte

AMBARI-3727. Need ability to restart host_components in bulk (on services and hosts) (alexantonenko)

Alex Antonenko há 11 anos atrás
pai
commit
a9f5a470a8

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

@@ -867,9 +867,47 @@ App.MainHostDetailsController = Em.Controller.extend({
     })
   },
 
-  restartComponents: function() {
-    App.showConfirmationPopup(function() {
-
+  restartComponents: function(e) {
+    var staleComponents = this.get('content.hostComponents').filterProperty('staleConfigs', true);
+    var commandName = "stop_component";
+    if(e.context) {
+      if(!staleComponents.findProperty('workStatus','INSTALLED')){
+        return;
+      }
+    }else {
+      commandName = "start_component";
+      if(!staleComponents.findProperty('workStatus','STARTED')){
+        return;
+      }
+    };
+    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 hostComponents = this.content.get('content.hostComponents').filterProperty('staleConfigs', true);
+        hostComponents.forEach(function(item){
+          var componentName = item.get('componentName');
+          var hostName = item.get('host.hostName');
+          App.ajax.send({
+            name: 'config.stale.'+commandName,
+            sender: this,
+            data: {
+              hostName: hostName,
+              componentName: componentName,
+              displayName: App.format.role(componentName)
+            }
+          });
+        })
+        this.hide();
+        App.router.get('backgroundOperationsController').showPopup();
+      },
+      onSecondary: function () {
+        this.hide();
+      }
     });
   },
   /**

+ 42 - 3
ambari-web/app/controllers/main/service/info/configs.js

@@ -1633,11 +1633,50 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
     this.loadStep();
   },
 
-  restartComponents: function() {
-    App.showConfirmationPopup(function() {
-
+  restartComponents: function(e) {
+    var commandName = "stop_component";
+    if(e.context) {
+      if(this.get('content.healthStatus') != 'green'){
+        return;
+      }
+    }else {
+      commandName = "start_component";
+      if(this.get('content.healthStatus') != 'red'){
+        return;
+      }
+    };
+    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 selectedService = this.content.get('content.id');
+        var hostComponents = App.HostComponent.find().filterProperty('service.id', selectedService).filterProperty('staleConfigs', true)
+        hostComponents.forEach(function(item){
+          var componentName = item.get('componentName');
+          var hostName = item.get('host.hostName');
+          App.ajax.send({
+            name: 'config.stale.'+commandName,
+            sender: this,
+            data: {
+              hostName: hostName,
+              componentName: componentName,
+              displayName: App.format.role(componentName)
+            }
+          });
+        })
+        this.hide();
+        App.router.get('backgroundOperationsController').showPopup();
+      },
+      onSecondary: function () {
+        this.hide();
+      }
     });
   },
+
   showHostsShouldBeRestarted: function() {
     var hosts = [];
     for(var hostName in this.get('content.restartRequiredHostsAndComponents')) {

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

@@ -1298,6 +1298,8 @@ Em.I18n.translations = {
   'hosts.host.details.hostActions':'Host Actions...',
   'hosts.host.details.needToRestart':'Host needs {0} components 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.deleteHost':'Delete Host',
   'hosts.host.details.startAllComponents':'Start All Components',
   'hosts.host.details.stopAllComponents':'Stop All Components',

+ 1 - 1
ambari-web/app/styles/application.less

@@ -4770,7 +4770,7 @@ i.icon-asterisks {
   .accordion-heading {
     background-color: #f0f0f0;
     a:hover {
-      text-decoration: none;;
+      text-decoration: none;
     }
   }
   .accordion-body {

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

@@ -30,9 +30,14 @@
           {{#if view.needToRestartComponentsCount}}
               <div class="alert alert-warning clearfix">
                 <i class="icon-refresh"></i> {{view.needToRestartMessage}}
-                <button class="btn btn-warning restart-components pull-right" {{action restartComponents target="controller"}}>
-                  {{t hosts.host.details.needToRestart.button}}
+                <br/>
+                <button {{bindAttr class=":btn :btn-warning :restart-components :pull-left view.stopComponentsIsDisabled:disabled" }} {{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 :btn-warning :restart-components :pull-left view.startComponentsIsDisabled:disabled" }} {{action restartComponents target="controller"}}>
+                  {{t hosts.host.details.needToRestart.startButton}}
+                 </button>
               </div>
           {{/if}}
 

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

@@ -20,14 +20,21 @@
   {{#if dataIsLoaded}}
     {{#if App.supports.hostOverrides}}
       {{#if controller.content.isRestartRequired}}
-        <div>
-          <div class="alert alert-warning clearfix">
-            <i class="icon-refresh"></i> {{{view.needToRestartMessage}}} <a href="#" {{action showComponentsShouldBeRestarted target="controller"}}>{{view.componentsCount}} {{t common.components}}</a> {{t on}} <a href="#" {{action showHostsShouldBeRestarted target="controller"}}>{{view.hostsCount}} {{t dashboard.services.hosts}}</a> {{t services.service.config.restartService.needToRestartEnd}}
-            <button class="btn btn-warning restart-components pull-right" {{action restartComponents target="controller"}}>
-              {{t hosts.host.details.needToRestart.button}}
-            </button>
+        {{#if App.isAdmin}}
+          <div>
+            <div class="alert alert-warning clearfix">
+              <i class="icon-refresh"></i> {{{view.needToRestartMessage}}} <a href="#" {{action showComponentsShouldBeRestarted target="controller"}}>{{view.componentsCount}} {{t common.components}}</a> {{t on}} <a href="#" {{action showHostsShouldBeRestarted target="controller"}}>{{view.hostsCount}} {{t dashboard.services.hosts}}</a> {{t services.service.config.restartService.needToRestartEnd}}
+
+              <button {{bindAttr class=":btn :btn-warning :restart-components :pull-right 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 :btn-warning :restart-components :pull-right view.stopComponentsIsDisabled:disabled" }} {{action restartComponents view.isStopCommand target="controller"}}>
+                {{t hosts.host.details.needToRestart.stopButton}}
+              </button>
+            </div>
           </div>
-        </div>
+        {{/if}}
       {{/if}}
     {{/if}}
     <div class="clearfix"></div>

+ 38 - 0
ambari-web/app/utils/ajax.js

@@ -228,6 +228,44 @@ var urls = {
       };
     }
   },
+  'config.stale.stop_component': {
+    'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
+    'mock': '',
+    'type': 'PUT',
+    'format': function (data) {
+      return {
+        data: JSON.stringify({
+          RequestInfo: {
+            "context": "Stop " + data.displayName
+          },
+          Body: {
+            "HostRoles": {
+              "state": "INSTALLED"
+            }
+          }
+        })
+      }
+    }
+  },
+  'config.stale.start_component': {
+    'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
+    'mock': '',
+    'type': 'PUT',
+    'format': function (data) {
+      return {
+        data: JSON.stringify({
+          RequestInfo: {
+            "context": "Start " + data.displayName
+          },
+          Body: {
+            "HostRoles": {
+              "state": "STARTED"
+            }
+          }
+        })
+      }
+    }
+  },
   'service.metrics.flume.channel_fill_percent': {
     'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/flume/flume/CHANNEL/*/ChannelFillPercentage[{fromSeconds},{toSeconds},{stepSeconds}]',
     'mock': '/data/services/metrics/flume/channelFillPct.json',

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

@@ -22,6 +22,8 @@ var uiEffects = require('utils/ui_effects');
 App.MainHostSummaryView = Em.View.extend({
   templateName: require('templates/main/host/summary'),
 
+  isStopCommand:true,
+
   content: function () {
     return App.router.get('mainHostDetailsController.content');
   }.property('App.router.mainHostDetailsController.content'),
@@ -36,6 +38,24 @@ App.MainHostSummaryView = Em.View.extend({
     return this.get('sortedComponents').filterProperty('staleConfigs', true).length;
   }.property('sortedComponents.@each.staleConfigs'),
 
+  stopComponentsIsDisabled: function () {
+    var staleComponents = this.get('sortedComponents').filterProperty('staleConfigs', true);
+    if(!staleComponents.findProperty('workStatus','INSTALLED')){
+      return true;
+    }else{
+      return false;
+    }
+  }.property('sortedComponents.@each.workStatus'),
+
+  startComponentsIsDisabled:function () {
+    var staleComponents = this.get('sortedComponents').filterProperty('staleConfigs', true);
+    if(!staleComponents.findProperty('workStatus','STARTED')){
+      return true;
+    }else{
+      return false;
+    }
+  }.property('sortedComponents.@each.workStatus'),
+
   needToRestartMessage: function() {
     return Em.I18n.t('hosts.host.details.needToRestart').format(this.get('needToRestartComponentsCount'));
   }.property('needToRestartComponentsCount'),

+ 20 - 0
ambari-web/app/views/main/service/info/configs.js

@@ -27,6 +27,26 @@ App.MainServiceInfoConfigsView = Em.View.extend({
 
   componentsCount: null,
   hostsCount: null,
+  isStopCommand:true,
+
+
+  stopComponentsIsDisabled: function () {
+    var controller = this.get('controller');
+    if(controller.get('content.healthStatus') == 'green'){
+      return false;
+    }else{
+      return true;
+    }
+  }.property('controller.content.healthStatus'),
+
+  startComponentsIsDisabled:function () {
+    var controller = this.get('controller');
+    if(controller.get('content.healthStatus') == 'red'){
+      return false;
+    }else{
+      return true;
+    }
+  }.property('controller.content.healthStatus'),
 
   calculateCounts: function() {
     var hc = this.get('controller.content.restartRequiredHostsAndComponents');