step4_controller.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. * Onclick handler for <code>Next</code> button.
  90. * @method submit
  91. */
  92. submit: function () {
  93. if (!this.get('isSubmitDisabled')) {
  94. this.setGroupedServices();
  95. if (this.validate()) {
  96. this.set('errorStack', []);
  97. App.router.send('next');
  98. }
  99. }
  100. },
  101. /**
  102. * Check if validation passed:
  103. * - required file system services selected
  104. * - dependencies between services
  105. * - monitoring services selected (not required)
  106. *
  107. * @return {Boolean}
  108. * @method validate
  109. **/
  110. validate: function() {
  111. this.serviceDependencyValidation();
  112. this.fileSystemServiceValidation();
  113. if (!!this.get('errorStack').filterProperty('isShown', false).length) {
  114. this.showError(this.get('errorStack').findProperty('isShown', false));
  115. return false;
  116. }
  117. return true;
  118. },
  119. /**
  120. * Create error and push it to stack.
  121. *
  122. * @param {Object} errorObject - look to #createError
  123. * @return {Boolean}
  124. * @method addValidationError
  125. **/
  126. addValidationError: function(errorObject) {
  127. if (!this.get('errorStack').mapProperty('id').contains(errorObject.id)) {
  128. this.get('errorStack').push(this.createError(errorObject));
  129. return true;
  130. } else {
  131. return false;
  132. }
  133. },
  134. /**
  135. * Show current error by passed error object.
  136. *
  137. * @param {Object} errorObject
  138. * @method showError
  139. **/
  140. showError: function(errorObject) {
  141. return errorObject.callback.apply(errorObject.callbackContext, errorObject.callbackParams);
  142. },
  143. /**
  144. * Default primary button("Ok") callback for warning popups.
  145. * Change isShown state for last shown error.
  146. * Call #submit() method.
  147. *
  148. * @method onPrimaryPopupCallback
  149. **/
  150. onPrimaryPopupCallback: function() {
  151. if (this.get('errorStack').someProperty('isShown', false)) {
  152. this.get('errorStack').findProperty('isShown', false).isShown = true;
  153. }
  154. this.submit();
  155. },
  156. /**
  157. * Create error object with passed options.
  158. * Available options:
  159. * id - {String}
  160. * type - {String}
  161. * isShowed - {Boolean}
  162. * callback - {Function}
  163. * callbackContext
  164. * callbackParams - {Array}
  165. *
  166. * @param {Object} opt
  167. * @return {Object}
  168. * @method createError
  169. **/
  170. createError: function(opt) {
  171. var options = {
  172. // {String} error identifier
  173. id: '',
  174. // {String} type of error CRITICAL|WARNING
  175. type: 'CRITICAL',
  176. // {Boolean} error was shown
  177. isShown: false,
  178. // {Function} callback to execute
  179. callback: null,
  180. // context which execute from
  181. callbackContext: this,
  182. // {Array} params applied to callback
  183. callbackParams: []
  184. };
  185. $.extend(options, opt);
  186. return options;
  187. },
  188. /**
  189. * Checks if a filesystem is present in the Stack
  190. *
  191. * @method isDFSStack
  192. */
  193. isDFSStack: function () {
  194. var bDFSStack = false;
  195. var dfsServices = ['HDFS', 'GLUSTERFS'];
  196. var availableServices = this.filterProperty('isInstalled',false);
  197. availableServices.forEach(function(service){
  198. if (dfsServices.contains(service.get('serviceName'))) {
  199. console.log("found DFS " + service.get('serviceName'));
  200. bDFSStack=true;
  201. }
  202. },this);
  203. return bDFSStack;
  204. },
  205. /**
  206. * Checks if a filesystem is selected and only one filesystem is selected
  207. *
  208. * @method isFileSystemCheckFailed
  209. */
  210. fileSystemServiceValidation: function() {
  211. if(this.isDFSStack()){
  212. var primaryDFS = this.findProperty('isPrimaryDFS',true);
  213. var primaryDfsDisplayName = primaryDFS.get('displayNameOnSelectServicePage');
  214. var primaryDfsServiceName = primaryDFS.get('serviceName');
  215. if (this.multipleDFSs()) {
  216. var dfsServices = this.filterProperty('isDFS',true).filterProperty('isSelected',true).mapProperty('serviceName');
  217. var services = dfsServices.map(function (item){
  218. return {
  219. serviceName: item,
  220. selected: item === primaryDfsServiceName
  221. };
  222. });
  223. this.addValidationError({
  224. id: 'multipleDFS',
  225. callback: this.needToAddServicePopup,
  226. callbackParams: [services, 'multipleDFS', primaryDfsDisplayName]
  227. });
  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 selectedServices = this.filterProperty('isSelected',true);
  238. var missingDependencies = [];
  239. var missingDependenciesDisplayName = [];
  240. selectedServices.forEach(function(service){
  241. var requiredServices = service.get('requiredServices');
  242. if (!!requiredServices && requiredServices.length) {
  243. requiredServices.forEach(function(_requiredService){
  244. var requiredService = this.findProperty('serviceName', _requiredService);
  245. if (requiredService && requiredService.get('isSelected') === false) {
  246. if(missingDependencies.indexOf(_requiredService) == -1 ) {
  247. missingDependencies.push(_requiredService);
  248. missingDependenciesDisplayName.push(requiredService.get('displayNameOnSelectServicePage'));
  249. }
  250. }
  251. },this);
  252. }
  253. },this);
  254. if (missingDependencies.length > 0) {
  255. for(var i = 0; i < missingDependencies.length; i++) {
  256. this.addValidationError({
  257. id: 'serviceCheck_' + missingDependencies[i],
  258. callback: this.needToAddServicePopup,
  259. callbackParams: [{serviceName: missingDependencies[i], selected: true}, 'serviceCheck', missingDependenciesDisplayName[i]]
  260. });
  261. }
  262. }
  263. },
  264. /**
  265. * Select co hosted services which not showed on UI.
  266. *
  267. * @method setGroupedServices
  268. **/
  269. setGroupedServices: function() {
  270. this.forEach(function(service){
  271. var coSelectedServices = service.get('coSelectedServices');
  272. coSelectedServices.forEach(function(groupedServiceName) {
  273. var groupedService = this.findProperty('serviceName', groupedServiceName);
  274. if (groupedService.get('isSelected') !== service.get('isSelected')) {
  275. groupedService.set('isSelected',service.get('isSelected'));
  276. }
  277. },this);
  278. },this);
  279. },
  280. /**
  281. * Select/deselect services
  282. * @param services array of objects
  283. * <code>
  284. * [
  285. * {
  286. * service: 'HDFS',
  287. * selected: true
  288. * },
  289. * ....
  290. * ]
  291. * </code>
  292. * @param {string} i18nSuffix
  293. * @param {string} serviceName
  294. * @return {App.ModalPopup}
  295. * @method needToAddServicePopup
  296. */
  297. needToAddServicePopup: function(services, i18nSuffix, serviceName) {
  298. if (!(services instanceof Array)) {
  299. services = [services];
  300. }
  301. var self = this;
  302. return App.ModalPopup.show({
  303. header: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.header').format(serviceName),
  304. body: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.body').format(serviceName),
  305. onPrimary: function () {
  306. services.forEach(function (service) {
  307. self.findProperty('serviceName', service.serviceName).set('isSelected', service.selected);
  308. });
  309. self.onPrimaryPopupCallback();
  310. this.hide();
  311. }
  312. });
  313. }
  314. });