step7_controller.js 9.6 KB

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