lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [6/7] lucene-solr:jira/solr-10515: SOLR-10738: Trigger has an init method which is called before schedule. Actions are init'ed in this method. Fixed NodeLostTriggerTest failures.
Date Wed, 24 May 2017 14:56:10 GMT
SOLR-10738: Trigger has an init method which is called before schedule. Actions are init'ed
in this method. Fixed NodeLostTriggerTest failures.


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

Branch: refs/heads/jira/solr-10515
Commit: 0214f2ee901311aa3c782cf70f715ddc03f0991c
Parents: a35852e
Author: Shalin Shekhar Mangar <shalin@apache.org>
Authored: Wed May 24 16:46:25 2017 +0530
Committer: Andrzej Bialecki <ab@apache.org>
Committed: Wed May 24 13:37:48 2017 +0200

----------------------------------------------------------------------
 .../org/apache/solr/cloud/autoscaling/AutoScaling.java  |  6 ++++++
 .../apache/solr/cloud/autoscaling/NodeAddedTrigger.java | 11 +++++++++++
 .../apache/solr/cloud/autoscaling/NodeLostTrigger.java  | 11 +++++++++++
 .../solr/cloud/autoscaling/ScheduledTriggers.java       |  5 +----
 .../solr/cloud/autoscaling/NodeLostTriggerTest.java     | 12 +++++++++++-
 .../solr/cloud/autoscaling/TriggerIntegrationTest.java  |  2 +-
 6 files changed, 41 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0214f2ee/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScaling.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScaling.java b/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScaling.java
index cf6a1e4..2236291 100644
--- a/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScaling.java
+++ b/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScaling.java
@@ -124,6 +124,12 @@ public class AutoScaling {
 
     /** Restore internal state of this trigger from ZooKeeper. */
     void restoreState();
+
+    /**
+     * Called before a trigger is scheduled. Any heavy object creation or initialisation
should
+     * be done in this method instead of the Trigger's constructor.
+     */
+    public void init();
   }
 
   public static class TriggerFactory implements Closeable {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0214f2ee/solr/core/src/java/org/apache/solr/cloud/autoscaling/NodeAddedTrigger.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/autoscaling/NodeAddedTrigger.java b/solr/core/src/java/org/apache/solr/cloud/autoscaling/NodeAddedTrigger.java
index c443826..8ebb6d5 100644
--- a/solr/core/src/java/org/apache/solr/cloud/autoscaling/NodeAddedTrigger.java
+++ b/solr/core/src/java/org/apache/solr/cloud/autoscaling/NodeAddedTrigger.java
@@ -88,6 +88,17 @@ public class NodeAddedTrigger extends TriggerBase {
   }
 
   @Override
+  public void init() {
+    List<Map<String, String>> o = (List<Map<String, String>>) properties.get("actions");
+    if (o != null && !o.isEmpty()) {
+      for (int i = 0; i < o.size(); i++) {
+        Map<String, String> map = o.get(i);
+        actions.get(i).init(map);
+      }
+    }
+  }
+
+  @Override
   public void setListener(AutoScaling.TriggerListener listener) {
     listenerRef.set(listener);
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0214f2ee/solr/core/src/java/org/apache/solr/cloud/autoscaling/NodeLostTrigger.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/autoscaling/NodeLostTrigger.java b/solr/core/src/java/org/apache/solr/cloud/autoscaling/NodeLostTrigger.java
index 981ca3f..525b3c1 100644
--- a/solr/core/src/java/org/apache/solr/cloud/autoscaling/NodeLostTrigger.java
+++ b/solr/core/src/java/org/apache/solr/cloud/autoscaling/NodeLostTrigger.java
@@ -87,6 +87,17 @@ public class NodeLostTrigger extends TriggerBase {
   }
 
   @Override
+  public void init() {
+    List<Map<String, String>> o = (List<Map<String, String>>) properties.get("actions");
+    if (o != null && !o.isEmpty()) {
+      for (int i = 0; i < o.size(); i++) {
+        Map<String, String> map = o.get(i);
+        actions.get(i).init(map);
+      }
+    }
+  }
+
+  @Override
   public void setListener(AutoScaling.TriggerListener listener) {
     listenerRef.set(listener);
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0214f2ee/solr/core/src/java/org/apache/solr/cloud/autoscaling/ScheduledTriggers.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/autoscaling/ScheduledTriggers.java b/solr/core/src/java/org/apache/solr/cloud/autoscaling/ScheduledTriggers.java
index acc9e97..32e674b 100644
--- a/solr/core/src/java/org/apache/solr/cloud/autoscaling/ScheduledTriggers.java
+++ b/solr/core/src/java/org/apache/solr/cloud/autoscaling/ScheduledTriggers.java
@@ -174,10 +174,7 @@ public class ScheduledTriggers implements Closeable {
         return false;
       }
     });
-    List<TriggerAction> actions = newTrigger.getActions();
-    for (TriggerAction action : actions) {
-      action.init(newTrigger.getProperties());
-    }
+    newTrigger.init(); // mark as ready for scheduling
     scheduledTrigger.scheduledFuture = scheduledThreadPoolExecutor.scheduleWithFixedDelay(scheduledTrigger,
0, DEFAULT_SCHEDULED_TRIGGER_DELAY_SECONDS, TimeUnit.SECONDS);
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0214f2ee/solr/core/src/test/org/apache/solr/cloud/autoscaling/NodeLostTriggerTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/NodeLostTriggerTest.java
b/solr/core/src/test/org/apache/solr/cloud/autoscaling/NodeLostTriggerTest.java
index e916ab6..3835f2e 100644
--- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/NodeLostTriggerTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/NodeLostTriggerTest.java
@@ -196,7 +196,17 @@ public class NodeLostTriggerTest extends SolrCloudTestCase {
     NodeLostTrigger trigger = new NodeLostTrigger("node_lost_trigger", props, container);
     trigger.setListener(noFirstRunListener);
     trigger.run();
-    newNode.stop();
+
+    // stop the newly created node
+    List<JettySolrRunner> jettySolrRunners = cluster.getJettySolrRunners();
+    for (int i = 0; i < jettySolrRunners.size(); i++) {
+      JettySolrRunner jettySolrRunner = jettySolrRunners.get(i);
+      if (newNode == jettySolrRunner) {
+        cluster.stopJettySolrRunner(i);
+        break;
+      }
+    }
+
     trigger.run(); // this run should detect the lost node
     trigger.close(); // close the old trigger
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0214f2ee/solr/core/src/test/org/apache/solr/cloud/autoscaling/TriggerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/TriggerIntegrationTest.java
b/solr/core/src/test/org/apache/solr/cloud/autoscaling/TriggerIntegrationTest.java
index 23c1391..715417a 100644
--- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/TriggerIntegrationTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/TriggerIntegrationTest.java
@@ -375,7 +375,7 @@ public class TriggerIntegrationTest extends SolrCloudTestCase {
     NamedList<Object> response = solrClient.request(req);
     assertEquals(response.get("result").toString(), "success");
 
-    if (!actionCreated.await(3, TimeUnit.SECONDS))  {
+    if (!actionCreated.await(10, TimeUnit.SECONDS))  {
       fail("The TriggerAction should have been created by now");
     }
 


Mime
View raw message