manage_config_groups_controller.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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 hostsManagement = require('utils/hosts');
  20. var serviceComponents = require('data/service_components');
  21. App.ManageConfigGroupsController = Em.Controller.extend({
  22. name: 'manageConfigGroupsController',
  23. isLoaded: false,
  24. serviceName: null,
  25. configGroups: [],
  26. selectedConfigGroup: null,
  27. selectedHosts: [],
  28. loadedHostsToGroupMap: {},
  29. resortConfigGroup: function() {
  30. var configGroups = Ember.copy(this.get('configGroups'));
  31. if(configGroups.length < 2){
  32. return;
  33. }
  34. var defaultConfigGroup = configGroups.findProperty('isDefault');
  35. configGroups.removeObject(defaultConfigGroup);
  36. var sorted = configGroups.sort(function(configGroupA, configGroupB){
  37. return String(configGroupA.get('name')) >= String(configGroupB.get('name'));
  38. });
  39. sorted = [defaultConfigGroup].concat(sorted);
  40. this.removeObserver('configGroups.@each.name', this, 'resortConfigGroup');
  41. this.set('configGroups', sorted);
  42. this.addObserver('configGroups.@each.name', this, 'resortConfigGroup');
  43. }.observes('configGroups.@each.name'),
  44. loadConfigGroups: function (serviceName) {
  45. this.set('serviceName', serviceName);
  46. App.ajax.send({
  47. name: 'service.load_config_groups',
  48. data: {
  49. serviceName: serviceName
  50. },
  51. sender: this,
  52. success: 'onLoadConfigGroupsSuccess',
  53. error: 'onLoadConfigGroupsError'
  54. });
  55. },
  56. onLoadConfigGroupsSuccess: function (data) {
  57. var loadedHostsToGroupMap = this.get('loadedHostsToGroupMap');
  58. var usedHosts = [];
  59. var unusedHosts = [];
  60. var serviceName = this.get('serviceName');
  61. var defaultConfigGroup = App.ConfigGroup.create({
  62. name: App.Service.DisplayNames[serviceName] + " Default",
  63. description: "Default cluster level " + this.get('serviceName') + " configuration",
  64. isDefault: true,
  65. parentConfigGroup: null,
  66. service: this.get('content'),
  67. configSiteTags: [],
  68. serviceName: serviceName
  69. });
  70. if (data && data.items) {
  71. var groupToTypeToTagMap = {};
  72. var configGroups = [];
  73. data.items.forEach(function (configGroup) {
  74. configGroup = configGroup.ConfigGroup;
  75. var hostNames = configGroup.hosts.mapProperty('host_name');
  76. loadedHostsToGroupMap[configGroup.group_name] = hostNames.slice();
  77. var newConfigGroup = App.ConfigGroup.create({
  78. id: configGroup.id,
  79. name: configGroup.group_name,
  80. description: configGroup.description,
  81. isDefault: false,
  82. parentConfigGroup: defaultConfigGroup,
  83. service: App.Service.find().findProperty('serviceName', configGroup.tag),
  84. hosts: hostNames,
  85. configSiteTags: [],
  86. properties: [],
  87. apiResponse: configGroup
  88. });
  89. usedHosts = usedHosts.concat(newConfigGroup.get('hosts'));
  90. configGroups.push(newConfigGroup);
  91. var newConfigGroupSiteTags = newConfigGroup.get('configSiteTags');
  92. configGroup.desired_configs.forEach(function (config) {
  93. newConfigGroupSiteTags.push(App.ConfigSiteTag.create({
  94. site: config.type,
  95. tag: config.tag
  96. }));
  97. if (!groupToTypeToTagMap[configGroup.group_name]) {
  98. groupToTypeToTagMap[configGroup.group_name] = {}
  99. }
  100. groupToTypeToTagMap[configGroup.group_name][config.type] = config.tag;
  101. });
  102. }, this);
  103. unusedHosts = App.Host.find().mapProperty('hostName');
  104. usedHosts.uniq().forEach(function (host) {
  105. unusedHosts = unusedHosts.without(host);
  106. }, this);
  107. defaultConfigGroup.set('childConfigGroups', configGroups);
  108. defaultConfigGroup.set('hosts', unusedHosts);
  109. this.set('configGroups', [defaultConfigGroup].concat(configGroups));
  110. this.loadProperties(groupToTypeToTagMap);
  111. this.set('isLoaded', true);
  112. }
  113. },
  114. onLoadConfigGroupsError: function () {
  115. console.error('Unable to load config groups for service.');
  116. },
  117. loadProperties: function (groupToTypeToTagMap) {
  118. var typeTagToGroupMap = {};
  119. var urlParams = [];
  120. for (var group in groupToTypeToTagMap) {
  121. var overrideTypeTags = groupToTypeToTagMap[group];
  122. for (var type in overrideTypeTags) {
  123. var tag = overrideTypeTags[type];
  124. typeTagToGroupMap[type + "///" + tag] = group;
  125. urlParams.push('(type=' + type + '&tag=' + tag + ')');
  126. }
  127. }
  128. var params = urlParams.join('|');
  129. if (urlParams.length) {
  130. App.ajax.send({
  131. name: 'config.host_overrides',
  132. sender: this,
  133. data: {
  134. params: params,
  135. typeTagToGroupMap: typeTagToGroupMap
  136. },
  137. success: 'onLoadPropertiesSuccess'
  138. });
  139. }
  140. },
  141. onLoadPropertiesSuccess: function (data, opt, params) {
  142. data.items.forEach(function (configs) {
  143. var typeTagConfigs = [];
  144. App.config.loadedConfigurationsCache[configs.type + "_" + configs.tag] = configs.properties;
  145. var group = params.typeTagToGroupMap[configs.type + "///" + configs.tag];
  146. for (var config in configs.properties) {
  147. typeTagConfigs.push({
  148. name: config,
  149. value: configs.properties[config]
  150. });
  151. }
  152. this.get('configGroups').findProperty('name', group).get('properties').pushObjects(typeTagConfigs);
  153. }, this);
  154. },
  155. showProperties: function () {
  156. var properies = this.get('selectedConfigGroup.propertiesList').htmlSafe();
  157. if (properies) {
  158. App.showAlertPopup(Em.I18n.t('services.service.config_groups_popup.properties'), properies);
  159. }
  160. },
  161. /**
  162. * add hosts to group
  163. * @return {Array}
  164. */
  165. componentsForFilter: function() {
  166. var components = serviceComponents.filterProperty('service_name',this.get('serviceName'));
  167. return components.map(function(component) {
  168. return Em.Object.create({
  169. displayName: component.display_name,
  170. componentName: component.component_name,
  171. selected: false
  172. });
  173. });
  174. }.property('serviceName'),
  175. addHosts: function () {
  176. if (this.get('selectedConfigGroup.isAddHostsDisabled')){
  177. return false;
  178. }
  179. var availableHosts = this.get('selectedConfigGroup.availableHosts');
  180. var popupDescription = {
  181. header: Em.I18n.t('hosts.selectHostsDialog.title'),
  182. dialogMessage: Em.I18n.t('hosts.selectHostsDialog.message').format(App.Service.DisplayNames[this.get('serviceName')])
  183. };
  184. hostsManagement.launchHostsSelectionDialog(availableHosts, [], false, this.get('componentsForFilter'), this.addHostsCallback.bind(this), popupDescription);
  185. },
  186. /**
  187. * add hosts callback
  188. */
  189. addHostsCallback: function (selectedHosts) {
  190. var group = this.get('selectedConfigGroup');
  191. if (selectedHosts) {
  192. var defaultHosts = group.get('parentConfigGroup.hosts');
  193. var configGroupHosts = group.get('hosts');
  194. selectedHosts.forEach(function (hostName) {
  195. configGroupHosts.pushObject(hostName);
  196. defaultHosts.removeObject(hostName);
  197. });
  198. }
  199. },
  200. /**
  201. * delete hosts from group
  202. */
  203. deleteHosts: function () {
  204. if (this.get('isDeleteHostsDisabled')) {
  205. return false;
  206. }
  207. var groupHosts = this.get('selectedConfigGroup.hosts');
  208. var defaultGroupHosts = this.get('selectedConfigGroup.parentConfigGroup.hosts');
  209. this.get('selectedHosts').slice().forEach(function (hostName) {
  210. defaultGroupHosts.pushObject(hostName);
  211. groupHosts.removeObject(hostName);
  212. });
  213. this.set('selectedHosts', []);
  214. },
  215. isDeleteHostsDisabled: function () {
  216. var selectedConfigGroup = this.get('selectedConfigGroup');
  217. if (selectedConfigGroup) {
  218. if (selectedConfigGroup.isDefault || this.get('selectedHosts').length === 0) {
  219. return true;
  220. } else {
  221. return false;
  222. }
  223. }
  224. return true;
  225. }.property('selectedConfigGroup', 'selectedConfigGroup.hosts.length', 'selectedHosts.length'),
  226. /**
  227. * confirm delete config group
  228. */
  229. confirmDelete : function () {
  230. var self = this;
  231. App.showConfirmationPopup(function() {
  232. self.deleteConfigGroup();
  233. });
  234. },
  235. /**
  236. * delete selected config group
  237. */
  238. deleteConfigGroup: function () {
  239. var selectedConfigGroup = this.get('selectedConfigGroup');
  240. if (this.get('isDeleteGroupDisabled')) {
  241. return;
  242. }
  243. App.ajax.send({
  244. name: 'config_groups.delete_config_group',
  245. sender: this,
  246. data: {
  247. id: selectedConfigGroup.get('id')
  248. }
  249. });
  250. //move hosts of group to default group (available hosts)
  251. this.set('selectedHosts', selectedConfigGroup.get('hosts'));
  252. this.deleteHosts();
  253. this.get('configGroups').removeObject(selectedConfigGroup);
  254. delete this.get('loadedHostsToGroupMap')[selectedConfigGroup.get('name')];
  255. this.set('selectedConfigGroup', this.get('configGroups').findProperty('isDefault'));
  256. },
  257. /**
  258. * rename new config group
  259. */
  260. renameConfigGroup: function () {
  261. if(this.get('selectedConfigGroup.isDefault')) {
  262. return;
  263. }
  264. var content = this;
  265. var self = this;
  266. this.renameGroupPopup = App.ModalPopup.show({
  267. primary: Em.I18n.t('ok'),
  268. secondary: Em.I18n.t('common.cancel'),
  269. header: Em.I18n.t('services.service.config_groups.rename_config_group_popup.header'),
  270. bodyClass: Ember.View.extend({
  271. templateName: require('templates/main/service/new_config_group')
  272. }),
  273. configGroupName: "",
  274. content: content,
  275. validate: function () {
  276. var warningMessage = '';
  277. if (self.get('configGroups').mapProperty('name').contains(this.get('configGroupName'))) {
  278. warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  279. }
  280. this.set('warningMessage', warningMessage);
  281. }.observes('configGroupName'),
  282. enablePrimary: function () {
  283. return this.get('configGroupName').length > 0 && !this.get('warningMessage');
  284. }.property('warningMessage', 'configGroupName'),
  285. onPrimary: function () {
  286. if (!this.get('enablePrimary')) {
  287. return false;
  288. }
  289. var copyHsots = this.get('content.loadedHostsToGroupMap')[this.get('content.selectedConfigGroup.name')];
  290. delete this.get('content.loadedHostsToGroupMap')[this.get('content.selectedConfigGroup.name')];
  291. this.get('content.loadedHostsToGroupMap')[this.get('configGroupName')] = copyHsots;
  292. this.get('content.selectedConfigGroup').set('name', this.get('configGroupName'));
  293. this.get('content.selectedConfigGroup').set('description', this.get('configGroupDesc'));
  294. this.get('content.selectedConfigGroup.apiResponse').group_name = this.get('configGroupName');
  295. this.get('content.selectedConfigGroup.apiResponse').description = this.get('configGroupDesc');
  296. var configGroup = {
  297. ConfigGroup: this.get('content.selectedConfigGroup.apiResponse')
  298. };
  299. App.ajax.send({
  300. name: 'config_groups.update_config_group',
  301. sender: this,
  302. data: {
  303. id: this.get('content.selectedConfigGroup.id'),
  304. configGroup: configGroup
  305. }
  306. });
  307. this.hide();
  308. },
  309. onSecondary: function () {
  310. this.hide();
  311. }
  312. });
  313. this.get('renameGroupPopup').set('configGroupName', this.get('selectedConfigGroup.name'));
  314. this.get('renameGroupPopup').set('configGroupDesc', this.get('selectedConfigGroup.description'));
  315. },
  316. /**
  317. * add new config group
  318. */
  319. addConfigGroup: function (isDuplicated) {
  320. isDuplicated = isDuplicated === true ? true : false;
  321. var content = this;
  322. var self = this;
  323. this.addGroupPopup = App.ModalPopup.show({
  324. primary: Em.I18n.t('ok'),
  325. secondary: Em.I18n.t('common.cancel'),
  326. header: Em.I18n.t('services.service.config_groups.add_config_group_popup.header'),
  327. bodyClass: Ember.View.extend({
  328. templateName: require('templates/main/service/new_config_group')
  329. }),
  330. configGroupName: "",
  331. configGroupDesc: "",
  332. content: content,
  333. warningMessage: '',
  334. validate: function () {
  335. var warningMessage = '';
  336. if (self.get('configGroups').mapProperty('name').contains(this.get('configGroupName').trim())) {
  337. warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  338. }
  339. this.set('warningMessage', warningMessage);
  340. }.observes('configGroupName'),
  341. enablePrimary: function () {
  342. return this.get('configGroupName').trim().length > 0 && !this.get('warningMessage');
  343. }.property('warningMessage', 'configGroupName'),
  344. onPrimary: function () {
  345. if (!this.get('enablePrimary')) {
  346. return false;
  347. }
  348. this.get('content').set('configGroupName', this.get('configGroupName').trim());
  349. this.get('content').set('configGroupDesc', this.get('configGroupDesc'));
  350. var desiredConfig = [];
  351. if (isDuplicated) {
  352. this.get('content.selectedConfigGroup.apiResponse.desired_configs').forEach(function(desired_config){
  353. var properties = {};
  354. this.get('content.selectedConfigGroup.properties').forEach(function(property){
  355. properties[property.name] = property.value;
  356. });
  357. desiredConfig.push({
  358. tag: 'version' + (new Date).getTime(),
  359. type: desired_config.type,
  360. properties : properties
  361. })
  362. }, this);
  363. }
  364. self.createNewConfigurationGroup(this.get('configGroupName').trim(),this.get('content.serviceName'),this.get('configGroupDesc'), desiredConfig, this.get('content'));
  365. },
  366. onSecondary: function () {
  367. this.hide();
  368. }
  369. });
  370. },
  371. createNewConfigurationGroup: function(configGroupName, serviceName, configGroupDesc, desiredConfigs, sender) {
  372. App.ajax.send({
  373. name: 'config_groups.create',
  374. sender: sender,
  375. data: {
  376. 'group_name': configGroupName,
  377. 'service_id': serviceName,
  378. 'description': configGroupDesc,
  379. 'desired_configs': desiredConfigs
  380. },
  381. success: 'onAddNewConfigGroup',
  382. error: 'onAddNewConfigGroupError'
  383. });
  384. },
  385. /**
  386. * On successful api resonse for creating new config group
  387. */
  388. onAddNewConfigGroup: function (data,response) {
  389. var defaultConfigGroup = this.get('configGroups').findProperty('isDefault');
  390. var desiredConfigs = jQuery.parseJSON(response.data)[0].ConfigGroup.desired_configs;
  391. var properties = [];
  392. var configSiteTags = [];
  393. if (desiredConfigs && desiredConfigs.length > 0) {
  394. desiredConfigs.forEach(function(configs){
  395. var configSiteTag = App.ConfigSiteTag.create({
  396. site: configs.type,
  397. tag: configs.tag
  398. });
  399. configSiteTags.push(configSiteTag);
  400. });
  401. properties = this.get('selectedConfigGroup.properties');
  402. }
  403. var newConfigGroupData = App.ConfigGroup.create({
  404. id: data.resources[0].ConfigGroup.id,
  405. name: this.get('configGroupName'),
  406. description: this.get('configGroupDesc'),
  407. isDefault: false,
  408. parentConfigGroup: defaultConfigGroup,
  409. service: App.Service.find().findProperty('serviceName', this.get('serviceName')),
  410. hosts: [],
  411. configSiteTags: configSiteTags,
  412. properties: properties
  413. });
  414. this.get('loadedHostsToGroupMap')[newConfigGroupData.get('name')] = [];
  415. defaultConfigGroup.get('childConfigGroups').push(newConfigGroupData);
  416. this.get('configGroups').pushObject(newConfigGroupData);
  417. this.updateConfigGroup(data.resources[0].ConfigGroup.id);
  418. this.addGroupPopup.hide();
  419. },
  420. onAddNewConfigGroupError: function() {
  421. console.warn('Can\'t add configuration group');
  422. },
  423. /**
  424. * update config group apiResponse property
  425. */
  426. updateConfigGroup: function (id) {
  427. App.ajax.send({
  428. name: 'config_groups.get_config_group_by_id',
  429. sender: this,
  430. data: {
  431. 'id': id
  432. },
  433. success: 'successLoadingConfigGroup'
  434. });
  435. },
  436. successLoadingConfigGroup: function (data) {
  437. if(data.ConfigGroup) {
  438. var confGroup = this.get('configGroups').findProperty('id', data.ConfigGroup.id);
  439. confGroup.set('apiResponse', data.ConfigGroup);
  440. }
  441. },
  442. /**
  443. * duplicate config group
  444. */
  445. duplicateConfigGroup: function() {
  446. if(this.get('selectedConfigGroup.isDefault')) {
  447. return;
  448. }
  449. this.addConfigGroup(true);
  450. this.get('addGroupPopup').set('header',Em.I18n.t('services.service.config_groups.duplicate_config_group_popup.header'));
  451. this.get('addGroupPopup').set('configGroupName', this.get('selectedConfigGroup.name') + ' Copy');
  452. this.get('addGroupPopup').set('configGroupDesc', this.get('selectedConfigGroup.description') + ' (Copy)');
  453. },
  454. hostsModifiedConfigGroups: function () {
  455. var groupsToClearHosts = [];
  456. var groupsToSetHosts = [];
  457. var groups = this.get('configGroups');
  458. var loadedHostsToGroupMap = this.get('loadedHostsToGroupMap');
  459. groups.forEach(function (group) {
  460. if (!group.get('isDefault')) {
  461. if (!(JSON.stringify(group.get('hosts').slice().sort()) === JSON.stringify(loadedHostsToGroupMap[group.get('name')].sort()))) {
  462. groupsToClearHosts.push(group);
  463. if (group.get('hosts').length) {
  464. groupsToSetHosts.push(group);
  465. }
  466. }
  467. }
  468. });
  469. return {
  470. toClearHosts: groupsToClearHosts,
  471. toSetHosts: groupsToSetHosts
  472. };
  473. }.property('selectedConfigGroup', 'selectedConfigGroup.hosts.@each'),
  474. isHostsModified: function () {
  475. var modifiedGroups = this.get('hostsModifiedConfigGroups');
  476. return !!(modifiedGroups.toClearHosts.length || modifiedGroups.toSetHosts.length);
  477. }.property('hostsModifiedConfigGroups', 'hostsModifiedConfigGroups.length')
  478. });
  479. App.InstallerManageConfigGroupsController = App.ManageConfigGroupsController.extend({
  480. name: 'installerManageConfigGroupsController',
  481. loadConfigGroups: function (serviceName) {
  482. this.set('serviceName', serviceName);
  483. var loadedHostsToGroupMap = this.get('loadedHostsToGroupMap');
  484. var configGroups = this.copyConfigGroups(App.router.get('wizardStep7Controller.selectedService.configGroups'));
  485. configGroups.forEach(function (configGroup) {
  486. if (!configGroup.get('isDefault')) {
  487. loadedHostsToGroupMap[configGroup.name] = configGroup.hosts.slice();
  488. }
  489. });
  490. this.set('configGroups', configGroups);
  491. this.set('isLoaded', true);
  492. },
  493. /**
  494. * copy config groups to manage popup to give user choice whether or not save changes
  495. * @param originGroups
  496. * @return {Array}
  497. */
  498. copyConfigGroups: function (originGroups) {
  499. var configGroups = [];
  500. var defaultConfigGroup = App.ConfigGroup.create($.extend(true, {},originGroups.findProperty('isDefault')));
  501. originGroups.forEach(function (configGroup) {
  502. if (!configGroup.get('isDefault')) {
  503. var copiedGroup = App.ConfigGroup.create($.extend(true, {}, configGroup));
  504. copiedGroup.set('parentConfigGroup', defaultConfigGroup);
  505. configGroups.pushObject(copiedGroup);
  506. }
  507. });
  508. defaultConfigGroup.set('childConfigGroups', configGroups.slice());
  509. configGroups.pushObject(defaultConfigGroup);
  510. return configGroups;
  511. },
  512. /**
  513. * delete selected config group
  514. */
  515. deleteConfigGroup: function () {
  516. var selectedConfigGroup = this.get('selectedConfigGroup');
  517. if (this.get('isDeleteGroupDisabled')) {
  518. return;
  519. }
  520. //move hosts of group to default group (available hosts)
  521. this.set('selectedHosts', selectedConfigGroup.get('hosts'));
  522. this.deleteHosts();
  523. this.get('configGroups').removeObject(selectedConfigGroup);
  524. delete this.get('loadedHostsToGroupMap')[selectedConfigGroup.get('name')];
  525. this.set('selectedConfigGroup', this.get('configGroups').findProperty('isDefault'));
  526. },
  527. /**
  528. * rename new config group
  529. */
  530. renameConfigGroup: function () {
  531. if(this.get('selectedConfigGroup.isDefault')) {
  532. return;
  533. }
  534. var self = this;
  535. App.ModalPopup.show({
  536. primary: Em.I18n.t('ok'),
  537. secondary: Em.I18n.t('common.cancel'),
  538. header: Em.I18n.t('services.service.config_groups.rename_config_group_popup.header'),
  539. bodyClass: Ember.View.extend({
  540. templateName: require('templates/main/service/new_config_group')
  541. }),
  542. configGroupName: self.get('selectedConfigGroup.name'),
  543. configGroupDesc: self.get('selectedConfigGroup.description'),
  544. warningMessage: '',
  545. validate: function () {
  546. var warningMessage = '';
  547. if (self.get('configGroups').mapProperty('name').contains(this.get('configGroupName'))) {
  548. warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  549. }
  550. this.set('warningMessage', warningMessage);
  551. }.observes('configGroupName'),
  552. enablePrimary: function () {
  553. return this.get('configGroupName').length > 0 && !this.get('warningMessage');
  554. }.property('warningMessage', 'configGroupName'),
  555. onPrimary: function () {
  556. if (!this.get('enablePrimary')) {
  557. return false;
  558. }
  559. var copyHsots = self.get('loadedHostsToGroupMap')[self.get('selectedConfigGroup.name')];
  560. delete self.get('loadedHostsToGroupMap')[self.get('selectedConfigGroup.name')];
  561. self.get('loadedHostsToGroupMap')[this.get('configGroupName')] = copyHsots;
  562. self.set('selectedConfigGroup.name', this.get('configGroupName'));
  563. self.set('selectedConfigGroup.description', this.get('configGroupDesc'));
  564. this.hide();
  565. }
  566. });
  567. },
  568. /**
  569. * add new config group
  570. */
  571. addConfigGroup: function () {
  572. var self = this;
  573. this.addGroupPopup = App.ModalPopup.show({
  574. primary: Em.I18n.t('ok'),
  575. secondary: Em.I18n.t('common.cancel'),
  576. header: Em.I18n.t('services.service.config_groups.add_config_group_popup.header'),
  577. bodyClass: Ember.View.extend({
  578. templateName: require('templates/main/service/new_config_group')
  579. }),
  580. configGroupName: "",
  581. configGroupDesc: "",
  582. warningMessage: '',
  583. validate: function () {
  584. var warningMessage = '';
  585. if (self.get('configGroups').mapProperty('name').contains(this.get('configGroupName'))) {
  586. warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  587. }
  588. this.set('warningMessage', warningMessage);
  589. }.observes('configGroupName'),
  590. enablePrimary: function () {
  591. return this.get('configGroupName').length > 0 && !this.get('warningMessage');
  592. }.property('warningMessage', 'configGroupName'),
  593. onPrimary: function () {
  594. if (!this.get('enablePrimary')) {
  595. return false;
  596. }
  597. var defaultConfigGroup = self.get('configGroups').findProperty('isDefault');
  598. var newConfigGroupData = App.ConfigGroup.create({
  599. id: null,
  600. name: this.get('configGroupName'),
  601. description: this.get('configGroupDesc'),
  602. isDefault: false,
  603. parentConfigGroup: defaultConfigGroup,
  604. service: Em.Object.create({id: self.get('serviceName')}),
  605. hosts: [],
  606. configSiteTags: [],
  607. properties: []
  608. });
  609. self.get('loadedHostsToGroupMap')[newConfigGroupData.get('name')] = [];
  610. self.get('configGroups').pushObject(newConfigGroupData);
  611. defaultConfigGroup.get('childConfigGroups').pushObject(newConfigGroupData);
  612. this.hide();
  613. }
  614. });
  615. }
  616. })