step4_controller.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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 && !ambariMetricsService.get('isSelected')) {
  78. this.addValidationError({
  79. id: 'ambariMetricsCheck',
  80. type: 'WARNING',
  81. callback: this.ambariMetricsCheckPopup
  82. });
  83. }
  84. },
  85. /**
  86. * Check whether Ranger is selected and show installation requirements if yes
  87. * @method rangerValidation
  88. */
  89. rangerValidation: function () {
  90. var rangerService = this.findProperty('serviceName', 'RANGER');
  91. if (rangerService && rangerService.get('isSelected')) {
  92. this.addValidationError({
  93. id: 'rangerRequirements',
  94. type: 'WARNING',
  95. callback: this.rangerRequirementsPopup
  96. });
  97. }
  98. },
  99. /**
  100. * Onclick handler for <code>Next</code> button.
  101. * @method submit
  102. */
  103. submit: function () {
  104. if (!this.get('isSubmitDisabled')) {
  105. this.unSelectServices();
  106. this.setGroupedServices();
  107. if (this.validate()) {
  108. this.set('errorStack', []);
  109. App.router.send('next');
  110. }
  111. }
  112. },
  113. /**
  114. * Set isSelected based on property doNotShowAndInstall
  115. */
  116. unSelectServices: function () {
  117. this.filterProperty('isSelected',true).filterProperty('doNotShowAndInstall', true).setEach('isSelected', false);
  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. if (this.get('wizardController.name') == 'installerController') {
  132. this.ambariMetricsValidation();
  133. }
  134. this.rangerValidation();
  135. if (!!this.get('errorStack').filterProperty('isShown', false).length) {
  136. this.showError(this.get('errorStack').findProperty('isShown', false));
  137. return false;
  138. }
  139. return true;
  140. },
  141. /**
  142. * Create error and push it to stack.
  143. *
  144. * @param {Object} errorObject - look to #createError
  145. * @return {Boolean}
  146. * @method addValidationError
  147. **/
  148. addValidationError: function(errorObject) {
  149. if (!this.get('errorStack').mapProperty('id').contains(errorObject.id)) {
  150. this.get('errorStack').push(this.createError(errorObject));
  151. return true;
  152. } else {
  153. return false;
  154. }
  155. },
  156. /**
  157. * Show current error by passed error object.
  158. *
  159. * @param {Object} errorObject
  160. * @method showError
  161. **/
  162. showError: function(errorObject) {
  163. return errorObject.callback.apply(errorObject.callbackContext, errorObject.callbackParams);
  164. },
  165. /**
  166. * Default primary button("Ok") callback for warning popups.
  167. * Change isShown state for last shown error.
  168. * Call #submit() method.
  169. *
  170. * @method onPrimaryPopupCallback
  171. **/
  172. onPrimaryPopupCallback: function() {
  173. if (this.get('errorStack').someProperty('isShown', false)) {
  174. this.get('errorStack').findProperty('isShown', false).isShown = true;
  175. }
  176. this.submit();
  177. },
  178. /**
  179. * Create error object with passed options.
  180. * Available options:
  181. * id - {String}
  182. * type - {String}
  183. * isShowed - {Boolean}
  184. * callback - {Function}
  185. * callbackContext
  186. * callbackParams - {Array}
  187. *
  188. * @param {Object} opt
  189. * @return {Object}
  190. * @method createError
  191. **/
  192. createError: function(opt) {
  193. var options = {
  194. // {String} error identifier
  195. id: '',
  196. // {String} type of error CRITICAL|WARNING
  197. type: 'CRITICAL',
  198. // {Boolean} error was shown
  199. isShown: false,
  200. // {Function} callback to execute
  201. callback: null,
  202. // context which execute from
  203. callbackContext: this,
  204. // {Array} params applied to callback
  205. callbackParams: []
  206. };
  207. $.extend(options, opt);
  208. return options;
  209. },
  210. /**
  211. * Checks if a filesystem is present in the Stack
  212. *
  213. * @method isDFSStack
  214. */
  215. isDFSStack: function () {
  216. var bDFSStack = false;
  217. var dfsServices = ['HDFS', 'GLUSTERFS'];
  218. var availableServices = this.filterProperty('isInstalled',false);
  219. availableServices.forEach(function(service){
  220. if (dfsServices.contains(service.get('serviceName'))) {
  221. console.log("found DFS " + service.get('serviceName'));
  222. bDFSStack=true;
  223. }
  224. },this);
  225. return bDFSStack;
  226. },
  227. /**
  228. * Checks if a filesystem is selected and only one filesystem is selected
  229. *
  230. * @method isFileSystemCheckFailed
  231. */
  232. fileSystemServiceValidation: function() {
  233. if(this.isDFSStack()){
  234. var primaryDFS = this.findProperty('isPrimaryDFS',true);
  235. var primaryDfsDisplayName = primaryDFS.get('displayNameOnSelectServicePage');
  236. var primaryDfsServiceName = primaryDFS.get('serviceName');
  237. if (this.multipleDFSs()) {
  238. var dfsServices = this.filterProperty('isDFS',true).filterProperty('isSelected',true).mapProperty('serviceName');
  239. var services = dfsServices.map(function (item){
  240. return {
  241. serviceName: item,
  242. selected: item === primaryDfsServiceName
  243. };
  244. });
  245. this.addValidationError({
  246. id: 'multipleDFS',
  247. callback: this.needToAddServicePopup,
  248. callbackParams: [services, 'multipleDFS', primaryDfsDisplayName]
  249. });
  250. }
  251. }
  252. },
  253. /**
  254. * Checks if a dependent service is selected without selecting the main service.
  255. *
  256. * @method serviceDependencyValidation
  257. */
  258. serviceDependencyValidation: function() {
  259. var selectedServices = this.filterProperty('isSelected',true);
  260. var missingDependencies = [];
  261. var missingDependenciesDisplayName = [];
  262. selectedServices.forEach(function(service){
  263. var requiredServices = service.get('requiredServices');
  264. if (!!requiredServices && requiredServices.length) {
  265. requiredServices.forEach(function(_requiredService){
  266. var requiredService = this.findProperty('serviceName', _requiredService);
  267. if (requiredService && requiredService.get('isSelected') === false) {
  268. if(missingDependencies.indexOf(_requiredService) == -1 ) {
  269. missingDependencies.push(_requiredService);
  270. missingDependenciesDisplayName.push(requiredService.get('displayNameOnSelectServicePage'));
  271. }
  272. }
  273. },this);
  274. }
  275. },this);
  276. if (missingDependencies.length > 0) {
  277. for(var i = 0; i < missingDependencies.length; i++) {
  278. this.addValidationError({
  279. id: 'serviceCheck_' + missingDependencies[i],
  280. callback: this.needToAddServicePopup,
  281. callbackParams: [{serviceName: missingDependencies[i], selected: true}, 'serviceCheck', missingDependenciesDisplayName[i]]
  282. });
  283. }
  284. }
  285. },
  286. /**
  287. * Select co hosted services which not showed on UI.
  288. *
  289. * @method setGroupedServices
  290. **/
  291. setGroupedServices: function() {
  292. this.forEach(function(service){
  293. var coSelectedServices = service.get('coSelectedServices');
  294. coSelectedServices.forEach(function(groupedServiceName) {
  295. var groupedService = this.findProperty('serviceName', groupedServiceName);
  296. if (groupedService.get('isSelected') !== service.get('isSelected')) {
  297. groupedService.set('isSelected',service.get('isSelected'));
  298. }
  299. },this);
  300. },this);
  301. },
  302. /**
  303. * Select/deselect services
  304. * @param services array of objects
  305. * <code>
  306. * [
  307. * {
  308. * service: 'HDFS',
  309. * selected: true
  310. * },
  311. * ....
  312. * ]
  313. * </code>
  314. * @param {string} i18nSuffix
  315. * @param {string} serviceName
  316. * @return {App.ModalPopup}
  317. * @method needToAddServicePopup
  318. */
  319. needToAddServicePopup: function(services, i18nSuffix, serviceName) {
  320. if (!(services instanceof Array)) {
  321. services = [services];
  322. }
  323. var self = this;
  324. return App.ModalPopup.show({
  325. header: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.header').format(serviceName),
  326. body: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.body').format(serviceName),
  327. onPrimary: function () {
  328. services.forEach(function (service) {
  329. self.findProperty('serviceName', service.serviceName).set('isSelected', service.selected);
  330. });
  331. self.onPrimaryPopupCallback();
  332. this.hide();
  333. }
  334. });
  335. },
  336. /**
  337. * Show popup with info about not selected Ambari Metrics service
  338. * @return {App.ModalPopup}
  339. * @method ambariMetricsCheckPopup
  340. */
  341. ambariMetricsCheckPopup: function () {
  342. var self = this;
  343. return App.ModalPopup.show({
  344. header: Em.I18n.t('installer.step4.ambariMetricsCheck.popup.header'),
  345. body: Em.I18n.t('installer.step4.ambariMetricsCheck.popup.body'),
  346. primary: Em.I18n.t('common.proceedAnyway'),
  347. onPrimary: function () {
  348. self.onPrimaryPopupCallback();
  349. this.hide();
  350. }
  351. });
  352. },
  353. /**
  354. * Show popup with installation requirements for Ranger service
  355. * @return {App.ModalPopup}
  356. * @method rangerRequirementsPopup
  357. */
  358. rangerRequirementsPopup: function () {
  359. var self = this;
  360. return App.ModalPopup.show({
  361. header: Em.I18n.t('installer.step4.rangerRequirements.popup.header'),
  362. bodyClass: Em.View.extend({
  363. templateName: require('templates/wizard/step4/step4_ranger_requirements_popup')
  364. }),
  365. primary: Em.I18n.t('common.proceed'),
  366. isChecked: false,
  367. disablePrimary: function () {
  368. return !this.get('isChecked');
  369. }.property('isChecked'),
  370. onPrimary: function () {
  371. self.onPrimaryPopupCallback();
  372. this.hide();
  373. }
  374. });
  375. }
  376. });