manage_config_groups_controller.js 24 KB

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