Prechádzať zdrojové kódy

AMBARI-6559. Config_groups API does not persist properties_attributes

Srimanth Gunturi 11 rokov pred
rodič
commit
bb79b152fc

+ 17 - 6
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);
         }

+ 53 - 0
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"));
+  }
 }