step7_controller.js 16 KB

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