step4_controller.js 18 KB

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