ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject ambari git commit: AMBARI-11520 - Alert Provider Does Not Return Results Paginated From An Offset (jonathanhurley)
Date Fri, 29 May 2015 17:09:09 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk c8d214fc4 -> c2764be2f


AMBARI-11520 - Alert Provider Does Not Return Results Paginated From An Offset (jonathanhurley)


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

Branch: refs/heads/trunk
Commit: c2764be2f12d4ef6c12d6ad73a8d810443e9124d
Parents: c8d214f
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Fri May 29 10:34:40 2015 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Fri May 29 13:08:17 2015 -0400

----------------------------------------------------------------------
 .../internal/AlertHistoryResourceProvider.java  |  8 +--
 .../internal/AlertResourceProvider.java         | 17 ++++++-
 .../internal/DefaultProviderModule.java         |  2 +-
 .../AlertHistoryResourceProviderTest.java       | 17 ++++---
 .../internal/AlertResourceProviderTest.java     | 51 ++++++++++++++++++--
 5 files changed, 80 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c2764be2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertHistoryResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertHistoryResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertHistoryResourceProvider.java
index f21c4ab..89ee69a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertHistoryResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertHistoryResourceProvider.java
@@ -27,6 +27,7 @@ import java.util.Set;
 
 import org.apache.ambari.server.StaticallyInject;
 import org.apache.ambari.server.controller.AlertHistoryRequest;
+import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.spi.ExtendedResourceProvider;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
 import org.apache.ambari.server.controller.spi.NoSuchResourceException;
@@ -49,7 +50,8 @@ import com.google.inject.Inject;
  * ResourceProvider for Alert History
  */
 @StaticallyInject
-public class AlertHistoryResourceProvider extends AbstractResourceProvider implements ExtendedResourceProvider{
+public class AlertHistoryResourceProvider extends ReadOnlyResourceProvider implements
+    ExtendedResourceProvider {
 
   public static final String ALERT_HISTORY_DEFINITION_ID = "AlertHistory/definition_id";
   public static final String ALERT_HISTORY_DEFINITION_NAME = "AlertHistory/definition_name";
@@ -109,8 +111,8 @@ public class AlertHistoryResourceProvider extends AbstractResourceProvider
imple
   /**
    * Constructor.
    */
-  AlertHistoryResourceProvider() {
-    super(PROPERTY_IDS, KEY_PROPERTY_IDS);
+  AlertHistoryResourceProvider(AmbariManagementController controller) {
+    super(PROPERTY_IDS, KEY_PROPERTY_IDS, controller);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/c2764be2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertResourceProvider.java
index a25cba0..4dc4dcf 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertResourceProvider.java
@@ -28,9 +28,11 @@ import java.util.Set;
 import org.apache.ambari.server.StaticallyInject;
 import org.apache.ambari.server.controller.AlertCurrentRequest;
 import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.spi.ExtendedResourceProvider;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
 import org.apache.ambari.server.controller.spi.NoSuchResourceException;
 import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.QueryResponse;
 import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.SystemException;
@@ -46,7 +48,8 @@ import com.google.inject.Inject;
  * ResourceProvider for Alert instances
  */
 @StaticallyInject
-public class AlertResourceProvider extends ReadOnlyResourceProvider {
+public class AlertResourceProvider extends ReadOnlyResourceProvider implements
+    ExtendedResourceProvider {
 
   public static final String ALERT_ID = "Alert/id";
   public static final String ALERT_STATE = "Alert/state";
@@ -121,6 +124,18 @@ public class AlertResourceProvider extends ReadOnlyResourceProvider {
     return pkPropertyIds;
   }
 
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public QueryResponse queryForResources(Request request, Predicate predicate)
+      throws SystemException, UnsupportedPropertyException, NoSuchResourceException,
+      NoSuchParentResourceException {
+
+    return new QueryResponseImpl(getResources(request, predicate),
+        request.getSortRequest() != null, request.getPageRequest() != null,
+        alertsDAO.getCount(predicate));
+  }
 
   @Override
   public Set<Resource> getResources(Request request, Predicate predicate)

http://git-wip-us.apache.org/repos/asf/ambari/blob/c2764be2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
index 0c4942e..dde934d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
@@ -89,7 +89,7 @@ public class DefaultProviderModule extends AbstractProviderModule {
       case AlertDefinition:
         return new AlertDefinitionResourceProvider(managementController);
       case AlertHistory:
-        return new AlertHistoryResourceProvider();
+        return new AlertHistoryResourceProvider(managementController);
       case AlertTarget:
         return new AlertTargetResourceProvider();
       case AlertGroup:

http://git-wip-us.apache.org/repos/asf/ambari/blob/c2764be2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertHistoryResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertHistoryResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertHistoryResourceProviderTest.java
index 0367dd3..99aca45 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertHistoryResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertHistoryResourceProviderTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.server.controller.internal;
 
+import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.createStrictMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
@@ -29,6 +30,7 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.ambari.server.controller.AlertHistoryRequest;
+import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.Resource;
@@ -50,6 +52,7 @@ import org.junit.Test;
 
 import com.google.inject.Binder;
 import com.google.inject.Guice;
+import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.Module;
 import com.google.inject.util.Modules;
@@ -62,6 +65,9 @@ public class AlertHistoryResourceProviderTest {
   private AlertsDAO m_dao = null;
   private Injector m_injector;
 
+  @Inject
+  private AmbariManagementController m_amc;
+
   @Before
   public void before() {
     m_dao = createStrictMock(AlertsDAO.class);
@@ -70,7 +76,7 @@ public class AlertHistoryResourceProviderTest {
     m_injector = Guice.createInjector(Modules.override(
         new InMemoryDefaultTestModule()).with(new MockModule()));
 
-    Assert.assertNotNull(m_injector);
+    m_injector.injectMembers(this);
   }
 
   /**
@@ -173,7 +179,7 @@ public class AlertHistoryResourceProviderTest {
    * @return
    */
   private AlertHistoryResourceProvider createProvider() {
-    return new AlertHistoryResourceProvider();
+    return new AlertHistoryResourceProvider(m_amc);
   }
 
   /**
@@ -214,10 +220,9 @@ public class AlertHistoryResourceProviderTest {
     @Override
     public void configure(Binder binder) {
       binder.bind(AlertsDAO.class).toInstance(m_dao);
-      binder.bind(Clusters.class).toInstance(
-          EasyMock.createNiceMock(Clusters.class));
-      binder.bind(Cluster.class).toInstance(
-          EasyMock.createNiceMock(Cluster.class));
+      binder.bind(Clusters.class).toInstance(EasyMock.createNiceMock(Clusters.class));
+      binder.bind(Cluster.class).toInstance(EasyMock.createNiceMock(Cluster.class));
+      binder.bind(AmbariManagementController.class).toInstance(createMock(AmbariManagementController.class));
       binder.bind(ActionMetadata.class);
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c2764be2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
index 0100771..71226a1 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
@@ -21,14 +21,16 @@ import static org.apache.ambari.server.configuration.Configuration.JDBC_IN_MEMOR
 import static org.apache.ambari.server.configuration.Configuration.JDBC_IN_MEMROY_DRIVER;
 import static org.easymock.EasyMock.capture;
 import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.createStrictMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -46,7 +48,10 @@ import org.apache.ambari.server.api.util.TreeNode;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.AlertCurrentRequest;
 import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.spi.PageRequest;
+import org.apache.ambari.server.controller.spi.PageRequest.StartingPoint;
 import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.QueryResponse;
 import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
@@ -94,10 +99,10 @@ public class AlertResourceProviderTest {
   @Before
   @SuppressWarnings("boxing")
   public void before() throws Exception {
-    m_dao = createStrictMock(AlertsDAO.class);
+    m_dao = EasyMock.createNiceMock(AlertsDAO.class);
 
-    m_injector = Guice.createInjector(Modules.override(
-        new InMemoryDefaultTestModule()).with(new MockModule()));
+    m_injector = Guice.createInjector(Modules.override(new InMemoryDefaultTestModule()).with(
+        new MockModule()));
 
     m_amc = m_injector.getInstance(AmbariManagementController.class);
 
@@ -406,6 +411,44 @@ public class AlertResourceProviderTest {
   }
 
   /**
+   * @throws Exception
+   */
+  @Test
+  public void testResponseIsPaginated() throws Exception {
+    expect(m_dao.findAll(EasyMock.anyObject(AlertCurrentRequest.class))).andReturn(
+        getClusterMockEntities()).atLeastOnce();
+
+    expect(m_dao.getCount(EasyMock.anyObject(Predicate.class))).andReturn(0).atLeastOnce();
+
+    replay(m_dao);
+
+    Set<String> requestProperties = new HashSet<String>();
+    requestProperties.add(AlertResourceProvider.ALERT_ID);
+    requestProperties.add(AlertResourceProvider.ALERT_DEFINITION_NAME);
+
+    Request request = PropertyHelper.getReadRequest(requestProperties);
+
+    Predicate predicate = new PredicateBuilder().property(AlertResourceProvider.ALERT_CLUSTER_NAME).equals(
+        "c1").toPredicate();
+
+    AlertResourceProvider provider = createProvider();
+    QueryResponse response = provider.queryForResources(request, predicate);
+
+    // since the request didn't have paging, then this should be false
+    assertFalse(response.isPagedResponse());
+
+    // add a paged request
+    PageRequest pageRequest = new PageRequestImpl(StartingPoint.Beginning, 5, 10, predicate,
null);
+    request = PropertyHelper.getReadRequest(requestProperties, null, null, pageRequest, null);
+    response = provider.queryForResources(request, predicate);
+
+    // now the request has paging
+    assertTrue(response.isPagedResponse());
+
+    verify(m_dao);
+  }
+
+  /**
    * @return
    */
   private AlertResourceProvider createProvider() {


Mime
View raw message