ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vbrodets...@apache.org
Subject git commit: AMBARI-6546. API call for hosts filtered by host_components/HostRoles/component_name returns 400 error.(vbrodetskyi)
Date Mon, 21 Jul 2014 16:16:02 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 566e754e5 -> e793b6c83


AMBARI-6546. API call for hosts filtered by host_components/HostRoles/component_name returns
400 error.(vbrodetskyi)


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

Branch: refs/heads/trunk
Commit: e793b6c83812f3e1712437315e8790397c55311a
Parents: 566e754
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Mon Jul 21 18:24:04 2014 +0300
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Mon Jul 21 18:24:04 2014 +0300

----------------------------------------------------------------------
 .../api/query/ProcessingPredicateVisitor.java   | 15 ++++++++++-
 .../api/query/SubResourcePredicateVisitor.java  | 18 ++++++++++++-
 .../query/ProcessingPredicateVisitorTest.java   | 27 ++++++++++++++++++++
 .../query/SubResourcePredicateVisitorTest.java  | 14 ++++++++++
 4 files changed, 72 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e793b6c8/ambari-server/src/main/java/org/apache/ambari/server/api/query/ProcessingPredicateVisitor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/query/ProcessingPredicateVisitor.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/query/ProcessingPredicateVisitor.java
index a9cd46c..8924840 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/query/ProcessingPredicateVisitor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/query/ProcessingPredicateVisitor.java
@@ -129,7 +129,20 @@ public class ProcessingPredicateVisitor implements PredicateVisitor {
 
   @Override
   public void acceptUnaryPredicate(UnaryPredicate predicate) {
-    lastVisited = predicate;
+    String propertyId = predicate.getPropertyIds().iterator().next();
+    int    index      = propertyId.indexOf("/");
+    String category   = index == -1 ? propertyId : propertyId.substring(0, index);
+
+    Map<String, QueryImpl> subResources = query.ensureSubResources();
+
+    if (subResources.containsKey(category)) {
+      subResourceCategories.add(category);
+      subResourceProperties.add(propertyId);
+      lastVisited = AlwaysPredicate.INSTANCE;
+    }
+    else {
+      lastVisited = predicate;
+    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/e793b6c8/ambari-server/src/main/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitor.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitor.java
index 5ec2f10..ebeae8b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitor.java
@@ -24,6 +24,7 @@ import org.apache.ambari.server.controller.predicate.CategoryPredicate;
 import org.apache.ambari.server.controller.predicate.ComparisonPredicate;
 import org.apache.ambari.server.controller.predicate.PredicateVisitor;
 import org.apache.ambari.server.controller.predicate.UnaryPredicate;
+import org.apache.ambari.server.controller.predicate.NotPredicate;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.utilities.PredicateHelper;
 
@@ -100,7 +101,22 @@ public class SubResourcePredicateVisitor implements PredicateVisitor
{
 
   @Override
   public void acceptUnaryPredicate(UnaryPredicate predicate) {
-    lastVisited = predicate;
+    if (predicate.getPredicate() instanceof ComparisonPredicate) {
+      ComparisonPredicate innerPredicate = (ComparisonPredicate) predicate.getPredicate();
+      String propertyId = innerPredicate.getPropertyId();
+
+      int    index    = propertyId.indexOf("/");
+      String category = index == -1 ? propertyId : propertyId.substring(0, index);
+
+      if(index > -1 && category.equals(this.category)) {
+        // copy and strip off category
+        lastVisited = new NotPredicate(innerPredicate.copy(propertyId.substring(index + 1)));
+      } else {
+        lastVisited = AlwaysPredicate.INSTANCE;
+      }
+    } else {
+      lastVisited = predicate;
+    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/e793b6c8/ambari-server/src/test/java/org/apache/ambari/server/api/query/ProcessingPredicateVisitorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/query/ProcessingPredicateVisitorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/api/query/ProcessingPredicateVisitorTest.java
index 393d5f5..714b16f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/query/ProcessingPredicateVisitorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/query/ProcessingPredicateVisitorTest.java
@@ -17,8 +17,10 @@
  */
 package org.apache.ambari.server.api.query;
 
+import org.apache.ambari.server.api.resources.HostResourceDefinition;
 import org.apache.ambari.server.api.resources.ResourceDefinition;
 import org.apache.ambari.server.api.resources.StackResourceDefinition;
+import org.apache.ambari.server.controller.predicate.AndPredicate;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
@@ -60,6 +62,31 @@ public class ProcessingPredicateVisitorTest {
   }
 
   @Test
+  public void testGetSubResourceForNotPredicate() throws Exception {
+    ResourceDefinition resourceDefinition = new HostResourceDefinition();
+
+    Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
+    mapIds.put(Resource.Type.Host, null);
+
+    //test
+    QueryImpl instance = new QueryImplTest.TestQuery(mapIds, resourceDefinition);
+
+    Predicate notPredicate1 = new PredicateBuilder().not().property("host_components/HostRoles/component_name").
+            equals("ZOOKEEPER_SERVER").toPredicate();
+    Predicate notPredicate2 = new PredicateBuilder().not().property("host_components/HostRoles/component_name").
+            equals("HBASE_MASTER").toPredicate();
+    Predicate andPredicate = new AndPredicate(notPredicate1,notPredicate2);
+
+    ProcessingPredicateVisitor visitor = new ProcessingPredicateVisitor(instance);
+    PredicateHelper.visit(andPredicate, visitor);
+
+    Set<String> categories = visitor.getSubResourceCategories();
+
+    Assert.assertEquals(categories.iterator().next(), "host_components");
+  }
+
+
+  @Test
   public void testGetSubResourceCategories() throws Exception {
     ResourceDefinition resourceDefinition = new StackResourceDefinition();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/e793b6c8/ambari-server/src/test/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitorTest.java
index f6dbdd7..eba80e7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/query/SubResourcePredicateVisitorTest.java
@@ -55,5 +55,19 @@ public class SubResourcePredicateVisitorTest {
     subResourcePredicate = visitor.getSubResourcePredicate();
 
     Assert.assertEquals(new AndPredicate(), subResourcePredicate);
+
+
+    Predicate notPredicate = new PredicateBuilder().not().property("host_components/HostRoles/component_name").
+            equals("ZOOKEEPER_SERVER").toPredicate();
+
+    Predicate expectedNotPredicate = new PredicateBuilder().not().property("HostRoles/component_name").
+            equals("ZOOKEEPER_SERVER").toPredicate();
+
+    visitor = new SubResourcePredicateVisitor("host_components");
+    PredicateHelper.visit(notPredicate, visitor);
+
+    subResourcePredicate = visitor.getSubResourcePredicate();
+
+    Assert.assertEquals(expectedNotPredicate, subResourcePredicate);
   }
 }


Mime
View raw message