step7_controller.js 10 KB

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