config_test.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  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. function getController() {
  23. return App.MainServiceInfoConfigsController.create({
  24. dependentServiceNames: [],
  25. loadDependentConfigs: function () {
  26. return {done: Em.K}
  27. },
  28. loadConfigTheme: function () {
  29. return $.Deferred().resolve().promise();
  30. }
  31. });
  32. }
  33. describe("App.MainServiceInfoConfigsController", function () {
  34. beforeEach(function () {
  35. sinon.stub(App.themesMapper, 'generateAdvancedTabs').returns(Em.K);
  36. mainServiceInfoConfigsController = getController();
  37. });
  38. App.TestAliases.testAsComputedAlias(getController(), 'serviceConfigs', 'App.config.preDefinedServiceConfigs', 'array');
  39. afterEach(function() {
  40. App.themesMapper.generateAdvancedTabs.restore();
  41. });
  42. describe("#showSavePopup", function () {
  43. var tests = [
  44. {
  45. transitionCallback: false,
  46. callback: false,
  47. action: "onSave",
  48. m: "save configs without transitionCallback/callback",
  49. results: [
  50. {
  51. method: "restartServicePopup",
  52. called: true
  53. }
  54. ]
  55. },
  56. {
  57. transitionCallback: true,
  58. callback: true,
  59. action: "onSave",
  60. m: "save configs with transitionCallback/callback",
  61. results: [
  62. {
  63. method: "restartServicePopup",
  64. called: true
  65. }
  66. ]
  67. },
  68. {
  69. transitionCallback: false,
  70. callback: false,
  71. action: "onDiscard",
  72. m: "discard changes without transitionCallback/callback",
  73. results: [
  74. {
  75. method: "restartServicePopup",
  76. called: false
  77. }
  78. ]
  79. },
  80. {
  81. transitionCallback: false,
  82. callback: true,
  83. action: "onDiscard",
  84. m: "discard changes with callback",
  85. results: [
  86. {
  87. method: "restartServicePopup",
  88. called: false
  89. },
  90. {
  91. method: "callback",
  92. called: true
  93. },
  94. {
  95. field: "hash",
  96. value: "hash"
  97. }
  98. ]
  99. },
  100. {
  101. transitionCallback: true,
  102. callback: false,
  103. action: "onDiscard",
  104. m: "discard changes with transitionCallback",
  105. results: [
  106. {
  107. method: "restartServicePopup",
  108. called: false
  109. },
  110. {
  111. method: "transitionCallback",
  112. called: true
  113. }
  114. ]
  115. }
  116. ];
  117. beforeEach(function () {
  118. mainServiceInfoConfigsController.reopen({
  119. passwordConfigsAreChanged: false
  120. });
  121. sinon.stub(mainServiceInfoConfigsController, "get", function(key) {
  122. return key == 'isSubmitDisabled' ? false : Em.get(mainServiceInfoConfigsController, key);
  123. });
  124. sinon.stub(mainServiceInfoConfigsController, "restartServicePopup", Em.K);
  125. sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
  126. return "hash"
  127. });
  128. });
  129. afterEach(function () {
  130. mainServiceInfoConfigsController.get.restore();
  131. mainServiceInfoConfigsController.restartServicePopup.restore();
  132. mainServiceInfoConfigsController.getHash.restore();
  133. });
  134. tests.forEach(function (t) {
  135. t.results.forEach(function (r) {
  136. it(t.m + " " + r.method + " " + r.field, function () {
  137. if (t.callback) {
  138. t.callback = sinon.stub();
  139. }
  140. if (t.transitionCallback) {
  141. t.transitionCallback = sinon.stub();
  142. }
  143. mainServiceInfoConfigsController.showSavePopup(t.transitionCallback, t.callback)[t.action]();
  144. if (r.method) {
  145. if (r.method === 'callback') {
  146. expect(t.callback.calledOnce).to.equal(r.called);
  147. } else if (r.method === 'transitionCallback') {
  148. expect(t.transitionCallback.calledOnce).to.equal(r.called);
  149. } else {
  150. expect(mainServiceInfoConfigsController[r.method].calledOnce).to.equal(r.called);
  151. }
  152. } else if (r.field) {
  153. expect(mainServiceInfoConfigsController.get(r.field)).to.equal(r.value);
  154. }
  155. }, this);
  156. });
  157. }, this);
  158. });
  159. describe("#hasUnsavedChanges", function () {
  160. var cases = [
  161. {
  162. hash: null,
  163. hasUnsavedChanges: false,
  164. title: 'configs not rendered'
  165. },
  166. {
  167. hash: 'hash1',
  168. hasUnsavedChanges: true,
  169. title: 'with unsaved'
  170. },
  171. {
  172. hash: 'hash',
  173. hasUnsavedChanges: false,
  174. title: 'without unsaved'
  175. }
  176. ];
  177. beforeEach(function () {
  178. sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
  179. return "hash"
  180. });
  181. });
  182. afterEach(function () {
  183. mainServiceInfoConfigsController.getHash.restore();
  184. });
  185. cases.forEach(function (item) {
  186. it(item.title, function () {
  187. mainServiceInfoConfigsController.set('hash', item.hash);
  188. expect(mainServiceInfoConfigsController.hasUnsavedChanges()).to.equal(item.hasUnsavedChanges);
  189. });
  190. });
  191. });
  192. describe("#showComponentsShouldBeRestarted", function () {
  193. var tests = [
  194. {
  195. input: {
  196. context: {
  197. restartRequiredHostsAndComponents: {
  198. 'publicHostName1': ['TaskTracker'],
  199. 'publicHostName2': ['JobTracker', 'TaskTracker']
  200. }
  201. }
  202. },
  203. components: "2 TaskTrackers, 1 JobTracker",
  204. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.components'))
  205. },
  206. {
  207. input: {
  208. context: {
  209. restartRequiredHostsAndComponents: {
  210. 'publicHostName1': ['TaskTracker']
  211. }
  212. }
  213. },
  214. components: "1 TaskTracker",
  215. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.component'))
  216. }
  217. ];
  218. beforeEach(function () {
  219. sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
  220. });
  221. afterEach(function () {
  222. mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
  223. });
  224. tests.forEach(function (t) {
  225. it("trigger showItemsShouldBeRestarted popup with components", function () {
  226. mainServiceInfoConfigsController.showComponentsShouldBeRestarted(t.input);
  227. expect(mainServiceInfoConfigsController.showItemsShouldBeRestarted.calledWith(t.components, t.text)).to.equal(true);
  228. });
  229. });
  230. });
  231. describe("#showHostsShouldBeRestarted", function () {
  232. var tests = [
  233. {
  234. input: {
  235. context: {
  236. restartRequiredHostsAndComponents: {
  237. 'publicHostName1': ['TaskTracker'],
  238. 'publicHostName2': ['JobTracker', 'TaskTracker']
  239. }
  240. }
  241. },
  242. hosts: "publicHostName1, publicHostName2",
  243. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.hosts'))
  244. },
  245. {
  246. input: {
  247. context: {
  248. restartRequiredHostsAndComponents: {
  249. 'publicHostName1': ['TaskTracker']
  250. }
  251. }
  252. },
  253. hosts: "publicHostName1",
  254. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.host'))
  255. }
  256. ];
  257. beforeEach(function () {
  258. sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
  259. });
  260. afterEach(function () {
  261. mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
  262. });
  263. tests.forEach(function (t) {
  264. it("trigger showItemsShouldBeRestarted popup with hosts", function () {
  265. mainServiceInfoConfigsController.showHostsShouldBeRestarted(t.input);
  266. expect(mainServiceInfoConfigsController.showItemsShouldBeRestarted.calledWith(t.hosts, t.text)).to.equal(true);
  267. });
  268. });
  269. });
  270. describe("#rollingRestartStaleConfigSlaveComponents", function () {
  271. var tests = [
  272. {
  273. componentName: {
  274. context: "ComponentName"
  275. },
  276. displayName: "displayName",
  277. passiveState: "ON"
  278. },
  279. {
  280. componentName: {
  281. context: "ComponentName1"
  282. },
  283. displayName: "displayName1",
  284. passiveState: "OFF"
  285. }
  286. ];
  287. beforeEach(function () {
  288. mainServiceInfoConfigsController.set("content", {displayName: "", passiveState: ""});
  289. sinon.stub(batchUtils, "launchHostComponentRollingRestart", Em.K);
  290. });
  291. afterEach(function () {
  292. batchUtils.launchHostComponentRollingRestart.restore();
  293. });
  294. tests.forEach(function (t) {
  295. it("trigger rollingRestartStaleConfigSlaveComponents", function () {
  296. mainServiceInfoConfigsController.set("content.displayName", t.displayName);
  297. mainServiceInfoConfigsController.set("content.passiveState", t.passiveState);
  298. mainServiceInfoConfigsController.rollingRestartStaleConfigSlaveComponents(t.componentName);
  299. expect(batchUtils.launchHostComponentRollingRestart.calledWith(t.componentName.context, t.displayName, t.passiveState == "ON", true)).to.equal(true);
  300. });
  301. });
  302. });
  303. describe("#restartAllStaleConfigComponents", function () {
  304. beforeEach(function () {
  305. sinon.stub(batchUtils, "restartAllServiceHostComponents", Em.K);
  306. });
  307. afterEach(function () {
  308. batchUtils.restartAllServiceHostComponents.restore();
  309. });
  310. it("trigger restartAllServiceHostComponents", function () {
  311. mainServiceInfoConfigsController.restartAllStaleConfigComponents().onPrimary();
  312. expect(batchUtils.restartAllServiceHostComponents.calledOnce).to.equal(true);
  313. });
  314. it("trigger check last check point warning before triggering restartAllServiceHostComponents", function () {
  315. var mainConfigsControllerHdfsStarted = App.MainServiceInfoConfigsController.create({
  316. content: {
  317. serviceName: "HDFS",
  318. hostComponents: [{
  319. componentName: 'NAMENODE',
  320. workStatus: 'STARTED'
  321. }],
  322. restartRequiredHostsAndComponents: {
  323. "host1": ['NameNode'],
  324. "host2": ['DataNode', 'ZooKeeper']
  325. }
  326. }
  327. });
  328. var mainServiceItemController = App.MainServiceItemController.create({});
  329. sinon.stub(mainServiceItemController, 'checkNnLastCheckpointTime', function() {
  330. return true;
  331. });
  332. sinon.stub(App.router, 'get', function(k) {
  333. if ('mainServiceItemController' === k) {
  334. return mainServiceItemController;
  335. }
  336. return Em.get(App.router, k);
  337. });
  338. mainConfigsControllerHdfsStarted.restartAllStaleConfigComponents();
  339. expect(mainServiceItemController.checkNnLastCheckpointTime.calledOnce).to.equal(true);
  340. mainServiceItemController.checkNnLastCheckpointTime.restore();
  341. App.router.get.restore();
  342. });
  343. });
  344. describe("#doCancel", function () {
  345. beforeEach(function () {
  346. sinon.stub(Em.run, 'once', Em.K);
  347. });
  348. afterEach(function () {
  349. Em.run.once.restore();
  350. });
  351. it("should clear dependent configs", function() {
  352. mainServiceInfoConfigsController.set('groupsToSave', { HDFS: 'my cool group'});
  353. mainServiceInfoConfigsController.set('_dependentConfigValues', Em.A([{name: 'prop_1'}]));
  354. mainServiceInfoConfigsController.doCancel();
  355. expect(App.isEmptyObject(mainServiceInfoConfigsController.get('_dependentConfigValues'))).to.be.true;
  356. });
  357. });
  358. describe("#putChangedConfigurations", function () {
  359. var sc = [
  360. Em.Object.create({
  361. configs: [
  362. Em.Object.create({
  363. name: '_heapsize',
  364. value: '1024m'
  365. }),
  366. Em.Object.create({
  367. name: '_newsize',
  368. value: '1024m'
  369. }),
  370. Em.Object.create({
  371. name: '_maxnewsize',
  372. value: '1024m'
  373. })
  374. ]
  375. })
  376. ],
  377. scExc = [
  378. Em.Object.create({
  379. configs: [
  380. Em.Object.create({
  381. name: 'hadoop_heapsize',
  382. value: '1024m'
  383. }),
  384. Em.Object.create({
  385. name: 'yarn_heapsize',
  386. value: '1024m'
  387. }),
  388. Em.Object.create({
  389. name: 'nodemanager_heapsize',
  390. value: '1024m'
  391. }),
  392. Em.Object.create({
  393. name: 'resourcemanager_heapsize',
  394. value: '1024m'
  395. }),
  396. Em.Object.create({
  397. name: 'apptimelineserver_heapsize',
  398. value: '1024m'
  399. }),
  400. Em.Object.create({
  401. name: 'jobhistory_heapsize',
  402. value: '1024m'
  403. })
  404. ]
  405. })
  406. ];
  407. beforeEach(function () {
  408. sinon.stub(App.router, 'getClusterName', function() {
  409. return 'clName';
  410. });
  411. sinon.stub(App.ajax, "send", Em.K);
  412. });
  413. afterEach(function () {
  414. App.ajax.send.restore();
  415. App.router.getClusterName.restore();
  416. });
  417. it("ajax request to put cluster cfg", function () {
  418. mainServiceInfoConfigsController.set('stepConfigs', sc);
  419. expect(mainServiceInfoConfigsController.putChangedConfigurations([]));
  420. expect(App.ajax.send.calledOnce).to.be.true;
  421. });
  422. it('values should be parsed', function () {
  423. mainServiceInfoConfigsController.set('stepConfigs', sc);
  424. mainServiceInfoConfigsController.putChangedConfigurations([]);
  425. expect(mainServiceInfoConfigsController.get('stepConfigs')[0].get('configs').mapProperty('value').uniq()).to.eql(['1024m']);
  426. });
  427. it('values should not be parsed', function () {
  428. mainServiceInfoConfigsController.set('stepConfigs', scExc);
  429. mainServiceInfoConfigsController.putChangedConfigurations([]);
  430. expect(mainServiceInfoConfigsController.get('stepConfigs')[0].get('configs').mapProperty('value').uniq()).to.eql(['1024m']);
  431. });
  432. });
  433. describe("#isDirChanged", function() {
  434. describe("when service name is HDFS", function() {
  435. beforeEach(function() {
  436. mainServiceInfoConfigsController.set('content', Ember.Object.create ({ serviceName: 'HDFS' }));
  437. });
  438. describe("for hadoop 2", function() {
  439. var tests = [
  440. {
  441. it: "should set dirChanged to false if none of the properties exist",
  442. expect: false,
  443. config: Ember.Object.create ({})
  444. },
  445. {
  446. it: "should set dirChanged to true if dfs.namenode.name.dir is not default",
  447. expect: true,
  448. config: Ember.Object.create ({
  449. name: 'dfs.namenode.name.dir',
  450. isNotDefaultValue: true
  451. })
  452. },
  453. {
  454. it: "should set dirChanged to false if dfs.namenode.name.dir is default",
  455. expect: false,
  456. config: Ember.Object.create ({
  457. name: 'dfs.namenode.name.dir',
  458. isNotDefaultValue: false
  459. })
  460. },
  461. {
  462. it: "should set dirChanged to true if dfs.namenode.checkpoint.dir is not default",
  463. expect: true,
  464. config: Ember.Object.create ({
  465. name: 'dfs.namenode.checkpoint.dir',
  466. isNotDefaultValue: true
  467. })
  468. },
  469. {
  470. it: "should set dirChanged to false if dfs.namenode.checkpoint.dir is default",
  471. expect: false,
  472. config: Ember.Object.create ({
  473. name: 'dfs.namenode.checkpoint.dir',
  474. isNotDefaultValue: false
  475. })
  476. },
  477. {
  478. it: "should set dirChanged to true if dfs.datanode.data.dir is not default",
  479. expect: true,
  480. config: Ember.Object.create ({
  481. name: 'dfs.datanode.data.dir',
  482. isNotDefaultValue: true
  483. })
  484. },
  485. {
  486. it: "should set dirChanged to false if dfs.datanode.data.dir is default",
  487. expect: false,
  488. config: Ember.Object.create ({
  489. name: 'dfs.datanode.data.dir',
  490. isNotDefaultValue: false
  491. })
  492. }
  493. ];
  494. beforeEach(function() {
  495. sinon.stub(App, 'get').returns(true);
  496. });
  497. afterEach(function() {
  498. App.get.restore();
  499. });
  500. tests.forEach(function(test) {
  501. it(test.it, function() {
  502. mainServiceInfoConfigsController.set('stepConfigs', [Ember.Object.create ({ configs: [test.config], serviceName: 'HDFS' })]);
  503. expect(mainServiceInfoConfigsController.isDirChanged()).to.equal(test.expect);
  504. })
  505. });
  506. });
  507. });
  508. });
  509. describe("#formatConfigValues", function () {
  510. var t = {
  511. configs: [
  512. Em.Object.create({ name: "p1", value: " v1 v1 ", displayType: "" }),
  513. Em.Object.create({ name: "p2", value: true, displayType: "" }),
  514. Em.Object.create({ name: "p3", value: " d1 ", displayType: "directory" }),
  515. Em.Object.create({ name: "p4", value: " d1 d2 d3 ", displayType: "directories" }),
  516. Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
  517. Em.Object.create({ name: "p6", value: " v ", displayType: "host" }),
  518. Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1 ", displayType: "string" }),
  519. Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1 ", displayType: "string" })
  520. ],
  521. result: [
  522. Em.Object.create({ name: "p1", value: " v1 v1", displayType: "" }),
  523. Em.Object.create({ name: "p2", value: "true", displayType: "" }),
  524. Em.Object.create({ name: "p3", value: "d1", displayType: "directory" }),
  525. Em.Object.create({ name: "p4", value: "d1,d2,d3", displayType: "directories" }),
  526. Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
  527. Em.Object.create({ name: "p6", value: "v", displayType: "host" }),
  528. Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1", displayType: "string" }),
  529. Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1", displayType: "string" })
  530. ]
  531. };
  532. it("format config values", function () {
  533. mainServiceInfoConfigsController.formatConfigValues(t.configs);
  534. expect(t.configs).to.deep.equal(t.result);
  535. });
  536. });
  537. describe("#putConfigGroupChanges", function() {
  538. var t = {
  539. data: {
  540. ConfigGroup: {
  541. id: "id"
  542. }
  543. },
  544. request: [{
  545. ConfigGroup: {
  546. id: "id"
  547. }
  548. }]
  549. };
  550. beforeEach(function() {
  551. sinon.spy($,"ajax");
  552. });
  553. afterEach(function() {
  554. $.ajax.restore();
  555. });
  556. it("updates configs groups", function() {
  557. mainServiceInfoConfigsController.putConfigGroupChanges(t.data);
  558. expect(JSON.parse($.ajax.args[0][0].data)).to.deep.equal(t.request);
  559. });
  560. });
  561. describe("#checkOverrideProperty", function () {
  562. var tests = [{
  563. overrideToAdd: {
  564. name: "name1",
  565. filename: "filename1"
  566. },
  567. componentConfig: {
  568. configs: [
  569. {
  570. name: "name1",
  571. filename: "filename2"
  572. },
  573. {
  574. name: "name1",
  575. filename: "filename1"
  576. }
  577. ]
  578. },
  579. add: true,
  580. m: "add property"
  581. },
  582. {
  583. overrideToAdd: {
  584. name: "name1"
  585. },
  586. componentConfig: {
  587. configs: [
  588. {
  589. name: "name2"
  590. }
  591. ]
  592. },
  593. add: false,
  594. m: "don't add property, different names"
  595. },
  596. {
  597. overrideToAdd: {
  598. name: "name1",
  599. filename: "filename1"
  600. },
  601. componentConfig: {
  602. configs: [
  603. {
  604. name: "name1",
  605. filename: "filename2"
  606. }
  607. ]
  608. },
  609. add: false,
  610. m: "don't add property, different filenames"
  611. },
  612. {
  613. overrideToAdd: null,
  614. componentConfig: {},
  615. add: false,
  616. m: "don't add property, overrideToAdd is null"
  617. }];
  618. beforeEach(function() {
  619. sinon.stub(App.config,"createOverride", Em.K)
  620. });
  621. afterEach(function() {
  622. App.config.createOverride.restore();
  623. });
  624. tests.forEach(function(t) {
  625. it(t.m, function() {
  626. mainServiceInfoConfigsController.set("overrideToAdd", t.overrideToAdd);
  627. mainServiceInfoConfigsController.checkOverrideProperty(t.componentConfig);
  628. if(t.add) {
  629. expect(App.config.createOverride.calledWith(t.overrideToAdd)).to.equal(true);
  630. expect(mainServiceInfoConfigsController.get("overrideToAdd")).to.equal(null);
  631. } else {
  632. expect(App.config.createOverride.calledOnce).to.equal(false);
  633. }
  634. });
  635. });
  636. });
  637. describe("#trackRequest()", function () {
  638. after(function(){
  639. mainServiceInfoConfigsController.get('requestsInProgress').clear();
  640. });
  641. it("should set requestsInProgress", function () {
  642. mainServiceInfoConfigsController.get('requestsInProgress').clear();
  643. mainServiceInfoConfigsController.trackRequest({'request': {}});
  644. expect(mainServiceInfoConfigsController.get('requestsInProgress')[0]).to.eql({'request': {}});
  645. });
  646. });
  647. describe("#setCompareDefaultGroupConfig", function() {
  648. beforeEach(function() {
  649. sinon.stub(mainServiceInfoConfigsController, "getComparisonConfig").returns("compConfig");
  650. sinon.stub(mainServiceInfoConfigsController, "getMockComparisonConfig").returns("mockConfig");
  651. sinon.stub(mainServiceInfoConfigsController, "hasCompareDiffs").returns(true);
  652. });
  653. afterEach(function() {
  654. mainServiceInfoConfigsController.getComparisonConfig.restore();
  655. mainServiceInfoConfigsController.getMockComparisonConfig.restore();
  656. mainServiceInfoConfigsController.hasCompareDiffs.restore();
  657. });
  658. it("empty service config passed, expect that setCompareDefaultGroupConfig will not run anything", function() {
  659. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({}).compareConfigs.length).to.equal(0);
  660. });
  661. it("empty service config and comparison passed, expect that setCompareDefaultGroupConfig will not run anything", function() {
  662. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({},{}).compareConfigs).to.eql(["compConfig"]);
  663. });
  664. it("expect that serviceConfig.compareConfigs will be getMockComparisonConfig", function() {
  665. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isUserProperty: true}, null)).to.eql({compareConfigs: ["mockConfig"], isUserProperty: true, isComparison: true, hasCompareDiffs: true});
  666. });
  667. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  668. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isUserProperty: true}, {})).to.eql({compareConfigs: ["compConfig"], isUserProperty: true, isComparison: true, hasCompareDiffs: true});
  669. });
  670. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  671. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isReconfigurable: true}, {})).to.eql({compareConfigs: ["compConfig"], isReconfigurable: true, isComparison: true, hasCompareDiffs: true});
  672. });
  673. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  674. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isReconfigurable: true, isMock: true}, {})).to.eql({compareConfigs: ["compConfig"], isReconfigurable: true, isMock: true, isComparison: true, hasCompareDiffs: true});
  675. });
  676. it("property was created during upgrade and have no comparison, compare with 'Undefined' value should be created", function() {
  677. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({name: 'prop1', isUserProperty: false}, null)).to.eql({
  678. name: 'prop1', isUserProperty: false, compareConfigs: ["mockConfig"],
  679. isComparison: true, hasCompareDiffs: true
  680. });
  681. });
  682. });
  683. describe('#showSaveConfigsPopup', function () {
  684. var bodyView;
  685. describe('#bodyClass', function () {
  686. beforeEach(function() {
  687. sinon.stub(App.StackService, 'find').returns([{dependentServiceNames: []}]);
  688. sinon.stub(App.ajax, 'send', Em.K);
  689. // default implementation
  690. bodyView = mainServiceInfoConfigsController.showSaveConfigsPopup().get('bodyClass').create({
  691. parentView: Em.View.create()
  692. });
  693. });
  694. afterEach(function() {
  695. App.ajax.send.restore();
  696. App.StackService.find.restore();
  697. });
  698. describe('#componentsFilterSuccessCallback', function () {
  699. it('check components with unknown state', function () {
  700. bodyView = mainServiceInfoConfigsController.showSaveConfigsPopup('', true, '', {}, '', 'unknown', '').get('bodyClass').create({
  701. parentView: Em.View.create()
  702. });
  703. bodyView.componentsFilterSuccessCallback({
  704. items: [
  705. {
  706. ServiceComponentInfo: {
  707. total_count: 4,
  708. started_count: 2,
  709. installed_count: 1,
  710. component_name: 'c1'
  711. },
  712. host_components: [
  713. {HostRoles: {host_name: 'h1'}}
  714. ]
  715. }
  716. ]
  717. });
  718. var unknownHosts = bodyView.get('unknownHosts');
  719. expect(unknownHosts.length).to.equal(1);
  720. expect(unknownHosts[0]).to.eql({name: 'h1', components: 'C1'});
  721. });
  722. });
  723. });
  724. });
  725. describe('#errorsCount', function () {
  726. it('should ignore configs with widgets (enhanced configs)', function () {
  727. mainServiceInfoConfigsController.reopen({selectedService: Em.Object.create({
  728. configsWithErrors: Em.A([
  729. Em.Object.create({widget: {}}),
  730. Em.Object.create({widget: null})
  731. ])
  732. })});
  733. expect(mainServiceInfoConfigsController.get('errorsCount')).to.equal(1);
  734. });
  735. });
  736. describe('#_onLoadComplete', function () {
  737. beforeEach(function () {
  738. sinon.stub(Em.run, 'next', Em.K);
  739. mainServiceInfoConfigsController.setProperties({
  740. dataIsLoaded: false,
  741. versionLoaded: false,
  742. isInit: true
  743. });
  744. });
  745. afterEach(function () {
  746. Em.run.next.restore();
  747. });
  748. it('should update flags', function () {
  749. mainServiceInfoConfigsController._onLoadComplete();
  750. expect(mainServiceInfoConfigsController.get('dataIsLoaded')).to.be.true;
  751. expect(mainServiceInfoConfigsController.get('versionLoaded')).to.be.true;
  752. expect(mainServiceInfoConfigsController.get('isInit')).to.be.false;
  753. });
  754. });
  755. describe('#hasCompareDiffs', function () {
  756. it('should return false for `password`-configs', function () {
  757. var hasCompareDiffs = mainServiceInfoConfigsController.hasCompareDiffs({displayType: 'password'}, {});
  758. expect(hasCompareDiffs).to.be.false;
  759. });
  760. });
  761. });