public class AlertsDAO extends Object implements Cleanable
AlertsDAO
class manages the AlertHistoryEntity
and
AlertCurrentEntity
instances. Each AlertHistoryEntity
is
known as an "alert" that has been triggered and received.
If alert caching is enabled, then updates to AlertCurrentEntity
are
not immediately persisted to JPA. Instead, they are kept in a cache and
periodically flushed. This means that many queries will need to swap in the
cached AlertCurrentEntity
with that returned from the EclipseLink JPA
entity manager.Constructor and Description |
---|
AlertsDAO(Configuration configuration)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
long |
cleanup(TimeBasedCleanupPolicy policy)
Performs the cleanup for the entiries the implementing DAO is responsible for.
|
void |
create(AlertCurrentEntity alert)
Persists a new current alert.
|
void |
create(AlertHistoryEntity alert)
Persists a new alert.
|
AlertSummaryDTO |
findAggregateCounts(long clusterId,
String alertName)
Finds the aggregate counts for an alert name, across all hosts.
|
List<AlertHistoryEntity> |
findAll()
Gets all alerts stored in the database across all clusters.
|
List<AlertCurrentEntity> |
findAll(AlertCurrentRequest request)
Finds all
AlertCurrentEntity that match the provided
AlertCurrentRequest . |
List<AlertHistoryEntity> |
findAll(AlertHistoryRequest request)
Finds all
AlertHistoryEntity that match the provided
AlertHistoryRequest . |
List<AlertHistoryEntity> |
findAll(long clusterId)
Gets all alerts stored in the database for the given cluster.
|
List<AlertHistoryEntity> |
findAll(long clusterId,
Date startDate,
Date endDate)
Gets all alerts stored in the database for the given cluster and that fall
withing the specified date range.
|
List<AlertHistoryEntity> |
findAll(long clusterId,
List<AlertState> alertStates)
Gets all alerts stored in the database for the given cluster that have one
of the specified alert states.
|
AlertHistoryEntity |
findById(long alertId)
Gets an alert with the specified ID.
|
List<AlertCurrentEntity> |
findCurrent()
Gets the current alerts.
|
List<AlertCurrentEntity> |
findCurrentByCluster(long clusterId)
Gets the current alerts for a given cluster.
|
List<AlertCurrentEntity> |
findCurrentByDefinitionId(long definitionId)
Gets the current alerts for the specified definition ID.
|
AlertCurrentEntity |
findCurrentByHostAndName(long clusterId,
String hostName,
String alertName)
Locate the current alert for the provided service and alert name.
|
AlertCurrentEntity |
findCurrentById(long alertId)
Gets a current alert with the specified ID.
|
AlertCurrentEntity |
findCurrentByNameNoHost(long clusterId,
String alertName)
Locate the current alert for the provided service and alert name, but when
host is not set (
IS NULL ). |
List<AlertCurrentEntity> |
findCurrentByService(long clusterId,
String serviceName)
Gets the current alerts for a given service.
|
AlertSummaryDTO |
findCurrentCounts(long clusterId,
String serviceName,
String hostName)
Retrieves the summary information for a particular scope.
|
AlertHostSummaryDTO |
findCurrentHostCounts(long clusterId)
Retrieve the summary alert information for all hosts.
|
Map<String,AlertSummaryDTO> |
findCurrentPerHostCounts(long clusterId)
Retrieves the summary information for all the hosts in the provided cluster.
|
void |
flushCachedEntitiesToJPA()
Writes all cached
AlertCurrentEntity instances to the database and
clears the cache. |
int |
getCount(Predicate predicate)
Gets the total count of all
AlertHistoryEntity rows that match the
specified Predicate . |
AlertCurrentEntity |
merge(AlertCurrentEntity alert)
Merge the speicified current alert with the existing alert in the database.
|
AlertCurrentEntity |
merge(AlertCurrentEntity alert,
boolean updateCacheOnly)
Updates the internal cache of alerts with the specified alert.
|
AlertHistoryEntity |
merge(AlertHistoryEntity alert)
Merge the speicified alert with the existing alert in the database.
|
void |
refresh(AlertCurrentEntity alert)
Refresh the state of the current alert from the database.
|
void |
refresh(AlertHistoryEntity alert)
Refresh the state of the alert from the database.
|
void |
remove(AlertCurrentEntity alert)
Removes the specified current alert from the database.
|
void |
remove(AlertHistoryEntity alert)
Removes the specified alert from the database.
|
void |
removeByDefinitionId(long definitionId)
Removes alert history and current alerts for the specified alert defintiion
ID.
|
int |
removeCurrentByHistoryId(long historyId)
Remove a current alert whose history entry matches the specfied ID.
|
int |
removeCurrentByHost(String hostName)
Remove the current alert that matches the given host.
|
int |
removeCurrentByService(long clusterId,
String serviceName)
Remove the current alert that matches the given service.
|
int |
removeCurrentByServiceComponentHost(long clusterId,
String serviceName,
String componentName,
String hostName)
Remove the current alert that matches the given service, component and
host.
|
int |
removeCurrentDisabledAlerts()
Remove all current alerts that are disabled.
|
@Inject public AlertsDAO(Configuration configuration)
public AlertHistoryEntity findById(long alertId)
alertId
- the ID of the alert to retrieve.null
if none exists.public List<AlertHistoryEntity> findAll()
null
).public List<AlertHistoryEntity> findAll(long clusterId)
clusterId
- the ID of the cluster.null
).public List<AlertHistoryEntity> findAll(long clusterId, List<AlertState> alertStates)
clusterId
- the ID of the cluster.alertStates
- the states to match for the retrieved alerts (not null
).public List<AlertHistoryEntity> findAll(long clusterId, Date startDate, Date endDate)
clusterId
- the ID of the cluster.startDate
- the date that the earliest entry must occur after, normalized to
UTC, or null
for all entries that occur before the given
end date.endDate
- the date that the latest entry must occur before, normalized to
UTC, or null
for all entries that occur after the given
start date.public List<AlertHistoryEntity> findAll(AlertHistoryRequest request)
AlertHistoryEntity
that match the provided
AlertHistoryRequest
. This method will make JPA do the heavy lifting
of providing a slice of the result set.request
- public List<AlertCurrentEntity> findAll(AlertCurrentRequest request)
AlertCurrentEntity
that match the provided
AlertCurrentRequest
. This method will make JPA do the heavy lifting
of providing a slice of the result set.request
- public int getCount(Predicate predicate)
AlertHistoryEntity
rows that match the
specified Predicate
.predicate
- the predicate to apply, or null
for none.public List<AlertCurrentEntity> findCurrent()
null
).public AlertCurrentEntity findCurrentById(long alertId)
alertId
- the ID of the alert to retrieve.null
if none exists.public List<AlertCurrentEntity> findCurrentByDefinitionId(long definitionId)
definitionId
- the ID of the definition to retrieve current alerts for.null
).public List<AlertCurrentEntity> findCurrentByCluster(long clusterId)
null
).public AlertSummaryDTO findCurrentCounts(long clusterId, String serviceName, String hostName)
clusterId
- the cluster idserviceName
- the service name. Use null
to not filter on service.hostName
- the host name. Use null
to not filter on host.public Map<String,AlertSummaryDTO> findCurrentPerHostCounts(long clusterId)
clusterId
- the cluster idpublic AlertHostSummaryDTO findCurrentHostCounts(long clusterId)
findCurrentCounts(long, String, String)
since this will
return only alerts related to hosts and those values will be the total
number of hosts affected, not the total number of alerts.clusterId
- the cluster idpublic List<AlertCurrentEntity> findCurrentByService(long clusterId, String serviceName)
null
).public AlertCurrentEntity findCurrentByHostAndName(long clusterId, String hostName, String alertName)
Configuration.isAlertCacheEnabled()
.clusterId
- the cluster idhostName
- the name of the host (not null
).alertName
- the name of the alert (not null
).null
if not foundpublic void removeByDefinitionId(long definitionId)
EntityManager.clear()
when completed since the
JPQL statement will remove entries without going through the EM.definitionId
- the ID of the definition to remove.public int removeCurrentByHistoryId(long historyId)
historyId
- the ID of the history entry.public int removeCurrentDisabledAlerts()
public int removeCurrentByService(long clusterId, String serviceName)
This method will also fire an AggregateAlertRecalculateEvent
in
order to recalculate all aggregates.
clusterId
- the ID of the cluster.serviceName
- the name of the service that the current alerts are being removed
for (not null
).public int removeCurrentByHost(String hostName)
This method will also fire an AggregateAlertRecalculateEvent
in
order to recalculate all aggregates.
hostName
- the name of the host that the current alerts are being removed for
(not null
).public int removeCurrentByServiceComponentHost(long clusterId, String serviceName, String componentName, String hostName)
This method will also fire an AggregateAlertRecalculateEvent
in
order to recalculate all aggregates.
clusterId
- the ID of the cluster.serviceName
- the name of the service that the current alerts are being removed
for (not null
).componentName
- the name of the component that the current alerts are being
removed for (not null
).hostName
- the name of the host that the current alerts are being removed for
(not null
).public void create(AlertHistoryEntity alert)
alert
- the alert to persist (not null
).public void refresh(AlertHistoryEntity alert)
alert
- the alert to refresh (not null
).public AlertHistoryEntity merge(AlertHistoryEntity alert)
alert
- the alert to merge (not null
).null
).public void remove(AlertHistoryEntity alert)
alert
- the alert to remove.public void create(AlertCurrentEntity alert)
alert
- the current alert to persist (not null
).public void refresh(AlertCurrentEntity alert)
alert
- the current alert to refresh (not null
).public AlertCurrentEntity merge(AlertCurrentEntity alert)
alert
- the current alert to merge (not null
).null
).public AlertCurrentEntity merge(AlertCurrentEntity alert, boolean updateCacheOnly)
merge(AlertCurrentEntity)
, this is not transactional and only
updates the cache.
The alert should already exist in JPA - this is mainly to update the text
and timestamp.alert
- the alert to update in the cache (not null
).updateCacheOnly
- if true
, then only the cache is updated and not JPA.Configuration.isAlertCacheEnabled()
public void remove(AlertCurrentEntity alert)
alert
- the current alert to remove.public AlertSummaryDTO findAggregateCounts(long clusterId, String alertName)
clusterId
- the cluster idalertName
- the name of the alert to find the aggregatepublic AlertCurrentEntity findCurrentByNameNoHost(long clusterId, String alertName)
IS NULL
). This method will first consult the cache
if configured with Configuration.isAlertCacheEnabled()
.clusterId
- the cluster idalertName
- the name of the alertnull
if not foundpublic void flushCachedEntitiesToJPA()
AlertCurrentEntity
instances to the database and
clears the cache.public long cleanup(TimeBasedCleanupPolicy policy)
Cleanable
Copyright © 2022 Apache Software Foundation. All rights reserved.