config_test.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('controllers/main/service/info/configs');
  20. var batchUtils = require('utils/batch_scheduled_requests');
  21. var mainServiceInfoConfigsController = null;
  22. describe("App.MainServiceInfoConfigsController", function () {
  23. beforeEach(function () {
  24. sinon.stub(App.themesMapper, 'generateAdvancedTabs').returns(Em.K);
  25. mainServiceInfoConfigsController = App.MainServiceInfoConfigsController.create({
  26. dependentServiceNames: [],
  27. loadDependentConfigs: function () {
  28. return {done: Em.K}
  29. },
  30. loadConfigTheme: function () {
  31. return $.Deferred().resolve().promise();
  32. }
  33. });
  34. });
  35. afterEach(function() {
  36. App.themesMapper.generateAdvancedTabs.restore();
  37. });
  38. describe("#showSavePopup", function () {
  39. var tests = [
  40. {
  41. path: false,
  42. callback: null,
  43. action: "onSave",
  44. m: "save configs without path/callback",
  45. results: [
  46. {
  47. method: "restartServicePopup",
  48. called: true
  49. }
  50. ]
  51. },
  52. {
  53. path: true,
  54. callback: true,
  55. action: "onSave",
  56. m: "save configs with path/callback",
  57. results: [
  58. {
  59. method: "restartServicePopup",
  60. called: true
  61. }
  62. ]
  63. },
  64. {
  65. path: false,
  66. callback: false,
  67. action: "onDiscard",
  68. m: "discard changes without path/callback",
  69. results: [
  70. {
  71. method: "restartServicePopup",
  72. called: false
  73. }
  74. ]
  75. },
  76. {
  77. path: false,
  78. callback: true,
  79. action: "onDiscard",
  80. m: "discard changes with callback",
  81. results: [
  82. {
  83. method: "restartServicePopup",
  84. called: false
  85. },
  86. {
  87. method: "callback",
  88. called: true
  89. },
  90. {
  91. field: "hash",
  92. value: "hash"
  93. }
  94. ]
  95. },
  96. {
  97. path: true,
  98. callback: null,
  99. action: "onDiscard",
  100. m: "discard changes with path",
  101. results: [
  102. {
  103. method: "restartServicePopup",
  104. called: false
  105. },
  106. {
  107. field: "forceTransition",
  108. value: true
  109. }
  110. ]
  111. }
  112. ];
  113. beforeEach(function () {
  114. sinon.stub(mainServiceInfoConfigsController, "get", function(key) {
  115. return key == 'isSubmitDisabled' ? false : Em.get(mainServiceInfoConfigsController, key);
  116. });
  117. sinon.stub(mainServiceInfoConfigsController, "restartServicePopup", Em.K);
  118. sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
  119. return "hash"
  120. });
  121. sinon.stub(App.router, "route", Em.K);
  122. });
  123. afterEach(function () {
  124. mainServiceInfoConfigsController.get.restore();
  125. mainServiceInfoConfigsController.restartServicePopup.restore();
  126. mainServiceInfoConfigsController.getHash.restore();
  127. App.router.route.restore();
  128. });
  129. tests.forEach(function (t) {
  130. t.results.forEach(function (r) {
  131. it(t.m + " " + r.method + " " + r.field, function () {
  132. if (t.callback) {
  133. t.callback = sinon.stub();
  134. }
  135. mainServiceInfoConfigsController.showSavePopup(t.path, t.callback)[t.action]();
  136. if (r.method) {
  137. if (r.method === 'callback') {
  138. expect(t.callback.calledOnce).to.equal(r.called);
  139. } else {
  140. expect(mainServiceInfoConfigsController[r.method].calledOnce).to.equal(r.called);
  141. }
  142. } else if (r.field) {
  143. expect(mainServiceInfoConfigsController.get(r.field)).to.equal(r.value);
  144. }
  145. }, this);
  146. });
  147. }, this);
  148. });
  149. describe("#hasUnsavedChanges", function () {
  150. var cases = [
  151. {
  152. hash: null,
  153. hasUnsavedChanges: false,
  154. title: 'configs not rendered'
  155. },
  156. {
  157. hash: 'hash1',
  158. hasUnsavedChanges: true,
  159. title: 'with unsaved'
  160. },
  161. {
  162. hash: 'hash',
  163. hasUnsavedChanges: false,
  164. title: 'without unsaved'
  165. }
  166. ];
  167. beforeEach(function () {
  168. sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
  169. return "hash"
  170. });
  171. });
  172. afterEach(function () {
  173. mainServiceInfoConfigsController.getHash.restore();
  174. });
  175. cases.forEach(function (item) {
  176. it(item.title, function () {
  177. mainServiceInfoConfigsController.set('hash', item.hash);
  178. expect(mainServiceInfoConfigsController.hasUnsavedChanges()).to.equal(item.hasUnsavedChanges);
  179. });
  180. });
  181. });
  182. describe("#showComponentsShouldBeRestarted", function () {
  183. var tests = [
  184. {
  185. input: {
  186. context: {
  187. restartRequiredHostsAndComponents: {
  188. 'publicHostName1': ['TaskTracker'],
  189. 'publicHostName2': ['JobTracker', 'TaskTracker']
  190. }
  191. }
  192. },
  193. components: "2 TaskTrackers, 1 JobTracker",
  194. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.components'))
  195. },
  196. {
  197. input: {
  198. context: {
  199. restartRequiredHostsAndComponents: {
  200. 'publicHostName1': ['TaskTracker']
  201. }
  202. }
  203. },
  204. components: "1 TaskTracker",
  205. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.component'))
  206. }
  207. ];
  208. beforeEach(function () {
  209. sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
  210. });
  211. afterEach(function () {
  212. mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
  213. });
  214. tests.forEach(function (t) {
  215. it("trigger showItemsShouldBeRestarted popup with components", function () {
  216. mainServiceInfoConfigsController.showComponentsShouldBeRestarted(t.input);
  217. expect(mainServiceInfoConfigsController.showItemsShouldBeRestarted.calledWith(t.components, t.text)).to.equal(true);
  218. });
  219. });
  220. });
  221. describe("#showHostsShouldBeRestarted", function () {
  222. var tests = [
  223. {
  224. input: {
  225. context: {
  226. restartRequiredHostsAndComponents: {
  227. 'publicHostName1': ['TaskTracker'],
  228. 'publicHostName2': ['JobTracker', 'TaskTracker']
  229. }
  230. }
  231. },
  232. hosts: "publicHostName1, publicHostName2",
  233. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.hosts'))
  234. },
  235. {
  236. input: {
  237. context: {
  238. restartRequiredHostsAndComponents: {
  239. 'publicHostName1': ['TaskTracker']
  240. }
  241. }
  242. },
  243. hosts: "publicHostName1",
  244. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.host'))
  245. }
  246. ];
  247. beforeEach(function () {
  248. sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
  249. });
  250. afterEach(function () {
  251. mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
  252. });
  253. tests.forEach(function (t) {
  254. it("trigger showItemsShouldBeRestarted popup with hosts", function () {
  255. mainServiceInfoConfigsController.showHostsShouldBeRestarted(t.input);
  256. expect(mainServiceInfoConfigsController.showItemsShouldBeRestarted.calledWith(t.hosts, t.text)).to.equal(true);
  257. });
  258. });
  259. });
  260. describe("#rollingRestartStaleConfigSlaveComponents", function () {
  261. var tests = [
  262. {
  263. componentName: {
  264. context: "ComponentName"
  265. },
  266. displayName: "displayName",
  267. passiveState: "ON"
  268. },
  269. {
  270. componentName: {
  271. context: "ComponentName1"
  272. },
  273. displayName: "displayName1",
  274. passiveState: "OFF"
  275. }
  276. ];
  277. beforeEach(function () {
  278. mainServiceInfoConfigsController.set("content", {displayName: "", passiveState: ""});
  279. sinon.stub(batchUtils, "launchHostComponentRollingRestart", Em.K);
  280. });
  281. afterEach(function () {
  282. batchUtils.launchHostComponentRollingRestart.restore();
  283. });
  284. tests.forEach(function (t) {
  285. it("trigger rollingRestartStaleConfigSlaveComponents", function () {
  286. mainServiceInfoConfigsController.set("content.displayName", t.displayName);
  287. mainServiceInfoConfigsController.set("content.passiveState", t.passiveState);
  288. mainServiceInfoConfigsController.rollingRestartStaleConfigSlaveComponents(t.componentName);
  289. expect(batchUtils.launchHostComponentRollingRestart.calledWith(t.componentName.context, t.displayName, t.passiveState == "ON", true)).to.equal(true);
  290. });
  291. });
  292. });
  293. describe("#restartAllStaleConfigComponents", function () {
  294. beforeEach(function () {
  295. sinon.stub(batchUtils, "restartAllServiceHostComponents", Em.K);
  296. });
  297. afterEach(function () {
  298. batchUtils.restartAllServiceHostComponents.restore();
  299. });
  300. it("trigger restartAllServiceHostComponents", function () {
  301. mainServiceInfoConfigsController.restartAllStaleConfigComponents().onPrimary();
  302. expect(batchUtils.restartAllServiceHostComponents.calledOnce).to.equal(true);
  303. });
  304. });
  305. describe("#doCancel", function () {
  306. beforeEach(function () {
  307. sinon.stub(Em.run, 'once', Em.K);
  308. });
  309. afterEach(function () {
  310. Em.run.once.restore();
  311. });
  312. it("should clear dependent configs", function() {
  313. mainServiceInfoConfigsController.set('groupsToSave', { HDFS: 'my cool group'});
  314. mainServiceInfoConfigsController.set('_dependentConfigValues', Em.A([{name: 'prop_1'}]));
  315. mainServiceInfoConfigsController.doCancel();
  316. expect(App.isEmptyObject(mainServiceInfoConfigsController.get('_dependentConfigValues'))).to.be.true;
  317. });
  318. });
  319. describe("#getMasterComponentHostValue", function () {
  320. var tests = [
  321. {
  322. content: {
  323. hostComponents: [
  324. Em.Object.create({
  325. componentName: "componentName1",
  326. hostName: "hostName"
  327. })
  328. ]
  329. },
  330. result: "hostName",
  331. multiple: false,
  332. m: "returns hostname"
  333. },
  334. {
  335. content: {
  336. hostComponents: [
  337. Em.Object.create({
  338. componentName: "componentName2",
  339. hostName: "hostName1"
  340. }),
  341. Em.Object.create({
  342. componentName: "componentName2",
  343. hostName: "hostName2"
  344. })
  345. ]
  346. },
  347. result: ["hostName1","hostName2"],
  348. multiple: true,
  349. m: "returns hostnames"
  350. }
  351. ];
  352. tests.forEach(function(t){
  353. it(t.m, function () {
  354. sinon.stub(App.HostComponent, 'find', function(){
  355. return t.content.hostComponents;
  356. });
  357. expect(mainServiceInfoConfigsController.getMasterComponentHostValue(t.content.hostComponents[0].componentName, t.multiple)).to.eql(t.result);
  358. App.HostComponent.find.restore();
  359. });
  360. });
  361. });
  362. describe("#putChangedConfigurations", function () {
  363. var sc = [
  364. Em.Object.create({
  365. configs: [
  366. Em.Object.create({
  367. name: '_heapsize',
  368. value: '1024m'
  369. }),
  370. Em.Object.create({
  371. name: '_newsize',
  372. value: '1024m'
  373. }),
  374. Em.Object.create({
  375. name: '_maxnewsize',
  376. value: '1024m'
  377. })
  378. ]
  379. })
  380. ],
  381. scExc = [
  382. Em.Object.create({
  383. configs: [
  384. Em.Object.create({
  385. name: 'hadoop_heapsize',
  386. value: '1024m'
  387. }),
  388. Em.Object.create({
  389. name: 'yarn_heapsize',
  390. value: '1024m'
  391. }),
  392. Em.Object.create({
  393. name: 'nodemanager_heapsize',
  394. value: '1024m'
  395. }),
  396. Em.Object.create({
  397. name: 'resourcemanager_heapsize',
  398. value: '1024m'
  399. }),
  400. Em.Object.create({
  401. name: 'apptimelineserver_heapsize',
  402. value: '1024m'
  403. }),
  404. Em.Object.create({
  405. name: 'jobhistory_heapsize',
  406. value: '1024m'
  407. })
  408. ]
  409. })
  410. ];
  411. beforeEach(function () {
  412. sinon.stub(App.router, 'getClusterName', function() {
  413. return 'clName';
  414. });
  415. sinon.stub(App.ajax, "send", Em.K);
  416. });
  417. afterEach(function () {
  418. App.ajax.send.restore();
  419. App.router.getClusterName.restore();
  420. });
  421. it("ajax request to put cluster cfg", function () {
  422. mainServiceInfoConfigsController.set('stepConfigs', sc);
  423. expect(mainServiceInfoConfigsController.putChangedConfigurations([]));
  424. expect(App.ajax.send.calledOnce).to.be.true;
  425. });
  426. it('values should be parsed', function () {
  427. mainServiceInfoConfigsController.set('stepConfigs', sc);
  428. mainServiceInfoConfigsController.putChangedConfigurations([]);
  429. expect(mainServiceInfoConfigsController.get('stepConfigs')[0].get('configs').mapProperty('value').uniq()).to.eql(['1024m']);
  430. });
  431. it('values should not be parsed', function () {
  432. mainServiceInfoConfigsController.set('stepConfigs', scExc);
  433. mainServiceInfoConfigsController.putChangedConfigurations([]);
  434. expect(mainServiceInfoConfigsController.get('stepConfigs')[0].get('configs').mapProperty('value').uniq()).to.eql(['1024m']);
  435. });
  436. });
  437. describe("#isConfigChanged", function () {
  438. var tests = [
  439. {
  440. loadedConfig: {
  441. apptimelineserver_heapsize: "1024",
  442. hbase_log_dir: "/var/log/hbase",
  443. lzo_enabled: "true"
  444. },
  445. savingConfig: {
  446. apptimelineserver_heapsize: "1024",
  447. hbase_log_dir: "/var/log/hbase",
  448. lzo_enabled: "true"
  449. },
  450. m: "configs doesn't changed",
  451. res: false
  452. },
  453. {
  454. loadedConfig: {
  455. apptimelineserver_heapsize: "1024",
  456. hbase_log_dir: "/var/log/hbase",
  457. lzo_enabled: "true"
  458. },
  459. savingConfig: {
  460. apptimelineserver_heapsize: "1024",
  461. hbase_log_dir: "/var/log/hbase",
  462. lzo_enabled: "false"
  463. },
  464. m: "configs changed",
  465. res: true
  466. },
  467. {
  468. loadedConfig: {
  469. apptimelineserver_heapsize: "1024",
  470. hbase_log_dir: "/var/log/hbase"
  471. },
  472. savingConfig: {
  473. apptimelineserver_heapsize: "1024",
  474. hbase_log_dir: "/var/log/hbase",
  475. lzo_enabled: "false"
  476. },
  477. m: "add new config",
  478. res: true
  479. }
  480. ];
  481. tests.forEach(function(t){
  482. it(t.m, function () {
  483. expect(mainServiceInfoConfigsController.isConfigChanged(t.loadedConfig, t.savingConfig)).to.equal(t.res);
  484. });
  485. });
  486. });
  487. describe("#isDirChanged", function() {
  488. describe("when service name is HDFS", function() {
  489. beforeEach(function() {
  490. mainServiceInfoConfigsController.set('content', Ember.Object.create ({ serviceName: 'HDFS' }));
  491. });
  492. describe("for hadoop 2", function() {
  493. var tests = [
  494. {
  495. it: "should set dirChanged to false if none of the properties exist",
  496. expect: false,
  497. config: Ember.Object.create ({})
  498. },
  499. {
  500. it: "should set dirChanged to true if dfs.namenode.name.dir is not default",
  501. expect: true,
  502. config: Ember.Object.create ({
  503. name: 'dfs.namenode.name.dir',
  504. isNotDefaultValue: true
  505. })
  506. },
  507. {
  508. it: "should set dirChanged to false if dfs.namenode.name.dir is default",
  509. expect: false,
  510. config: Ember.Object.create ({
  511. name: 'dfs.namenode.name.dir',
  512. isNotDefaultValue: false
  513. })
  514. },
  515. {
  516. it: "should set dirChanged to true if dfs.namenode.checkpoint.dir is not default",
  517. expect: true,
  518. config: Ember.Object.create ({
  519. name: 'dfs.namenode.checkpoint.dir',
  520. isNotDefaultValue: true
  521. })
  522. },
  523. {
  524. it: "should set dirChanged to false if dfs.namenode.checkpoint.dir is default",
  525. expect: false,
  526. config: Ember.Object.create ({
  527. name: 'dfs.namenode.checkpoint.dir',
  528. isNotDefaultValue: false
  529. })
  530. },
  531. {
  532. it: "should set dirChanged to true if dfs.datanode.data.dir is not default",
  533. expect: true,
  534. config: Ember.Object.create ({
  535. name: 'dfs.datanode.data.dir',
  536. isNotDefaultValue: true
  537. })
  538. },
  539. {
  540. it: "should set dirChanged to false if dfs.datanode.data.dir is default",
  541. expect: false,
  542. config: Ember.Object.create ({
  543. name: 'dfs.datanode.data.dir',
  544. isNotDefaultValue: false
  545. })
  546. }
  547. ];
  548. beforeEach(function() {
  549. sinon.stub(App, 'get').returns(true);
  550. });
  551. afterEach(function() {
  552. App.get.restore();
  553. });
  554. tests.forEach(function(test) {
  555. it(test.it, function() {
  556. mainServiceInfoConfigsController.set('stepConfigs', [Ember.Object.create ({ configs: [test.config], serviceName: 'HDFS' })]);
  557. expect(mainServiceInfoConfigsController.isDirChanged()).to.equal(test.expect);
  558. })
  559. });
  560. });
  561. });
  562. });
  563. describe("#formatConfigValues", function () {
  564. var t = {
  565. configs: [
  566. Em.Object.create({ name: "p1", value: " v1 v1 ", displayType: "" }),
  567. Em.Object.create({ name: "p2", value: true, displayType: "" }),
  568. Em.Object.create({ name: "p3", value: " d1 ", displayType: "directory" }),
  569. Em.Object.create({ name: "p4", value: " d1 d2 d3 ", displayType: "directories" }),
  570. Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
  571. Em.Object.create({ name: "p6", value: " v ", displayType: "host" }),
  572. Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1 ", displayType: "advanced" }),
  573. Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1 ", displayType: "advanced" })
  574. ],
  575. result: [
  576. Em.Object.create({ name: "p1", value: " v1 v1", displayType: "" }),
  577. Em.Object.create({ name: "p2", value: "true", displayType: "" }),
  578. Em.Object.create({ name: "p3", value: "d1", displayType: "directory" }),
  579. Em.Object.create({ name: "p4", value: "d1,d2,d3", displayType: "directories" }),
  580. Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
  581. Em.Object.create({ name: "p6", value: "v", displayType: "host" }),
  582. Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1", displayType: "advanced" }),
  583. Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1", displayType: "advanced" })
  584. ]
  585. };
  586. it("format config values", function () {
  587. mainServiceInfoConfigsController.formatConfigValues(t.configs);
  588. expect(t.configs).to.deep.equal(t.result);
  589. });
  590. });
  591. describe("#putConfigGroupChanges", function() {
  592. var t = {
  593. data: {
  594. ConfigGroup: {
  595. id: "id"
  596. }
  597. },
  598. request: [{
  599. ConfigGroup: {
  600. id: "id"
  601. }
  602. }]
  603. };
  604. beforeEach(function() {
  605. sinon.spy($,"ajax");
  606. });
  607. afterEach(function() {
  608. $.ajax.restore();
  609. });
  610. it("updates configs groups", function() {
  611. mainServiceInfoConfigsController.putConfigGroupChanges(t.data);
  612. expect(JSON.parse($.ajax.args[0][0].data)).to.deep.equal(t.request);
  613. });
  614. });
  615. describe("#checkOverrideProperty", function () {
  616. var tests = [{
  617. overrideToAdd: {
  618. name: "name1",
  619. filename: "filename1"
  620. },
  621. componentConfig: {
  622. configs: [
  623. {
  624. name: "name1",
  625. filename: "filename2"
  626. },
  627. {
  628. name: "name1",
  629. filename: "filename1"
  630. }
  631. ]
  632. },
  633. add: true,
  634. m: "add property"
  635. },
  636. {
  637. overrideToAdd: {
  638. name: "name1"
  639. },
  640. componentConfig: {
  641. configs: [
  642. {
  643. name: "name2"
  644. }
  645. ]
  646. },
  647. add: false,
  648. m: "don't add property, different names"
  649. },
  650. {
  651. overrideToAdd: {
  652. name: "name1",
  653. filename: "filename1"
  654. },
  655. componentConfig: {
  656. configs: [
  657. {
  658. name: "name1",
  659. filename: "filename2"
  660. }
  661. ]
  662. },
  663. add: false,
  664. m: "don't add property, different filenames"
  665. },
  666. {
  667. overrideToAdd: null,
  668. componentConfig: {},
  669. add: false,
  670. m: "don't add property, overrideToAdd is null"
  671. }];
  672. beforeEach(function() {
  673. sinon.stub(App.config,"createOverride", Em.K)
  674. });
  675. afterEach(function() {
  676. App.config.createOverride.restore();
  677. });
  678. tests.forEach(function(t) {
  679. it(t.m, function() {
  680. mainServiceInfoConfigsController.set("overrideToAdd", t.overrideToAdd);
  681. mainServiceInfoConfigsController.checkOverrideProperty(t.componentConfig);
  682. if(t.add) {
  683. expect(App.config.createOverride.calledWith(t.overrideToAdd)).to.equal(true);
  684. expect(mainServiceInfoConfigsController.get("overrideToAdd")).to.equal(null);
  685. } else {
  686. expect(App.config.createOverride.calledOnce).to.equal(false);
  687. }
  688. });
  689. });
  690. });
  691. describe("#trackRequest()", function () {
  692. after(function(){
  693. mainServiceInfoConfigsController.get('requestsInProgress').clear();
  694. });
  695. it("should set requestsInProgress", function () {
  696. mainServiceInfoConfigsController.get('requestsInProgress').clear();
  697. mainServiceInfoConfigsController.trackRequest({'request': {}});
  698. expect(mainServiceInfoConfigsController.get('requestsInProgress')[0]).to.eql({'request': {}});
  699. });
  700. });
  701. describe("#setCompareDefaultGroupConfig", function() {
  702. beforeEach(function() {
  703. sinon.stub(mainServiceInfoConfigsController, "getComparisonConfig").returns("compConfig");
  704. sinon.stub(mainServiceInfoConfigsController, "getMockComparisonConfig").returns("mockConfig");
  705. sinon.stub(mainServiceInfoConfigsController, "hasCompareDiffs").returns(true);
  706. });
  707. afterEach(function() {
  708. mainServiceInfoConfigsController.getComparisonConfig.restore();
  709. mainServiceInfoConfigsController.getMockComparisonConfig.restore();
  710. mainServiceInfoConfigsController.hasCompareDiffs.restore();
  711. });
  712. it("empty service config passed, expect that setCompareDefaultGroupConfig will not run anything", function() {
  713. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({}).compareConfigs.length).to.equal(0);
  714. });
  715. it("empty service config and comparison passed, expect that setCompareDefaultGroupConfig will not run anything", function() {
  716. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({},{}).compareConfigs.length).to.equal(0);
  717. });
  718. it("expect that serviceConfig.compareConfigs will be getMockComparisonConfig", function() {
  719. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isUserProperty: true}, null)).to.eql({compareConfigs: ["mockConfig"], isUserProperty: true, isComparison: true, hasCompareDiffs: true});
  720. });
  721. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  722. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isUserProperty: true}, {})).to.eql({compareConfigs: ["compConfig"], isUserProperty: true, isComparison: true, hasCompareDiffs: true});
  723. });
  724. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  725. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isReconfigurable: true}, {})).to.eql({compareConfigs: ["compConfig"], isReconfigurable: true, isComparison: true, hasCompareDiffs: true});
  726. });
  727. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  728. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isReconfigurable: true, isMock: true}, {})).to.eql({compareConfigs: ["compConfig"], isReconfigurable: true, isMock: true, isComparison: true, hasCompareDiffs: true});
  729. });
  730. it("property was created during upgrade and have no comparison, compare with 'Undefined' value should be created", function() {
  731. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({name: 'prop1', isUserProperty: false}, null)).to.eql({
  732. name: 'prop1', isUserProperty: false, compareConfigs: ["mockConfig"],
  733. isComparison: true, hasCompareDiffs: true
  734. });
  735. });
  736. });
  737. describe('#showSaveConfigsPopup', function () {
  738. var bodyView;
  739. describe('#bodyClass', function () {
  740. beforeEach(function() {
  741. sinon.stub(App.ajax, 'send', Em.K);
  742. // default implementation
  743. bodyView = mainServiceInfoConfigsController.showSaveConfigsPopup().get('bodyClass').create({
  744. parentView: Em.View.create()
  745. });
  746. });
  747. afterEach(function() {
  748. App.ajax.send.restore();
  749. });
  750. describe('#componentsFilterSuccessCallback', function () {
  751. it('check components with unknown state', function () {
  752. bodyView = mainServiceInfoConfigsController.showSaveConfigsPopup('', true, '', {}, '', 'unknown', '').get('bodyClass').create({
  753. parentView: Em.View.create()
  754. });
  755. bodyView.componentsFilterSuccessCallback({
  756. items: [
  757. {
  758. ServiceComponentInfo: {
  759. total_count: 4,
  760. started_count: 2,
  761. installed_count: 1,
  762. component_name: 'c1'
  763. },
  764. host_components: [
  765. {HostRoles: {host_name: 'h1'}}
  766. ]
  767. }
  768. ]
  769. });
  770. var unknownHosts = bodyView.get('unknownHosts');
  771. expect(unknownHosts.length).to.equal(1);
  772. expect(unknownHosts[0]).to.eql({name: 'h1', components: 'C1'});
  773. });
  774. });
  775. });
  776. });
  777. describe('#setHiveHostName', function () {
  778. beforeEach(function () {
  779. sinon.stub(App.StackService, 'find').returns([
  780. {
  781. serviceName: 'HIVE'
  782. },
  783. {
  784. serviceName: 'OOZIE'
  785. }
  786. ]);
  787. });
  788. afterEach(function () {
  789. App.StackService.find.restore();
  790. });
  791. Em.A([
  792. {
  793. globals: [
  794. Em.Object.create({name: 'hive_database', value: 'New MySQL Database'}),
  795. Em.Object.create({name: 'hive_database_type', value: 'mysql'}),
  796. Em.Object.create({name: 'hive_ambari_host', value: 'h1'}),
  797. Em.Object.create({name: 'hive_hostname', value: 'h2'})
  798. ],
  799. removed: ['hive_existing_mysql_host', 'hive_existing_mysql_database', 'hive_existing_oracle_host', 'hive_existing_oracle_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database', 'hive_existing_mssql_server_database', 'hive_existing_mssql_server_host', 'hive_existing_mssql_server_2_database', 'hive_existing_mssql_server_2_host'],
  800. m: 'hive_database: New MySQL Database',
  801. host: 'h2'
  802. },
  803. {
  804. globals: [
  805. Em.Object.create({name: 'hive_database', value: 'New PostgreSQL Database'}),
  806. Em.Object.create({name: 'hive_database_type', value: 'mysql'}),
  807. Em.Object.create({name: 'hive_ambari_host', value: 'h1'}),
  808. Em.Object.create({name: 'hive_hostname', value: 'h2'})
  809. ],
  810. removed: ['hive_existing_mysql_host', 'hive_existing_mysql_database', 'hive_existing_oracle_host', 'hive_existing_oracle_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database', 'hive_existing_mssql_server_database', 'hive_existing_mssql_server_host', 'hive_existing_mssql_server_2_database', 'hive_existing_mssql_server_2_host'],
  811. m: 'hive_database: New PostgreSQL Database',
  812. host: 'h2'
  813. },
  814. {
  815. globals: [
  816. Em.Object.create({name: 'hive_database', value: 'Existing MySQL Database'}),
  817. Em.Object.create({name: 'hive_database_type', value: 'mysql'}),
  818. Em.Object.create({name: 'hive_existing_mysql_host', value: 'h1'}),
  819. Em.Object.create({name: 'hive_hostname', value: 'h2'})
  820. ],
  821. removed: ['hive_ambari_database', 'hive_existing_oracle_host', 'hive_existing_oracle_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database', 'hive_existing_mssql_server_database', 'hive_existing_mssql_server_host', 'hive_existing_mssql_server_2_database', 'hive_existing_mssql_server_2_host'],
  822. m: 'hive_database: Existing MySQL Database',
  823. host: 'h2'
  824. },
  825. {
  826. globals: [
  827. Em.Object.create({name: 'hive_database', value: 'Existing PostgreSQL Database'}),
  828. Em.Object.create({name: 'hive_database_type', value: 'postgresql'}),
  829. Em.Object.create({name: 'hive_existing_postgresql_host', value: 'h1'}),
  830. Em.Object.create({name: 'hive_hostname', value: 'h2'})
  831. ],
  832. removed: ['hive_ambari_database', 'hive_existing_mysql_host', 'hive_existing_mysql_database', 'hive_existing_oracle_host', 'hive_existing_oracle_database', 'hive_existing_mssql_server_database', 'hive_existing_mssql_server_host', 'hive_existing_mssql_server_2_database', 'hive_existing_mssql_server_2_host'],
  833. m: 'hive_database: Existing PostgreSQL Database',
  834. host: 'h2'
  835. },
  836. {
  837. globals: [
  838. Em.Object.create({name: 'hive_database', value: 'Existing Oracle Database'}),
  839. Em.Object.create({name: 'hive_database_type', value: 'oracle'}),
  840. Em.Object.create({name: 'hive_existing_oracle_host', value: 'h1'}),
  841. Em.Object.create({name: 'hive_hostname', value: 'h2'})
  842. ],
  843. removed: ['hive_ambari_database', 'hive_existing_mysql_host', 'hive_existing_mysql_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database', 'hive_existing_mssql_server_database', 'hive_existing_mssql_server_host', 'hive_existing_mssql_server_2_database', 'hive_existing_mssql_server_2_host'],
  844. m: 'hive_database: Existing Oracle Database',
  845. host: 'h2'
  846. },
  847. {
  848. globals: [
  849. Em.Object.create({name: 'hive_database', value: 'Existing MSSQL Server database with SQL authentication'}),
  850. Em.Object.create({name: 'hive_database_type', value: 'mssql'}),
  851. Em.Object.create({name: 'hive_existing_mssql_server_host', value: 'h1'}),
  852. Em.Object.create({name: 'hive_hostname', value: 'h2'})
  853. ],
  854. removed: ['hive_ambari_database', 'hive_existing_mysql_host', 'hive_existing_mysql_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database', 'hive_existing_oracle_host', 'hive_existing_oracle_database', 'hive_existing_mssql_server_2_database', 'hive_existing_mssql_server_2_host'],
  855. m: 'hive_database: Existing MSSQL Server database with SQL authentication',
  856. host: 'h2'
  857. },
  858. {
  859. globals: [
  860. Em.Object.create({name: 'hive_database', value: 'Existing MSSQL Server database with integrated authentication'}),
  861. Em.Object.create({name: 'hive_database_type', value: 'mssql'}),
  862. Em.Object.create({name: 'hive_existing_mssql_server_2_host', value: 'h1'}),
  863. Em.Object.create({name: 'hive_hostname', value: 'h2'})
  864. ],
  865. removed: ['hive_ambari_database', 'hive_existing_mysql_host', 'hive_existing_mysql_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database', 'hive_existing_oracle_host', 'hive_existing_oracle_database', 'hive_existing_mssql_server_database', 'hive_existing_mssql_server_host'],
  866. m: 'hive_database: Existing MSSQL Server database with integrated authentication',
  867. host: 'h2'
  868. }
  869. ]).forEach(function (test) {
  870. it(test.m, function () {
  871. var configs = test.globals.slice();
  872. test.removed.forEach(function (c) {
  873. configs.pushObject(Em.Object.create({name: c}))
  874. });
  875. configs = mainServiceInfoConfigsController.setHiveHostName(configs);
  876. test.removed.forEach(function (name) {
  877. if (!Em.isNone(configs.findProperty('name', name))) console.log('!!!!', name);
  878. expect(Em.isNone(configs.findProperty('name', name))).to.equal(true);
  879. });
  880. expect(configs.findProperty('name', 'hive_hostname').value).to.equal(test.host);
  881. });
  882. });
  883. });
  884. describe('#setOozieHostName', function () {
  885. beforeEach(function () {
  886. sinon.stub(App.StackService, 'find').returns([
  887. {
  888. serviceName: 'HIVE'
  889. },
  890. {
  891. serviceName: 'OOZIE'
  892. }
  893. ]);
  894. });
  895. afterEach(function () {
  896. App.StackService.find.restore();
  897. });
  898. Em.A([
  899. {
  900. globals: [
  901. Em.Object.create({name: 'oozie_database', value: 'New Derby Database'}),
  902. Em.Object.create({name: 'oozie_ambari_host', value: 'h1'}),
  903. Em.Object.create({name: 'oozie_hostname', value: 'h2'})
  904. ],
  905. removed: ['oozie_ambari_database', 'oozie_existing_mysql_host', 'oozie_existing_mysql_database', 'oozie_existing_oracle_host', 'oozie_existing_oracle_database', 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database', 'oozie_existing_mssql_server_database', 'oozie_existing_mssql_server_host', 'oozie_existing_mssql_server_2_database', 'oozie_existing_mssql_server_2_host'],
  906. m: 'oozie_database: New Derby Database',
  907. host: 'h2'
  908. },
  909. {
  910. globals: [
  911. Em.Object.create({name: 'oozie_database', value: 'New MySQL Database'}),
  912. Em.Object.create({name: 'oozie_ambari_host', value: 'h1'}),
  913. Em.Object.create({name: 'oozie_hostname', value: 'h2'})
  914. ],
  915. removed: ['oozie_existing_mysql_host', 'oozie_existing_mysql_database', 'oozie_existing_oracle_host', 'oozie_existing_oracle_database', 'oozie_derby_database', 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database', 'oozie_existing_mssql_server_database', 'oozie_existing_mssql_server_host', 'oozie_existing_mssql_server_2_database', 'oozie_existing_mssql_server_2_host'],
  916. m: 'oozie_database: New MySQL Database',
  917. host: 'h1'
  918. },
  919. {
  920. globals: [
  921. Em.Object.create({name: 'oozie_database', value: 'Existing MySQL Database'}),
  922. Em.Object.create({name: 'oozie_existing_mysql_host', value: 'h1'}),
  923. Em.Object.create({name: 'oozie_hostname', value: 'h2'})
  924. ],
  925. removed: ['oozie_ambari_database', 'oozie_existing_oracle_host', 'oozie_existing_oracle_database', 'oozie_derby_database', 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database', 'oozie_existing_mssql_server_database', 'oozie_existing_mssql_server_host', 'oozie_existing_mssql_server_2_database', 'oozie_existing_mssql_server_2_host'],
  926. m: 'oozie_database: Existing MySQL Database',
  927. host: 'h2'
  928. },
  929. {
  930. globals: [
  931. Em.Object.create({name: 'oozie_database', value: 'Existing PostgreSQL Database'}),
  932. Em.Object.create({name: 'oozie_existing_postgresql_host', value: 'h1'}),
  933. Em.Object.create({name: 'oozie_hostname', value: 'h2'})
  934. ],
  935. removed: ['oozie_ambari_database', 'oozie_existing_mysql_host', 'oozie_existing_mysql_database', 'oozie_existing_oracle_host', 'oozie_existing_oracle_database', 'oozie_existing_mssql_server_database', 'oozie_existing_mssql_server_host', 'oozie_existing_mssql_server_2_database', 'oozie_existing_mssql_server_2_host'],
  936. m: 'oozie_database: Existing PostgreSQL Database',
  937. host: 'h2'
  938. },
  939. {
  940. globals: [
  941. Em.Object.create({name: 'oozie_database', value: 'Existing Oracle Database'}),
  942. Em.Object.create({name: 'oozie_existing_oracle_host', value: 'h1'}),
  943. Em.Object.create({name: 'oozie_hostname', value: 'h2'})
  944. ],
  945. removed: ['oozie_ambari_database', 'oozie_existing_mysql_host', 'oozie_existing_mysql_database', 'oozie_derby_database', 'oozie_existing_mssql_server_database', 'oozie_existing_mssql_server_host', 'oozie_existing_mssql_server_2_database', 'oozie_existing_mssql_server_2_host'],
  946. m: 'oozie_database: Existing Oracle Database',
  947. host: 'h2'
  948. },
  949. {
  950. globals: [
  951. Em.Object.create({name: 'oozie_database', value: 'Existing MSSQL Server database with SQL authentication'}),
  952. Em.Object.create({name: 'oozie_existing_oracle_host', value: 'h1'}),
  953. Em.Object.create({name: 'oozie_hostname', value: 'h2'})
  954. ],
  955. removed: ['oozie_ambari_database', 'oozie_existing_oracle_host', 'oozie_existing_oracle_database', 'oozie_derby_database', 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database', 'oozie_existing_mysql_host', 'oozie_existing_mysql_database', 'oozie_existing_mssql_server_2_database', 'oozie_existing_mssql_server_2_host'],
  956. m: 'oozie_database: Existing MSSQL Server database with SQL authentication',
  957. host: 'h2'
  958. },
  959. {
  960. globals: [
  961. Em.Object.create({name: 'oozie_database', value: 'Existing MSSQL Server database with integrated authentication'}),
  962. Em.Object.create({name: 'oozie_existing_oracle_host', value: 'h1'}),
  963. Em.Object.create({name: 'oozie_hostname', value: 'h2'})
  964. ],
  965. removed: ['oozie_ambari_database', 'oozie_existing_oracle_host', 'oozie_existing_oracle_database', 'oozie_derby_database', 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database', 'oozie_existing_mysql_host', 'oozie_existing_mysql_database', 'oozie_existing_mssql_server_database', 'oozie_existing_mssql_server_host'],
  966. m: 'oozie_database: Existing MSSQL Server database with integrated authentication',
  967. host: 'h2'
  968. }
  969. ]).forEach(function (test) {
  970. it(test.m, function () {
  971. var configs = test.globals.slice();
  972. test.removed.forEach(function (c) {
  973. if (!configs.findProperty('name', c)) {
  974. configs.pushObject(Em.Object.create({name: c}))
  975. }
  976. });
  977. configs = mainServiceInfoConfigsController.setOozieHostName(configs);
  978. test.removed.forEach(function (name) {
  979. expect(Em.isNone(configs.findProperty('name', name))).to.equal(true);
  980. });
  981. expect(configs.findProperty('name', 'oozie_hostname').value).to.equal(test.host);
  982. });
  983. });
  984. });
  985. describe('#errorsCount', function () {
  986. it('should ignore configs with widgets (enhanced configs)', function () {
  987. mainServiceInfoConfigsController.reopen({selectedService: {
  988. configs: [
  989. Em.Object.create({isVisible: true, widget: Em.View, isValid: false}),
  990. Em.Object.create({isVisible: true, widget: Em.View, isValid: true}),
  991. Em.Object.create({isVisible: true, isValid: true}),
  992. Em.Object.create({isVisible: true, isValid: false})
  993. ]
  994. }});
  995. expect(mainServiceInfoConfigsController.get('errorsCount')).to.equal(1);
  996. });
  997. it('should ignore configs with widgets (enhanced configs) and hidden configs', function () {
  998. mainServiceInfoConfigsController.reopen({selectedService: {
  999. configs: [
  1000. Em.Object.create({isVisible: true, widget: Em.View, isValid: false}),
  1001. Em.Object.create({isVisible: true, widget: Em.View, isValid: true}),
  1002. Em.Object.create({isVisible: false, isValid: false}),
  1003. Em.Object.create({isVisible: true, isValid: true}),
  1004. Em.Object.create({isVisible: true, isValid: false})
  1005. ]
  1006. }});
  1007. expect(mainServiceInfoConfigsController.get('errorsCount')).to.equal(1);
  1008. });
  1009. });
  1010. describe('#_onLoadComplete', function () {
  1011. beforeEach(function () {
  1012. sinon.stub(Em.run, 'next', Em.K);
  1013. mainServiceInfoConfigsController.setProperties({
  1014. dataIsLoaded: false,
  1015. versionLoaded: false,
  1016. isInit: true
  1017. });
  1018. });
  1019. afterEach(function () {
  1020. Em.run.next.restore();
  1021. });
  1022. it('should update flags', function () {
  1023. mainServiceInfoConfigsController._onLoadComplete();
  1024. expect(mainServiceInfoConfigsController.get('dataIsLoaded')).to.be.true;
  1025. expect(mainServiceInfoConfigsController.get('versionLoaded')).to.be.true;
  1026. expect(mainServiceInfoConfigsController.get('isInit')).to.be.false;
  1027. });
  1028. });
  1029. });