batch_scheduled_requests_test.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. var testHelpers = require('test/helpers');
  23. describe('batch_scheduled_requests', function() {
  24. beforeEach(function(){
  25. modelSetup.setupStackServiceComponent();
  26. });
  27. afterEach(function(){
  28. modelSetup.cleanStackServiceComponent();
  29. });
  30. describe('#getRollingRestartComponentName', function() {
  31. var tests = [
  32. {serviceName: 'HDFS', componentName: 'DATANODE'},
  33. {serviceName: 'YARN', componentName: 'NODEMANAGER'},
  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. }
  97. return Em.get(App, k);
  98. });
  99. });
  100. afterEach(function() {
  101. batchUtils.showRollingRestartPopup.restore();
  102. batchUtils.showWarningRollingRestartPopup.restore();
  103. App.get.restore();
  104. });
  105. var tests = Em.A([
  106. {componentName: 'DATANODE', e:{showRollingRestartPopup:true, showWarningRollingRestartPopup:false}},
  107. {componentName: 'TASKTRACKER', e:{showRollingRestartPopup:true, showWarningRollingRestartPopup:false}},
  108. {componentName: 'NODEMANAGER', e:{showRollingRestartPopup:true, showWarningRollingRestartPopup:false}},
  109. {componentName: 'HBASE_REGIONSERVER', e:{showRollingRestartPopup:true, showWarningRollingRestartPopup:false}},
  110. {componentName: 'SUPERVISOR', e:{showRollingRestartPopup:true, showWarningRollingRestartPopup:false}},
  111. {componentName: 'SOME_OTHER_COMPONENT', e:{showRollingRestartPopup:false, showWarningRollingRestartPopup:true}}
  112. ]);
  113. tests.forEach(function(test) {
  114. it(test.componentName, function() {
  115. batchUtils.launchHostComponentRollingRestart(test.componentName);
  116. expect(batchUtils.showRollingRestartPopup.calledOnce).to.equal(test.e.showRollingRestartPopup);
  117. expect(batchUtils.showWarningRollingRestartPopup.calledOnce).to.equal(test.e.showWarningRollingRestartPopup);
  118. });
  119. });
  120. });
  121. describe('#restartHostComponents', function () {
  122. beforeEach(function () {
  123. sinon.stub(App.HostComponent, 'find').returns([Em.Object.create({componentName: 'RESOURCEMANAGER', hostName: '1'})]);
  124. });
  125. afterEach(function () {
  126. App.HostComponent.find.restore();
  127. });
  128. it('should make batch request to refresh YARN queues', function () {
  129. batchUtils.restartHostComponents([Em.Object.create({componentName: 'HIVE_SERVER_INTERACTIVE'})]);
  130. expect(testHelpers.findAjaxRequest('name', 'common.batch.request_schedules')).to.exists;
  131. });
  132. it('should make single request without refresh YARN queues', function () {
  133. batchUtils.restartHostComponents([Em.Object.create({componentName: 'NAMENODE'})]);
  134. expect(testHelpers.findAjaxRequest('name', 'restart.hostComponents')).to.exists;
  135. });
  136. });
  137. });