service_config_test.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  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('models/service_config');
  20. var serviceConfig,
  21. serviceConfigCategory,
  22. group,
  23. serviceConfigProperty,
  24. serviceConfigPropertyInit,
  25. configsData = [
  26. Ember.Object.create({
  27. overrides: [
  28. {
  29. error: true,
  30. errorMessage: 'error'
  31. },
  32. {
  33. error: true
  34. },
  35. {}
  36. ]
  37. }),
  38. Ember.Object.create({
  39. isValid: false,
  40. isVisible: true
  41. }),
  42. Ember.Object.create({
  43. isValid: true,
  44. isVisible: true
  45. }),
  46. Ember.Object.create({
  47. isValid: false,
  48. isVisible: false
  49. })
  50. ],
  51. configCategoriesData = [
  52. Em.Object.create({
  53. slaveErrorCount: 1
  54. }),
  55. Em.Object.create({
  56. slaveErrorCount: 2
  57. })
  58. ],
  59. nameCases = [
  60. {
  61. name: 'DataNode',
  62. primary: 'DATANODE'
  63. },
  64. {
  65. name: 'TaskTracker',
  66. primary: 'TASKTRACKER'
  67. },
  68. {
  69. name: 'RegionServer',
  70. primary: 'HBASE_REGIONSERVER'
  71. },
  72. {
  73. name: 'name',
  74. primary: null
  75. }
  76. ],
  77. components = [
  78. {
  79. name: 'NameNode',
  80. master: true
  81. },
  82. {
  83. name: 'SNameNode',
  84. master: true
  85. },
  86. {
  87. name: 'JobTracker',
  88. master: true
  89. },
  90. {
  91. name: 'HBase Master',
  92. master: true
  93. },
  94. {
  95. name: 'Oozie Master',
  96. master: true
  97. },
  98. {
  99. name: 'Hive Metastore',
  100. master: true
  101. },
  102. {
  103. name: 'WebHCat Server',
  104. master: true
  105. },
  106. {
  107. name: 'ZooKeeper Server',
  108. master: true
  109. },
  110. {
  111. name: 'Ganglia',
  112. master: true
  113. },
  114. {
  115. name: 'DataNode',
  116. slave: true
  117. },
  118. {
  119. name: 'TaskTracker',
  120. slave: true
  121. },
  122. {
  123. name: 'RegionServer',
  124. slave: true
  125. }
  126. ],
  127. masters = components.filterProperty('master'),
  128. slaves = components.filterProperty('slave'),
  129. groupsData = {
  130. groups: [
  131. Em.Object.create({
  132. errorCount: 1
  133. }),
  134. Em.Object.create({
  135. errorCount: 2
  136. })
  137. ]
  138. },
  139. groupNoErrorsData = [].concat(configsData.slice(2)),
  140. groupErrorsData = [configsData[1]],
  141. overridableFalseData = [
  142. {
  143. isOverridable: false
  144. },
  145. {
  146. isEditable: false,
  147. overrides: configsData[0].overrides
  148. },
  149. {
  150. displayType: 'masterHost'
  151. }
  152. ],
  153. overridableTrueData = [
  154. {
  155. isOverridable: true,
  156. isEditable: true
  157. }, {
  158. isOverridable: true,
  159. overrides: []
  160. },
  161. {
  162. isOverridable: true
  163. }
  164. ],
  165. overriddenFalseData = [
  166. {
  167. overrides: null,
  168. isOriginalSCP: true
  169. },
  170. {
  171. overrides: [],
  172. isOriginalSCP: true
  173. }
  174. ],
  175. overriddenTrueData = [
  176. {
  177. overrides: configsData[0].overrides
  178. },
  179. {
  180. isOriginalSCP: false
  181. }
  182. ],
  183. removableFalseData = [
  184. {
  185. isEditable: false
  186. },
  187. {
  188. hasOverrides: true
  189. },
  190. {
  191. isUserProperty: false,
  192. isOriginalSCP: true
  193. }
  194. ],
  195. removableTrueData = [
  196. {
  197. isEditable: true,
  198. hasOverrides: false,
  199. isUserProperty: true
  200. },
  201. {
  202. isEditable: true,
  203. hasOverrides: false,
  204. isOriginalSCP: false
  205. }
  206. ],
  207. initPropertyData = [
  208. {
  209. initial: {
  210. displayType: 'password',
  211. value: 'value'
  212. },
  213. result: {
  214. retypedPassword: 'value'
  215. }
  216. },
  217. {
  218. initial: {
  219. id: 'puppet var',
  220. value: '',
  221. defaultValue: 'default'
  222. },
  223. result: {
  224. value: 'default'
  225. }
  226. }
  227. ],
  228. notDefaultFalseData = [
  229. {
  230. isEditable: false
  231. },
  232. {
  233. defaultValue: null
  234. },
  235. {
  236. value: 'value',
  237. defaultValue: 'value'
  238. }
  239. ],
  240. notDefaultTrueData = {
  241. isEditable: true,
  242. value: 'value',
  243. defaultValue: 'default'
  244. },
  245. types = ['masterHost', 'slaveHosts', 'masterHosts', 'slaveHost', 'radio button'],
  246. classCases = [
  247. {
  248. initial: {
  249. displayType: 'checkbox'
  250. },
  251. viewClass: App.ServiceConfigCheckbox
  252. },
  253. {
  254. initial: {
  255. displayType: 'checkbox',
  256. dependentConfigPattern: 'somPattern'
  257. },
  258. viewClass: App.ServiceConfigCheckboxWithDependencies
  259. },
  260. {
  261. initial: {
  262. displayType: 'password'
  263. },
  264. viewClass: App.ServiceConfigPasswordField
  265. },
  266. {
  267. initial: {
  268. displayType: 'combobox'
  269. },
  270. viewClass: App.ServiceConfigComboBox
  271. },
  272. {
  273. initial: {
  274. displayType: 'radio button'
  275. },
  276. viewClass: App.ServiceConfigRadioButtons
  277. },
  278. {
  279. initial: {
  280. displayType: 'directories'
  281. },
  282. viewClass: App.ServiceConfigTextArea
  283. },
  284. {
  285. initial: {
  286. displayType: 'content'
  287. },
  288. viewClass: App.ServiceConfigTextAreaContent
  289. },
  290. {
  291. initial: {
  292. displayType: 'multiLine'
  293. },
  294. viewClass: App.ServiceConfigTextArea
  295. },
  296. {
  297. initial: {
  298. displayType: 'custom'
  299. },
  300. viewClass: App.ServiceConfigBigTextArea
  301. },
  302. {
  303. initial: {
  304. displayType: 'masterHost'
  305. },
  306. viewClass: App.ServiceConfigMasterHostView
  307. },
  308. {
  309. initial: {
  310. displayType: 'masterHosts'
  311. },
  312. viewClass: App.ServiceConfigMasterHostsView
  313. },
  314. {
  315. initial: {
  316. displayType: 'slaveHosts'
  317. },
  318. viewClass: App.ServiceConfigSlaveHostsView
  319. },
  320. {
  321. initial: {
  322. unit: true,
  323. displayType: 'type'
  324. },
  325. viewClass: App.ServiceConfigTextFieldWithUnit
  326. },
  327. {
  328. initial: {
  329. unit: false,
  330. displayType: 'type'
  331. },
  332. viewClass: App.ServiceConfigTextField
  333. },
  334. {
  335. initial: {
  336. unit: false,
  337. displayType: 'supportTextConnection'
  338. },
  339. viewClass: App.checkConnectionView
  340. }
  341. ];
  342. describe('App.ServiceConfig', function () {
  343. beforeEach(function () {
  344. serviceConfig = App.ServiceConfig.create();
  345. });
  346. describe('#errorCount', function () {
  347. it('should be 0', function () {
  348. serviceConfig.setProperties({
  349. configs: [],
  350. configCategories: []
  351. });
  352. expect(serviceConfig.get('errorCount')).to.equal(0);
  353. });
  354. it('should sum counts of all errors', function () {
  355. serviceConfig.setProperties({
  356. configs: configsData,
  357. configCategories: configCategoriesData
  358. });
  359. expect(serviceConfig.get('errorCount')).to.equal(6);
  360. });
  361. });
  362. });
  363. describe('App.ServiceConfigCategory', function () {
  364. beforeEach(function () {
  365. serviceConfigCategory = App.ServiceConfigCategory.create();
  366. });
  367. describe('#primaryName', function () {
  368. nameCases.forEach(function (item) {
  369. it('should return ' + item.primary, function () {
  370. serviceConfigCategory.set('name', item.name);
  371. expect(serviceConfigCategory.get('primaryName')).to.equal(item.primary);
  372. })
  373. });
  374. });
  375. describe('#isForMasterComponent', function () {
  376. masters.forEach(function (item) {
  377. it('should be true for ' + item.name, function () {
  378. serviceConfigCategory.set('name', item.name);
  379. expect(serviceConfigCategory.get('isForMasterComponent')).to.be.true;
  380. });
  381. });
  382. it('should be false', function () {
  383. serviceConfigCategory.set('name', 'name');
  384. expect(serviceConfigCategory.get('isForMasterComponent')).to.be.false;
  385. });
  386. });
  387. describe('#isForSlaveComponent', function () {
  388. slaves.forEach(function (item) {
  389. it('should be true for ' + item.name, function () {
  390. serviceConfigCategory.set('name', item.name);
  391. expect(serviceConfigCategory.get('isForSlaveComponent')).to.be.true;
  392. });
  393. });
  394. it('should be false', function () {
  395. serviceConfigCategory.set('name', 'name');
  396. expect(serviceConfigCategory.get('isForSlaveComponent')).to.be.false;
  397. });
  398. });
  399. describe('#slaveErrorCount', function () {
  400. it('should be 0', function () {
  401. serviceConfigCategory.set('slaveConfigs', []);
  402. expect(serviceConfigCategory.get('slaveErrorCount')).to.equal(0);
  403. });
  404. it('should sum all errorCount values', function () {
  405. serviceConfigCategory.set('slaveConfigs', groupsData);
  406. expect(serviceConfigCategory.get('slaveErrorCount')).to.equal(3);
  407. });
  408. });
  409. describe('#isAdvanced', function () {
  410. it('should be true', function () {
  411. serviceConfigCategory.set('name', 'Advanced');
  412. expect(serviceConfigCategory.get('isAdvanced')).to.be.true;
  413. });
  414. it('should be false', function () {
  415. serviceConfigCategory.set('name', 'name');
  416. expect(serviceConfigCategory.get('isAdvanced')).to.be.false;
  417. });
  418. });
  419. });
  420. describe('App.Group', function () {
  421. beforeEach(function () {
  422. group = App.Group.create();
  423. });
  424. describe('#errorCount', function () {
  425. it('should be 0', function () {
  426. group.set('properties', groupNoErrorsData);
  427. expect(group.get('errorCount')).to.equal(0);
  428. });
  429. it('should be 1', function () {
  430. group.set('properties', groupErrorsData);
  431. expect(group.get('errorCount')).to.equal(1);
  432. });
  433. });
  434. });
  435. describe('App.ServiceConfigProperty', function () {
  436. beforeEach(function () {
  437. serviceConfigProperty = App.ServiceConfigProperty.create();
  438. });
  439. describe('#overrideErrorTrigger', function () {
  440. it('should be an increment', function () {
  441. serviceConfigProperty.set('overrides', configsData[0].overrides);
  442. expect(serviceConfigProperty.get('overrideErrorTrigger')).to.equal(1);
  443. serviceConfigProperty.set('overrides', []);
  444. expect(serviceConfigProperty.get('overrideErrorTrigger')).to.equal(2);
  445. });
  446. });
  447. describe('#isPropertyOverridable', function () {
  448. overridableFalseData.forEach(function (item) {
  449. it('should be false', function () {
  450. Em.keys(item).forEach(function (prop) {
  451. serviceConfigProperty.set(prop, item[prop]);
  452. });
  453. expect(serviceConfigProperty.get('isPropertyOverridable')).to.be.false;
  454. });
  455. });
  456. overridableTrueData.forEach(function (item) {
  457. it('should be true', function () {
  458. Em.keys(item).forEach(function (prop) {
  459. serviceConfigProperty.set(prop, item[prop]);
  460. });
  461. expect(serviceConfigProperty.get('isPropertyOverridable')).to.be.true;
  462. });
  463. });
  464. });
  465. describe('#isOverridden', function () {
  466. overriddenFalseData.forEach(function (item) {
  467. it('should be false', function () {
  468. Em.keys(item).forEach(function (prop) {
  469. serviceConfigProperty.set(prop, item[prop]);
  470. });
  471. expect(serviceConfigProperty.get('isOverridden')).to.be.false;
  472. });
  473. });
  474. overriddenTrueData.forEach(function (item) {
  475. it('should be true', function () {
  476. Em.keys(item).forEach(function (prop) {
  477. serviceConfigProperty.set(prop, item[prop]);
  478. });
  479. expect(serviceConfigProperty.get('isOverridden')).to.be.true;
  480. });
  481. });
  482. });
  483. describe('#isRemovable', function () {
  484. removableFalseData.forEach(function (item) {
  485. it('should be false', function () {
  486. Em.keys(item).forEach(function (prop) {
  487. serviceConfigProperty.set(prop, item[prop]);
  488. });
  489. expect(serviceConfigProperty.get('isRemovable')).to.be.false;
  490. });
  491. });
  492. removableTrueData.forEach(function (item) {
  493. it('should be true', function () {
  494. Em.keys(item).forEach(function (prop) {
  495. serviceConfigProperty.set(prop, item[prop]);
  496. });
  497. expect(serviceConfigProperty.get('isRemovable')).to.be.true;
  498. });
  499. });
  500. });
  501. describe('#init', function () {
  502. initPropertyData.forEach(function (item) {
  503. it('should set initial data', function () {
  504. serviceConfigPropertyInit = App.ServiceConfigProperty.create(item.initial);
  505. Em.keys(item.result).forEach(function (prop) {
  506. expect(serviceConfigPropertyInit.get(prop)).to.equal(item.result[prop]);
  507. });
  508. });
  509. });
  510. });
  511. describe('#isNotDefaultValue', function () {
  512. notDefaultFalseData.forEach(function (item) {
  513. it('should be false', function () {
  514. Em.keys(item).forEach(function (prop) {
  515. serviceConfigProperty.set(prop, item[prop]);
  516. });
  517. expect(serviceConfigProperty.get('isNotDefaultValue')).to.be.false;
  518. });
  519. });
  520. it('should be true', function () {
  521. Em.keys(notDefaultTrueData).forEach(function (prop) {
  522. serviceConfigProperty.set(prop, notDefaultTrueData[prop]);
  523. });
  524. expect(serviceConfigProperty.get('isNotDefaultValue')).to.be.true;
  525. });
  526. });
  527. describe('#cantBeUndone', function () {
  528. types.forEach(function (item) {
  529. it('should be true', function () {
  530. serviceConfigProperty.set('displayType', item);
  531. expect(serviceConfigProperty.get('cantBeUndone')).to.be.true;
  532. });
  533. });
  534. it('should be false', function () {
  535. serviceConfigProperty.set('displayType', 'type');
  536. expect(serviceConfigProperty.get('cantBeUndone')).to.be.false;
  537. });
  538. });
  539. describe('#setDefaultValue', function () {
  540. it('should change the default value', function () {
  541. serviceConfigProperty.set('defaultValue', 'value0');
  542. serviceConfigProperty.setDefaultValue(/\d/, '1');
  543. expect(serviceConfigProperty.get('defaultValue')).to.equal('value1');
  544. });
  545. });
  546. describe('#isValid', function () {
  547. it('should be true', function () {
  548. serviceConfigProperty.set('errorMessage', '');
  549. expect(serviceConfigProperty.get('isValid')).to.be.true;
  550. });
  551. it('should be false', function () {
  552. serviceConfigProperty.set('errorMessage', 'message');
  553. expect(serviceConfigProperty.get('isValid')).to.be.false;
  554. });
  555. });
  556. describe('#viewClass', function () {
  557. classCases.forEach(function (item) {
  558. it ('should be ' + item.viewClass, function () {
  559. Em.keys(item.initial).forEach(function (prop) {
  560. serviceConfigProperty.set(prop, item.initial[prop]);
  561. });
  562. expect(serviceConfigProperty.get('viewClass')).to.eql(item.viewClass);
  563. });
  564. });
  565. });
  566. describe('#validate', function () {
  567. it('not required', function () {
  568. serviceConfigProperty.setProperties({
  569. isRequired: false,
  570. value: ''
  571. });
  572. expect(serviceConfigProperty.get('errorMessage')).to.be.empty;
  573. expect(serviceConfigProperty.get('error')).to.be.false;
  574. });
  575. it('should validate', function () {
  576. serviceConfigProperty.setProperties({
  577. isRequired: true,
  578. value: 'value'
  579. });
  580. expect(serviceConfigProperty.get('errorMessage')).to.be.empty;
  581. expect(serviceConfigProperty.get('error')).to.be.false;
  582. });
  583. it('should fail', function () {
  584. serviceConfigProperty.setProperties({
  585. isRequired: true,
  586. value: 'value'
  587. });
  588. serviceConfigProperty.set('value', '');
  589. expect(serviceConfigProperty.get('errorMessage')).to.equal('This is required');
  590. expect(serviceConfigProperty.get('error')).to.be.true;
  591. });
  592. });
  593. describe('#initialValue', function () {
  594. var cases = {
  595. 'kafka.ganglia.metrics.host': [
  596. {
  597. message: 'kafka.ganglia.metrics.host property should have the value of ganglia hostname when ganglia is selected',
  598. localDB: {
  599. masterComponentHosts: [
  600. {
  601. component: 'GANGLIA_SERVER',
  602. hostName: 'c6401'
  603. }
  604. ]
  605. },
  606. expected: 'c6401'
  607. },
  608. {
  609. message: 'kafka.ganglia.metrics.host property should have the value "localhost" when ganglia is not selected',
  610. localDB: {
  611. masterComponentHosts: [
  612. {
  613. component: 'NAMENODE',
  614. hostName: 'c6401'
  615. }
  616. ]
  617. },
  618. expected: 'localhost'
  619. }
  620. ],
  621. 'hive_database': [
  622. {
  623. alwaysEnableManagedMySQLForHive: true,
  624. currentStateName: '',
  625. isManagedMySQLForHiveEnabled: false,
  626. receivedValue: 'New MySQL Database',
  627. value: 'New MySQL Database',
  628. options: [
  629. {
  630. displayName: 'New MySQL Database'
  631. }
  632. ],
  633. hidden: false
  634. },
  635. {
  636. alwaysEnableManagedMySQLForHive: false,
  637. currentStateName: 'configs',
  638. isManagedMySQLForHiveEnabled: false,
  639. receivedValue: 'New MySQL Database',
  640. value: 'New MySQL Database',
  641. options: [
  642. {
  643. displayName: 'New MySQL Database'
  644. }
  645. ],
  646. hidden: false
  647. },
  648. {
  649. alwaysEnableManagedMySQLForHive: false,
  650. currentStateName: '',
  651. isManagedMySQLForHiveEnabled: true,
  652. receivedValue: 'New MySQL Database',
  653. value: 'New MySQL Database',
  654. options: [
  655. {
  656. displayName: 'New MySQL Database'
  657. }
  658. ],
  659. hidden: false
  660. },
  661. {
  662. alwaysEnableManagedMySQLForHive: false,
  663. currentStateName: '',
  664. isManagedMySQLForHiveEnabled: false,
  665. receivedValue: 'New MySQL Database',
  666. value: 'Existing MySQL Database',
  667. options: [
  668. {
  669. displayName: 'New MySQL Database'
  670. }
  671. ],
  672. hidden: true
  673. },
  674. {
  675. alwaysEnableManagedMySQLForHive: false,
  676. currentStateName: '',
  677. isManagedMySQLForHiveEnabled: false,
  678. receivedValue: 'New PostgreSQL Database',
  679. value: 'New PostgreSQL Database',
  680. options: [
  681. {
  682. displayName: 'New MySQL Database'
  683. }
  684. ],
  685. hidden: true
  686. }
  687. ],
  688. 'hbase.zookeeper.quorum': [
  689. {
  690. filename: 'hbase-site.xml',
  691. value: 'host0,host1',
  692. defaultValue: 'host0,host1',
  693. title: 'should set ZooKeeper Server hostnames'
  694. },
  695. {
  696. filename: 'ams-hbase-site.xml',
  697. value: 'localhost',
  698. defaultValue: '',
  699. title: 'should ignore ZooKeeper Server hostnames'
  700. }
  701. ],
  702. 'hbase.tmp.dir': [
  703. {
  704. filename: 'hbase-site.xml',
  705. isUnionAllMountPointsCalled: true,
  706. title: 'unionAllMountPoints should be called'
  707. },
  708. {
  709. filename: 'ams-hbase-site.xml',
  710. isUnionAllMountPointsCalled: false,
  711. title: 'unionAllMountPoints shouldn\'t be called'
  712. }
  713. ],
  714. 'hivemetastore_host': {
  715. localDB: {
  716. masterComponentHosts: [
  717. {
  718. component: 'HIVE_METASTORE',
  719. hostName: 'h0'
  720. },
  721. {
  722. component: 'HIVE_METASTORE',
  723. hostName: 'h1'
  724. }
  725. ]
  726. },
  727. value: ['h0', 'h1'],
  728. title: 'array that contains names of hosts with Hive Metastore'
  729. },
  730. 'hive_master_hosts': {
  731. localDB: {
  732. masterComponentHosts: [
  733. {
  734. component: 'HIVE_SERVER',
  735. hostName: 'h0'
  736. },
  737. {
  738. component: 'HIVE_METASTORE',
  739. hostName: 'h0'
  740. },
  741. {
  742. component: 'HIVE_METASTORE',
  743. hostName: 'h1'
  744. },
  745. {
  746. component: 'WEBHCAT_SERVER',
  747. hostName: 'h2'
  748. }
  749. ]
  750. },
  751. value: 'h0,h1',
  752. title: 'comma separated list of hosts with Hive Server and Metastore'
  753. },
  754. 'hive.metastore.uris': {
  755. localDB: {
  756. masterComponentHosts: [
  757. {
  758. component: 'HIVE_METASTORE',
  759. hostName: 'h0'
  760. },
  761. {
  762. component: 'HIVE_METASTORE',
  763. hostName: 'h1'
  764. }
  765. ]
  766. },
  767. dependencies: {
  768. 'hive.metastore.uris': 'thrift://localhost:9083'
  769. },
  770. defaultValue: 'thrift://localhost:9083',
  771. value: 'thrift://h0:9083,thrift://h1:9083',
  772. title: 'comma separated list of Metastore hosts with thrift prefix and port'
  773. },
  774. 'templeton.hive.properties': {
  775. localDB: {
  776. masterComponentHosts: [
  777. {
  778. component: 'HIVE_METASTORE',
  779. hostName: 'h0'
  780. },
  781. {
  782. component: 'HIVE_METASTORE',
  783. hostName: 'h1'
  784. }
  785. ]
  786. },
  787. dependencies: {
  788. 'hive.metastore.uris': 'thrift://localhost:9083'
  789. },
  790. defaultValue: 'hive.metastore.local=false,hive.metastore.uris=thrift://localhost:9933,hive.metastore.sasl.enabled=false',
  791. value: 'hive.metastore.local=false,hive.metastore.uris=thrift://h0:9083\\,thrift://h1:9083,hive.metastore.sasl.enabled=false,hive.metastore.execute.setugi=true',
  792. title: 'should add relevant hive.metastore.uris value'
  793. },
  794. 'yarn.resourcemanager.zk-address': {
  795. localDB: {
  796. masterComponentHosts: [
  797. {
  798. component: 'ZOOKEEPER_SERVER',
  799. hostName: 'h0'
  800. },
  801. {
  802. component: 'ZOOKEEPER_SERVER',
  803. hostName: 'h1'
  804. }
  805. ]
  806. },
  807. dependencies: {
  808. clientPort: '2182'
  809. },
  810. defaultValue: 'localhost:2181',
  811. value: 'h0:2182',
  812. title: 'should add ZK host and port dynamically'
  813. }
  814. };
  815. cases['kafka.ganglia.metrics.host'].forEach(function(item){
  816. it(item.message, function () {
  817. serviceConfigProperty.setProperties({
  818. name: 'kafka.ganglia.metrics.host',
  819. value: 'localhost'
  820. });
  821. serviceConfigProperty.initialValue(item.localDB);
  822. expect(serviceConfigProperty.get('value')).to.equal(item.expected);
  823. });
  824. });
  825. cases['hive_database'].forEach(function (item) {
  826. var title = 'hive_database value should be set to {0}';
  827. it(title.format(item.value), function () {
  828. sinon.stub(App, 'get')
  829. .withArgs('supports.alwaysEnableManagedMySQLForHive').returns(item.alwaysEnableManagedMySQLForHive)
  830. .withArgs('router.currentState.name').returns(item.currentStateName)
  831. .withArgs('isManagedMySQLForHiveEnabled').returns(item.isManagedMySQLForHiveEnabled);
  832. serviceConfigProperty.setProperties({
  833. name: 'hive_database',
  834. value: item.receivedValue,
  835. options: item.options
  836. });
  837. serviceConfigProperty.initialValue({});
  838. expect(serviceConfigProperty.get('value')).to.equal(item.value);
  839. expect(serviceConfigProperty.get('options').findProperty('displayName', 'New MySQL Database').hidden).to.equal(item.hidden);
  840. App.get.restore();
  841. });
  842. });
  843. cases['hbase.zookeeper.quorum'].forEach(function (item) {
  844. it(item.title, function () {
  845. serviceConfigProperty.setProperties({
  846. name: 'hbase.zookeeper.quorum',
  847. value: 'localhost',
  848. 'filename': item.filename
  849. });
  850. serviceConfigProperty.initialValue({
  851. masterComponentHosts: {
  852. filterProperty: function () {
  853. return {
  854. mapProperty: function () {
  855. return ['host0', 'host1'];
  856. }
  857. };
  858. }
  859. }
  860. });
  861. expect(serviceConfigProperty.get('value')).to.equal(item.value);
  862. expect(serviceConfigProperty.get('defaultValue')).to.equal(item.defaultValue);
  863. });
  864. });
  865. cases['hbase.tmp.dir'].forEach(function (item) {
  866. var isOnlyFirstOneNeeded = true,
  867. localDB = {
  868. p: 'v'
  869. };
  870. it(item.title, function () {
  871. sinon.stub(serviceConfigProperty, 'unionAllMountPoints', Em.K);
  872. serviceConfigProperty.setProperties({
  873. name: 'hbase.tmp.dir',
  874. filename: item.filename
  875. });
  876. serviceConfigProperty.initialValue(localDB);
  877. expect(serviceConfigProperty.unionAllMountPoints.calledWith(isOnlyFirstOneNeeded, localDB)).to.equal(item.isUnionAllMountPointsCalled);
  878. serviceConfigProperty.unionAllMountPoints.restore();
  879. });
  880. });
  881. it(cases['hivemetastore_host'].title, function () {
  882. serviceConfigProperty.set('name', 'hivemetastore_host');
  883. serviceConfigProperty.initialValue(cases['hivemetastore_host'].localDB);
  884. expect(serviceConfigProperty.get('value')).to.eql(cases['hivemetastore_host'].value);
  885. });
  886. it(cases['hive_master_hosts'].title, function () {
  887. serviceConfigProperty.set('name', 'hive_master_hosts');
  888. serviceConfigProperty.initialValue(cases['hive_master_hosts'].localDB);
  889. expect(serviceConfigProperty.get('value')).to.equal(cases['hive_master_hosts'].value);
  890. });
  891. it(cases['hive.metastore.uris'].title, function () {
  892. serviceConfigProperty.setProperties({
  893. name: 'hive.metastore.uris',
  894. defaultValue: cases['hive.metastore.uris'].defaultValue
  895. });
  896. serviceConfigProperty.initialValue(cases['hive.metastore.uris'].localDB, cases['hive.metastore.uris'].dependencies);
  897. expect(serviceConfigProperty.get('value')).to.equal(cases['hive.metastore.uris'].value);
  898. expect(serviceConfigProperty.get('defaultValue')).to.equal(cases['hive.metastore.uris'].value);
  899. });
  900. it(cases['templeton.hive.properties'].title, function () {
  901. serviceConfigProperty.setProperties({
  902. name: 'templeton.hive.properties',
  903. defaultValue: cases['templeton.hive.properties'].defaultValue,
  904. value: cases['templeton.hive.properties'].defaultValue
  905. });
  906. serviceConfigProperty.initialValue(cases['templeton.hive.properties'].localDB, cases['templeton.hive.properties'].dependencies);
  907. expect(serviceConfigProperty.get('value')).to.equal(cases['templeton.hive.properties'].value);
  908. expect(serviceConfigProperty.get('defaultValue')).to.equal(cases['templeton.hive.properties'].value);
  909. });
  910. it(cases['yarn.resourcemanager.zk-address'].title, function () {
  911. serviceConfigProperty.setProperties({
  912. name: 'yarn.resourcemanager.zk-address',
  913. defaultValue: cases['yarn.resourcemanager.zk-address'].defaultValue
  914. });
  915. serviceConfigProperty.initialValue(cases['yarn.resourcemanager.zk-address'].localDB, cases['yarn.resourcemanager.zk-address'].dependencies);
  916. expect(serviceConfigProperty.get('value')).to.equal(cases['yarn.resourcemanager.zk-address'].value);
  917. expect(serviceConfigProperty.get('defaultValue')).to.equal(cases['yarn.resourcemanager.zk-address'].value);
  918. });
  919. });
  920. describe('#getHiveMetastoreUris', function () {
  921. var cases = [
  922. {
  923. hosts: [
  924. {
  925. hostName: 'h0',
  926. component: 'HIVE_SERVER'
  927. },
  928. {
  929. hostName: 'h1',
  930. component: 'HIVE_METASTORE'
  931. },
  932. {
  933. hostName: 'h2',
  934. component: 'HIVE_METASTORE'
  935. }
  936. ],
  937. defaultValue: 'thrift://localhost:9083',
  938. expected: 'thrift://h1:9083,thrift://h2:9083',
  939. title: 'typical case'
  940. },
  941. {
  942. hosts: [
  943. {
  944. hostName: 'h0',
  945. component: 'HIVE_SERVER'
  946. }
  947. ],
  948. defaultValue: 'thrift://localhost:9083',
  949. expected: '',
  950. title: 'no Metastore hosts in DB'
  951. },
  952. {
  953. hosts: [
  954. {
  955. hostName: 'h0',
  956. component: 'HIVE_SERVER'
  957. },
  958. {
  959. hostName: 'h1',
  960. component: 'HIVE_METASTORE'
  961. },
  962. {
  963. hostName: 'h2',
  964. component: 'HIVE_METASTORE'
  965. }
  966. ],
  967. defaultValue: '',
  968. expected: '',
  969. title: 'default value without port'
  970. },
  971. {
  972. hosts: [
  973. {
  974. hostName: 'h0',
  975. component: 'HIVE_SERVER'
  976. },
  977. {
  978. hostName: 'h1',
  979. component: 'HIVE_METASTORE'
  980. },
  981. {
  982. hostName: 'h2',
  983. component: 'HIVE_METASTORE'
  984. }
  985. ],
  986. expected: '',
  987. title: 'no default value specified'
  988. }
  989. ];
  990. cases.forEach(function (item) {
  991. it(item.title, function () {
  992. expect(serviceConfigProperty.getHiveMetastoreUris(item.hosts, item.defaultValue)).to.equal(item.expected);
  993. });
  994. });
  995. });
  996. });