Class TriggerBase
- java.lang.Object
-
- org.apache.solr.cloud.autoscaling.TriggerBase
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Runnable
,AutoScaling.Trigger
- Direct Known Subclasses:
IndexSizeTrigger
,MetricTrigger
,NodeAddedTrigger
,NodeLostTrigger
,ScheduledTrigger
,SearchRateTrigger
public abstract class TriggerBase extends Object implements AutoScaling.Trigger
Base class forAutoScaling.Trigger
implementations. It handles state snapshot / restore in ZK.
-
-
Field Summary
Fields Modifier and Type Field Description protected List<TriggerAction>
actions
protected SolrCloudManager
cloudManager
protected boolean
enabled
protected TriggerEventType
eventType
protected boolean
isClosed
protected Map<String,Object>
lastState
protected SolrResourceLoader
loader
protected String
name
protected AtomicReference<AutoScaling.TriggerEventProcessor>
processorRef
protected Map<String,Object>
properties
protected Set<String>
requiredProperties
Set of required property names.protected DistribStateManager
stateManager
protected Set<String>
validProperties
Set of valid property names.protected int
waitForSecond
-
Constructor Summary
Constructors Modifier Constructor Description protected
TriggerBase(TriggerEventType eventType, String name)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
void
configure(SolrResourceLoader loader, SolrCloudManager cloudManager, Map<String,Object> properties)
Called when trigger is created but before it's initialized or scheduled for use.Map<String,Object>
deepCopyState()
Returns an immutable deep copy of this trigger's state, suitible for saving.boolean
equals(Object obj)
List<TriggerAction>
getActions()
Actions to execute when event is fired.TriggerEventType
getEventType()
Event type generated by this trigger.String
getName()
Trigger name.AutoScaling.TriggerEventProcessor
getProcessor()
Get event processor.Map<String,Object>
getProperties()
Trigger properties.Set<String>
getRequiredProperties()
Return a set of required property names supported by this trigger.protected abstract Map<String,Object>
getState()
Prepare and return internal state of this trigger in a format suitable for persisting in ZK.Set<String>
getValidProperties()
Return a set of valid property names supported by this trigger.int
getWaitForSecond()
Number of seconds to wait between fired events ("waitFor" property).int
hashCode()
void
init()
Called before a trigger is scheduled.boolean
isClosed()
Return true when this trigger is closed and cannot be used.boolean
isEnabled()
Returns true if this trigger is enabled.void
restoreState()
Restore internal state of this trigger from ZooKeeper.void
saveState()
Save internal state of this trigger in ZooKeeper.void
setProcessor(AutoScaling.TriggerEventProcessor processor)
Set event processor to call when event is fired.protected abstract void
setState(Map<String,Object> state)
Restore internal state of this trigger from properties retrieved from ZK.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.solr.cloud.autoscaling.AutoScaling.Trigger
restoreState
-
-
-
-
Field Detail
-
name
protected final String name
-
cloudManager
protected SolrCloudManager cloudManager
-
loader
protected SolrResourceLoader loader
-
stateManager
protected DistribStateManager stateManager
-
validProperties
protected final Set<String> validProperties
Set of valid property names. Subclasses may add to this set usingTriggerUtils.validProperties(Set, String...)
-
requiredProperties
protected final Set<String> requiredProperties
Set of required property names. Subclasses may add to this set usingTriggerUtils.requiredProperties(Set, Set, String...)
(required properties are also valid properties).
-
eventType
protected final TriggerEventType eventType
-
waitForSecond
protected int waitForSecond
-
processorRef
protected final AtomicReference<AutoScaling.TriggerEventProcessor> processorRef
-
actions
protected List<TriggerAction> actions
-
enabled
protected boolean enabled
-
isClosed
protected boolean isClosed
-
-
Constructor Detail
-
TriggerBase
protected TriggerBase(TriggerEventType eventType, String name)
-
-
Method Detail
-
getValidProperties
public final Set<String> getValidProperties()
Return a set of valid property names supported by this trigger.
-
getRequiredProperties
public final Set<String> getRequiredProperties()
Return a set of required property names supported by this trigger.
-
configure
public void configure(SolrResourceLoader loader, SolrCloudManager cloudManager, Map<String,Object> properties) throws TriggerValidationException
Description copied from interface:AutoScaling.Trigger
Called when trigger is created but before it's initialized or scheduled for use. This method should also verify that the trigger configuration parameters are correct. It may be called multiple times.- Specified by:
configure
in interfaceAutoScaling.Trigger
properties
- configuration properties- Throws:
TriggerValidationException
- contains details of invalid configuration parameters.
-
init
public void init() throws Exception
Description copied from interface:AutoScaling.Trigger
Called before a trigger is scheduled. Any heavy object creation or initialisation should be done in this method instead of the Trigger's constructor.- Specified by:
init
in interfaceAutoScaling.Trigger
- Throws:
Exception
-
setProcessor
public void setProcessor(AutoScaling.TriggerEventProcessor processor)
Description copied from interface:AutoScaling.Trigger
Set event processor to call when event is fired.- Specified by:
setProcessor
in interfaceAutoScaling.Trigger
-
getProcessor
public AutoScaling.TriggerEventProcessor getProcessor()
Description copied from interface:AutoScaling.Trigger
Get event processor.- Specified by:
getProcessor
in interfaceAutoScaling.Trigger
-
getName
public String getName()
Description copied from interface:AutoScaling.Trigger
Trigger name.- Specified by:
getName
in interfaceAutoScaling.Trigger
-
getEventType
public TriggerEventType getEventType()
Description copied from interface:AutoScaling.Trigger
Event type generated by this trigger.- Specified by:
getEventType
in interfaceAutoScaling.Trigger
-
isEnabled
public boolean isEnabled()
Description copied from interface:AutoScaling.Trigger
Returns true if this trigger is enabled.- Specified by:
isEnabled
in interfaceAutoScaling.Trigger
-
getWaitForSecond
public int getWaitForSecond()
Description copied from interface:AutoScaling.Trigger
Number of seconds to wait between fired events ("waitFor" property).- Specified by:
getWaitForSecond
in interfaceAutoScaling.Trigger
-
getProperties
public Map<String,Object> getProperties()
Description copied from interface:AutoScaling.Trigger
Trigger properties.- Specified by:
getProperties
in interfaceAutoScaling.Trigger
-
getActions
public List<TriggerAction> getActions()
Description copied from interface:AutoScaling.Trigger
Actions to execute when event is fired.- Specified by:
getActions
in interfaceAutoScaling.Trigger
-
isClosed
public boolean isClosed()
Description copied from interface:AutoScaling.Trigger
Return true when this trigger is closed and cannot be used.- Specified by:
isClosed
in interfaceAutoScaling.Trigger
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getState
protected abstract Map<String,Object> getState()
Prepare and return internal state of this trigger in a format suitable for persisting in ZK.- Returns:
- map of internal state properties. Note: values must be supported by
Utils.toJSON(Object)
.
-
setState
protected abstract void setState(Map<String,Object> state)
Restore internal state of this trigger from properties retrieved from ZK.- Parameters:
state
- never null but may be empty.
-
deepCopyState
public Map<String,Object> deepCopyState()
Returns an immutable deep copy of this trigger's state, suitible for saving. This method is public only for tests that wish to do grey-box introspection- See Also:
getState()
- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
saveState
public void saveState()
Description copied from interface:AutoScaling.Trigger
Save internal state of this trigger in ZooKeeper.- Specified by:
saveState
in interfaceAutoScaling.Trigger
-
restoreState
public void restoreState()
Description copied from interface:AutoScaling.Trigger
Restore internal state of this trigger from ZooKeeper.- Specified by:
restoreState
in interfaceAutoScaling.Trigger
-
-