ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject git commit: AMBARI-8018 - Show all properties for source subresource in alert_definitions API response (jonathanhurley)
Date Wed, 29 Oct 2014 18:26:57 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 957077c5c -> d063cc637


AMBARI-8018 - Show all properties for source subresource in alert_definitions API response
(jonathanhurley)


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

Branch: refs/heads/trunk
Commit: d063cc637991c152d0dfd2da5479f66909197f2a
Parents: 957077c
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Wed Oct 29 11:11:23 2014 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Wed Oct 29 14:26:50 2014 -0400

----------------------------------------------------------------------
 .../AlertDefinitionResourceProvider.java        |  9 ++-
 .../AlertDefinitionResourceProviderTest.java    | 64 ++++++++++++++++++++
 2 files changed, 70 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d063cc63/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java
index 5d0a180..e1c0082 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java
@@ -553,12 +553,15 @@ public class AlertDefinitionResourceProvider extends AbstractControllerResourceP
     setResourceProperty(resource, ALERT_DEF_COMPONENT_NAME, entity.getComponentName(), requestedIds);
     setResourceProperty(resource, ALERT_DEF_ENABLED, Boolean.valueOf(entity.getEnabled()),
requestedIds);
     setResourceProperty(resource, ALERT_DEF_SCOPE, entity.getScope(), requestedIds);
-    setResourceProperty(resource, ALERT_DEF_SOURCE_TYPE, entity.getSourceType(), requestedIds);
 
-    if (!isCollection && null != resource.getPropertyValue(ALERT_DEF_SOURCE_TYPE))
{
+    boolean sourceTypeRequested = setResourceProperty(resource,
+        ALERT_DEF_SOURCE_TYPE, entity.getSourceType(), requestedIds);
 
+    if (sourceTypeRequested
+        && null != resource.getPropertyValue(ALERT_DEF_SOURCE_TYPE)) {
       try {
-        Map<String, String> map = gson.<Map<String, String>>fromJson(entity.getSource(),
Map.class);
+        Map<String, String> map = gson.<Map<String, String>> fromJson(
+            entity.getSource(), Map.class);
 
         for (Entry<String, String> entry : map.entrySet()) {
           String subProp = PropertyHelper.getPropertyId(ALERT_DEF_SOURCE, entry.getKey());

http://git-wip-us.apache.org/repos/asf/ambari/blob/d063cc63/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProviderTest.java
index a28fe5f..a82e8c4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProviderTest.java
@@ -204,6 +204,70 @@ public class AlertDefinitionResourceProviderTest {
   }
 
   /**
+   * Tests that the source structure returned has the entire set of
+   * subproperties on it (such as reporting)
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testGetResourcesAssertSourceType() throws Exception {
+    Request request = PropertyHelper.getReadRequest(
+        AlertDefinitionResourceProvider.ALERT_DEF_CLUSTER_NAME,
+        AlertDefinitionResourceProvider.ALERT_DEF_ID,
+        AlertDefinitionResourceProvider.ALERT_DEF_NAME,
+        AlertDefinitionResourceProvider.ALERT_DEF_LABEL,
+        AlertDefinitionResourceProvider.ALERT_DEF_SOURCE_TYPE);
+
+    AmbariManagementController amc = createMock(AmbariManagementController.class);
+    Clusters clusters = createMock(Clusters.class);
+    Cluster cluster = createMock(Cluster.class);
+    expect(amc.getClusters()).andReturn(clusters).atLeastOnce();
+    expect(clusters.getCluster((String) anyObject())).andReturn(cluster).atLeastOnce();
+    expect(cluster.getClusterId()).andReturn(Long.valueOf(1)).anyTimes();
+
+    Predicate predicate = new PredicateBuilder().property(
+        AlertDefinitionResourceProvider.ALERT_DEF_CLUSTER_NAME).equals("c1").toPredicate();
+
+    expect(dao.findAll(1L)).andReturn(getMockEntities()).atLeastOnce();
+
+    replay(amc, clusters, cluster, dao);
+
+    AlertDefinitionResourceProvider provider = createProvider(amc);
+    Set<Resource> results = provider.getResources(request, predicate);
+
+    assertEquals(1, results.size());
+
+    Resource resource = results.iterator().next();
+
+    Assert.assertEquals("my_def",
+        resource.getPropertyValue(AlertDefinitionResourceProvider.ALERT_DEF_NAME));
+
+    Map<String, String> reporting = (Map<String, String>) resource.getPropertyValue(AlertDefinitionResourceProvider.ALERT_DEF_SOURCE_REPORTING);
+
+    Assert.assertTrue(reporting.containsKey("ok"));
+    Assert.assertTrue(reporting.containsKey("critical"));
+
+    verify(amc, clusters, cluster, dao);
+
+    // make another request, this time without the source and ensure that no
+    // source properties come back
+    request = PropertyHelper.getReadRequest(
+        AlertDefinitionResourceProvider.ALERT_DEF_CLUSTER_NAME,
+        AlertDefinitionResourceProvider.ALERT_DEF_ID,
+        AlertDefinitionResourceProvider.ALERT_DEF_NAME);
+
+    results = provider.getResources(request, predicate);
+    resource = results.iterator().next();
+
+    Assert.assertEquals(
+        "my_def",
+        resource.getPropertyValue(AlertDefinitionResourceProvider.ALERT_DEF_NAME));
+
+    reporting = (Map<String, String>) resource.getPropertyValue(AlertDefinitionResourceProvider.ALERT_DEF_SOURCE_REPORTING);
+    Assert.assertNull(reporting);
+  }
+
+  /**
    * @throws Exception
    */
   @Test


Mime
View raw message