ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject ambari git commit: AMBARI-10505. Equals predicate does not work for host component metrics. (swagle)
Date Wed, 15 Apr 2015 20:58:59 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk e9617f7f6 -> f05543d39


AMBARI-10505. Equals predicate does not work for host component metrics. (swagle)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f05543d3
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f05543d3
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f05543d3

Branch: refs/heads/trunk
Commit: f05543d393aed760f49f799a447366d45b3a128b
Parents: e9617f7
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Wed Apr 15 13:16:17 2015 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Wed Apr 15 13:58:56 2015 -0700

----------------------------------------------------------------------
 .../ambari/server/api/query/QueryImpl.java      |  2 +-
 .../ambari/server/api/query/QueryImplTest.java  | 73 ++++++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f05543d3/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java
index 0ab9d07..2319683 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java
@@ -445,7 +445,7 @@ public class QueryImpl implements Query, ResourceInstance {
             new QueryResult(request, queryPredicate, subResourcePredicate, map, new QueryResponseImpl(resourceSet)));
         }
       }
-      clusterController.populateResources(resourceType, providerResourceSet, request, null);
+      clusterController.populateResources(resourceType, providerResourceSet, request, subResourcePredicate);
       subResource.queryForSubResources();
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f05543d3/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
index 5ac91fd..01361d2 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
@@ -23,6 +23,7 @@ package org.apache.ambari.server.api.query;
 import static org.easymock.EasyMock.anyBoolean;
 import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
@@ -301,6 +302,78 @@ public class QueryImplTest {
   }
 
   @Test
+  public void testExecute_SubResourcePropertyPredicate() throws Exception {
+    ResourceDefinition resourceDefinition = new ClusterResourceDefinition();
+
+    Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
+    mapIds.put(Resource.Type.Cluster, "c1");
+    mapIds.put(Resource.Type.Host, "h1");
+
+    ClusterController clusterController = createNiceMock(ClusterController.class);
+    QueryResponse clusterResponse = createNiceMock(QueryResponse.class);
+    QueryResponse hostResponse = createNiceMock(QueryResponse.class);
+    Schema clusterSchema = createNiceMock("ClusterSchema", Schema.class);
+    Schema hostSchema = createNiceMock("HostSchema", Schema.class);
+    Renderer renderer = createNiceMock(Renderer.class);
+    Resource clusterResource = createMock("ClusterResource", Resource.class);
+    Resource hostResource = createMock("HostResource", Resource.class);
+    Set<Resource> clusterResources = Collections.singleton(clusterResource);
+    Set<Resource> hostResources = Collections.singleton(hostResource);
+    Iterable<Resource> iterable = createNiceMock(Iterable.class);
+    Iterator<Resource> iterator = createNiceMock(Iterator.class);
+
+    expect(clusterController.getSchema(Resource.Type.Cluster)).andReturn(clusterSchema).anyTimes();
+    expect(clusterController.getSchema(Resource.Type.Host)).andReturn(hostSchema).anyTimes();
+
+    expect(clusterController.getResources(eq(Resource.Type.Cluster),
+      anyObject(org.apache.ambari.server.controller.spi.Request.class), anyObject(Predicate.class))).
+      andReturn(clusterResponse);
+
+    // Expect this call with a predicate passed down
+    expect(clusterController.getResources(eq(Resource.Type.Host),
+      anyObject(org.apache.ambari.server.controller.spi.Request.class), anyObject(Predicate.class))).
+      andReturn(hostResponse);
+
+    expect(iterable.iterator()).andReturn(iterator).anyTimes();
+    expect(iterator.hasNext()).andReturn(false).anyTimes();
+
+    expect(clusterResponse.getResources()).andReturn(clusterResources).anyTimes();
+    expect(hostResponse.getResources()).andReturn(hostResources).anyTimes();
+    expect(clusterResource.getType()).andReturn(Resource.Type.Cluster).anyTimes();
+    expect(hostResource.getType()).andReturn(Resource.Type.Host).anyTimes();
+
+    expect(clusterSchema.getKeyPropertyId(Resource.Type.Cluster)).andReturn("Clusters/cluster_name").anyTimes();
+    expect(clusterSchema.getKeyTypes()).andReturn(Collections.singleton(Resource.Type.Cluster)).anyTimes();
+    expect(hostSchema.getKeyPropertyId(Resource.Type.Cluster)).andReturn(null).anyTimes();
+    expect(hostSchema.getKeyPropertyId(Resource.Type.Host)).andReturn("Hosts/host_name").anyTimes();
+    expect(hostSchema.getKeyTypes()).andReturn(Collections.singleton(Resource.Type.Host)).anyTimes();
+
+    expect(clusterResource.getPropertyValue("Clusters/cluster_name")).andReturn("c1").anyTimes();
+
+    TreeNode<Set<String>> treeNode = new TreeNodeImpl<Set<String>>(null,
Collections.EMPTY_SET, null);
+    expect(renderer.finalizeProperties(anyObject(TreeNode.class), anyBoolean())).andReturn(treeNode).anyTimes();
+
+    expect(clusterController.getIterable(eq(Resource.Type.Cluster), anyObject(QueryResponse.class),
+      anyObject(org.apache.ambari.server.controller.spi.Request.class), anyObject(Predicate.class),
+      anyObject(PageRequest.class), anyObject(SortRequest.class))).andReturn(iterable).anyTimes();
+
+    replay(clusterController, clusterResponse, clusterSchema, renderer,
+      hostSchema, clusterResource, hostResource, hostResponse, iterable, iterator);
+
+    //test
+    QueryImpl query = new TestQuery(mapIds, resourceDefinition, clusterController);
+    query.setUserPredicate(new PredicateBuilder()
+      .property("hosts/Hosts/host_name").equals("h1").and()
+      .property("metrics/boottime").equals("value").toPredicate());
+    query.setRenderer(renderer);
+
+    query.execute();
+
+    verify(clusterController, clusterResponse, clusterSchema, renderer,
+      hostSchema, clusterResource, hostResource, hostResponse, iterable, iterator);
+  }
+
+  @Test
   public void testExecute_collection_NoSuchResourceException() throws Exception {
     ResourceDefinition resourceDefinition = new ClusterResourceDefinition();
 


Mime
View raw message