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 17:39:53 UTC
git commit: add logging for failures only
Repository: incubator-usergrid
Updated Branches:
refs/heads/two-dot-o 66c377df5 -> 13ae49b37
add logging for failures only
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/13ae49b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/13ae49b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/13ae49b3
Branch: refs/heads/two-dot-o
Commit: 13ae49b374d6d4aba65decb8a8bdfc50f02d7e49
Parents: 66c377d
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Oct 8 09:39:36 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Oct 8 09:39:36 2014 -0600
----------------------------------------------------------------------
.../notifications/ApplicationQueueManager.java | 7 +-
.../services/notifications/TaskManager.java | 85 +++++++++++---------
2 files changed, 50 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/13ae49b3/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 079fd4b..b806bcb 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
@@ -223,10 +223,10 @@ public class ApplicationQueueManager {
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 || notification.getDebug()) {
+ if (deviceCount.get() <= 0) {
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);
+ taskManager.finishedBatch(false,true);
}else {
em.update(notification);
}
@@ -378,8 +378,7 @@ public class ApplicationQueueManager {
try {
TaskManager taskManager = taskMap.get(message.getNotificationId());
notifications.put(message.getNotificationId(), message);
- Notification notification = notificationMap.get(message.getNotificationId());
- if(notification.getDebug())taskManager.finishedBatch();
+ taskManager.finishedBatch();
} catch (Exception e) {
LOG.error("Failed to finish batch", e);
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/13ae49b3/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 a11ad45..03f036d 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
@@ -50,6 +50,13 @@ public class TaskManager {
hasFinished = false;
}
+ public long getSuccesses(){return successes.get();}
+
+ public long getFailures(){ return failures.get();}
+
+ public void completed(Notifier notifier, UUID deviceUUID) throws Exception {
+ completed(notifier,null,deviceUUID,null);
+ }
public void completed(Notifier notifier, Receipt receipt, UUID deviceUUID, String newProviderId) throws Exception {
LOG.debug("REMOVED {}", deviceUUID);
try {
@@ -59,7 +66,7 @@ public class TaskManager {
if (receipt != null) {
LOG.debug("notification {} sent to device {}. saving receipt.", notification.getUuid(), deviceUUID);
receipt.setSent(System.currentTimeMillis());
- this.saveReceipt(notification, deviceRef, receipt);
+ this.saveReceipt(notification, deviceRef, receipt,false);
LOG.debug("notification {} receipt saved for device {}", notification.getUuid(), deviceUUID);
successes.incrementAndGet();
}
@@ -97,10 +104,10 @@ public class TaskManager {
}
receipt.setErrorCode(code);
receipt.setErrorMessage(message);
- this.saveReceipt(notification, new SimpleEntityRef(Device.ENTITY_TYPE, deviceUUID), receipt);
+ this.saveReceipt(notification, new SimpleEntityRef(Device.ENTITY_TYPE, deviceUUID), receipt,true);
LOG.debug("notification {} receipt saved for device {}", notification.getUuid(), deviceUUID);
} finally {
- completed(notifier, null, deviceUUID, null);
+ completed(notifier, deviceUUID);
}
}
@@ -108,8 +115,8 @@ public class TaskManager {
* called from TaskManager - creates a persistent receipt and updates the
* passed one w/ the UUID
*/
- private void saveReceipt(EntityRef notification, EntityRef device, Receipt receipt) throws Exception {
- if (this.notification.getDebug()) {
+ private void saveReceipt(EntityRef notification, EntityRef device, Receipt receipt, boolean hasError) throws Exception {
+ if (this.notification.getDebug() || hasError) {
if (receipt.getUuid() == null) {
Receipt savedReceipt = em.create(receipt);
receipt.setUuid(savedReceipt.getUuid());
@@ -137,42 +144,44 @@ public class TaskManager {
}
}
public void finishedBatch() throws Exception {
- finishedBatch(true);
+ finishedBatch(true,false);
}
- 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++) {
- this.successes.decrementAndGet();
- }
- for (int i = 0; i < failures; i++) {
- this.failures.decrementAndGet();
- }
+ public void finishedBatch(boolean fetch, boolean force) throws Exception {
+ if (notification.getDebug() || getFailures() > 0 || force) {
+ long successes = this.successes.get(); //reset counters
+ long failures = this.failures.get(); //reset counters
+ for (int i = 0; i < successes; i++) {
+ this.successes.decrementAndGet();
+ }
+ for (int i = 0; i < failures; i++) {
+ this.failures.decrementAndGet();
+ }
- this.hasFinished = true;
-
- // refresh notification
- if(fetch)
- notification = em.get(this.notification.getUuid(), Notification.class);
- notification.setModified(System.currentTimeMillis());
-
- //and write them out again, this will produce the most accurate count
- Map<String, Long> stats = new HashMap<>(2);
- stats.put("sent", successes);
- stats.put("errors", failures);
- notification.updateStatistics(successes, failures);
-
- long totals = (notification.getStatistics().get("sent") + notification.getStatistics().get("errors"));
- //none of this is known and should you ever do this
- Map<String, Object> properties = new HashMap<>();
- notification.setFinished(notification.getModified());
- properties.put("finished", notification.getModified());
- properties.put("state", notification.getState());
- notification.addProperties(properties);
- long latency = notification.getFinished() - notification.getStarted();
- LOG.info("notification finished batch: {} of {} devices in "+latency+"ms", notification.getUuid(), totals);
- em.update(notification);
+ this.hasFinished = true;
+
+ // refresh notification
+ if (fetch)
+ notification = em.get(this.notification.getUuid(), Notification.class);
+ notification.setModified(System.currentTimeMillis());
+
+ //and write them out again, this will produce the most accurate count
+ Map<String, Long> stats = new HashMap<>(2);
+ stats.put("sent", successes);
+ stats.put("errors", failures);
+ notification.updateStatistics(successes, failures);
+
+ long totals = (notification.getStatistics().get("sent") + notification.getStatistics().get("errors"));
+ //none of this is known and should you ever do this
+ Map<String, Object> properties = new HashMap<>();
+ notification.setFinished(notification.getModified());
+ properties.put("finished", notification.getModified());
+ properties.put("state", notification.getState());
+ notification.addProperties(properties);
+ 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);
+ }
}
}
\ No newline at end of file