From 5fd220a5e3c44346d0d1e75f97121a2432de8b4f Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Sat, 16 Apr 2016 10:42:26 +0200 Subject: [PATCH 1/4] change transaction handling of creating groups and check running Rollouts Signed-off-by: Michael Hirsch --- .../hawkbit/repository/RolloutManagement.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index 1573048ec..6fb2ce0f9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -58,6 +58,8 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.transaction.support.TransactionTemplate; @@ -259,13 +261,7 @@ public class RolloutManagement { entityManager.flush(); executor.execute(() -> { try { - final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); - def.setName("creatingRollout"); - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); - new TransactionTemplate(txManager, def).execute(status -> { - createRolloutGroups(amountGroup, conditions, savedRollout); - return null; - }); + createRolloutGroupsInNewTransaction(amountGroup, conditions, savedRollout); } finally { creatingRollouts.remove(savedRollout.getName()); } @@ -288,6 +284,15 @@ public class RolloutManagement { } } + private Rollout createRolloutGroupsInNewTransaction(final int amountGroup, final RolloutGroupConditions conditions, + final Rollout savedRollout) { + final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); + def.setName("creatingRollout"); + def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); + return new TransactionTemplate(txManager, def) + .execute(status -> createRolloutGroups(amountGroup, conditions, savedRollout)); + } + /** * Method for creating rollout groups and calculating group sizes. Group * sizes are calculated by dividing the total count of targets through the @@ -308,7 +313,8 @@ public class RolloutManagement { int groupIndex = 0; final Long totalCount = savedRollout.getTotalTargets(); final int groupSize = (int) Math.ceil((double) totalCount / (double) amountGroup); - // validate if the amount of groups that will be created are the amount + // validate if the amount of groups that will be created are the + // amount // of groups that the client what's to have created. int amountGroupValidated = amountGroup; final int amountGroupCreation = (int) (Math.ceil((double) totalCount / (double) groupSize)); @@ -540,7 +546,7 @@ public class RolloutManagement { * this check. This check is only applied if the last check is * less than (lastcheck-delay). */ - @Transactional + @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_UNCOMMITTED) @Modifying @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) From f62b740ae8dfd1518910484b9e99d6ffb40a5a32 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 28 Apr 2016 11:43:46 +0200 Subject: [PATCH 2/4] change propagation level to SUPPORTS instead of NOT_SUPPORTED Signed-off-by: Michael Hirsch --- .../java/org/eclipse/hawkbit/repository/SystemManagement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index c1cee7223..be370cf2d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -164,7 +164,7 @@ public class SystemManagement { * @return the {@link CurrentTenantKeyGenerator} */ @Bean - @Transactional(propagation = Propagation.NOT_SUPPORTED) + @Transactional(propagation = Propagation.SUPPORTS) public CurrentTenantKeyGenerator currentTenantKeyGenerator() { return new CurrentTenantKeyGenerator(); } From 30788904be49bb3ab6064f5d6126871e945c2581 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 28 Apr 2016 11:45:06 +0200 Subject: [PATCH 3/4] code cleanup pull-request feedback Signed-off-by: Michael Hirsch --- .../hawkbit/repository/RolloutManagement.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index 6fb2ce0f9..d02b64f35 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -299,7 +299,7 @@ public class RolloutManagement { * amount of given groups. In same cases this will lead to less rollout * groups than given by client. * - * @param amountGroup + * @param amountOfGroups * the amount of groups * @param conditions * the rollout group conditions @@ -307,18 +307,17 @@ public class RolloutManagement { * the rollout * @return the rollout with created groups */ - private Rollout createRolloutGroups(final int amountGroup, final RolloutGroupConditions conditions, + private Rollout createRolloutGroups(final int amountOfGroups, final RolloutGroupConditions conditions, final Rollout savedRollout) { int pageIndex = 0; int groupIndex = 0; final Long totalCount = savedRollout.getTotalTargets(); - final int groupSize = (int) Math.ceil((double) totalCount / (double) amountGroup); - // validate if the amount of groups that will be created are the - // amount + final int groupSize = (int) Math.ceil((double) totalCount / (double) amountOfGroups); + // validate if the amount of groups that will be created are the amount // of groups that the client what's to have created. - int amountGroupValidated = amountGroup; + int amountGroupValidated = amountOfGroups; final int amountGroupCreation = (int) (Math.ceil((double) totalCount / (double) groupSize)); - if (amountGroupCreation == (amountGroup - 1)) { + if (amountGroupCreation == (amountOfGroups - 1)) { amountGroupValidated--; } RolloutGroup lastSavedGroup = null; From 4e48c7c9d7e7d8323e337762560ae47ffb90ad60 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 28 Apr 2016 11:46:01 +0200 Subject: [PATCH 4/4] code cleanup pull-request feedback Signed-off-by: Michael Hirsch --- .../org/eclipse/hawkbit/repository/RolloutManagement.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index d02b64f35..9508a6aeb 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -284,13 +284,13 @@ public class RolloutManagement { } } - private Rollout createRolloutGroupsInNewTransaction(final int amountGroup, final RolloutGroupConditions conditions, + private Rollout createRolloutGroupsInNewTransaction(final int amountOfGroups, final RolloutGroupConditions conditions, final Rollout savedRollout) { final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("creatingRollout"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); return new TransactionTemplate(txManager, def) - .execute(status -> createRolloutGroups(amountGroup, conditions, savedRollout)); + .execute(status -> createRolloutGroups(amountOfGroups, conditions, savedRollout)); } /**