Browse Source

AMBARI-8375 - AlertGroup REST Endpoint Should Return Alert Definition Source Type (jonathanhurley)

Jonathan Hurley 10 years ago
parent
commit
8b6e7e9e21

+ 23 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/AlertDefinitionResponse.java

@@ -18,6 +18,7 @@
 package org.apache.ambari.server.controller;
 
 import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
+import org.apache.ambari.server.state.alert.SourceType;
 import org.codehaus.jackson.annotate.JsonProperty;
 
 
@@ -34,6 +35,7 @@ public class AlertDefinitionResponse {
   private String label = null;
   private Long definitionId;
   private boolean enabled = true;
+  private SourceType sourceType;
 
   /**
    * @return the definitionId
@@ -136,6 +138,26 @@ public class AlertDefinitionResponse {
     this.enabled = enabled;
   }
 
+  /**
+   * Gets the type of alert.
+   *
+   * @return the sourceType
+   */
+  @JsonProperty("source_type")
+  public SourceType getSourceType() {
+    return sourceType;
+  }
+
+  /**
+   * Sets the type of alert.
+   *
+   * @param sourceType
+   *          the sourceType to set
+   */
+  public void setSourceType(SourceType sourceType) {
+    this.sourceType = sourceType;
+  }
+
   @Override
   public String toString() {
     return name;
@@ -160,6 +182,7 @@ public class AlertDefinitionResponse {
     response.setName(entity.getDefinitionName());
     response.setServiceName(entity.getServiceName());
     response.setEnabled(entity.getEnabled());
+    response.setSourceType(entity.getSourceType());
 
     return response;
   }

+ 2 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProviderTest.java

@@ -213,6 +213,7 @@ public class AlertGroupResourceProviderTest {
     assertNotNull(definitions);
     assertEquals(1, definitions.size());
     assertEquals(ALERT_DEF_NAME, definitions.get(0).getName());
+    assertEquals(SourceType.METRIC, definitions.get(0).getSourceType());
 
     verify(m_amc, m_clusters, m_cluster, m_dao);
   }
@@ -263,6 +264,7 @@ public class AlertGroupResourceProviderTest {
 
     assertEquals(1, definitions.size());
     assertEquals(ALERT_DEF_NAME, definitions.get(0).getName());
+    assertEquals(SourceType.METRIC, definitions.get(0).getSourceType());
 
     assertEquals(1, targets.size());
     assertEquals(ALERT_TARGET_NAME, targets.get(0).getName());