step6_test.js 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902
  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. var validationUtils = require('utils/validator');
  20. require('utils/helper');
  21. require('controllers/wizard/step6_controller');
  22. var controller,
  23. services = [
  24. Em.Object.create({
  25. serviceName: 'YARN',
  26. isSelected: true
  27. }),
  28. Em.Object.create({
  29. serviceName: 'HBASE',
  30. isSelected: true
  31. }),
  32. Em.Object.create({
  33. serviceName: 'HDFS',
  34. isSelected: true
  35. }),
  36. Em.Object.create({
  37. serviceName: 'STORM',
  38. isSelected: true
  39. }),
  40. Em.Object.create({
  41. serviceName: 'FLUME',
  42. isSelected: true
  43. })
  44. ];
  45. function getController() {
  46. var c = App.WizardStep6Controller.create({
  47. content: Em.Object.create({
  48. hosts: {},
  49. masterComponentHosts: {},
  50. services: services,
  51. controllerName: ''
  52. })
  53. });
  54. var h = {}, m = [];
  55. Em.A(['host0', 'host1', 'host2', 'host3']).forEach(function (hostName) {
  56. var obj = Em.Object.create({
  57. name: hostName,
  58. hostName: hostName,
  59. bootStatus: 'REGISTERED'
  60. });
  61. h[hostName] = obj;
  62. m.push(obj);
  63. });
  64. c.set('content.hosts', h);
  65. c.set('content.masterComponentHosts', m);
  66. c.set('isMasters', false);
  67. return c;
  68. }
  69. describe('App.WizardStep6Controller', function () {
  70. beforeEach(function () {
  71. controller = getController();
  72. });
  73. App.TestAliases.testAsComputedEqual(getController(), 'isAddHostWizard', 'content.controllerName', 'addHostController');
  74. describe('#installedServiceNames', function () {
  75. it(' should filter content.services by isInstalled property', function () {
  76. var _services = Em.A([]);
  77. _services.pushObjects(Em.A([{isInstalled: true, serviceName: "service1"},
  78. {isInstalled: false, serviceName: "service2"},
  79. {isInstalled: true, serviceName: "service3"},
  80. {isInstalled: false, serviceName: "service4"},
  81. {isInstalled: true, serviceName: "service5"}]));
  82. controller.set('content.services', _services);
  83. expect(controller.get('installedServiceNames')).to.eql(["service1", "service3", "service5"]);
  84. });
  85. });
  86. describe('#showValidationIssuesAcceptBox', function () {
  87. it('should return true if success callback', function () {
  88. var deffer = jQuery.Deferred();
  89. function callback() {
  90. deffer.resolve(true);
  91. }
  92. controller.showValidationIssuesAcceptBox(callback);
  93. jQuery.when(deffer.promise()).then(function(data) {
  94. expect(data).to.equal(true);
  95. });
  96. });
  97. });
  98. describe('#selectAllNodes', function () {
  99. var hostsObj = Em.A([Em.Object.create({
  100. hasMaster: false,
  101. isInstalled: false,
  102. checkboxes: Em.A([
  103. Em.Object.create({
  104. title: 'l1',
  105. component: 'name',
  106. isInstalled: false,
  107. checked: false
  108. })
  109. ])
  110. })]);
  111. var obj = Em.Object.create({
  112. context: {
  113. name: "name"
  114. }
  115. });
  116. var clientComponents = Em.A([{component_name: "name1"}]);
  117. it('should make checkbox checked', function () {
  118. controller.set('hosts', hostsObj);
  119. controller.set('content.clients', clientComponents);
  120. controller.selectAllNodes(obj);
  121. expect(controller.get('hosts')).to.eql(Em.A([Em.Object.create({
  122. hasMaster: false,
  123. isInstalled: false,
  124. checkboxes: Em.A([
  125. Em.Object.create({
  126. title: 'l1',
  127. component: 'name',
  128. isInstalled: false,
  129. checked: true
  130. })
  131. ])
  132. })]));
  133. });
  134. });
  135. describe('#deselectAllNodes', function () {
  136. var hostsObj = Em.A([Em.Object.create({
  137. hasMaster: false,
  138. isInstalled: false,
  139. checkboxes: Em.A([
  140. Em.Object.create({
  141. title: 'l1',
  142. component: 'name',
  143. isInstalled: false,
  144. checked: true
  145. })
  146. ])
  147. })]);
  148. var obj = Em.Object.create({
  149. context: {
  150. name: "name"
  151. }
  152. });
  153. var clientComponents = Em.A([{component_name: "name1"}]);
  154. it('should uncheck checkbox', function () {
  155. controller.set('hosts', hostsObj);
  156. controller.set('content.clients', clientComponents);
  157. controller.deselectAllNodes(obj);
  158. expect(controller.get('hosts')).to.eql(Em.A([Em.Object.create({
  159. hasMaster: false,
  160. isInstalled: false,
  161. checkboxes: Em.A([
  162. Em.Object.create({
  163. title: 'l1',
  164. component: 'name',
  165. isInstalled: false,
  166. checked: false
  167. })
  168. ])
  169. })]));
  170. });
  171. });
  172. describe('#renderSlaves()', function () {
  173. var hostsObj = [{}];
  174. beforeEach(function() {
  175. sinon.stub(controller, 'selectRecommendedComponents');
  176. sinon.stub(controller, 'setInstalledComponents');
  177. sinon.stub(controller, 'restoreComponentsSelection');
  178. sinon.stub(controller, 'selectClientHost');
  179. });
  180. afterEach(function() {
  181. controller.selectRecommendedComponents.restore();
  182. controller.setInstalledComponents.restore();
  183. controller.restoreComponentsSelection.restore();
  184. controller.selectClientHost.restore();
  185. });
  186. describe("slaveComponents is null", function() {
  187. beforeEach(function() {
  188. controller.set('content.slaveComponentHosts', null);
  189. });
  190. it("selectRecommendedComponents should be called", function() {
  191. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  192. expect(controller.selectRecommendedComponents.calledWith(hostsObj)).to.be.true;
  193. });
  194. it("setInstalledComponents should be called", function() {
  195. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  196. expect(controller.setInstalledComponents.calledWith(hostsObj)).to.be.true;
  197. });
  198. it("restoreComponentsSelection should not be called", function() {
  199. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  200. expect(controller.restoreComponentsSelection.called).to.be.false;
  201. });
  202. it("selectClientHost should be called", function() {
  203. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  204. expect(controller.selectClientHost.calledWith(hostsObj)).to.be.true;
  205. });
  206. });
  207. describe("slaveComponents is defined", function() {
  208. var slaveComponentHosts = [{}];
  209. beforeEach(function() {
  210. controller.set('content.slaveComponentHosts', slaveComponentHosts);
  211. });
  212. it("selectRecommendedComponents should not be called", function() {
  213. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  214. expect(controller.selectRecommendedComponents.called).to.be.false;
  215. });
  216. it("setInstalledComponents should not be called", function() {
  217. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  218. expect(controller.setInstalledComponents.called).to.be.false;
  219. });
  220. it("restoreComponentsSelection should be called", function() {
  221. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  222. expect(controller.restoreComponentsSelection.calledWith(hostsObj, slaveComponentHosts)).to.be.true;
  223. });
  224. it("selectClientHost should be called", function() {
  225. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  226. expect(controller.selectClientHost.calledWith(hostsObj)).to.be.true;
  227. });
  228. });
  229. });
  230. describe("#setInstalledComponents()", function() {
  231. var hostsObj = [{
  232. hostName: 'host1',
  233. checkboxes: [
  234. {
  235. component: 'C1',
  236. isInstalled: false,
  237. checked: false
  238. },
  239. {
  240. component: 'C2',
  241. isInstalled: false,
  242. checked: false
  243. }
  244. ]
  245. }];
  246. it("installedHosts is null", function() {
  247. controller.set('content.installedHosts', null);
  248. expect(controller.setInstalledComponents(hostsObj)).to.be.false;
  249. });
  250. it("installedHosts is defined", function() {
  251. controller.set('content.installedHosts', {
  252. 'host1': {
  253. hostComponents: [
  254. {
  255. HostRoles: {
  256. component_name: 'C1'
  257. }
  258. }
  259. ]
  260. }
  261. });
  262. controller.setInstalledComponents(hostsObj);
  263. expect(hostsObj[0].checkboxes[0].isInstalled).to.be.true;
  264. expect(hostsObj[0].checkboxes[1].isInstalled).to.be.false;
  265. expect(hostsObj[0].checkboxes[0].checked).to.be.true;
  266. expect(hostsObj[0].checkboxes[1].checked).to.be.false;
  267. });
  268. });
  269. describe("#restoreComponentsSelection()", function() {
  270. var getHostsObj = function() {
  271. return [{
  272. hostName: 'host1',
  273. checkboxes: [
  274. {
  275. component: 'C1',
  276. title: 'c1',
  277. isInstalled: false,
  278. checked: false
  279. },
  280. {
  281. component: 'C2',
  282. title: 'c1',
  283. isInstalled: true,
  284. checked: false
  285. },
  286. {
  287. component: 'C3',
  288. title: 'c3',
  289. isInstalled: false,
  290. checked: false
  291. }
  292. ]
  293. }];
  294. };
  295. var slaveComponents = [
  296. {
  297. componentName: 'C1',
  298. hosts: [{hostName: 'host1', isInstalled: true}]
  299. }
  300. ];
  301. beforeEach(function() {
  302. controller.set('headers', [
  303. Em.Object.create({
  304. name: 'C1',
  305. label: 'c1'
  306. }),
  307. Em.Object.create({
  308. name: 'C2',
  309. label: 'c2'
  310. }),
  311. Em.Object.create({
  312. name: 'C3',
  313. label: 'c3'
  314. })
  315. ]);
  316. });
  317. it("C1 components should be checked and installed", function() {
  318. var hostsObj = getHostsObj();
  319. controller.restoreComponentsSelection(hostsObj, slaveComponents);
  320. expect(hostsObj[0].checkboxes[0].isInstalled).to.be.true;
  321. expect(hostsObj[0].checkboxes[0].checked).to.be.true;
  322. });
  323. it("C2 components should not be checked and should be installed", function() {
  324. var hostsObj = getHostsObj();
  325. controller.restoreComponentsSelection(hostsObj, slaveComponents);
  326. expect(hostsObj[0].checkboxes[1].isInstalled).to.be.true;
  327. expect(hostsObj[0].checkboxes[1].checked).to.be.false;
  328. });
  329. it("C3 components should not be checked and should not be installed", function() {
  330. var hostsObj = getHostsObj();
  331. controller.restoreComponentsSelection(hostsObj, slaveComponents);
  332. expect(hostsObj[0].checkboxes[2].isInstalled).to.be.false;
  333. expect(hostsObj[0].checkboxes[2].checked).to.be.false;
  334. });
  335. });
  336. describe("#selectRecommendedComponents()", function() {
  337. var hostsObj = [{
  338. hostName: 'host1',
  339. checkboxes: [
  340. {
  341. component: 'C1',
  342. checked: false,
  343. isDisabled: false
  344. },
  345. {
  346. component: 'C2',
  347. checked: false,
  348. isDisabled: true
  349. },
  350. {
  351. component: 'C3',
  352. checked: false,
  353. isDisabled: false
  354. },
  355. {
  356. component: 'CLIENT',
  357. checked: false,
  358. isDisabled: false
  359. }
  360. ]
  361. }];
  362. var recommendations = {
  363. blueprint: {
  364. host_groups: [
  365. {
  366. name: 'g1',
  367. components: [
  368. {name: 'C1'},
  369. {name: 'C2'},
  370. {name: 'C_CLIENT'}
  371. ]
  372. }
  373. ]
  374. },
  375. blueprint_cluster_binding: {
  376. host_groups: [
  377. {
  378. name: 'g1',
  379. hosts: [{fqdn: 'host1'}]
  380. }
  381. ]
  382. }
  383. };
  384. beforeEach(function() {
  385. sinon.stub(App, 'get').returns(['C_CLIENT']);
  386. });
  387. afterEach(function() {
  388. App.get.restore();
  389. });
  390. it("C1 should be checked", function() {
  391. controller.set('content.recommendations', recommendations);
  392. controller.selectRecommendedComponents(hostsObj);
  393. expect(hostsObj[0].checkboxes[0].checked).to.be.true;
  394. });
  395. it("C2 should not be checked, as it is disabled", function() {
  396. controller.set('content.recommendations', recommendations);
  397. controller.selectRecommendedComponents(hostsObj);
  398. expect(hostsObj[0].checkboxes[1].checked).to.be.false;
  399. });
  400. it("C3 should not be checked", function() {
  401. controller.set('content.recommendations', recommendations);
  402. controller.selectRecommendedComponents(hostsObj);
  403. expect(hostsObj[0].checkboxes[2].checked).to.be.false;
  404. });
  405. it("CLIENT should be checked", function() {
  406. controller.set('content.recommendations', recommendations);
  407. controller.selectRecommendedComponents(hostsObj);
  408. expect(hostsObj[0].checkboxes[3].checked).to.be.true;
  409. });
  410. });
  411. App.TestAliases.testAsComputedOr(getController(), 'anyGeneralErrors', ['errorMessage', 'generalErrorMessages.length']);
  412. describe('#render', function () {
  413. it('true if loaded', function () {
  414. var hosts = {
  415. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  416. h2: {bootStatus: 'REGISTERED', name: 'h2'},
  417. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  418. };
  419. var headers = Em.A([
  420. Em.Object.create({name: "c1", label: 'l1', isDisabled: true}),
  421. Em.Object.create({name: "c2", label: 'l2', isDisabled: false})
  422. ]);
  423. var masterComponentHosts = Em.A([
  424. {hostName: 'h1', component: 'c1'}
  425. ]);
  426. var recommendations = {
  427. blueprint: {
  428. host_groups: [
  429. {
  430. components: [
  431. {
  432. name: 'c6'
  433. }
  434. ],
  435. name: 'host-group-1'
  436. },
  437. {
  438. components: [
  439. {
  440. name: 'c8'
  441. }
  442. ],
  443. name: 'host-group-2'
  444. }
  445. ]
  446. },
  447. blueprint_cluster_binding: {
  448. host_groups: [
  449. {
  450. hosts: [
  451. {
  452. fqdn: 'h0'
  453. }
  454. ],
  455. name: 'host-group-1'
  456. },
  457. {
  458. hosts: [
  459. {
  460. fqdn: 'h1'
  461. }
  462. ],
  463. name: 'host-group-2'
  464. }]
  465. }
  466. };
  467. controller.set('content.hosts', hosts);
  468. controller.set('content.masterComponentHosts', masterComponentHosts);
  469. controller.set('content.recommendations', recommendations);
  470. controller.set('headers', headers);
  471. controller.render();
  472. expect(controller.get('isLoaded')).to.equal(true);
  473. });
  474. });
  475. describe('#anyGeneralWarnings', function () {
  476. it('true if generalWarningMessages is non empty array and warningMessage is undefined', function () {
  477. controller.set('generalWarningMessages', ["warning1", "warning2"]);
  478. expect(controller.get('anyGeneralWarnings')).to.equal(true);
  479. });
  480. it('false if generalWarningMessages is empty array', function () {
  481. controller.set('generalWarningMessages', []);
  482. expect(controller.get('anyGeneralWarnings')).to.equal(false);
  483. });
  484. it('undefined if generalWarningMessages is undefined', function () {
  485. controller.set('generalWarningMessages', false);
  486. expect(controller.get('anyGeneralWarnings')).to.equal(false);
  487. });
  488. });
  489. App.TestAliases.testAsComputedOr(getController(), 'anyGeneralIssues', ['anyGeneralErrors', 'anyGeneralWarnings']);
  490. App.TestAliases.testAsComputedOr(getController(), 'anyErrors', ['anyGeneralErrors', 'anyHostErrors']);
  491. App.TestAliases.testAsComputedOr(getController(), 'anyWarnings', ['anyGeneralWarnings', 'anyHostWarnings']);
  492. describe('#anyWarnings', function () {
  493. it('true if generalWarningMessages is non empty', function () {
  494. controller.set('generalWarningMessages', ["error 404", "error"]);
  495. expect(controller.get('anyWarnings')).to.equal(true);
  496. });
  497. it('false if generalWarningMessages is empty', function () {
  498. controller.set('generalWarningMessages', []);
  499. expect(controller.get('anyWarnings')).to.equal(false);
  500. });
  501. });
  502. App.TestAliases.testAsComputedEqual(getController(), 'isInstallerWizard', 'content.controllerName', 'installerController');
  503. App.TestAliases.testAsComputedEqual(getController(), 'isAddServiceWizard', 'content.controllerName', 'addServiceController');
  504. describe('#selectClientHost', function () {
  505. it('true if isClientsSet false', function () {
  506. var hostsObj = Em.A([Em.Object.create({
  507. hasMaster: false,
  508. checkboxes: Em.A([
  509. Em.Object.create({
  510. component: 'c1',
  511. isInstalled: false,
  512. checked: true
  513. })
  514. ])
  515. })]);
  516. controller.set('isClientsSet', false);
  517. controller.selectClientHost(hostsObj);
  518. expect(controller.get('isClientsSet')).to.equal(true);
  519. });
  520. });
  521. describe('#updateValidationsSuccessCallback', function () {
  522. var hosts = Em.A([Em.Object.create({
  523. warnMessages: "warn",
  524. errorMessages: "error",
  525. anyMessage: true,
  526. checkboxes: Em.A([Em.Object.create({
  527. hasWarnMessage: true,
  528. hasErrorMessage: true
  529. })])
  530. })]);
  531. var validationData = Em.Object.create({
  532. resources: Em.A([
  533. Em.Object.create({
  534. items: Em.A([
  535. Em.Object.create({
  536. "component-name": 'HDFS_CLIENT',
  537. host: "1",
  538. isMaster: true
  539. })
  540. ])
  541. })
  542. ])
  543. });
  544. beforeEach(function () {
  545. sinon.stub(validationUtils, 'filterNotInstalledComponents', function () {
  546. return Em.A([Em.Object.create({
  547. componentName: 'c0',
  548. isSlave: true,
  549. type: 'host-component',
  550. level: 'ERROR'
  551. }),
  552. Em.Object.create({
  553. componentName: 'c1',
  554. isSlave: true,
  555. type: 'host-component',
  556. level: 'WARN',
  557. isShownOnInstallerSlaveClientPage: true
  558. })]);
  559. });
  560. sinon.stub(App.StackServiceComponent, 'find', function () {
  561. return [
  562. Em.Object.create({
  563. componentName: 'c0',
  564. isSlave: true
  565. }),
  566. Em.Object.create({
  567. componentName: 'c1',
  568. isSlave: true,
  569. isShownOnInstallerSlaveClientPage: true
  570. }),
  571. Em.Object.create({
  572. componentName: 'c2',
  573. isSlave: true,
  574. isShownOnInstallerSlaveClientPage: false
  575. }),
  576. Em.Object.create({
  577. componentName: 'c3',
  578. isClient: true
  579. }),
  580. Em.Object.create({
  581. componentName: 'c4',
  582. isClient: true,
  583. isRequiredOnAllHosts: false
  584. }),
  585. Em.Object.create({
  586. componentName: 'c5',
  587. isClient: true,
  588. isRequiredOnAllHosts: true
  589. }),
  590. Em.Object.create({
  591. componentName: 'c6',
  592. isMaster: true,
  593. isShownOnInstallerAssignMasterPage: true
  594. }),
  595. Em.Object.create({
  596. componentName: 'c7',
  597. isMaster: true,
  598. isShownOnInstallerAssignMasterPage: false
  599. }),
  600. Em.Object.create({
  601. componentName: 'HDFS_CLIENT',
  602. isMaster: true,
  603. isShownOnAddServiceAssignMasterPage: true
  604. }),
  605. Em.Object.create({
  606. componentName: 'c9',
  607. isMaster: true,
  608. isShownOnAddServiceAssignMasterPage: false
  609. })
  610. ];
  611. });
  612. controller.set('hosts', hosts);
  613. controller.updateValidationsSuccessCallback(validationData);
  614. });
  615. afterEach(function () {
  616. App.StackServiceComponent.find.restore();
  617. validationUtils.filterNotInstalledComponents.restore();
  618. });
  619. it('no generalErrorMessages', function () {
  620. expect(controller.get('generalErrorMessages').length).to.equal(0);
  621. });
  622. it('no generalWarningMessages', function () {
  623. expect(controller.get('generalWarningMessages').length).to.equal(0);
  624. });
  625. it('hosts info is valid', function () {
  626. var cHosts = JSON.parse(JSON.stringify(controller.get('hosts')));
  627. var expected = [{
  628. warnMessages: [null],
  629. errorMessages: [null],
  630. anyMessage: true,
  631. checkboxes: [{
  632. hasWarnMessage: true,
  633. hasErrorMessage: true
  634. }]
  635. }];
  636. expect(cHosts).to.eql(expected);
  637. });
  638. });
  639. describe('#clearError', function () {
  640. var headers = Em.A([
  641. Em.Object.create({name: "c1", label: 't1'}),
  642. Em.Object.create({name: "c2", label: 't2'})]);
  643. beforeEach(function () {
  644. controller.set('errorMessage', 'error');
  645. controller.set('headers', headers);
  646. });
  647. it('both checkboxes are checked', function () {
  648. var hosts = Em.A([
  649. Em.Object.create({
  650. checkboxes: Em.A([
  651. Em.Object.create({
  652. component: 'c1',
  653. isInstalled: false,
  654. checked: true
  655. }),
  656. Em.Object.create({
  657. component: 'c2',
  658. isInstalled: false,
  659. checked: true
  660. })])
  661. })
  662. ]);
  663. controller.set('hosts', hosts);
  664. controller.clearError();
  665. expect(controller.get('errorMessage')).to.equal('');
  666. });
  667. it('true if is one of checkboxes checked false', function () {
  668. var hosts = Em.A([
  669. Em.Object.create({
  670. checkboxes: Em.A([
  671. Em.Object.create({
  672. title: "t1",
  673. component: 'c1',
  674. isInstalled: false,
  675. checked: false
  676. }),
  677. Em.Object.create({
  678. title: "t2",
  679. component: 'c2',
  680. isInstalled: false,
  681. checked: true
  682. })])
  683. })
  684. ]);
  685. controller.set('hosts', hosts);
  686. controller.set('isAddHostWizard', true);
  687. controller.clearError();
  688. expect(controller.get('errorMessage')).to.equal('error');
  689. });
  690. });
  691. describe('#clearStep', function () {
  692. beforeEach(function () {
  693. sinon.stub(controller, 'clearError', Em.K);
  694. });
  695. afterEach(function () {
  696. controller.clearError.restore();
  697. });
  698. it('should call clearError', function () {
  699. controller.clearStep();
  700. expect(controller.clearError.calledOnce).to.equal(true);
  701. });
  702. it('should clear hosts', function () {
  703. controller.set('hosts', [
  704. {},
  705. {}
  706. ]);
  707. controller.clearStep();
  708. expect(controller.get('hosts')).to.eql([]);
  709. });
  710. it('should clear headers', function () {
  711. controller.set('headers', [
  712. {},
  713. {}
  714. ]);
  715. controller.clearStep();
  716. expect(controller.get('headers')).to.eql([]);
  717. });
  718. it('should set isLoaded to false', function () {
  719. controller.set('isLoaded', true);
  720. controller.clearStep();
  721. expect(controller.get('isLoaded')).to.equal(false);
  722. });
  723. });
  724. describe('#checkCallback', function () {
  725. beforeEach(function () {
  726. sinon.stub(controller, 'clearError', Em.K);
  727. });
  728. afterEach(function () {
  729. controller.clearError.restore();
  730. });
  731. it('should call clearError', function () {
  732. controller.checkCallback('');
  733. expect(controller.clearError.calledOnce).to.equal(true);
  734. });
  735. Em.A([
  736. {
  737. m: 'all checked, isInstalled false',
  738. headers: Em.A([
  739. Em.Object.create({name: 'c1'})
  740. ]),
  741. hosts: Em.A([
  742. Em.Object.create({
  743. checkboxes: Em.A([
  744. Em.Object.create({
  745. component: 'c1',
  746. isInstalled: false,
  747. checked: true
  748. })
  749. ])
  750. })
  751. ]),
  752. component: 'c1',
  753. e: {
  754. allChecked: true,
  755. noChecked: false
  756. }
  757. },
  758. {
  759. m: 'all checked, isInstalled true',
  760. headers: Em.A([
  761. Em.Object.create({name: 'c1'})
  762. ]),
  763. hosts: Em.A([
  764. Em.Object.create({
  765. checkboxes: Em.A([
  766. Em.Object.create({
  767. component: 'c1',
  768. isInstalled: true,
  769. checked: true
  770. })
  771. ])
  772. })
  773. ]),
  774. component: 'c1',
  775. e: {
  776. allChecked: true,
  777. noChecked: true
  778. }
  779. },
  780. {
  781. m: 'no one checked',
  782. headers: Em.A([
  783. Em.Object.create({name: 'c1'})
  784. ]),
  785. hosts: Em.A([
  786. Em.Object.create({
  787. checkboxes: Em.A([
  788. Em.Object.create({
  789. component: 'c1',
  790. isInstalled: false,
  791. checked: false
  792. })
  793. ])
  794. })
  795. ]),
  796. component: 'c1',
  797. e: {
  798. allChecked: false,
  799. noChecked: true
  800. }
  801. },
  802. {
  803. m: 'some checked',
  804. headers: Em.A([
  805. Em.Object.create({name: 'c1'})
  806. ]),
  807. hosts: Em.A([
  808. Em.Object.create({
  809. checkboxes: Em.A([
  810. Em.Object.create({
  811. component: 'c1',
  812. isInstalled: false,
  813. checked: true
  814. }),
  815. Em.Object.create({
  816. component: 'c1',
  817. isInstalled: false,
  818. checked: false
  819. })
  820. ])
  821. })
  822. ]),
  823. component: 'c1',
  824. e: {
  825. allChecked: false,
  826. noChecked: false
  827. }
  828. },
  829. {
  830. m: 'some checked, some isInstalled true',
  831. headers: Em.A([
  832. Em.Object.create({name: 'c1'})
  833. ]),
  834. hosts: Em.A([
  835. Em.Object.create({
  836. checkboxes: Em.A([
  837. Em.Object.create({
  838. component: 'c1',
  839. isInstalled: true,
  840. checked: true
  841. }),
  842. Em.Object.create({
  843. component: 'c1',
  844. isInstalled: true,
  845. checked: true
  846. })
  847. ])
  848. })
  849. ]),
  850. component: 'c1',
  851. e: {
  852. allChecked: true,
  853. noChecked: true
  854. }
  855. },
  856. {
  857. m: 'some checked, some isInstalled true (2)',
  858. headers: Em.A([
  859. Em.Object.create({name: 'c1'})
  860. ]),
  861. hosts: Em.A([
  862. Em.Object.create({
  863. checkboxes: Em.A([
  864. Em.Object.create({
  865. component: 'c1',
  866. isInstalled: false,
  867. checked: false
  868. }),
  869. Em.Object.create({
  870. component: 'c1',
  871. isInstalled: true,
  872. checked: true
  873. })
  874. ])
  875. })
  876. ]),
  877. component: 'c1',
  878. e: {
  879. allChecked: false,
  880. noChecked: true
  881. }
  882. }
  883. ]).forEach(function (test) {
  884. describe(test.m, function () {
  885. beforeEach(function () {
  886. controller.clearStep();
  887. controller.set('headers', test.headers);
  888. controller.set('hosts', test.hosts);
  889. controller.checkCallback(test.component);
  890. this.header = controller.get('headers').findProperty('name', test.component);
  891. });
  892. it('allChecked is ' + test.e.allChecked, function () {
  893. expect(this.header.get('allChecked')).to.equal(test.e.allChecked);
  894. });
  895. it('noChecked is ' + test.e.noChecked, function () {
  896. expect(this.header.get('noChecked')).to.equal(test.e.noChecked);
  897. });
  898. });
  899. });
  900. });
  901. describe('#getHostNames', function () {
  902. var tests = Em.A([
  903. {
  904. hosts: {
  905. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  906. h2: {bootStatus: 'REGISTERED', name: 'h2'},
  907. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  908. },
  909. m: 'All REGISTERED',
  910. e: ['h1', 'h2', 'h3']
  911. },
  912. {
  913. hosts: {
  914. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  915. h2: {bootStatus: 'FAILED', name: 'h2'},
  916. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  917. },
  918. m: 'Some REGISTERED',
  919. e: ['h1', 'h3']
  920. },
  921. {
  922. hosts: {
  923. h1: {bootStatus: 'FAILED', name: 'h1'},
  924. h2: {bootStatus: 'FAILED', name: 'h2'},
  925. h3: {bootStatus: 'FAILED', name: 'h3'}
  926. },
  927. m: 'No one REGISTERED',
  928. e: []
  929. },
  930. {
  931. hosts: {},
  932. m: 'Empty hosts',
  933. e: []
  934. }
  935. ]);
  936. tests.forEach(function (test) {
  937. it(test.m, function () {
  938. controller.set('content.hosts', test.hosts);
  939. var r = controller.getHostNames();
  940. expect(r).to.eql(test.e);
  941. });
  942. });
  943. });
  944. describe('#getMasterComponentsForHost', function () {
  945. var tests = Em.A([
  946. {
  947. masterComponentHosts: Em.A([
  948. {hostName: 'h1', component: 'c1'}
  949. ]),
  950. hostName: 'h1',
  951. m: 'host exists',
  952. e: ['c1']
  953. },
  954. {
  955. masterComponentHosts: Em.A([
  956. {hostName: 'h1', component: 'c1'}
  957. ]),
  958. hostName: 'h2',
  959. m: 'host donesn\'t exists',
  960. e: []
  961. }
  962. ]);
  963. tests.forEach(function (test) {
  964. it(test.m, function () {
  965. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  966. var r = controller.getMasterComponentsForHost(test.hostName);
  967. expect(r).to.eql(test.e);
  968. });
  969. });
  970. });
  971. describe('#selectMasterComponents', function () {
  972. var tests = Em.A([
  973. {
  974. masterComponentHosts: Em.A([
  975. {
  976. hostName: 'h1',
  977. component: 'c1'
  978. }
  979. ]),
  980. hostsObj: [
  981. Em.Object.create({
  982. hostName: 'h1',
  983. checkboxes: [
  984. Em.Object.create({
  985. component: 'c1',
  986. checked: false
  987. })
  988. ]
  989. })
  990. ],
  991. e: true,
  992. m: 'host and component exist'
  993. },
  994. {
  995. masterComponentHosts: Em.A([
  996. {
  997. hostName: 'h1',
  998. component: 'c2'
  999. }
  1000. ]),
  1001. hostsObj: [
  1002. Em.Object.create({
  1003. hostName: 'h1',
  1004. checkboxes: [
  1005. Em.Object.create({
  1006. component: 'c1',
  1007. checked: false
  1008. })
  1009. ]
  1010. })
  1011. ],
  1012. e: false,
  1013. m: 'host exists'
  1014. },
  1015. {
  1016. masterComponentHosts: Em.A([
  1017. {
  1018. hostName: 'h2',
  1019. component: 'c2'
  1020. }
  1021. ]),
  1022. hostsObj: [
  1023. Em.Object.create({
  1024. hostName: 'h1',
  1025. checkboxes: [
  1026. Em.Object.create({
  1027. component: 'c1',
  1028. checked: false
  1029. })
  1030. ]
  1031. })
  1032. ],
  1033. e: false,
  1034. m: 'host and component don\'t exist'
  1035. }
  1036. ]);
  1037. tests.forEach(function (test) {
  1038. it(test.m, function () {
  1039. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  1040. var r = controller.selectMasterComponents(test.hostsObj);
  1041. expect(r.findProperty('hostName', 'h1').get('checkboxes').findProperty('component', 'c1').get('checked')).to.equal(test.e);
  1042. });
  1043. });
  1044. });
  1045. describe('#getCurrentMastersBlueprint', function () {
  1046. var tests = Em.A([
  1047. {
  1048. masterComponentHosts: Em.A([
  1049. {hostName: 'h1', component: 'c1'}
  1050. ]),
  1051. hosts: {'h1': {}},
  1052. m: 'one host and one component',
  1053. e:{
  1054. blueprint: {
  1055. host_groups: [
  1056. {
  1057. name: 'host-group-1',
  1058. components: [
  1059. { name: 'c1' }
  1060. ]
  1061. }
  1062. ]
  1063. },
  1064. blueprint_cluster_binding: {
  1065. host_groups: [
  1066. {
  1067. name: 'host-group-1',
  1068. hosts: [
  1069. { fqdn: 'h1' }
  1070. ]
  1071. }
  1072. ]
  1073. }
  1074. }
  1075. },
  1076. {
  1077. masterComponentHosts: Em.A([
  1078. {hostName: 'h1', component: 'c1'},
  1079. {hostName: 'h2', component: 'c2'},
  1080. {hostName: 'h2', component: 'c3'}
  1081. ]),
  1082. hosts: {'h1': {}, 'h2': {}, 'h3': {}},
  1083. m: 'multiple hosts and multiple components',
  1084. e: {
  1085. blueprint: {
  1086. host_groups: [
  1087. {
  1088. name: 'host-group-1',
  1089. components: [
  1090. { name: 'c1' }
  1091. ]
  1092. },
  1093. {
  1094. name: 'host-group-2',
  1095. components: [
  1096. { name: 'c2' },
  1097. { name: 'c3' }
  1098. ]
  1099. },
  1100. {
  1101. name: 'host-group-3',
  1102. components: []
  1103. }
  1104. ]
  1105. },
  1106. blueprint_cluster_binding: {
  1107. host_groups: [
  1108. {
  1109. name: 'host-group-1',
  1110. hosts: [
  1111. { fqdn: 'h1' }
  1112. ]
  1113. },
  1114. {
  1115. name: 'host-group-2',
  1116. hosts: [
  1117. { fqdn: 'h2' }
  1118. ]
  1119. },
  1120. {
  1121. name: 'host-group-3',
  1122. hosts: [
  1123. { fqdn: 'h3' }
  1124. ]
  1125. }
  1126. ]
  1127. }
  1128. }
  1129. }
  1130. ]);
  1131. tests.forEach(function (test) {
  1132. it(test.m, function () {
  1133. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  1134. controller.set('content.hosts', test.hosts);
  1135. var r = controller.getCurrentMastersBlueprint();
  1136. expect(r).to.eql(test.e);
  1137. });
  1138. });
  1139. });
  1140. describe('#getCurrentBlueprint', function () {
  1141. var tests = Em.A([
  1142. {
  1143. clientComponents: Em.A([{component_name: "name1"}]),
  1144. hosts: Em.A([
  1145. Em.Object.create({
  1146. checkboxes: Em.A([
  1147. Em.Object.create({
  1148. component: 'c1',
  1149. checked: true
  1150. }),
  1151. Em.Object.create({
  1152. component: 'CLIENT',
  1153. checked: true
  1154. })
  1155. ])
  1156. })
  1157. ]),
  1158. m: 'one host and one component',
  1159. e:{
  1160. blueprint: {
  1161. host_groups: [
  1162. {
  1163. name: 'host-group-1',
  1164. components: [
  1165. { name: 'c1' },
  1166. { name: 'name1' }
  1167. ]
  1168. }
  1169. ]
  1170. },
  1171. blueprint_cluster_binding: {
  1172. host_groups: [
  1173. {
  1174. name: 'host-group-1',
  1175. hosts: [
  1176. {}
  1177. ]
  1178. }
  1179. ]
  1180. }
  1181. }
  1182. }
  1183. ]);
  1184. tests.forEach(function (test) {
  1185. it(test.m, function () {
  1186. controller.set('content.clients', test.clientComponents);
  1187. controller.set('hosts', test.hosts);
  1188. var r = controller.getCurrentBlueprint();
  1189. expect(JSON.parse(JSON.stringify(r))).to.eql(JSON.parse(JSON.stringify(test.e)));
  1190. });
  1191. });
  1192. });
  1193. describe('#callServerSideValidation', function () {
  1194. var cases = [
  1195. {
  1196. controllerName: 'installerController',
  1197. hosts: [
  1198. {
  1199. hostName: 'h0'
  1200. },
  1201. {
  1202. hostName: 'h1'
  1203. }
  1204. ],
  1205. expected: [
  1206. ['c0', 'c6'],
  1207. ['c1', 'c3', 'c8']
  1208. ]
  1209. },
  1210. {
  1211. controllerName: 'addServiceController',
  1212. hosts: [
  1213. {
  1214. hostName: 'h0'
  1215. },
  1216. {
  1217. hostName: 'h1'
  1218. }
  1219. ],
  1220. expected: [
  1221. ['c0', 'c6'],
  1222. ['c1', 'c3', 'c8']
  1223. ]
  1224. },
  1225. {
  1226. controllerName: 'addHostController',
  1227. hosts: [
  1228. {
  1229. hostName: 'h0'
  1230. }
  1231. ],
  1232. expected: [
  1233. ['c0', 'c2', 'c5', 'c6'],
  1234. ['c1', 'c2', 'c3', 'c5', 'c8']
  1235. ]
  1236. }
  1237. ],
  1238. expectedHostGroups = [
  1239. {
  1240. name: 'host-group-1',
  1241. fqdn: 'h0'
  1242. },
  1243. {
  1244. name: 'host-group-2',
  1245. fqdn: 'h1'
  1246. }
  1247. ];
  1248. beforeEach(function () {
  1249. controller.get('content').setProperties({
  1250. recommendations: {
  1251. blueprint: {
  1252. host_groups: [
  1253. {
  1254. components: [
  1255. {
  1256. name: 'c6'
  1257. }
  1258. ],
  1259. name: 'host-group-1'
  1260. },
  1261. {
  1262. components: [
  1263. {
  1264. name: 'c8'
  1265. }
  1266. ],
  1267. name: 'host-group-2'
  1268. }
  1269. ]
  1270. },
  1271. blueprint_cluster_binding: {
  1272. host_groups: [
  1273. {
  1274. hosts: [
  1275. {
  1276. fqdn: 'h0'
  1277. }
  1278. ],
  1279. name: 'host-group-1'
  1280. },
  1281. {
  1282. hosts: [
  1283. {
  1284. fqdn: 'h1'
  1285. }
  1286. ],
  1287. name: 'host-group-2'
  1288. }]
  1289. }
  1290. },
  1291. clients: [
  1292. {
  1293. component_name: 'c3'
  1294. }
  1295. ]
  1296. });
  1297. sinon.stub(App.StackService, 'find', function () {
  1298. return [
  1299. Em.Object.create({
  1300. serviceName: 's0',
  1301. isSelected: true
  1302. }),
  1303. Em.Object.create({
  1304. serviceName: 's1',
  1305. isInstalled: true,
  1306. isSelected: true
  1307. })
  1308. ];
  1309. });
  1310. sinon.stub(App.StackServiceComponent, 'find', function () {
  1311. return [
  1312. Em.Object.create({
  1313. componentName: 'c0',
  1314. isSlave: true
  1315. }),
  1316. Em.Object.create({
  1317. componentName: 'c1',
  1318. isSlave: true,
  1319. isShownOnInstallerSlaveClientPage: true
  1320. }),
  1321. Em.Object.create({
  1322. componentName: 'c2',
  1323. isSlave: true,
  1324. isShownOnInstallerSlaveClientPage: false
  1325. }),
  1326. Em.Object.create({
  1327. componentName: 'c3',
  1328. isClient: true
  1329. }),
  1330. Em.Object.create({
  1331. componentName: 'c4',
  1332. isClient: true,
  1333. isRequiredOnAllHosts: false
  1334. }),
  1335. Em.Object.create({
  1336. componentName: 'c5',
  1337. isClient: true,
  1338. isRequiredOnAllHosts: true
  1339. }),
  1340. Em.Object.create({
  1341. componentName: 'c6',
  1342. isMaster: true,
  1343. isShownOnInstallerAssignMasterPage: true
  1344. }),
  1345. Em.Object.create({
  1346. componentName: 'c7',
  1347. isMaster: true,
  1348. isShownOnInstallerAssignMasterPage: false
  1349. }),
  1350. Em.Object.create({
  1351. componentName: 'c8',
  1352. isMaster: true,
  1353. isShownOnAddServiceAssignMasterPage: true
  1354. }),
  1355. Em.Object.create({
  1356. componentName: 'c9',
  1357. isMaster: true,
  1358. isShownOnAddServiceAssignMasterPage: false
  1359. })
  1360. ];
  1361. });
  1362. sinon.stub(controller, 'getCurrentBlueprint', function () {
  1363. return {
  1364. blueprint: {
  1365. host_groups: [
  1366. {
  1367. components: [
  1368. {
  1369. name: 'c0'
  1370. }
  1371. ],
  1372. name: 'host-group-1'
  1373. },
  1374. {
  1375. components: [
  1376. {
  1377. name: 'c1'
  1378. },
  1379. {
  1380. name: 'c3'
  1381. }
  1382. ],
  1383. name: 'host-group-2'
  1384. }
  1385. ]
  1386. },
  1387. blueprint_cluster_binding: {
  1388. host_groups: [
  1389. {
  1390. hosts: [
  1391. {
  1392. fqdn: 'h0'
  1393. }
  1394. ],
  1395. name: 'host-group-1'
  1396. },
  1397. {
  1398. hosts: [
  1399. {
  1400. fqdn: 'h1'
  1401. }
  1402. ],
  1403. name: 'host-group-2'
  1404. }]
  1405. }
  1406. };
  1407. });
  1408. sinon.stub(controller, 'getCurrentMastersBlueprint', function () {
  1409. return {
  1410. blueprint: {
  1411. host_groups: [
  1412. {
  1413. components: [
  1414. {
  1415. name: 'c6'
  1416. }
  1417. ],
  1418. name: 'host-group-1'
  1419. },
  1420. {
  1421. components: [
  1422. {
  1423. name: 'c8'
  1424. }
  1425. ],
  1426. name: 'host-group-2'
  1427. }
  1428. ]
  1429. },
  1430. blueprint_cluster_binding: {
  1431. host_groups: [
  1432. {
  1433. hosts: [
  1434. {
  1435. fqdn: 'h0'
  1436. }
  1437. ],
  1438. name: 'host-group-1'
  1439. },
  1440. {
  1441. hosts: [
  1442. {
  1443. fqdn: 'h1'
  1444. }
  1445. ],
  1446. name: 'host-group-2'
  1447. }]
  1448. }
  1449. };
  1450. });
  1451. sinon.stub(App, 'get').withArgs('components.clients').returns(['c3', 'c4']);
  1452. sinon.stub(controller, 'getCurrentMasterSlaveBlueprint', function () {
  1453. return {
  1454. blueprint: {
  1455. host_groups: [
  1456. {
  1457. components: [
  1458. {
  1459. name: 'c6'
  1460. }
  1461. ],
  1462. name: 'host-group-1'
  1463. },
  1464. {
  1465. components: [
  1466. {
  1467. name: 'c8'
  1468. }
  1469. ],
  1470. name: 'host-group-2'
  1471. }
  1472. ]
  1473. },
  1474. blueprint_cluster_binding: {
  1475. host_groups: [
  1476. {
  1477. hosts: [
  1478. {
  1479. fqdn: 'h0'
  1480. }
  1481. ],
  1482. name: 'host-group-1'
  1483. },
  1484. {
  1485. hosts: [
  1486. {
  1487. fqdn: 'h1'
  1488. }
  1489. ],
  1490. name: 'host-group-2'
  1491. }]
  1492. }
  1493. };
  1494. });
  1495. sinon.stub(App.Host, 'find', function () {
  1496. return [
  1497. {
  1498. hostName: 'h1'
  1499. }
  1500. ];
  1501. });
  1502. });
  1503. afterEach(function () {
  1504. App.StackService.find.restore();
  1505. App.StackServiceComponent.find.restore();
  1506. controller.getCurrentBlueprint.restore();
  1507. controller.getCurrentMastersBlueprint.restore();
  1508. App.get.restore();
  1509. controller.getCurrentMasterSlaveBlueprint.restore();
  1510. App.Host.find.restore();
  1511. });
  1512. cases.forEach(function (item) {
  1513. describe(item.controllerName, function () {
  1514. beforeEach(function () {
  1515. controller.set('hosts', item.hosts);
  1516. controller.set('content.controllerName', item.controllerName);
  1517. controller.callServerSideValidation();
  1518. });
  1519. it('blueprint.host_groups count is correct', function () {
  1520. expect(controller.get('content.recommendationsHostGroups.blueprint.host_groups.length')).to.equal(expectedHostGroups.length);
  1521. });
  1522. it('blueprint_cluster_binding.host_groups count is correct', function () {
  1523. expect(controller.get('content.recommendationsHostGroups.blueprint_cluster_binding.host_groups.length')).to.equal(expectedHostGroups.length);
  1524. });
  1525. item.expected.forEach(function (e, index) {
  1526. it('components are valid for group# ' + (index + 1), function () {
  1527. expect(controller.get('content.recommendationsHostGroups.blueprint.host_groups')[index].components.mapProperty('name').sort()).to.be.eql(e);
  1528. });
  1529. });
  1530. expectedHostGroups.forEach(function (group) {
  1531. it(group.name, function () {
  1532. var bpGroup = controller.get('content.recommendationsHostGroups.blueprint_cluster_binding.host_groups').findProperty('name', group.name);
  1533. expect(bpGroup.hosts).to.have.length(1);
  1534. expect(bpGroup.hosts[0].fqdn).to.equal(group.fqdn);
  1535. });
  1536. });
  1537. });
  1538. });
  1539. });
  1540. describe('#isAllCheckboxesEmpty', function () {
  1541. Em.A([
  1542. {
  1543. m: 'all checkboxes are not empty',
  1544. hosts: [
  1545. {checkboxes: [{checked: true}, {checked: true}]},
  1546. {checkboxes: [{checked: true}, {checked: true}]}
  1547. ],
  1548. e: false
  1549. },
  1550. {
  1551. m: 'some checkboxes are empty',
  1552. hosts: [
  1553. {checkboxes: [{checked: true}, {checked: false}]},
  1554. {checkboxes: [{checked: true}, {checked: false}]}
  1555. ],
  1556. e: false
  1557. },
  1558. {
  1559. m: 'all checkboxes are empty',
  1560. hosts: [
  1561. {checkboxes: [{checked: false}, {checked: false}]},
  1562. {checkboxes: [{checked: false}, {checked: false}]}
  1563. ],
  1564. e: true
  1565. }
  1566. ]).forEach(function (test) {
  1567. it(test.m, function () {
  1568. controller.set('hosts', test.hosts);
  1569. expect(controller.isAllCheckboxesEmpty()).to.be.equal(test.e);
  1570. });
  1571. });
  1572. });
  1573. describe('#loadStep', function () {
  1574. beforeEach(function () {
  1575. sinon.stub(controller, 'render', Em.K);
  1576. sinon.stub(controller, 'callValidation', Em.K);
  1577. sinon.stub(App.StackService, 'find').returns([
  1578. Em.Object.create({
  1579. isSelected: true,
  1580. serviceName: 's1',
  1581. serviceComponents: [
  1582. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's1c1', isRequired: true}),
  1583. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's1c2', isRequired: true})
  1584. ]
  1585. }),
  1586. Em.Object.create({
  1587. isSelected: true,
  1588. serviceName: 's2',
  1589. serviceComponents: [
  1590. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's2c3', isRequired: false}),
  1591. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's2c4', isRequired: false})
  1592. ]
  1593. }),
  1594. Em.Object.create({
  1595. isInstalled: true,
  1596. serviceName: 's3',
  1597. serviceComponents: [
  1598. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's3c1', isRequired: true}),
  1599. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's3c2', isRequired: true})
  1600. ]
  1601. }),
  1602. Em.Object.create({
  1603. isInstalled: true,
  1604. serviceName: 's4',
  1605. serviceComponents: [
  1606. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's4c3', isRequired: false}),
  1607. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's4c4', isRequired: false})
  1608. ]
  1609. })
  1610. ]);
  1611. });
  1612. afterEach(function () {
  1613. controller.render.restore();
  1614. controller.callValidation.restore();
  1615. App.StackService.find.restore();
  1616. });
  1617. describe('isInstallerWizard', function () {
  1618. beforeEach(function () {
  1619. controller.set('content', {
  1620. clients: [{}],
  1621. controllerName: 'installerController'
  1622. });
  1623. controller.loadStep();
  1624. });
  1625. it('component names are valid', function () {
  1626. expect(controller.get('headers').mapProperty('name')).to.be.eql(['s1c1', 's1c2', 's2c3', 's2c4', 'CLIENT']);
  1627. });
  1628. it('component labels are valid', function () {
  1629. expect(controller.get('headers').mapProperty('label')).to.be.eql(['S1c1', 'S1c2', 'S2c3', 'S2c4', 'Client']);
  1630. });
  1631. it('everyone allChecked is false', function () {
  1632. expect(controller.get('headers').everyProperty('allChecked', false)).to.be.true;
  1633. });
  1634. it('component required-flags are valid', function () {
  1635. expect(controller.get('headers').mapProperty('isRequired')).to.be.eql([true, true, false, false, undefined]);
  1636. });
  1637. it('everyone noChecked is false', function () {
  1638. expect(controller.get('headers').everyProperty('noChecked', true)).to.be.true;
  1639. });
  1640. it('everyone isDisabled is false', function () {
  1641. expect(controller.get('headers').everyProperty('isDisabled', false)).to.be.true;
  1642. });
  1643. it('component allId-fields are valid', function () {
  1644. expect(controller.get('headers').mapProperty('allId')).to.be.eql(['all-s1c1', 'all-s1c2', 'all-s2c3', 'all-s2c4', 'all-CLIENT']);
  1645. });
  1646. it('component noneId-fields are valid', function () {
  1647. expect(controller.get('headers').mapProperty('noneId')).to.be.eql(['none-s1c1', 'none-s1c2', 'none-s2c3', 'none-s2c4', 'none-CLIENT']);
  1648. });
  1649. });
  1650. describe('isAddHostWizard', function () {
  1651. beforeEach(function () {
  1652. controller.set('content', {
  1653. clients: [{}],
  1654. controllerName: 'addHostController'
  1655. });
  1656. controller.loadStep();
  1657. });
  1658. it('component names are valid', function () {
  1659. expect(controller.get('headers').mapProperty('name')).to.be.eql(['s3c1', 's3c2', 's4c3', 's4c4', 'CLIENT']);
  1660. });
  1661. it('component labels are valid', function () {
  1662. expect(controller.get('headers').mapProperty('label')).to.be.eql(['S3c1', 'S3c2', 'S4c3', 'S4c4', 'Client']);
  1663. });
  1664. it('everyone allChecked is false', function () {
  1665. expect(controller.get('headers').everyProperty('allChecked', false)).to.be.true;
  1666. });
  1667. it('component required-flags are valid', function () {
  1668. expect(controller.get('headers').mapProperty('isRequired')).to.be.eql([true, true, false, false, undefined]);
  1669. });
  1670. it('everyone noChecked is false', function () {
  1671. expect(controller.get('headers').everyProperty('noChecked', true)).to.be.true;
  1672. });
  1673. it('everyone isDisabled is false', function () {
  1674. expect(controller.get('headers').everyProperty('isDisabled', false)).to.be.true;
  1675. });
  1676. it('component allId-fields are valid', function () {
  1677. expect(controller.get('headers').mapProperty('allId')).to.be.eql(['all-s3c1', 'all-s3c2', 'all-s4c3', 'all-s4c4', 'all-CLIENT']);
  1678. });
  1679. it('component noneId-fields are valid', function () {
  1680. expect(controller.get('headers').mapProperty('noneId')).to.be.eql(['none-s3c1', 'none-s3c2', 'none-s4c3', 'none-s4c4', 'none-CLIENT']);
  1681. });
  1682. });
  1683. describe('isAddServiceWizard', function () {
  1684. beforeEach(function () {
  1685. controller.set('content', {
  1686. clients: [{}],
  1687. controllerName: 'addServiceController'
  1688. });
  1689. controller.loadStep();
  1690. });
  1691. it('component names are valid', function () {
  1692. expect(controller.get('headers').mapProperty('name')).to.be.eql(['s3c1', 's3c2', 's4c3', 's4c4', 's1c1', 's1c2', 's2c3', 's2c4', 'CLIENT']);
  1693. });
  1694. it('component labels are valid', function () {
  1695. expect(controller.get('headers').mapProperty('label')).to.be.eql(['S3c1', 'S3c2', 'S4c3', 'S4c4', 'S1c1', 'S1c2', 'S2c3', 'S2c4', 'Client']);
  1696. });
  1697. it('everyone allChecked is false', function () {
  1698. expect(controller.get('headers').everyProperty('allChecked', false)).to.be.true;
  1699. });
  1700. it('component required-flags are valid', function () {
  1701. expect(controller.get('headers').mapProperty('isRequired')).to.be.eql([true, true, false, false, true, true, false, false, undefined]);
  1702. });
  1703. it('everyone noChecked is false', function () {
  1704. expect(controller.get('headers').everyProperty('noChecked', true)).to.be.true;
  1705. });
  1706. it('installed services are disabled', function () {
  1707. expect(controller.get('headers').mapProperty('isDisabled', false)).to.be.eql([true, true, true, true, false, false, false, false, false]);
  1708. });
  1709. it('component allId-fields are valid', function () {
  1710. expect(controller.get('headers').mapProperty('allId')).to.be.eql(['all-s3c1', 'all-s3c2', 'all-s4c3', 'all-s4c4', 'all-s1c1', 'all-s1c2', 'all-s2c3', 'all-s2c4', 'all-CLIENT']);
  1711. });
  1712. it('component noneId-fields are valid', function () {
  1713. expect(controller.get('headers').mapProperty('noneId')).to.be.eql(['none-s3c1', 'none-s3c2', 'none-s4c3', 'none-s4c4', 'none-s1c1', 'none-s1c2', 'none-s2c3', 'none-s2c4', 'none-CLIENT']);
  1714. });
  1715. });
  1716. });
  1717. describe('#anyHostErrors', function () {
  1718. var tests = [
  1719. {
  1720. it: "anyHostErrors returns true if errorMessages are defined",
  1721. host: Em.A([Em.Object.create({
  1722. errorMessages: "Error Message"
  1723. })]),
  1724. result: true
  1725. },
  1726. {
  1727. it: "anyHostErrors returns false if errorMessages are not defined",
  1728. host: Em.A([Em.Object.create({
  1729. })]),
  1730. result: false
  1731. }
  1732. ];
  1733. tests.forEach(function(test) {
  1734. it(test.it, function() {
  1735. controller.set('hosts', test.host);
  1736. expect(controller.get('anyHostErrors')).to.equal(test.result);
  1737. })
  1738. });
  1739. });
  1740. describe('#anyHostWarnings', function () {
  1741. var tests = [
  1742. {
  1743. it: "anyHostWarnings returns true if warnMessages are defined",
  1744. host: Em.A([Em.Object.create({
  1745. warnMessages: "Warning Message"
  1746. })]),
  1747. result: true
  1748. },
  1749. {
  1750. it: "anyHostWarnings returns false if warnMessages are not defined",
  1751. host: Em.A([Em.Object.create({
  1752. })]),
  1753. result: false
  1754. }
  1755. ];
  1756. tests.forEach(function(test) {
  1757. it(test.it, function() {
  1758. controller.set('hosts', test.host);
  1759. expect(controller.get('anyHostWarnings')).to.equal(test.result);
  1760. })
  1761. });
  1762. });
  1763. });