lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject lucene-solr:feature/autoscaling: added testcase for nodeRole
Date Mon, 29 May 2017 05:19:37 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/feature/autoscaling b1ce4d3b8 -> 4638488ff


added testcase for nodeRole


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/4638488f
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/4638488f
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/4638488f

Branch: refs/heads/feature/autoscaling
Commit: 4638488ff9305636cb3e90b0be0b8a6b8e61a9ff
Parents: b1ce4d3
Author: Noble Paul <noble@apache.org>
Authored: Mon May 29 14:49:29 2017 +0930
Committer: Noble Paul <noble@apache.org>
Committed: Mon May 29 14:49:29 2017 +0930

----------------------------------------------------------------------
 .../solr/cloud/autoscaling/TestPolicyCloud.java | 24 ++++++++++++++++----
 .../solrj/impl/SolrClientDataProvider.java      |  4 +---
 .../apache/solr/common/cloud/SolrZkClient.java  |  7 +++++-
 .../solr/common/cloud/rule/ImplicitSnitch.java  |  7 +++---
 4 files changed, 30 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4638488f/solr/core/src/test/org/apache/solr/cloud/autoscaling/TestPolicyCloud.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/TestPolicyCloud.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/TestPolicyCloud.java
index b1abdec..7520d9a 100644
--- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/TestPolicyCloud.java
+++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/TestPolicyCloud.java
@@ -25,9 +25,13 @@ import org.apache.lucene.util.LuceneTestCase;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.impl.SolrClientDataProvider;
 import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.cloud.OverseerNodePrioritizer;
+import org.apache.solr.cloud.OverseerTaskProcessor;
 import org.apache.solr.cloud.SolrCloudTestCase;
 import org.apache.solr.common.cloud.DocCollection;
+import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.common.util.Utils;
+import org.apache.zookeeper.KeeperException;
 import org.junit.After;
 import org.junit.BeforeClass;
 import org.junit.rules.ExpectedException;
@@ -55,20 +59,30 @@ public class TestPolicyCloud extends SolrCloudTestCase {
   }
 
 
-  public void testDataProvider() throws IOException, SolrServerException {
+  public void testDataProvider() throws IOException, SolrServerException, KeeperException,
InterruptedException {
     CollectionAdminRequest.createCollectionWithImplicitRouter("policiesTest", "conf", "shard1",
2)
         .process(cluster.getSolrClient());
     DocCollection rulesCollection = getCollectionState("policiesTest");
     SolrClientDataProvider provider = new SolrClientDataProvider(cluster.getSolrClient());
-
     Map<String, Object> val = provider.getNodeValues(rulesCollection.getReplicas().get(0).getNodeName(),
Arrays.asList(
         "freedisk",
         "cores",
         "heapUsage",
         "sysLoadAvg"));
     assertTrue(((Number) val.get("cores")).intValue() > 0);
-    assertTrue("freedisk value is "+((Number) val.get("freedisk")).longValue() , ((Number)
val.get("freedisk")).longValue() > 0);
-    assertTrue("heapUsage value is "+((Number) val.get("heapUsage")).longValue() , ((Number)
val.get("heapUsage")).longValue() > 0);
-    assertTrue("sysLoadAvg value is "+((Number) val.get("sysLoadAvg")).longValue() , ((Number)
val.get("sysLoadAvg")).longValue() > 0);
+    assertTrue("freedisk value is " + ((Number) val.get("freedisk")).longValue(), ((Number)
val.get("freedisk")).longValue() > 0);
+    assertTrue("heapUsage value is " + ((Number) val.get("heapUsage")).longValue(), ((Number)
val.get("heapUsage")).longValue() > 0);
+    assertTrue("sysLoadAvg value is " + ((Number) val.get("sysLoadAvg")).longValue(), ((Number)
val.get("sysLoadAvg")).longValue() > 0);
+    String overseerNode = OverseerTaskProcessor.getLeaderNode(cluster.getZkClient());
+    cluster.getSolrClient().request(CollectionAdminRequest.addRole(overseerNode, "overseer"));
+    for (int i = 0; i < 10; i++) {
+      Map<String, Object> data = cluster.getSolrClient().getZkStateReader().getZkClient().getJson(ZkStateReader.ROLES,
true);
+      if (i >= 9 && data == null) {
+        throw new RuntimeException("NO overseer node created");
+      }
+      Thread.sleep(100);
+    }
+    val = provider.getNodeValues(overseerNode, Arrays.asList("nodeRole"));
+    assertEquals("overseer",val.get("nodeRole"));
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4638488f/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientDataProvider.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientDataProvider.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientDataProvider.java
index 41f9cfc..6a49f69 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientDataProvider.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientDataProvider.java
@@ -95,7 +95,7 @@ public class SolrClientDataProvider implements ClusterDataProvider, MapWriter
{
   public Map<String, Object> getNodeValues(String node, Collection<String> tags)
{
     AutoScalingSnitch  snitch = new AutoScalingSnitch();
     ClientSnitchCtx ctx = new ClientSnitchCtx(null, node, snitchSession, solrClient);
-    snitch.getRemoteInfo(node, new HashSet<>(tags), ctx);
+    snitch.getTags(node, new HashSet<>(tags), ctx);
     nodeVsTags.put(node, ctx.getTags());
     return ctx.getTags();
   }
@@ -162,8 +162,6 @@ public class SolrClientDataProvider implements ClusterDataProvider, MapWriter
{
 
   //uses metrics API to get node information
   static class AutoScalingSnitch extends ImplicitSnitch {
-
-
     @Override
     protected void getRemoteInfo(String solrNode, Set<String> requestedTags, SnitchContext
ctx) {
       ClientSnitchCtx snitchContext = (ClientSnitchCtx) ctx;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4638488f/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java
index e25bc1d..aecfc3e 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java
@@ -364,7 +364,12 @@ public class SolrZkClient implements Closeable {
   }
 
   public Map<String, Object> getJson(String path, boolean retryOnConnLoss) throws KeeperException,
InterruptedException {
-    byte[] bytes = getData(path, null, null, retryOnConnLoss);
+    byte[] bytes = null;
+    try {
+      bytes = getData(path, null, null, retryOnConnLoss);
+    } catch (KeeperException.NoNodeException e) {
+      return null;
+    }
     if (bytes != null && bytes.length > 0) {
       return (Map<String, Object>) Utils.fromJSON(bytes);
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4638488f/solr/solrj/src/java/org/apache/solr/common/cloud/rule/ImplicitSnitch.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/rule/ImplicitSnitch.java b/solr/solrj/src/java/org/apache/solr/common/cloud/rule/ImplicitSnitch.java
index 8e596dc..a2af163 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/rule/ImplicitSnitch.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/rule/ImplicitSnitch.java
@@ -64,7 +64,8 @@ public class ImplicitSnitch extends Snitch {
       Matcher hostAndPortMatcher = hostAndPortPattern.matcher(solrNode);
       if (hostAndPortMatcher.find()) ctx.getTags().put(PORT, hostAndPortMatcher.group(2));
     }
-    if (requestedTags.contains(ROLE) || requestedTags.contains(NODEROLE)) fillRole(solrNode,
ctx);
+    if (requestedTags.contains(ROLE)) fillRole(solrNode, ctx, ROLE);
+    if (requestedTags.contains(NODEROLE)) fillRole(solrNode, ctx, NODEROLE);// for new policy
framework
 
     addIpTags(solrNode, requestedTags, ctx);
 
@@ -81,7 +82,7 @@ public class ImplicitSnitch extends Snitch {
     if (params.size() > 0) ctx.invokeRemote(solrNode, params, "org.apache.solr.cloud.rule.ImplicitSnitch",
null);
   }
 
-  private void fillRole(String solrNode, SnitchContext ctx) {
+  private void fillRole(String solrNode, SnitchContext ctx, String key) {
     Map roles = (Map) ctx.retrieve(ZkStateReader.ROLES); // we don't want to hit the ZK for
each node
     // so cache and reuse
     if(roles == null) roles = ctx.getZkJson(ZkStateReader.ROLES);
@@ -91,7 +92,7 @@ public class ImplicitSnitch extends Snitch {
         Map.Entry e = (Map.Entry) o;
         if (e.getValue() instanceof List) {
           if(((List) e.getValue()).contains(solrNode)) {
-            ctx.getTags().put(ROLE, e.getKey());
+            ctx.getTags().put(key, e.getKey());
             break;
           }
         }


Mime
View raw message