step7_controller.js 11 KB

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