This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
The following commit(s) were added to refs/heads/master by this push:
new 7b22c96ea2 allow workflow to delete themselves without deleting
independent submitted tasks
7b22c96ea2 is described below
commit 7b22c96ea2908b391eb1a355d34f7be56069b4aa
Author: Alex Heneveld <[email protected]>
AuthorDate: Mon Jun 26 21:19:07 2023 +0100
allow workflow to delete themselves without deleting independent submitted
tasks
---
.../store/WorkflowRetentionAndExpiration.java | 2 +-
.../util/core/task/BasicExecutionManager.java | 24 ++++++++++++++--------
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git
a/core/src/main/java/org/apache/brooklyn/core/workflow/store/WorkflowRetentionAndExpiration.java
b/core/src/main/java/org/apache/brooklyn/core/workflow/store/WorkflowRetentionAndExpiration.java
index a71502f4ff..cc0adc5e9b 100644
---
a/core/src/main/java/org/apache/brooklyn/core/workflow/store/WorkflowRetentionAndExpiration.java
+++
b/core/src/main/java/org/apache/brooklyn/core/workflow/store/WorkflowRetentionAndExpiration.java
@@ -154,7 +154,7 @@ public class WorkflowRetentionAndExpiration {
BasicExecutionManager em = ((BasicExecutionManager)
w.getManagementContext().getExecutionManager());
w.getReplays().forEach(wr -> {
Task<?> wrt = em.getTask(wr.getTaskId());
- if (wrt != null) em.deleteTask(wrt, false);
+ if (wrt != null) em.deleteTask(wrt, false, true);
});
}
return removed;
diff --git
a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
index 26756368f1..8a73ad03e9 100644
---
a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
+++
b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
@@ -400,7 +400,7 @@ public class BasicExecutionManager implements
ExecutionManager {
if (tasks != null) {
for (Task<?> task : tasks) {
if (task.isDone(true)) {
- deleteTask(task);
+ deleteTask(task, true, true);
} else {
tagEmpty = false;
}
@@ -415,22 +415,29 @@ public class BasicExecutionManager implements
ExecutionManager {
}
public boolean deleteTask(Task<?> task) {
- return deleteTask(task, true);
+ return deleteTask(task, true, false);
+ }
+ public boolean deleteTask(Task<?> task, boolean
keepByIdIfParentPresentById) {
+ return deleteTask(task, true, false);
}
/** removes all exec manager records of a task, except, if second argument
is true (usually is) keep the pointer to ID
* if its submitter is a parent with an active record to this child.
- * returns true if completely deleted (false if not deleted, or deleted in
byTags map but kept due to parent ID) */
- public boolean deleteTask(Task<?> task, boolean
keepByIdIfParentPresentById) {
- Boolean removed = deleteTaskNonRecursive(task,
keepByIdIfParentPresentById);
- if (!Boolean.TRUE.equals(removed)) return false;
+ * returns true if the task is completely deleted (false if not deleted,
or deleted in byTags map but kept due to parent ID); children may be kept */
+ public boolean deleteTask(Task<?> task, boolean
keepByIdIfParentPresentById, boolean keepActiveTasks) {
+ boolean result = false;
+ if (!keepActiveTasks || task.isDone() || !task.isSubmitted()) {
+ Boolean removed = deleteTaskNonRecursive(task,
keepByIdIfParentPresentById);
+ if (!Boolean.TRUE.equals(removed)) return false;
+ result = true;
+ }
if (task instanceof HasTaskChildren) {
List<Task<?>> children = ImmutableList.copyOf(((HasTaskChildren)
task).getChildren());
for (Task<?> child : children) {
- deleteTask(child, keepByIdIfParentPresentById);
+ deleteTask(child, keepByIdIfParentPresentById,
keepActiveTasks);
}
}
- return true;
+ return result;
}
protected Boolean deleteTaskNonRecursive(Task<?> task) {
@@ -481,6 +488,7 @@ public class BasicExecutionManager implements
ExecutionManager {
if (removedById != null && removedById.isSubmitted() &&
!removedById.isDone(true)) {
Entity context = BrooklynTaskTags.getContextEntity(removedById);
if (context != null && !Entities.isManaged(context)) {
+ // this cautiously only does debug if already unmanaged; will
warn if still unmanaging
log.debug("Deleting active task on unmanagement of " + context
+ ": " + removedById);
} else {
boolean debugOnly = removedById.isDone();