step7_controller.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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. groupsToDelete: [],
  42. selectedConfigGroup: null,
  43. /**
  44. * config tags of actually installed services
  45. */
  46. serviceConfigTags: [],
  47. serviceConfigsData: require('data/service_configs'),
  48. isSubmitDisabled: function () {
  49. return (!this.stepConfigs.filterProperty('showConfig', true).everyProperty('errorCount', 0) || this.get("miscModalVisible"));
  50. }.property('stepConfigs.@each.errorCount', 'miscModalVisible'),
  51. selectedServiceNames: function () {
  52. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  53. }.property('content.services').cacheable(),
  54. allSelectedServiceNames: function () {
  55. return this.get('content.services').filterProperty('isSelected').mapProperty('serviceName');
  56. }.property('content.services').cacheable(),
  57. installedServiceNames: function () {
  58. return this.get('content.services').filterProperty('isInstalled').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('serviceConfigTags').clear();
  69. this.get('stepConfigs').clear();
  70. this.set('filter', '');
  71. this.get('filterColumns').setEach('selected', false);
  72. },
  73. /**
  74. * Load config groups for installed services
  75. */
  76. loadInstalledServicesConfigGroups: function (servicesNames) {
  77. if (servicesNames.indexOf('MISC') > -1)
  78. servicesNames.splice(servicesNames.indexOf('MISC'), 1);
  79. servicesNames.forEach(function(serviceName) {
  80. App.ajax.send({
  81. name: 'config.tags_and_groups',
  82. sender: this,
  83. data: {
  84. serviceName: serviceName,
  85. serviceConfigsDef: App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName)
  86. },
  87. success: 'loadServiceTagsSuccess'
  88. });
  89. }, this);
  90. },
  91. /**
  92. * Load config groups success callback
  93. */
  94. loadServiceTagsSuccess: function (data, opt, params) {
  95. var serviceConfigsDef = params.serviceConfigsDef;
  96. var serviceName = params.serviceName;
  97. var service = this.get('stepConfigs').findProperty('serviceName', serviceName);
  98. // Create default configuration group
  99. var defaultConfigGroupHosts = App.Host.find().mapProperty('hostName');
  100. var selectedConfigGroup;
  101. var siteToTagMap = {};
  102. for (var site in data.Clusters.desired_configs) {
  103. if (serviceConfigsDef.sites.indexOf(site) > -1) {
  104. siteToTagMap[site] = data.Clusters.desired_configs[site].tag;
  105. }
  106. }
  107. this.loadedClusterSiteToTagMap = siteToTagMap;
  108. //parse loaded config groups
  109. if (App.supports.hostOverrides) {
  110. var configGroups = [];
  111. if (data.config_groups.length) {
  112. data.config_groups.forEach(function (item) {
  113. item = item.ConfigGroup;
  114. if (item.tag === serviceName) {
  115. var groupHosts = item.hosts.mapProperty('host_name');
  116. var newConfigGroup = App.ConfigGroup.create({
  117. id: item.id,
  118. name: item.group_name,
  119. description: item.description,
  120. isDefault: false,
  121. parentConfigGroup: null,
  122. service: App.Service.find().findProperty('serviceName', item.tag),
  123. hosts: groupHosts,
  124. configSiteTags: []
  125. });
  126. groupHosts.forEach(function (host) {
  127. defaultConfigGroupHosts = defaultConfigGroupHosts.without(host);
  128. }, this);
  129. item.desired_configs.forEach(function (config) {
  130. newConfigGroup.configSiteTags.push(App.ConfigSiteTag.create({
  131. site: config.type,
  132. tag: config.tag
  133. }));
  134. }, this);
  135. configGroups.push(newConfigGroup);
  136. }
  137. }, this);
  138. }
  139. }
  140. var defaultConfigGroup = App.ConfigGroup.create({
  141. name: App.Service.DisplayNames[serviceName] + " Default",
  142. description: "Default cluster level " + serviceName + " configuration",
  143. isDefault: true,
  144. hosts: defaultConfigGroupHosts,
  145. parentConfigGroup: null,
  146. service: Em.Object.create({
  147. id: serviceName
  148. }),
  149. serviceName: serviceName,
  150. configSiteTags: []
  151. });
  152. if (!selectedConfigGroup) {
  153. selectedConfigGroup = defaultConfigGroup;
  154. }
  155. configGroups.sort(function(configGroupA, configGroupB){
  156. return (configGroupA.name > configGroupB.name);
  157. });
  158. configGroups.unshift(defaultConfigGroup);
  159. if (App.supports.hostOverrides) {
  160. service.set('configGroups', configGroups);
  161. var loadedGroupToOverrideSiteToTagMap = {};
  162. if (App.supports.hostOverrides) {
  163. var configGroupsWithOverrides = selectedConfigGroup.get('isDefault') ? service.get('configGroups') : [selectedConfigGroup];
  164. configGroupsWithOverrides.forEach(function (item) {
  165. var groupName = item.get('name');
  166. loadedGroupToOverrideSiteToTagMap[groupName] = {};
  167. item.get('configSiteTags').forEach(function (siteTag) {
  168. var site = siteTag.get('site');
  169. var tag = siteTag.get('tag');
  170. loadedGroupToOverrideSiteToTagMap[groupName][site] = tag;
  171. }, this);
  172. }, this);
  173. }
  174. App.config.loadServiceConfigHostsOverrides(service.get('configs'), loadedGroupToOverrideSiteToTagMap, service.get('configGroups'));
  175. var serviceConfig = App.config.createServiceConfig(serviceName);
  176. if (serviceConfig.get('serviceName') === 'HDFS') {
  177. App.config.OnNnHAHideSnn(serviceConfig);
  178. }
  179. service.set('selectedConfigGroup', selectedConfigGroup);
  180. this.loadComponentConfigs(service.get('configs'), serviceConfig, service);
  181. }
  182. service.set('configs', serviceConfig.get('configs'));
  183. },
  184. loadComponentConfigs: function (configs, componentConfig, component) {
  185. var localDB = App.router.get('mainServiceInfoConfigsController').getInfoForDefaults();
  186. var recommendedDefaults = {};
  187. var s = this.get('serviceConfigsData').findProperty('serviceName', component.get('serviceName'));
  188. var defaultGroupSelected = component.get('selectedConfigGroup.isDefault');
  189. var defaults = [];
  190. if (s.defaultsProviders) {
  191. s.defaultsProviders.forEach(function(defaultsProvider) {
  192. var d = defaultsProvider.getDefaults(localDB);
  193. defaults.push(d);
  194. for (var name in d) {
  195. recommendedDefaults[name] = d[name];
  196. }
  197. });
  198. }
  199. if (s.configsValidator) {
  200. s.configsValidator.set('recommendedDefaults', recommendedDefaults);
  201. }
  202. configs.forEach(function (serviceConfigProperty) {
  203. console.log("config", serviceConfigProperty);
  204. if (!serviceConfigProperty) return;
  205. var overrides = serviceConfigProperty.get('overrides');
  206. // we will populate the override properties below
  207. serviceConfigProperty.set('overrides', null);
  208. if (serviceConfigProperty.isOverridable === undefined) {
  209. serviceConfigProperty.set('isOverridable', true);
  210. }
  211. if (serviceConfigProperty.displayType === 'checkbox') {
  212. switch (serviceConfigProperty.value) {
  213. case 'true':
  214. serviceConfigProperty.set('value', true);
  215. serviceConfigProperty.set('defaultValue', true);
  216. break;
  217. case 'false':
  218. serviceConfigProperty.set('value', false);
  219. serviceConfigProperty.set('defaultValue', false);
  220. break;
  221. }
  222. }
  223. if (serviceConfigProperty.get('serviceName') === component.get('serviceName')) {
  224. if (s.configsValidator) {
  225. var validators = s.configsValidator.get('configValidators');
  226. for (var validatorName in validators) {
  227. if (serviceConfigProperty.name == validatorName) {
  228. serviceConfigProperty.set('serviceValidator', s.configsValidator);
  229. }
  230. }
  231. }
  232. serviceConfigProperty.set('isVisible', true);
  233. console.log("config result", serviceConfigProperty);
  234. } else {
  235. serviceConfigProperty.set('isVisible', false);
  236. }
  237. if (overrides != null) {
  238. overrides.forEach(function (override) {
  239. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  240. newSCP.set('value', override.value);
  241. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  242. newSCP.set('parentSCP', serviceConfigProperty);
  243. if (App.supports.hostOverrides && defaultGroupSelected) {
  244. var group = component.get('configGroups').findProperty('name', override.group.get('name'));
  245. // prevent cycle in proto object, clean link
  246. if (group.get('properties').length == 0)
  247. group.set('properties', Em.A([]));
  248. group.get('properties').push(newSCP);
  249. newSCP.set('group', override.group);
  250. newSCP.set('isEditable', false);
  251. }
  252. var parentOverridesArray = serviceConfigProperty.get('overrides');
  253. if (parentOverridesArray == null) {
  254. parentOverridesArray = Ember.A([]);
  255. serviceConfigProperty.set('overrides', parentOverridesArray);
  256. }
  257. serviceConfigProperty.get('overrides').pushObject(newSCP);
  258. console.debug("createOverrideProperty(): Added:", newSCP, " to main-property:", serviceConfigProperty)
  259. }, this);
  260. } else {
  261. serviceConfigProperty.set('overrides', Ember.A([]));
  262. }
  263. if (App.get('isAdmin')) {
  264. if(defaultGroupSelected && !this.get('isHostsConfigsPage')){
  265. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  266. } else {
  267. serviceConfigProperty.set('isEditable', false);
  268. }
  269. } else {
  270. serviceConfigProperty.set('isEditable', false);
  271. }
  272. componentConfig.get('configs').pushObject(serviceConfigProperty);
  273. serviceConfigProperty.validate();
  274. }, this);
  275. var overrideToAdd = this.get('overrideToAdd');
  276. if (overrideToAdd) {
  277. overrideToAdd = componentConfig.configs.findProperty('name', overrideToAdd.name);
  278. if (overrideToAdd) {
  279. this.addOverrideProperty(overrideToAdd);
  280. component.set('overrideToAdd', null);
  281. }
  282. }
  283. },
  284. /**
  285. * On load function
  286. */
  287. loadStep: function () {
  288. console.log("TRACE: Loading step7: Configure Services");
  289. this.clearStep();
  290. //STEP 1: Load advanced configs
  291. var advancedConfigs = this.get('content.advancedServiceConfig');
  292. //STEP 2: Load on-site configs by service from local DB
  293. var storedConfigs = this.get('content.serviceConfigProperties');
  294. //STEP 3: Merge pre-defined configs with loaded on-site configs
  295. var configs = App.config.mergePreDefinedWithStored(storedConfigs, advancedConfigs);
  296. //STEP 4: Add advanced configs
  297. App.config.addAdvancedConfigs(configs, advancedConfigs);
  298. //STEP 5: Add custom configs
  299. App.config.addCustomConfigs(configs);
  300. //put properties from capacity-scheduler.xml into one config with textarea view
  301. if (this.get('allSelectedServiceNames').contains('YARN') && !App.supports.capacitySchedulerUi) {
  302. configs = App.config.fileConfigsIntoTextarea(configs, 'capacity-scheduler.xml');
  303. }
  304. this.set('groupsToDelete', this.get('wizardController').getDBProperty('groupsToDelete') || []);
  305. var localDB = {
  306. hosts: this.get('wizardController').getDBProperty('hosts'),
  307. masterComponentHosts: this.get('wizardController').getDBProperty('masterComponentHosts'),
  308. slaveComponentHosts: this.get('wizardController').getDBProperty('slaveComponentHosts')
  309. };
  310. if (this.get('wizardController.name') === 'addServiceController') {
  311. this.getConfigTags();
  312. this.setInstalledServiceConfigs(this.get('serviceConfigTags'), configs);
  313. }
  314. //STEP 6: Distribute configs by service and wrap each one in App.ServiceConfigProperty (configs -> serviceConfigs)
  315. var serviceConfigs = App.config.renderConfigs(configs, storedConfigs, this.get('allSelectedServiceNames'), this.get('installedServiceNames'), localDB);
  316. if (this.get('wizardController.name') === 'addServiceController') {
  317. serviceConfigs.setEach('showConfig', true);
  318. serviceConfigs.setEach('selected', false);
  319. this.get('selectedServiceNames').forEach(function(serviceName) {
  320. if(!serviceConfigs.findProperty('serviceName', serviceName)) return;
  321. serviceConfigs.findProperty('serviceName', serviceName).set('selected', true);
  322. });
  323. // Remove SNameNode if HA is enabled
  324. if (App.get('isHaEnabled')) {
  325. configs = serviceConfigs.findProperty('serviceName', 'HDFS').configs;
  326. var removedConfigs = configs.filterProperty('category', 'SNameNode');
  327. removedConfigs.map(function(config) {
  328. configs = configs.without(config);
  329. });
  330. serviceConfigs.findProperty('serviceName', 'HDFS').configs = configs;
  331. }
  332. }
  333. this.set('stepConfigs', serviceConfigs);
  334. if (App.supports.hostOverridesInstaller) {
  335. this.loadConfigGroups(this.get('content.configGroups'));
  336. var installedServicesConfigs = this.get('stepConfigs').filterProperty('selected', false);
  337. if (installedServicesConfigs.length > 0 && !storedConfigs)
  338. this.loadInstalledServicesConfigGroups(installedServicesConfigs.mapProperty('serviceName'));
  339. }
  340. this.activateSpecialConfigs();
  341. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  342. if (this.get('content.skipConfigStep')) {
  343. App.router.send('next');
  344. }
  345. },
  346. getConfigTags: function() {
  347. App.ajax.send({
  348. name: 'config.tags.sync',
  349. sender: this,
  350. success: 'getConfigTagsSuccess'
  351. });
  352. },
  353. getConfigTagsSuccess: function (data, opt, params) {
  354. var installedServiceSites = [];
  355. this.get('serviceConfigsData').filter(function (service) {
  356. if (this.get('installedServiceNames').contains(service.serviceName)){
  357. installedServiceSites = installedServiceSites.concat(service.sites);
  358. }
  359. }, this);
  360. installedServiceSites = installedServiceSites.uniq();
  361. var serviceConfigTags = [];
  362. for (var site in data.Clusters.desired_configs) {
  363. if (installedServiceSites.contains(site)) {
  364. serviceConfigTags.push({
  365. siteName: site,
  366. tagName: data.Clusters.desired_configs[site].tag,
  367. newTagName: null
  368. });
  369. }
  370. }
  371. this.set('serviceConfigTags', serviceConfigTags);
  372. },
  373. /**
  374. * set configs actual values from server
  375. * @param serviceConfigTags
  376. * @param configs
  377. */
  378. setInstalledServiceConfigs: function (serviceConfigTags, configs) {
  379. var configsMap = {};
  380. App.router.get('configurationController').getConfigsByTags(serviceConfigTags).forEach(function(configSite){
  381. $.extend(configsMap, configSite.properties);
  382. });
  383. configs.forEach(function (_config) {
  384. if (configsMap[_config.name] !== undefined) {
  385. _config.value = configsMap[_config.name];
  386. _config.defaultValue = configsMap[_config.name];
  387. App.config.handleSpecialProperties(_config);
  388. }
  389. })
  390. },
  391. setGroupsToDelete: function(groups) {
  392. var groupsToDelete = this.get('groupsToDelete');
  393. groups.forEach(function(group) {
  394. if (group.get('id'))
  395. groupsToDelete.push({
  396. id: group.get('id')
  397. });
  398. });
  399. this.get('wizardController').setDBProperty('groupsToDelete', groupsToDelete);
  400. },
  401. selectedServiceObserver: function () {
  402. if (App.supports.hostOverridesInstaller && this.get('selectedService') && (this.get('selectedService.serviceName') !== 'MISC')) {
  403. var serviceGroups = this.get('selectedService.configGroups');
  404. serviceGroups.forEach(function (item, index, array) {
  405. if (item.isDefault) {
  406. array.unshift(item);
  407. array.splice(index + 1, 1);
  408. }
  409. });
  410. this.set('configGroups', serviceGroups);
  411. this.set('selectedConfigGroup', serviceGroups.findProperty('isDefault'));
  412. }
  413. }.observes('selectedService.configGroups.@each'),
  414. /**
  415. * load default groups for each service in case of initial load
  416. * @param serviceConfigGroups
  417. */
  418. loadConfigGroups: function (serviceConfigGroups) {
  419. var services = this.get('stepConfigs');
  420. var hosts = this.get('getAllHosts').mapProperty('hostName');
  421. services.forEach(function (service) {
  422. if (service.get('serviceName') === 'MISC') return;
  423. var serviceRawGroups = serviceConfigGroups.filterProperty('service.id', service.serviceName);
  424. if (!serviceRawGroups.length) {
  425. service.set('configGroups', [
  426. App.ConfigGroup.create({
  427. name: App.Service.DisplayNames[service.serviceName] + " Default",
  428. description: "Default cluster level " + service.serviceName + " configuration",
  429. isDefault: true,
  430. hosts: Em.copy(hosts),
  431. service: Em.Object.create({
  432. id: service.serviceName
  433. }),
  434. serviceName: service.serviceName
  435. })
  436. ]);
  437. } else {
  438. var defaultGroup = App.ConfigGroup.create(serviceRawGroups.findProperty('isDefault'));
  439. var serviceGroups = service.get('configGroups');
  440. serviceRawGroups.filterProperty('isDefault', false).forEach(function (configGroup) {
  441. var readyGroup = App.ConfigGroup.create(configGroup);
  442. var wrappedProperties = [];
  443. readyGroup.get('properties').forEach(function(property){
  444. wrappedProperties.pushObject(App.ServiceConfigProperty.create(property));
  445. });
  446. wrappedProperties.setEach('group', readyGroup);
  447. readyGroup.set('properties', wrappedProperties);
  448. readyGroup.set('parentConfigGroup', defaultGroup);
  449. serviceGroups.pushObject(readyGroup);
  450. });
  451. defaultGroup.set('childConfigGroups', serviceGroups);
  452. serviceGroups.pushObject(defaultGroup);
  453. }
  454. });
  455. },
  456. selectConfigGroup: function (event) {
  457. this.set('selectedConfigGroup', event.context);
  458. },
  459. /**
  460. * rebuild list of configs switch of config group:
  461. * on default - display all configs from default group and configs from non-default groups as disabled
  462. * on non-default - display all from default group as disabled and configs from selected non-default group
  463. */
  464. switchConfigGroupConfigs: function () {
  465. var serviceConfigs = this.get('selectedService.configs');
  466. var selectedGroup = this.get('selectedConfigGroup');
  467. var overrideToAdd = this.get('overrideToAdd');
  468. var isServiceInstalled = this.get('installedServiceNames').contains(this.get('selectedService.serviceName'));
  469. if(!selectedGroup) return;
  470. var displayedConfigGroups = (selectedGroup.get('isDefault')) ?
  471. this.get('selectedService.configGroups').filterProperty('isDefault', false) :
  472. [this.get('selectedConfigGroup')];
  473. var overrides = [];
  474. displayedConfigGroups.forEach(function (group) {
  475. overrides.pushObjects(group.get('properties'));
  476. });
  477. serviceConfigs.forEach(function (config) {
  478. var configOverrides = overrides.filterProperty('name', config.get('name'));
  479. var isEditable = config.get('isEditable');
  480. if (isServiceInstalled) {
  481. isEditable = (!isEditable && !config.get('isReconfigurable')) ? false : selectedGroup.get('isDefault');
  482. } else {
  483. isEditable = selectedGroup.get('isDefault');
  484. }
  485. config.set('isEditable', isEditable);
  486. if (overrideToAdd && overrideToAdd.get('name') === config.get('name')) {
  487. configOverrides.push(this.addOverrideProperty(config));
  488. this.set('overrideToAdd', null);
  489. }
  490. configOverrides.setEach('isEditable', !selectedGroup.get('isDefault'));
  491. configOverrides.setEach('parentSCP', config);
  492. config.set('overrides', configOverrides);
  493. }, this);
  494. }.observes('selectedConfigGroup'),
  495. /**
  496. * create overriden property and push it into Config group
  497. * @param serviceConfigProperty
  498. * @return {*}
  499. */
  500. addOverrideProperty: function (serviceConfigProperty) {
  501. var overrides = serviceConfigProperty.get('overrides') || [];
  502. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  503. var group = this.get('selectedService.configGroups').findProperty('name', this.get('selectedConfigGroup.name'));
  504. newSCP.set('group', group);
  505. newSCP.set('value', '');
  506. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  507. newSCP.set('parentSCP', serviceConfigProperty);
  508. newSCP.set('isEditable', true);
  509. group.get('properties').pushObject(newSCP);
  510. overrides.pushObject(newSCP);
  511. return newSCP;
  512. },
  513. manageConfigurationGroup: function () {
  514. App.router.get('mainServiceInfoConfigsController').manageConfigurationGroups(this);
  515. },
  516. /**
  517. * Filter text will be located here
  518. */
  519. filter: '',
  520. /**
  521. * Dropdown menu items in filter combobox
  522. */
  523. filterColumns: function () {
  524. var result = [];
  525. for (var i = 1; i < 2; i++) {
  526. result.push(Ember.Object.create({
  527. name: this.t('common.combobox.dropdown.' + i),
  528. selected: false
  529. }));
  530. }
  531. return result;
  532. }.property(),
  533. /**
  534. * make some configs visible depending on active services
  535. */
  536. activateSpecialConfigs: function () {
  537. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  538. miscConfigs = App.config.miscConfigVisibleProperty(miscConfigs, this.get('selectedServiceNames'));
  539. },
  540. /**
  541. * @param: An array of display names
  542. */
  543. setDisplayMessage: function (siteProperty, displayNames) {
  544. var displayMsg = null;
  545. if (displayNames && displayNames.length) {
  546. if (displayNames.length === 1) {
  547. displayMsg = siteProperty + ' ' + Em.I18n.t('as') + ' ' + displayNames[0];
  548. } else {
  549. var name = null;
  550. displayNames.forEach(function (_name, index) {
  551. if (index === 0) {
  552. name = _name;
  553. } else if (index === displayNames.length - 1) {
  554. name = name + ' ' + Em.I18n.t('and') + ' ' + _name;
  555. } else {
  556. name = name + ', ' + _name;
  557. }
  558. }, this);
  559. displayMsg = siteProperty + ' ' + Em.I18n.t('as') + ' ' + name;
  560. }
  561. } else {
  562. displayMsg = siteProperty;
  563. }
  564. return displayMsg;
  565. },
  566. /**
  567. * Set display names of the property tfrom he puppet/global names
  568. * @param displayNames: a field to be set with displayNames
  569. * @param names: array of property puppet/global names
  570. * @param configProperties: array of config properties of the respective service to the name param
  571. */
  572. setPropertyDisplayNames: function (displayNames, names, configProperties) {
  573. names.forEach(function (_name, index) {
  574. if (configProperties.someProperty('name', _name)) {
  575. displayNames.push(configProperties.findProperty('name', _name).displayName);
  576. }
  577. }, this);
  578. },
  579. /**
  580. * Display Error Message with service name, its custom configuration name and displaynames on the page
  581. * @param customConfig: array with custom configuration, serviceName and displayNames relative to custom configuration
  582. */
  583. showCustomConfigErrMsg: function (customConfig) {
  584. App.ModalPopup.show({
  585. header: Em.I18n.t('installer.step7.ConfigErrMsg.header'),
  586. primary: Em.I18n.t('ok'),
  587. secondary: null,
  588. bodyClass: Ember.View.extend({
  589. message: Em.I18n.t('installer.step7.ConfigErrMsg.message'),
  590. siteProperties: customConfig,
  591. getDisplayMessage: function () {
  592. }.property('customConfig.@each.siteProperties.@each.siteProperty'),
  593. customConfig: customConfig,
  594. templateName: require('templates/wizard/step7_custom_config_error')
  595. })
  596. });
  597. },
  598. submit: function () {
  599. if (!this.get('isSubmitDisabled')) {
  600. App.router.send('next');
  601. }
  602. },
  603. /**
  604. * Provides service component name and display-name information for
  605. * the current selected service.
  606. */
  607. getCurrentServiceComponents: function () {
  608. var selectedServiceName = this.get('selectedService.serviceName');
  609. var masterComponents = this.get('content.masterComponentHosts');
  610. var slaveComponents = this.get('content.slaveComponentHosts');
  611. var scMaps = require('data/service_components');
  612. var validComponents = Ember.A([]);
  613. var seenComponents = {};
  614. masterComponents.forEach(function(component){
  615. var cn = component.component
  616. var cdn = component.display_name;
  617. if(component.serviceId===selectedServiceName && !seenComponents[cn]){
  618. validComponents.pushObject(Ember.Object.create({
  619. componentName: cn,
  620. displayName: cdn,
  621. selected: false
  622. }));
  623. seenComponents[cn] = cn;
  624. }
  625. });
  626. slaveComponents.forEach(function(component){
  627. var cn = component.componentName
  628. var cdn = component.displayName;
  629. var componentDef = scMaps.findProperty('component_name', cn);
  630. if(componentDef!=null && selectedServiceName===componentDef.service_name && !seenComponents[cn]){
  631. validComponents.pushObject(Ember.Object.create({
  632. componentName: cn,
  633. displayName: cdn,
  634. selected: false
  635. }));
  636. seenComponents[cn] = cn;
  637. }
  638. });
  639. return validComponents;
  640. }.property('content'),
  641. getAllHosts: function () {
  642. if (App.Host.find().content.length > 0) {
  643. return App.Host.find();
  644. }
  645. var hosts = this.get('content.hosts');
  646. var masterComponents = this.get('content.masterComponentHosts');
  647. var slaveComponents = this.get('content.slaveComponentHosts');
  648. masterComponents.forEach(function (component) {
  649. App.HostComponent.createRecord({
  650. id: component.component + '_' + component.hostName,
  651. componentName: component.component,
  652. host_id: component.hostName
  653. });
  654. if (!hosts[component.hostName].hostComponents) {
  655. hosts[component.hostName].hostComponents = [];
  656. }
  657. hosts[component.hostName].hostComponents.push(component.component + '_' + component.hostName);
  658. });
  659. slaveComponents.forEach(function (component) {
  660. component.hosts.forEach(function (host) {
  661. App.HostComponent.createRecord({
  662. id: component.componentName + '_' + host.hostName,
  663. componentName: component.componentName,
  664. host_id: host.hostName
  665. });
  666. if (!hosts[host.hostName].hostComponents) {
  667. hosts[host.hostName].hostComponents = [];
  668. }
  669. hosts[host.hostName].hostComponents.push(component.componentName + '_' + host.hostName);
  670. });
  671. });
  672. for (var hostName in hosts) {
  673. var host = hosts[hostName];
  674. var disksOverallCapacity = 0;
  675. var diskFree = 0;
  676. host.disk_info.forEach(function(disk) {
  677. disksOverallCapacity += parseFloat(disk.size);
  678. diskFree += parseFloat(disk.available);
  679. });
  680. App.store.load(App.Host,
  681. {
  682. id: host.name,
  683. ip: host.ip,
  684. os_type: host.os_type,
  685. os_arch: host.os_arch,
  686. host_name: host.name,
  687. public_host_name: host.name,
  688. cpu: host.cpu,
  689. memory: host.memory,
  690. disk_info: host.disk_info,
  691. disk_total: disksOverallCapacity / (1024 * 1024),
  692. disk_free: diskFree / (1024 * 1024),
  693. host_components: host.hostComponents
  694. }
  695. )
  696. }
  697. return App.Host.find();
  698. }.property('content.hosts')
  699. });