step7_controller.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. var numberUtils = require('utils/number_utils');
  20. /**
  21. * By Step 7, we have the following information stored in App.db and set on this
  22. * controller by the router.
  23. *
  24. * selectedServices: App.db.selectedServices (the services that the user selected in Step 4)
  25. * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
  26. * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  27. *
  28. */
  29. App.WizardStep7Controller = Em.Controller.extend({
  30. name: 'wizardStep7Controller',
  31. stepConfigs: [], //contains all field properties that are viewed in this step
  32. selectedService: null,
  33. slaveHostToGroup: null,
  34. secureConfigs: require('data/secure_mapping'),
  35. miscModalVisible: false, //If miscConfigChange Modal is shown
  36. gangliaAvailableSpace: null,
  37. gangliaMoutDir:'/',
  38. overrideToAdd: null,
  39. isInstaller: true,
  40. configGroups: [],
  41. selectedConfigGroup: null,
  42. allConfigGroupsNames: function () {
  43. var names = [];
  44. this.get('stepConfigs').forEach(function (service) {
  45. names.pushObjects(service.get('configGroups').mapProperty('name'));
  46. });
  47. return names.uniq();
  48. }.property('selectedService.configGroups.@each.name'),
  49. isSubmitDisabled: function () {
  50. return (!this.stepConfigs.filterProperty('showConfig', true).everyProperty('errorCount', 0) || this.get("miscModalVisible"));
  51. }.property('stepConfigs.@each.errorCount', 'miscModalVisible'),
  52. selectedServiceNames: function () {
  53. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  54. }.property('content.services').cacheable(),
  55. allInstalledServiceNames: function () {
  56. return this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  57. }.property('content.services').cacheable(),
  58. masterComponentHosts: function () {
  59. return this.get('content.masterComponentHosts');
  60. }.property('content.masterComponentHosts'),
  61. slaveComponentHosts: function () {
  62. return this.get('content.slaveGroupProperties');
  63. }.property('content.slaveGroupProperties', 'content.slaveComponentHosts'),
  64. customData: [],
  65. clearStep: function () {
  66. this.get('stepConfigs').clear();
  67. },
  68. /**
  69. * On load function
  70. */
  71. loadStep: function () {
  72. console.log("TRACE: Loading step7: Configure Services");
  73. this.clearStep();
  74. //STEP 1: Load advanced configs
  75. var advancedConfigs = this.get('content.advancedServiceConfig');
  76. //STEP 2: Load on-site configs by service from local DB
  77. var storedConfigs = this.get('content.serviceConfigProperties');
  78. //STEP 3: Merge pre-defined configs with loaded on-site configs
  79. var configs = App.config.mergePreDefinedWithStored(storedConfigs, advancedConfigs);
  80. //STEP 4: Add advanced configs
  81. App.config.addAdvancedConfigs(configs, advancedConfigs);
  82. //STEP 5: Add custom configs
  83. App.config.addCustomConfigs(configs);
  84. //put properties from capacity-scheduler.xml into one config with textarea view
  85. if(this.get('allInstalledServiceNames').contains('YARN') && !App.supports.capacitySchedulerUi){
  86. configs = App.config.fileConfigsIntoTextarea(configs, 'capacity-scheduler.xml');
  87. }
  88. var localDB = {
  89. hosts: this.get('wizardController').getDBProperty('hosts'),
  90. masterComponentHosts: this.get('wizardController').getDBProperty('masterComponentHosts'),
  91. slaveComponentHosts: this.get('wizardController').getDBProperty('slaveComponentHosts')
  92. };
  93. //STEP 6: Distribute configs by service and wrap each one in App.ServiceConfigProperty (configs -> serviceConfigs)
  94. var serviceConfigs = App.config.renderConfigs(configs, storedConfigs, this.get('allInstalledServiceNames'), this.get('selectedServiceNames'), localDB);
  95. if (this.get('wizardController.name') === 'addServiceController') {
  96. serviceConfigs.setEach('showConfig', true);
  97. serviceConfigs.setEach('selected', false);
  98. this.get('selectedServiceNames').forEach(function(serviceName) {
  99. serviceConfigs.findProperty('serviceName', serviceName).set('selected', true);
  100. });
  101. }
  102. this.set('stepConfigs', serviceConfigs);
  103. if (App.supports.hostOverridesInstaller) {
  104. this.loadConfigGroups(this.get('content.configGroups'));
  105. }
  106. this.activateSpecialConfigs();
  107. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  108. if (this.get('content.skipConfigStep')) {
  109. App.router.send('next');
  110. }
  111. },
  112. selectedServiceObserver: function () {
  113. if (App.supports.hostOverridesInstaller && this.get('selectedService') && (this.get('selectedService.serviceName') !== 'MISC')) {
  114. var serviceGroups = this.get('selectedService.configGroups');
  115. this.set('configGroups', serviceGroups);
  116. this.set('selectedConfigGroup', serviceGroups.findProperty('isDefault'));
  117. }
  118. }.observes('selectedService.configGroups.@each'),
  119. /**
  120. * load default groups for each service in case of initial load
  121. * @param serviceConfigGroups
  122. */
  123. loadConfigGroups: function (serviceConfigGroups) {
  124. var services = this.get('stepConfigs');
  125. var hosts = this.get('getAllHosts').mapProperty('hostName');
  126. services.forEach(function (service) {
  127. if (service.get('serviceName') === 'MISC') return;
  128. var serviceRawGroups = serviceConfigGroups.filterProperty('service.id', service.serviceName);
  129. if (!serviceRawGroups.length) {
  130. service.set('configGroups', [
  131. App.ConfigGroup.create({
  132. name: "Default",
  133. description: "Default cluster level " + service.serviceName + " configuration",
  134. isDefault: true,
  135. hosts: hosts,
  136. service: Em.Object.create({
  137. id: service.serviceName
  138. })
  139. })
  140. ]);
  141. } else {
  142. var defaultGroup = App.ConfigGroup.create(serviceRawGroups.findProperty('isDefault'));
  143. var serviceGroups = service.get('configGroups');
  144. serviceRawGroups.filterProperty('isDefault', false).forEach(function (configGroup) {
  145. var readyGroup = App.ConfigGroup.create(configGroup);
  146. var wrappedProperties = [];
  147. readyGroup.get('properties').forEach(function(property){
  148. wrappedProperties.pushObject(App.ServiceConfigProperty.create(property));
  149. });
  150. wrappedProperties.setEach('group', readyGroup);
  151. readyGroup.set('properties', wrappedProperties);
  152. readyGroup.set('parentConfigGroup', defaultGroup);
  153. serviceGroups.pushObject(readyGroup);
  154. });
  155. defaultGroup.set('childConfigGroups', serviceGroups);
  156. serviceGroups.pushObject(defaultGroup);
  157. }
  158. });
  159. },
  160. selectConfigGroup: function (event) {
  161. this.set('selectedConfigGroup', event.context);
  162. },
  163. /**
  164. * rebuild list of configs switch of config group:
  165. * on default - display all configs from default group and configs from non-default groups as disabled
  166. * on non-default - display all from default group as disabled and configs from selected non-default group
  167. */
  168. switchConfigGroupConfigs: function () {
  169. var serviceConfigs = this.get('selectedService.configs');
  170. var selectedGroup = this.get('selectedConfigGroup');
  171. var overrideToAdd = this.get('overrideToAdd');
  172. var displayedConfigGroups = (selectedGroup.get('isDefault')) ?
  173. this.get('selectedService.configGroups').filterProperty('isDefault', false) :
  174. [this.get('selectedConfigGroup')];
  175. var overrides = [];
  176. displayedConfigGroups.forEach(function (group) {
  177. overrides.pushObjects(group.get('properties'));
  178. });
  179. serviceConfigs.forEach(function (config) {
  180. var configOverrides = overrides.filterProperty('name', config.get('name'));
  181. config.set('isEditable', selectedGroup.get('isDefault'));
  182. if (overrideToAdd && overrideToAdd.get('name') === config.get('name')) {
  183. configOverrides.push(this.addOverrideProperty(config));
  184. this.set('overrideToAdd', null);
  185. }
  186. configOverrides.setEach('isEditable', !selectedGroup.get('isDefault'));
  187. config.set('overrides', configOverrides);
  188. }, this);
  189. }.observes('selectedConfigGroup'),
  190. /**
  191. * create overriden property and push it into Config group
  192. * @param serviceConfigProperty
  193. * @return {*}
  194. */
  195. addOverrideProperty: function (serviceConfigProperty) {
  196. var overrides = serviceConfigProperty.get('overrides') || [];
  197. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  198. var group = this.get('selectedService.configGroups').findProperty('name', this.get('selectedConfigGroup.name'));
  199. newSCP.set('group', group);
  200. newSCP.set('value', '');
  201. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  202. newSCP.set('parentSCP', serviceConfigProperty);
  203. newSCP.set('isEditable', true);
  204. group.get('properties').pushObject(newSCP);
  205. overrides.pushObject(newSCP);
  206. return newSCP;
  207. },
  208. manageConfigurationGroup: function () {
  209. App.router.get('mainServiceItemController').manageConfigurationGroups(this);
  210. },
  211. /**
  212. * make some configs visible depending on active services
  213. */
  214. activateSpecialConfigs: function () {
  215. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  216. miscConfigs = App.config.miscConfigVisibleProperty(miscConfigs, this.get('selectedServiceNames'));
  217. },
  218. /**
  219. * @param: An array of display names
  220. */
  221. setDisplayMessage: function (siteProperty, displayNames) {
  222. var displayMsg = null;
  223. if (displayNames && displayNames.length) {
  224. if (displayNames.length === 1) {
  225. displayMsg = siteProperty + ' ' + Em.I18n.t('as') + ' ' + displayNames[0];
  226. } else {
  227. var name = null;
  228. displayNames.forEach(function (_name, index) {
  229. if (index === 0) {
  230. name = _name;
  231. } else if (index === displayNames.length - 1) {
  232. name = name + ' ' + Em.I18n.t('and') + ' ' + _name;
  233. } else {
  234. name = name + ', ' + _name;
  235. }
  236. }, this);
  237. displayMsg = siteProperty + ' ' + Em.I18n.t('as') + ' ' + name;
  238. }
  239. } else {
  240. displayMsg = siteProperty;
  241. }
  242. return displayMsg;
  243. },
  244. /**
  245. * Set display names of the property tfrom he puppet/global names
  246. * @param displayNames: a field to be set with displayNames
  247. * @param names: array of property puppet/global names
  248. * @param configProperties: array of config properties of the respective service to the name param
  249. */
  250. setPropertyDisplayNames: function (displayNames, names, configProperties) {
  251. names.forEach(function (_name, index) {
  252. if (configProperties.someProperty('name', _name)) {
  253. displayNames.push(configProperties.findProperty('name', _name).displayName);
  254. }
  255. }, this);
  256. },
  257. /**
  258. * Display Error Message with service name, its custom configuration name and displaynames on the page
  259. * @param customConfig: array with custom configuration, serviceName and displayNames relative to custom configuration
  260. */
  261. showCustomConfigErrMsg: function (customConfig) {
  262. App.ModalPopup.show({
  263. header: Em.I18n.t('installer.step7.ConfigErrMsg.header'),
  264. primary: Em.I18n.t('ok'),
  265. secondary: null,
  266. onPrimary: function () {
  267. this.hide();
  268. },
  269. bodyClass: Ember.View.extend({
  270. message: Em.I18n.t('installer.step7.ConfigErrMsg.message'),
  271. siteProperties: customConfig,
  272. getDisplayMessage: function () {
  273. }.property('customConfig.@each.siteProperties.@each.siteProperty'),
  274. customConfig: customConfig,
  275. templateName: require('templates/wizard/step7_custom_config_error')
  276. })
  277. });
  278. },
  279. submit: function () {
  280. if (!this.get('isSubmitDisabled')) {
  281. App.router.send('next');
  282. }
  283. },
  284. /**
  285. * Provides service component name and display-name information for
  286. * the current selected service.
  287. */
  288. getCurrentServiceComponents: function () {
  289. var selectedServiceName = this.get('selectedService.serviceName');
  290. var masterComponents = this.get('content.masterComponentHosts');
  291. var slaveComponents = this.get('content.slaveComponentHosts');
  292. var scMaps = require('data/service_components');
  293. var validComponents = Ember.A([]);
  294. var seenComponents = {};
  295. masterComponents.forEach(function(component){
  296. var cn = component.component
  297. var cdn = component.display_name;
  298. if(component.serviceId===selectedServiceName && !seenComponents[cn]){
  299. validComponents.pushObject(Ember.Object.create({
  300. componentName: cn,
  301. displayName: cdn,
  302. selected: false
  303. }));
  304. seenComponents[cn] = cn;
  305. }
  306. });
  307. slaveComponents.forEach(function(component){
  308. var cn = component.componentName
  309. var cdn = component.displayName;
  310. var componentDef = scMaps.findProperty('component_name', cn);
  311. if(componentDef!=null && selectedServiceName===componentDef.service_name && !seenComponents[cn]){
  312. validComponents.pushObject(Ember.Object.create({
  313. componentName: cn,
  314. displayName: cdn,
  315. selected: false
  316. }));
  317. seenComponents[cn] = cn;
  318. }
  319. });
  320. return validComponents;
  321. }.property('content'),
  322. getAllHosts: function () {
  323. // Load hosts
  324. var allHosts = Ember.A([]);
  325. var hostNameToHostMap = {};
  326. var hosts = this.get('content.hosts');
  327. for ( var hostName in hosts) {
  328. var host = hosts[hostName];
  329. hostNameToHostMap[hostName] = App.Host.createRecord({
  330. id: host.name,
  331. hostName: host.name,
  332. publicHostName: host.name,
  333. cpu: host.cpu,
  334. memory: host.memory
  335. });
  336. allHosts.pushObject(hostNameToHostMap[hostName]);
  337. }
  338. // Load host-components
  339. var masterComponents = this.get('content.masterComponentHosts');
  340. var slaveComponents = this.get('content.slaveComponentHosts');
  341. masterComponents.forEach(function (component) {
  342. var host = hostNameToHostMap[component.hostName];
  343. var hc = App.HostComponent.createRecord({
  344. componentName: component.component,
  345. host: host
  346. });
  347. if (host != null) {
  348. host.get('hostComponents').pushObject(hc);
  349. }
  350. });
  351. slaveComponents.forEach(function (component) {
  352. component.hosts.forEach(function (host) {
  353. var h = hostNameToHostMap[host.hostName];
  354. var hc = App.HostComponent.createRecord({
  355. componentName: component.componentName,
  356. host: h
  357. });
  358. if (h != null) {
  359. h.get('hostComponents').pushObject(hc);
  360. }
  361. });
  362. });
  363. return allHosts;
  364. }.property('content')
  365. });