config_test.js 41 KB

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