mirror of https://github.com/apache/lucene.git
SOLR-10738: Trigger has an init method which is called before schedule. Actions are init'ed in this method. Fixed NodeLostTriggerTest failures.
This commit is contained in:
parent
fe217668cb
commit
ce7367d54e
|
@ -115,6 +115,12 @@ public class AutoScaling {
|
||||||
public boolean isClosed();
|
public boolean isClosed();
|
||||||
|
|
||||||
public void restoreState(Trigger<E> old);
|
public void restoreState(Trigger<E> old);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
public static class TriggerFactory implements Closeable {
|
||||||
|
|
|
@ -81,6 +81,17 @@ public class NodeAddedTrigger implements AutoScaling.Trigger<NodeAddedTrigger.No
|
||||||
log.debug("NodeAddedTrigger {} instantiated with properties: {}", name, properties);
|
log.debug("NodeAddedTrigger {} instantiated with properties: {}", name, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Override
|
||||||
public void setListener(AutoScaling.TriggerListener<NodeAddedEvent> listener) {
|
public void setListener(AutoScaling.TriggerListener<NodeAddedEvent> listener) {
|
||||||
listenerRef.set(listener);
|
listenerRef.set(listener);
|
||||||
|
|
|
@ -82,6 +82,17 @@ public class NodeLostTrigger implements AutoScaling.Trigger<NodeLostTrigger.Node
|
||||||
this.eventType = AutoScaling.EventType.valueOf(properties.get("event").toString().toUpperCase(Locale.ROOT));
|
this.eventType = AutoScaling.EventType.valueOf(properties.get("event").toString().toUpperCase(Locale.ROOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Override
|
||||||
public void setListener(AutoScaling.TriggerListener<NodeLostEvent> listener) {
|
public void setListener(AutoScaling.TriggerListener<NodeLostEvent> listener) {
|
||||||
listenerRef.set(listener);
|
listenerRef.set(listener);
|
||||||
|
|
|
@ -143,10 +143,7 @@ public class ScheduledTriggers implements Closeable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
List<TriggerAction> actions = newTrigger.getActions();
|
newTrigger.init(); // mark as ready for scheduling
|
||||||
for (TriggerAction action : actions) {
|
|
||||||
action.init(newTrigger.getProperties());
|
|
||||||
}
|
|
||||||
scheduledTrigger.scheduledFuture = scheduledThreadPoolExecutor.scheduleWithFixedDelay(scheduledTrigger, 0, DEFAULT_SCHEDULED_TRIGGER_DELAY_SECONDS, TimeUnit.SECONDS);
|
scheduledTrigger.scheduledFuture = scheduledThreadPoolExecutor.scheduleWithFixedDelay(scheduledTrigger, 0, DEFAULT_SCHEDULED_TRIGGER_DELAY_SECONDS, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,17 @@ public class NodeLostTriggerTest extends SolrCloudTestCase {
|
||||||
NodeLostTrigger trigger = new NodeLostTrigger("node_lost_trigger", props, container);
|
NodeLostTrigger trigger = new NodeLostTrigger("node_lost_trigger", props, container);
|
||||||
trigger.setListener(noFirstRunListener);
|
trigger.setListener(noFirstRunListener);
|
||||||
trigger.run();
|
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.run(); // this run should detect the lost node
|
||||||
trigger.close(); // close the old trigger
|
trigger.close(); // close the old trigger
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue