step4_controller.js 11 KB

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