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