step4_controller.js 13 KB

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