step4_controller.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. * List of validation errors. Look to #createError method for information
  36. * regarding object structure.
  37. *
  38. * @type {Object[]}
  39. */
  40. errorStack: [],
  41. /**
  42. * Check whether all properties are selected
  43. * @type {bool}
  44. */
  45. isAll: function () {
  46. return this.filterProperty('isInstalled', false).
  47. filterProperty('isHiddenOnSelectServicePage', false).
  48. everyProperty('isSelected', true);
  49. }.property('@each.isSelected'),
  50. /**
  51. * Check whether none properties(minimum) are selected
  52. * @type {bool}
  53. */
  54. isMinimum: function () {
  55. return this.filterProperty('isInstalled', false).
  56. filterProperty('isHiddenOnSelectServicePage', false).
  57. everyProperty('isSelected', false);
  58. }.property('@each.isSelected'),
  59. /**
  60. * Drop errorStack content on selected state changes.
  61. **/
  62. clearErrors: function() {
  63. this.set('errorStack', []);
  64. }.observes('@each.isSelected'),
  65. /**
  66. * Onclick handler for <code>select all</code> link
  67. * @method selectAll
  68. */
  69. selectAll: function () {
  70. this.filterProperty('isInstalled', false).setEach('isSelected', true);
  71. },
  72. /**
  73. * Onclick handler for <code>select minimum</code> link
  74. * @method selectMinimum
  75. */
  76. selectMinimum: function () {
  77. this.filterProperty('isInstalled', false).setEach('isSelected', false);
  78. },
  79. /**
  80. * Check if multiple distributed file systems were selected
  81. * @return {bool}
  82. * @method multipleDFSs
  83. */
  84. multipleDFSs: function () {
  85. var dfsServices = this.filterProperty('isDFS',true).filterProperty('isSelected',true);
  86. return dfsServices.length > 1;
  87. },
  88. /**
  89. * Check whether user turned on monitoring service and go to next step
  90. * @method validateMonitoring
  91. */
  92. serviceMonitoringValidation: function () {
  93. var monitoringServices = this.filterProperty('isMonitoringService', true);
  94. var notSelectedService = monitoringServices.filterProperty('isSelected', false);
  95. if (!!notSelectedService.length) {
  96. notSelectedService = stringUtils.getFormattedStringFromArray(notSelectedService.mapProperty('displayNameOnSelectServicePage'));
  97. monitoringServices = stringUtils.getFormattedStringFromArray(monitoringServices.mapProperty('displayNameOnSelectServicePage'));
  98. this.addValidationError({
  99. id: 'monitoringCheck',
  100. type: 'WARNING',
  101. callback: this.monitoringCheckPopup,
  102. callbackParams: [notSelectedService, monitoringServices]
  103. });
  104. }
  105. },
  106. /**
  107. * Onclick handler for <code>Next</code> button.
  108. * @method submit
  109. */
  110. submit: function () {
  111. if (!this.get('isSubmitDisabled')) {
  112. if (this.validate()) {
  113. this.set('errorStack', []);
  114. this.setGroupedServices();
  115. App.router.send('next');
  116. }
  117. }
  118. },
  119. /**
  120. * Check if validation passed:
  121. * - required file system services selected
  122. * - dependencies between services
  123. * - monitoring services selected (not required)
  124. *
  125. * @return {Boolean}
  126. * @method validate
  127. **/
  128. validate: function() {
  129. this.serviceDependencyValidation();
  130. this.fileSystemServiceValidation();
  131. this.serviceMonitoringValidation();
  132. if (!!this.get('errorStack').filterProperty('isShown', false).length) {
  133. this.showError(this.get('errorStack').findProperty('isShown', false));
  134. return false;
  135. }
  136. return true;
  137. },
  138. /**
  139. * Create error and push it to stack.
  140. *
  141. * @param {Object} errorObject - look to #createError
  142. * @return {Boolean}
  143. * @method addValidationError
  144. **/
  145. addValidationError: function(errorObject) {
  146. if (!this.get('errorStack').mapProperty('id').contains(errorObject.id)) {
  147. this.get('errorStack').push(this.createError(errorObject));
  148. return true;
  149. } else {
  150. return false;
  151. }
  152. },
  153. /**
  154. * Show current error by passed error object.
  155. *
  156. * @param {Object} errorObject
  157. * @method showError
  158. **/
  159. showError: function(errorObject) {
  160. return errorObject.callback.apply(errorObject.callbackContext, errorObject.callbackParams);
  161. },
  162. /**
  163. * Default primary button("Ok") callback for warning popups.
  164. * Change isShown state for last shown error.
  165. * Call #submit() method.
  166. *
  167. * @method onPrimaryPopupCallback
  168. **/
  169. onPrimaryPopupCallback: function() {
  170. if (this.get('errorStack').someProperty('isShown', false)) {
  171. this.get('errorStack').findProperty('isShown', false).isShown = true;
  172. }
  173. this.submit();
  174. },
  175. /**
  176. * Create error object with passed options.
  177. * Available options:
  178. * id - {String}
  179. * type - {String}
  180. * isShowed - {Boolean}
  181. * callback - {Function}
  182. * callbackContext
  183. * callbackParams - {Array}
  184. *
  185. * @param {Object} opt
  186. * @return {Object}
  187. * @method createError
  188. **/
  189. createError: function(opt) {
  190. var options = {
  191. // {String} error identifier
  192. id: '',
  193. // {String} type of error CRITICAL|WARNING
  194. type: 'CRITICAL',
  195. // {Boolean} error was shown
  196. isShown: false,
  197. // {Function} callback to execute
  198. callback: null,
  199. // context which execute from
  200. callbackContext: this,
  201. // {Array} params applied to callback
  202. callbackParams: []
  203. };
  204. $.extend(options, opt);
  205. return options;
  206. },
  207. /**
  208. * Checks if a filesystem is selected and only one filesystem is selected
  209. *
  210. * @method isFileSystemCheckFailed
  211. */
  212. fileSystemServiceValidation: function() {
  213. var primaryDFS = this.findProperty('isPrimaryDFS',true);
  214. var primaryDfsDisplayName = primaryDFS.get('displayNameOnSelectServicePage');
  215. var primaryDfsServiceName = primaryDFS.get('serviceName');
  216. if (this.multipleDFSs()) {
  217. var dfsServices = this.filterProperty('isDFS',true).filterProperty('isSelected',true).mapProperty('serviceName');
  218. var services = dfsServices.map(function (item){
  219. return {
  220. serviceName: item,
  221. selected: item === primaryDfsServiceName
  222. };
  223. });
  224. this.addValidationError({
  225. id: 'multipleDFS',
  226. callback: this.needToAddServicePopup,
  227. callbackParams: [services, 'multipleDFS', primaryDfsDisplayName]
  228. });
  229. }
  230. },
  231. /**
  232. * Checks if a dependent service is selected without selecting the main service.
  233. *
  234. * @method serviceDependencyValidation
  235. */
  236. serviceDependencyValidation: function() {
  237. var notSelectedServices = this.filterProperty('isSelected',false);
  238. notSelectedServices.forEach(function(service){
  239. var showWarningPopup;
  240. var dependentServices = service.get('dependentServices');
  241. if (!!dependentServices) {
  242. showWarningPopup = false;
  243. dependentServices.forEach(function(_dependentService){
  244. var dependentService = this.findProperty('serviceName', _dependentService);
  245. if (dependentService && dependentService.get('isSelected') === true) {
  246. showWarningPopup = true;
  247. }
  248. },this);
  249. if (showWarningPopup) {
  250. this.addValidationError({
  251. id: 'serviceCheck_' + service.get('serviceName'),
  252. callback: this.needToAddServicePopup,
  253. callbackParams: [{serviceName: service.get('serviceName'), selected: true}, 'serviceCheck', service.get('displayNameOnSelectServicePage')]
  254. });
  255. }
  256. }
  257. },this);
  258. },
  259. /**
  260. * Select co hosted services which not showed on UI.
  261. *
  262. * @method setGroupedServices
  263. **/
  264. setGroupedServices: function() {
  265. this.forEach(function(service){
  266. var coSelectedServices = service.get('coSelectedServices');
  267. coSelectedServices.forEach(function(groupedServiceName) {
  268. var groupedService = this.findProperty('serviceName', groupedServiceName);
  269. groupedService.set('isSelected',service.get('isSelected'));
  270. },this);
  271. },this);
  272. },
  273. /**
  274. * Select/deselect services
  275. * @param services array of objects
  276. * <code>
  277. * [
  278. * {
  279. * service: 'HDFS',
  280. * selected: true
  281. * },
  282. * ....
  283. * ]
  284. * </code>
  285. * @param {string} i18nSuffix
  286. * @param {string} serviceName
  287. * @return {App.ModalPopup}
  288. * @method needToAddServicePopup
  289. */
  290. needToAddServicePopup: function(services, i18nSuffix, serviceName) {
  291. if (!(services instanceof Array)) {
  292. services = [services];
  293. }
  294. var self = this;
  295. return App.ModalPopup.show({
  296. header: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.header').format(serviceName),
  297. body: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.body').format(serviceName),
  298. onPrimary: function () {
  299. services.forEach(function (service) {
  300. self.findProperty('serviceName', service.serviceName).set('isSelected', service.selected);
  301. });
  302. self.onPrimaryPopupCallback();
  303. this.hide();
  304. }
  305. });
  306. },
  307. /**
  308. * Show popup with info about not selected (but should be selected) services
  309. * @return {App.ModalPopup}
  310. * @method monitoringCheckPopup
  311. */
  312. monitoringCheckPopup: function (notSelectedServiceNames,monitoringServicesNames) {
  313. var self = this;
  314. return App.ModalPopup.show({
  315. header: Em.I18n.t('installer.step4.monitoringCheck.popup.header'),
  316. body: Em.I18n.t('installer.step4.monitoringCheck.popup.body').format(notSelectedServiceNames,monitoringServicesNames),
  317. onPrimary: function () {
  318. self.onPrimaryPopupCallback();
  319. this.hide();
  320. }
  321. });
  322. }
  323. });