Small Rollout create code improvements (#1754)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-06-26 11:06:56 +03:00
committed by GitHub
parent 4b2c454f1d
commit 494170405a
4 changed files with 39 additions and 58 deletions

View File

@@ -742,7 +742,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
private void createDynamicGroup(final JpaRollout rollout, final RolloutGroup lastGroup, final int groupCount, final RolloutGroupStatus status) {
try {
RolloutHelper.verifyRolloutGroupParameter(groupCount + 1, quotaManagement);
RolloutHelper.verifyRolloutGroupAmount(groupCount + 1, quotaManagement);
} catch (final AssignmentQuotaExceededException e) {
log.warn("Quota exceeded for dynamic rollout group creation: {}. Stop it", e.getMessage());
if (isRolloutComplete(rollout)) {

View File

@@ -199,13 +199,15 @@ public class JpaRolloutManagement implements RolloutManagement {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout create(final RolloutCreate rollout, final int amountGroup, final boolean confirmationRequired,
final RolloutGroupConditions conditions, final DynamicRolloutGroupTemplate dynamicRolloutGroupTemplate) {
if (amountGroup == 0) {
if (amountGroup < 0) {
throw new ValidationException("The amount of groups cannot be lower than or equal to zero for static rollouts");
} else if (amountGroup == 0) {
if (dynamicRolloutGroupTemplate == null) {
throw new ValidationException(
"When amount of groups is 0, the rollouts shall be dynamic and a dynamic group template must be provided");
}
} else {
RolloutHelper.verifyRolloutGroupParameter(amountGroup, quotaManagement);
RolloutHelper.verifyRolloutGroupAmount(amountGroup, quotaManagement);
}
final JpaRollout rolloutRequest = (JpaRollout) rollout.build();
@@ -223,7 +225,10 @@ public class JpaRolloutManagement implements RolloutManagement {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout create(final RolloutCreate rollout, final List<RolloutGroupCreate> groups,
final RolloutGroupConditions conditions) {
RolloutHelper.verifyRolloutGroupParameter(groups.size(), quotaManagement);
if (groups.isEmpty()) {
throw new ValidationException("The amount of groups cannot be 0");
}
RolloutHelper.verifyRolloutGroupAmount(groups.size(), quotaManagement);
final JpaRollout rolloutRequest = (JpaRollout) rollout.build();
final JpaRollout savedRollout = createRollout(rolloutRequest, false);
return createRolloutGroups(groups, conditions, savedRollout);
@@ -329,6 +334,8 @@ public class JpaRolloutManagement implements RolloutManagement {
publishRolloutGroupCreatedEventAfterCommit(lastSavedGroup, rollout);
}
// lastSavedGroup is never null! amountOfGroups > 0 (and has static groups) or dynamicRolloutGroupTemplate is
// not null (validated) and (validated) the rollout is dynamic, so has dynamic group
rollout.setRolloutGroupsCreated(lastSavedGroup.isDynamic() ? amountOfGroups + 1 : amountOfGroups);
return rolloutRepository.save(rollout);
}

View File

@@ -154,7 +154,7 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
// filters for action of the last static group
.filter(action -> Integer.parseInt(action.getTarget().getControllerId().substring(targetPrefix.length())) < amountGroups * 3)
.forEach(this::finishAction);
executeWithoutOneTargetFromAGroup(rollout, dynamic1, 3);
executeWithoutOneTargetFromAGroup(dynamic1, rollout, 3);
assertAndGetRunning(rollout, 1); // remains on in the first dynamic
rolloutHandler.handleAll();
@@ -254,7 +254,7 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
// filters for action of the last static group
.filter(action -> Integer.parseInt(action.getTarget().getControllerId().substring(targetPrefix.length())) < amountGroups * 3)
.forEach(this::finishAction);
executeWithoutOneTargetFromAGroup(rollout, dynamic1, 6);
executeWithoutOneTargetFromAGroup(dynamic1, rollout, 6);
assertAndGetRunning(rollout, 1); // remains on in the first dynamic
rolloutHandler.handleAll();
@@ -339,7 +339,7 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
assertScheduled(rollout, 0);
// executes dynamic1 without 1 target
executeWithoutOneTargetFromAGroup(rollout, dynamic1, 6);
executeWithoutOneTargetFromAGroup(dynamic1, rollout, 6);
assertAndGetRunning(rollout, 1); // remains on in the first dynamic
rolloutHandler.handleAll();
@@ -402,8 +402,7 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
}
}
private void executeWithoutOneTargetFromAGroup(
final Rollout rollout, final RolloutGroup group, final int count) {
private void executeWithoutOneTargetFromAGroup(final RolloutGroup group, final Rollout rollout, final int count) {
// execute groups (without on of the last)
assertThat(refresh(group).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING);
// skip on from the last group only