Kaynağa Gözat

AMBARI-7673 - Alerts: Service-level Definitions Should Be Processed by the Service Master (jonathanhurley)

Jonathan Hurley 10 yıl önce
ebeveyn
işleme
f702bb529d

+ 1 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java

@@ -567,6 +567,7 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
     }
 
     Set<String> hostNames = alertDefinitionHash.getAssociatedHosts(cluster,
+        entity.getSourceType(),
         entity.getDefinitionName(), entity.getServiceName(),
         entity.getComponentName());
 

+ 26 - 8
ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertDefinitionHash.java

@@ -263,7 +263,8 @@ public class AlertDefinitionHash {
 
   /**
    * Invalidate the hashes of any host that would be affected by the specified
-   * definition.
+   * definition. If the definition is an {@link SourceType#AGGREGATE}, this will
+   * return an empty set since aggregates do not affect hosts.
    *
    * @param definition
    *          the definition to use to find the hosts to invlidate (not
@@ -273,13 +274,15 @@ public class AlertDefinitionHash {
    */
   public Set<String> invalidateHosts(AlertDefinitionEntity definition) {
     return invalidateHosts(definition.getClusterId(),
+        definition.getSourceType(),
         definition.getDefinitionName(), definition.getServiceName(),
         definition.getComponentName());
   }
 
   /**
    * Invalidate the hashes of any host that would be affected by the specified
-   * definition.
+   * definition. If the definition is an {@link SourceType#AGGREGATE}, this will
+   * return an empty set since aggregates do not affect hosts.
    *
    * @param definition
    *          the definition to use to find the hosts to invlidate (not
@@ -288,16 +291,20 @@ public class AlertDefinitionHash {
    *         {@code null}).
    */
   public Set<String> invalidateHosts(AlertDefinition definition) {
-    return invalidateHosts(definition.getClusterId(), definition.getName(),
+    return invalidateHosts(definition.getClusterId(),
+        definition.getSource().getType(), definition.getName(),
         definition.getServiceName(), definition.getComponentName());
   }
 
   /**
    * Invalidate the hashes of any host that would be affected by the specified
-   * definition.
+   * definition. If the definition is an {@link SourceType#AGGREGATE}, this will
+   * return an empty set since aggregates do not affect hosts.
    *
    * @param clusterId
    *          the cluster ID
+   * @param definitionSourceType
+   *          the type of alert definition
    * @param definitionName
    *          the definition unique name.
    * @param definitionServiceName
@@ -307,7 +314,8 @@ public class AlertDefinitionHash {
    * @return the hosts that were invalidated, or an empty set (never
    *         {@code null}).
    */
-  public Set<String> invalidateHosts(long clusterId, String definitionName,
+  public Set<String> invalidateHosts(long clusterId,
+      SourceType definitionSourceType, String definitionName,
       String definitionServiceName, String definitionComponentName) {
 
     Cluster cluster = null;
@@ -330,8 +338,10 @@ public class AlertDefinitionHash {
     }
 
     // determine which hosts in the cluster would be affected by a change
-    // to the specified definition
-    Set<String> affectedHosts = getAssociatedHosts(cluster, definitionName,
+    // to the specified definition; pass in the definition source type
+    // to check for AGGREGATE
+    Set<String> affectedHosts = getAssociatedHosts(cluster,
+        definitionSourceType, definitionName,
         definitionServiceName, definitionComponentName);
 
     // invalidate all returned hosts
@@ -347,6 +357,9 @@ public class AlertDefinitionHash {
    * returned is expected to be capable of running the alert. A change to the
    * definition would entail contacting each returned host and invalidating
    * their current alert definitions.
+   * <p/>
+   * If the definition is an {@link SourceType#AGGREGATE}, this will return an
+   * empty set since aggregates do not affect hosts.
    *
    * @param cluster
    * @param definitionName
@@ -354,9 +367,14 @@ public class AlertDefinitionHash {
    * @param definitionComponentName
    * @return a set of all associated hosts or an empty set, never {@code null}.
    */
-  public Set<String> getAssociatedHosts(Cluster cluster, String definitionName,
+  public Set<String> getAssociatedHosts(Cluster cluster,
+      SourceType definitionSourceType, String definitionName,
       String definitionServiceName, String definitionComponentName) {
 
+    if (definitionSourceType == SourceType.AGGREGATE) {
+      return Collections.emptySet();
+    }
+
     Map<String, Host> hosts = null;
     String clusterName = cluster.getClusterName();
     Set<String> affectedHosts = new HashSet<String>();

+ 15 - 0
ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertDefinitionHashTest.java

@@ -50,6 +50,7 @@ import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.alert.AlertDefinition;
 import org.apache.ambari.server.state.alert.AlertDefinitionHash;
 import org.apache.ambari.server.state.alert.Scope;
+import org.apache.ambari.server.state.alert.SourceType;
 import org.apache.commons.codec.binary.Hex;
 import org.easymock.EasyMock;
 import org.junit.After;
@@ -85,6 +86,7 @@ public class AlertDefinitionHashTest extends TestCase {
    */
   @Override
   @Before
+  @SuppressWarnings("unchecked")
   protected void setUp() throws Exception {
     super.setUp();
 
@@ -327,6 +329,19 @@ public class AlertDefinitionHashTest extends TestCase {
     assertFalse(m_hash.isHashCached("foo", HOSTNAME));
   }
 
+  @Test
+  public void testAggregateIgnored() {
+    Set<String> associatedHosts = m_hash.getAssociatedHosts(m_mockCluster,
+        SourceType.AGGREGATE, "definitionName", "HDFS", null);
+
+    assertEquals(0, associatedHosts.size());
+
+    associatedHosts = m_hash.getAssociatedHosts(m_mockCluster, SourceType.PORT,
+        "definitionName", "HDFS", null);
+
+    assertEquals(1, associatedHosts.size());
+  }
+
   @Test
   public void testHashingAlgorithm() throws Exception {
     List<String> uuids = new ArrayList<String>();