service_config_test.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  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. category: 'c0',
  28. overrides: [
  29. {
  30. error: true,
  31. errorMessage: 'error'
  32. },
  33. {
  34. error: true
  35. },
  36. {}
  37. ]
  38. }),
  39. Ember.Object.create({
  40. category: 'c1',
  41. isValid: false,
  42. isVisible: true
  43. }),
  44. Ember.Object.create({
  45. category: 'c0',
  46. isValid: true,
  47. isVisible: true
  48. }),
  49. Ember.Object.create({
  50. category: 'c1',
  51. isValid: false,
  52. isVisible: false
  53. })
  54. ],
  55. configCategoriesData = [
  56. Em.Object.create({
  57. name: 'c0',
  58. slaveErrorCount: 1
  59. }),
  60. Em.Object.create({
  61. name: 'c1',
  62. slaveErrorCount: 2
  63. })
  64. ],
  65. nameCases = [
  66. {
  67. name: 'DataNode',
  68. primary: 'DATANODE'
  69. },
  70. {
  71. name: 'TaskTracker',
  72. primary: 'TASKTRACKER'
  73. },
  74. {
  75. name: 'RegionServer',
  76. primary: 'HBASE_REGIONSERVER'
  77. },
  78. {
  79. name: 'name',
  80. primary: null
  81. }
  82. ],
  83. components = [
  84. {
  85. name: 'NameNode',
  86. master: true
  87. },
  88. {
  89. name: 'SNameNode',
  90. master: true
  91. },
  92. {
  93. name: 'JobTracker',
  94. master: true
  95. },
  96. {
  97. name: 'HBase Master',
  98. master: true
  99. },
  100. {
  101. name: 'Oozie Master',
  102. master: true
  103. },
  104. {
  105. name: 'Hive Metastore',
  106. master: true
  107. },
  108. {
  109. name: 'WebHCat Server',
  110. master: true
  111. },
  112. {
  113. name: 'ZooKeeper Server',
  114. master: true
  115. },
  116. {
  117. name: 'Ganglia',
  118. master: true
  119. },
  120. {
  121. name: 'DataNode',
  122. slave: true
  123. },
  124. {
  125. name: 'TaskTracker',
  126. slave: true
  127. },
  128. {
  129. name: 'RegionServer',
  130. slave: true
  131. }
  132. ],
  133. masters = components.filterProperty('master'),
  134. slaves = components.filterProperty('slave'),
  135. groupsData = {
  136. groups: [
  137. Em.Object.create({
  138. errorCount: 1
  139. }),
  140. Em.Object.create({
  141. errorCount: 2
  142. })
  143. ]
  144. },
  145. groupNoErrorsData = [].concat(configsData.slice(2)),
  146. groupErrorsData = [configsData[1]],
  147. overridableFalseData = [
  148. {
  149. isOverridable: false
  150. },
  151. {
  152. isEditable: false,
  153. overrides: configsData[0].overrides
  154. },
  155. {
  156. displayType: 'masterHost'
  157. }
  158. ],
  159. overridableTrueData = [
  160. {
  161. isOverridable: true,
  162. isEditable: true
  163. }, {
  164. isOverridable: true,
  165. overrides: []
  166. },
  167. {
  168. isOverridable: true
  169. }
  170. ],
  171. overriddenFalseData = [
  172. {
  173. overrides: null,
  174. isOriginalSCP: true
  175. },
  176. {
  177. overrides: [],
  178. isOriginalSCP: true
  179. }
  180. ],
  181. overriddenTrueData = [
  182. {
  183. overrides: configsData[0].overrides
  184. },
  185. {
  186. isOriginalSCP: false
  187. }
  188. ],
  189. removableFalseData = [
  190. {
  191. isEditable: false
  192. },
  193. {
  194. hasOverrides: true
  195. },
  196. {
  197. isUserProperty: false,
  198. isOriginalSCP: true
  199. }
  200. ],
  201. removableTrueData = [
  202. {
  203. isEditable: true,
  204. hasOverrides: false,
  205. isUserProperty: true
  206. },
  207. {
  208. isEditable: true,
  209. hasOverrides: false,
  210. isOriginalSCP: false
  211. }
  212. ],
  213. initPropertyData = [
  214. {
  215. initial: {
  216. displayType: 'password',
  217. value: 'value'
  218. },
  219. result: {
  220. retypedPassword: 'value'
  221. }
  222. },
  223. {
  224. initial: {
  225. id: 'puppet var',
  226. value: '',
  227. defaultValue: 'default'
  228. },
  229. result: {
  230. value: 'default'
  231. }
  232. }
  233. ],
  234. notDefaultFalseData = [
  235. {
  236. isEditable: false
  237. },
  238. {
  239. defaultValue: null
  240. },
  241. {
  242. value: 'value',
  243. defaultValue: 'value'
  244. }
  245. ],
  246. notDefaultTrueData = {
  247. isEditable: true,
  248. value: 'value',
  249. defaultValue: 'default'
  250. },
  251. types = ['masterHost', 'slaveHosts', 'masterHosts', 'slaveHost', 'radio button'],
  252. classCases = [
  253. {
  254. initial: {
  255. displayType: 'checkbox'
  256. },
  257. viewClass: App.ServiceConfigCheckbox
  258. },
  259. {
  260. initial: {
  261. displayType: 'checkbox',
  262. dependentConfigPattern: 'somPattern'
  263. },
  264. viewClass: App.ServiceConfigCheckboxWithDependencies
  265. },
  266. {
  267. initial: {
  268. displayType: 'password'
  269. },
  270. viewClass: App.ServiceConfigPasswordField
  271. },
  272. {
  273. initial: {
  274. displayType: 'combobox'
  275. },
  276. viewClass: App.ServiceConfigComboBox
  277. },
  278. {
  279. initial: {
  280. displayType: 'radio button'
  281. },
  282. viewClass: App.ServiceConfigRadioButtons
  283. },
  284. {
  285. initial: {
  286. displayType: 'directories'
  287. },
  288. viewClass: App.ServiceConfigTextArea
  289. },
  290. {
  291. initial: {
  292. displayType: 'content'
  293. },
  294. viewClass: App.ServiceConfigTextAreaContent
  295. },
  296. {
  297. initial: {
  298. displayType: 'multiLine'
  299. },
  300. viewClass: App.ServiceConfigTextArea
  301. },
  302. {
  303. initial: {
  304. displayType: 'custom'
  305. },
  306. viewClass: App.ServiceConfigBigTextArea
  307. },
  308. {
  309. initial: {
  310. displayType: 'masterHost'
  311. },
  312. viewClass: App.ServiceConfigMasterHostView
  313. },
  314. {
  315. initial: {
  316. displayType: 'masterHosts'
  317. },
  318. viewClass: App.ServiceConfigMasterHostsView
  319. },
  320. {
  321. initial: {
  322. displayType: 'slaveHosts'
  323. },
  324. viewClass: App.ServiceConfigSlaveHostsView
  325. },
  326. {
  327. initial: {
  328. unit: true,
  329. displayType: 'type'
  330. },
  331. viewClass: App.ServiceConfigTextFieldWithUnit
  332. },
  333. {
  334. initial: {
  335. unit: false,
  336. displayType: 'type'
  337. },
  338. viewClass: App.ServiceConfigTextField
  339. },
  340. {
  341. initial: {
  342. unit: false,
  343. displayType: 'supportTextConnection'
  344. },
  345. viewClass: App.checkConnectionView
  346. }
  347. ];
  348. describe('App.ServiceConfig', function () {
  349. beforeEach(function () {
  350. serviceConfig = App.ServiceConfig.create();
  351. });
  352. describe('#errorCount', function () {
  353. it('should be 0', function () {
  354. serviceConfig.setProperties({
  355. configs: [],
  356. configCategories: []
  357. });
  358. expect(serviceConfig.get('errorCount')).to.equal(0);
  359. });
  360. it('should sum counts of all errors', function () {
  361. serviceConfig.setProperties({
  362. configs: configsData,
  363. configCategories: configCategoriesData
  364. });
  365. expect(serviceConfig.get('errorCount')).to.equal(6);
  366. expect(serviceConfig.get('configCategories').findProperty('name', 'c0').get('nonSlaveErrorCount')).to.equal(2);
  367. expect(serviceConfig.get('configCategories').findProperty('name', 'c1').get('nonSlaveErrorCount')).to.equal(1);
  368. });
  369. });
  370. });
  371. describe('App.ServiceConfigCategory', function () {
  372. beforeEach(function () {
  373. serviceConfigCategory = App.ServiceConfigCategory.create();
  374. });
  375. describe('#primaryName', function () {
  376. nameCases.forEach(function (item) {
  377. it('should return ' + item.primary, function () {
  378. serviceConfigCategory.set('name', item.name);
  379. expect(serviceConfigCategory.get('primaryName')).to.equal(item.primary);
  380. })
  381. });
  382. });
  383. describe('#isForMasterComponent', function () {
  384. masters.forEach(function (item) {
  385. it('should be true for ' + item.name, function () {
  386. serviceConfigCategory.set('name', item.name);
  387. expect(serviceConfigCategory.get('isForMasterComponent')).to.be.true;
  388. });
  389. });
  390. it('should be false', function () {
  391. serviceConfigCategory.set('name', 'name');
  392. expect(serviceConfigCategory.get('isForMasterComponent')).to.be.false;
  393. });
  394. });
  395. describe('#isForSlaveComponent', function () {
  396. slaves.forEach(function (item) {
  397. it('should be true for ' + item.name, function () {
  398. serviceConfigCategory.set('name', item.name);
  399. expect(serviceConfigCategory.get('isForSlaveComponent')).to.be.true;
  400. });
  401. });
  402. it('should be false', function () {
  403. serviceConfigCategory.set('name', 'name');
  404. expect(serviceConfigCategory.get('isForSlaveComponent')).to.be.false;
  405. });
  406. });
  407. describe('#slaveErrorCount', function () {
  408. it('should be 0', function () {
  409. serviceConfigCategory.set('slaveConfigs', []);
  410. expect(serviceConfigCategory.get('slaveErrorCount')).to.equal(0);
  411. });
  412. it('should sum all errorCount values', function () {
  413. serviceConfigCategory.set('slaveConfigs', groupsData);
  414. expect(serviceConfigCategory.get('slaveErrorCount')).to.equal(3);
  415. });
  416. });
  417. describe('#errorCount', function () {
  418. it('should sum all errors for category', function () {
  419. serviceConfigCategory.reopen({
  420. slaveErrorCount: 1
  421. });
  422. expect(serviceConfigCategory.get('errorCount')).to.equal(1);
  423. serviceConfigCategory.set('nonSlaveErrorCount', 2);
  424. expect(serviceConfigCategory.get('errorCount')).to.equal(3);
  425. serviceConfigCategory.set('slaveErrorCount', 0);
  426. expect(serviceConfigCategory.get('errorCount')).to.equal(2);
  427. });
  428. });
  429. describe('#isAdvanced', function () {
  430. it('should be true', function () {
  431. serviceConfigCategory.set('name', 'Advanced');
  432. expect(serviceConfigCategory.get('isAdvanced')).to.be.true;
  433. });
  434. it('should be false', function () {
  435. serviceConfigCategory.set('name', 'name');
  436. expect(serviceConfigCategory.get('isAdvanced')).to.be.false;
  437. });
  438. });
  439. });
  440. describe('App.Group', function () {
  441. beforeEach(function () {
  442. group = App.Group.create();
  443. });
  444. describe('#errorCount', function () {
  445. it('should be 0', function () {
  446. group.set('properties', groupNoErrorsData);
  447. expect(group.get('errorCount')).to.equal(0);
  448. });
  449. it('should be 1', function () {
  450. group.set('properties', groupErrorsData);
  451. expect(group.get('errorCount')).to.equal(1);
  452. });
  453. });
  454. });
  455. describe('App.ServiceConfigProperty', function () {
  456. beforeEach(function () {
  457. serviceConfigProperty = App.ServiceConfigProperty.create();
  458. });
  459. describe('#overrideErrorTrigger', function () {
  460. it('should be an increment', function () {
  461. serviceConfigProperty.set('overrides', configsData[0].overrides);
  462. expect(serviceConfigProperty.get('overrideErrorTrigger')).to.equal(1);
  463. serviceConfigProperty.set('overrides', []);
  464. expect(serviceConfigProperty.get('overrideErrorTrigger')).to.equal(2);
  465. });
  466. });
  467. describe('#isPropertyOverridable', function () {
  468. overridableFalseData.forEach(function (item) {
  469. it('should be false', function () {
  470. Em.keys(item).forEach(function (prop) {
  471. serviceConfigProperty.set(prop, item[prop]);
  472. });
  473. expect(serviceConfigProperty.get('isPropertyOverridable')).to.be.false;
  474. });
  475. });
  476. overridableTrueData.forEach(function (item) {
  477. it('should be true', function () {
  478. Em.keys(item).forEach(function (prop) {
  479. serviceConfigProperty.set(prop, item[prop]);
  480. });
  481. expect(serviceConfigProperty.get('isPropertyOverridable')).to.be.true;
  482. });
  483. });
  484. });
  485. describe('#isOverridden', function () {
  486. overriddenFalseData.forEach(function (item) {
  487. it('should be false', function () {
  488. Em.keys(item).forEach(function (prop) {
  489. serviceConfigProperty.set(prop, item[prop]);
  490. });
  491. expect(serviceConfigProperty.get('isOverridden')).to.be.false;
  492. });
  493. });
  494. overriddenTrueData.forEach(function (item) {
  495. it('should be true', function () {
  496. Em.keys(item).forEach(function (prop) {
  497. serviceConfigProperty.set(prop, item[prop]);
  498. });
  499. expect(serviceConfigProperty.get('isOverridden')).to.be.true;
  500. });
  501. });
  502. });
  503. describe('#isRemovable', function () {
  504. removableFalseData.forEach(function (item) {
  505. it('should be false', function () {
  506. Em.keys(item).forEach(function (prop) {
  507. serviceConfigProperty.set(prop, item[prop]);
  508. });
  509. expect(serviceConfigProperty.get('isRemovable')).to.be.false;
  510. });
  511. });
  512. removableTrueData.forEach(function (item) {
  513. it('should be true', function () {
  514. Em.keys(item).forEach(function (prop) {
  515. serviceConfigProperty.set(prop, item[prop]);
  516. });
  517. expect(serviceConfigProperty.get('isRemovable')).to.be.true;
  518. });
  519. });
  520. });
  521. describe('#init', function () {
  522. initPropertyData.forEach(function (item) {
  523. it('should set initial data', function () {
  524. serviceConfigPropertyInit = App.ServiceConfigProperty.create(item.initial);
  525. Em.keys(item.result).forEach(function (prop) {
  526. expect(serviceConfigPropertyInit.get(prop)).to.equal(item.result[prop]);
  527. });
  528. });
  529. });
  530. });
  531. describe('#isNotDefaultValue', function () {
  532. notDefaultFalseData.forEach(function (item) {
  533. it('should be false', function () {
  534. Em.keys(item).forEach(function (prop) {
  535. serviceConfigProperty.set(prop, item[prop]);
  536. });
  537. expect(serviceConfigProperty.get('isNotDefaultValue')).to.be.false;
  538. });
  539. });
  540. it('should be true', function () {
  541. Em.keys(notDefaultTrueData).forEach(function (prop) {
  542. serviceConfigProperty.set(prop, notDefaultTrueData[prop]);
  543. });
  544. expect(serviceConfigProperty.get('isNotDefaultValue')).to.be.true;
  545. });
  546. });
  547. describe('#cantBeUndone', function () {
  548. types.forEach(function (item) {
  549. it('should be true', function () {
  550. serviceConfigProperty.set('displayType', item);
  551. expect(serviceConfigProperty.get('cantBeUndone')).to.be.true;
  552. });
  553. });
  554. it('should be false', function () {
  555. serviceConfigProperty.set('displayType', 'type');
  556. expect(serviceConfigProperty.get('cantBeUndone')).to.be.false;
  557. });
  558. });
  559. describe('#setDefaultValue', function () {
  560. it('should change the default value', function () {
  561. serviceConfigProperty.set('defaultValue', 'value0');
  562. serviceConfigProperty.setDefaultValue(/\d/, '1');
  563. expect(serviceConfigProperty.get('defaultValue')).to.equal('value1');
  564. });
  565. });
  566. describe('#isValid', function () {
  567. it('should be true', function () {
  568. serviceConfigProperty.set('errorMessage', '');
  569. expect(serviceConfigProperty.get('isValid')).to.be.true;
  570. });
  571. it('should be false', function () {
  572. serviceConfigProperty.set('errorMessage', 'message');
  573. expect(serviceConfigProperty.get('isValid')).to.be.false;
  574. });
  575. });
  576. describe('#viewClass', function () {
  577. classCases.forEach(function (item) {
  578. it ('should be ' + item.viewClass, function () {
  579. Em.keys(item.initial).forEach(function (prop) {
  580. serviceConfigProperty.set(prop, item.initial[prop]);
  581. });
  582. expect(serviceConfigProperty.get('viewClass')).to.eql(item.viewClass);
  583. });
  584. });
  585. });
  586. describe('#validate', function () {
  587. it('not required', function () {
  588. serviceConfigProperty.setProperties({
  589. isRequired: false,
  590. value: ''
  591. });
  592. expect(serviceConfigProperty.get('errorMessage')).to.be.empty;
  593. expect(serviceConfigProperty.get('error')).to.be.false;
  594. });
  595. it('should validate', function () {
  596. serviceConfigProperty.setProperties({
  597. isRequired: true,
  598. value: 'value'
  599. });
  600. expect(serviceConfigProperty.get('errorMessage')).to.be.empty;
  601. expect(serviceConfigProperty.get('error')).to.be.false;
  602. });
  603. it('should fail', function () {
  604. serviceConfigProperty.setProperties({
  605. isRequired: true,
  606. value: 'value'
  607. });
  608. serviceConfigProperty.set('value', '');
  609. expect(serviceConfigProperty.get('errorMessage')).to.equal('This is required');
  610. expect(serviceConfigProperty.get('error')).to.be.true;
  611. });
  612. });
  613. describe('#initialValue', function () {
  614. var cases = {
  615. 'kafka.ganglia.metrics.host': [
  616. {
  617. message: 'kafka.ganglia.metrics.host property should have the value of ganglia hostname when ganglia is selected',
  618. localDB: {
  619. masterComponentHosts: [
  620. {
  621. component: 'GANGLIA_SERVER',
  622. hostName: 'c6401'
  623. }
  624. ]
  625. },
  626. expected: 'c6401'
  627. },
  628. {
  629. message: 'kafka.ganglia.metrics.host property should have the value "localhost" when ganglia is not selected',
  630. localDB: {
  631. masterComponentHosts: [
  632. {
  633. component: 'NAMENODE',
  634. hostName: 'c6401'
  635. }
  636. ]
  637. },
  638. expected: 'localhost'
  639. }
  640. ],
  641. 'hive_database': [
  642. {
  643. alwaysEnableManagedMySQLForHive: true,
  644. currentStateName: '',
  645. isManagedMySQLForHiveEnabled: false,
  646. receivedValue: 'New MySQL Database',
  647. value: 'New MySQL Database',
  648. options: [
  649. {
  650. displayName: 'New MySQL Database'
  651. }
  652. ],
  653. hidden: false
  654. },
  655. {
  656. alwaysEnableManagedMySQLForHive: false,
  657. currentStateName: 'configs',
  658. isManagedMySQLForHiveEnabled: false,
  659. receivedValue: 'New MySQL Database',
  660. value: 'New MySQL Database',
  661. options: [
  662. {
  663. displayName: 'New MySQL Database'
  664. }
  665. ],
  666. hidden: false
  667. },
  668. {
  669. alwaysEnableManagedMySQLForHive: false,
  670. currentStateName: '',
  671. isManagedMySQLForHiveEnabled: true,
  672. receivedValue: 'New MySQL Database',
  673. value: 'New MySQL Database',
  674. options: [
  675. {
  676. displayName: 'New MySQL Database'
  677. }
  678. ],
  679. hidden: false
  680. },
  681. {
  682. alwaysEnableManagedMySQLForHive: false,
  683. currentStateName: '',
  684. isManagedMySQLForHiveEnabled: false,
  685. receivedValue: 'New MySQL Database',
  686. value: 'Existing MySQL Database',
  687. options: [
  688. {
  689. displayName: 'New MySQL Database'
  690. }
  691. ],
  692. hidden: true
  693. },
  694. {
  695. alwaysEnableManagedMySQLForHive: false,
  696. currentStateName: '',
  697. isManagedMySQLForHiveEnabled: false,
  698. receivedValue: 'New PostgreSQL Database',
  699. value: 'New PostgreSQL Database',
  700. options: [
  701. {
  702. displayName: 'New MySQL Database'
  703. }
  704. ],
  705. hidden: true
  706. }
  707. ],
  708. 'hbase.zookeeper.quorum': [
  709. {
  710. filename: 'hbase-site.xml',
  711. value: 'host0,host1',
  712. defaultValue: 'host0,host1',
  713. title: 'should set ZooKeeper Server hostnames'
  714. },
  715. {
  716. filename: 'ams-hbase-site.xml',
  717. value: 'localhost',
  718. defaultValue: '',
  719. title: 'should ignore ZooKeeper Server hostnames'
  720. }
  721. ],
  722. 'hbase.tmp.dir': [
  723. {
  724. filename: 'hbase-site.xml',
  725. isUnionAllMountPointsCalled: true,
  726. title: 'unionAllMountPoints should be called'
  727. },
  728. {
  729. filename: 'ams-hbase-site.xml',
  730. isUnionAllMountPointsCalled: false,
  731. title: 'unionAllMountPoints shouldn\'t be called'
  732. }
  733. ],
  734. 'hivemetastore_host': {
  735. localDB: {
  736. masterComponentHosts: [
  737. {
  738. component: 'HIVE_METASTORE',
  739. hostName: 'h0'
  740. },
  741. {
  742. component: 'HIVE_METASTORE',
  743. hostName: 'h1'
  744. }
  745. ]
  746. },
  747. value: ['h0', 'h1'],
  748. title: 'array that contains names of hosts with Hive Metastore'
  749. },
  750. 'hive_master_hosts': {
  751. localDB: {
  752. masterComponentHosts: [
  753. {
  754. component: 'HIVE_SERVER',
  755. hostName: 'h0'
  756. },
  757. {
  758. component: 'HIVE_METASTORE',
  759. hostName: 'h0'
  760. },
  761. {
  762. component: 'HIVE_METASTORE',
  763. hostName: 'h1'
  764. },
  765. {
  766. component: 'WEBHCAT_SERVER',
  767. hostName: 'h2'
  768. }
  769. ]
  770. },
  771. value: 'h0,h1',
  772. title: 'comma separated list of hosts with Hive Server and Metastore'
  773. },
  774. 'hive.metastore.uris': {
  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: 'thrift://localhost:9083',
  791. value: 'thrift://h0:9083,thrift://h1:9083',
  792. title: 'comma separated list of Metastore hosts with thrift prefix and port'
  793. },
  794. 'templeton.hive.properties': {
  795. localDB: {
  796. masterComponentHosts: [
  797. {
  798. component: 'HIVE_METASTORE',
  799. hostName: 'h0'
  800. },
  801. {
  802. component: 'HIVE_METASTORE',
  803. hostName: 'h1'
  804. }
  805. ]
  806. },
  807. dependencies: {
  808. 'hive.metastore.uris': 'thrift://localhost:9083'
  809. },
  810. defaultValue: 'hive.metastore.local=false,hive.metastore.uris=thrift://localhost:9933,hive.metastore.sasl.enabled=false',
  811. value: 'hive.metastore.local=false,hive.metastore.uris=thrift://h0:9083\\,thrift://h1:9083,hive.metastore.sasl.enabled=false,hive.metastore.execute.setugi=true',
  812. title: 'should add relevant hive.metastore.uris value'
  813. },
  814. 'yarn.resourcemanager.zk-address': {
  815. localDB: {
  816. masterComponentHosts: [
  817. {
  818. component: 'ZOOKEEPER_SERVER',
  819. hostName: 'h0'
  820. },
  821. {
  822. component: 'ZOOKEEPER_SERVER',
  823. hostName: 'h1'
  824. }
  825. ]
  826. },
  827. dependencies: {
  828. clientPort: '2182'
  829. },
  830. defaultValue: 'localhost:2181',
  831. value: 'h0:2182',
  832. title: 'should add ZK host and port dynamically'
  833. },
  834. 'oozieserver_host': {
  835. localDB: {
  836. masterComponentHosts: [
  837. {
  838. component: 'OOZIE_SERVER',
  839. hostName: 'h0'
  840. },
  841. {
  842. component: 'OOZIE_SERVER',
  843. hostName: 'h1'
  844. }
  845. ]
  846. },
  847. value: ['h0', 'h1'],
  848. title: 'array that contains names of hosts with Oozie Server'
  849. },
  850. 'knox_gateway_host': {
  851. localDB: {
  852. masterComponentHosts: [
  853. {
  854. component: 'KNOX_GATEWAY',
  855. hostName: 'h0'
  856. },
  857. {
  858. component: 'KNOX_GATEWAY',
  859. hostName: 'h1'
  860. }
  861. ]
  862. },
  863. value: ['h0', 'h1'],
  864. title: 'array that contains names of hosts with Knox Gateway'
  865. }
  866. };
  867. cases['kafka.ganglia.metrics.host'].forEach(function(item){
  868. it(item.message, function () {
  869. serviceConfigProperty.setProperties({
  870. name: 'kafka.ganglia.metrics.host',
  871. value: 'localhost'
  872. });
  873. serviceConfigProperty.initialValue(item.localDB);
  874. expect(serviceConfigProperty.get('value')).to.equal(item.expected);
  875. });
  876. });
  877. cases['hive_database'].forEach(function (item) {
  878. var title = 'hive_database value should be set to {0}';
  879. it(title.format(item.value), function () {
  880. sinon.stub(App, 'get')
  881. .withArgs('supports.alwaysEnableManagedMySQLForHive').returns(item.alwaysEnableManagedMySQLForHive)
  882. .withArgs('router.currentState.name').returns(item.currentStateName)
  883. .withArgs('isManagedMySQLForHiveEnabled').returns(item.isManagedMySQLForHiveEnabled);
  884. serviceConfigProperty.setProperties({
  885. name: 'hive_database',
  886. value: item.receivedValue,
  887. options: item.options
  888. });
  889. serviceConfigProperty.initialValue({});
  890. expect(serviceConfigProperty.get('value')).to.equal(item.value);
  891. expect(serviceConfigProperty.get('options').findProperty('displayName', 'New MySQL Database').hidden).to.equal(item.hidden);
  892. App.get.restore();
  893. });
  894. });
  895. cases['hbase.zookeeper.quorum'].forEach(function (item) {
  896. it(item.title, function () {
  897. serviceConfigProperty.setProperties({
  898. name: 'hbase.zookeeper.quorum',
  899. value: 'localhost',
  900. 'filename': item.filename
  901. });
  902. serviceConfigProperty.initialValue({
  903. masterComponentHosts: {
  904. filterProperty: function () {
  905. return {
  906. mapProperty: function () {
  907. return ['host0', 'host1'];
  908. }
  909. };
  910. }
  911. }
  912. });
  913. expect(serviceConfigProperty.get('value')).to.equal(item.value);
  914. expect(serviceConfigProperty.get('defaultValue')).to.equal(item.defaultValue);
  915. });
  916. });
  917. cases['hbase.tmp.dir'].forEach(function (item) {
  918. var isOnlyFirstOneNeeded = true,
  919. localDB = {
  920. p: 'v'
  921. };
  922. it(item.title, function () {
  923. sinon.stub(serviceConfigProperty, 'unionAllMountPoints', Em.K);
  924. serviceConfigProperty.setProperties({
  925. name: 'hbase.tmp.dir',
  926. filename: item.filename
  927. });
  928. serviceConfigProperty.initialValue(localDB);
  929. expect(serviceConfigProperty.unionAllMountPoints.calledWith(isOnlyFirstOneNeeded, localDB)).to.equal(item.isUnionAllMountPointsCalled);
  930. serviceConfigProperty.unionAllMountPoints.restore();
  931. });
  932. });
  933. it(cases['hivemetastore_host'].title, function () {
  934. serviceConfigProperty.set('name', 'hivemetastore_host');
  935. serviceConfigProperty.initialValue(cases['hivemetastore_host'].localDB);
  936. expect(serviceConfigProperty.get('value')).to.eql(cases['hivemetastore_host'].value);
  937. });
  938. it(cases['hive_master_hosts'].title, function () {
  939. serviceConfigProperty.set('name', 'hive_master_hosts');
  940. serviceConfigProperty.initialValue(cases['hive_master_hosts'].localDB);
  941. expect(serviceConfigProperty.get('value')).to.equal(cases['hive_master_hosts'].value);
  942. });
  943. it(cases['hive.metastore.uris'].title, function () {
  944. serviceConfigProperty.setProperties({
  945. name: 'hive.metastore.uris',
  946. defaultValue: cases['hive.metastore.uris'].defaultValue
  947. });
  948. serviceConfigProperty.initialValue(cases['hive.metastore.uris'].localDB, cases['hive.metastore.uris'].dependencies);
  949. expect(serviceConfigProperty.get('value')).to.equal(cases['hive.metastore.uris'].value);
  950. expect(serviceConfigProperty.get('defaultValue')).to.equal(cases['hive.metastore.uris'].value);
  951. });
  952. it(cases['templeton.hive.properties'].title, function () {
  953. serviceConfigProperty.setProperties({
  954. name: 'templeton.hive.properties',
  955. defaultValue: cases['templeton.hive.properties'].defaultValue,
  956. value: cases['templeton.hive.properties'].defaultValue
  957. });
  958. serviceConfigProperty.initialValue(cases['templeton.hive.properties'].localDB, cases['templeton.hive.properties'].dependencies);
  959. expect(serviceConfigProperty.get('value')).to.equal(cases['templeton.hive.properties'].value);
  960. expect(serviceConfigProperty.get('defaultValue')).to.equal(cases['templeton.hive.properties'].value);
  961. });
  962. it(cases['yarn.resourcemanager.zk-address'].title, function () {
  963. serviceConfigProperty.setProperties({
  964. name: 'yarn.resourcemanager.zk-address',
  965. defaultValue: cases['yarn.resourcemanager.zk-address'].defaultValue
  966. });
  967. serviceConfigProperty.initialValue(cases['yarn.resourcemanager.zk-address'].localDB, cases['yarn.resourcemanager.zk-address'].dependencies);
  968. expect(serviceConfigProperty.get('value')).to.equal(cases['yarn.resourcemanager.zk-address'].value);
  969. expect(serviceConfigProperty.get('defaultValue')).to.equal(cases['yarn.resourcemanager.zk-address'].value);
  970. });
  971. it(cases['oozieserver_host'].title, function () {
  972. serviceConfigProperty.set('name', 'oozieserver_host');
  973. serviceConfigProperty.initialValue(cases['oozieserver_host'].localDB);
  974. expect(serviceConfigProperty.get('value')).to.eql(cases['oozieserver_host'].value);
  975. });
  976. it(cases['knox_gateway_host'].title, function () {
  977. serviceConfigProperty.set('name', 'knox_gateway_host');
  978. serviceConfigProperty.initialValue(cases['knox_gateway_host'].localDB);
  979. expect(serviceConfigProperty.get('value')).to.eql(cases['knox_gateway_host'].value);
  980. });
  981. });
  982. describe('#getHiveMetastoreUris', function () {
  983. var cases = [
  984. {
  985. hosts: [
  986. {
  987. hostName: 'h0',
  988. component: 'HIVE_SERVER'
  989. },
  990. {
  991. hostName: 'h1',
  992. component: 'HIVE_METASTORE'
  993. },
  994. {
  995. hostName: 'h2',
  996. component: 'HIVE_METASTORE'
  997. }
  998. ],
  999. defaultValue: 'thrift://localhost:9083',
  1000. expected: 'thrift://h1:9083,thrift://h2:9083',
  1001. title: 'typical case'
  1002. },
  1003. {
  1004. hosts: [
  1005. {
  1006. hostName: 'h0',
  1007. component: 'HIVE_SERVER'
  1008. }
  1009. ],
  1010. defaultValue: 'thrift://localhost:9083',
  1011. expected: '',
  1012. title: 'no Metastore hosts in DB'
  1013. },
  1014. {
  1015. hosts: [
  1016. {
  1017. hostName: 'h0',
  1018. component: 'HIVE_SERVER'
  1019. },
  1020. {
  1021. hostName: 'h1',
  1022. component: 'HIVE_METASTORE'
  1023. },
  1024. {
  1025. hostName: 'h2',
  1026. component: 'HIVE_METASTORE'
  1027. }
  1028. ],
  1029. defaultValue: '',
  1030. expected: '',
  1031. title: 'default value without port'
  1032. },
  1033. {
  1034. hosts: [
  1035. {
  1036. hostName: 'h0',
  1037. component: 'HIVE_SERVER'
  1038. },
  1039. {
  1040. hostName: 'h1',
  1041. component: 'HIVE_METASTORE'
  1042. },
  1043. {
  1044. hostName: 'h2',
  1045. component: 'HIVE_METASTORE'
  1046. }
  1047. ],
  1048. expected: '',
  1049. title: 'no default value specified'
  1050. }
  1051. ];
  1052. cases.forEach(function (item) {
  1053. it(item.title, function () {
  1054. expect(serviceConfigProperty.getHiveMetastoreUris(item.hosts, item.defaultValue)).to.equal(item.expected);
  1055. });
  1056. });
  1057. });
  1058. describe('#unionAllMountPoints', function () {
  1059. var localDB = {
  1060. masterComponentHosts: [
  1061. {
  1062. component: 'NAMENODE',
  1063. hostName: 'h0'
  1064. },
  1065. {
  1066. component: 'SECONDARY_NAMENODE',
  1067. hostName: 'h4'
  1068. },
  1069. {
  1070. component: 'APP_TIMELINE_SERVER',
  1071. hostName: 'h0'
  1072. },
  1073. {
  1074. component: 'ZOOKEEPER_SERVER',
  1075. hostName: 'h0'
  1076. },
  1077. {
  1078. component: 'ZOOKEEPER_SERVER',
  1079. hostName: 'h1'
  1080. },
  1081. {
  1082. component: 'OOZIE_SERVER',
  1083. hostName: 'h0'
  1084. },
  1085. {
  1086. component: 'OOZIE_SERVER',
  1087. hostName: 'h1'
  1088. },
  1089. {
  1090. component: 'NIMBUS',
  1091. hostName: 'h2'
  1092. },
  1093. {
  1094. component: 'FALCON_SERVER',
  1095. hostName: 'h3'
  1096. },
  1097. {
  1098. component: 'KAFKA_BROKER',
  1099. hostName: 'h0'
  1100. },
  1101. {
  1102. component: 'KAFKA_BROKER',
  1103. hostName: 'h1'
  1104. }
  1105. ],
  1106. slaveComponentHosts: [
  1107. {
  1108. componentName: 'DATANODE',
  1109. hosts: [
  1110. {
  1111. hostName: 'h0'
  1112. },
  1113. {
  1114. hostName: 'h1'
  1115. }
  1116. ]
  1117. },
  1118. {
  1119. componentName: 'TASKTRACKER',
  1120. hosts: [
  1121. {
  1122. hostName: 'h0'
  1123. },
  1124. {
  1125. hostName: 'h1'
  1126. }
  1127. ]
  1128. },
  1129. {
  1130. componentName: 'NODEMANAGER',
  1131. hosts: [
  1132. {
  1133. hostName: 'h0'
  1134. },
  1135. {
  1136. hostName: 'h1'
  1137. },
  1138. {
  1139. hostName: 'h4'
  1140. }
  1141. ]
  1142. },
  1143. {
  1144. componentName: 'HBASE_REGIONSERVER',
  1145. hosts: [
  1146. {
  1147. hostName: 'h0'
  1148. },
  1149. {
  1150. hostName: 'h1'
  1151. }
  1152. ]
  1153. },
  1154. {
  1155. componentName: 'SUPERVISOR',
  1156. hosts: [
  1157. {
  1158. hostName: 'h0'
  1159. },
  1160. {
  1161. hostName: 'h1'
  1162. }
  1163. ]
  1164. }
  1165. ],
  1166. hosts: {
  1167. h0: {
  1168. disk_info: [
  1169. {
  1170. mountpoint: '/'
  1171. },
  1172. {
  1173. mountpoint: '/home'
  1174. },
  1175. {
  1176. mountpoint: '/boot'
  1177. },
  1178. {
  1179. mountpoint: '/boot/efi'
  1180. },
  1181. {
  1182. mountpoint: '/mnt'
  1183. },
  1184. {
  1185. mountpoint: '/mnt/efi'
  1186. },
  1187. {
  1188. mountpoint: '/media/disk0',
  1189. available: '100000000'
  1190. },
  1191. {
  1192. mountpoint: '/mount0',
  1193. available: '100000000'
  1194. }
  1195. ]
  1196. },
  1197. h4: {
  1198. disk_info: [
  1199. {
  1200. mountpoint: 'c:',
  1201. available: '100000000'
  1202. }
  1203. ]
  1204. }
  1205. }
  1206. },
  1207. cases = [
  1208. {
  1209. name: 'dfs.namenode.name.dir',
  1210. isOnlyFirstOneNeeded: false,
  1211. value: '/media/disk0/default\n/mount0/default\n'
  1212. },
  1213. {
  1214. name: 'dfs.name.dir',
  1215. isOnlyFirstOneNeeded: false,
  1216. value: '/media/disk0/default\n/mount0/default\n'
  1217. },
  1218. {
  1219. name: 'fs.checkpoint.dir',
  1220. isOnlyFirstOneNeeded: true,
  1221. value: 'file:///c:/default\n'
  1222. },
  1223. {
  1224. name: 'dfs.namenode.checkpoint.dir',
  1225. isOnlyFirstOneNeeded: true,
  1226. value: 'file:///c:/default\n'
  1227. },
  1228. {
  1229. name: 'dfs.data.dir',
  1230. isOnlyFirstOneNeeded: false,
  1231. value: '/media/disk0/default\n/mount0/default\n/media/disk1/default\n/mount1/default\n'
  1232. },
  1233. {
  1234. name: 'dfs.datanode.data.dir',
  1235. isOnlyFirstOneNeeded: false,
  1236. value: '/media/disk0/default\n/mount0/default\n/media/disk1/default\n/mount1/default\n'
  1237. },
  1238. {
  1239. name: 'mapred.local.dir',
  1240. isOnlyFirstOneNeeded: false,
  1241. value: '/media/disk0/default\n/mount0/default\n/media/disk1/default\n/mount1/default\n'
  1242. },
  1243. {
  1244. name: 'yarn.nodemanager.log-dirs',
  1245. isOnlyFirstOneNeeded: false,
  1246. value: '/media/disk0/default\n/mount0/default\n/media/disk1/default\n/mount1/default\nc:\\default\n'
  1247. },
  1248. {
  1249. name: 'yarn.nodemanager.local-dirs',
  1250. isOnlyFirstOneNeeded: false,
  1251. value: '/media/disk0/default\n/mount0/default\n/media/disk1/default\n/mount1/default\nc:\\default\n'
  1252. },
  1253. {
  1254. name: 'yarn.timeline-service.leveldb-timeline-store.path',
  1255. isOnlyFirstOneNeeded: true,
  1256. value: '/media/disk0/default'
  1257. },
  1258. {
  1259. name: 'dataDir',
  1260. isOnlyFirstOneNeeded: true,
  1261. value: '/media/disk0/default'
  1262. },
  1263. {
  1264. name: 'oozie_data_dir',
  1265. isOnlyFirstOneNeeded: true,
  1266. value: '/media/disk0/default'
  1267. },
  1268. {
  1269. name: 'hbase.tmp.dir',
  1270. isOnlyFirstOneNeeded: true,
  1271. value: '/media/disk0/default'
  1272. },
  1273. {
  1274. name: 'storm.local.dir',
  1275. isOnlyFirstOneNeeded: true,
  1276. value: '/media/disk0/default'
  1277. },
  1278. {
  1279. name: '*.falcon.graph.storage.directory',
  1280. isOnlyFirstOneNeeded: true,
  1281. value: '/default'
  1282. },
  1283. {
  1284. name: '*.falcon.graph.serialize.path',
  1285. isOnlyFirstOneNeeded: true,
  1286. value: '/default'
  1287. },
  1288. {
  1289. name: 'log.dirs',
  1290. isOnlyFirstOneNeeded: false,
  1291. value: '/media/disk0/default\n/mount0/default\n/media/disk1/default\n/mount1/default\n'
  1292. }
  1293. ];
  1294. beforeEach(function () {
  1295. sinon.stub(App.Host, 'find').returns([
  1296. Em.Object.create({
  1297. id: 'h1',
  1298. diskInfo: [
  1299. {
  1300. mountpoint: '/media/disk1',
  1301. type: 'devtmpfs'
  1302. },
  1303. {
  1304. mountpoint: '/media/disk1',
  1305. type: 'tmpfs'
  1306. },
  1307. {
  1308. mountpoint: '/media/disk1',
  1309. type: 'vboxsf'
  1310. },
  1311. {
  1312. mountpoint: '/media/disk1',
  1313. type: 'CDFS'
  1314. },
  1315. {
  1316. mountpoint: '/media/disk1',
  1317. available: '0'
  1318. },
  1319. {
  1320. mountpoint: '/media/disk1',
  1321. available: '100000000'
  1322. },
  1323. {
  1324. mountpoint: '/mount1',
  1325. available: '100000000'
  1326. }
  1327. ]
  1328. }),
  1329. Em.Object.create({
  1330. id: 'h2',
  1331. diskInfo: [
  1332. {
  1333. mountpoint: '/'
  1334. }
  1335. ]
  1336. }),
  1337. Em.Object.create({
  1338. id: 'h3',
  1339. diskInfo: []
  1340. })
  1341. ]);
  1342. });
  1343. afterEach(function () {
  1344. App.Host.find.restore();
  1345. });
  1346. cases.forEach(function (item) {
  1347. it(item.name, function () {
  1348. serviceConfigProperty.setProperties({
  1349. name: item.name,
  1350. defaultDirectory: '/default'
  1351. });
  1352. serviceConfigProperty.unionAllMountPoints(item.isOnlyFirstOneNeeded, localDB);
  1353. expect(serviceConfigProperty.get('value')).to.equal(item.value);
  1354. expect(serviceConfigProperty.get('defaultValue')).to.equal(item.value);
  1355. });
  1356. });
  1357. });
  1358. });