batch_scheduled_requests.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. doPostRestartAllServiceComponents : function(serviceName) {
  50. var allHostComponents = App.HostComponent.find();
  51. var componentToHostsMap = {};
  52. var componentCount = 0;
  53. allHostComponents.forEach(function(hc) {
  54. if (serviceName == hc.get('service.serviceName')) {
  55. var componentName = hc.get('componentName');
  56. if (!componentToHostsMap[componentName]) {
  57. componentToHostsMap[componentName] = [];
  58. componentCount++;
  59. }
  60. componentToHostsMap[componentName].push(hc.get('host.hostName'));
  61. }
  62. });
  63. for ( var componentName in componentToHostsMap) {
  64. var hosts = componentToHostsMap[componentName].join(",");
  65. var data = {
  66. serviceName : serviceName,
  67. componentName : componentName,
  68. hosts : hosts
  69. }
  70. var sender = {
  71. successFunction : function() {
  72. App.router.get('applicationController').dataLoading().done(function (initValue) {
  73. if (initValue) {
  74. App.router.get('backgroundOperationsController').showPopup();
  75. }
  76. });
  77. },
  78. errorFunction : function(xhr, textStatus, error, opt) {
  79. App.ajax.defaultErrorHandler(xhr, opt.url, 'POST', xhr.status);
  80. }
  81. }
  82. App.ajax.send({
  83. name : 'restart.service.hostComponents',
  84. sender : sender,
  85. data : data,
  86. success : 'successFunction',
  87. error : 'errorFunction'
  88. });
  89. }
  90. },
  91. /**
  92. * Makes a REST call to the server requesting the rolling restart of the
  93. * provided host components.
  94. */
  95. doPostBatchRollingRestartRequest : function(restartHostComponents, batchSize, intervalTimeSeconds, tolerateSize, successCallback, errorCallback) {
  96. var clusterName = App.get('clusterName');
  97. var data = {
  98. restartHostComponents : restartHostComponents,
  99. batchSize : batchSize,
  100. intervalTimeSeconds : intervalTimeSeconds,
  101. tolerateSize : tolerateSize,
  102. clusterName : clusterName
  103. }
  104. var sender = {
  105. successFunction : function() {
  106. successCallback();
  107. },
  108. errorFunction : function(xhr, textStatus, error, opt) {
  109. errorCallback(xhr, textStatus, error, opt);
  110. }
  111. }
  112. App.ajax.send({
  113. name : 'rolling_restart.post',
  114. sender : sender,
  115. data : data,
  116. success : 'successFunction',
  117. error : 'errorFunction'
  118. });
  119. },
  120. /**
  121. * Launches dialog to handle rolling restarts of host components.
  122. *
  123. * Rolling restart is supported for the following host components only
  124. * <ul>
  125. * <li>Data Nodes (HDFS)
  126. * <li>Task Trackers (MapReduce)
  127. * <li>Node Managers (YARN)
  128. * <li>Region Servers (HBase)
  129. * <li>Supervisors (Storm)
  130. * </ul>
  131. *
  132. * @param {String}
  133. * hostComponentName Type of host-component to restart across cluster
  134. * (ex: DATANODE)
  135. * @param {Boolean}
  136. * staleConfigsOnly Pre-select host-components which have stale
  137. * configurations
  138. */
  139. launchHostComponentRollingRestart : function(hostComponentName, staleConfigsOnly) {
  140. var componentDisplayName = App.format.role(hostComponentName);
  141. if (!componentDisplayName) {
  142. componentDisplayName = hostComponentName;
  143. }
  144. var self = this;
  145. var title = Em.I18n.t('rollingrestart.dialog.title').format(componentDisplayName)
  146. if (hostComponentName == "DATANODE" || hostComponentName == "TASKTRACKER" || hostComponentName == "NODEMANAGER"
  147. || hostComponentName == "HBASE_REGIONSERVER" || hostComponentName == "SUPERVISOR") {
  148. App.ModalPopup.show({
  149. header : title,
  150. hostComponentName : hostComponentName,
  151. staleConfigsOnly : staleConfigsOnly,
  152. innerView : null,
  153. bodyClass : App.RollingRestartView.extend({
  154. hostComponentName : hostComponentName,
  155. staleConfigsOnly : staleConfigsOnly,
  156. didInsertElement : function() {
  157. this.set('parentView.innerView', this);
  158. this.initialize();
  159. }
  160. }),
  161. classNames : [ 'rolling-restart-popup' ],
  162. primary : Em.I18n.t('rollingrestart.dialog.primary'),
  163. secondary : Em.I18n.t('common.cancel'),
  164. onPrimary : function() {
  165. var dialog = this;
  166. if (!dialog.get('enablePrimary')) {
  167. return false;
  168. }
  169. var restartComponents = this.get('innerView.restartHostComponents');
  170. var batchSize = this.get('innerView.batchSize');
  171. var waitTime = this.get('innerView.interBatchWaitTimeSeconds');
  172. var tolerateSize = this.get('innerView.tolerateSize');
  173. self.doPostBatchRollingRestartRequest(restartComponents, batchSize, waitTime, tolerateSize, function() {
  174. dialog.hide();
  175. App.router.get('applicationController').dataLoading().done(function (initValue) {
  176. if (initValue) {
  177. App.router.get('backgroundOperationsController').showPopup();
  178. }
  179. });
  180. }, function(xhr, textStatus, error, opt) {
  181. App.ajax.defaultErrorHandler(xhr, opt.url, 'POST', xhr.status);
  182. });
  183. return;
  184. },
  185. onSecondary : function() {
  186. this.hide();
  187. },
  188. onClose : function() {
  189. this.hide();
  190. },
  191. updateButtons : function() {
  192. var errors = this.get('innerView.errors');
  193. this.set('enablePrimary', !(errors != null && errors.length > 0))
  194. }.observes('innerView.errors'),
  195. });
  196. } else {
  197. var msg = Em.I18n.t('rollingrestart.notsupported.hostComponent').format(componentDisplayName);
  198. console.log(msg);
  199. App.ModalPopup.show({
  200. header : title,
  201. secondary : false,
  202. msg : msg,
  203. bodyClass : Ember.View.extend({
  204. template : Ember.Handlebars.compile('<div class="alert alert-warning">{{msg}}</div>'),
  205. msg : msg
  206. })
  207. });
  208. }
  209. }
  210. }