step7_controller.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 numberUtils = require('utils/number_utils');
  20. /**
  21. * By Step 7, we have the following information stored in App.db and set on this
  22. * controller by the router.
  23. *
  24. * selectedServices: App.db.selectedServices (the services that the user selected in Step 4)
  25. * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
  26. * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  27. *
  28. */
  29. App.WizardStep7Controller = Em.Controller.extend({
  30. name: 'wizardStep7Controller',
  31. stepConfigs: [], //contains all field properties that are viewed in this step
  32. selectedService: null,
  33. slaveHostToGroup: null,
  34. secureConfigs: require('data/secure_mapping'),
  35. miscModalVisible: false, //If miscConfigChange Modal is shown
  36. gangliaAvailableSpace: null,
  37. gangliaMoutDir:'/',
  38. isSubmitDisabled: function () {
  39. return (!this.stepConfigs.filterProperty('showConfig', true).everyProperty('errorCount', 0) || this.get("miscModalVisible"));
  40. }.property('stepConfigs.@each.errorCount', 'miscModalVisible'),
  41. selectedServiceNames: function () {
  42. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  43. }.property('content.services').cacheable(),
  44. allInstalledServiceNames: function () {
  45. return this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  46. }.property('content.services').cacheable(),
  47. masterComponentHosts: function () {
  48. return this.get('content.masterComponentHosts');
  49. }.property('content.masterComponentHosts'),
  50. slaveComponentHosts: function () {
  51. return this.get('content.slaveGroupProperties');
  52. }.property('content.slaveGroupProperties', 'content.slaveComponentHosts'),
  53. customData: [],
  54. clearStep: function () {
  55. this.get('stepConfigs').clear();
  56. },
  57. /**
  58. * On load function
  59. */
  60. loadStep: function () {
  61. console.log("TRACE: Loading step7: Configure Services");
  62. this.clearStep();
  63. //STEP 1: Load advanced configs
  64. var advancedConfigs = this.get('content.advancedServiceConfig');
  65. //STEP 2: Load on-site configs by service from local DB
  66. var storedConfigs = this.get('content.serviceConfigProperties');
  67. //STEP 3: Merge pre-defined configs with loaded on-site configs
  68. var configs = App.config.mergePreDefinedWithStored(storedConfigs, advancedConfigs);
  69. //STEP 4: Add advanced configs
  70. App.config.addAdvancedConfigs(configs, advancedConfigs);
  71. //STEP 5: Add custom configs
  72. App.config.addCustomConfigs(configs);
  73. //put properties from capacity-scheduler.xml into one config with textarea view
  74. if(this.get('allInstalledServiceNames').contains('YARN') && !App.supports.capacitySchedulerUi){
  75. configs = App.config.fileConfigsIntoTextarea(configs, 'capacity-scheduler.xml');
  76. }
  77. var localDB = {
  78. hosts: this.get('wizardController').getDBProperty('hosts'),
  79. masterComponentHosts: this.get('wizardController').getDBProperty('masterComponentHosts'),
  80. slaveComponentHosts: this.get('wizardController').getDBProperty('slaveComponentHosts')
  81. };
  82. //STEP 6: Distribute configs by service and wrap each one in App.ServiceConfigProperty (configs -> serviceConfigs)
  83. var serviceConfigs = App.config.renderConfigs(configs, storedConfigs, this.get('allInstalledServiceNames'), this.get('selectedServiceNames'), localDB);
  84. if (this.get('wizardController.name') === 'addServiceController') {
  85. serviceConfigs.setEach('showConfig', true);
  86. serviceConfigs.setEach('selected', false);
  87. this.get('selectedServiceNames').forEach(function(serviceName) {
  88. serviceConfigs.findProperty('serviceName', serviceName).set('selected', true);
  89. });
  90. }
  91. this.set('stepConfigs', serviceConfigs);
  92. this.activateSpecialConfigs();
  93. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  94. if (this.get('content.skipConfigStep')) {
  95. App.router.send('next');
  96. }
  97. },
  98. /**
  99. * make some configs visible depending on active services
  100. */
  101. activateSpecialConfigs: function () {
  102. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  103. miscConfigs = App.config.miscConfigVisibleProperty(miscConfigs, this.get('selectedServiceNames'));
  104. },
  105. /**
  106. * @param: An array of display names
  107. */
  108. setDisplayMessage: function (siteProperty, displayNames) {
  109. var displayMsg = null;
  110. if (displayNames && displayNames.length) {
  111. if (displayNames.length === 1) {
  112. displayMsg = siteProperty + ' ' + Em.I18n.t('as') + ' ' + displayNames[0];
  113. } else {
  114. var name = null;
  115. displayNames.forEach(function (_name, index) {
  116. if (index === 0) {
  117. name = _name;
  118. } else if (index === displayNames.length - 1) {
  119. name = name + ' ' + Em.I18n.t('and') + ' ' + _name;
  120. } else {
  121. name = name + ', ' + _name;
  122. }
  123. }, this);
  124. displayMsg = siteProperty + ' ' + Em.I18n.t('as') + ' ' + name;
  125. }
  126. } else {
  127. displayMsg = siteProperty;
  128. }
  129. return displayMsg;
  130. },
  131. /**
  132. * Set display names of the property tfrom he puppet/global names
  133. * @param displayNames: a field to be set with displayNames
  134. * @param names: array of property puppet/global names
  135. * @param configProperties: array of config properties of the respective service to the name param
  136. */
  137. setPropertyDisplayNames: function (displayNames, names, configProperties) {
  138. names.forEach(function (_name, index) {
  139. if (configProperties.someProperty('name', _name)) {
  140. displayNames.push(configProperties.findProperty('name', _name).displayName);
  141. }
  142. }, this);
  143. },
  144. /**
  145. * Display Error Message with service name, its custom configuration name and displaynames on the page
  146. * @param customConfig: array with custom configuration, serviceName and displayNames relative to custom configuration
  147. */
  148. showCustomConfigErrMsg: function (customConfig) {
  149. App.ModalPopup.show({
  150. header: Em.I18n.t('installer.step7.ConfigErrMsg.header'),
  151. primary: Em.I18n.t('ok'),
  152. secondary: null,
  153. onPrimary: function () {
  154. this.hide();
  155. },
  156. bodyClass: Ember.View.extend({
  157. message: Em.I18n.t('installer.step7.ConfigErrMsg.message'),
  158. siteProperties: customConfig,
  159. getDisplayMessage: function () {
  160. }.property('customConfig.@each.siteProperties.@each.siteProperty'),
  161. customConfig: customConfig,
  162. templateName: require('templates/wizard/step7_custom_config_error')
  163. })
  164. });
  165. },
  166. submit: function () {
  167. if (!this.get('isSubmitDisabled')) {
  168. App.router.send('next');
  169. }
  170. },
  171. /**
  172. * Provides service component name and display-name information for
  173. * the current selected service.
  174. */
  175. getCurrentServiceComponents: function () {
  176. var selectedServiceName = this.get('selectedService.serviceName');
  177. var masterComponents = this.get('content.masterComponentHosts');
  178. var slaveComponents = this.get('content.slaveComponentHosts');
  179. var scMaps = require('data/service_components');
  180. var validComponents = Ember.A([]);
  181. var seenComponents = {};
  182. masterComponents.forEach(function(component){
  183. var cn = component.component
  184. var cdn = component.display_name;
  185. if(component.serviceId===selectedServiceName && !seenComponents[cn]){
  186. validComponents.pushObject(Ember.Object.create({
  187. componentName: cn,
  188. displayName: cdn,
  189. selected: false
  190. }));
  191. seenComponents[cn] = cn;
  192. }
  193. });
  194. slaveComponents.forEach(function(component){
  195. var cn = component.componentName
  196. var cdn = component.displayName;
  197. var componentDef = scMaps.findProperty('component_name', cn);
  198. if(componentDef!=null && selectedServiceName===componentDef.service_name && !seenComponents[cn]){
  199. validComponents.pushObject(Ember.Object.create({
  200. componentName: cn,
  201. displayName: cdn,
  202. selected: false
  203. }));
  204. seenComponents[cn] = cn;
  205. }
  206. });
  207. return validComponents;
  208. }.property('content'),
  209. getAllHosts: function () {
  210. // Load hosts
  211. var allHosts = Ember.A([]);
  212. var hostNameToHostMap = {};
  213. var hosts = this.get('content.hosts');
  214. for ( var hostName in hosts) {
  215. var host = hosts[hostName];
  216. hostNameToHostMap[hostName] = App.Host.createRecord({
  217. id: host.name,
  218. hostName: host.name,
  219. publicHostName: host.name,
  220. cpu: host.cpu,
  221. memory: host.memory
  222. });
  223. allHosts.pushObject(hostNameToHostMap[hostName]);
  224. }
  225. // Load host-components
  226. var masterComponents = this.get('content.masterComponentHosts');
  227. var slaveComponents = this.get('content.slaveComponentHosts');
  228. masterComponents.forEach(function (component) {
  229. var host = hostNameToHostMap[component.hostName];
  230. var hc = App.HostComponent.createRecord({
  231. componentName: component.component,
  232. host: host
  233. });
  234. if (host != null) {
  235. host.get('hostComponents').pushObject(hc);
  236. }
  237. });
  238. slaveComponents.forEach(function (component) {
  239. component.hosts.forEach(function (host) {
  240. var h = hostNameToHostMap[host.hostName];
  241. var hc = App.HostComponent.createRecord({
  242. componentName: component.componentName,
  243. host: h
  244. });
  245. if (h != null) {
  246. h.get('hostComponents').pushObject(hc);
  247. }
  248. });
  249. });
  250. return allHosts;
  251. }.property('content')
  252. });