eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject incubator-eagle git commit: [EAGLE-597] Add API to filter publishment and single policy metadata by policyId
Date Sun, 09 Oct 2016 12:19:00 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/master ae8857772 -> 8ba1b844c


[EAGLE-597] Add API to filter publishment and single policy metadata by policyId

Alert engine publishments API only support to provide all publishments and let client-side
to filter according requirements, which is NOT an scalable implementation.

As a quick solution to fix it in some way, we should provide a API to filter publishments
by policy ID, so in this patch it mainly added two APIs:

* GET /metadata/policies/{policyId}
* GET /metadata/policies/{policyId}/publishments

Author: Hao Chen <hao@apache.org>

Closes #480 from haoch/EAGLE-597.


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

Branch: refs/heads/master
Commit: 8ba1b844cdb9e165844896b526631eec5a1b64aa
Parents: ae88577
Author: Hao Chen <hao@apache.org>
Authored: Sun Oct 9 20:18:49 2016 +0800
Committer: Hao Chen <hao@apache.org>
Committed: Sun Oct 9 20:18:49 2016 +0800

----------------------------------------------------------------------
 .../eagle/alert/engine/router/TestAlertBolt.java    |  2 +-
 .../service/metadata/resource/MetadataResource.java | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8ba1b844/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertBolt.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertBolt.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertBolt.java
index 2b9144d..c3842fa 100755
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertBolt.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertBolt.java
@@ -517,7 +517,7 @@ public class TestAlertBolt {
         Tuple input2 = new TupleImpl(context, Collections.singletonList(partitionedEvent2),
taskId, "default");
         bolt.execute(input);
         bolt.execute(input2);
-        Assert.assertTrue("Timeout to acquire mutex in 5s", mutex.tryAcquire(1, 5, TimeUnit.SECONDS));
+        Assert.assertTrue("Timeout to acquire mutex in 10s", mutex.tryAcquire(1, 10, TimeUnit.SECONDS));
         Assert.assertEquals(3, alertCount.get());
         bolt.cleanup();
     }

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8ba1b844/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 5922f20..d381aad 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
@@ -29,6 +29,7 @@ import com.google.inject.Inject;
 
 import java.util.LinkedList;
 import java.util.List;
+import java.util.stream.Collectors;
 import javax.ws.rs.*;
 
 /**
@@ -44,7 +45,6 @@ public class MetadataResource {
 
     public MetadataResource() {
         this.dao = MetadataDaoFactory.getInstance().getMetadataDao();
-        ;
     }
 
     @Inject
@@ -212,6 +212,20 @@ public class MetadataResource {
         return dao.removePolicy(policyId);
     }
 
+    @Path("/policies/{policyId}/publishments")
+    @GET
+    public List<Publishment> getPolicyPublishments(@PathParam("policyId") String policyId)
{
+        return dao.listPublishment().stream().filter(ps ->
+            ps.getPolicyIds() != null && ps.getPolicyIds().contains(policyId)
+        ).collect(Collectors.toList());
+    }
+
+    @Path("/policies/{policyId}")
+    @GET
+    public List<PolicyDefinition> getPolicyByID(@PathParam("policyId") String policyId)
{
+        return dao.listPolicies().stream().filter(pc -> pc.getName().equals(policyId)).collect(Collectors.toList());
+    }
+
     @Path("/policies")
     @DELETE
     public List<OpResult> removePolicies(List<String> policies) {


Mime
View raw message