You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2014/10/08 02:09:10 UTC

git commit: adding debug mode for notifications, to save us from logging

Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o 7c8eb6281 -> 0b43040f3


adding debug mode for notifications, to save us from logging


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

Branch: refs/heads/two-dot-o
Commit: 0b43040f326f26ba1ab3c6e2665c5c8dcc3961d3
Parents: 7c8eb62
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Oct 7 18:08:38 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Oct 7 18:08:38 2014 -0600

----------------------------------------------------------------------
 .../persistence/entities/Notification.java      | 13 ++++++++
 .../notifications/ApplicationQueueManager.java  | 17 +++++------
 .../services/notifications/TaskManager.java     | 31 ++++++++++----------
 .../apns/NotificationsServiceIT.java            | 12 ++++++++
 .../gcm/NotificationsServiceIT.java             | 10 +++++++
 5 files changed, 57 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b43040f/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
index d8e7242..4abb5b1 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
@@ -57,6 +57,10 @@ public class Notification extends TypedEntity {
     @EntityProperty
     protected Long queued;
 
+    /** Debug logging is on  */
+    @EntityProperty
+    protected boolean debug;
+
     /** Time send started */
     @EntityProperty
     protected Long started;
@@ -156,6 +160,15 @@ public class Notification extends TypedEntity {
     }
 
     @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public boolean getDebug() {
+        return debug;
+    }
+
+    public void setDebug(boolean debug) {
+        this.debug = debug;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
     public Long getStarted() {
         return started;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b43040f/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
index 7728111..079fd4b 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
@@ -203,16 +203,12 @@ public class ApplicationQueueManager  {
                     });
             o.toBlocking().lastOrDefault(null);
             LOG.info("notification {} done queueing duration {} ms", notification.getUuid(), System.currentTimeMillis() - now);
-
-
         }
 
         // update queued time
         Map<String, Object> properties = new HashMap<String, Object>(2);
         properties.put("queued", notification.getQueued());
         properties.put("state", notification.getState());
-
-
         if(errorMessages.size()>0){
             if (notification.getErrorMessage() == null) {
                 notification.setErrorMessage("There was a problem delivering all of your notifications. See deliveryErrors in properties");
@@ -224,17 +220,17 @@ public class ApplicationQueueManager  {
         long now = System.currentTimeMillis();
 
 
-        LOG.info("notification {} updated notification duration {} ms", notification.getUuid(),System.currentTimeMillis() - now);
+        LOG.info("notification {} updated notification duration {} ms", notification.getUuid(), System.currentTimeMillis() - now);
 
         //do i have devices, and have i already started batching.
-        if (deviceCount.get() <= 0) {
+        if (deviceCount.get() <= 0 || notification.getDebug()) {
             TaskManager taskManager = new TaskManager(em, this, notification);
             //if i'm in a test value will be false, do not mark finished for test orchestration, not ideal need real tests
-            taskManager.finishedBatch(false,false);
+            taskManager.finishedBatch(false);
+        }else {
+            em.update(notification);
         }
 
-        em.update(notification);
-
         long elapsed = notification.getQueued() != null ? notification.getQueued() - startTime : 0;
         LOG.info("notification {} done queuing to {} devices in " + elapsed + " ms", notification.getUuid().toString(), deviceCount.get());
     }
@@ -382,7 +378,8 @@ public class ApplicationQueueManager  {
                                 try {
                                     TaskManager taskManager = taskMap.get(message.getNotificationId());
                                     notifications.put(message.getNotificationId(), message);
-                                    taskManager.finishedBatch();
+                                    Notification notification = notificationMap.get(message.getNotificationId());
+                                    if(notification.getDebug())taskManager.finishedBatch();
                                 } catch (Exception e) {
                                     LOG.error("Failed to finish batch", e);
                                 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b43040f/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
index 4b55e95..a11ad45 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
@@ -109,15 +109,17 @@ public class TaskManager {
     * passed one w/ the UUID
     */
     private void saveReceipt(EntityRef notification, EntityRef device, Receipt receipt) throws Exception {
-        if (receipt.getUuid() == null) {
-            Receipt savedReceipt = em.create(receipt);
-            receipt.setUuid(savedReceipt.getUuid());
-
-            List<EntityRef> entities = Arrays.asList(notification, device);
-//            em.addToCollections(entities, Notification.RECEIPTS_COLLECTION, savedReceipt);
-        } else {
-            em.update(receipt);
+        if (this.notification.getDebug()) {
+            if (receipt.getUuid() == null) {
+                Receipt savedReceipt = em.create(receipt);
+                receipt.setUuid(savedReceipt.getUuid());
+                List<EntityRef> entities = Arrays.asList(notification, device);
+//              em.addToCollections(entities, Notification.RECEIPTS_COLLECTION, savedReceipt);
+            } else {
+                em.update(receipt);
+            }
         }
+
     }
 
     protected void replaceProviderId(EntityRef device, Notifier notifier,
@@ -135,9 +137,9 @@ public class TaskManager {
         }
     }
     public void finishedBatch() throws Exception {
-        finishedBatch(true,true);
+        finishedBatch(true);
     }
-    public void finishedBatch(boolean update, boolean fetch) throws Exception {
+    public void finishedBatch(boolean fetch) throws Exception {
         long successes = this.successes.get(); //reset counters
         long failures = this.failures.get(); //reset counters
         for (int i = 0; i < successes; i++) {
@@ -166,13 +168,10 @@ public class TaskManager {
         notification.setFinished(notification.getModified());
         properties.put("finished", notification.getModified());
         properties.put("state", notification.getState());
-        LOG.info("done sending to devices in {} ms", notification.getFinished() - notification.getStarted());
         notification.addProperties(properties);
-
-        LOG.info("notification finished batch: {} of {} devices", notification.getUuid(), totals);
-        if (update){
-            em.update(notification);
-        }
+        long latency = notification.getFinished() - notification.getStarted();
+        LOG.info("notification finished batch: {} of {} devices in "+latency+"ms", notification.getUuid(), totals);
+        em.update(notification);
 //        Set<Notifier> notifiers = new HashSet<>(proxy.getNotifierMap().values()); // remove dups
 //        proxy.asyncCheckForInactiveDevices(notifiers);
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b43040f/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
index f1d2dea..935f6b6 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
@@ -174,6 +174,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getName().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         // post notification to service manager
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
@@ -251,6 +252,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         app.put("payloads", payloads);
         app.put("started", System.currentTimeMillis());
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         Query pQuery = new Query();
         pQuery.setLimit(100);
@@ -306,6 +308,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         app.put("payloads", payloads);
         app.put("deliver", System.currentTimeMillis() + 240000);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
                 .getEntity();
@@ -352,6 +355,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         app.clear();
         app.put("payloads", "{asdf}");
+        app.put("debug",true);
 
         try {
             Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
@@ -444,6 +448,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getUuid().toString(), payload);
         properties.put("payloads", payloads);
         properties.put("queued", System.currentTimeMillis());
+        properties.put("debug",true);
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
                 .getEntity();
@@ -479,6 +484,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifierName, payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
@@ -536,6 +542,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier2Name, payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
@@ -596,6 +603,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier2.getUuid().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
@@ -663,6 +671,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getUuid().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
@@ -719,6 +728,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getUuid().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
                 .getEntity();
@@ -785,6 +795,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getUuid().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         // create a notification
         entity = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
@@ -818,6 +829,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getUuid().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         // create a notification
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0b43040f/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
index 6edf0b5..81f1f77 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
@@ -143,6 +143,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         Map<String, String> payloads = new HashMap<String, String>(1);
         payloads.put("foo", payload);
         app.put("payloads", payloads);
+        app.put("debug",true);
         app.put("queued", System.currentTimeMillis());
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
@@ -173,6 +174,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getUuid().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
@@ -218,6 +220,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getUuid().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
 
@@ -241,6 +244,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getUuid().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
                 .getEntity();
@@ -291,6 +295,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getUuid().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
                 .getEntity();
@@ -320,6 +325,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         app.clear();
         app.put("payloads", "{asdf}");
+        app.put("debug",true);
 
         try {
             app.testRequest(ServiceAction.POST, 1, "notifications");
@@ -363,6 +369,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         app.clear();
         app.put("payloads", payloads);
+        app.put("debug",true);
 
         try {
             app.testRequest(ServiceAction.POST, 1, "notifications");
@@ -401,6 +408,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getUuid().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
                 .getEntity();
@@ -457,6 +465,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getUuid().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
+        app.put("debug",true);
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
                 .getEntity();
@@ -493,6 +502,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getUuid().toString(), payload);
         properties.put("payloads", payloads);
         properties.put("queued", System.currentTimeMillis());
+        properties.put("debug",true);
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
                 .getEntity();