service_config_test.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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. {
  27. overrides: [
  28. {
  29. error: true,
  30. errorMessage: 'error'
  31. },
  32. {
  33. error: true
  34. },
  35. {}
  36. ]
  37. },
  38. {
  39. isValid: false,
  40. isVisible: true
  41. },
  42. {
  43. isValid: true,
  44. isVisible: true
  45. }, {
  46. isValid: false,
  47. isVisible: false
  48. }
  49. ],
  50. configCategoriesData = [
  51. Em.Object.create({
  52. slaveErrorCount: 1
  53. }),
  54. Em.Object.create({
  55. slaveErrorCount: 2
  56. })
  57. ],
  58. nameCases = [
  59. {
  60. name: 'DataNode',
  61. primary: 'DATANODE'
  62. },
  63. {
  64. name: 'TaskTracker',
  65. primary: 'TASKTRACKER'
  66. },
  67. {
  68. name: 'RegionServer',
  69. primary: 'HBASE_REGIONSERVER'
  70. },
  71. {
  72. name: 'name',
  73. primary: null
  74. }
  75. ],
  76. components = [
  77. {
  78. name: 'NameNode',
  79. master: true
  80. },
  81. {
  82. name: 'SNameNode',
  83. master: true
  84. },
  85. {
  86. name: 'JobTracker',
  87. master: true
  88. },
  89. {
  90. name: 'HBase Master',
  91. master: true
  92. },
  93. {
  94. name: 'Oozie Master',
  95. master: true
  96. },
  97. {
  98. name: 'Hive Metastore',
  99. master: true
  100. },
  101. {
  102. name: 'WebHCat Server',
  103. master: true
  104. },
  105. {
  106. name: 'ZooKeeper Server',
  107. master: true
  108. },
  109. {
  110. name: 'Nagios',
  111. master: true
  112. },
  113. {
  114. name: 'Ganglia',
  115. master: true
  116. },
  117. {
  118. name: 'DataNode',
  119. slave: true
  120. },
  121. {
  122. name: 'TaskTracker',
  123. slave: true
  124. },
  125. {
  126. name: 'RegionServer',
  127. slave: true
  128. }
  129. ],
  130. masters = components.filterProperty('master'),
  131. slaves = components.filterProperty('slave'),
  132. groupsData = {
  133. groups: [
  134. Em.Object.create({
  135. errorCount: 1
  136. }),
  137. Em.Object.create({
  138. errorCount: 2
  139. })
  140. ]
  141. },
  142. groupNoErrorsData = [].concat(configsData.slice(2)),
  143. groupErrorsData = [configsData[1]],
  144. overridableFalseData = [
  145. {
  146. isOverridable: false
  147. },
  148. {
  149. isEditable: false,
  150. overrides: configsData[0].overrides
  151. },
  152. {
  153. displayType: 'masterHost'
  154. }
  155. ],
  156. overridableTrueData = [
  157. {
  158. isOverridable: true,
  159. isEditable: true
  160. }, {
  161. isOverridable: true,
  162. overrides: []
  163. },
  164. {
  165. isOverridable: true
  166. }
  167. ],
  168. overriddenFalseData = [
  169. {
  170. overrides: null,
  171. isOriginalSCP: true
  172. },
  173. {
  174. overrides: [],
  175. isOriginalSCP: true
  176. }
  177. ],
  178. overriddenTrueData = [
  179. {
  180. overrides: configsData[0].overrides
  181. },
  182. {
  183. isOriginalSCP: false
  184. }
  185. ],
  186. removableFalseData = [
  187. {
  188. isEditable: false
  189. },
  190. {
  191. hasOverrides: true
  192. },
  193. {
  194. isUserProperty: false,
  195. isOriginalSCP: true
  196. }
  197. ],
  198. removableTrueData = [
  199. {
  200. isEditable: true,
  201. hasOverrides: false,
  202. isUserProperty: true
  203. },
  204. {
  205. isEditable: true,
  206. hasOverrides: false,
  207. isOriginalSCP: false
  208. }
  209. ],
  210. initPropertyData = [
  211. {
  212. initial: {
  213. displayType: 'password',
  214. value: 'value'
  215. },
  216. result: {
  217. retypedPassword: 'value'
  218. }
  219. },
  220. {
  221. initial: {
  222. id: 'puppet var',
  223. value: '',
  224. defaultValue: 'default'
  225. },
  226. result: {
  227. value: 'default'
  228. }
  229. }
  230. ],
  231. notDefaultFalseData = [
  232. {
  233. isEditable: false
  234. },
  235. {
  236. defaultValue: null
  237. },
  238. {
  239. value: 'value',
  240. defaultValue: 'value'
  241. }
  242. ],
  243. notDefaultTrueData = {
  244. isEditable: true,
  245. value: 'value',
  246. defaultValue: 'default'
  247. },
  248. types = ['masterHost', 'slaveHosts', 'masterHosts', 'slaveHost', 'radio button'],
  249. classCases = [
  250. {
  251. initial: {
  252. displayType: 'checkbox'
  253. },
  254. viewClass: App.ServiceConfigCheckbox
  255. },
  256. {
  257. initial: {
  258. displayType: 'password'
  259. },
  260. viewClass: App.ServiceConfigPasswordField
  261. },
  262. {
  263. initial: {
  264. displayType: 'combobox'
  265. },
  266. viewClass: App.ServiceConfigComboBox
  267. },
  268. {
  269. initial: {
  270. displayType: 'radio button'
  271. },
  272. viewClass: App.ServiceConfigRadioButtons
  273. },
  274. {
  275. initial: {
  276. displayType: 'directories'
  277. },
  278. viewClass: App.ServiceConfigTextArea
  279. },
  280. {
  281. initial: {
  282. displayType: 'content'
  283. },
  284. viewClass: App.ServiceConfigTextAreaContent
  285. },
  286. {
  287. initial: {
  288. displayType: 'multiLine'
  289. },
  290. viewClass: App.ServiceConfigTextArea
  291. },
  292. {
  293. initial: {
  294. displayType: 'custom'
  295. },
  296. viewClass: App.ServiceConfigBigTextArea
  297. },
  298. {
  299. initial: {
  300. displayType: 'masterHost'
  301. },
  302. viewClass: App.ServiceConfigMasterHostView
  303. },
  304. {
  305. initial: {
  306. displayType: 'masterHosts'
  307. },
  308. viewClass: App.ServiceConfigMasterHostsView
  309. },
  310. {
  311. initial: {
  312. displayType: 'slaveHosts'
  313. },
  314. viewClass: App.ServiceConfigSlaveHostsView
  315. },
  316. {
  317. initial: {
  318. unit: true,
  319. displayType: 'type'
  320. },
  321. viewClass: App.ServiceConfigTextFieldWithUnit
  322. },
  323. {
  324. initial: {
  325. unit: false,
  326. displayType: 'type'
  327. },
  328. viewClass: App.ServiceConfigTextField
  329. }
  330. ];
  331. describe('App.ServiceConfig', function () {
  332. beforeEach(function () {
  333. serviceConfig = App.ServiceConfig.create();
  334. });
  335. describe('#errorCount', function () {
  336. it('should be 0', function () {
  337. serviceConfig.setProperties({
  338. configs: [],
  339. configCategories: []
  340. });
  341. expect(serviceConfig.get('errorCount')).to.equal(0);
  342. });
  343. it('should sum counts of all errors', function () {
  344. serviceConfig.setProperties({
  345. configs: configsData,
  346. configCategories: configCategoriesData
  347. });
  348. expect(serviceConfig.get('errorCount')).to.equal(6);
  349. });
  350. });
  351. });
  352. describe('App.ServiceConfigCategory', function () {
  353. beforeEach(function () {
  354. serviceConfigCategory = App.ServiceConfigCategory.create();
  355. });
  356. describe('#primaryName', function () {
  357. nameCases.forEach(function (item) {
  358. it('should return ' + item.primary, function () {
  359. serviceConfigCategory.set('name', item.name);
  360. expect(serviceConfigCategory.get('primaryName')).to.equal(item.primary);
  361. })
  362. });
  363. });
  364. describe('#isForMasterComponent', function () {
  365. masters.forEach(function (item) {
  366. it('should be true for ' + item.name, function () {
  367. serviceConfigCategory.set('name', item.name);
  368. expect(serviceConfigCategory.get('isForMasterComponent')).to.be.true;
  369. });
  370. });
  371. it('should be false', function () {
  372. serviceConfigCategory.set('name', 'name');
  373. expect(serviceConfigCategory.get('isForMasterComponent')).to.be.false;
  374. });
  375. });
  376. describe('#isForSlaveComponent', function () {
  377. slaves.forEach(function (item) {
  378. it('should be true for ' + item.name, function () {
  379. serviceConfigCategory.set('name', item.name);
  380. expect(serviceConfigCategory.get('isForSlaveComponent')).to.be.true;
  381. });
  382. });
  383. it('should be false', function () {
  384. serviceConfigCategory.set('name', 'name');
  385. expect(serviceConfigCategory.get('isForSlaveComponent')).to.be.false;
  386. });
  387. });
  388. describe('#slaveErrorCount', function () {
  389. it('should be 0', function () {
  390. serviceConfigCategory.set('slaveConfigs', []);
  391. expect(serviceConfigCategory.get('slaveErrorCount')).to.equal(0);
  392. });
  393. it('should sum all errorCount values', function () {
  394. serviceConfigCategory.set('slaveConfigs', groupsData);
  395. expect(serviceConfigCategory.get('slaveErrorCount')).to.equal(3);
  396. });
  397. });
  398. describe('#isAdvanced', function () {
  399. it('should be true', function () {
  400. serviceConfigCategory.set('name', 'Advanced');
  401. expect(serviceConfigCategory.get('isAdvanced')).to.be.true;
  402. });
  403. it('should be false', function () {
  404. serviceConfigCategory.set('name', 'name');
  405. expect(serviceConfigCategory.get('isAdvanced')).to.be.false;
  406. });
  407. });
  408. });
  409. describe('App.Group', function () {
  410. beforeEach(function () {
  411. group = App.Group.create();
  412. });
  413. describe('#errorCount', function () {
  414. it('should be 0', function () {
  415. group.set('properties', groupNoErrorsData);
  416. expect(group.get('errorCount')).to.equal(0);
  417. });
  418. it('should be 1', function () {
  419. group.set('properties', groupErrorsData);
  420. expect(group.get('errorCount')).to.equal(1);
  421. });
  422. });
  423. });
  424. describe('App.ServiceConfigProperty', function () {
  425. beforeEach(function () {
  426. serviceConfigProperty = App.ServiceConfigProperty.create();
  427. });
  428. describe('#overrideErrorTrigger', function () {
  429. it('should be an increment', function () {
  430. serviceConfigProperty.set('overrides', configsData[0].overrides);
  431. expect(serviceConfigProperty.get('overrideErrorTrigger')).to.equal(1);
  432. serviceConfigProperty.set('overrides', []);
  433. expect(serviceConfigProperty.get('overrideErrorTrigger')).to.equal(2);
  434. });
  435. });
  436. describe('#isPropertyOverridable', function () {
  437. overridableFalseData.forEach(function (item) {
  438. it('should be false', function () {
  439. Em.keys(item).forEach(function (prop) {
  440. serviceConfigProperty.set(prop, item[prop]);
  441. });
  442. expect(serviceConfigProperty.get('isPropertyOverridable')).to.be.false;
  443. });
  444. });
  445. overridableTrueData.forEach(function (item) {
  446. it('should be true', function () {
  447. Em.keys(item).forEach(function (prop) {
  448. serviceConfigProperty.set(prop, item[prop]);
  449. });
  450. expect(serviceConfigProperty.get('isPropertyOverridable')).to.be.true;
  451. });
  452. });
  453. });
  454. describe('#isOverridden', function () {
  455. overriddenFalseData.forEach(function (item) {
  456. it('should be false', function () {
  457. Em.keys(item).forEach(function (prop) {
  458. serviceConfigProperty.set(prop, item[prop]);
  459. });
  460. expect(serviceConfigProperty.get('isOverridden')).to.be.false;
  461. });
  462. });
  463. overriddenTrueData.forEach(function (item) {
  464. it('should be true', function () {
  465. Em.keys(item).forEach(function (prop) {
  466. serviceConfigProperty.set(prop, item[prop]);
  467. });
  468. expect(serviceConfigProperty.get('isOverridden')).to.be.true;
  469. });
  470. });
  471. });
  472. describe('#isRemovable', function () {
  473. removableFalseData.forEach(function (item) {
  474. it('should be false', function () {
  475. Em.keys(item).forEach(function (prop) {
  476. serviceConfigProperty.set(prop, item[prop]);
  477. });
  478. expect(serviceConfigProperty.get('isRemovable')).to.be.false;
  479. });
  480. });
  481. removableTrueData.forEach(function (item) {
  482. it('should be true', function () {
  483. Em.keys(item).forEach(function (prop) {
  484. serviceConfigProperty.set(prop, item[prop]);
  485. });
  486. expect(serviceConfigProperty.get('isRemovable')).to.be.true;
  487. });
  488. });
  489. });
  490. describe('#init', function () {
  491. initPropertyData.forEach(function (item) {
  492. it('should set initial data', function () {
  493. serviceConfigPropertyInit = App.ServiceConfigProperty.create(item.initial);
  494. Em.keys(item.result).forEach(function (prop) {
  495. expect(serviceConfigPropertyInit.get(prop)).to.equal(item.result[prop]);
  496. });
  497. });
  498. });
  499. });
  500. describe('#isNotDefaultValue', function () {
  501. notDefaultFalseData.forEach(function (item) {
  502. it('should be false', function () {
  503. Em.keys(item).forEach(function (prop) {
  504. serviceConfigProperty.set(prop, item[prop]);
  505. });
  506. expect(serviceConfigProperty.get('isNotDefaultValue')).to.be.false;
  507. });
  508. });
  509. it('should be true', function () {
  510. Em.keys(notDefaultTrueData).forEach(function (prop) {
  511. serviceConfigProperty.set(prop, notDefaultTrueData[prop]);
  512. });
  513. expect(serviceConfigProperty.get('isNotDefaultValue')).to.be.true;
  514. });
  515. });
  516. describe('#cantBeUndone', function () {
  517. types.forEach(function (item) {
  518. it('should be true', function () {
  519. serviceConfigProperty.set('displayType', item);
  520. expect(serviceConfigProperty.get('cantBeUndone')).to.be.true;
  521. });
  522. });
  523. it('should be false', function () {
  524. serviceConfigProperty.set('displayType', 'type');
  525. expect(serviceConfigProperty.get('cantBeUndone')).to.be.false;
  526. });
  527. });
  528. describe('#setDefaultValue', function () {
  529. it('should change the default value', function () {
  530. serviceConfigProperty.set('defaultValue', 'value0');
  531. serviceConfigProperty.setDefaultValue(/\d/, '1');
  532. expect(serviceConfigProperty.get('defaultValue')).to.equal('value1');
  533. });
  534. });
  535. describe('#isValid', function () {
  536. it('should be true', function () {
  537. serviceConfigProperty.set('errorMessage', '');
  538. expect(serviceConfigProperty.get('isValid')).to.be.true;
  539. });
  540. it('should be false', function () {
  541. serviceConfigProperty.set('errorMessage', 'message');
  542. expect(serviceConfigProperty.get('isValid')).to.be.false;
  543. });
  544. });
  545. describe('#viewClass', function () {
  546. classCases.forEach(function (item) {
  547. it ('should be ' + item.viewClass, function () {
  548. Em.keys(item.initial).forEach(function (prop) {
  549. serviceConfigProperty.set(prop, item.initial[prop]);
  550. });
  551. expect(serviceConfigProperty.get('viewClass')).to.eql(item.viewClass);
  552. });
  553. });
  554. });
  555. describe('#validate', function () {
  556. it('not required', function () {
  557. serviceConfigProperty.setProperties({
  558. isRequired: false,
  559. value: ''
  560. });
  561. expect(serviceConfigProperty.get('errorMessage')).to.be.empty;
  562. expect(serviceConfigProperty.get('error')).to.be.false;
  563. });
  564. it('should validate', function () {
  565. serviceConfigProperty.setProperties({
  566. isRequired: true,
  567. value: 'value'
  568. });
  569. expect(serviceConfigProperty.get('errorMessage')).to.be.empty;
  570. expect(serviceConfigProperty.get('error')).to.be.false;
  571. });
  572. it('should fail', function () {
  573. serviceConfigProperty.setProperties({
  574. isRequired: true,
  575. value: 'value'
  576. });
  577. serviceConfigProperty.set('value', '');
  578. expect(serviceConfigProperty.get('errorMessage')).to.equal('This is required');
  579. expect(serviceConfigProperty.get('error')).to.be.true;
  580. });
  581. });
  582. });