step4_controller.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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. App.WizardStep4Controller = Em.ArrayController.extend({
  20. name: 'wizardStep4Controller',
  21. /**
  22. * List of Services
  23. * @type {Object[]}
  24. */
  25. content: [],
  26. /**
  27. * Check / Uncheck 'Select All' checkbox with one argument; Check / Uncheck all other checkboxes with more arguments
  28. * @type {bool}
  29. */
  30. isAllChecked: function(key, value) {
  31. if (arguments.length > 1) {
  32. this.filterProperty('isInstalled', false).setEach('isSelected', value);
  33. return value;
  34. }
  35. return this.filterProperty('isInstalled', false).
  36. filterProperty('isHiddenOnSelectServicePage', false).
  37. everyProperty('isSelected', true);
  38. }.property('@each.isSelected'),
  39. /**
  40. * Is Submit button disabled
  41. * @type {bool}
  42. */
  43. isSubmitDisabled: function () {
  44. return this.filterProperty('isSelected', true).filterProperty('isInstalled', false).length === 0 || App.get('router.btnClickInProgress');
  45. }.property('@each.isSelected', 'App.router.btnClickInProgress'),
  46. /**
  47. * List of validation errors. Look to #createError method for information
  48. * regarding object structure.
  49. *
  50. * @type {Object[]}
  51. */
  52. errorStack: [],
  53. /**
  54. * Drop errorStack content on selected state changes.
  55. **/
  56. clearErrors: function() {
  57. if (!this.get('errorStack').someProperty('isAccepted', false)) {
  58. this.set('errorStack', []);
  59. }
  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. return this.filterProperty('isDFS',true).filterProperty('isSelected',true).length > 1;
  68. },
  69. /**
  70. * Check whether Ranger is selected and show installation requirements if yes
  71. * @param {function} callback
  72. * @method rangerValidation
  73. */
  74. rangerValidation: function (callback) {
  75. var rangerService = this.findProperty('serviceName', 'RANGER');
  76. if (rangerService && !rangerService.get('isInstalled')) {
  77. if(rangerService.get('isSelected')) {
  78. this.addValidationError({
  79. id: 'rangerRequirements',
  80. type: 'WARNING',
  81. callback: this.rangerRequirementsPopup,
  82. callbackParams: [callback]
  83. });
  84. }
  85. else {
  86. //Ranger is selected, remove the Ranger error from errorObject array
  87. var rangerError = this.get('errorStack').filterProperty('id',"rangerRequirements");
  88. if(rangerError)
  89. {
  90. this.get('errorStack').removeObject(rangerError[0]);
  91. }
  92. }
  93. }
  94. },
  95. /**
  96. * Warn user if he tries to install Spark with HDP 2.2
  97. * @param {function} callback
  98. * @method sparkValidation
  99. */
  100. sparkValidation: function (callback) {
  101. var sparkService = this.findProperty('serviceName', 'SPARK');
  102. if (sparkService && !sparkService.get('isInstalled') &&
  103. App.get('currentStackName') === 'HDP' && App.get('currentStackVersionNumber') === '2.2') {
  104. if(sparkService.get('isSelected')) {
  105. this.addValidationError({
  106. id: 'sparkWarning',
  107. type: 'WARNING',
  108. callback: this.sparkWarningPopup,
  109. callbackParams: [callback]
  110. });
  111. }
  112. else {
  113. //Spark is selected, remove the Spark error from errorObject array
  114. var sparkError = this.get('errorStack').filterProperty('id',"sparkWarning");
  115. if(sparkError)
  116. {
  117. this.get('errorStack').removeObject(sparkError[0]);
  118. }
  119. }
  120. }
  121. },
  122. /**
  123. * Onclick handler for <code>Next</code> button.
  124. * Disable 'Next' button while it is already under process. (using Router's property 'nextBtnClickInProgress')
  125. * @method submit
  126. */
  127. submit: function () {
  128. if(App.get('router.nextBtnClickInProgress')) {
  129. return;
  130. }
  131. if (!this.get('isSubmitDisabled')) {
  132. this.unSelectServices();
  133. this.setGroupedServices();
  134. if (this.validate()) {
  135. this.set('errorStack', []);
  136. App.router.send('next');
  137. }
  138. }
  139. },
  140. /**
  141. * Set isSelected based on property doNotShowAndInstall
  142. */
  143. unSelectServices: function () {
  144. this.filterProperty('isSelected',true).filterProperty('doNotShowAndInstall', true).setEach('isSelected', false);
  145. },
  146. /**
  147. * Check if validation passed:
  148. * - required file system services selected
  149. * - dependencies between services
  150. * - monitoring services selected (not required)
  151. *
  152. * @return {Boolean}
  153. * @method validate
  154. **/
  155. validate: function () {
  156. var result;
  157. var self = this;
  158. // callback function to reset `isAccepted` needs to be called everytime when a popup from errorStack is dismissed/proceed by user action
  159. var callback = function (id) {
  160. var check = self.get('errorStack').findProperty('id', id);
  161. if (check) {
  162. check.isAccepted = true;
  163. }
  164. };
  165. this.serviceDependencyValidation(callback);
  166. this.fileSystemServiceValidation(callback);
  167. if (this.get('wizardController.name') === 'installerController') {
  168. this.serviceValidation(callback, 'AMBARI_METRICS', 'ambariMetricsCheck');
  169. this.serviceValidation(callback, 'SMARTSENSE', 'smartSenseCheck');
  170. }
  171. this.rangerValidation(callback);
  172. this.sparkValidation(callback);
  173. if (!!this.get('errorStack').filterProperty('isShown', false).length) {
  174. var firstError = this.get('errorStack').findProperty('isShown', false);
  175. this.showError(firstError);
  176. result = false;
  177. } else {
  178. result = true;
  179. }
  180. return result;
  181. },
  182. /**
  183. * Check whether user selected service to install and go to next step
  184. * @param callback {Function}
  185. * @param serviceName {string}
  186. * @param id {string}
  187. * @method serviceValidation
  188. */
  189. serviceValidation: function(callback, serviceName, id) {
  190. var service = this.findProperty('serviceName', serviceName);
  191. if (service) {
  192. if (!service.get('isSelected')) {
  193. this.addValidationError({
  194. id: id,
  195. type: 'WARNING',
  196. callback: this.serviceCheckPopup,
  197. callbackParams: [callback]
  198. });
  199. }
  200. else {
  201. //metrics is selected, remove the metrics error from errorObject array
  202. var metricsError = this.get('errorStack').filterProperty('id', id);
  203. if (metricsError) {
  204. this.get('errorStack').removeObject(metricsError[0]);
  205. }
  206. }
  207. }
  208. },
  209. /**
  210. * Create error and push it to stack.
  211. *
  212. * @param {Object} errorObject - look to #createError
  213. * @return {Boolean}
  214. * @method addValidationError
  215. **/
  216. addValidationError: function (errorObject) {
  217. if (!this.get('errorStack').someProperty('id', errorObject.id)) {
  218. this.get('errorStack').push(this.createError(errorObject));
  219. return true;
  220. }
  221. return false;
  222. },
  223. /**
  224. * Show current error by passed error object.
  225. *
  226. * @param {Object} errorObject
  227. * @method showError
  228. **/
  229. showError: function (errorObject) {
  230. return errorObject.callback.apply(errorObject.callbackContext, errorObject.callbackParams.concat(errorObject.id));
  231. },
  232. /**
  233. * Default primary button("Ok") callback for warning popups.
  234. * Change isShown state for last shown error.
  235. * Call #submit() method.
  236. *
  237. * @param {function} callback
  238. * @param {string} id
  239. * @method onPrimaryPopupCallback
  240. **/
  241. onPrimaryPopupCallback: function(callback, id) {
  242. var firstError = this.get('errorStack').findProperty('isShown', false);
  243. if (firstError) {
  244. firstError.isShown = true;
  245. }
  246. if (callback) {
  247. callback(id);
  248. }
  249. this.submit();
  250. },
  251. /**
  252. * Create error object with passed options.
  253. * Available options:
  254. * id - {String}
  255. * type - {String}
  256. * isShowed - {Boolean}
  257. * callback - {Function}
  258. * callbackContext
  259. * callbackParams - {Array}
  260. *
  261. * @param {Object} opt
  262. * @return {Object}
  263. * @method createError
  264. **/
  265. createError: function(opt) {
  266. var options = {
  267. // {String} error identifier
  268. id: '',
  269. // {String} type of error CRITICAL|WARNING
  270. type: 'CRITICAL',
  271. // {Boolean} error was shown
  272. isShown: false,
  273. // {Boolean} error was accepted by user
  274. isAccepted: false,
  275. // {Function} callback to execute
  276. callback: null,
  277. // context which execute from
  278. callbackContext: this,
  279. // {Array} params applied to callback
  280. callbackParams: []
  281. };
  282. $.extend(options, opt);
  283. return options;
  284. },
  285. /**
  286. * Checks if a filesystem is present in the Stack
  287. *
  288. * @method isDFSStack
  289. */
  290. isDFSStack: function () {
  291. var bDFSStack = false;
  292. var dfsServices = ['HDFS', 'GLUSTERFS'];
  293. var availableServices = this.filterProperty('isInstalled',false);
  294. availableServices.forEach(function(service){
  295. if (dfsServices.contains(service.get('serviceName')) || service.get('serviceType') == 'HCFS' ) {
  296. bDFSStack=true;
  297. }
  298. },this);
  299. return bDFSStack;
  300. },
  301. /**
  302. * Checks if a filesystem is selected and only one filesystem is selected
  303. * @param {function} callback
  304. * @method isFileSystemCheckFailed
  305. */
  306. fileSystemServiceValidation: function(callback) {
  307. if(this.isDFSStack()){
  308. var primaryDFS = this.findProperty('isPrimaryDFS',true);
  309. if (primaryDFS) {
  310. var primaryDfsDisplayName = primaryDFS.get('displayNameOnSelectServicePage');
  311. var primaryDfsServiceName = primaryDFS.get('serviceName');
  312. if (this.multipleDFSs()) {
  313. var dfsServices = this.filterProperty('isDFS',true).filterProperty('isSelected',true).mapProperty('serviceName');
  314. var services = dfsServices.map(function (item){
  315. return {
  316. serviceName: item,
  317. selected: item === primaryDfsServiceName
  318. };
  319. });
  320. this.addValidationError({
  321. id: 'multipleDFS',
  322. callback: this.needToAddServicePopup,
  323. callbackParams: [services, 'multipleDFS', primaryDfsDisplayName, callback]
  324. });
  325. }
  326. else
  327. {
  328. //if multiple DFS are not selected, remove the related error from the error array
  329. var fsError = this.get('errorStack').filterProperty('id',"multipleDFS");
  330. if(fsError)
  331. {
  332. this.get('errorStack').removeObject(fsError[0]);
  333. }
  334. }
  335. }
  336. }
  337. },
  338. /**
  339. * Checks if a dependent service is selected without selecting the main service.
  340. * @param {function} callback
  341. * @method serviceDependencyValidation
  342. */
  343. serviceDependencyValidation: function(callback) {
  344. var selectedServices = this.filterProperty('isSelected',true);
  345. var missingDependencies = [];
  346. var missingDependenciesDisplayName = [];
  347. selectedServices.forEach(function(service){
  348. var requiredServices = service.get('requiredServices');
  349. if (!!requiredServices && requiredServices.length) {
  350. requiredServices.forEach(function(_requiredService){
  351. var requiredService = this.findProperty('serviceName', _requiredService);
  352. if (requiredService) {
  353. if(requiredService.get('isSelected') === false)
  354. {
  355. if(missingDependencies.indexOf(_requiredService) == -1 ) {
  356. missingDependencies.push(_requiredService);
  357. missingDependenciesDisplayName.push(requiredService.get('displayNameOnSelectServicePage'));
  358. }
  359. }
  360. else
  361. {
  362. //required service is selected, remove the service error from errorObject array
  363. var serviceName = requiredService.get('serviceName');
  364. var serviceError = this.get('errorStack').filterProperty('id',"serviceCheck_"+serviceName);
  365. if(serviceError)
  366. {
  367. this.get('errorStack').removeObject(serviceError[0]);
  368. }
  369. }
  370. }
  371. },this);
  372. }
  373. },this);
  374. //create a copy of the errorStack, reset it
  375. //and add the dependencies in the correct order
  376. var errorStackCopy = this.get('errorStack');
  377. this.set('errorStack', []);
  378. if (missingDependencies.length > 0) {
  379. for(var i = 0; i < missingDependencies.length; i++) {
  380. this.addValidationError({
  381. id: 'serviceCheck_' + missingDependencies[i],
  382. callback: this.needToAddServicePopup,
  383. callbackParams: [{serviceName: missingDependencies[i], selected: true}, 'serviceCheck', missingDependenciesDisplayName[i], callback]
  384. });
  385. }
  386. }
  387. //iterate through the errorStackCopy array and add to errorStack array, the error objects that have no matching entry in the errorStack
  388. //and that are not related to serviceChecks since serviceCheck errors have already been added when iterating through the missing dependencies list
  389. //Only add Ranger, Ambari Metrics, Spark and file system service validation errors if they exist in the errorStackCopy array
  390. var ctr = 0;
  391. while(ctr < errorStackCopy.length) {
  392. //no matching entry in errorStack array
  393. if (!this.get('errorStack').someProperty('id', errorStackCopy[ctr].id)) {
  394. //not serviceCheck error
  395. if(!errorStackCopy[ctr].id.startsWith('serviceCheck_')) {
  396. this.get('errorStack').push(this.createError(errorStackCopy[ctr]));
  397. }
  398. }
  399. ctr++;
  400. }
  401. },
  402. /**
  403. * Select co hosted services which not showed on UI.
  404. *
  405. * @method setGroupedServices
  406. **/
  407. setGroupedServices: function() {
  408. this.forEach(function(service){
  409. var coSelectedServices = service.get('coSelectedServices');
  410. coSelectedServices.forEach(function(groupedServiceName) {
  411. var groupedService = this.findProperty('serviceName', groupedServiceName);
  412. if (groupedService.get('isSelected') !== service.get('isSelected')) {
  413. groupedService.set('isSelected',service.get('isSelected'));
  414. }
  415. },this);
  416. },this);
  417. },
  418. /**
  419. * Select/deselect services
  420. * @param services array of objects
  421. * <code>
  422. * [
  423. * {
  424. * service: 'HDFS',
  425. * selected: true
  426. * },
  427. * ....
  428. * ]
  429. * </code>
  430. * @param {string} i18nSuffix
  431. * @param {string} serviceName
  432. * @param {function} callback
  433. * @param {string} id
  434. * @return {App.ModalPopup}
  435. * @method needToAddServicePopup
  436. */
  437. needToAddServicePopup: function (services, i18nSuffix, serviceName, callback, id) {
  438. if (!(services instanceof Array)) {
  439. services = [services];
  440. }
  441. var self = this;
  442. return App.ModalPopup.show({
  443. header: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.header').format(serviceName),
  444. body: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.body').format(serviceName),
  445. onPrimary: function () {
  446. services.forEach(function (service) {
  447. self.findProperty('serviceName', service.serviceName).set('isSelected', service.selected);
  448. });
  449. self.onPrimaryPopupCallback(callback, id);
  450. this.hide();
  451. },
  452. onSecondary: function () {
  453. if (callback) {
  454. callback(id);
  455. }
  456. this._super();
  457. },
  458. onClose: function () {
  459. if (callback) {
  460. callback(id);
  461. }
  462. this._super();
  463. }
  464. });
  465. },
  466. /**
  467. * Show popup with info about not selected service
  468. * @param {function} callback
  469. * @param {string} id
  470. * @return {App.ModalPopup}
  471. * @method serviceCheckPopup
  472. */
  473. serviceCheckPopup: function (callback, id) {
  474. var self = this;
  475. return App.ModalPopup.show({
  476. header: Em.I18n.t('installer.step4.limitedFunctionality.popup.header'),
  477. body: Em.I18n.t('installer.step4.' + id + '.popup.body'),
  478. primary: Em.I18n.t('common.proceedAnyway'),
  479. primaryClass: 'btn-warning',
  480. onPrimary: function () {
  481. self.onPrimaryPopupCallback(callback);
  482. this.hide();
  483. },
  484. onSecondary: function () {
  485. if (callback) {
  486. callback(id);
  487. }
  488. this._super();
  489. },
  490. onClose: function () {
  491. if (callback) {
  492. callback(id);
  493. }
  494. this._super();
  495. }
  496. });
  497. },
  498. /**
  499. * Show popup with installation requirements for Ranger service
  500. * @param {function} callback
  501. * @param {string} id
  502. * @return {App.ModalPopup}
  503. * @method rangerRequirementsPopup
  504. */
  505. rangerRequirementsPopup: function (callback, id) {
  506. var self = this;
  507. return App.ModalPopup.show({
  508. header: Em.I18n.t('installer.step4.rangerRequirements.popup.header'),
  509. bodyClass: Em.View.extend({
  510. templateName: require('templates/wizard/step4/step4_ranger_requirements_popup')
  511. }),
  512. primary: Em.I18n.t('common.proceed'),
  513. isChecked: false,
  514. disablePrimary: function () {
  515. return !this.get('isChecked');
  516. }.property('isChecked'),
  517. onPrimary: function () {
  518. self.onPrimaryPopupCallback(callback);
  519. this.hide();
  520. },
  521. onSecondary: function () {
  522. if (callback) {
  523. callback(id);
  524. }
  525. this._super();
  526. },
  527. onClose: function () {
  528. if (callback) {
  529. callback(id);
  530. }
  531. this._super();
  532. }
  533. });
  534. },
  535. /**
  536. * Show popup with Spark installation warning
  537. * @param {function} callback
  538. * @param {string} id
  539. * @return {App.ModalPopup}
  540. * @method sparkWarningPopup
  541. */
  542. sparkWarningPopup: function (callback, id) {
  543. var self = this;
  544. return App.ModalPopup.show({
  545. header: Em.I18n.t('common.warning'),
  546. body: Em.I18n.t('installer.step4.sparkWarning.popup.body'),
  547. primary: Em.I18n.t('common.proceed'),
  548. onPrimary: function () {
  549. self.onPrimaryPopupCallback(callback);
  550. this.hide();
  551. },
  552. onSecondary: function () {
  553. if (callback) {
  554. callback(id);
  555. }
  556. this._super();
  557. },
  558. onClose: function () {
  559. if (callback) {
  560. callback(id);
  561. }
  562. this._super();
  563. }
  564. });
  565. }
  566. });