eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qingwz...@apache.org
Subject incubator-eagle git commit: [EAGLE-760] add size limit in the alert list APIs
Date Thu, 10 Nov 2016 08:15:04 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/master 8f8fe57e6 -> 0a0d1f6ee


[EAGLE-760] add size limit in the alert list APIs

https://issues.apache.org/jira/browse/EAGLE-760

Author: Zhao, Qingwen <qingwzhao@apache.org>

Closes #644 from qingwen220/EAGLE-760.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/0a0d1f6e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/0a0d1f6e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/0a0d1f6e

Branch: refs/heads/master
Commit: 0a0d1f6ee9dcb36ca96721a90392a676b2652d28
Parents: 8f8fe57
Author: Zhao, Qingwen <qingwzhao@apache.org>
Authored: Thu Nov 10 16:14:56 2016 +0800
Committer: Zhao, Qingwen <qingwzhao@apache.org>
Committed: Thu Nov 10 16:14:56 2016 +0800

----------------------------------------------------------------------
 .../metadata/resource/MetadataResource.java        |  5 +++--
 .../apache/eagle/alert/metadata/IMetadataDao.java  |  2 +-
 .../alert/metadata/impl/InMemMetadataDaoImpl.java  |  9 ++++++---
 .../alert/metadata/impl/JdbcMetadataDaoImpl.java   | 15 +++++++++------
 .../alert/metadata/impl/MongoMetadataDaoImpl.java  | 17 ++++++++++++-----
 5 files changed, 31 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0a0d1f6e/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
index a658933..fc4a2bd 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
@@ -244,8 +244,9 @@ public class MetadataResource {
 
     @Path("/policies/{policyId}/alerts")
     @GET
-    public List<AlertPublishEvent> getAlertPublishEventByPolicyId(@PathParam("policyId")
String policyId) {
-        return dao.getAlertPublishEventByPolicyId(policyId);
+    public List<AlertPublishEvent> getAlertPublishEventByPolicyId(@PathParam("policyId")
String policyId,
+                                                                  @QueryParam("size") int
size) {
+        return dao.getAlertPublishEventByPolicyId(policyId, size);
     }
 
     @Path("/policies/{policyId}/publishments")

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0a0d1f6e/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/IMetadataDao.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/IMetadataDao.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/IMetadataDao.java
index 4321796..19d2b31 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/IMetadataDao.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/IMetadataDao.java
@@ -82,7 +82,7 @@ public interface IMetadataDao extends Closeable {
 
     AlertPublishEvent getAlertPublishEvent(String alertId);
 
-    List<AlertPublishEvent> getAlertPublishEventByPolicyId(String policyId);
+    List<AlertPublishEvent> getAlertPublishEventByPolicyId(String policyId, int size);
 
     OpResult addAlertPublishEvent(AlertPublishEvent event);
 

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0a0d1f6e/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/InMemMetadataDaoImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/InMemMetadataDaoImpl.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/InMemMetadataDaoImpl.java
index 03dad05..96cb20e 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/InMemMetadataDaoImpl.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/InMemMetadataDaoImpl.java
@@ -202,7 +202,7 @@ public class InMemMetadataDaoImpl implements IMetadataDao {
     @Override
     public List<AlertPublishEvent> listAlertPublishEvent(int size) {
         if (size > 0 && size <= alerts.size()) {
-            return alerts.subList(0, size);
+            return alerts.subList(alerts.size() - size, alerts.size());
         }
         return alerts;
     }
@@ -218,9 +218,12 @@ public class InMemMetadataDaoImpl implements IMetadataDao {
     }
 
     @Override
-    public List<AlertPublishEvent> getAlertPublishEventByPolicyId(String policyId)
{
+    public List<AlertPublishEvent> getAlertPublishEventByPolicyId(String policyId,
int size) {
+        if (size < 0 || size > alerts.size()) {
+            size = alerts.size();
+        }
         List<AlertPublishEvent> result = alerts.stream().filter(alert -> alert.getPolicyId().equals(policyId)).collect(Collectors.toList());
-        return result;
+        return result.subList(result.size() - size, result.size());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0a0d1f6e/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcMetadataDaoImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcMetadataDaoImpl.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcMetadataDaoImpl.java
index c540b52..d748ed1 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcMetadataDaoImpl.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcMetadataDaoImpl.java
@@ -75,11 +75,11 @@ public class JdbcMetadataDaoImpl implements IMetadataDao {
 
     @Override
     public List<AlertPublishEvent> listAlertPublishEvent(int size) {
-        if (size <= 0) {
-            return handler.list(AlertPublishEvent.class);
-        } else {
-            return handler.listSubset(AlertPublishEvent.class, size);
+        List<AlertPublishEvent> result = handler.list(AlertPublishEvent.class);
+        if (size < 0 || size > result.size()) {
+            size = result.size();
         }
+        return result.subList(result.size() - size, result.size());
     }
 
     @Override
@@ -88,10 +88,13 @@ public class JdbcMetadataDaoImpl implements IMetadataDao {
     }
 
     @Override
-    public List<AlertPublishEvent> getAlertPublishEventByPolicyId(String policyId)
{
+    public List<AlertPublishEvent> getAlertPublishEventByPolicyId(String policyId,
int size) {
         List<AlertPublishEvent> alerts = handler.list(AlertPublishEvent.class);
+        if (size < 0 || size > alerts.size()) {
+            size = alerts.size();
+        }
         List<AlertPublishEvent> result = alerts.stream().filter(alert -> alert.getPolicyId().equals(policyId)).collect(Collectors.toList());
-        return result;
+        return result.subList(result.size() - size, result.size());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0a0d1f6e/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MongoMetadataDaoImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MongoMetadataDaoImpl.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MongoMetadataDaoImpl.java
index dd1e586..498f540 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MongoMetadataDaoImpl.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MongoMetadataDaoImpl.java
@@ -354,7 +354,11 @@ public class MongoMetadataDaoImpl implements IMetadataDao {
 
     @Override
     public List<AlertPublishEvent> listAlertPublishEvent(int size) {
-        return list(alerts, AlertPublishEvent.class);
+        List<AlertPublishEvent> result = list(alerts, AlertPublishEvent.class);
+        if (size < 0 || size > result.size()) {
+            size = result.size();
+        }
+        return result.subList(result.size() - size, result.size());
     }
 
     @Override
@@ -368,10 +372,13 @@ public class MongoMetadataDaoImpl implements IMetadataDao {
     }
 
     @Override
-    public List<AlertPublishEvent> getAlertPublishEventByPolicyId(String policyId)
{
-        List<AlertPublishEvent> results = list(alerts, AlertPublishEvent.class);
-        List<AlertPublishEvent> ret = results.stream().filter(alert -> alert.getPolicyId().equals(policyId)).collect(Collectors.toList());
-        return ret;
+    public List<AlertPublishEvent> getAlertPublishEventByPolicyId(String policyId,
int size) {
+        List<AlertPublishEvent> events = list(alerts, AlertPublishEvent.class);
+        if (size < 0 || size > events.size()) {
+            size = events.size();
+        }
+        List<AlertPublishEvent> result = events.stream().filter(alert -> alert.getPolicyId().equals(policyId)).collect(Collectors.toList());
+        return events.subList(result.size() - size, result.size());
     }
 
     @Override


Mime
View raw message