step4_controller.js 11 KB

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