item_test.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  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('views/main/service/item');
  20. var view;
  21. function getView() {
  22. return App.MainServiceItemView.create({
  23. controller: Em.Object.create({
  24. content: Em.Object.create({
  25. hostComponents: []
  26. })
  27. })
  28. });
  29. }
  30. describe('App.MainServiceItemView', function () {
  31. App.TestAliases.testAsComputedAlias(getView(), 'serviceName', 'controller.content.serviceName', 'string');
  32. App.TestAliases.testAsComputedAlias(getView(), 'displayName', 'controller.content.displayName', 'string');
  33. describe('#mastersExcludedCommands', function () {
  34. view = App.MainServiceItemView.create({
  35. controller: Em.Object.create({
  36. content: Em.Object.create({
  37. hostComponents: []
  38. })
  39. })
  40. });
  41. var nonCustomAction = ['RESTART_ALL', 'RUN_SMOKE_TEST', 'REFRESH_CONFIGS', 'ROLLING_RESTART', 'TOGGLE_PASSIVE', 'TOGGLE_NN_HA', 'TOGGLE_RM_HA', 'MOVE_COMPONENT', 'DOWNLOAD_CLIENT_CONFIGS', 'MASTER_CUSTOM_COMMAND'];
  42. var keys = Object.keys(view.mastersExcludedCommands);
  43. var mastersExcludedCommands = [];
  44. for (var i = 0; i < keys.length; i++) {
  45. mastersExcludedCommands[i] = view.mastersExcludedCommands[keys[i]];
  46. }
  47. var allMastersExcludedCommands = mastersExcludedCommands.reduce(function (previous, current) {
  48. return previous.concat(current);
  49. });
  50. var actionMap = App.HostComponentActionMap.getMap(view);
  51. var customActionsArray = [];
  52. Object.keys(actionMap).forEach(function (iter) {
  53. customActionsArray.push(actionMap[iter]);
  54. });
  55. var customActions = customActionsArray.mapProperty('customCommand').filter(function (action) {
  56. return !nonCustomAction.contains(action);
  57. }).uniq();
  58. // remove null and undefined from the list
  59. customActions = customActions.filter(function (value) {
  60. return !Em.isNone(value);
  61. });
  62. customActions.forEach(function (action) {
  63. it(action + ' should be present in App.MainServiceItemView mastersExcludedCommands object', function () {
  64. expect(allMastersExcludedCommands).to.contain(action);
  65. });
  66. });
  67. });
  68. describe('#observeMaintenance', function () {
  69. var cases = [
  70. {
  71. isMaintenanceSet: true,
  72. isServicesInfoLoaded: true,
  73. isServiceConfigsLoaded: true,
  74. observeMaintenanceOnceCallCount: 0,
  75. title: 'actions array set, services info loaded'
  76. },
  77. {
  78. isMaintenanceSet: true,
  79. isServicesInfoLoaded: false,
  80. isServiceConfigsLoaded: true,
  81. observeMaintenanceOnceCallCount: 0,
  82. title: 'actions array set, services info not loaded'
  83. },
  84. {
  85. isMaintenanceSet: false,
  86. isServicesInfoLoaded: true,
  87. isServiceConfigsLoaded: true,
  88. observeMaintenanceOnceCallCount: 1,
  89. title: 'actions array not set, services info loaded'
  90. },
  91. {
  92. isMaintenanceSet: false,
  93. isServicesInfoLoaded: false,
  94. isServiceConfigsLoaded: true,
  95. observeMaintenanceOnceCallCount: 0,
  96. title: 'actions array not set, services info not loaded'
  97. }
  98. ];
  99. beforeEach(function () {
  100. sinon.stub(view, 'observeMaintenanceOnce', Em.K);
  101. });
  102. afterEach(function () {
  103. view.observeMaintenanceOnce.restore();
  104. });
  105. cases.forEach(function (item) {
  106. it(item.title, function () {
  107. view.setProperties({
  108. 'isMaintenanceSet': item.isMaintenanceSet,
  109. 'controller.isServicesInfoLoaded': item.isServicesInfoLoaded,
  110. 'controller.isServiceConfigsLoaded': item.isServiceConfigsLoaded
  111. });
  112. view.observeMaintenance();
  113. expect(view.observeMaintenanceOnce.callCount).to.equal(item.observeMaintenanceOnceCallCount);
  114. });
  115. });
  116. });
  117. describe('#observeMaintenanceOnce', function () {
  118. var mastersExcludedCommands = {
  119. NAMENODE: ["DECOMMISSION", "REBALANCEHDFS"],
  120. RESOURCEMANAGER: ["DECOMMISSION", "REFRESHQUEUES"],
  121. HBASE_MASTER: ["DECOMMISSION"],
  122. KNOX_GATEWAY: ["STARTDEMOLDAP", "STOPDEMOLDAP"]
  123. },
  124. hasConfigTab = true,
  125. testCases = [
  126. {
  127. serviceName: "HDFS",
  128. displayName: "HDFS",
  129. isSingleNode: true,
  130. serviceTypes: ["HA_MODE"],
  131. slaveComponents: [
  132. Em.Object.create({
  133. componentName: 'DATANODE',
  134. totalCount: 1
  135. })
  136. ],
  137. clientComponents: [
  138. Em.Object.create({
  139. componentName: 'HDFS_CLIENT',
  140. totalCount: 1
  141. })
  142. ],
  143. hostComponents: [
  144. Em.Object.create({
  145. componentName: 'NAMENODE',
  146. isNotInstalled: true,
  147. isMaster: true,
  148. isSlave: false
  149. }),
  150. Em.Object.create({
  151. componentName: 'SECONDARY_NAMENODE',
  152. isMaster: true,
  153. isSlave: false
  154. })
  155. ],
  156. result: [
  157. {"action": "restartAllHostComponents", "context": "HDFS", "label": "Restart All", "cssClass": "icon-repeat", "disabled": false},
  158. {"action": "rollingRestart", "label": "Restart DataNodes", "cssClass": "icon-time", "disabled": false, "context": "DATANODE"},
  159. {"action": "reassignMaster", "context": "NAMENODE", "label": "Move NameNode", "cssClass": "icon-share-alt", "disabled": false},
  160. {"action": "reassignMaster", "context": "SECONDARY_NAMENODE", "label": "Move SNameNode", "cssClass": "icon-share-alt", "disabled": false},
  161. {"action": "enableHighAvailability", "label": "Enable NameNode HA", "cssClass": "icon-arrow-up", "isHidden": false, "disabled": true},
  162. {"action": "runSmokeTest", "label": "Run Service Check", "cssClass": "icon-thumbs-up-alt", "disabled": false},
  163. {"action": "turnOnOffPassive", "context": "Turn On Maintenance Mode for HDFS", "label": "Turn On Maintenance Mode", "cssClass": "icon-medkit", "disabled": false},
  164. {"action": "rebalanceHdfsNodes", "customCommand": "REBALANCEHDFS", "context": "Rebalance HDFS", "label": "Rebalance HDFS", "cssClass": "icon-refresh", "disabled": false},
  165. {"action": "downloadClientConfigs", "label": "Download Client Configs", "cssClass": "icon-download-alt", "isHidden": false, "disabled": false, hasSubmenu: false, submenuOptions: []}
  166. ]
  167. },
  168. {
  169. serviceName: "ZOOKEEPER",
  170. displayName: "ZooKeeper",
  171. serviceTypes: [],
  172. slaveComponents: [],
  173. clientComponents: [
  174. Em.Object.create({
  175. componentName: 'ZOOKEEPER_CLIENT',
  176. totalCount: 1
  177. })
  178. ],
  179. hostComponents: [
  180. Em.Object.create({
  181. componentName: 'ZOOKEEPER_SERVER',
  182. isMaster: true,
  183. isSlave: false
  184. })
  185. ],
  186. controller: [
  187. {'addDisabledTooltipZOOKEEPER_SERVER': ''},
  188. {'isAddDisabled-ZOOKEEPER_SERVER': 'disabled'}
  189. ],
  190. result: [
  191. {"action": "restartAllHostComponents", "context": "ZOOKEEPER", "label": "Restart All", "cssClass": "icon-repeat", "disabled": false},
  192. {"action": "runSmokeTest", "label": "Run Service Check", "cssClass": "icon-thumbs-up-alt", "disabled": false},
  193. {"action": "turnOnOffPassive", "context": "Turn On Maintenance Mode for ZooKeeper", "label": "Turn On Maintenance Mode", "cssClass": "icon-medkit", "disabled": false},
  194. {"cssClass": "icon-plus", "label": "Add ZooKeeper Server", "service": "ZOOKEEPER", "component": "ZOOKEEPER_SERVER", "action": "addComponent", "disabled": "", tooltip: ''},
  195. {"action": "downloadClientConfigs", "label": "Download Client Configs", "cssClass": "icon-download-alt", "isHidden": false, "disabled": false, "hasSubmenu": false, "submenuOptions": []}
  196. ]
  197. },
  198. {
  199. serviceName: "YARN",
  200. displayName: "YARN",
  201. serviceTypes: ['HA_MODE'],
  202. slaveComponents: [
  203. Em.Object.create({
  204. componentName: 'NODEMANAGER',
  205. totalCount: 1
  206. })
  207. ],
  208. clientComponents: [
  209. Em.Object.create({
  210. componentName: 'YARN_CLIENT',
  211. totalCount: 1
  212. })
  213. ],
  214. hostComponents: [
  215. Em.Object.create({
  216. componentName: 'APP_TIMELINE_SERVER',
  217. isMaster: true,
  218. isSlave: false
  219. }),
  220. Em.Object.create({
  221. componentName: 'RESOURCEMANAGER',
  222. isMaster: true,
  223. isSlave: false,
  224. isNotInstalled: false
  225. })
  226. ],
  227. result: [
  228. {"action": "refreshYarnQueues", "customCommand": "REFRESHQUEUES", "context": "Refresh YARN Capacity Scheduler", "label": "Refresh YARN Capacity Scheduler", "cssClass": "icon-refresh", "disabled": false},
  229. {"action": "restartAllHostComponents", "context": "YARN", "label": "Restart All", "cssClass": "icon-repeat", "disabled": false},
  230. {"action": "rollingRestart", "label": "Restart NodeManagers", "cssClass": "icon-time", "disabled": false, "context": "NODEMANAGER"},
  231. {"action": "reassignMaster", "context": "APP_TIMELINE_SERVER", "label": "Move App Timeline Server", "cssClass": "icon-share-alt", "disabled": false},
  232. {"action": "reassignMaster", "context": "RESOURCEMANAGER", "label": "Move ResourceManager", "cssClass": "icon-share-alt", "disabled": false},
  233. {"action": "enableRMHighAvailability", "label": "Enable ResourceManager HA", "cssClass": "icon-arrow-up", "isHidden": false, disabled: false},
  234. {"action": "runSmokeTest", "label": "Run Service Check", "cssClass": "icon-thumbs-up-alt", "disabled": false},
  235. {"action": "turnOnOffPassive", "context": "Turn On Maintenance Mode for YARN", "label": "Turn On Maintenance Mode", "cssClass": "icon-medkit", "disabled": false},
  236. {"action": "downloadClientConfigs", "label": "Download Client Configs", "cssClass": "icon-download-alt", "isHidden": false, "disabled": false, "hasSubmenu": false, "submenuOptions": []}
  237. ]
  238. },
  239. {
  240. serviceName: "MAPREDUCE2",
  241. displayName: "MapReduce2",
  242. serviceTypes: [],
  243. slaveComponents: [],
  244. clientComponents: [
  245. Em.Object.create({
  246. componentName: 'MAPREDUCE2_CLIENT',
  247. totalCount: 1
  248. })
  249. ],
  250. hostComponents: [
  251. Em.Object.create({
  252. componentName: 'HISTORYSERVER',
  253. isMaster: true,
  254. isSlave: false
  255. })
  256. ],
  257. result: [
  258. {"action": "restartAllHostComponents", "context": "MAPREDUCE2", "label": "Restart All", "cssClass": "icon-repeat", "disabled": false},
  259. {"action": "runSmokeTest", "label": "Run Service Check", "cssClass": "icon-thumbs-up-alt", "disabled": false},
  260. {"action": "turnOnOffPassive", "context": "Turn On Maintenance Mode for MapReduce2", "label": "Turn On Maintenance Mode", "cssClass": "icon-medkit", "disabled": false},
  261. {"action": "downloadClientConfigs", "label": "Download Client Configs", "cssClass": "icon-download-alt", "isHidden": false, "disabled": false, "hasSubmenu": false, "submenuOptions": []}
  262. ]
  263. },
  264. {
  265. serviceName: "KAFKA",
  266. displayName: "Kafka",
  267. serviceTypes: [],
  268. slaveComponents: [],
  269. clientComponents: [],
  270. hostComponents: [
  271. Em.Object.create({
  272. componentName: 'KAFKA_BROKER',
  273. isMaster: true,
  274. isSlave: false
  275. })
  276. ],
  277. result: [
  278. {"action": "restartAllHostComponents", "context": "KAFKA", "label": "Restart All", "cssClass": "icon-repeat", "disabled": false},
  279. {"action": "runSmokeTest", "label": "Run Service Check", "cssClass": "icon-thumbs-up-alt", "disabled": false},
  280. {"action": "turnOnOffPassive", "context": "Turn On Maintenance Mode for Kafka", "label": "Turn On Maintenance Mode", "cssClass": "icon-medkit", "disabled": false},
  281. {"action": "downloadClientConfigs", "label": "Download Client Configs", "cssClass": "icon-download-alt", "isHidden": true, "disabled": false, "hasSubmenu": false, "submenuOptions": []}
  282. ]
  283. },
  284. {
  285. serviceName: "FLUME",
  286. displayName: "Flume",
  287. serviceTypes: [],
  288. clientComponents: [],
  289. slaveComponents: [
  290. Em.Object.create({
  291. componentName: 'FLUME_HANDLER',
  292. totalCount: 1
  293. })
  294. ],
  295. hostComponents: [
  296. ],
  297. controller: [
  298. {'addDisabledTooltipFLUME_HANDLER': ''},
  299. {'isAddDisabled-FLUME_HANDLER': ''}
  300. ],
  301. result: [
  302. {"action": "refreshConfigs", "label": "Refresh configs", "cssClass": "icon-refresh", "disabled": false},
  303. {"action": "restartAllHostComponents", "context": "FLUME", "label": "Restart All", "cssClass": "icon-repeat", "disabled": false},
  304. {"action": "rollingRestart", "label": "Restart Flumes", "cssClass": "icon-time", "disabled": false, "context": "FLUME_HANDLER"},
  305. {"action": "runSmokeTest", "label": "Run Service Check", "cssClass": "icon-thumbs-up-alt", "disabled": false},
  306. {"action": "turnOnOffPassive", "context": "Turn On Maintenance Mode for Flume", "label": "Turn On Maintenance Mode", "cssClass": "icon-medkit", "disabled": false},
  307. {"cssClass": "icon-plus", "label": "Add Flume Component", "service": "FLUME", "component": "FLUME_HANDLER", "action": "addComponent", "disabled": '', tooltip: ''},
  308. {"action": "downloadClientConfigs", "label": "Download Client Configs", "cssClass": "icon-download-alt", "isHidden": true, "disabled": false, "hasSubmenu": false, "submenuOptions": []}
  309. ]
  310. },
  311. {
  312. serviceName: "HBASE",
  313. displayName: "HBase",
  314. serviceTypes: [],
  315. slaveComponents: [
  316. Em.Object.create({
  317. componentName: 'HBASE_REGIONSERVER',
  318. totalCount: 1
  319. })
  320. ],
  321. clientComponents: [
  322. Em.Object.create({
  323. componentName: 'HBASE_CLIENT',
  324. totalCount: 1
  325. })
  326. ],
  327. hostComponents: [
  328. Em.Object.create({
  329. componentName: 'HBASE_MASTER',
  330. isMaster: true,
  331. isSlave: false
  332. })
  333. ],
  334. controller: [
  335. {'addDisabledTooltipHBASE_MASTER': ''},
  336. {'isAddDisabled-HBASE_MASTER': ''}
  337. ],
  338. result: [
  339. {"action": "restartAllHostComponents", "context": "HBASE", "label": "Restart All", "cssClass": "icon-repeat", "disabled": false},
  340. {"action": "rollingRestart", "label": "Restart RegionServers", "cssClass": "icon-time", "disabled": false, "context": "HBASE_REGIONSERVER"},
  341. {"action": "runSmokeTest", "label": "Run Service Check", "cssClass": "icon-thumbs-up-alt", "disabled": false},
  342. {"action": "turnOnOffPassive", "context": "Turn On Maintenance Mode for HBase", "label": "Turn On Maintenance Mode", "cssClass": "icon-medkit", "disabled": false},
  343. {"cssClass": "icon-plus", "label": "Add HBase Master", "service": "HBASE", "component": "HBASE_MASTER", "action": "addComponent", "disabled": '', tooltip: ''},
  344. {"action": "downloadClientConfigs", "label": "Download Client Configs", "cssClass": "icon-download-alt", "isHidden": false, "disabled": false, "hasSubmenu": false, "submenuOptions": []}
  345. ]
  346. },
  347. {
  348. serviceName: "OOZIE",
  349. displayName: "Oozie",
  350. serviceTypes: [],
  351. slaveComponents: [],
  352. clientComponents: [
  353. Em.Object.create({
  354. componentName: 'OOZIE_CLIENT',
  355. totalCount: 1
  356. })
  357. ],
  358. hostComponents: [
  359. Em.Object.create({
  360. componentName: 'OOZIE_SERVER',
  361. isMaster: true,
  362. isSlave: false
  363. })
  364. ],
  365. result: [
  366. {"action": "restartAllHostComponents", "context": "OOZIE", "label": "Restart All", "cssClass": "icon-repeat", "disabled": false},
  367. {"action": "reassignMaster", "context": "OOZIE_SERVER", "label": "Move Oozie Server", "cssClass": "icon-share-alt", "disabled": false},
  368. {"action": "runSmokeTest", "label": "Run Service Check", "cssClass": "icon-thumbs-up-alt", "disabled": false},
  369. {"action": "turnOnOffPassive", "context": "Turn On Maintenance Mode for Oozie", "label": "Turn On Maintenance Mode", "cssClass": "icon-medkit", "disabled": false},
  370. {"cssClass": "icon-plus", "label": "Add Oozie Server", "service": "OOZIE", "component": "OOZIE_SERVER", "action": "addComponent", "disabled": "disabled", tooltip: Em.I18n.t('services.summary.allHostsAlreadyRunComponent').format('OOZIE_SERVER')},
  371. {"action": "downloadClientConfigs", "label": "Download Client Configs", "cssClass": "icon-download-alt", "isHidden": false, "disabled": false, "hasSubmenu": false, "submenuOptions": []}
  372. ]
  373. },
  374. {
  375. serviceName: "KNOX",
  376. displayName: "Knox",
  377. serviceTypes: [],
  378. slaveComponents: [],
  379. clientComponents: [],
  380. hostComponents: [
  381. Em.Object.create({
  382. componentName: 'KNOX_GATEWAY',
  383. isMaster: true,
  384. isSlave: false
  385. })
  386. ],
  387. result: [
  388. {"action": "restartAllHostComponents", "context": "KNOX", "label": "Restart All", "cssClass": "icon-repeat", "disabled": false},
  389. {"action": "runSmokeTest", "label": "Run Service Check", "cssClass": "icon-thumbs-up-alt", "disabled": false},
  390. {"action": "turnOnOffPassive", "context": "Turn On Maintenance Mode for Knox", "label": "Turn On Maintenance Mode", "cssClass": "icon-medkit", "disabled": false},
  391. {"action": "startLdapKnox", "customCommand": "STARTDEMOLDAP", "context": "Start Demo LDAP", "label": "Start Demo LDAP", "cssClass": "icon-play-sign", "disabled": false},
  392. {"action": "stopLdapKnox", "customCommand": "STOPDEMOLDAP", "context": "Stop Demo LDAP", "label": "Stop Demo LDAP", "cssClass": "icon-stop", "disabled": false},
  393. {"action": "downloadClientConfigs", "label": "Download Client Configs", "cssClass": "icon-download-alt", "isHidden": true, "disabled": false, "hasSubmenu": false, "submenuOptions": []}
  394. ]
  395. },
  396. {
  397. serviceName: "STORM",
  398. displayName: "Storm",
  399. serviceTypes: [],
  400. slaveComponents: [],
  401. clientComponents: [],
  402. hostComponents: [
  403. Em.Object.create({
  404. componentName: 'NIMBUS',
  405. isMaster: true,
  406. isSlave: false
  407. })
  408. ],
  409. result: [
  410. {"action": "restartAllHostComponents", "context": "STORM", "label": "Restart All", "cssClass": "icon-repeat", "disabled": false},
  411. {"action": "runSmokeTest", "label": "Run Service Check", "cssClass": "icon-thumbs-up-alt", "disabled": false},
  412. {"action": "turnOnOffPassive", "context": "Turn On Maintenance Mode for Storm", "label": "Turn On Maintenance Mode", "cssClass": "icon-medkit", "disabled": false},
  413. {"action": "downloadClientConfigs", "label": "Download Client Configs", "cssClass": "icon-download-alt", "isHidden": true, "disabled": false, "hasSubmenu": false, "submenuOptions": []}
  414. ]
  415. }
  416. ];
  417. beforeEach(function () {
  418. view = App.MainServiceItemView.create({});
  419. sinon.stub(App, 'get', function (k) {
  420. switch (k) {
  421. case 'isSingleNode':
  422. return view.get('controller.content.serviceName') === 'HDFS';
  423. case 'supports.autoRollbackHA':
  424. case 'isRMHaEnabled':
  425. case 'isHaEnabled':
  426. return false;
  427. case 'components.rollinRestartAllowed':
  428. return ["DATANODE", "JOURNALNODE", "ZKFC", "NODEMANAGER", "GANGLIA_MONITOR", "HBASE_REGIONSERVER", "SUPERVISOR", "FLUME_HANDLER"];
  429. case 'components.reassignable':
  430. return ["NAMENODE", "SECONDARY_NAMENODE", "APP_TIMELINE_SERVER", "RESOURCEMANAGER", "WEBHCAT_SERVER", "OOZIE_SERVER"];
  431. case 'services.supportsServiceCheck':
  432. return ["HDFS", "MAPREDUCE2", "YARN", "HIVE", "HBASE", "PIG", "SQOOP", "OOZIE", "ZOOKEEPER", "FALCON", "STORM", "FLUME", "SLIDER", "KNOX", "KAFKA"];
  433. case 'components.addableToHost':
  434. return ["DATANODE", "HDFS_CLIENT", "MAPREDUCE2_CLIENT", "NODEMANAGER", "YARN_CLIENT", "TEZ_CLIENT", "GANGLIA_MONITOR", "HCAT", "HIVE_CLIENT", "HIVE_METASTORE", "HIVE_SERVER", "WEBHCAT_SERVER", "HBASE_CLIENT", "HBASE_MASTER", "HBASE_REGIONSERVER", "PIG", "SQOOP", "OOZIE_CLIENT", "OOZIE_SERVER", "ZOOKEEPER_CLIENT", "ZOOKEEPER_SERVER", "FALCON_CLIENT", "SUPERVISOR", "FLUME_HANDLER", "METRICS_MONITOR", "KAFKA_BROKER", "KERBEROS_CLIENT", "KNOX_GATEWAY", "SLIDER", "SPARK_CLIENT"];
  435. case 'allHostNames.length':
  436. return 2;
  437. default:
  438. return Em.get(App, k);
  439. }
  440. });
  441. sinon.stub(App.HostComponent, 'find', function () {
  442. return [
  443. Em.Object.create({
  444. hostName: 'host1',
  445. componentName: 'NAMENODE'
  446. }),
  447. Em.Object.create({
  448. hostName: 'host1',
  449. componentName: 'SECONDARY_NAMENODE'
  450. }),
  451. Em.Object.create({
  452. hostName: 'host1',
  453. componentName: 'APP_TIMELINE_SERVER'
  454. }),
  455. Em.Object.create({
  456. hostName: 'host1',
  457. componentName: 'RESOURCEMANAGER'
  458. }),
  459. Em.Object.create({
  460. hostName: 'host1',
  461. componentName: 'OOZIE_SERVER'
  462. })
  463. ];
  464. });
  465. /*eslint-disable complexity */
  466. sinon.stub(App.StackServiceComponent, 'find', function (id) {
  467. switch (id) {
  468. case 'NAMENODE':
  469. return Em.Object.create({ customCommands: ["DECOMMISSION", "REBALANCEHDFS"] });
  470. case 'RESOURCEMANAGER':
  471. return Em.Object.create({ customCommands: ["DECOMMISSION", "REFRESHQUEUES"] });
  472. case 'HBASE_MASTER':
  473. return Em.Object.create({ customCommands: ["DECOMMISSION"] });
  474. case 'KNOX_GATEWAY':
  475. return Em.Object.create({ customCommands: ["STARTDEMOLDAP", "STOPDEMOLDAP"] });
  476. case 'HISTORYSERVER':
  477. case 'SECONDARY_NAMENODE':
  478. case 'ZOOKEEPER_SERVER':
  479. case 'APP_TIMELINE_SERVER':
  480. case 'KAFKA_BROKER':
  481. case 'OOZIE_SERVER':
  482. case 'NIMBUS':
  483. return Em.Object.create({ customCommands: [] });
  484. default:
  485. return [
  486. Em.Object.create({
  487. customCommands: ["DECOMMISSION", "REBALANCEHDFS"],
  488. componentName: 'NAMENODE'
  489. }),
  490. Em.Object.create({
  491. customCommands: ["STARTDEMOLDAP", "STOPDEMOLDAP"],
  492. componentName: 'KNOX_GATEWAY'
  493. })
  494. ];
  495. }
  496. });
  497. /*eslint-enable complexity */
  498. });
  499. afterEach(function () {
  500. App.get.restore();
  501. App.HostComponent.find.restore();
  502. App.StackServiceComponent.find.restore();
  503. });
  504. testCases.forEach(function (testCase) {
  505. describe('Maintenance for ' + testCase.serviceName + ' service', function () {
  506. beforeEach(function () {
  507. view.reopen({
  508. controller: Em.Object.create({
  509. content: Em.Object.create({
  510. hostComponents: testCase.hostComponents,
  511. slaveComponents: testCase.slaveComponents,
  512. clientComponents: testCase.clientComponents,
  513. serviceName: testCase.serviceName,
  514. displayName: testCase.displayName,
  515. serviceTypes: testCase.serviceTypes,
  516. passiveState: 'OFF'
  517. }),
  518. isSeveralClients: false,
  519. clientComponents: [],
  520. isStopDisabled: false
  521. }),
  522. mastersExcludedCommands: mastersExcludedCommands,
  523. hasConfigTab: hasConfigTab
  524. });
  525. if (testCase.controller) {
  526. testCase.controller.forEach(function (item) {
  527. Object.keys(item).forEach(function (key) {
  528. view.set('controller.' + key, item[key]);
  529. });
  530. });
  531. }
  532. view.observeMaintenanceOnce();
  533. });
  534. testCase.result.forEach(function (option, index) {
  535. Object.keys(option).forEach(function (key) {
  536. it(option.action + ', key - ' + key, function () {
  537. var r = view.get('maintenance')[index];
  538. expect(Em.get(option, key)).to.eql(Em.get(r, key));
  539. });
  540. });
  541. });
  542. it('maintenance is updated', function () {
  543. var oldMaintenance = JSON.parse(JSON.stringify(view.get('maintenance')));
  544. view.set('controller.content.passiveState', 'ON');
  545. view.observeMaintenanceOnce();
  546. expect(view.get('maintenance')).to.not.eql(oldMaintenance);
  547. expect(view.get('isMaintenanceSet')).to.be.true;
  548. });
  549. });
  550. });
  551. });
  552. describe('#clearIsMaintenanceSet', function () {
  553. it('isMaintenanceSet should be false', function () {
  554. view.set('isMaintenanceSet', true);
  555. view.clearIsMaintenanceSet();
  556. expect(view.get('isMaintenanceSet')).to.be.false;
  557. });
  558. });
  559. });