host_component_test.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('models/host_component');
  20. describe('App.HostComponent', function() {
  21. App.store.load(App.HostComponent, {
  22. id: 'COMP_host',
  23. component_name: 'COMP1'
  24. });
  25. var hc = App.HostComponent.find('COMP_host');
  26. describe('#getStatusesList', function() {
  27. it('allowed statuses', function() {
  28. var statuses = ["STARTED","STARTING","INSTALLED","STOPPING","INSTALL_FAILED","INSTALLING","UPGRADE_FAILED","UNKNOWN","DISABLED","INIT"];
  29. expect(App.HostComponentStatus.getStatusesList()).to.include.members(statuses);
  30. expect(statuses).to.include.members(App.HostComponentStatus.getStatusesList());
  31. });
  32. });
  33. describe('#isClient', function() {
  34. beforeEach(function () {
  35. sinon.stub(App.get('components.clients'), 'contains', Em.K);
  36. hc.propertyDidChange('isClient');
  37. hc.get('isClient');
  38. });
  39. afterEach(function () {
  40. App.get('components.clients').contains.restore();
  41. });
  42. it('components.clients is called with correct data', function() {
  43. expect(App.get('components.clients').contains.calledWith('COMP1')).to.be.true;
  44. });
  45. });
  46. describe('#displayName', function() {
  47. beforeEach(function () {
  48. sinon.stub(App.format, 'role', Em.K);
  49. hc.propertyDidChange('displayName');
  50. hc.get('displayName');
  51. });
  52. afterEach(function () {
  53. App.format.role.restore();
  54. });
  55. it('App.format.role is called with correct data', function() {
  56. expect(App.format.role.calledWith('COMP1')).to.be.true;
  57. });
  58. });
  59. describe('#isMaster', function() {
  60. beforeEach(function () {
  61. sinon.stub(App.get('components.masters'), 'contains', Em.K);
  62. hc.propertyDidChange('isMaster');
  63. hc.get('isMaster');
  64. });
  65. afterEach(function () {
  66. App.get('components.masters').contains.restore();
  67. });
  68. it('components.masters is called with correct data', function() {
  69. expect(App.get('components.masters').contains.calledWith('COMP1')).to.be.true;
  70. });
  71. });
  72. describe('#isSlave', function() {
  73. beforeEach(function () {
  74. sinon.stub(App.get('components.slaves'), 'contains', Em.K);
  75. hc.propertyDidChange('isSlave');
  76. hc.get('isSlave');
  77. });
  78. afterEach(function () {
  79. App.get('components.slaves').contains.restore();
  80. });
  81. it('components.slaves is called with correct data', function() {
  82. expect(App.get('components.slaves').contains.calledWith('COMP1')).to.be.true;
  83. });
  84. });
  85. describe('#isDeletable', function() {
  86. beforeEach(function () {
  87. sinon.stub(App.get('components.deletable'), 'contains', Em.K);
  88. hc.propertyDidChange('isDeletable');
  89. hc.get('isDeletable');
  90. });
  91. afterEach(function () {
  92. App.get('components.deletable').contains.restore();
  93. });
  94. it('components.deletable is called with correct data', function() {
  95. expect(App.get('components.deletable').contains.calledWith('COMP1')).to.be.true;
  96. });
  97. });
  98. App.TestAliases.testAsComputedIfThenElse(hc, 'passiveTooltip', 'isActive', '', Em.I18n.t('hosts.component.passive.mode'));
  99. App.TestAliases.testAsComputedExistsIn(hc, 'isRunning', 'workStatus', ['STARTED', 'STARTING']);
  100. describe('#isDecommissioning', function() {
  101. var mock = [];
  102. beforeEach(function () {
  103. sinon.stub(App.HDFSService, 'find', function () {
  104. return mock;
  105. })
  106. });
  107. afterEach(function () {
  108. App.HDFSService.find.restore();
  109. });
  110. it('component name is not DATANODE', function() {
  111. hc.propertyDidChange('isDecommissioning');
  112. expect(hc.get('isDecommissioning')).to.be.false;
  113. });
  114. it('component name is DATANODE but no HDFS service', function() {
  115. hc.set('componentName', 'DATANODE');
  116. hc.propertyDidChange('isDecommissioning');
  117. expect(hc.get('isDecommissioning')).to.be.false;
  118. });
  119. it('HDFS has no decommission DataNodes', function() {
  120. hc.set('componentName', 'DATANODE');
  121. mock.push(Em.Object.create({
  122. decommissionDataNodes: []
  123. }));
  124. hc.propertyDidChange('isDecommissioning');
  125. expect(hc.get('isDecommissioning')).to.be.false;
  126. });
  127. it('HDFS has decommission DataNodes', function() {
  128. hc.set('componentName', 'DATANODE');
  129. hc.set('hostName', 'host1');
  130. mock.clear();
  131. mock.push(Em.Object.create({
  132. decommissionDataNodes: [{hostName: 'host1'}]
  133. }));
  134. hc.propertyDidChange('isDecommissioning');
  135. expect(hc.get('isDecommissioning')).to.be.true;
  136. });
  137. });
  138. App.TestAliases.testAsComputedEqual(hc, 'isActive', 'passiveState', 'OFF');
  139. App.TestAliases.testAsComputedIfThenElse(hc, 'passiveTooltip', 'isActive', '', Em.I18n.t('hosts.component.passive.mode'));
  140. describe('#isActive', function() {
  141. it('passiveState is ON', function() {
  142. hc.set('passiveState', "ON");
  143. hc.propertyDidChange('isActive');
  144. expect(hc.get('isActive')).to.be.false;
  145. });
  146. it('passiveState is OFF', function() {
  147. hc.set('passiveState', "OFF");
  148. hc.propertyDidChange('isActive');
  149. expect(hc.get('isActive')).to.be.true;
  150. });
  151. });
  152. describe('#statusClass', function() {
  153. it('isActive is false', function() {
  154. hc.reopen({
  155. isActive: false
  156. });
  157. hc.propertyDidChange('statusClass');
  158. expect(hc.get('statusClass')).to.equal('icon-medkit');
  159. });
  160. it('isActive is true', function() {
  161. var status = 'INSTALLED';
  162. hc.set('isActive', true);
  163. hc.set('workStatus', status);
  164. hc.propertyDidChange('statusClass');
  165. expect(hc.get('statusClass')).to.equal(status);
  166. });
  167. });
  168. describe('#statusIconClass', function () {
  169. var testCases = [
  170. {
  171. statusClass: 'STARTED',
  172. result: 'icon-ok-sign'
  173. },
  174. {
  175. statusClass: 'STARTING',
  176. result: 'icon-ok-sign'
  177. },
  178. {
  179. statusClass: 'INSTALLED',
  180. result: 'icon-warning-sign'
  181. },
  182. {
  183. statusClass: 'STOPPING',
  184. result: 'icon-warning-sign'
  185. },
  186. {
  187. statusClass: 'UNKNOWN',
  188. result: 'icon-question-sign'
  189. },
  190. {
  191. statusClass: '',
  192. result: ''
  193. }
  194. ];
  195. beforeEach(function () {
  196. hc.reopen({
  197. statusClass: ''
  198. });
  199. });
  200. testCases.forEach(function (test) {
  201. it('statusClass - ' + test.statusClass, function () {
  202. hc.set('statusClass', test.statusClass);
  203. hc.propertyDidChange('statusIconClass');
  204. expect(hc.get('statusIconClass')).to.equal(test.result);
  205. });
  206. });
  207. });
  208. describe('#componentTextStatus', function () {
  209. before(function () {
  210. sinon.stub(App.HostComponentStatus, 'getTextStatus', Em.K);
  211. });
  212. after(function () {
  213. App.HostComponentStatus.getTextStatus.restore();
  214. });
  215. it('componentTextStatus should be changed', function () {
  216. var status = 'INSTALLED';
  217. hc.set('workStatus', status);
  218. hc.propertyDidChange('componentTextStatus');
  219. hc.get('componentTextStatus');
  220. expect(App.HostComponentStatus.getTextStatus.calledWith(status)).to.be.true;
  221. });
  222. });
  223. describe("#getCount", function () {
  224. var testCases = [
  225. {
  226. t: 'unknown component',
  227. data: {
  228. componentName: 'CC',
  229. type: 'totalCount',
  230. stackComponent: Em.Object.create()
  231. },
  232. result: 0
  233. },
  234. {
  235. t: 'master component',
  236. data: {
  237. componentName: 'C1',
  238. type: 'totalCount',
  239. stackComponent: Em.Object.create({componentCategory: 'MASTER'})
  240. },
  241. result: 3
  242. },
  243. {
  244. t: 'slave component',
  245. data: {
  246. componentName: 'C1',
  247. type: 'installedCount',
  248. stackComponent: Em.Object.create({componentCategory: 'SLAVE'})
  249. },
  250. result: 4
  251. },
  252. {
  253. t: 'client component',
  254. data: {
  255. componentName: 'C1',
  256. type: 'startedCount',
  257. stackComponent: Em.Object.create({componentCategory: 'CLIENT'})
  258. },
  259. result: 5
  260. },
  261. {
  262. t: 'client component, unknown type',
  263. data: {
  264. componentName: 'C1',
  265. type: 'unknownCount',
  266. stackComponent: Em.Object.create({componentCategory: 'CLIENT'})
  267. },
  268. result: 0
  269. }
  270. ];
  271. beforeEach(function () {
  272. this.mock = sinon.stub(App.StackServiceComponent, 'find');
  273. sinon.stub(App.MasterComponent, 'find').returns(Em.Object.create({totalCount: 3}));
  274. sinon.stub(App.SlaveComponent, 'find').returns(Em.Object.create({installedCount: 4}));
  275. sinon.stub(App.ClientComponent, 'find').returns(Em.Object.create({startedCount: 5, unknownCount: null}));
  276. });
  277. afterEach(function () {
  278. this.mock.restore();
  279. App.MasterComponent.find.restore();
  280. App.SlaveComponent.find.restore();
  281. App.ClientComponent.find.restore();
  282. });
  283. testCases.forEach(function (test) {
  284. it(test.t, function () {
  285. this.mock.returns(test.data.stackComponent);
  286. expect(App.HostComponent.getCount(test.data.componentName, test.data.type)).to.equal(test.result);
  287. });
  288. });
  289. });
  290. App.TestAliases.testAsComputedExistsIn(hc, 'isNotInstalled', 'workStatus', ['INIT', 'INSTALL_FAILED']);
  291. });