step7_controller.js 11 KB

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