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.Triggerimplementations. It handles state snapshot / restore in ZK.
-
-
Field Summary
Fields Modifier and Type Field Description protected List<TriggerAction>actionsprotected SolrCloudManagercloudManagerprotected booleanenabledprotected TriggerEventTypeeventTypeprotected booleanisClosedprotected Map<String,Object>lastStateprotected SolrResourceLoaderloaderprotected Stringnameprotected AtomicReference<AutoScaling.TriggerEventProcessor>processorRefprotected Map<String,Object>propertiesprotected Set<String>requiredPropertiesSet of required property names.protected DistribStateManagerstateManagerprotected Set<String>validPropertiesSet of valid property names.protected intwaitForSecond
-
Constructor Summary
Constructors Modifier Constructor Description protectedTriggerBase(TriggerEventType eventType, String name)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()voidconfigure(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.booleanequals(Object obj)List<TriggerAction>getActions()Actions to execute when event is fired.TriggerEventTypegetEventType()Event type generated by this trigger.StringgetName()Trigger name.AutoScaling.TriggerEventProcessorgetProcessor()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.intgetWaitForSecond()Number of seconds to wait between fired events ("waitFor" property).inthashCode()voidinit()Called before a trigger is scheduled.booleanisClosed()Return true when this trigger is closed and cannot be used.booleanisEnabled()Returns true if this trigger is enabled.voidrestoreState()Restore internal state of this trigger from ZooKeeper.voidsaveState()Save internal state of this trigger in ZooKeeper.voidsetProcessor(AutoScaling.TriggerEventProcessor processor)Set event processor to call when event is fired.protected abstract voidsetState(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.TriggerCalled 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:
configurein interfaceAutoScaling.Triggerproperties- configuration properties- Throws:
TriggerValidationException- contains details of invalid configuration parameters.
-
init
public void init() throws ExceptionDescription copied from interface:AutoScaling.TriggerCalled 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:
initin interfaceAutoScaling.Trigger- Throws:
Exception
-
setProcessor
public void setProcessor(AutoScaling.TriggerEventProcessor processor)
Description copied from interface:AutoScaling.TriggerSet event processor to call when event is fired.- Specified by:
setProcessorin interfaceAutoScaling.Trigger
-
getProcessor
public AutoScaling.TriggerEventProcessor getProcessor()
Description copied from interface:AutoScaling.TriggerGet event processor.- Specified by:
getProcessorin interfaceAutoScaling.Trigger
-
getName
public String getName()
Description copied from interface:AutoScaling.TriggerTrigger name.- Specified by:
getNamein interfaceAutoScaling.Trigger
-
getEventType
public TriggerEventType getEventType()
Description copied from interface:AutoScaling.TriggerEvent type generated by this trigger.- Specified by:
getEventTypein interfaceAutoScaling.Trigger
-
isEnabled
public boolean isEnabled()
Description copied from interface:AutoScaling.TriggerReturns true if this trigger is enabled.- Specified by:
isEnabledin interfaceAutoScaling.Trigger
-
getWaitForSecond
public int getWaitForSecond()
Description copied from interface:AutoScaling.TriggerNumber of seconds to wait between fired events ("waitFor" property).- Specified by:
getWaitForSecondin interfaceAutoScaling.Trigger
-
getProperties
public Map<String,Object> getProperties()
Description copied from interface:AutoScaling.TriggerTrigger properties.- Specified by:
getPropertiesin interfaceAutoScaling.Trigger
-
getActions
public List<TriggerAction> getActions()
Description copied from interface:AutoScaling.TriggerActions to execute when event is fired.- Specified by:
getActionsin interfaceAutoScaling.Trigger
-
isClosed
public boolean isClosed()
Description copied from interface:AutoScaling.TriggerReturn true when this trigger is closed and cannot be used.- Specified by:
isClosedin interfaceAutoScaling.Trigger
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein 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.TriggerSave internal state of this trigger in ZooKeeper.- Specified by:
saveStatein interfaceAutoScaling.Trigger
-
restoreState
public void restoreState()
Description copied from interface:AutoScaling.TriggerRestore internal state of this trigger from ZooKeeper.- Specified by:
restoreStatein interfaceAutoScaling.Trigger
-
-