config_test.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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. event: false,
  31. action: "onSave",
  32. m: "save configs without path/event",
  33. results: [
  34. {
  35. method: "restartServicePopup",
  36. called: true
  37. },
  38. {
  39. method: "selectConfigGroup",
  40. called: false
  41. }
  42. ]
  43. },
  44. {
  45. path: true,
  46. event: true,
  47. action: "onSave",
  48. m: "save configs with path/event",
  49. results: [
  50. {
  51. method: "restartServicePopup",
  52. called: true
  53. },
  54. {
  55. method: "selectConfigGroup",
  56. called: false
  57. }
  58. ]
  59. },
  60. {
  61. path: false,
  62. event: false,
  63. action: "onDiscard",
  64. m: "discard changes without path/event",
  65. results: [
  66. {
  67. method: "restartServicePopup",
  68. called: false
  69. },
  70. {
  71. method: "selectConfigGroup",
  72. called: false
  73. }
  74. ]
  75. },
  76. {
  77. path: false,
  78. event: true,
  79. action: "onDiscard",
  80. m: "discard changes with event",
  81. results: [
  82. {
  83. method: "restartServicePopup",
  84. called: false
  85. },
  86. {
  87. method: "selectConfigGroup",
  88. called: true
  89. },
  90. {
  91. field: "hash",
  92. value: "hash"
  93. }
  94. ]
  95. },
  96. {
  97. path: true,
  98. event: false,
  99. action: "onDiscard",
  100. m: "discard changes with path",
  101. results: [
  102. {
  103. method: "restartServicePopup",
  104. called: false
  105. },
  106. {
  107. method: "selectConfigGroup",
  108. called: false
  109. },
  110. {
  111. field: "forceTransition",
  112. value: true
  113. }
  114. ]
  115. }
  116. ];
  117. beforeEach(function () {
  118. sinon.stub(mainServiceInfoConfigsController, "restartServicePopup", Em.K);
  119. sinon.stub(mainServiceInfoConfigsController, "selectConfigGroup", Em.K);
  120. sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
  121. return "hash"
  122. });
  123. App.router.route = Em.K;
  124. });
  125. afterEach(function () {
  126. mainServiceInfoConfigsController.restartServicePopup.restore();
  127. mainServiceInfoConfigsController.selectConfigGroup.restore();
  128. mainServiceInfoConfigsController.getHash.restore();
  129. });
  130. tests.forEach(function (t) {
  131. t.results.forEach(function (r) {
  132. it(t.m + " " + r.method + " " + r.field, function () {
  133. mainServiceInfoConfigsController.showSavePopup(t.path, t.event)[t.action]();
  134. if (r.method) {
  135. expect(mainServiceInfoConfigsController[r.method].calledOnce).to.equal(r.called);
  136. } else if (r.field) {
  137. expect(mainServiceInfoConfigsController.get(r.field)).to.equal(r.value);
  138. }
  139. }, this);
  140. });
  141. }, this);
  142. });
  143. describe("#hasUnsavedChanges", function () {
  144. beforeEach(function () {
  145. sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
  146. return "hash"
  147. });
  148. });
  149. afterEach(function () {
  150. mainServiceInfoConfigsController.getHash.restore();
  151. });
  152. it("with unsaved", function () {
  153. mainServiceInfoConfigsController.set("hash", "hash1");
  154. expect(mainServiceInfoConfigsController.hasUnsavedChanges()).to.equal(true);
  155. });
  156. it("without unsaved", function () {
  157. mainServiceInfoConfigsController.set("hash", "hash");
  158. expect(mainServiceInfoConfigsController.hasUnsavedChanges()).to.equal(false);
  159. });
  160. });
  161. describe("#selectConfigGroup", function () {
  162. var tests = [
  163. {
  164. event: {
  165. context: "cfgGroup"
  166. },
  167. isInit: true,
  168. showPopup: false,
  169. m: "setup new cfg group"
  170. },
  171. {
  172. event: {
  173. context: "cfgGroup"
  174. },
  175. isInit: false,
  176. hash: "hash",
  177. showPopup: false,
  178. m: "setup new cfg group, has some changes"
  179. },
  180. {
  181. event: {
  182. context: "cfgGroup"
  183. },
  184. isInit: false,
  185. hash: "hash1",
  186. showPopup: true,
  187. m: "show popup, doesn't setup new cfg group"
  188. }
  189. ];
  190. beforeEach(function () {
  191. sinon.stub(mainServiceInfoConfigsController, "showSavePopup", Em.K);
  192. sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
  193. return "hash"
  194. });
  195. sinon.stub(mainServiceInfoConfigsController, "onConfigGroupChange", Em.K);
  196. });
  197. afterEach(function () {
  198. mainServiceInfoConfigsController.showSavePopup.restore();
  199. mainServiceInfoConfigsController.getHash.restore();
  200. mainServiceInfoConfigsController.onConfigGroupChange.restore();
  201. });
  202. tests.forEach(function (t) {
  203. it(t.m, function () {
  204. mainServiceInfoConfigsController.set("isInit", t.isInit);
  205. mainServiceInfoConfigsController.set("hash", t.hash);
  206. mainServiceInfoConfigsController.selectConfigGroup(t.event);
  207. if (!t.showPopup) {
  208. expect(mainServiceInfoConfigsController.get("selectedConfigGroup")).to.equal(t.event.context);
  209. expect(mainServiceInfoConfigsController.showSavePopup.calledOnce).to.equal(false);
  210. } else {
  211. expect(mainServiceInfoConfigsController.showSavePopup.calledWith(null, t.event)).to.equal(true);
  212. }
  213. });
  214. });
  215. });
  216. describe("#manageConfigurationGroup", function () {
  217. beforeEach(function () {
  218. sinon.stub(mainServiceInfoConfigsController, "manageConfigurationGroups", Em.K);
  219. });
  220. afterEach(function () {
  221. mainServiceInfoConfigsController.manageConfigurationGroups.restore();
  222. });
  223. it("run manageConfigurationGroups", function () {
  224. mainServiceInfoConfigsController.manageConfigurationGroup();
  225. expect(mainServiceInfoConfigsController.manageConfigurationGroups.calledOnce).to.equal(true);
  226. });
  227. });
  228. describe("#addOverrideProperty", function () {
  229. var serviceConfigProperty = Em.Object.create({
  230. overrides: []
  231. });
  232. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  233. newSCP.set('value', '');
  234. newSCP.set('isOriginalSCP', false);
  235. newSCP.set('parentSCP', serviceConfigProperty);
  236. newSCP.set('isEditable', true);
  237. it("add new overridden property", function () {
  238. mainServiceInfoConfigsController.addOverrideProperty(serviceConfigProperty);
  239. expect(serviceConfigProperty.get("overrides")[0]).to.eql(newSCP);
  240. });
  241. });
  242. describe("#showComponentsShouldBeRestarted", function () {
  243. var tests = [
  244. {
  245. input: {
  246. 'publicHostName1': ['TaskTracker'],
  247. 'publicHostName2': ['JobTracker', 'TaskTracker']
  248. },
  249. components: "2 TaskTrackers, 1 JobTracker",
  250. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.components'))
  251. },
  252. {
  253. input: {
  254. 'publicHostName1': ['TaskTracker']
  255. },
  256. components: "1 TaskTracker",
  257. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.component'))
  258. }
  259. ];
  260. beforeEach(function () {
  261. sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
  262. mainServiceInfoConfigsController.set("content", {restartRequiredHostsAndComponents: ""});
  263. });
  264. afterEach(function () {
  265. mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
  266. mainServiceInfoConfigsController.set("content", undefined);
  267. });
  268. tests.forEach(function (t) {
  269. it("trigger showItemsShouldBeRestarted popup with components", function () {
  270. mainServiceInfoConfigsController.set("content.restartRequiredHostsAndComponents", t.input);
  271. mainServiceInfoConfigsController.showComponentsShouldBeRestarted();
  272. expect(mainServiceInfoConfigsController.showItemsShouldBeRestarted.calledWith(t.components, t.text)).to.equal(true);
  273. });
  274. });
  275. });
  276. describe("#showHostsShouldBeRestarted", function () {
  277. var tests = [
  278. {
  279. input: {
  280. 'publicHostName1': ['TaskTracker'],
  281. 'publicHostName2': ['JobTracker', 'TaskTracker']
  282. },
  283. hosts: "publicHostName1, publicHostName2",
  284. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.hosts'))
  285. },
  286. {
  287. input: {
  288. 'publicHostName1': ['TaskTracker']
  289. },
  290. hosts: "publicHostName1",
  291. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.host'))
  292. }
  293. ];
  294. beforeEach(function () {
  295. sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
  296. mainServiceInfoConfigsController.set("content", {restartRequiredHostsAndComponents: ""});
  297. });
  298. afterEach(function () {
  299. mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
  300. mainServiceInfoConfigsController.set("content", undefined);
  301. });
  302. tests.forEach(function (t) {
  303. it("trigger showItemsShouldBeRestarted popup with hosts", function () {
  304. mainServiceInfoConfigsController.set("content.restartRequiredHostsAndComponents", t.input);
  305. mainServiceInfoConfigsController.showHostsShouldBeRestarted();
  306. expect(mainServiceInfoConfigsController.showItemsShouldBeRestarted.calledWith(t.hosts, t.text)).to.equal(true);
  307. });
  308. });
  309. });
  310. describe("rollingRestartStaleConfigSlaveComponents", function () {
  311. var tests = [
  312. {
  313. componentName: {
  314. context: "ComponentName"
  315. },
  316. displayName: "displayName",
  317. passiveState: "ON"
  318. },
  319. {
  320. componentName: {
  321. context: "ComponentName1"
  322. },
  323. displayName: "displayName1",
  324. passiveState: "OFF"
  325. }
  326. ];
  327. beforeEach(function () {
  328. mainServiceInfoConfigsController.set("content", {displayName: "", passiveState: ""});
  329. sinon.stub(batchUtils, "launchHostComponentRollingRestart", Em.K);
  330. });
  331. afterEach(function () {
  332. batchUtils.launchHostComponentRollingRestart.restore();
  333. });
  334. tests.forEach(function (t) {
  335. it("trigger rollingRestartStaleConfigSlaveComponents", function () {
  336. mainServiceInfoConfigsController.set("content.displayName", t.displayName);
  337. mainServiceInfoConfigsController.set("content.passiveState", t.passiveState);
  338. mainServiceInfoConfigsController.rollingRestartStaleConfigSlaveComponents(t.componentName);
  339. expect(batchUtils.launchHostComponentRollingRestart.calledWith(t.componentName.context, t.displayName, t.passiveState == "ON", true)).to.equal(true);
  340. });
  341. });
  342. });
  343. describe("#restartAllStaleConfigComponents", function () {
  344. beforeEach(function () {
  345. sinon.stub(batchUtils, "restartAllServiceHostComponents", Em.K);
  346. });
  347. afterEach(function () {
  348. batchUtils.restartAllServiceHostComponents.restore();
  349. });
  350. it("trigger restartAllServiceHostComponents", function () {
  351. mainServiceInfoConfigsController.restartAllStaleConfigComponents().onPrimary();
  352. expect(batchUtils.restartAllServiceHostComponents.calledOnce).to.equal(true);
  353. });
  354. });
  355. describe("#doCancel", function () {
  356. beforeEach(function () {
  357. sinon.stub(mainServiceInfoConfigsController, "loadStep", Em.K);
  358. });
  359. afterEach(function () {
  360. mainServiceInfoConfigsController.loadStep.restore();
  361. });
  362. it("trigger loadStep", function () {
  363. mainServiceInfoConfigsController.doCancel();
  364. expect(mainServiceInfoConfigsController.loadStep.calledOnce).to.equal(true);
  365. });
  366. });
  367. describe("#getCurrentServiceComponents", function () {
  368. var t = Em.Object.create({
  369. content: Em.Object.create({
  370. hostComponents: [
  371. Em.Object.create({
  372. componentName: "componentName1",
  373. displayName: "displayName1"
  374. }),
  375. Em.Object.create({
  376. componentName: "componentName2",
  377. displayName: "displayName2"
  378. })
  379. ]
  380. }),
  381. validComponents: Em.A([
  382. Em.Object.create({
  383. componentName: "componentName1",
  384. displayName: "displayName1",
  385. selected: false
  386. }),
  387. Em.Object.create({
  388. componentName: "componentName2",
  389. displayName: "displayName2",
  390. selected: false
  391. })
  392. ])
  393. });
  394. beforeEach(function () {
  395. mainServiceInfoConfigsController.set("content", { hostComponents: Em.A([])});
  396. });
  397. it("get current service components", function () {
  398. mainServiceInfoConfigsController.get("content.hostComponents").push(t.content.hostComponents[0]);
  399. var com = mainServiceInfoConfigsController.get("getCurrentServiceComponents");
  400. expect(com[0]).to.eql(t.validComponents[0]);
  401. });
  402. });
  403. describe("#getMasterComponentHostValue", function () {
  404. var tests = [
  405. {
  406. content: {
  407. hostComponents: [
  408. Em.Object.create({
  409. componentName: "componentName1",
  410. hostName: "hostName"
  411. })
  412. ]
  413. },
  414. result: "hostName",
  415. multiple: false,
  416. m: "returns hostname"
  417. },
  418. {
  419. content: {
  420. hostComponents: [
  421. Em.Object.create({
  422. componentName: "componentName2",
  423. hostName: "hostName1"
  424. }),
  425. Em.Object.create({
  426. componentName: "componentName2",
  427. hostName: "hostName2"
  428. })
  429. ]
  430. },
  431. result: ["hostName1","hostName2"],
  432. multiple: true,
  433. m: "returns hostnames"
  434. }
  435. ];
  436. tests.forEach(function(t){
  437. beforeEach(function () {
  438. mainServiceInfoConfigsController.set("content", { hostComponents: []});
  439. });
  440. it(t.m, function () {
  441. mainServiceInfoConfigsController.set("content.hostComponents", t.content.hostComponents);
  442. expect(mainServiceInfoConfigsController.getMasterComponentHostValue(t.content.hostComponents[0].componentName, t.multiple)).to.eql(t.result);
  443. });
  444. });
  445. });
  446. describe("#setServerConfigValue", function () {
  447. it("parsing storm.zookeeper.servers property in non standart method", function () {
  448. expect(mainServiceInfoConfigsController.setServerConfigValue("storm.zookeeper.servers", ["a", "b"])).to.equal('[\'a\',\'b\']');
  449. });
  450. it("parsing content property in non standart method", function () {
  451. expect(mainServiceInfoConfigsController.setServerConfigValue("content", "value")).to.equal("value");
  452. });
  453. it("parsing default properties", function () {
  454. expect(mainServiceInfoConfigsController.setServerConfigValue("any.other.property", "value&lt;")).to.equal("value<");
  455. });
  456. });
  457. describe("#createSiteObj", function () {
  458. var tests = [
  459. {
  460. siteName: "hdfs-site",
  461. tagName: "version1",
  462. siteObj: Em.A([
  463. {
  464. name: "property1",
  465. value: "value1"
  466. },
  467. {
  468. name: "property2",
  469. value: "value2&lt;"
  470. }
  471. ]),
  472. result: {
  473. "type": "hdfs-site",
  474. "tag": "version1",
  475. "properties": {
  476. "property1": "value1",
  477. "property2": "value2<"
  478. }
  479. },
  480. m: "default"
  481. },
  482. {
  483. siteName: "falcon-startup.properties",
  484. tagName: "version1",
  485. siteObj: Em.A([
  486. {
  487. name: "property1",
  488. value: "value1"
  489. },
  490. {
  491. name: "property2",
  492. value: "value2&lt;"
  493. }
  494. ]),
  495. result: {
  496. "type": "falcon-startup.properties",
  497. "tag": "version1",
  498. "properties": {
  499. "property1": "value1",
  500. "property2": "value2&lt;"
  501. }
  502. },
  503. m: "for falcon-startup.properties"
  504. }
  505. ];
  506. tests.forEach(function (t) {
  507. it("create site object " + t.m, function () {
  508. expect(mainServiceInfoConfigsController.createSiteObj(t.siteName, t.tagName, t.siteObj)).to.deep.eql(t.result)
  509. });
  510. });
  511. });
  512. describe("#createCoreSiteObj", function () {
  513. var tests = [
  514. {
  515. tagName: "version1",
  516. uiConfigs: Em.A([
  517. Em.Object.create({
  518. name: "property1",
  519. value: "value1",
  520. filename: "core-site.xml"
  521. }),
  522. Em.Object.create({
  523. name: "property2",
  524. value: "value2&lt;",
  525. filename: "core-site.xml"
  526. })
  527. ]),
  528. result: {
  529. "type": "core-site",
  530. "tag": "version1",
  531. "properties": {
  532. "property1": "value1",
  533. "property2": "value2<"
  534. }
  535. }
  536. }
  537. ];
  538. tests.forEach(function (t) {
  539. it("create core object", function () {
  540. mainServiceInfoConfigsController.set("uiConfigs", t.uiConfigs);
  541. expect(mainServiceInfoConfigsController.createCoreSiteObj(t.tagName)).to.deep.eql(t.result);
  542. });
  543. });
  544. });
  545. describe("#doPUTClusterConfigurationSite", function () {
  546. var t = {
  547. data: "data",
  548. request: {
  549. Clusters: {
  550. desired_config: "data"
  551. }
  552. }
  553. };
  554. beforeEach(function () {
  555. sinon.stub(App.router, 'getClusterName', function() {
  556. return 'clName';
  557. });
  558. sinon.spy($, "ajax");
  559. });
  560. afterEach(function () {
  561. $.ajax.restore();
  562. App.router.getClusterName.restore();
  563. });
  564. it("ajax request to put clsuter cfg", function () {
  565. expect(mainServiceInfoConfigsController.doPUTClusterConfigurationSite(t.data)).to.equal(mainServiceInfoConfigsController.get("doPUTClusterConfigurationSiteResult"));
  566. expect(JSON.parse($.ajax.args[0][0].data)).to.deep.equal(t.request);
  567. });
  568. });
  569. describe("#isConfigChanged", function () {
  570. var tests = [
  571. {
  572. loadedConfig: {
  573. apptimelineserver_heapsize: "1024",
  574. hbase_log_dir: "/var/log/hbase",
  575. lzo_enabled: "true"
  576. },
  577. savingConfig: {
  578. apptimelineserver_heapsize: "1024",
  579. hbase_log_dir: "/var/log/hbase",
  580. lzo_enabled: "true"
  581. },
  582. m: "configs doesn't changed",
  583. res: false
  584. },
  585. {
  586. loadedConfig: {
  587. apptimelineserver_heapsize: "1024",
  588. hbase_log_dir: "/var/log/hbase",
  589. lzo_enabled: "true"
  590. },
  591. savingConfig: {
  592. apptimelineserver_heapsize: "1024",
  593. hbase_log_dir: "/var/log/hbase",
  594. lzo_enabled: "false"
  595. },
  596. m: "configs changed",
  597. res: true
  598. },
  599. {
  600. loadedConfig: {
  601. apptimelineserver_heapsize: "1024",
  602. hbase_log_dir: "/var/log/hbase"
  603. },
  604. savingConfig: {
  605. apptimelineserver_heapsize: "1024",
  606. hbase_log_dir: "/var/log/hbase",
  607. lzo_enabled: "false"
  608. },
  609. m: "add new config",
  610. res: true
  611. }
  612. ];
  613. tests.forEach(function(t){
  614. it(t.m, function () {
  615. expect(mainServiceInfoConfigsController.isConfigChanged(t.loadedConfig, t.savingConfig)).to.equal(t.res);
  616. });
  617. });
  618. });
  619. describe("#addDynamicProperties", function() {
  620. var tests = [
  621. {
  622. stepConfigs: [Em.Object.create({
  623. serviceName: "WEBHCAT",
  624. configs: []
  625. })],
  626. content: Em.Object.create({
  627. serviceName: "WEBHCAT"
  628. }),
  629. m: "add dynamic property",
  630. addDynamic: true
  631. },
  632. {
  633. stepConfigs: [Em.Object.create({
  634. serviceName: "WEBHCAT",
  635. configs: [
  636. Em.Object.create({
  637. name: "templeton.hive.properties"
  638. })
  639. ]
  640. })],
  641. content: Em.Object.create({
  642. serviceName: "WEBHCAT"
  643. }),
  644. m: "don't add dynamic property (already included)",
  645. addDynamic: false
  646. },
  647. {
  648. stepConfigs: [Em.Object.create({
  649. serviceName: "HDFS",
  650. configs: []
  651. })],
  652. content: Em.Object.create({
  653. serviceName: "HDFS"
  654. }),
  655. m: "don't add dynamic property (wrong service)",
  656. addDynamic: false
  657. }
  658. ];
  659. var dynamicProperty = {
  660. "name": "templeton.hive.properties",
  661. "templateName": ["hivemetastore_host"],
  662. "foreignKey": null,
  663. "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",
  664. "filename": "webhcat-site.xml"
  665. };
  666. tests.forEach(function(t) {
  667. it(t.m, function() {
  668. mainServiceInfoConfigsController.set("content", t.content);
  669. mainServiceInfoConfigsController.set("stepConfigs", t.stepConfigs);
  670. var configs = [];
  671. mainServiceInfoConfigsController.addDynamicProperties(configs);
  672. if (t.addDynamic){
  673. expect(configs.findProperty("name","templeton.hive.properties")).to.deep.eql(dynamicProperty);
  674. }
  675. });
  676. });
  677. });
  678. describe("#loadUiSideConfigs", function () {
  679. var t = {
  680. configMapping: [
  681. {
  682. foreignKey: null,
  683. templateName: "",
  684. value: "default",
  685. name: "name1",
  686. filename: "filename1"
  687. },
  688. {
  689. foreignKey: "notNull",
  690. templateName: "",
  691. value: "default2",
  692. name: "name2",
  693. filename: "filename2"
  694. }
  695. ],
  696. configMappingf: [
  697. {
  698. foreignKey: null,
  699. templateName: "",
  700. value: "default",
  701. name: "name1",
  702. filename: "filename1"
  703. }
  704. ],
  705. valueWithOverrides: {
  706. "value": "default",
  707. "overrides": {
  708. "value1": "value1",
  709. "value2": "value2"
  710. }
  711. },
  712. uiConfigs: [
  713. {
  714. "id": "site property",
  715. "name": "name1",
  716. "value": "default",
  717. "filename": "filename1",
  718. "overrides": {
  719. "value1": "value1",
  720. "value2": "value2"
  721. }
  722. }
  723. ]
  724. };
  725. beforeEach(function(){
  726. sinon.stub(mainServiceInfoConfigsController, "addDynamicProperties", Em.K);
  727. sinon.stub(mainServiceInfoConfigsController, "getGlobConfigValueWithOverrides", function () {
  728. return t.valueWithOverrides
  729. });
  730. });
  731. afterEach(function(){
  732. mainServiceInfoConfigsController.addDynamicProperties.restore();
  733. mainServiceInfoConfigsController.getGlobConfigValueWithOverrides.restore();
  734. });
  735. it("load ui config", function() {
  736. expect(mainServiceInfoConfigsController.loadUiSideConfigs(t.configMapping)[0]).to.deep.equal(t.uiConfigs[0]);
  737. expect(mainServiceInfoConfigsController.addDynamicProperties.calledWith(t.configMappingf)).to.equal(true);
  738. });
  739. });
  740. describe("#formatConfigValues", function () {
  741. var t = {
  742. configs: [
  743. Em.Object.create({ name: "p1", value: " v1 v1 ", displayType: "" }),
  744. Em.Object.create({ name: "p2", value: true, displayType: "" }),
  745. Em.Object.create({ name: "p3", value: " d1 ", displayType: "directory" }),
  746. Em.Object.create({ name: "p4", value: " d1 d2 d3 ", displayType: "directories" }),
  747. Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
  748. Em.Object.create({ name: "p6", value: " v ", displayType: "host" }),
  749. Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1 ", displayType: "advanced" }),
  750. Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1 ", displayType: "advanced" })
  751. ],
  752. result: [
  753. Em.Object.create({ name: "p1", value: " v1 v1", displayType: "" }),
  754. Em.Object.create({ name: "p2", value: "true", displayType: "" }),
  755. Em.Object.create({ name: "p3", value: "d1", displayType: "directory" }),
  756. Em.Object.create({ name: "p4", value: "d1,d2,d3", displayType: "directories" }),
  757. Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
  758. Em.Object.create({ name: "p6", value: "v", displayType: "host" }),
  759. Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1", displayType: "advanced" }),
  760. Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1", displayType: "advanced" })
  761. ]
  762. };
  763. it("format config values", function () {
  764. mainServiceInfoConfigsController.formatConfigValues(t.configs);
  765. expect(t.configs).to.deep.equal(t.result);
  766. });
  767. });
  768. describe("#createConfigObject", function() {
  769. var tests = [
  770. {
  771. siteName: "core-site",
  772. serviceName: "HDFS",
  773. method: "createCoreSiteObj"
  774. },
  775. {
  776. siteName: "core-site",
  777. serviceName: "ANY",
  778. method: false
  779. },
  780. {
  781. siteName: "any",
  782. method: "createSiteObj"
  783. },
  784. {
  785. siteName: "mapred-queue-acls",
  786. method: false,
  787. capacitySchedulerUi: false
  788. },
  789. {
  790. siteName: "mapred-queue-acls",
  791. method: "createSiteObj",
  792. capacitySchedulerUi: true
  793. }
  794. ];
  795. var capacitySchedulerUi = App.supports.capacitySchedulerUi;
  796. beforeEach(function() {
  797. sinon.stub(mainServiceInfoConfigsController, "createCoreSiteObj", Em.K);
  798. sinon.stub(mainServiceInfoConfigsController, "createSiteObj", Em.K);
  799. mainServiceInfoConfigsController.set("content", {});
  800. });
  801. afterEach(function() {
  802. mainServiceInfoConfigsController.createCoreSiteObj.restore();
  803. mainServiceInfoConfigsController.createSiteObj.restore();
  804. App.supports.capacitySchedulerUi = capacitySchedulerUi;
  805. });
  806. tests.forEach(function(t) {
  807. it("create object for " + t.siteName + " run method " + t.method, function() {
  808. App.supports.capacitySchedulerUi = t.capacitySchedulerUi;
  809. mainServiceInfoConfigsController.set("content.serviceName", t.serviceName);
  810. mainServiceInfoConfigsController.createConfigObject(t.siteName, "versrion1");
  811. if (t.method) {
  812. expect(mainServiceInfoConfigsController[t.method].calledOnce).to.equal(true);
  813. } else {
  814. expect(mainServiceInfoConfigsController["createCoreSiteObj"].calledOnce).to.equal(false);
  815. expect(mainServiceInfoConfigsController["createSiteObj"].calledOnce).to.equal(false);
  816. }
  817. });
  818. });
  819. });
  820. describe("#putConfigGroupChanges", function() {
  821. var t = {
  822. data: {
  823. ConfigGroup: {
  824. id: "id"
  825. }
  826. },
  827. request: [{
  828. ConfigGroup: {
  829. id: "id"
  830. }
  831. }]
  832. };
  833. beforeEach(function() {
  834. sinon.spy($,"ajax");
  835. });
  836. afterEach(function() {
  837. $.ajax.restore();
  838. });
  839. it("updates configs groups", function() {
  840. mainServiceInfoConfigsController.putConfigGroupChanges(t.data);
  841. expect(JSON.parse($.ajax.args[0][0].data)).to.deep.equal(t.request);
  842. });
  843. });
  844. describe("#setValueForCheckBox", function() {
  845. var tests = [
  846. {
  847. serviceConfigPropertyInput: Em.Object.create({
  848. value: "true",
  849. defaultValue: "true",
  850. displayType: 'checkbox'
  851. }),
  852. serviceConfigProperty: Em.Object.create({
  853. value: true,
  854. defaultValue: true,
  855. displayType: 'checkbox'
  856. })
  857. },
  858. {
  859. serviceConfigPropertyInput: Em.Object.create({
  860. value: "false",
  861. defaultValue: "false",
  862. displayType: 'checkbox'
  863. }),
  864. serviceConfigProperty: Em.Object.create({
  865. value: false,
  866. defaultValue: false,
  867. displayType: 'checkbox'
  868. })
  869. },
  870. {
  871. serviceConfigPropertyInput: Em.Object.create({
  872. value: "false",
  873. defaultValue: "false"
  874. }),
  875. serviceConfigProperty: Em.Object.create({
  876. value: "false",
  877. defaultValue: "false"
  878. })
  879. }
  880. ];
  881. tests.forEach(function(t) {
  882. it("set " + t.serviceConfigPropertyInput.value, function(){
  883. var serviceConfigProperty = t.serviceConfigPropertyInput;
  884. mainServiceInfoConfigsController.setValueForCheckBox(serviceConfigProperty);
  885. expect(serviceConfigProperty).to.eql(t.serviceConfigProperty);
  886. });
  887. });
  888. });
  889. describe("#setEditability", function () {
  890. var tests = [
  891. {
  892. isAdmin: true,
  893. isHostsConfigsPage: false,
  894. defaultGroupSelected: true,
  895. isReconfigurable: true,
  896. isEditable: true,
  897. m: ""
  898. },
  899. {
  900. isAdmin: false,
  901. isHostsConfigsPage: false,
  902. defaultGroupSelected: true,
  903. isReconfigurable: true,
  904. isEditable: false,
  905. m: "(non admin)"
  906. },
  907. {
  908. isAdmin: true,
  909. isHostsConfigsPage: true,
  910. defaultGroupSelected: true,
  911. isReconfigurable: true,
  912. isEditable: false,
  913. m: "(isHostsConfigsPage)"
  914. },
  915. {
  916. isAdmin: true,
  917. isHostsConfigsPage: false,
  918. defaultGroupSelected: false,
  919. isReconfigurable: true,
  920. isEditable: false,
  921. m: "(defaultGroupSelected is false)"
  922. },
  923. {
  924. isAdmin: true,
  925. isHostsConfigsPage: false,
  926. defaultGroupSelected: true,
  927. isReconfigurable: false,
  928. isEditable: false,
  929. m: "(isReconfigurable is false)"
  930. }
  931. ];
  932. var a = App.get('isAdmin');
  933. afterEach(function () {
  934. App.set('isAdmin', a);
  935. });
  936. tests.forEach(function(t) {
  937. it("set isEditable " + t.isEditable + t.m, function(){
  938. App.set('isAdmin', t.isAdmin);
  939. mainServiceInfoConfigsController.set("isHostsConfigsPage", t.isHostsConfigsPage);
  940. var serviceConfigProperty = Em.Object.create({
  941. isReconfigurable: t.isReconfigurable
  942. });
  943. mainServiceInfoConfigsController.setEditability(serviceConfigProperty, t.defaultGroupSelected);
  944. expect(serviceConfigProperty.get("isEditable")).to.equal(t.isEditable);
  945. });
  946. });
  947. });
  948. describe("#checkOverrideProperty", function () {
  949. var tests = [{
  950. overrideToAdd: {
  951. name: "name1",
  952. filename: "filename1"
  953. },
  954. componentConfig: {
  955. configs: [
  956. {
  957. name: "name1",
  958. filename: "filename2"
  959. },
  960. {
  961. name: "name1",
  962. filename: "filename1"
  963. }
  964. ]
  965. },
  966. add: true,
  967. m: "add property"
  968. },
  969. {
  970. overrideToAdd: {
  971. name: "name1"
  972. },
  973. componentConfig: {
  974. configs: [
  975. {
  976. name: "name2"
  977. }
  978. ]
  979. },
  980. add: false,
  981. m: "don't add property, different names"
  982. },
  983. {
  984. overrideToAdd: {
  985. name: "name1",
  986. filename: "filename1"
  987. },
  988. componentConfig: {
  989. configs: [
  990. {
  991. name: "name1",
  992. filename: "filename2"
  993. }
  994. ]
  995. },
  996. add: false,
  997. m: "don't add property, different filenames"
  998. },
  999. {
  1000. overrideToAdd: null,
  1001. componentConfig: {},
  1002. add: false,
  1003. m: "don't add property, overrideToAdd is null"
  1004. }];
  1005. beforeEach(function() {
  1006. sinon.stub(mainServiceInfoConfigsController,"addOverrideProperty", Em.K)
  1007. });
  1008. afterEach(function() {
  1009. mainServiceInfoConfigsController.addOverrideProperty.restore();
  1010. });
  1011. tests.forEach(function(t) {
  1012. it(t.m, function() {
  1013. mainServiceInfoConfigsController.set("overrideToAdd", t.overrideToAdd);
  1014. mainServiceInfoConfigsController.checkOverrideProperty(t.componentConfig);
  1015. if(t.add) {
  1016. expect(mainServiceInfoConfigsController.addOverrideProperty.calledWith(t.overrideToAdd)).to.equal(true);
  1017. expect(mainServiceInfoConfigsController.get("overrideToAdd")).to.equal(null);
  1018. } else {
  1019. expect(mainServiceInfoConfigsController.addOverrideProperty.calledOnce).to.equal(false);
  1020. }
  1021. });
  1022. });
  1023. });
  1024. describe("#setValuesForOverrides", function() {
  1025. var tests = [
  1026. {
  1027. overrides: [
  1028. {name: "override1"},
  1029. {name: "override2"}
  1030. ],
  1031. _serviceConfigProperty: {},
  1032. serviceConfigProperty: Em.Object.create({overrides: Em.A([])}),
  1033. defaultGroupSelected: true
  1034. }
  1035. ];
  1036. beforeEach(function() {
  1037. sinon.stub(mainServiceInfoConfigsController, "createNewSCP", function(override) {return {name: override.name}})
  1038. });
  1039. afterEach(function() {
  1040. mainServiceInfoConfigsController.createNewSCP.restore();
  1041. });
  1042. tests.forEach(function(t) {
  1043. it("set values for overrides. use createNewSCP method to do this", function() {
  1044. var serviceConfigProperty = t.serviceConfigProperty;
  1045. mainServiceInfoConfigsController.setValuesForOverrides(t.overrides, serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected);
  1046. expect(serviceConfigProperty.get("overrides")[0]).to.eql(t.overrides[0]);
  1047. expect(serviceConfigProperty.get("overrides")[1]).to.eql(t.overrides[1]);
  1048. });
  1049. });
  1050. });
  1051. describe("#createConfigProperty", function() {
  1052. var tests = [
  1053. {
  1054. _serviceConfigProperty: {
  1055. overrides: {
  1056. }
  1057. },
  1058. defaultGroupSelected: true,
  1059. restartData: {},
  1060. serviceConfigsData: {},
  1061. serviceConfigProperty: {
  1062. overrides: null,
  1063. isOverridable: true
  1064. }
  1065. }];
  1066. beforeEach(function() {
  1067. sinon.stub(mainServiceInfoConfigsController, "setValueForCheckBox", Em.K);
  1068. sinon.stub(mainServiceInfoConfigsController, "setValidator", Em.K);
  1069. sinon.stub(mainServiceInfoConfigsController, "setValuesForOverrides", Em.K);
  1070. sinon.stub(mainServiceInfoConfigsController, "setEditability", Em.K);
  1071. });
  1072. afterEach(function() {
  1073. mainServiceInfoConfigsController.setValueForCheckBox.restore();
  1074. mainServiceInfoConfigsController.setValidator.restore();
  1075. mainServiceInfoConfigsController.setValuesForOverrides.restore();
  1076. mainServiceInfoConfigsController.setEditability.restore();
  1077. });
  1078. tests.forEach(function(t) {
  1079. it("create service config. run methods to correctly set object fileds", function() {
  1080. var result = mainServiceInfoConfigsController.createConfigProperty(t._serviceConfigProperty, t.defaultGroupSelected, t.restartData, t.serviceConfigsData);
  1081. expect(mainServiceInfoConfigsController.setValueForCheckBox.calledWith(t.serviceConfigProperty));
  1082. expect(mainServiceInfoConfigsController.setValidator.calledWith(t.serviceConfigProperty, t.serviceConfigsData));
  1083. expect(mainServiceInfoConfigsController.setValuesForOverrides.calledWith(t._serviceConfigProperty.overrides, t._serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected));
  1084. expect(mainServiceInfoConfigsController.setValidator.calledWith(t.serviceConfigProperty, t.defaultGroupSelected));
  1085. expect(result.getProperties('overrides','isOverridable')).to.eql(t.serviceConfigProperty);
  1086. });
  1087. });
  1088. });
  1089. describe("#createNewSCP", function() {
  1090. var tests = [
  1091. {
  1092. overrides: {
  1093. value: "value",
  1094. group: {
  1095. value: "group1"
  1096. }
  1097. },
  1098. _serviceConfigProperty: {},
  1099. serviceConfigProperty: {
  1100. value: "parentSCP"
  1101. },
  1102. defaultGroupSelected: true,
  1103. newSCP: {
  1104. value: "value",
  1105. isOriginalSCP: false,
  1106. parentSCP:{
  1107. value: "parentSCP"
  1108. },
  1109. group: {
  1110. value: "group1"
  1111. },
  1112. isEditable: false
  1113. }
  1114. }
  1115. ];
  1116. tests.forEach(function(t) {
  1117. it("", function() {
  1118. var newSCP = mainServiceInfoConfigsController.createNewSCP(t.overrides, t._serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected);
  1119. expect(newSCP.getProperties("value", "isOriginalSCP", "parentSCP", "group", "isEditable")).to.eql(t.newSCP);
  1120. });
  1121. });
  1122. });
  1123. });