step4_controller.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. /**
  28. * Is Submit button disabled
  29. * @type {bool}
  30. */
  31. isSubmitDisabled: function () {
  32. return this.filterProperty('isSelected', true).filterProperty('isInstalled', false).length === 0;
  33. }.property("@each.isSelected"),
  34. /**
  35. * Check whether all properties are selected
  36. * @type {bool}
  37. */
  38. isAll: function () {
  39. return this.everyProperty('isSelected', true);
  40. }.property('@each.isSelected'),
  41. /**
  42. * Check whether none properties(minimum) are selected
  43. * @type {bool}
  44. */
  45. isMinimum: function () {
  46. return this.everyProperty('isSelected', false);
  47. }.property('@each.isSelected'),
  48. /**
  49. * Onclick handler for <code>select all</code> link
  50. * @method selectAll
  51. */
  52. selectAll: function () {
  53. this.setEach('isSelected', true);
  54. },
  55. /**
  56. * Onclick handler for <code>select minimum</code> link
  57. * @method selectMinimum
  58. */
  59. selectMinimum: function () {
  60. this.setEach('isSelected', false);
  61. },
  62. /**
  63. * Check whether we should turn on <code>HDFS or GLUSTERFS</code> service
  64. * @return {bool}
  65. * @method noDFSs
  66. */
  67. noDFSs: function () {
  68. return !this.filterProperty('isDFS',true).someProperty('isSelected',true);
  69. },
  70. /**
  71. * Check if multiple distributed file systems were selected
  72. * @return {bool}
  73. * @method multipleDFSs
  74. */
  75. multipleDFSs: function () {
  76. var dfsServices = this.filterProperty('isDFS',true).filterProperty('isSelected',true);
  77. return dfsServices.length > 1;
  78. },
  79. /**
  80. * Check do we have any monitoring service turned on
  81. * @return {bool}
  82. * @method gangliaOrNagiosNotSelected
  83. */
  84. isMonitoringServiceNotSelected: function () {
  85. var stackMonitoringServices = this.filterProperty('isMonitoringService',true);
  86. return stackMonitoringServices.someProperty('isSelected',false);
  87. },
  88. /**
  89. * Check whether user turned on monitoring service and go to next step
  90. * @method validateMonitoring
  91. */
  92. validateMonitoring: function () {
  93. var monitoringServices = this.filterProperty('isMonitoringService',true);
  94. var notSelectedService = monitoringServices.filterProperty('isSelected',false);
  95. if (!!notSelectedService.length) {
  96. notSelectedService = stringUtils.getFormattedStringFromArray(notSelectedService.mapProperty('displayNameOnSelectServicePage'));
  97. monitoringServices = stringUtils.getFormattedStringFromArray(monitoringServices.mapProperty('displayNameOnSelectServicePage'));
  98. this.monitoringCheckPopup(notSelectedService,monitoringServices);
  99. } else {
  100. App.router.send('next');
  101. }
  102. },
  103. /**
  104. * Onclick handler for <code>Next</code> button
  105. * @method submit
  106. */
  107. submit: function () {
  108. this.setGroupedServices();
  109. if (!this.get("isSubmitDisabled") && !this.isSubmitChecksFailed()) {
  110. this.validateMonitoring();
  111. }
  112. },
  113. /**
  114. * @method {isSubmitChecksFailed} Do the required checks on Next button click event
  115. * @returns {boolean}
  116. */
  117. isSubmitChecksFailed: function() {
  118. return this.isFileSystemCheckFailed() || this.isServiceDependencyCheckFailed();
  119. },
  120. /**
  121. * @method: isFileSystemCheckFailed - Checks if a filesystem is selected and only one filesystem is selected
  122. * @return: {boolean}
  123. */
  124. isFileSystemCheckFailed: function() {
  125. var isCheckFailed = false;
  126. var primaryDFS = this.findProperty('isPrimaryDFS',true);
  127. var primaryDfsDisplayName = primaryDFS.get('displayNameOnSelectServicePage');
  128. var primaryDfsServiceName = primaryDFS.get('serviceName');
  129. if (this.noDFSs()) {
  130. isCheckFailed = true;
  131. this.needToAddServicePopup.apply(this, [{serviceName: primaryDfsServiceName, selected: true},'fsCheck',primaryDfsDisplayName]);
  132. } else if (this.multipleDFSs()) {
  133. var dfsServices = this.filterProperty('isDFS',true).filterProperty('isSelected',true).mapProperty('serviceName');
  134. var services = dfsServices.map(function (item){
  135. var mappedObj = {
  136. serviceName: item,
  137. selected: false
  138. };
  139. if (item === primaryDfsServiceName) {
  140. mappedObj.selected = true;
  141. }
  142. return mappedObj;
  143. });
  144. isCheckFailed = true;
  145. this.needToAddServicePopup.apply(this, [services,'multipleDFS',primaryDfsDisplayName]);
  146. }
  147. return isCheckFailed;
  148. },
  149. /**
  150. * @method: isServiceDependencyCheckFailed - Checks if a dependent service is selected without selecting the main service
  151. * @return {boolean}
  152. */
  153. isServiceDependencyCheckFailed: function() {
  154. var isCheckFailed = false;
  155. var notSelectedServices = this.filterProperty('isSelected',false);
  156. notSelectedServices.forEach(function(service){
  157. var showWarningPopup;
  158. var dependentServices = service.get('dependentServices');
  159. if (!!dependentServices) {
  160. showWarningPopup = false;
  161. dependentServices.forEach(function(_dependentService){
  162. var dependentService = this.findProperty('serviceName', _dependentService);
  163. if (dependentService.get('isSelected') === true) {
  164. showWarningPopup = true;
  165. isCheckFailed = true;
  166. }
  167. },this);
  168. if (showWarningPopup) {
  169. this.needToAddServicePopup.apply(this, [{serviceName: service.get('serviceName'), selected: true},'serviceCheck',service.get('displayNameOnSelectServicePage')]);
  170. }
  171. }
  172. },this);
  173. return isCheckFailed;
  174. },
  175. setGroupedServices: function() {
  176. this.forEach(function(service){
  177. var coSelectedServices = service.get('coSelectedServices');
  178. coSelectedServices.forEach(function(groupedServiceName) {
  179. var groupedService = this.findProperty('serviceName', groupedServiceName);
  180. groupedService.set('isSelected',service.get('isSelected'));
  181. },this);
  182. },this);
  183. },
  184. /**
  185. * Select/deselect services
  186. * @param services array of objects
  187. * <code>
  188. * [
  189. * {
  190. * service: 'HDFS',
  191. * selected: true
  192. * },
  193. * ....
  194. * ]
  195. * </code>
  196. * @param {string} i18nSuffix
  197. * @param {string} serviceName
  198. * @return {App.ModalPopup}
  199. * @method needToAddServicePopup
  200. */
  201. needToAddServicePopup: function(services, i18nSuffix, serviceName) {
  202. if (!(services instanceof Array)) {
  203. services = [services];
  204. }
  205. var self = this;
  206. return App.ModalPopup.show({
  207. header: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.header').format(serviceName),
  208. body: Em.I18n.t('installer.step4.' + i18nSuffix + '.popup.body').format(serviceName),
  209. onPrimary: function () {
  210. services.forEach(function (service) {
  211. self.findProperty('serviceName', service.serviceName).set('isSelected', service.selected);
  212. });
  213. this.hide();
  214. self.submit();
  215. }
  216. });
  217. },
  218. /**
  219. * Show popup with info about not selected (but should be selected) services
  220. * @return {App.ModalPopup}
  221. * @method monitoringCheckPopup
  222. */
  223. monitoringCheckPopup: function (notSelectedServiceNames,monitoringServicesNames) {
  224. return App.ModalPopup.show({
  225. header: Em.I18n.t('installer.step4.monitoringCheck.popup.header'),
  226. body: Em.I18n.t('installer.step4.monitoringCheck.popup.body').format(notSelectedServiceNames,monitoringServicesNames),
  227. onPrimary: function () {
  228. this.hide();
  229. App.router.send('next');
  230. }
  231. });
  232. }
  233. });