step7_controller.js 17 KB

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