step4_controller.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. console.log("IN isDFSStack() serviceName = " + service.get('serviceName'));
  244. console.log("IN isDFSStack() serviceType = " + service.get('serviceType'));
  245. if (dfsServices.contains(service.get('serviceName')) || service.get('serviceType') == 'HCFS' ) {
  246. console.log("found DFS " + service.get('serviceName'));
  247. bDFSStack=true;
  248. }
  249. },this);
  250. return bDFSStack;
  251. },
  252. /**
  253. * Checks if a filesystem is selected and only one filesystem is selected
  254. *
  255. * @method isFileSystemCheckFailed
  256. */
  257. fileSystemServiceValidation: function() {
  258. if(this.isDFSStack()){
  259. var primaryDFS = this.findProperty('isPrimaryDFS',true);
  260. if (primaryDFS) {
  261. var primaryDfsDisplayName = primaryDFS.get('displayNameOnSelectServicePage');
  262. var primaryDfsServiceName = primaryDFS.get('serviceName');
  263. if (this.multipleDFSs()) {
  264. var dfsServices = this.filterProperty('isDFS',true).filterProperty('isSelected',true).mapProperty('serviceName');
  265. var services = dfsServices.map(function (item){
  266. return {
  267. serviceName: item,
  268. selected: item === primaryDfsServiceName
  269. };
  270. });
  271. this.addValidationError({
  272. id: 'multipleDFS',
  273. callback: this.needToAddServicePopup,
  274. callbackParams: [services, 'multipleDFS', primaryDfsDisplayName]
  275. });
  276. }
  277. }
  278. }
  279. },
  280. /**
  281. * Checks if a dependent service is selected without selecting the main service.
  282. *
  283. * @method serviceDependencyValidation
  284. */
  285. serviceDependencyValidation: function() {
  286. var selectedServices = this.filterProperty('isSelected',true);
  287. var missingDependencies = [];
  288. var missingDependenciesDisplayName = [];
  289. selectedServices.forEach(function(service){
  290. var requiredServices = service.get('requiredServices');
  291. if (!!requiredServices && requiredServices.length) {
  292. requiredServices.forEach(function(_requiredService){
  293. var requiredService = this.findProperty('serviceName', _requiredService);
  294. if (requiredService && requiredService.get('isSelected') === false) {
  295. if(missingDependencies.indexOf(_requiredService) == -1 ) {
  296. missingDependencies.push(_requiredService);
  297. missingDependenciesDisplayName.push(requiredService.get('displayNameOnSelectServicePage'));
  298. }
  299. }
  300. },this);
  301. }
  302. },this);
  303. if (missingDependencies.length > 0) {
  304. for(var i = 0; i < missingDependencies.length; i++) {
  305. this.addValidationError({
  306. id: 'serviceCheck_' + missingDependencies[i],
  307. callback: this.needToAddServicePopup,
  308. callbackParams: [{serviceName: missingDependencies[i], selected: true}, 'serviceCheck', missingDependenciesDisplayName[i]]
  309. });
  310. }
  311. }
  312. },
  313. /**
  314. * Select co hosted services which not showed on UI.
  315. *
  316. * @method setGroupedServices
  317. **/
  318. setGroupedServices: function() {
  319. this.forEach(function(service){
  320. var coSelectedServices = service.get('coSelectedServices');
  321. coSelectedServices.forEach(function(groupedServiceName) {
  322. var groupedService = this.findProperty('serviceName', groupedServiceName);
  323. if (groupedService.get('isSelected') !== service.get('isSelected')) {
  324. groupedService.set('isSelected',service.get('isSelected'));
  325. }
  326. },this);
  327. },this);
  328. },
  329. /**
  330. * Select/deselect services
  331. * @param services array of objects
  332. * <code>
  333. * [
  334. * {
  335. * service: 'HDFS',
  336. * selected: true
  337. * },
  338. * ....
  339. * ]
  340. * </code>
  341. * @param {string} i18nSuffix
  342. * @param {string} serviceName
  343. * @return {App.ModalPopup}
  344. * @method needToAddServicePopup
  345. */
  346. needToAddServicePopup: function(services, i18nSuffix, serviceName) {
  347. if (!(services instanceof Array)) {
  348. services = [services];
  349. }
  350. var self = this;
  351. return App.ModalPopup.show({
  352. header: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.header').format(serviceName),
  353. body: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.body').format(serviceName),
  354. onPrimary: function () {
  355. services.forEach(function (service) {
  356. self.findProperty('serviceName', service.serviceName).set('isSelected', service.selected);
  357. });
  358. self.onPrimaryPopupCallback();
  359. this.hide();
  360. }
  361. });
  362. },
  363. /**
  364. * Show popup with info about not selected Ambari Metrics service
  365. * @return {App.ModalPopup}
  366. * @method ambariMetricsCheckPopup
  367. */
  368. ambariMetricsCheckPopup: function () {
  369. var self = this;
  370. return App.ModalPopup.show({
  371. header: Em.I18n.t('installer.step4.ambariMetricsCheck.popup.header'),
  372. body: Em.I18n.t('installer.step4.ambariMetricsCheck.popup.body'),
  373. primary: Em.I18n.t('common.proceedAnyway'),
  374. onPrimary: function () {
  375. self.onPrimaryPopupCallback();
  376. this.hide();
  377. }
  378. });
  379. },
  380. /**
  381. * Show popup with installation requirements for Ranger service
  382. * @return {App.ModalPopup}
  383. * @method rangerRequirementsPopup
  384. */
  385. rangerRequirementsPopup: function () {
  386. var self = this;
  387. return App.ModalPopup.show({
  388. header: Em.I18n.t('installer.step4.rangerRequirements.popup.header'),
  389. bodyClass: Em.View.extend({
  390. templateName: require('templates/wizard/step4/step4_ranger_requirements_popup')
  391. }),
  392. primary: Em.I18n.t('common.proceed'),
  393. isChecked: false,
  394. disablePrimary: function () {
  395. return !this.get('isChecked');
  396. }.property('isChecked'),
  397. onPrimary: function () {
  398. self.onPrimaryPopupCallback();
  399. this.hide();
  400. }
  401. });
  402. },
  403. /**
  404. * Show popup with Spark installation warning
  405. * @return {App.ModalPopup}
  406. * @method sparkWarningPopup
  407. */
  408. sparkWarningPopup: function () {
  409. var self = this;
  410. return App.ModalPopup.show({
  411. header: Em.I18n.t('common.warning'),
  412. body: Em.I18n.t('installer.step4.sparkWarning.popup.body'),
  413. primary: Em.I18n.t('common.proceed'),
  414. onPrimary: function () {
  415. self.onPrimaryPopupCallback();
  416. this.hide();
  417. }
  418. });
  419. }
  420. });