step7_controller.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. //STEP 6: Distribute configs by service and wrap each one in App.ServiceConfigProperty (configs -> serviceConfigs)
  78. var serviceConfigs = App.config.renderConfigs(configs, storedConfigs, this.get('allInstalledServiceNames'), this.get('selectedServiceNames'));
  79. this.set('stepConfigs', serviceConfigs);
  80. this.activateSpecialConfigs();
  81. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  82. },
  83. /**
  84. * make some configs visible depending on active services
  85. */
  86. activateSpecialConfigs: function () {
  87. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  88. miscConfigs = App.config.miscConfigVisibleProperty(miscConfigs, this.get('selectedServiceNames'));
  89. },
  90. /**
  91. * @param: An array of display names
  92. */
  93. setDisplayMessage: function (siteProperty, displayNames) {
  94. var displayMsg = null;
  95. if (displayNames && displayNames.length) {
  96. if (displayNames.length === 1) {
  97. displayMsg = siteProperty + ' ' + Em.I18n.t('as') + ' ' + displayNames[0];
  98. } else {
  99. var name = null;
  100. displayNames.forEach(function (_name, index) {
  101. if (index === 0) {
  102. name = _name;
  103. } else if (index === displayNames.length - 1) {
  104. name = name + ' ' + Em.I18n.t('and') + ' ' + _name;
  105. } else {
  106. name = name + ', ' + _name;
  107. }
  108. }, this);
  109. displayMsg = siteProperty + ' ' + Em.I18n.t('as') + ' ' + name;
  110. }
  111. } else {
  112. displayMsg = siteProperty;
  113. }
  114. return displayMsg;
  115. },
  116. /**
  117. * Set display names of the property tfrom he puppet/global names
  118. * @param displayNames: a field to be set with displayNames
  119. * @param names: array of property puppet/global names
  120. * @param configProperties: array of config properties of the respective service to the name param
  121. */
  122. setPropertyDisplayNames: function (displayNames, names, configProperties) {
  123. names.forEach(function (_name, index) {
  124. if (configProperties.someProperty('name', _name)) {
  125. displayNames.push(configProperties.findProperty('name', _name).displayName);
  126. }
  127. }, this);
  128. },
  129. /**
  130. * Display Error Message with service name, its custom configuration name and displaynames on the page
  131. * @param customConfig: array with custom configuration, serviceName and displayNames relative to custom configuration
  132. */
  133. showCustomConfigErrMsg: function (customConfig) {
  134. App.ModalPopup.show({
  135. header: Em.I18n.t('installer.step7.ConfigErrMsg.header'),
  136. primary: Em.I18n.t('ok'),
  137. secondary: null,
  138. onPrimary: function () {
  139. this.hide();
  140. },
  141. bodyClass: Ember.View.extend({
  142. message: Em.I18n.t('installer.step7.ConfigErrMsg.message'),
  143. siteProperties: customConfig,
  144. getDisplayMessage: function () {
  145. }.property('customConfig.@each.siteProperties.@each.siteProperty'),
  146. customConfig: customConfig,
  147. template: Ember.Handlebars.compile([
  148. '<h5>{{view.message}}</h5>',
  149. '<br/>',
  150. '<div class="pre-scrollable" style="max-height: 250px;">',
  151. '<ul>',
  152. '{{#each val in view.customConfig}}',
  153. '{{#if val.siteProperties}}',
  154. '<li>',
  155. '{{val.serviceName}}',
  156. '<ul>',
  157. '{{#each item in val.siteProperties}}',
  158. '<li>',
  159. '{{item.displayMsg}}',
  160. '</li>',
  161. '{{/each}}',
  162. '</ul>',
  163. '</li>',
  164. '{{/if}}',
  165. '{{/each}}',
  166. '</ul>',
  167. '</div>'
  168. ].join('\n'))
  169. })
  170. });
  171. },
  172. submit: function () {
  173. if (!this.get('isSubmitDisabled')) {
  174. App.router.send('next');
  175. }
  176. },
  177. /**
  178. * Provides service component name and display-name information for
  179. * the current selected service.
  180. */
  181. getCurrentServiceComponents: function () {
  182. var selectedServiceName = this.get('selectedService.serviceName');
  183. var masterComponents = this.get('content.masterComponentHosts');
  184. var slaveComponents = this.get('content.slaveComponentHosts');
  185. var scMaps = require('data/service_components');
  186. var validComponents = Ember.A([]);
  187. var seenComponents = {};
  188. masterComponents.forEach(function(component){
  189. var cn = component.component
  190. var cdn = component.display_name;
  191. if(component.serviceId===selectedServiceName && !seenComponents[cn]){
  192. validComponents.pushObject(Ember.Object.create({
  193. componentName: cn,
  194. displayName: cdn,
  195. selected: false
  196. }));
  197. seenComponents[cn] = cn;
  198. }
  199. });
  200. slaveComponents.forEach(function(component){
  201. var cn = component.componentName
  202. var cdn = component.displayName;
  203. var componentDef = scMaps.findProperty('component_name', cn);
  204. if(componentDef!=null && selectedServiceName===componentDef.service_name && !seenComponents[cn]){
  205. validComponents.pushObject(Ember.Object.create({
  206. componentName: cn,
  207. displayName: cdn,
  208. selected: false
  209. }));
  210. seenComponents[cn] = cn;
  211. }
  212. });
  213. return validComponents;
  214. }.property('content'),
  215. getAllHosts: function () {
  216. // Load hosts
  217. var allHosts = Ember.A([]);
  218. var hostNameToHostMap = {};
  219. var hosts = this.get('content.hosts');
  220. for ( var hostName in hosts) {
  221. var host = hosts[hostName];
  222. hostNameToHostMap[hostName] = App.Host.createRecord({
  223. id: host.name,
  224. hostName: host.name,
  225. publicHostName: host.name,
  226. cpu: host.cpu,
  227. memory: host.memory
  228. });
  229. allHosts.pushObject(hostNameToHostMap[hostName]);
  230. }
  231. // Load host-components
  232. var masterComponents = this.get('content.masterComponentHosts');
  233. var slaveComponents = this.get('content.slaveComponentHosts');
  234. masterComponents.forEach(function (component) {
  235. var host = hostNameToHostMap[component.hostName];
  236. var hc = App.HostComponent.createRecord({
  237. componentName: component.component,
  238. host: host
  239. });
  240. if (host != null) {
  241. host.get('hostComponents').pushObject(hc);
  242. }
  243. });
  244. slaveComponents.forEach(function (component) {
  245. component.hosts.forEach(function (host) {
  246. var h = hostNameToHostMap[host.hostName];
  247. var hc = App.HostComponent.createRecord({
  248. componentName: component.componentName,
  249. host: h
  250. });
  251. if (h != null) {
  252. h.get('hostComponents').pushObject(hc);
  253. }
  254. });
  255. });
  256. return allHosts;
  257. }.property('content')
  258. });