From 613a11a78b21da40cfb10c05ba8a12cc469c41a4 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Fri, 6 Dec 2024 14:40:52 +0200 Subject: [PATCH] Detatch DS in rollout execution in case lasy loaded (#2123) Signed-off-by: Avgustin Marinov --- .../repository/jpa/JpaRolloutExecutor.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java index f4ffbffe3..18d96539f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java @@ -844,14 +844,13 @@ public class JpaRolloutExecutor implements RolloutExecutor { return totalActionsCreated; } - private Long createActionsForTargetsInNewTransaction( - final Rollout rollout, final RolloutGroup group, final int limit) { + private Long createActionsForTargetsInNewTransaction(final Rollout rollout, final RolloutGroup group, final int limit) { return DeploymentHelper.runInNewTransaction(txManager, "createActionsForTargets", status -> { - final Slice targets = - targetManagement.findByInRolloutGroupWithoutAction(PageRequest.of(0, limit), group.getId()); + final Slice targets = targetManagement.findByInRolloutGroupWithoutAction(PageRequest.of(0, limit), group.getId()); if (targets.getNumberOfElements() > 0) { final DistributionSet distributionSet = rollout.getDistributionSet(); + entityManager.detach(distributionSet); // if lazy loaded with different session final ActionType actionType = rollout.getActionType(); final long forceTime = rollout.getForcedTime(); createActions(targets.getContent(), distributionSet, actionType, forceTime, rollout, group); @@ -866,17 +865,13 @@ public class JpaRolloutExecutor implements RolloutExecutor { } /** - * Creates an action entry into the action repository. In case of existing - * scheduled actions the scheduled actions gets canceled. A scheduled action - * is created in-active for static and running for dynamic groups. + * Creates an action entry into the action repository. In case of existing scheduled actions the scheduled actions gets canceled. + * A scheduled action is created in-active for static and running for dynamic groups. */ private List createActions(final Collection targets, final DistributionSet distributionSet, - final ActionType actionType, final Long forcedTime, final Rollout rollout, - final RolloutGroup rolloutGroup) { - // cancel all current scheduled actions for this target. E.g. an action - // is already scheduled and a next action is created then cancel the - // current scheduled action to cancel. E.g. a new scheduled action is - // created. + final ActionType actionType, final Long forcedTime, final Rollout rollout, final RolloutGroup rolloutGroup) { + // cancel all current scheduled actions for this target. E.g. an action is already scheduled and a next action is created + // then cancel the current scheduled action to cancel. E.g. a new scheduled action is created. final List targetIds = targets.stream().map(Target::getId).toList(); deploymentManagement.cancelInactiveScheduledActionsForTargets(targetIds); return targets.stream()