You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sr...@apache.org on 2014/07/22 19:59:44 UTC
git commit: AMBARI-6559. Config_groups API does not persist
properties_attributes
Repository: ambari
Updated Branches:
refs/heads/trunk e3a93a1db -> bb79b152f
AMBARI-6559. Config_groups API does not persist properties_attributes
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/bb79b152
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/bb79b152
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/bb79b152
Branch: refs/heads/trunk
Commit: bb79b152fccf3b26cd8a2e001180036886a93325
Parents: e3a93a1
Author: Srimanth Gunturi <sg...@hortonworks.com>
Authored: Mon Jul 21 17:21:20 2014 -0700
Committer: Srimanth Gunturi <sg...@hortonworks.com>
Committed: Tue Jul 22 10:32:42 2014 -0700
----------------------------------------------------------------------
.../internal/ConfigGroupResourceProvider.java | 23 ++++++---
.../ConfigGroupResourceProviderTest.java | 53 ++++++++++++++++++++
2 files changed, 70 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/bb79b152/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
index d455526..7948f56 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
@@ -547,7 +547,7 @@ public class ConfigGroupResourceProvider extends
}
@SuppressWarnings("unchecked")
- private ConfigGroupRequest getConfigGroupRequest(Map<String, Object> properties) {
+ ConfigGroupRequest getConfigGroupRequest(Map<String, Object> properties) {
Object groupIdObj = properties.get(CONFIGGROUP_ID_PROPERTY_ID);
Long groupId = null;
if (groupIdObj != null) {
@@ -599,20 +599,31 @@ public class ConfigGroupResourceProvider extends
.CONFIGURATION_CONFIG_TAG_PROPERTY_ID);
Map<String, String> configProperties = new HashMap<String, String>();
+ Map<String, Map<String, String>> configAttributes = new HashMap<String, Map<String, String>>();
for (Map.Entry<String, Object> entry : configMap.entrySet()) {
String propertyCategory = PropertyHelper.getPropertyCategory(entry.getKey());
- if (propertyCategory != null
- && propertyCategory.equals("properties")
- && null != entry.getValue()) {
- configProperties.put(PropertyHelper.getPropertyName(entry.getKey()),
- entry.getValue().toString());
+ if (propertyCategory != null && entry.getValue() != null) {
+ if ("properties".equals(propertyCategory)) {
+ configProperties.put(PropertyHelper.getPropertyName(entry.getKey()),
+ entry.getValue().toString());
+ } else if ("properties_attributes".equals(PropertyHelper.getPropertyCategory(propertyCategory))) {
+ String attributeName = PropertyHelper.getPropertyName(propertyCategory);
+ if (!configAttributes.containsKey(attributeName)) {
+ configAttributes.put(attributeName, new HashMap<String, String>());
+ }
+ Map<String, String> attributeValues
+ = configAttributes.get(attributeName);
+ attributeValues.put(PropertyHelper.getPropertyName(entry.getKey()),
+ entry.getValue().toString());
+ }
}
}
Config config = new ConfigImpl(type);
config.setVersionTag(tag);
config.setProperties(configProperties);
+ config.setPropertiesAttributes(configAttributes);
configurations.put(config.getType(), config);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/bb79b152/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
index e64819c..c8c905a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
@@ -21,6 +21,7 @@ import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.ConfigGroupNotFoundException;
import org.apache.ambari.server.ObjectNotFoundException;
import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.ConfigGroupRequest;
import org.apache.ambari.server.controller.ConfigGroupResponse;
import org.apache.ambari.server.controller.RequestStatusResponse;
import org.apache.ambari.server.controller.spi.NoSuchResourceException;
@@ -524,4 +525,56 @@ public class ConfigGroupResourceProviderTest {
verify(managementController, clusters, cluster);
}
+
+ @Test
+ public void testGetConfigGroupRequest_populatesConfigAttributes() throws Exception {
+ AmbariManagementController managementController = createMock(AmbariManagementController.class);
+ ConfigGroupResourceProvider resourceProvider = getConfigGroupResourceProvider
+ (managementController);
+
+ Set<Map<String, String>> desiredConfigProperties = new HashSet<Map<String, String>>();
+ Map<String, String> desiredConfig1 = new HashMap<String, String>();
+ desiredConfig1.put("tag", "version2");
+ desiredConfig1.put("type", "type1");
+ desiredConfig1.put("properties/key1", "value1");
+ desiredConfig1.put("properties/key2", "value2");
+ desiredConfig1.put("properties_attributes/attr1/key1", "true");
+ desiredConfig1.put("properties_attributes/attr1/key2", "false");
+ desiredConfig1.put("properties_attributes/attr2/key1", "15");
+ desiredConfigProperties.add(desiredConfig1);
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put("ConfigGroup/hosts", new HashMap<String, String>(){{put("host_name", "ambari1");}});
+ properties.put("ConfigGroup/cluster_name", "c");
+ properties.put("ConfigGroup/desired_configs", desiredConfigProperties);
+
+ ConfigGroupRequest request = resourceProvider.getConfigGroupRequest(properties);
+
+ assertNotNull(request);
+ Map<String, Config> configMap = request.getConfigs();
+ assertNotNull(configMap);
+ assertEquals(1, configMap.size());
+ assertTrue(configMap.containsKey("type1"));
+ Config config = configMap.get("type1");
+ assertEquals("type1", config.getType());
+ Map<String, String> configProperties = config.getProperties();
+ assertNotNull(configProperties);
+ assertEquals(2, configProperties.size());
+ assertEquals("value1", configProperties.get("key1"));
+ assertEquals("value2", configProperties.get("key2"));
+ Map<String, Map<String, String>> configAttributes = config.getPropertiesAttributes();
+ assertNotNull(configAttributes);
+ assertEquals(2, configAttributes.size());
+ assertTrue(configAttributes.containsKey("attr1"));
+ Map<String, String> attr1 = configAttributes.get("attr1");
+ assertNotNull(attr1);
+ assertEquals(2, attr1.size());
+ assertEquals("true", attr1.get("key1"));
+ assertEquals("false", attr1.get("key2"));
+ assertTrue(configAttributes.containsKey("attr2"));
+ Map<String, String> attr2 = configAttributes.get("attr2");
+ assertNotNull(attr2);
+ assertEquals(1, attr2.size());
+ assertEquals("15", attr2.get("key1"));
+ }
}