step7_controller.js 11 KB

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