host_component_test.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. it('', function() {
  35. sinon.stub(App.get('components.clients'), 'contains', Em.K);
  36. hc.propertyDidChange('isClient');
  37. hc.get('isClient');
  38. expect(App.get('components.clients').contains.calledWith('COMP1')).to.be.true;
  39. App.get('components.clients').contains.restore();
  40. });
  41. });
  42. describe('#displayName', function() {
  43. it('', function() {
  44. sinon.stub(App.format, 'role', Em.K);
  45. hc.propertyDidChange('displayName');
  46. hc.get('displayName');
  47. expect(App.format.role.calledWith('COMP1')).to.be.true;
  48. App.format.role.restore();
  49. });
  50. });
  51. describe('#isMaster', function() {
  52. it('', function() {
  53. sinon.stub(App.get('components.masters'), 'contains', Em.K);
  54. hc.propertyDidChange('isMaster');
  55. hc.get('isMaster');
  56. expect(App.get('components.masters').contains.calledWith('COMP1')).to.be.true;
  57. App.get('components.masters').contains.restore();
  58. });
  59. });
  60. describe('#isSlave', function() {
  61. it('', function() {
  62. sinon.stub(App.get('components.slaves'), 'contains', Em.K);
  63. hc.propertyDidChange('isSlave');
  64. hc.get('isSlave');
  65. expect(App.get('components.slaves').contains.calledWith('COMP1')).to.be.true;
  66. App.get('components.slaves').contains.restore();
  67. });
  68. });
  69. describe('#isDeletable', function() {
  70. it('', function() {
  71. sinon.stub(App.get('components.deletable'), 'contains', Em.K);
  72. hc.propertyDidChange('isDeletable');
  73. hc.get('isDeletable');
  74. expect(App.get('components.deletable').contains.calledWith('COMP1')).to.be.true;
  75. App.get('components.deletable').contains.restore();
  76. });
  77. });
  78. App.TestAliases.testAsComputedIfThenElse(hc, 'passiveTooltip', 'isActive', '', Em.I18n.t('hosts.component.passive.mode'));
  79. App.TestAliases.testAsComputedExistsIn(hc, 'isRunning', 'workStatus', ['STARTED', 'STARTING']);
  80. describe('#isDecommissioning', function() {
  81. var mock = [];
  82. beforeEach(function () {
  83. sinon.stub(App.HDFSService, 'find', function () {
  84. return mock;
  85. })
  86. });
  87. afterEach(function () {
  88. App.HDFSService.find.restore();
  89. });
  90. it('component name is not DATANODE', function() {
  91. hc.propertyDidChange('isDecommissioning');
  92. expect(hc.get('isDecommissioning')).to.be.false;
  93. });
  94. it('component name is DATANODE but no HDFS service', function() {
  95. hc.set('componentName', 'DATANODE');
  96. hc.propertyDidChange('isDecommissioning');
  97. expect(hc.get('isDecommissioning')).to.be.false;
  98. });
  99. it('HDFS has no decommission DataNodes', function() {
  100. hc.set('componentName', 'DATANODE');
  101. mock.push(Em.Object.create({
  102. decommissionDataNodes: []
  103. }));
  104. hc.propertyDidChange('isDecommissioning');
  105. expect(hc.get('isDecommissioning')).to.be.false;
  106. });
  107. it('HDFS has decommission DataNodes', function() {
  108. hc.set('componentName', 'DATANODE');
  109. hc.set('hostName', 'host1');
  110. mock.clear();
  111. mock.push(Em.Object.create({
  112. decommissionDataNodes: [{hostName: 'host1'}]
  113. }));
  114. hc.propertyDidChange('isDecommissioning');
  115. expect(hc.get('isDecommissioning')).to.be.true;
  116. });
  117. });
  118. App.TestAliases.testAsComputedEqual(hc, 'isActive', 'passiveState', 'OFF');
  119. App.TestAliases.testAsComputedIfThenElse(hc, 'passiveTooltip', 'isActive', '', Em.I18n.t('hosts.component.passive.mode'));
  120. describe('#isActive', function() {
  121. it('passiveState is ON', function() {
  122. hc.set('passiveState', "ON");
  123. hc.propertyDidChange('isActive');
  124. expect(hc.get('isActive')).to.be.false;
  125. });
  126. it('passiveState is OFF', function() {
  127. hc.set('passiveState', "OFF");
  128. hc.propertyDidChange('isActive');
  129. expect(hc.get('isActive')).to.be.true;
  130. });
  131. });
  132. describe('#statusClass', function() {
  133. it('isActive is false', function() {
  134. hc.reopen({
  135. isActive: false
  136. });
  137. hc.propertyDidChange('statusClass');
  138. expect(hc.get('statusClass')).to.equal('icon-medkit');
  139. });
  140. it('isActive is true', function() {
  141. var status = 'INSTALLED';
  142. hc.set('isActive', true);
  143. hc.set('workStatus', status);
  144. hc.propertyDidChange('statusClass');
  145. expect(hc.get('statusClass')).to.equal(status);
  146. });
  147. });
  148. describe('#statusIconClass', function () {
  149. var testCases = [
  150. {
  151. statusClass: 'STARTED',
  152. result: 'icon-ok-sign'
  153. },
  154. {
  155. statusClass: 'STARTING',
  156. result: 'icon-ok-sign'
  157. },
  158. {
  159. statusClass: 'INSTALLED',
  160. result: 'icon-warning-sign'
  161. },
  162. {
  163. statusClass: 'STOPPING',
  164. result: 'icon-warning-sign'
  165. },
  166. {
  167. statusClass: 'UNKNOWN',
  168. result: 'icon-question-sign'
  169. },
  170. {
  171. statusClass: '',
  172. result: ''
  173. }
  174. ];
  175. it('reset statusClass to plain property', function () {
  176. hc.reopen({
  177. statusClass: ''
  178. })
  179. });
  180. testCases.forEach(function (test) {
  181. it('statusClass - ' + test.statusClass, function () {
  182. hc.set('statusClass', test.statusClass);
  183. hc.propertyDidChange('statusIconClass');
  184. expect(hc.get('statusIconClass')).to.equal(test.result);
  185. });
  186. });
  187. });
  188. describe('#componentTextStatus', function () {
  189. before(function () {
  190. sinon.stub(App.HostComponentStatus, 'getTextStatus', Em.K);
  191. });
  192. after(function () {
  193. App.HostComponentStatus.getTextStatus.restore();
  194. });
  195. it('componentTextStatus should be changed', function () {
  196. var status = 'INSTALLED';
  197. hc.set('workStatus', status);
  198. hc.propertyDidChange('componentTextStatus');
  199. hc.get('componentTextStatus');
  200. expect(App.HostComponentStatus.getTextStatus.calledWith(status)).to.be.true;
  201. });
  202. });
  203. describe("#getCount", function () {
  204. var testCases = [
  205. {
  206. t: 'unknown component',
  207. data: {
  208. componentName: 'CC',
  209. type: 'totalCount',
  210. stackComponent: Em.Object.create()
  211. },
  212. result: 0
  213. },
  214. {
  215. t: 'master component',
  216. data: {
  217. componentName: 'C1',
  218. type: 'totalCount',
  219. stackComponent: Em.Object.create({componentCategory: 'MASTER'})
  220. },
  221. result: 3
  222. },
  223. {
  224. t: 'slave component',
  225. data: {
  226. componentName: 'C1',
  227. type: 'installedCount',
  228. stackComponent: Em.Object.create({componentCategory: 'SLAVE'})
  229. },
  230. result: 4
  231. },
  232. {
  233. t: 'client component',
  234. data: {
  235. componentName: 'C1',
  236. type: 'startedCount',
  237. stackComponent: Em.Object.create({componentCategory: 'CLIENT'})
  238. },
  239. result: 5
  240. },
  241. {
  242. t: 'client component, unknown type',
  243. data: {
  244. componentName: 'C1',
  245. type: 'unknownCount',
  246. stackComponent: Em.Object.create({componentCategory: 'CLIENT'})
  247. },
  248. result: 0
  249. }
  250. ];
  251. beforeEach(function () {
  252. this.mock = sinon.stub(App.StackServiceComponent, 'find');
  253. sinon.stub(App.MasterComponent, 'find').returns(Em.Object.create({totalCount: 3}));
  254. sinon.stub(App.SlaveComponent, 'find').returns(Em.Object.create({installedCount: 4}));
  255. sinon.stub(App.ClientComponent, 'find').returns(Em.Object.create({startedCount: 5, unknownCount: null}));
  256. });
  257. afterEach(function () {
  258. this.mock.restore();
  259. App.MasterComponent.find.restore();
  260. App.SlaveComponent.find.restore();
  261. App.ClientComponent.find.restore();
  262. });
  263. testCases.forEach(function (test) {
  264. it(test.t, function () {
  265. this.mock.returns(test.data.stackComponent);
  266. expect(App.HostComponent.getCount(test.data.componentName, test.data.type)).to.equal(test.result);
  267. });
  268. });
  269. });
  270. App.TestAliases.testAsComputedExistsIn(hc, 'isNotInstalled', 'workStatus', ['INIT', 'INSTALL_FAILED']);
  271. });