step4_controller.js 13 KB

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