config_test.js 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  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('controllers/main/service/info/configs');
  20. var batchUtils = require('utils/batch_scheduled_requests');
  21. var mainServiceInfoConfigsController = null;
  22. describe("App.MainServiceInfoConfigsController", function () {
  23. beforeEach(function () {
  24. mainServiceInfoConfigsController = App.MainServiceInfoConfigsController.create({});
  25. });
  26. describe("#showSavePopup", function () {
  27. var tests = [
  28. {
  29. path: false,
  30. callback: null,
  31. action: "onSave",
  32. m: "save configs without path/callback",
  33. results: [
  34. {
  35. method: "restartServicePopup",
  36. called: true
  37. }
  38. ]
  39. },
  40. {
  41. path: true,
  42. callback: true,
  43. action: "onSave",
  44. m: "save configs with path/callback",
  45. results: [
  46. {
  47. method: "restartServicePopup",
  48. called: true
  49. }
  50. ]
  51. },
  52. {
  53. path: false,
  54. callback: false,
  55. action: "onDiscard",
  56. m: "discard changes without path/callback",
  57. results: [
  58. {
  59. method: "restartServicePopup",
  60. called: false
  61. }
  62. ]
  63. },
  64. {
  65. path: false,
  66. callback: true,
  67. action: "onDiscard",
  68. m: "discard changes with callback",
  69. results: [
  70. {
  71. method: "restartServicePopup",
  72. called: false
  73. },
  74. {
  75. method: "callback",
  76. called: true
  77. },
  78. {
  79. field: "hash",
  80. value: "hash"
  81. }
  82. ]
  83. },
  84. {
  85. path: true,
  86. callback: null,
  87. action: "onDiscard",
  88. m: "discard changes with path",
  89. results: [
  90. {
  91. method: "restartServicePopup",
  92. called: false
  93. },
  94. {
  95. field: "forceTransition",
  96. value: true
  97. }
  98. ]
  99. }
  100. ];
  101. beforeEach(function () {
  102. sinon.stub(mainServiceInfoConfigsController, "restartServicePopup", Em.K);
  103. sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
  104. return "hash"
  105. });
  106. App.router.route = Em.K;
  107. });
  108. afterEach(function () {
  109. mainServiceInfoConfigsController.restartServicePopup.restore();
  110. mainServiceInfoConfigsController.getHash.restore();
  111. });
  112. tests.forEach(function (t) {
  113. t.results.forEach(function (r) {
  114. it(t.m + " " + r.method + " " + r.field, function () {
  115. if (t.callback) {
  116. t.callback = sinon.stub();
  117. }
  118. mainServiceInfoConfigsController.showSavePopup(t.path, t.callback)[t.action]();
  119. if (r.method) {
  120. if (r.method === 'callback') {
  121. expect(t.callback.calledOnce).to.equal(r.called);
  122. } else {
  123. expect(mainServiceInfoConfigsController[r.method].calledOnce).to.equal(r.called);
  124. }
  125. } else if (r.field) {
  126. expect(mainServiceInfoConfigsController.get(r.field)).to.equal(r.value);
  127. }
  128. }, this);
  129. });
  130. }, this);
  131. });
  132. describe("#hasUnsavedChanges", function () {
  133. beforeEach(function () {
  134. sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
  135. return "hash"
  136. });
  137. });
  138. afterEach(function () {
  139. mainServiceInfoConfigsController.getHash.restore();
  140. });
  141. it("with unsaved", function () {
  142. mainServiceInfoConfigsController.set("hash", "hash1");
  143. expect(mainServiceInfoConfigsController.hasUnsavedChanges()).to.equal(true);
  144. });
  145. it("without unsaved", function () {
  146. mainServiceInfoConfigsController.set("hash", "hash");
  147. expect(mainServiceInfoConfigsController.hasUnsavedChanges()).to.equal(false);
  148. });
  149. });
  150. describe("#manageConfigurationGroup", function () {
  151. beforeEach(function () {
  152. sinon.stub(mainServiceInfoConfigsController, "manageConfigurationGroups", Em.K);
  153. });
  154. afterEach(function () {
  155. mainServiceInfoConfigsController.manageConfigurationGroups.restore();
  156. });
  157. it("run manageConfigurationGroups", function () {
  158. mainServiceInfoConfigsController.manageConfigurationGroup();
  159. expect(mainServiceInfoConfigsController.manageConfigurationGroups.calledOnce).to.equal(true);
  160. });
  161. });
  162. describe("#addOverrideProperty", function () {
  163. var serviceConfigProperty = Em.Object.create({
  164. overrides: []
  165. });
  166. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  167. newSCP.set('value', '');
  168. newSCP.set('isOriginalSCP', false);
  169. newSCP.set('parentSCP', serviceConfigProperty);
  170. newSCP.set('isEditable', true);
  171. it("add new overridden property", function () {
  172. mainServiceInfoConfigsController.addOverrideProperty(serviceConfigProperty);
  173. expect(serviceConfigProperty.get("overrides")[0]).to.eql(newSCP);
  174. });
  175. });
  176. describe("#showComponentsShouldBeRestarted", function () {
  177. var tests = [
  178. {
  179. input: {
  180. 'publicHostName1': ['TaskTracker'],
  181. 'publicHostName2': ['JobTracker', 'TaskTracker']
  182. },
  183. components: "2 TaskTrackers, 1 JobTracker",
  184. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.components'))
  185. },
  186. {
  187. input: {
  188. 'publicHostName1': ['TaskTracker']
  189. },
  190. components: "1 TaskTracker",
  191. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.component'))
  192. }
  193. ];
  194. beforeEach(function () {
  195. sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
  196. mainServiceInfoConfigsController.set("content", {restartRequiredHostsAndComponents: ""});
  197. });
  198. afterEach(function () {
  199. mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
  200. mainServiceInfoConfigsController.set("content", undefined);
  201. });
  202. tests.forEach(function (t) {
  203. it("trigger showItemsShouldBeRestarted popup with components", function () {
  204. mainServiceInfoConfigsController.set("content.restartRequiredHostsAndComponents", t.input);
  205. mainServiceInfoConfigsController.showComponentsShouldBeRestarted();
  206. expect(mainServiceInfoConfigsController.showItemsShouldBeRestarted.calledWith(t.components, t.text)).to.equal(true);
  207. });
  208. });
  209. });
  210. describe("#showHostsShouldBeRestarted", function () {
  211. var tests = [
  212. {
  213. input: {
  214. 'publicHostName1': ['TaskTracker'],
  215. 'publicHostName2': ['JobTracker', 'TaskTracker']
  216. },
  217. hosts: "publicHostName1, publicHostName2",
  218. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.hosts'))
  219. },
  220. {
  221. input: {
  222. 'publicHostName1': ['TaskTracker']
  223. },
  224. hosts: "publicHostName1",
  225. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.host'))
  226. }
  227. ];
  228. beforeEach(function () {
  229. sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
  230. mainServiceInfoConfigsController.set("content", {restartRequiredHostsAndComponents: ""});
  231. });
  232. afterEach(function () {
  233. mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
  234. mainServiceInfoConfigsController.set("content", undefined);
  235. });
  236. tests.forEach(function (t) {
  237. it("trigger showItemsShouldBeRestarted popup with hosts", function () {
  238. mainServiceInfoConfigsController.set("content.restartRequiredHostsAndComponents", t.input);
  239. mainServiceInfoConfigsController.showHostsShouldBeRestarted();
  240. expect(mainServiceInfoConfigsController.showItemsShouldBeRestarted.calledWith(t.hosts, t.text)).to.equal(true);
  241. });
  242. });
  243. });
  244. describe("#rollingRestartStaleConfigSlaveComponents", function () {
  245. var tests = [
  246. {
  247. componentName: {
  248. context: "ComponentName"
  249. },
  250. displayName: "displayName",
  251. passiveState: "ON"
  252. },
  253. {
  254. componentName: {
  255. context: "ComponentName1"
  256. },
  257. displayName: "displayName1",
  258. passiveState: "OFF"
  259. }
  260. ];
  261. beforeEach(function () {
  262. mainServiceInfoConfigsController.set("content", {displayName: "", passiveState: ""});
  263. sinon.stub(batchUtils, "launchHostComponentRollingRestart", Em.K);
  264. });
  265. afterEach(function () {
  266. batchUtils.launchHostComponentRollingRestart.restore();
  267. });
  268. tests.forEach(function (t) {
  269. it("trigger rollingRestartStaleConfigSlaveComponents", function () {
  270. mainServiceInfoConfigsController.set("content.displayName", t.displayName);
  271. mainServiceInfoConfigsController.set("content.passiveState", t.passiveState);
  272. mainServiceInfoConfigsController.rollingRestartStaleConfigSlaveComponents(t.componentName);
  273. expect(batchUtils.launchHostComponentRollingRestart.calledWith(t.componentName.context, t.displayName, t.passiveState == "ON", true)).to.equal(true);
  274. });
  275. });
  276. });
  277. describe("#restartAllStaleConfigComponents", function () {
  278. beforeEach(function () {
  279. sinon.stub(batchUtils, "restartAllServiceHostComponents", Em.K);
  280. });
  281. afterEach(function () {
  282. batchUtils.restartAllServiceHostComponents.restore();
  283. });
  284. it("trigger restartAllServiceHostComponents", function () {
  285. mainServiceInfoConfigsController.restartAllStaleConfigComponents().onPrimary();
  286. expect(batchUtils.restartAllServiceHostComponents.calledOnce).to.equal(true);
  287. });
  288. });
  289. describe("#doCancel", function () {
  290. beforeEach(function () {
  291. sinon.stub(Em.run, 'once', Em.K);
  292. });
  293. afterEach(function () {
  294. Em.run.once.restore();
  295. });
  296. it("trigger onConfigGroupChange", function () {
  297. mainServiceInfoConfigsController.doCancel();
  298. expect(Em.run.once.calledWith(mainServiceInfoConfigsController, "onConfigGroupChange")).to.equal(true);
  299. });
  300. });
  301. describe("#getCurrentServiceComponents", function () {
  302. var t = Em.Object.create({
  303. content: Em.Object.create({
  304. hostComponents: [
  305. Em.Object.create({
  306. componentName: "componentName1",
  307. displayName: "displayName1"
  308. }),
  309. Em.Object.create({
  310. componentName: "componentName2",
  311. displayName: "displayName2"
  312. })
  313. ]
  314. }),
  315. validComponents: Em.A([
  316. Em.Object.create({
  317. componentName: "componentName1",
  318. displayName: "displayName1",
  319. selected: false
  320. }),
  321. Em.Object.create({
  322. componentName: "componentName2",
  323. displayName: "displayName2",
  324. selected: false
  325. })
  326. ])
  327. });
  328. beforeEach(function () {
  329. mainServiceInfoConfigsController.set("content", { hostComponents: Em.A([])});
  330. });
  331. it("get current service components", function () {
  332. mainServiceInfoConfigsController.get("content.hostComponents").push(t.content.hostComponents[0]);
  333. var com = mainServiceInfoConfigsController.get("getCurrentServiceComponents");
  334. expect(com[0]).to.eql(t.validComponents[0]);
  335. });
  336. });
  337. describe("#getMasterComponentHostValue", function () {
  338. var tests = [
  339. {
  340. content: {
  341. hostComponents: [
  342. Em.Object.create({
  343. componentName: "componentName1",
  344. hostName: "hostName"
  345. })
  346. ]
  347. },
  348. result: "hostName",
  349. multiple: false,
  350. m: "returns hostname"
  351. },
  352. {
  353. content: {
  354. hostComponents: [
  355. Em.Object.create({
  356. componentName: "componentName2",
  357. hostName: "hostName1"
  358. }),
  359. Em.Object.create({
  360. componentName: "componentName2",
  361. hostName: "hostName2"
  362. })
  363. ]
  364. },
  365. result: ["hostName1","hostName2"],
  366. multiple: true,
  367. m: "returns hostnames"
  368. }
  369. ];
  370. tests.forEach(function(t){
  371. beforeEach(function () {
  372. mainServiceInfoConfigsController.set("content", { hostComponents: []});
  373. });
  374. it(t.m, function () {
  375. mainServiceInfoConfigsController.set("content.hostComponents", t.content.hostComponents);
  376. expect(mainServiceInfoConfigsController.getMasterComponentHostValue(t.content.hostComponents[0].componentName, t.multiple)).to.eql(t.result);
  377. });
  378. });
  379. });
  380. describe("#setServerConfigValue", function () {
  381. it("parsing storm.zookeeper.servers property in non standart method", function () {
  382. expect(mainServiceInfoConfigsController.setServerConfigValue("storm.zookeeper.servers", ["a", "b"])).to.equal('[\'a\',\'b\']');
  383. });
  384. it("parsing default properties", function () {
  385. expect(mainServiceInfoConfigsController.setServerConfigValue("any.other.property", "value")).to.equal("value");
  386. });
  387. });
  388. describe("#createSiteObj", function () {
  389. var tests = [
  390. {
  391. siteName: "hdfs-site",
  392. tagName: "version1",
  393. siteObj: Em.A([
  394. {
  395. name: "property1",
  396. value: "value1"
  397. },
  398. {
  399. name: "property2",
  400. value: "value2<"
  401. },
  402. {
  403. name: "property_heapsize",
  404. value: "value3"
  405. },
  406. {
  407. name: "property_permsize",
  408. value: "value4m"
  409. }
  410. ]),
  411. result: {
  412. "type": "hdfs-site",
  413. "tag": "version1",
  414. "properties": {
  415. "property1": "value1",
  416. "property2": "value2<",
  417. "property_heapsize": "value3m",
  418. "property_permsize": "value4m"
  419. }
  420. },
  421. m: "default"
  422. },
  423. {
  424. siteName: "falcon-startup.properties",
  425. tagName: "version1",
  426. siteObj: Em.A([
  427. {
  428. name: "property1",
  429. value: "value1"
  430. },
  431. {
  432. name: "property2",
  433. value: "value2<"
  434. }
  435. ]),
  436. result: {
  437. "type": "falcon-startup.properties",
  438. "tag": "version1",
  439. "properties": {
  440. "property1": "value1",
  441. "property2": "value2<"
  442. }
  443. },
  444. m: "for falcon-startup.properties"
  445. }
  446. ];
  447. tests.forEach(function (t) {
  448. it("create site object " + t.m, function () {
  449. expect(mainServiceInfoConfigsController.createSiteObj(t.siteName, t.tagName, t.siteObj)).to.deep.eql(t.result)
  450. });
  451. });
  452. });
  453. describe("#createCoreSiteObj", function () {
  454. var tests = [
  455. {
  456. tagName: "version1",
  457. uiConfigs: Em.A([
  458. Em.Object.create({
  459. name: "property1",
  460. value: "value1",
  461. filename: "core-site.xml"
  462. }),
  463. Em.Object.create({
  464. name: "property2",
  465. value: "value2<",
  466. filename: "core-site.xml"
  467. })
  468. ]),
  469. result: {
  470. "type": "core-site",
  471. "tag": "version1",
  472. "properties": {
  473. "property1": "value1",
  474. "property2": "value2<"
  475. }
  476. }
  477. }
  478. ];
  479. tests.forEach(function (t) {
  480. it("create core object", function () {
  481. mainServiceInfoConfigsController.set("uiConfigs", t.uiConfigs);
  482. expect(mainServiceInfoConfigsController.createCoreSiteObj(t.tagName)).to.deep.eql(t.result);
  483. });
  484. });
  485. });
  486. describe("#doPUTClusterConfigurationSites", function () {
  487. var sc = [
  488. Em.Object.create({
  489. configs: [
  490. Em.Object.create({
  491. name: '_heapsize',
  492. value: '1024m'
  493. }),
  494. Em.Object.create({
  495. name: '_newsize',
  496. value: '1024m'
  497. }),
  498. Em.Object.create({
  499. name: '_maxnewsize',
  500. value: '1024m'
  501. })
  502. ]
  503. })
  504. ],
  505. scExc = [
  506. Em.Object.create({
  507. configs: [
  508. Em.Object.create({
  509. name: 'hadoop_heapsize',
  510. value: '1024m'
  511. }),
  512. Em.Object.create({
  513. name: 'yarn_heapsize',
  514. value: '1024m'
  515. }),
  516. Em.Object.create({
  517. name: 'nodemanager_heapsize',
  518. value: '1024m'
  519. }),
  520. Em.Object.create({
  521. name: 'resourcemanager_heapsize',
  522. value: '1024m'
  523. }),
  524. Em.Object.create({
  525. name: 'apptimelineserver_heapsize',
  526. value: '1024m'
  527. }),
  528. Em.Object.create({
  529. name: 'jobhistory_heapsize',
  530. value: '1024m'
  531. })
  532. ]
  533. })
  534. ];
  535. beforeEach(function () {
  536. sinon.stub(App.router, 'getClusterName', function() {
  537. return 'clName';
  538. });
  539. sinon.stub(App.ajax, "send", Em.K);
  540. });
  541. afterEach(function () {
  542. App.ajax.send.restore();
  543. App.router.getClusterName.restore();
  544. });
  545. it("ajax request to put clsuter cfg", function () {
  546. mainServiceInfoConfigsController.set('stepConfigs', sc);
  547. expect(mainServiceInfoConfigsController.doPUTClusterConfigurationSites([])).to.equal(mainServiceInfoConfigsController.get("doPUTClusterConfigurationSiteResult"));
  548. expect(App.ajax.send.calledOnce).to.be.true;
  549. });
  550. it('values should be parsed', function () {
  551. mainServiceInfoConfigsController.set('stepConfigs', sc);
  552. mainServiceInfoConfigsController.doPUTClusterConfigurationSites([]);
  553. expect(mainServiceInfoConfigsController.get('stepConfigs')[0].get('configs').mapProperty('value').uniq()).to.eql(['1024m']);
  554. });
  555. it('values should not be parsed', function () {
  556. mainServiceInfoConfigsController.set('stepConfigs', scExc);
  557. mainServiceInfoConfigsController.doPUTClusterConfigurationSites([]);
  558. expect(mainServiceInfoConfigsController.get('stepConfigs')[0].get('configs').mapProperty('value').uniq()).to.eql(['1024m']);
  559. });
  560. });
  561. describe("#isConfigChanged", function () {
  562. var tests = [
  563. {
  564. loadedConfig: {
  565. apptimelineserver_heapsize: "1024",
  566. hbase_log_dir: "/var/log/hbase",
  567. lzo_enabled: "true"
  568. },
  569. savingConfig: {
  570. apptimelineserver_heapsize: "1024",
  571. hbase_log_dir: "/var/log/hbase",
  572. lzo_enabled: "true"
  573. },
  574. m: "configs doesn't changed",
  575. res: false
  576. },
  577. {
  578. loadedConfig: {
  579. apptimelineserver_heapsize: "1024",
  580. hbase_log_dir: "/var/log/hbase",
  581. lzo_enabled: "true"
  582. },
  583. savingConfig: {
  584. apptimelineserver_heapsize: "1024",
  585. hbase_log_dir: "/var/log/hbase",
  586. lzo_enabled: "false"
  587. },
  588. m: "configs changed",
  589. res: true
  590. },
  591. {
  592. loadedConfig: {
  593. apptimelineserver_heapsize: "1024",
  594. hbase_log_dir: "/var/log/hbase"
  595. },
  596. savingConfig: {
  597. apptimelineserver_heapsize: "1024",
  598. hbase_log_dir: "/var/log/hbase",
  599. lzo_enabled: "false"
  600. },
  601. m: "add new config",
  602. res: true
  603. }
  604. ];
  605. tests.forEach(function(t){
  606. it(t.m, function () {
  607. expect(mainServiceInfoConfigsController.isConfigChanged(t.loadedConfig, t.savingConfig)).to.equal(t.res);
  608. });
  609. });
  610. });
  611. describe("#isDirChanged", function() {
  612. describe("when service name is HDFS", function() {
  613. beforeEach(function() {
  614. mainServiceInfoConfigsController.set('content', Ember.Object.create ({ serviceName: 'HDFS' }));
  615. });
  616. describe("when isHadoop2Stack is true", function() {
  617. var tests = [
  618. {
  619. it: "should set dirChanged to false if none of the properties exist",
  620. expect: false,
  621. config: Ember.Object.create ({})
  622. },
  623. {
  624. it: "should set dirChanged to true if dfs.namenode.name.dir is not default",
  625. expect: true,
  626. config: Ember.Object.create ({
  627. name: 'dfs.namenode.name.dir',
  628. isNotDefaultValue: true
  629. })
  630. },
  631. {
  632. it: "should set dirChanged to false if dfs.namenode.name.dir is default",
  633. expect: false,
  634. config: Ember.Object.create ({
  635. name: 'dfs.namenode.name.dir',
  636. isNotDefaultValue: false
  637. })
  638. },
  639. {
  640. it: "should set dirChanged to true if dfs.namenode.checkpoint.dir is not default",
  641. expect: true,
  642. config: Ember.Object.create ({
  643. name: 'dfs.namenode.checkpoint.dir',
  644. isNotDefaultValue: true
  645. })
  646. },
  647. {
  648. it: "should set dirChanged to false if dfs.namenode.checkpoint.dir is default",
  649. expect: false,
  650. config: Ember.Object.create ({
  651. name: 'dfs.namenode.checkpoint.dir',
  652. isNotDefaultValue: false
  653. })
  654. },
  655. {
  656. it: "should set dirChanged to true if dfs.datanode.data.dir is not default",
  657. expect: true,
  658. config: Ember.Object.create ({
  659. name: 'dfs.datanode.data.dir',
  660. isNotDefaultValue: true
  661. })
  662. },
  663. {
  664. it: "should set dirChanged to false if dfs.datanode.data.dir is default",
  665. expect: false,
  666. config: Ember.Object.create ({
  667. name: 'dfs.datanode.data.dir',
  668. isNotDefaultValue: false
  669. })
  670. }
  671. ];
  672. beforeEach(function() {
  673. sinon.stub(App, 'get').returns(true);
  674. });
  675. afterEach(function() {
  676. App.get.restore();
  677. });
  678. tests.forEach(function(test) {
  679. it(test.it, function() {
  680. mainServiceInfoConfigsController.set('stepConfigs', [Ember.Object.create ({ configs: [test.config], serviceName: 'HDFS' })]);
  681. expect(mainServiceInfoConfigsController.isDirChanged()).to.equal(test.expect);
  682. })
  683. });
  684. });
  685. describe("when isHadoop2Stack is false", function() {
  686. var tests = [
  687. {
  688. it: "should set dirChanged to false if none of the properties exist",
  689. expect: false,
  690. config: Ember.Object.create ({})
  691. },
  692. {
  693. it: "should set dirChanged to true if dfs.name.dir is not default",
  694. expect: true,
  695. config: Ember.Object.create ({
  696. name: 'dfs.name.dir',
  697. isNotDefaultValue: true
  698. })
  699. },
  700. {
  701. it: "should set dirChanged to false if dfs.name.dir is default",
  702. expect: false,
  703. config: Ember.Object.create ({
  704. name: 'dfs.name.dir',
  705. isNotDefaultValue: false
  706. })
  707. },
  708. {
  709. it: "should set dirChanged to true if fs.checkpoint.dir is not default",
  710. expect: true,
  711. config: Ember.Object.create ({
  712. name: 'fs.checkpoint.dir',
  713. isNotDefaultValue: true
  714. })
  715. },
  716. {
  717. it: "should set dirChanged to false if fs.checkpoint.dir is default",
  718. expect: false,
  719. config: Ember.Object.create ({
  720. name: 'fs.checkpoint.dir',
  721. isNotDefaultValue: false
  722. })
  723. },
  724. {
  725. it: "should set dirChanged to true if dfs.data.dir is not default",
  726. expect: true,
  727. config: Ember.Object.create ({
  728. name: 'dfs.data.dir',
  729. isNotDefaultValue: true
  730. })
  731. },
  732. {
  733. it: "should set dirChanged to false if dfs.data.dir is default",
  734. expect: false,
  735. config: Ember.Object.create ({
  736. name: 'dfs.data.dir',
  737. isNotDefaultValue: false
  738. })
  739. }
  740. ];
  741. beforeEach(function() {
  742. sinon.stub(App, 'get').returns(false);
  743. });
  744. afterEach(function() {
  745. App.get.restore();
  746. });
  747. tests.forEach(function(test) {
  748. it(test.it, function() {
  749. mainServiceInfoConfigsController.set('stepConfigs', [Ember.Object.create ({ configs: [test.config], serviceName: 'HDFS' })]);
  750. expect(mainServiceInfoConfigsController.isDirChanged()).to.equal(test.expect);
  751. })
  752. });
  753. });
  754. });
  755. describe("when service name is MAPREDUCE", function() {
  756. beforeEach(function() {
  757. mainServiceInfoConfigsController.set('content', Ember.Object.create ({ serviceName: 'MAPREDUCE' }));
  758. });
  759. var tests = [
  760. {
  761. it: "should set dirChanged to false if none of the properties exist",
  762. expect: false,
  763. config: Ember.Object.create ({})
  764. },
  765. {
  766. it: "should set dirChanged to true if mapred.local.dir is not default",
  767. expect: true,
  768. config: Ember.Object.create ({
  769. name: 'mapred.local.dir',
  770. isNotDefaultValue: true
  771. })
  772. },
  773. {
  774. it: "should set dirChanged to false if mapred.local.dir is default",
  775. expect: false,
  776. config: Ember.Object.create ({
  777. name: 'mapred.local.dir',
  778. isNotDefaultValue: false
  779. })
  780. },
  781. {
  782. it: "should set dirChanged to true if mapred.system.dir is not default",
  783. expect: true,
  784. config: Ember.Object.create ({
  785. name: 'mapred.system.dir',
  786. isNotDefaultValue: true
  787. })
  788. },
  789. {
  790. it: "should set dirChanged to false if mapred.system.dir is default",
  791. expect: false,
  792. config: Ember.Object.create ({
  793. name: 'mapred.system.dir',
  794. isNotDefaultValue: false
  795. })
  796. }
  797. ];
  798. tests.forEach(function(test) {
  799. it(test.it, function() {
  800. mainServiceInfoConfigsController.set('stepConfigs', [Ember.Object.create ({ configs: [test.config], serviceName: 'MAPREDUCE' })]);
  801. expect(mainServiceInfoConfigsController.isDirChanged()).to.equal(test.expect);
  802. })
  803. });
  804. });
  805. });
  806. describe("#addDynamicProperties", function() {
  807. var tests = [
  808. {
  809. stepConfigs: [Em.Object.create({
  810. serviceName: "HIVE",
  811. configs: []
  812. })],
  813. content: Em.Object.create({
  814. serviceName: "HIVE"
  815. }),
  816. m: "add dynamic property",
  817. addDynamic: true
  818. },
  819. {
  820. stepConfigs: [Em.Object.create({
  821. serviceName: "HIVE",
  822. configs: [
  823. Em.Object.create({
  824. name: "templeton.hive.properties"
  825. })
  826. ]
  827. })],
  828. content: Em.Object.create({
  829. serviceName: "HIVE"
  830. }),
  831. m: "don't add dynamic property (already included)",
  832. addDynamic: false
  833. },
  834. {
  835. stepConfigs: [Em.Object.create({
  836. serviceName: "HDFS",
  837. configs: []
  838. })],
  839. content: Em.Object.create({
  840. serviceName: "HDFS"
  841. }),
  842. m: "don't add dynamic property (wrong service)",
  843. addDynamic: false
  844. }
  845. ];
  846. var dynamicProperty = {
  847. "name": "templeton.hive.properties",
  848. "templateName": ["hivemetastore_host"],
  849. "foreignKey": null,
  850. "value": "hive.metastore.local=false,hive.metastore.uris=thrift://<templateName[0]>:9083,hive.metastore.sasl.enabled=yes,hive.metastore.execute.setugi=true,hive.metastore.warehouse.dir=/apps/hive/warehouse",
  851. "filename": "webhcat-site.xml"
  852. };
  853. tests.forEach(function(t) {
  854. it(t.m, function() {
  855. mainServiceInfoConfigsController.set("content", t.content);
  856. mainServiceInfoConfigsController.set("stepConfigs", t.stepConfigs);
  857. var configs = [];
  858. mainServiceInfoConfigsController.addDynamicProperties(configs);
  859. if (t.addDynamic){
  860. expect(configs.findProperty("name","templeton.hive.properties")).to.deep.eql(dynamicProperty);
  861. }
  862. });
  863. });
  864. });
  865. describe("#loadUiSideConfigs", function () {
  866. var t = {
  867. configMapping: [
  868. {
  869. foreignKey: null,
  870. templateName: "",
  871. value: "default",
  872. name: "name1",
  873. filename: "filename1"
  874. },
  875. {
  876. foreignKey: "notNull",
  877. templateName: "",
  878. value: "default2",
  879. name: "name2",
  880. filename: "filename2"
  881. }
  882. ],
  883. configMappingf: [
  884. {
  885. foreignKey: null,
  886. templateName: "",
  887. value: "default",
  888. name: "name1",
  889. filename: "filename1"
  890. }
  891. ],
  892. valueWithOverrides: {
  893. "value": "default",
  894. "overrides": {
  895. "value1": "value1",
  896. "value2": "value2"
  897. }
  898. },
  899. uiConfigs: [
  900. {
  901. "id": "site property",
  902. "name": "name1",
  903. "value": "default",
  904. "filename": "filename1",
  905. "overrides": {
  906. "value1": "value1",
  907. "value2": "value2"
  908. }
  909. }
  910. ]
  911. };
  912. beforeEach(function(){
  913. sinon.stub(mainServiceInfoConfigsController, "addDynamicProperties", Em.K);
  914. sinon.stub(mainServiceInfoConfigsController, "getGlobConfigValueWithOverrides", function () {
  915. return t.valueWithOverrides
  916. });
  917. });
  918. afterEach(function(){
  919. mainServiceInfoConfigsController.addDynamicProperties.restore();
  920. mainServiceInfoConfigsController.getGlobConfigValueWithOverrides.restore();
  921. });
  922. it("load ui config", function() {
  923. expect(mainServiceInfoConfigsController.loadUiSideConfigs(t.configMapping)[0]).to.deep.equal(t.uiConfigs[0]);
  924. expect(mainServiceInfoConfigsController.addDynamicProperties.calledWith(t.configMappingf)).to.equal(true);
  925. });
  926. });
  927. describe("#formatConfigValues", function () {
  928. var t = {
  929. configs: [
  930. Em.Object.create({ name: "p1", value: " v1 v1 ", displayType: "" }),
  931. Em.Object.create({ name: "p2", value: true, displayType: "" }),
  932. Em.Object.create({ name: "p3", value: " d1 ", displayType: "directory" }),
  933. Em.Object.create({ name: "p4", value: " d1 d2 d3 ", displayType: "directories" }),
  934. Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
  935. Em.Object.create({ name: "p6", value: " v ", displayType: "host" }),
  936. Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1 ", displayType: "advanced" }),
  937. Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1 ", displayType: "advanced" })
  938. ],
  939. result: [
  940. Em.Object.create({ name: "p1", value: " v1 v1", displayType: "" }),
  941. Em.Object.create({ name: "p2", value: "true", displayType: "" }),
  942. Em.Object.create({ name: "p3", value: "d1", displayType: "directory" }),
  943. Em.Object.create({ name: "p4", value: "d1,d2,d3", displayType: "directories" }),
  944. Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
  945. Em.Object.create({ name: "p6", value: "v", displayType: "host" }),
  946. Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1", displayType: "advanced" }),
  947. Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1", displayType: "advanced" })
  948. ]
  949. };
  950. it("format config values", function () {
  951. mainServiceInfoConfigsController.formatConfigValues(t.configs);
  952. expect(t.configs).to.deep.equal(t.result);
  953. });
  954. });
  955. describe("#createConfigObject", function() {
  956. var tests = [
  957. {
  958. siteName: "core-site",
  959. serviceName: "HDFS",
  960. method: "createCoreSiteObj"
  961. },
  962. {
  963. siteName: "core-site",
  964. serviceName: "ANY",
  965. method: false
  966. },
  967. {
  968. siteName: "any",
  969. method: "createSiteObj"
  970. },
  971. {
  972. siteName: "mapred-queue-acls",
  973. method: false
  974. }
  975. ];
  976. beforeEach(function() {
  977. sinon.stub(mainServiceInfoConfigsController, "createCoreSiteObj", Em.K);
  978. sinon.stub(mainServiceInfoConfigsController, "createSiteObj", Em.K);
  979. mainServiceInfoConfigsController.set("content", {});
  980. });
  981. afterEach(function() {
  982. mainServiceInfoConfigsController.createCoreSiteObj.restore();
  983. mainServiceInfoConfigsController.createSiteObj.restore();
  984. });
  985. tests.forEach(function(t) {
  986. it("create object for " + t.siteName + " run method " + t.method, function() {
  987. mainServiceInfoConfigsController.set("content.serviceName", t.serviceName);
  988. mainServiceInfoConfigsController.createConfigObject(t.siteName, "versrion1");
  989. if (t.method) {
  990. expect(mainServiceInfoConfigsController[t.method].calledOnce).to.equal(true);
  991. } else {
  992. expect(mainServiceInfoConfigsController["createCoreSiteObj"].calledOnce).to.equal(false);
  993. expect(mainServiceInfoConfigsController["createSiteObj"].calledOnce).to.equal(false);
  994. }
  995. });
  996. });
  997. });
  998. describe("#putConfigGroupChanges", function() {
  999. var t = {
  1000. data: {
  1001. ConfigGroup: {
  1002. id: "id"
  1003. }
  1004. },
  1005. request: [{
  1006. ConfigGroup: {
  1007. id: "id"
  1008. }
  1009. }]
  1010. };
  1011. beforeEach(function() {
  1012. sinon.spy($,"ajax");
  1013. });
  1014. afterEach(function() {
  1015. $.ajax.restore();
  1016. });
  1017. it("updates configs groups", function() {
  1018. mainServiceInfoConfigsController.putConfigGroupChanges(t.data);
  1019. expect(JSON.parse($.ajax.args[0][0].data)).to.deep.equal(t.request);
  1020. });
  1021. });
  1022. describe("#setValueForCheckBox", function() {
  1023. var tests = [
  1024. {
  1025. serviceConfigPropertyInput: Em.Object.create({
  1026. value: "true",
  1027. defaultValue: "true",
  1028. displayType: 'checkbox'
  1029. }),
  1030. serviceConfigProperty: Em.Object.create({
  1031. value: true,
  1032. defaultValue: true,
  1033. displayType: 'checkbox'
  1034. })
  1035. },
  1036. {
  1037. serviceConfigPropertyInput: Em.Object.create({
  1038. value: "false",
  1039. defaultValue: "false",
  1040. displayType: 'checkbox'
  1041. }),
  1042. serviceConfigProperty: Em.Object.create({
  1043. value: false,
  1044. defaultValue: false,
  1045. displayType: 'checkbox'
  1046. })
  1047. },
  1048. {
  1049. serviceConfigPropertyInput: Em.Object.create({
  1050. value: "false",
  1051. defaultValue: "false"
  1052. }),
  1053. serviceConfigProperty: Em.Object.create({
  1054. value: "false",
  1055. defaultValue: "false"
  1056. })
  1057. }
  1058. ];
  1059. tests.forEach(function(t) {
  1060. it("set " + t.serviceConfigPropertyInput.value, function(){
  1061. var serviceConfigProperty = t.serviceConfigPropertyInput;
  1062. mainServiceInfoConfigsController.setValueForCheckBox(serviceConfigProperty);
  1063. expect(serviceConfigProperty).to.eql(t.serviceConfigProperty);
  1064. });
  1065. });
  1066. });
  1067. describe("#setEditability", function () {
  1068. var tests = [
  1069. {
  1070. isAdmin: true,
  1071. isHostsConfigsPage: false,
  1072. defaultGroupSelected: true,
  1073. isReconfigurable: true,
  1074. isEditable: true,
  1075. m: ""
  1076. },
  1077. {
  1078. isAdmin: false,
  1079. isHostsConfigsPage: false,
  1080. defaultGroupSelected: true,
  1081. isReconfigurable: true,
  1082. isEditable: false,
  1083. m: "(non admin)"
  1084. },
  1085. {
  1086. isAdmin: true,
  1087. isHostsConfigsPage: true,
  1088. defaultGroupSelected: true,
  1089. isReconfigurable: true,
  1090. isEditable: false,
  1091. m: "(isHostsConfigsPage)"
  1092. },
  1093. {
  1094. isAdmin: true,
  1095. isHostsConfigsPage: false,
  1096. defaultGroupSelected: false,
  1097. isReconfigurable: true,
  1098. isEditable: false,
  1099. m: "(defaultGroupSelected is false)"
  1100. },
  1101. {
  1102. isAdmin: true,
  1103. isHostsConfigsPage: false,
  1104. defaultGroupSelected: true,
  1105. isReconfigurable: false,
  1106. isEditable: false,
  1107. m: "(isReconfigurable is false)"
  1108. }
  1109. ];
  1110. var a = App.get('isAdmin');
  1111. afterEach(function () {
  1112. App.set('isAdmin', a);
  1113. });
  1114. tests.forEach(function(t) {
  1115. it("set isEditable " + t.isEditable + t.m, function(){
  1116. App.set('isAdmin', t.isAdmin);
  1117. mainServiceInfoConfigsController.set("isHostsConfigsPage", t.isHostsConfigsPage);
  1118. var serviceConfigProperty = Em.Object.create({
  1119. isReconfigurable: t.isReconfigurable
  1120. });
  1121. mainServiceInfoConfigsController.setEditability(serviceConfigProperty, t.defaultGroupSelected);
  1122. expect(serviceConfigProperty.get("isEditable")).to.equal(t.isEditable);
  1123. });
  1124. });
  1125. });
  1126. describe("#checkOverrideProperty", function () {
  1127. var tests = [{
  1128. overrideToAdd: {
  1129. name: "name1",
  1130. filename: "filename1"
  1131. },
  1132. componentConfig: {
  1133. configs: [
  1134. {
  1135. name: "name1",
  1136. filename: "filename2"
  1137. },
  1138. {
  1139. name: "name1",
  1140. filename: "filename1"
  1141. }
  1142. ]
  1143. },
  1144. add: true,
  1145. m: "add property"
  1146. },
  1147. {
  1148. overrideToAdd: {
  1149. name: "name1"
  1150. },
  1151. componentConfig: {
  1152. configs: [
  1153. {
  1154. name: "name2"
  1155. }
  1156. ]
  1157. },
  1158. add: false,
  1159. m: "don't add property, different names"
  1160. },
  1161. {
  1162. overrideToAdd: {
  1163. name: "name1",
  1164. filename: "filename1"
  1165. },
  1166. componentConfig: {
  1167. configs: [
  1168. {
  1169. name: "name1",
  1170. filename: "filename2"
  1171. }
  1172. ]
  1173. },
  1174. add: false,
  1175. m: "don't add property, different filenames"
  1176. },
  1177. {
  1178. overrideToAdd: null,
  1179. componentConfig: {},
  1180. add: false,
  1181. m: "don't add property, overrideToAdd is null"
  1182. }];
  1183. beforeEach(function() {
  1184. sinon.stub(mainServiceInfoConfigsController,"addOverrideProperty", Em.K)
  1185. });
  1186. afterEach(function() {
  1187. mainServiceInfoConfigsController.addOverrideProperty.restore();
  1188. });
  1189. tests.forEach(function(t) {
  1190. it(t.m, function() {
  1191. mainServiceInfoConfigsController.set("overrideToAdd", t.overrideToAdd);
  1192. mainServiceInfoConfigsController.checkOverrideProperty(t.componentConfig);
  1193. if(t.add) {
  1194. expect(mainServiceInfoConfigsController.addOverrideProperty.calledWith(t.overrideToAdd)).to.equal(true);
  1195. expect(mainServiceInfoConfigsController.get("overrideToAdd")).to.equal(null);
  1196. } else {
  1197. expect(mainServiceInfoConfigsController.addOverrideProperty.calledOnce).to.equal(false);
  1198. }
  1199. });
  1200. });
  1201. });
  1202. describe("#trackRequest()", function () {
  1203. after(function(){
  1204. mainServiceInfoConfigsController.set('requestInProgress', null);
  1205. });
  1206. it("should set requestInProgress", function () {
  1207. mainServiceInfoConfigsController.trackRequest({'request': {}});
  1208. expect(mainServiceInfoConfigsController.get('requestInProgress')).to.eql({'request': {}});
  1209. });
  1210. });
  1211. describe("#setValuesForOverrides", function() {
  1212. var tests = [
  1213. {
  1214. overrides: [
  1215. {name: "override1"},
  1216. {name: "override2"}
  1217. ],
  1218. _serviceConfigProperty: {},
  1219. serviceConfigProperty: Em.Object.create({overrides: Em.A([])}),
  1220. defaultGroupSelected: true
  1221. }
  1222. ];
  1223. beforeEach(function() {
  1224. sinon.stub(mainServiceInfoConfigsController, "createNewSCP", function(override) {return {name: override.name}})
  1225. });
  1226. afterEach(function() {
  1227. mainServiceInfoConfigsController.createNewSCP.restore();
  1228. });
  1229. tests.forEach(function(t) {
  1230. it("set values for overrides. use createNewSCP method to do this", function() {
  1231. var serviceConfigProperty = t.serviceConfigProperty;
  1232. mainServiceInfoConfigsController.setValuesForOverrides(t.overrides, serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected);
  1233. expect(serviceConfigProperty.get("overrides")[0]).to.eql(t.overrides[0]);
  1234. expect(serviceConfigProperty.get("overrides")[1]).to.eql(t.overrides[1]);
  1235. });
  1236. });
  1237. });
  1238. describe("#createConfigProperty", function() {
  1239. var tests = [
  1240. {
  1241. _serviceConfigProperty: {
  1242. overrides: {
  1243. }
  1244. },
  1245. defaultGroupSelected: true,
  1246. restartData: {},
  1247. serviceConfigsData: {},
  1248. serviceConfigProperty: {
  1249. overrides: null,
  1250. isOverridable: true
  1251. }
  1252. }];
  1253. beforeEach(function() {
  1254. sinon.stub(mainServiceInfoConfigsController, "setValueForCheckBox", Em.K);
  1255. sinon.stub(mainServiceInfoConfigsController, "setValuesForOverrides", Em.K);
  1256. sinon.stub(mainServiceInfoConfigsController, "setEditability", Em.K);
  1257. });
  1258. afterEach(function() {
  1259. mainServiceInfoConfigsController.setValueForCheckBox.restore();
  1260. mainServiceInfoConfigsController.setValuesForOverrides.restore();
  1261. mainServiceInfoConfigsController.setEditability.restore();
  1262. });
  1263. tests.forEach(function(t) {
  1264. it("create service config. run methods to correctly set object fileds", function() {
  1265. var result = mainServiceInfoConfigsController.createConfigProperty(t._serviceConfigProperty, t.defaultGroupSelected, t.restartData, t.serviceConfigsData);
  1266. expect(mainServiceInfoConfigsController.setValueForCheckBox.calledWith(t.serviceConfigProperty));
  1267. expect(mainServiceInfoConfigsController.setValuesForOverrides.calledWith(t._serviceConfigProperty.overrides, t._serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected));
  1268. expect(result.getProperties('overrides','isOverridable')).to.eql(t.serviceConfigProperty);
  1269. });
  1270. });
  1271. });
  1272. describe("#createNewSCP", function() {
  1273. var tests = [
  1274. {
  1275. overrides: {
  1276. value: "value",
  1277. group: {
  1278. value: "group1"
  1279. }
  1280. },
  1281. _serviceConfigProperty: {},
  1282. serviceConfigProperty: Em.Object.create({
  1283. value: "parentSCP",
  1284. supportsFinal: true
  1285. }),
  1286. defaultGroupSelected: true,
  1287. newSCP: {
  1288. value: "value",
  1289. isOriginalSCP: false,
  1290. parentSCP:Em.Object.create({
  1291. value: "parentSCP",
  1292. supportsFinal: true
  1293. }),
  1294. group: {
  1295. value: "group1"
  1296. },
  1297. isEditable: false
  1298. }
  1299. }
  1300. ];
  1301. tests.forEach(function(t) {
  1302. it("", function() {
  1303. var newSCP = mainServiceInfoConfigsController.createNewSCP(t.overrides, t._serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected);
  1304. expect(newSCP.getProperties("value", "isOriginalSCP", "parentSCP", "group", "isEditable")).to.eql(t.newSCP);
  1305. });
  1306. });
  1307. });
  1308. describe("#setCompareDefaultGroupConfig", function() {
  1309. beforeEach(function() {
  1310. sinon.stub(mainServiceInfoConfigsController, "getComparisonConfig").returns("compConfig");
  1311. sinon.stub(mainServiceInfoConfigsController, "getMockComparisonConfig").returns("mockConfig");
  1312. sinon.stub(mainServiceInfoConfigsController, "hasCompareDiffs").returns(true);
  1313. });
  1314. afterEach(function() {
  1315. mainServiceInfoConfigsController.getComparisonConfig.restore();
  1316. mainServiceInfoConfigsController.getMockComparisonConfig.restore();
  1317. mainServiceInfoConfigsController.hasCompareDiffs.restore();
  1318. });
  1319. it("expect that setCompareDefaultGroupConfig will not run anything", function() {
  1320. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({}).compareConfigs.length).to.equal(0);
  1321. });
  1322. it("expect that setCompareDefaultGroupConfig will not run anything", function() {
  1323. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({},{}).compareConfigs.length).to.equal(0);
  1324. });
  1325. it("expect that serviceConfig.compareConfigs will be getMockComparisonConfig", function() {
  1326. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isUserProperty: true}, null)).to.eql({compareConfigs: ["mockConfig"], isUserProperty: true, isComparison: true, hasCompareDiffs: true});
  1327. });
  1328. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  1329. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isUserProperty: true}, {})).to.eql({compareConfigs: ["compConfig"], isUserProperty: true, isComparison: true, hasCompareDiffs: true});
  1330. });
  1331. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  1332. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isReconfigurable: true}, {})).to.eql({compareConfigs: ["compConfig"], isReconfigurable: true, isComparison: true, hasCompareDiffs: true});
  1333. });
  1334. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  1335. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isReconfigurable: true, isMock: true}, {})).to.eql({compareConfigs: ["compConfig"], isReconfigurable: true, isMock: true, isComparison: true, hasCompareDiffs: true});
  1336. });
  1337. });
  1338. describe('#showSaveConfigsPopup', function () {
  1339. var bodyView;
  1340. describe('#bodyClass', function () {
  1341. beforeEach(function() {
  1342. sinon.stub(App.ajax, 'send', Em.K);
  1343. // default implementation
  1344. bodyView = mainServiceInfoConfigsController.showSaveConfigsPopup().get('bodyClass').create({
  1345. parentView: Em.View.create()
  1346. });
  1347. });
  1348. afterEach(function() {
  1349. App.ajax.send.restore();
  1350. });
  1351. describe('#componentsFilterSuccessCallback', function () {
  1352. it('check components with unknown state', function () {
  1353. bodyView = mainServiceInfoConfigsController.showSaveConfigsPopup('', true, '', {}, '', 'unknown', '').get('bodyClass').create({
  1354. parentView: Em.View.create()
  1355. });
  1356. bodyView.componentsFilterSuccessCallback({
  1357. items: [
  1358. {
  1359. ServiceComponentInfo: {
  1360. total_count: 4,
  1361. started_count: 2,
  1362. installed_count: 1,
  1363. component_name: 'c1'
  1364. },
  1365. host_components: [
  1366. {HostRoles: {host_name: 'h1'}}
  1367. ]
  1368. }
  1369. ]
  1370. });
  1371. var unknownHosts = bodyView.get('unknownHosts');
  1372. expect(unknownHosts.length).to.equal(1);
  1373. expect(unknownHosts[0]).to.eql({name: 'h1', components: 'C1'});
  1374. });
  1375. });
  1376. });
  1377. });
  1378. });