You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by tb...@apache.org on 2013/02/28 17:50:06 UTC
svn commit: r1451255 - in /incubator/ambari/trunk: CHANGES.txt
ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java
ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
Author: tbeerbower
Date: Thu Feb 28 16:50:06 2013
New Revision: 1451255
URL: http://svn.apache.org/r1451255
Log:
AMBARI-1523. Ambari API: Resources doesn't always honor partial response fields restrictions.
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1451255&r1=1451254&r2=1451255&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Thu Feb 28 16:50:06 2013
@@ -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)
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java?rev=1451255&r1=1451254&r2=1451255&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java Thu Feb 28 16:50:06 2013
@@ -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) {
Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java?rev=1451255&r1=1451254&r2=1451255&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java Thu Feb 28 16:50:06 2013
@@ -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);
}