Repository: ambari Updated Branches: refs/heads/branch-2.6 e7e58bbf4 -> 1a44c51db
AMBARI-21922. Allow SERVER Type Alerts To Run For Any Service/Component (amagyar) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1a44c51d Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1a44c51d Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1a44c51d Branch: refs/heads/branch-2.6 Commit: 1a44c51db62b6d806e9d5e6c25353d828ac27edd Parents: e7e58bb Author: Attila Magyar <amag...@hortonworks.com> Authored: Tue Sep 12 15:02:05 2017 +0200 Committer: Attila Magyar <amag...@hortonworks.com> Committed: Tue Sep 12 15:02:38 2017 +0200 ---------------------------------------------------------------------- .../server/orm/dao/AlertDefinitionDAO.java | 13 +++++++++++++ .../orm/entities/AlertDefinitionEntity.java | 4 ++-- .../services/AmbariServerAlertService.java | 20 ++++---------------- .../server/orm/dao/AlertDefinitionDAOTest.java | 6 ++++++ 4 files changed, 25 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/1a44c51d/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java index c3e3a9f..495398b 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java @@ -37,6 +37,7 @@ import org.apache.ambari.server.orm.entities.AlertGroupEntity; import org.apache.ambari.server.state.alert.AlertDefinition; import org.apache.ambari.server.state.alert.AlertDefinitionFactory; import org.apache.ambari.server.state.alert.Scope; +import org.apache.ambari.server.state.alert.SourceType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -308,6 +309,18 @@ public class AlertDefinitionDAO { } /** + * @return all definitions with the given sourceType + */ + @RequiresSession + public List<AlertDefinitionEntity> findBySourceType(Long clusterId, SourceType sourceType) { + return daoUtils.selectList( + entityManagerProvider.get() + .createNamedQuery("AlertDefinitionEntity.findBySourceType", AlertDefinitionEntity.class) + .setParameter("clusterId", clusterId) + .setParameter("sourceType", sourceType)); + } + + /** * Persists a new alert definition, also creating the associated * {@link AlertGroupEntity} relationship for the definition's service default * group. Fires an {@link AlertDefinitionRegistrationEvent}. http://git-wip-us.apache.org/repos/asf/ambari/blob/1a44c51d/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java index 0eebf4b..d944574 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java @@ -72,8 +72,8 @@ import org.apache.ambari.server.state.alert.SourceType; @NamedQuery(name = "AlertDefinitionEntity.findByService", query = "SELECT ad FROM AlertDefinitionEntity ad WHERE ad.serviceName = :serviceName AND ad.clusterId = :clusterId"), @NamedQuery(name = "AlertDefinitionEntity.findByServiceAndComponent", query = "SELECT ad FROM AlertDefinitionEntity ad WHERE ad.serviceName = :serviceName AND ad.componentName = :componentName AND ad.clusterId = :clusterId"), @NamedQuery(name = "AlertDefinitionEntity.findByServiceMaster", query = "SELECT ad FROM AlertDefinitionEntity ad WHERE ad.serviceName IN :services AND ad.scope = :scope AND ad.clusterId = :clusterId AND ad.componentName IS NULL"), - @NamedQuery(name = "AlertDefinitionEntity.findByIds", query = "SELECT ad FROM AlertDefinitionEntity ad WHERE ad.definitionId IN :definitionIds")}) - + @NamedQuery(name = "AlertDefinitionEntity.findByIds", query = "SELECT ad FROM AlertDefinitionEntity ad WHERE ad.definitionId IN :definitionIds"), + @NamedQuery(name = "AlertDefinitionEntity.findBySourceType", query = "SELECT ad FROM AlertDefinitionEntity ad WHERE ad.clusterId = :clusterId AND ad.sourceType = :sourceType")}) public class AlertDefinitionEntity { @Id http://git-wip-us.apache.org/repos/asf/ambari/blob/1a44c51d/ambari-server/src/main/java/org/apache/ambari/server/state/services/AmbariServerAlertService.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/services/AmbariServerAlertService.java b/ambari-server/src/main/java/org/apache/ambari/server/state/services/AmbariServerAlertService.java index 85fd92a..39c83bb 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/services/AmbariServerAlertService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/services/AmbariServerAlertService.java @@ -113,28 +113,18 @@ public class AmbariServerAlertService extends AbstractScheduledService { /** * {@inheritDoc} * <p/> - * Loads all of the {@link Components#AMBARI_SERVER} definitions and schedules + * Loads all of the definitions with SERVER source type and schedules * the ones that are enabled. */ @Override protected void startUp() throws Exception { Map<String, Cluster> clusterMap = m_clustersProvider.get().getClusters(); for (Cluster cluster : clusterMap.values()) { - List<AlertDefinitionEntity> entities = m_dao.findByServiceComponent( - cluster.getClusterId(), Services.AMBARI.name(), - Components.AMBARI_SERVER.name()); - - for (AlertDefinitionEntity entity : entities) { + for (AlertDefinitionEntity entity : m_dao.findBySourceType(cluster.getClusterId(), SourceType.SERVER)) { // don't schedule disabled alert definitions if (!entity.getEnabled()) { continue; } - - SourceType sourceType = entity.getSourceType(); - if (sourceType != SourceType.SERVER) { - continue; - } - // schedule the Runnable for the definition scheduleRunnable(entity); } @@ -152,10 +142,8 @@ public class AmbariServerAlertService extends AbstractScheduledService { protected void runOneIteration() throws Exception { Map<String, Cluster> clusterMap = m_clustersProvider.get().getClusters(); for (Cluster cluster : clusterMap.values()) { - // get all of the cluster alerts for AMBARI/AMBARI_SERVER - List<AlertDefinitionEntity> entities = m_dao.findByServiceComponent( - cluster.getClusterId(), Services.AMBARI.name(), - Components.AMBARI_SERVER.name()); + // get all of the cluster alerts with SERVER source type + List<AlertDefinitionEntity> entities = m_dao.findBySourceType(cluster.getClusterId(), SourceType.SERVER); // for each alert, check to see if it's scheduled correctly for (AlertDefinitionEntity entity : entities) { http://git-wip-us.apache.org/repos/asf/ambari/blob/1a44c51d/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java index 5669bb8..b01877a 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java @@ -280,6 +280,12 @@ public class AlertDefinitionDAOTest { } @Test + public void testFindBySourceType() throws Exception { + assertEquals(15, dao.findBySourceType(clusterId, SourceType.SCRIPT).size()); + assertEquals(0, dao.findBySourceType(clusterId, SourceType.METRIC).size()); + } + + @Test public void testRefresh() { }