Bladeren bron

AMBARI-1523. Ambari API: Resources doesn't always honor partial response fields restrictions.

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1451255 13f79535-47bb-0310-9956-ffa450edef68
Tom Beerbower 12 jaren geleden
bovenliggende
commit
d0c8c7c1df

+ 2 - 0
CHANGES.txt

@@ -387,6 +387,8 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-1523. Ambari API: Resources doesn't always honor partial response fields restrictions. (tbeerbower)
+
  AMBARI-1519. Ambari Web goes back and forth between frozen and usable state
  peridocially on a large cluster. (yusaku)
 

+ 9 - 1
ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java

@@ -94,7 +94,15 @@ public class QueryImpl implements Query {
       // wildcard
       addAllProperties(temporalInfo);
     } else{
-      if (!addPropertyToSubResource(category, name, temporalInfo)){
+      if (addPropertyToSubResource(category, name, temporalInfo)){
+        // add pk/fk properties of the resource to this query
+        Resource.Type resourceType = m_resource.getResourceDefinition().getType();
+        Schema        schema       = getClusterController().getSchema(resourceType);
+
+        for (Resource.Type type : m_resource.getIds().keySet()) {
+          addLocalProperty(schema.getKeyPropertyId(type));
+        }
+      } else {
         String propertyId = PropertyHelper.getPropertyId(category, name.equals("*") ? null : name);
         addLocalProperty(propertyId);
         if (temporalInfo != null) {

+ 14 - 0
ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java

@@ -549,6 +549,10 @@ public class QueryImplTest {
     ResourceInstance subResource = createNiceMock(ResourceInstance.class);
     Schema schema = createNiceMock(Schema.class);
 
+    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
+    mapResourceIds.put(Resource.Type.Service, "serviceName");
+    mapResourceIds.put(Resource.Type.Component, "componentName");
+
     //expectations
     expect(resource.getResourceDefinition()).andReturn(resourceDefinition).anyTimes();
 
@@ -556,7 +560,11 @@ public class QueryImplTest {
 
     expect(m_controller.getSchema(Resource.Type.Service)).andReturn(schema).anyTimes();
 
+    expect(schema.getKeyPropertyId(Resource.Type.Service)).andReturn("serviceName").anyTimes();
+    expect(schema.getKeyPropertyId(Resource.Type.Component)).andReturn("componentName").anyTimes();
+
     expect(resource.getSubResources()).andReturn(Collections.singletonMap("components", subResource)).anyTimes();
+    expect(resource.getIds()).andReturn(mapResourceIds).anyTimes();
 
     //todo: ensure that sub-resource was added.
 
@@ -565,6 +573,12 @@ public class QueryImplTest {
     Query query = new TestQuery(resource, null);
     query.addProperty(null, "components", null);
 
+    // verify that only the key properties of the parent resource have been added to the query
+    Set<String> properties = query.getProperties();
+    assertEquals(2, properties.size());
+    assertTrue(properties.contains("serviceName"));
+    assertTrue(properties.contains("componentName"));
+
     verify(m_controller, resource, resourceDefinition, subResource, schema);
   }