brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [05/10] brooklyn-server git commit: cleanup how tasks are loaded, better error message for GC case
Date Sat, 22 Jul 2017 02:14:44 GMT
cleanup how tasks are loaded, better error message for GC case


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

Branch: refs/heads/master
Commit: a6c4e1301dc7d5cd4161e34e2631deecee7231ec
Parents: fb04e20
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Thu Jul 6 14:58:58 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Thu Jul 6 14:58:58 2017 +0100

----------------------------------------------------------------------
 .../rest/resources/ActivityResource.java        | 33 ++++++++------------
 1 file changed, 13 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a6c4e130/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ActivityResource.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ActivityResource.java
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ActivityResource.java
index 81439d5..af49856 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ActivityResource.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ActivityResource.java
@@ -47,25 +47,26 @@ public class ActivityResource extends AbstractBrooklynRestResource implements
Ac
 
     @Override
     public TaskSummary get(String taskId) {
-        Task<?> t = mgmt().getExecutionManager().getTask(taskId);
-        if (t == null) {
-            throw WebResourceUtils.notFound("Cannot find task '%s'", taskId);
-        }
-        checkEntityEntitled(t);
+        Task<?> t = findTask(taskId);
 
         return TaskTransformer.fromTask(ui.getBaseUriBuilder()).apply(t);
     }
 
     @Override
     public Map<String, TaskSummary> getAllChildrenAsMap(final String taskId) {
-        final Task<?> parentTask = mgmt().getExecutionManager().getTask(taskId);
-        if (parentTask == null) {
-            throw WebResourceUtils.notFound("Cannot find task '%s'", taskId);
-        }
-        checkEntityEntitled(parentTask);
+        final Task<?> parentTask = findTask(taskId);
         return getAllDescendantTasks(parentTask);
     }
 
+    protected Task<?> findTask(final String taskId) {
+        final Task<?> task = mgmt().getExecutionManager().getTask(taskId);
+        if (task == null) {
+            throw WebResourceUtils.notFound("Cannot find task '%s' - possibly garbage collected
to save memory", taskId);
+        }
+        checkEntityEntitled(task);
+        return task;
+    }
+
     private LinkedHashMap<String, TaskSummary> getAllDescendantTasks(final Task<?>
parentTask) {
         final LinkedHashMap<String, TaskSummary> result = Maps.newLinkedHashMap();
         if (!(parentTask instanceof HasTaskChildren)) {
@@ -81,11 +82,7 @@ public class ActivityResource extends AbstractBrooklynRestResource implements
Ac
 
     @Override
     public List<TaskSummary> children(String taskId, Boolean includeBackground) {
-        Task<?> t = mgmt().getExecutionManager().getTask(taskId);
-        if (t == null) {
-            throw WebResourceUtils.notFound("Cannot find task '%s'", taskId);
-        }
-        checkEntityEntitled(t);
+        Task<?> t = findTask(taskId);
 
         Set<TaskSummary> result = MutableSet.copyOf(getSubTaskChildren(t));
         if (Boolean.TRUE.equals(includeBackground)) {
@@ -118,11 +115,7 @@ public class ActivityResource extends AbstractBrooklynRestResource implements
Ac
 
     @Override
     public String stream(String taskId, String streamId) {
-        Task<?> t = mgmt().getExecutionManager().getTask(taskId);
-        if (t == null) {
-            throw WebResourceUtils.notFound("Cannot find task '%s'", taskId);
-        }
-        checkEntityEntitled(t);
+        Task<?> t = findTask(taskId);
         checkStreamEntitled(t, streamId);
 
         WrappedStream stream = BrooklynTaskTags.stream(t, streamId);


Mime
View raw message