manage_config_groups_controller.js 22 KB

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