Updated Branches: refs/heads/trunk 5cac5f308 -> 41013792f
AMBARI-3877 Duplicate config-group action not duplicate configs. (ababiichuk) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/41013792 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/41013792 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/41013792 Branch: refs/heads/trunk Commit: 41013792f5dd7471e5b8568090ccdf280cd5d654 Parents: 5cac5f3 Author: aBabiichuk <[email protected]> Authored: Mon Nov 25 20:49:03 2013 +0200 Committer: aBabiichuk <[email protected]> Committed: Mon Nov 25 20:49:03 2013 +0200 ---------------------------------------------------------------------- .../service/manage_config_groups_controller.js | 67 ++++++++++++++++---- ambari-web/app/utils/ajax.js | 3 +- 2 files changed, 55 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/41013792/ambari-web/app/controllers/main/service/manage_config_groups_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/manage_config_groups_controller.js b/ambari-web/app/controllers/main/service/manage_config_groups_controller.js index 7d7e543..5f7221b 100644 --- a/ambari-web/app/controllers/main/service/manage_config_groups_controller.js +++ b/ambari-web/app/controllers/main/service/manage_config_groups_controller.js @@ -292,7 +292,8 @@ App.ManageConfigGroupsController = Em.Controller.extend({ /** * add new config group */ - addConfigGroup: function () { + addConfigGroup: function (isDuplicated) { + isDuplicated = isDuplicated === true ? true : false; var content = this; var self = this; this.addGroupPopup = App.ModalPopup.show({ @@ -319,16 +320,21 @@ App.ManageConfigGroupsController = Em.Controller.extend({ onPrimary: function () { this.get('content').set('configGroupName', this.get('configGroupName')); this.get('content').set('configGroupDesc', this.get('configGroupDesc')); - App.ajax.send({ - name: 'config_groups.create', - sender: this.get('content'), - data: { - 'group_name': this.get('configGroupName'), - 'service_id': this.get('content.serviceName'), - 'description': this.get('configGroupDesc') - }, - success: 'onAddNewConfigGroup' - }); + var desiredConfig = []; + if (isDuplicated) { + this.get('content.selectedConfigGroup.apiResponse.desired_configs').forEach(function(desired_config){ + var properties = {}; + this.get('content.selectedConfigGroup.properties').forEach(function(property){ + properties[property.name] = property.value; + }); + desiredConfig.push({ + tag: 'version' + (new Date).getTime(), + type: desired_config.type, + properties : properties + }) + }, this); + } + self.createNewConfigurationGroup(this.get('configGroupName'),this.get('content.serviceName'),this.get('configGroupDesc'), desiredConfig, this.get('content')); }, onSecondary: function () { this.hide(); @@ -336,11 +342,40 @@ App.ManageConfigGroupsController = Em.Controller.extend({ }); }, + + createNewConfigurationGroup: function(configGroupName, serviceName, configGroupDesc, desiredConfigs, sender) { + App.ajax.send({ + name: 'config_groups.create', + sender: sender, + data: { + 'group_name': configGroupName, + 'service_id': serviceName, + 'description': configGroupDesc, + 'desired_configs': desiredConfigs + }, + success: 'onAddNewConfigGroup', + error: 'onAddNewConfigGroupError' + }); + }, /** * On successful api resonse for creating new config group */ - onAddNewConfigGroup: function (data) { + onAddNewConfigGroup: function (data,response) { var defaultConfigGroup = this.get('configGroups').findProperty('isDefault'); + var desiredConfigs = jQuery.parseJSON(response.data)[0].ConfigGroup.desired_configs; + var properties = []; + var configSiteTags = []; + if (desiredConfigs && desiredConfigs.length > 0) { + desiredConfigs.forEach(function(configs){ + var configSiteTag = { + site: configs.type, + tag: configs.tag + } + configSiteTags.push(configSiteTag); + }); + properties = this.get('selectedConfigGroup.properties'); + } + var newConfigGroupData = App.ConfigGroup.create({ id: data.resources[0].ConfigGroup.id, name: this.get('configGroupName'), @@ -349,7 +384,8 @@ App.ManageConfigGroupsController = Em.Controller.extend({ parentConfigGroup: defaultConfigGroup, service: App.Service.find().findProperty('serviceName', this.get('serviceName')), hosts: [], - configSiteTags: [] + configSiteTags: configSiteTags, + properties: properties }); this.get('loadedHostsToGroupMap')[newConfigGroupData.get('name')] = []; defaultConfigGroup.get('childConfigGroups').push(newConfigGroupData); @@ -358,6 +394,9 @@ App.ManageConfigGroupsController = Em.Controller.extend({ this.addGroupPopup.hide(); }, + onAddNewConfigGroupError: function() { + console.warn('Can\'t add configuration group'); + }, /** * update config group apiResponse property */ @@ -381,7 +420,7 @@ App.ManageConfigGroupsController = Em.Controller.extend({ * duplicate config group */ duplicateConfigGroup: function() { - this.addConfigGroup(); + this.addConfigGroup(true); this.get('addGroupPopup').set('header',Em.I18n.t('services.service.config_groups.duplicate_config_group_popup.header')); this.get('addGroupPopup').set('configGroupName', this.get('selectedConfigGroup.name') + ' Copy'); this.get('addGroupPopup').set('configGroupDesc', this.get('selectedConfigGroup.description') + ' (Copy)'); http://git-wip-us.apache.org/repos/asf/ambari/blob/41013792/ambari-web/app/utils/ajax.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/ajax.js b/ambari-web/app/utils/ajax.js index 950cfbd..c576f62 100644 --- a/ambari-web/app/utils/ajax.js +++ b/ambari-web/app/utils/ajax.js @@ -1193,7 +1193,8 @@ var urls = { "ConfigGroup": { "group_name": data.group_name, "tag": data.service_id, - "description": data.description + "description": data.description, + "desired_configs": data.desired_configs } }]) }
