step4_controller.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. var stringUtils = require('utils/string_utils');
  20. App.WizardStep4Controller = Em.ArrayController.extend({
  21. name: 'wizardStep4Controller',
  22. /**
  23. * List of Services
  24. * @type {Object[]}
  25. */
  26. content: [],
  27. /**
  28. * Is Submit button disabled
  29. * @type {bool}
  30. */
  31. isSubmitDisabled: function () {
  32. return this.filterProperty('isSelected', true).filterProperty('isInstalled', false).length === 0;
  33. }.property("@each.isSelected"),
  34. /**
  35. * Check whether all properties are selected
  36. * @type {bool}
  37. */
  38. isAll: function () {
  39. return this.filterProperty('canBeSelected', true).everyProperty('isSelected', true);
  40. }.property('@each.isSelected'),
  41. /**
  42. * Check whether none properties(minimum) are selected
  43. * @type {bool}
  44. */
  45. isMinimum: function () {
  46. return this.filterProperty('isDisabled', false).everyProperty('isSelected', false);
  47. }.property('@each.isSelected'),
  48. /**
  49. * submit checks describe dependency rules between services
  50. * checkCallback - callback, which check for dependency
  51. * popupParams - parameters for popup
  52. * @type {{checkCallback: string, popupParams: Ember.Enumerable}[]}
  53. */
  54. submitChecks: [
  55. {
  56. checkCallback: 'needToAddMapReduce',
  57. popupParams: [
  58. {serviceName: 'MAPREDUCE', selected: true},
  59. 'mapreduceCheck'
  60. ]
  61. },
  62. {
  63. checkCallback: 'noDFSs',
  64. popupParams: [
  65. {serviceName: 'HDFS', selected: true},
  66. 'hdfsCheck'
  67. ]
  68. },
  69. {
  70. checkCallback: 'needToAddYarnMapReduce2',
  71. popupParams: [
  72. {serviceName: 'YARN', selected: true},
  73. 'yarnCheck'
  74. ]
  75. },
  76. {
  77. checkCallback: 'needToAddZooKeeper',
  78. popupParams: [
  79. {serviceName: 'ZOOKEEPER', selected: true},
  80. 'zooKeeperCheck'
  81. ]
  82. },
  83. {
  84. checkCallback: 'multipleDFSs',
  85. popupParams: [
  86. [
  87. {serviceName: 'HDFS', selected: true},
  88. {serviceName: 'GLUSTERFS', selected: false}
  89. ],
  90. 'multipleDFS'
  91. ]
  92. },
  93. {
  94. checkCallback: 'needToAddOozie',
  95. popupParams: [
  96. {serviceName: 'OOZIE', selected: true},
  97. 'oozieCheck'
  98. ]
  99. },
  100. {
  101. checkCallback: 'needToAddTez',
  102. popupParams: [
  103. {serviceName: 'TEZ', selected: true},
  104. 'tezCheck'
  105. ]
  106. }
  107. ],
  108. /**
  109. * Update hidden services. Make them to have the same status as master ones.
  110. * @method checkDependencies
  111. */
  112. checkDependencies: function () {
  113. var services = {};
  114. this.forEach(function (service) {
  115. services[service.get('serviceName')] = service;
  116. });
  117. // prevent against getting error when not all elements have been loaded yet
  118. if (services['HBASE'] && services['ZOOKEEPER'] && services['HIVE'] && services['HCATALOG'] && services['WEBHCAT']) {
  119. if (services['YARN'] && services['MAPREDUCE2']) {
  120. services['MAPREDUCE2'].set('isSelected', services['YARN'].get('isSelected'));
  121. }
  122. services['HCATALOG'].set('isSelected', services['HIVE'].get('isSelected'));
  123. services['WEBHCAT'].set('isSelected', services['HIVE'].get('isSelected'));
  124. }
  125. }.observes('@each.isSelected'),
  126. /**
  127. * Onclick handler for <code>select all</code> link
  128. * @method selectAll
  129. */
  130. selectAll: function () {
  131. this.filterProperty('canBeSelected', true).setEach('isSelected', true);
  132. },
  133. /**
  134. * Onclick handler for <code>select minimum</code> link
  135. * @method selectMinimum
  136. */
  137. selectMinimum: function () {
  138. this.filterProperty('isDisabled', false).setEach('isSelected', false);
  139. },
  140. /**
  141. * Check whether we should turn on <code>serviceName</code> service according to selected <code>dependentServices</code>
  142. * @param serviceName checked service
  143. * @param dependentServices list of dependent services
  144. * @returns {bool}
  145. * @method needAddService
  146. */
  147. needAddService: function (serviceName, dependentServices) {
  148. if (!(dependentServices instanceof Array)) {
  149. dependentServices = [dependentServices];
  150. }
  151. if (this.findProperty('serviceName', serviceName) && this.findProperty('serviceName', serviceName).get('isSelected') === false) {
  152. var ds = this.filter(function (item) {
  153. return dependentServices.contains(item.get('serviceName')) && item.get('isSelected');
  154. });
  155. return (ds.get('length') > 0);
  156. }
  157. return false;
  158. },
  159. /**
  160. * Check whether we should turn on <code>Oozie</code> service
  161. * @return {bool}
  162. * @method needToAddOozie
  163. */
  164. needToAddOozie: function () {
  165. return this.needAddService('OOZIE', ['FALCON']);
  166. },
  167. /**
  168. * Check whether we should turn on <code>MapReduce</code> service
  169. * @return {bool}
  170. * @method needToAddMapReduce
  171. */
  172. needToAddMapReduce: function () {
  173. return this.needAddService('MAPREDUCE', ['PIG', 'OOZIE', 'HIVE']);
  174. },
  175. /**
  176. * Check whether we should turn on <code>MapReduce2</code> service
  177. * @return {bool}
  178. * @method needToAddYarnMapReduce2
  179. */
  180. needToAddYarnMapReduce2: function () {
  181. return this.needAddService('YARN', ['PIG', 'OOZIE', 'HIVE', 'TEZ']);
  182. },
  183. /**
  184. * Check whether we should turn on <code>Tez</code> service
  185. * @return {bool}
  186. * @method needToAddTez
  187. */
  188. needToAddTez: function () {
  189. return this.needAddService('TEZ', ['YARN']);
  190. },
  191. /**
  192. * Check whether we should turn on <code>ZooKeeper</code> service
  193. * @return {bool}
  194. * @method needToAddZooKeeper
  195. */
  196. needToAddZooKeeper: function () {
  197. if (App.get('isHadoop2Stack')) {
  198. return this.findProperty('serviceName', 'ZOOKEEPER') && this.findProperty('serviceName', 'ZOOKEEPER').get('isSelected') === false;
  199. } else {
  200. return this.needAddService('ZOOKEEPER', ['HBASE', 'HIVE', 'WEBHCAT', 'STORM']);
  201. }
  202. },
  203. /**
  204. * Check whether we should turn on <code>HDFS or GLUSTERFS</code> service
  205. * @return {bool}
  206. * @method noDFSs
  207. */
  208. noDFSs: function () {
  209. return (this.findProperty('serviceName', 'HDFS').get('isSelected') === false &&
  210. (!this.findProperty('serviceName', 'GLUSTERFS') || this.findProperty('serviceName', 'GLUSTERFS').get('isSelected') === false));
  211. },
  212. /**
  213. * Check if multiple distributed file systems were selected
  214. * @return {bool}
  215. * @method multipleDFSs
  216. */
  217. multipleDFSs: function () {
  218. return (this.findProperty('serviceName', 'HDFS').get('isSelected') === true &&
  219. (this.findProperty('serviceName', 'GLUSTERFS') && this.findProperty('serviceName', 'GLUSTERFS').get('isSelected') === true));
  220. },
  221. /**
  222. * Check do we have any monitoring service turned on
  223. * @return {bool}
  224. * @method gangliaOrNagiosNotSelected
  225. */
  226. gangliaOrNagiosNotSelected: function () {
  227. return (this.findProperty('serviceName', 'GANGLIA').get('isSelected') === false || this.findProperty('serviceName', 'NAGIOS').get('isSelected') === false);
  228. },
  229. /**
  230. * Check whether user turned on monitoring service and go to next step
  231. * @method validateMonitoring
  232. */
  233. validateMonitoring: function () {
  234. if (this.gangliaOrNagiosNotSelected()) {
  235. this.monitoringCheckPopup();
  236. } else {
  237. App.router.send('next');
  238. }
  239. },
  240. /**
  241. * Onclick handler for <code>Next</code> button
  242. * @method submit
  243. */
  244. submit: function () {
  245. var submitChecks = this.get('submitChecks');
  246. var doValidateMonitoring = true;
  247. if (!this.get("isSubmitDisabled")) {
  248. for (var i = 0; i < submitChecks.length; i++) {
  249. if (this[submitChecks[i].checkCallback].call(this)) {
  250. doValidateMonitoring = false;
  251. this.needToAddServicePopup.apply(this, submitChecks[i].popupParams);
  252. break;
  253. }
  254. }
  255. if (doValidateMonitoring) {
  256. this.validateMonitoring();
  257. }
  258. }
  259. },
  260. /**
  261. * Select/deselect services
  262. * @param services array of objects
  263. * <code>
  264. * [
  265. * {
  266. * service: 'HDFS',
  267. * selected: true
  268. * },
  269. * ....
  270. * ]
  271. * </code>
  272. * @param {string} i18nSuffix
  273. * @return {App.ModalPopup}
  274. * @method needToAddServicePopup
  275. */
  276. needToAddServicePopup: function (services, i18nSuffix) {
  277. if (!(services instanceof Array)) {
  278. services = [services];
  279. }
  280. var self = this;
  281. return App.ModalPopup.show({
  282. header: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.header'),
  283. body: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.body'),
  284. onPrimary: function () {
  285. services.forEach(function (service) {
  286. self.findProperty('serviceName', service.serviceName).set('isSelected', service.selected);
  287. });
  288. this.hide();
  289. self.submit();
  290. }
  291. });
  292. },
  293. /**
  294. * Show popup with info about not selected (but should be selected) services
  295. * @return {App.ModalPopup}
  296. * @method monitoringCheckPopup
  297. */
  298. monitoringCheckPopup: function () {
  299. return App.ModalPopup.show({
  300. header: Em.I18n.t('installer.step4.monitoringCheck.popup.header'),
  301. body: Em.I18n.t('installer.step4.monitoringCheck.popup.body'),
  302. onPrimary: function () {
  303. this.hide();
  304. App.router.send('next');
  305. }
  306. });
  307. }
  308. });