You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by am...@apache.org on 2017/09/12 11:14:03 UTC

ambari git commit: AMBARI-21922. Allow SERVER Type Alerts To Run For Any Service/Component (amagyar)

Repository: ambari
Updated Branches:
  refs/heads/trunk c241b9a02 -> 252e9898c


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/252e9898
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/252e9898
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/252e9898

Branch: refs/heads/trunk
Commit: 252e9898c7e68a94924f63549b45af528d15ad14
Parents: c241b9a
Author: Attila Magyar <am...@hortonworks.com>
Authored: Tue Sep 12 13:12:37 2017 +0200
Committer: Attila Magyar <am...@hortonworks.com>
Committed: Tue Sep 12 13:13:51 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/252e9898/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 d71429c..cda03f3 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/252e9898/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 de203be..2f4941b 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/252e9898/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 b8058c8..f5d811d 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/252e9898/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 33d9b3d..d559e0c 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
@@ -279,6 +279,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() {
   }