step4_controller.js 19 KB

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