batch_scheduled_requests.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. /**
  18. * Contains helpful utilities for handling batch and scheduled requests.
  19. */
  20. module.exports = {
  21. /**
  22. * Some services have components which have a need for rolling restarts. This
  23. * method returns the name of the host-component which supports rolling
  24. * restarts for a service.
  25. */
  26. getRollingRestartComponentName : function(serviceName) {
  27. var rollingRestartComponent = null;
  28. switch (serviceName) {
  29. case 'HDFS':
  30. rollingRestartComponent = 'DATANODE';
  31. break;
  32. case 'YARN':
  33. rollingRestartComponent = 'NODEMANAGER';
  34. break;
  35. case 'MAPREDUCE':
  36. rollingRestartComponent = 'TASKTRACKER';
  37. break;
  38. case 'HBASE':
  39. rollingRestartComponent = 'HBASE_REGIONSERVER';
  40. break;
  41. case 'STORM':
  42. rollingRestartComponent = 'SUPERVISOR';
  43. break;
  44. default:
  45. break;
  46. }
  47. return rollingRestartComponent;
  48. },
  49. restartAllServiceHostComponents : function(serviceName, staleConfigsOnly) {
  50. var service = App.Service.find(serviceName);
  51. if (service) {
  52. var hostComponents = service.get('hostComponents')
  53. if (staleConfigsOnly) {
  54. hostComponents = hostComponents.filterProperty('staleConfigs', true);
  55. }
  56. this.restartHostComponents(hostComponents);
  57. }
  58. },
  59. restartHostComponents : function(hostComponentsList) {
  60. var componentToHostsMap = {};
  61. var componentToServiceMap = {};
  62. hostComponentsList.forEach(function(hc) {
  63. var componentName = hc.get('componentName');
  64. if (!componentToHostsMap[componentName]) {
  65. componentToHostsMap[componentName] = [];
  66. }
  67. componentToHostsMap[componentName].push(hc.get('host.hostName'));
  68. componentToServiceMap[componentName] = hc.get('service.serviceName');
  69. });
  70. for ( var componentName in componentToHostsMap) {
  71. var hosts = componentToHostsMap[componentName].join(",");
  72. var data = {
  73. serviceName : componentToServiceMap[componentName],
  74. componentName : componentName,
  75. hosts : hosts
  76. }
  77. var sender = {
  78. successFunction : function() {
  79. App.router.get('applicationController').dataLoading().done(function(initValue) {
  80. if (initValue) {
  81. App.router.get('backgroundOperationsController').showPopup();
  82. }
  83. });
  84. },
  85. errorFunction : function(xhr, textStatus, error, opt) {
  86. App.ajax.defaultErrorHandler(xhr, opt.url, 'POST', xhr.status);
  87. }
  88. }
  89. App.ajax.send({
  90. name : 'restart.service.hostComponents',
  91. sender : sender,
  92. data : data,
  93. success : 'successFunction',
  94. error : 'errorFunction'
  95. });
  96. }
  97. },
  98. /**
  99. * Makes a REST call to the server requesting the rolling restart of the
  100. * provided host components.
  101. */
  102. _doPostBatchRollingRestartRequest : function(restartHostComponents, batchSize, intervalTimeSeconds, tolerateSize, successCallback, errorCallback) {
  103. var clusterName = App.get('clusterName');
  104. var data = {
  105. restartHostComponents : restartHostComponents,
  106. batchSize : batchSize,
  107. intervalTimeSeconds : intervalTimeSeconds,
  108. tolerateSize : tolerateSize,
  109. clusterName : clusterName
  110. }
  111. var sender = {
  112. successFunction : function() {
  113. successCallback();
  114. },
  115. errorFunction : function(xhr, textStatus, error, opt) {
  116. errorCallback(xhr, textStatus, error, opt);
  117. }
  118. }
  119. App.ajax.send({
  120. name : 'rolling_restart.post',
  121. sender : sender,
  122. data : data,
  123. success : 'successFunction',
  124. error : 'errorFunction'
  125. });
  126. },
  127. /**
  128. * Launches dialog to handle rolling restarts of host components.
  129. *
  130. * Rolling restart is supported for the following host components only
  131. * <ul>
  132. * <li>Data Nodes (HDFS)
  133. * <li>Task Trackers (MapReduce)
  134. * <li>Node Managers (YARN)
  135. * <li>Region Servers (HBase)
  136. * <li>Supervisors (Storm)
  137. * </ul>
  138. *
  139. * @param {String}
  140. * hostComponentName Type of host-component to restart across cluster
  141. * (ex: DATANODE)
  142. * @param {Boolean}
  143. * staleConfigsOnly Pre-select host-components which have stale
  144. * configurations
  145. */
  146. launchHostComponentRollingRestart : function(hostComponentName, staleConfigsOnly) {
  147. var componentDisplayName = App.format.role(hostComponentName);
  148. if (!componentDisplayName) {
  149. componentDisplayName = hostComponentName;
  150. }
  151. var self = this;
  152. var title = Em.I18n.t('rollingrestart.dialog.title').format(componentDisplayName)
  153. if (hostComponentName == "DATANODE" || hostComponentName == "TASKTRACKER" || hostComponentName == "NODEMANAGER"
  154. || hostComponentName == "HBASE_REGIONSERVER" || hostComponentName == "SUPERVISOR") {
  155. App.ModalPopup.show({
  156. header : title,
  157. hostComponentName : hostComponentName,
  158. staleConfigsOnly : staleConfigsOnly,
  159. innerView : null,
  160. bodyClass : App.RollingRestartView.extend({
  161. hostComponentName : hostComponentName,
  162. staleConfigsOnly : staleConfigsOnly,
  163. didInsertElement : function() {
  164. this.set('parentView.innerView', this);
  165. this.initialize();
  166. }
  167. }),
  168. classNames : [ 'rolling-restart-popup' ],
  169. primary : Em.I18n.t('rollingrestart.dialog.primary'),
  170. secondary : Em.I18n.t('common.cancel'),
  171. onPrimary : function() {
  172. var dialog = this;
  173. if (!dialog.get('enablePrimary')) {
  174. return false;
  175. }
  176. var restartComponents = this.get('innerView.restartHostComponents');
  177. var batchSize = this.get('innerView.batchSize');
  178. var waitTime = this.get('innerView.interBatchWaitTimeSeconds');
  179. var tolerateSize = this.get('innerView.tolerateSize');
  180. self._doPostBatchRollingRestartRequest(restartComponents, batchSize, waitTime, tolerateSize, function() {
  181. dialog.hide();
  182. App.router.get('applicationController').dataLoading().done(function(initValue) {
  183. if (initValue) {
  184. App.router.get('backgroundOperationsController').showPopup();
  185. }
  186. });
  187. }, function(xhr, textStatus, error, opt) {
  188. App.ajax.defaultErrorHandler(xhr, opt.url, 'POST', xhr.status);
  189. });
  190. return;
  191. },
  192. onSecondary : function() {
  193. this.hide();
  194. },
  195. onClose : function() {
  196. this.hide();
  197. },
  198. updateButtons : function() {
  199. var errors = this.get('innerView.errors');
  200. this.set('enablePrimary', !(errors != null && errors.length > 0))
  201. }.observes('innerView.errors'),
  202. });
  203. } else {
  204. var msg = Em.I18n.t('rollingrestart.notsupported.hostComponent').format(componentDisplayName);
  205. console.log(msg);
  206. App.ModalPopup.show({
  207. header : title,
  208. secondary : false,
  209. msg : msg,
  210. bodyClass : Ember.View.extend({
  211. template : Ember.Handlebars.compile('<div class="alert alert-warning">{{msg}}</div>'),
  212. msg : msg
  213. })
  214. });
  215. }
  216. }
  217. }