batch_scheduled_requests_test.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. var App = require('app');
  18. require('utils/helper');
  19. require('views/common/rolling_restart_view');
  20. var batchUtils = require('utils/batch_scheduled_requests');
  21. var modelSetup = require('test/init_model_test');
  22. describe('batch_scheduled_requests', function() {
  23. beforeEach(function(){
  24. modelSetup.setupStackServiceComponent();
  25. });
  26. afterEach(function(){
  27. modelSetup.cleanStackServiceComponent();
  28. });
  29. describe('#getRollingRestartComponentName', function() {
  30. var tests = [
  31. {serviceName: 'HDFS', componentName: 'DATANODE'},
  32. {serviceName: 'YARN', componentName: 'NODEMANAGER'},
  33. {serviceName: 'MAPREDUCE', componentName: 'TASKTRACKER'},
  34. {serviceName: 'HBASE', componentName: 'HBASE_REGIONSERVER'},
  35. {serviceName: 'STORM', componentName: 'SUPERVISOR'},
  36. {serviceName: 'SOME_INVALID_SERVICE', componentName: null}
  37. ];
  38. tests.forEach(function(test) {
  39. it(test.serviceName + ' - ' + test.componentName, function() {
  40. expect(batchUtils.getRollingRestartComponentName(test.serviceName)).to.equal(test.componentName);
  41. });
  42. });
  43. });
  44. describe('#getBatchesForRollingRestartRequest', function() {
  45. var tests = [
  46. {
  47. hostComponents: Em.A([
  48. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host1'}}),
  49. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host2'}}),
  50. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host3'}})
  51. ]),
  52. batchSize: 2,
  53. m: 'DATANODES on three hosts, batchSize = 2',
  54. e: {
  55. batchCount: 2
  56. }
  57. },
  58. {
  59. hostComponents: Em.A([
  60. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host1'}}),
  61. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host2'}}),
  62. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host3'}})
  63. ]),
  64. batchSize: 3,
  65. m: 'DATANODES on 3 hosts, batchSize = 3',
  66. e: {
  67. batchCount: 1
  68. }
  69. },
  70. {
  71. hostComponents: Em.A([
  72. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host1'}}),
  73. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host2'}}),
  74. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host3'}})
  75. ]),
  76. batchSize: 1,
  77. m: 'DATANODES on 3 hosts, batchSize = 1',
  78. e: {
  79. batchCount: 3
  80. }
  81. }
  82. ];
  83. tests.forEach(function(test) {
  84. it(test.m, function() {
  85. expect(batchUtils.getBatchesForRollingRestartRequest(test.hostComponents, test.batchSize).length).to.equal(test.e.batchCount);
  86. });
  87. });
  88. });
  89. describe('#launchHostComponentRollingRestart', function() {
  90. beforeEach(function() {
  91. sinon.spy(batchUtils, 'showRollingRestartPopup');
  92. sinon.spy(batchUtils, 'showWarningRollingRestartPopup');
  93. sinon.stub(App, 'get', function(k) {
  94. if ('components.rollinRestartAllowed' === k)
  95. return ['DATANODE', 'TASKTRACKER', 'NODEMANAGER', 'HBASE_REGIONSERVER', 'SUPERVISOR'];
  96. return Em.get(App, k);
  97. });
  98. });
  99. afterEach(function() {
  100. batchUtils.showRollingRestartPopup.restore();
  101. batchUtils.showWarningRollingRestartPopup.restore();
  102. App.get.restore();
  103. });
  104. var tests = Em.A([
  105. {componentName: 'DATANODE', e:{showRollingRestartPopup:true, showWarningRollingRestartPopup:false}},
  106. {componentName: 'TASKTRACKER', e:{showRollingRestartPopup:true, showWarningRollingRestartPopup:false}},
  107. {componentName: 'NODEMANAGER', e:{showRollingRestartPopup:true, showWarningRollingRestartPopup:false}},
  108. {componentName: 'HBASE_REGIONSERVER', e:{showRollingRestartPopup:true, showWarningRollingRestartPopup:false}},
  109. {componentName: 'SUPERVISOR', e:{showRollingRestartPopup:true, showWarningRollingRestartPopup:false}},
  110. {componentName: 'SOME_OTHER_COMPONENT', e:{showRollingRestartPopup:false, showWarningRollingRestartPopup:true}}
  111. ]);
  112. tests.forEach(function(test) {
  113. it(test.componentName, function() {
  114. batchUtils.launchHostComponentRollingRestart(test.componentName);
  115. expect(batchUtils.showRollingRestartPopup.calledOnce).to.equal(test.e.showRollingRestartPopup);
  116. expect(batchUtils.showWarningRollingRestartPopup.calledOnce).to.equal(test.e.showWarningRollingRestartPopup);
  117. });
  118. });
  119. });
  120. describe('#restartHostComponents', function() {
  121. beforeEach(function() {
  122. sinon.spy($, 'ajax');
  123. sinon.stub(App, 'get', function(k) {
  124. if ('testMode' === k) return true;
  125. return Em.get(App, k);
  126. });
  127. });
  128. afterEach(function() {
  129. $.ajax.restore();
  130. App.get.restore();
  131. });
  132. var tests = Em.A([
  133. {
  134. hostComponentList: Em.A([
  135. Em.Object.create({
  136. componentName: 'NAMENODE',
  137. hostName: 'h1'
  138. }),
  139. Em.Object.create({
  140. componentName: 'NAMENODE',
  141. hostName: 'h2'
  142. })
  143. ]),
  144. e: {
  145. ajaxCalledOnce: true,
  146. resource_filters: [{"service_name": "HDFS", "component_name":"NAMENODE","hosts":"h1,h2"}]
  147. },
  148. m: '1 component on 2 hosts'
  149. },
  150. {
  151. hostComponentList: Em.A([
  152. Em.Object.create({
  153. componentName: 'NAMENODE',
  154. hostName: 'h1'
  155. }),
  156. Em.Object.create({
  157. componentName: 'NAMENODE',
  158. hostName: 'h2'
  159. }),
  160. Em.Object.create({
  161. componentName: 'HBASE_MASTER',
  162. hostName: 'h2'
  163. })
  164. ]),
  165. e: {
  166. ajaxCalledOnce: true,
  167. resource_filters: [{"service_name": "HDFS", "component_name":"NAMENODE","hosts":"h1,h2"},{"service_name": "HBASE", "component_name":"HBASE_MASTER","hosts":"h2"}]
  168. },
  169. m: '1 component on 2 hosts, 1 on 1 host'
  170. }
  171. ]);
  172. tests.forEach(function(test) {
  173. it(test.m, function() {
  174. batchUtils.restartHostComponents(test.hostComponentList);
  175. expect($.ajax.calledOnce).to.equal(test.e.ajaxCalledOnce);
  176. expect( JSON.parse($.ajax.args[0][0].data)['Requests/resource_filters']).to.eql(test.e.resource_filters);
  177. });
  178. });
  179. it('Empty data', function() {
  180. batchUtils.restartHostComponents([]);
  181. expect($.ajax.called).to.equal(false);
  182. });
  183. });
  184. });