You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2014/11/18 06:22:55 UTC

ambari git commit: AMBARI-8352 - Alert Groups REST Endpoint Should Support Associated Definitions (jonathanhurley)

Repository: ambari
Updated Branches:
  refs/heads/trunk a7f832097 -> 4955e5a19


AMBARI-8352 - Alert Groups REST Endpoint Should Support Associated Definitions (jonathanhurley)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/4955e5a1
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/4955e5a1
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/4955e5a1

Branch: refs/heads/trunk
Commit: 4955e5a19a142f3f3cdb8b339bc32a089c840644
Parents: a7f8320
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Mon Nov 17 13:09:20 2014 -0500
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Tue Nov 18 00:22:44 2014 -0500

----------------------------------------------------------------------
 .../controller/AlertDefinitionResponse.java     | 23 +++++++++
 .../internal/AlertGroupResourceProvider.java    | 28 ++++++-----
 .../AlertGroupResourceProviderTest.java         | 50 +++++++++++++++++---
 3 files changed, 84 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4955e5a1/ambari-server/src/main/java/org/apache/ambari/server/controller/AlertDefinitionResponse.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AlertDefinitionResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AlertDefinitionResponse.java
index 26e2f24..908fed8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AlertDefinitionResponse.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AlertDefinitionResponse.java
@@ -33,6 +33,7 @@ public class AlertDefinitionResponse {
   private String name = null;
   private String label = null;
   private Long definitionId;
+  private boolean enabled = true;
 
   /**
    * @return the definitionId
@@ -114,6 +115,27 @@ public class AlertDefinitionResponse {
     label = definitionLabel;
   }
 
+
+  /**
+   * Gets whether this definition is enabled.
+   *
+   * @return {@code true} if enabled.
+   */
+  @JsonProperty("enabled")
+  public boolean isEnabled() {
+    return enabled;
+  }
+
+  /**
+   * Sets whether this definition is enabled.
+   *
+   * @param enabled
+   *          {@code true} if enabled.
+   */
+  public void setEnabled(boolean enabled) {
+    this.enabled = enabled;
+  }
+
   @Override
   public String toString() {
     return name;
@@ -137,6 +159,7 @@ public class AlertDefinitionResponse {
     response.setLabel(entity.getLabel());
     response.setName(entity.getDefinitionName());
     response.setServiceName(entity.getServiceName());
+    response.setEnabled(entity.getEnabled());
 
     return response;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/4955e5a1/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java
index 0c2fb72..47fd65b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java
@@ -390,29 +390,35 @@ public class AlertGroupResourceProvider extends
     resource.setProperty(ALERT_GROUP_ID, entity.getGroupId());
     resource.setProperty(ALERT_GROUP_NAME, entity.getGroupName());
     resource.setProperty(ALERT_GROUP_CLUSTER_NAME, clusterName);
-    resource.setProperty(ALERT_GROUP_DEFAULT, entity.isDefault());
+
+    setResourceProperty(resource, ALERT_GROUP_DEFAULT, entity.isDefault(),
+        requestedIds);
+
+    // only set the definitions if requested
+    if (BaseProvider.isPropertyRequested(ALERT_GROUP_DEFINITIONS, requestedIds)) {
+      Set<AlertDefinitionEntity> definitions = entity.getAlertDefinitions();
+      List<AlertDefinitionResponse> definitionList = new ArrayList<AlertDefinitionResponse>(
+          definitions.size());
+
+      for (AlertDefinitionEntity definition : definitions) {
+        AlertDefinitionResponse response = AlertDefinitionResponse.coerce(definition);
+        definitionList.add(response);
+      }
+
+      resource.setProperty(ALERT_GROUP_DEFINITIONS, definitionList);
+    }
 
     if( !isCollection ){
       Set<AlertTargetEntity> targetEntities = entity.getAlertTargets();
-      Set<AlertDefinitionEntity> definitions = entity.getAlertDefinitions();
 
       List<AlertTarget> targets = new ArrayList<AlertTarget>(
           targetEntities.size());
 
-      List<AlertDefinitionResponse> definitionList = new ArrayList<AlertDefinitionResponse>(
-          definitions.size());
-
       for (AlertTargetEntity targetEntity : targetEntities) {
         AlertTarget target = AlertTarget.coerce(targetEntity);
         targets.add(target);
       }
 
-      for (AlertDefinitionEntity definition : definitions) {
-        AlertDefinitionResponse response = AlertDefinitionResponse.coerce(definition);
-        definitionList.add(response);
-      }
-
-      resource.setProperty(ALERT_GROUP_DEFINITIONS, definitionList);
       resource.setProperty(ALERT_GROUP_TARGETS, targets);
     }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/4955e5a1/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProviderTest.java
index 1c85aeb..422c6f2 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProviderTest.java
@@ -169,7 +169,7 @@ public class AlertGroupResourceProviderTest {
     assertEquals(ALERT_GROUP_CLUSTER_NAME,
         r.getPropertyValue(AlertGroupResourceProvider.ALERT_GROUP_CLUSTER_NAME));
 
-    // verify definitions do not come back in collections
+    // verify definitions do not come back when not requested
     assertNull(r.getPropertyValue(AlertGroupResourceProvider.ALERT_GROUP_DEFINITIONS));
 
     verify(m_amc, m_clusters, m_cluster, m_dao);
@@ -179,13 +179,51 @@ public class AlertGroupResourceProviderTest {
    * @throws Exception
    */
   @Test
+  public void testGetResourcesAllProperties() throws Exception {
+    Request request = PropertyHelper.getReadRequest();
+
+    Predicate predicate = new PredicateBuilder().property(
+        AlertGroupResourceProvider.ALERT_GROUP_CLUSTER_NAME).equals("c1").toPredicate();
+
+    expect(m_dao.findAllGroups(ALERT_GROUP_CLUSTER_ID)).andReturn(
+        getMockEntities());
+
+    replay(m_amc, m_clusters, m_cluster, m_dao);
+
+    AlertGroupResourceProvider provider = createProvider(m_amc);
+    Set<Resource> results = provider.getResources(request, predicate);
+
+    assertEquals(1, results.size());
+
+    Resource r = results.iterator().next();
+
+    assertEquals(ALERT_GROUP_NAME,
+        r.getPropertyValue(AlertGroupResourceProvider.ALERT_GROUP_NAME));
+
+    assertEquals(ALERT_GROUP_ID,
+        r.getPropertyValue(AlertGroupResourceProvider.ALERT_GROUP_ID));
+
+    assertEquals(ALERT_GROUP_CLUSTER_NAME,
+        r.getPropertyValue(AlertGroupResourceProvider.ALERT_GROUP_CLUSTER_NAME));
+
+
+    // verify definitions do not come back when not requested
+    List<AlertDefinitionResponse> definitions = (List<AlertDefinitionResponse>) r.getPropertyValue(AlertGroupResourceProvider.ALERT_GROUP_DEFINITIONS);
+
+    assertNotNull(definitions);
+    assertEquals(1, definitions.size());
+    assertEquals(ALERT_DEF_NAME, definitions.get(0).getName());
+
+    verify(m_amc, m_clusters, m_cluster, m_dao);
+  }
+
+  /**
+   * @throws Exception
+   */
+  @Test
   @SuppressWarnings("unchecked")
   public void testGetSingleResource() throws Exception {
-    Request request = PropertyHelper.getReadRequest(
-        AlertGroupResourceProvider.ALERT_GROUP_ID,
-        AlertGroupResourceProvider.ALERT_GROUP_NAME,
-        AlertGroupResourceProvider.ALERT_GROUP_CLUSTER_NAME,
-        AlertGroupResourceProvider.ALERT_GROUP_DEFAULT);
+    Request request = PropertyHelper.getReadRequest();
 
     AmbariManagementController amc = createMock(AmbariManagementController.class);