step7_controller.js 9.6 KB

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