config_test.js 41 KB

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