config_test.js 46 KB

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