Class ElasticAlarmIndexer
- java.lang.Object
-
- org.opennms.features.alarms.history.elastic.ElasticAlarmIndexer
-
- All Implemented Interfaces:
Runnable
,AlarmLifecycleListener
public class ElasticAlarmIndexer extends Object implements AlarmLifecycleListener, Runnable
Indexes alarms in Elasticsearch by listening for alarm state changes via theAlarmLifecycleListener
. In order to avoid blocking the callbacks issued via theAlarmLifecycleListener
interface while we communicate with ES, the callbacks create tasks which are added to a queue. Tasks on this queue are then handled by a worker thread and processed in the same order as which they were added.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_TASK_QUEUE_CAPACITY
static String
INDEX_NAME
-
Constructor Summary
Constructors Constructor Description ElasticAlarmIndexer(com.codahale.metrics.MetricRegistry metrics, io.searchbox.client.JestClient client, TemplateInitializer templateInitializer)
ElasticAlarmIndexer(com.codahale.metrics.MetricRegistry metrics, io.searchbox.client.JestClient client, TemplateInitializer templateInitializer, CacheConfig nodeCacheConfig, int taskQueueCapacity, IndexStrategy indexStrategy, IndexSettings indexSettings)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bulkInsert(List<AlarmDocumentDTO> alarmDocuments)
void
destroy()
void
handleAlarmSnapshot(List<OnmsAlarm> alarms)
Called periodically with a complete set of alarms as present in the database at the given timestamp.void
handleDeletedAlarm(int alarmId, String reductionKey)
Called when an alarm has been deleted.void
handleNewOrUpdatedAlarm(OnmsAlarm alarm)
Called when an alarm has been created or updated.void
init()
void
postHandleAlarmSnapshot()
Called afterAlarmLifecycleListener.handleAlarmSnapshot(java.util.List<org.opennms.netmgt.model.OnmsAlarm>)
has been called on all the listeners, and after the session & transaction used to perform the snapshot has been closed.void
preHandleAlarmSnapshot()
Called before the transaction is opened and the alarms are read for subsequent calls toAlarmLifecycleListener.handleAlarmSnapshot(java.util.List<org.opennms.netmgt.model.OnmsAlarm>)
.void
run()
void
setAlarmReindexDurationMs(long alarmReindexDurationMs)
void
setBatchSize(int batchSize)
void
setBulkRetryCount(int bulkRetryCount)
void
setIndexAllUpdates(boolean indexAllUpdates)
void
setLookbackPeriodMs(long lookbackPeriodMs)
void
setUsePseudoClock(boolean usePseudoClock)
-
-
-
Field Detail
-
DEFAULT_TASK_QUEUE_CAPACITY
public static final int DEFAULT_TASK_QUEUE_CAPACITY
- See Also:
- Constant Field Values
-
INDEX_NAME
public static final String INDEX_NAME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ElasticAlarmIndexer
public ElasticAlarmIndexer(com.codahale.metrics.MetricRegistry metrics, io.searchbox.client.JestClient client, TemplateInitializer templateInitializer)
-
ElasticAlarmIndexer
public ElasticAlarmIndexer(com.codahale.metrics.MetricRegistry metrics, io.searchbox.client.JestClient client, TemplateInitializer templateInitializer, CacheConfig nodeCacheConfig, int taskQueueCapacity, IndexStrategy indexStrategy, IndexSettings indexSettings)
-
-
Method Detail
-
init
public void init()
-
destroy
public void destroy()
-
bulkInsert
public void bulkInsert(List<AlarmDocumentDTO> alarmDocuments) throws PersistenceException, IOException
- Throws:
PersistenceException
IOException
-
preHandleAlarmSnapshot
public void preHandleAlarmSnapshot()
Description copied from interface:AlarmLifecycleListener
Called before the transaction is opened and the alarms are read for subsequent calls toAlarmLifecycleListener.handleAlarmSnapshot(java.util.List<org.opennms.netmgt.model.OnmsAlarm>)
. This can be used to trigger any necessary state tracking to accurately handle the snapshot results.- Specified by:
preHandleAlarmSnapshot
in interfaceAlarmLifecycleListener
-
handleAlarmSnapshot
public void handleAlarmSnapshot(List<OnmsAlarm> alarms)
Description copied from interface:AlarmLifecycleListener
Called periodically with a complete set of alarms as present in the database at the given timestamp. This should be used to synchronize any state to ensure it matches what is currently in the database. Note that it is possible that the *current* state of alarms is different from the state at the time at which the snapshot was taken. Implementations should take this in consideration when performing any state synchronization. This method will be called while the related session & transaction that created the alarm are still open. All of the listeners are invoked serially, so the implementors should avoid blocking when possible.- Specified by:
handleAlarmSnapshot
in interfaceAlarmLifecycleListener
- Parameters:
alarms
- canonical set of alarms in the database
-
postHandleAlarmSnapshot
public void postHandleAlarmSnapshot()
Description copied from interface:AlarmLifecycleListener
Called afterAlarmLifecycleListener.handleAlarmSnapshot(java.util.List<org.opennms.netmgt.model.OnmsAlarm>)
has been called on all the listeners, and after the session & transaction used to perform the snapshot has been closed. This can be used to trigger any necessary post-processing of the results once the related session has been closed. This function may be called immediately after a call toAlarmLifecycleListener.preHandleAlarmSnapshot()
if an error occurred while preparing the snapshot i.e. when opening the transaction.- Specified by:
postHandleAlarmSnapshot
in interfaceAlarmLifecycleListener
-
handleNewOrUpdatedAlarm
public void handleNewOrUpdatedAlarm(OnmsAlarm alarm)
Description copied from interface:AlarmLifecycleListener
Called when an alarm has been created or updated. This method will be called while the related session & transaction that created the alarm are still open. All of the listeners are invoked serially, so the implementors should avoid blocking when possible.- Specified by:
handleNewOrUpdatedAlarm
in interfaceAlarmLifecycleListener
- Parameters:
alarm
- a newly created or updated alarm
-
handleDeletedAlarm
public void handleDeletedAlarm(int alarmId, String reductionKey)
Description copied from interface:AlarmLifecycleListener
Called when an alarm has been deleted. This method will be called while the related session & transaction that created the alarm are still open. All of the listeners are invoked serially, so the implementors should avoid blocking when possible.- Specified by:
handleDeletedAlarm
in interfaceAlarmLifecycleListener
- Parameters:
alarmId
- id of the alarm that was deletedreductionKey
- reduction key of the alarm that was deleted
-
setBulkRetryCount
public void setBulkRetryCount(int bulkRetryCount)
-
setBatchSize
public void setBatchSize(int batchSize)
-
setAlarmReindexDurationMs
public void setAlarmReindexDurationMs(long alarmReindexDurationMs)
-
setLookbackPeriodMs
public void setLookbackPeriodMs(long lookbackPeriodMs)
-
setUsePseudoClock
public void setUsePseudoClock(boolean usePseudoClock)
-
setIndexAllUpdates
public void setIndexAllUpdates(boolean indexAllUpdates)
-
-