Fix sonar findings ... (#1987)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -85,7 +85,6 @@ public class JpaRolloutExecutor implements RolloutExecutor {
|
|||||||
* Max amount of targets that are handled in one transaction.
|
* Max amount of targets that are handled in one transaction.
|
||||||
*/
|
*/
|
||||||
private static final int TRANSACTION_TARGETS = 5_000;
|
private static final int TRANSACTION_TARGETS = 5_000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum amount of actions that are deleted in one transaction.
|
* Maximum amount of actions that are deleted in one transaction.
|
||||||
*/
|
*/
|
||||||
@@ -94,14 +93,16 @@ public class JpaRolloutExecutor implements RolloutExecutor {
|
|||||||
/**
|
/**
|
||||||
* Action statuses that result in a terminated action
|
* Action statuses that result in a terminated action
|
||||||
*/
|
*/
|
||||||
private static final List<Status> DEFAULT_ACTION_TERMINATION_STATUSES = Arrays.asList(Status.ERROR, Status.FINISHED,
|
private static final List<Status> DEFAULT_ACTION_TERMINATION_STATUSES = List.of(
|
||||||
Status.CANCELED);
|
Status.ERROR, Status.FINISHED, Status.CANCELED);
|
||||||
/**
|
/**
|
||||||
* In case of DOWNLOAD_ONLY, actions can be finished with DOWNLOADED status.
|
* In case of DOWNLOAD_ONLY, actions can be finished with DOWNLOADED status.
|
||||||
*/
|
*/
|
||||||
private static final List<Status> DOWNLOAD_ONLY_ACTION_TERMINATION_STATUSES = Arrays.asList(Status.ERROR,
|
private static final List<Status> DOWNLOAD_ONLY_ACTION_TERMINATION_STATUSES = List.of(
|
||||||
Status.FINISHED, Status.CANCELED, Status.DOWNLOADED);
|
Status.ERROR, Status.FINISHED, Status.CANCELED, Status.DOWNLOADED);
|
||||||
private static final Comparator<RolloutGroup> DESC_COMP = Comparator.comparingLong(RolloutGroup::getId).reversed();
|
private static final Comparator<RolloutGroup> DESC_COMP = Comparator.comparingLong(RolloutGroup::getId).reversed();
|
||||||
|
private static final String TRANSACTION_ASSIGNING_TARGETS_TO_ROLLOUT_GROUP_FAILED = "Transaction assigning Targets to RolloutGroup failed";
|
||||||
|
|
||||||
private final ActionRepository actionRepository;
|
private final ActionRepository actionRepository;
|
||||||
private final RolloutGroupRepository rolloutGroupRepository;
|
private final RolloutGroupRepository rolloutGroupRepository;
|
||||||
private final RolloutTargetGroupRepository rolloutTargetGroupRepository;
|
private final RolloutTargetGroupRepository rolloutTargetGroupRepository;
|
||||||
@@ -343,12 +344,10 @@ public class JpaRolloutExecutor implements RolloutExecutor {
|
|||||||
private void handleRunningRollout(final JpaRollout rollout) {
|
private void handleRunningRollout(final JpaRollout rollout) {
|
||||||
log.debug("handleRunningRollout called for rollout {}", rollout.getId());
|
log.debug("handleRunningRollout called for rollout {}", rollout.getId());
|
||||||
|
|
||||||
if (rollout.isDynamic()) {
|
if (rollout.isDynamic() && fillDynamicRolloutGroupsWithTargets(rollout)) {
|
||||||
if (fillDynamicRolloutGroupsWithTargets(rollout)) {
|
|
||||||
log.debug("Dynamic group created for rollout {}", rollout.getId());
|
log.debug("Dynamic group created for rollout {}", rollout.getId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
final List<JpaRolloutGroup> runningGroups =
|
final List<JpaRolloutGroup> runningGroups =
|
||||||
rollout.getRolloutGroups().stream()
|
rollout.getRolloutGroups().stream()
|
||||||
@@ -382,9 +381,9 @@ public class JpaRolloutExecutor implements RolloutExecutor {
|
|||||||
|
|
||||||
if (hasScheduledActions) {
|
if (hasScheduledActions) {
|
||||||
try {
|
try {
|
||||||
final Iterable<JpaAction> iterable = scheduledActions::iterator;
|
final List<Long> actionIds = StreamSupport.stream(scheduledActions.spliterator(), false)
|
||||||
final List<Long> actionIds = StreamSupport.stream(iterable.spliterator(), false).map(Action::getId)
|
.map(Action::getId)
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
actionRepository.deleteByIdIn(actionIds);
|
actionRepository.deleteByIdIn(actionIds);
|
||||||
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher()
|
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher()
|
||||||
.publishEvent(new RolloutUpdatedEvent(rollout, eventPublisherHolder.getApplicationId())));
|
.publishEvent(new RolloutUpdatedEvent(rollout, eventPublisherHolder.getApplicationId())));
|
||||||
@@ -647,7 +646,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
|
|||||||
return rolloutGroupRepository.save(group);
|
return rolloutGroupRepository.save(group);
|
||||||
|
|
||||||
} catch (final TransactionException e) {
|
} catch (final TransactionException e) {
|
||||||
log.warn("Transaction assigning Targets to RolloutGroup failed", e);
|
log.warn(TRANSACTION_ASSIGNING_TARGETS_TO_ROLLOUT_GROUP_FAILED, e);
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -728,7 +727,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (final TransactionException e) {
|
} catch (final TransactionException e) {
|
||||||
log.warn("Transaction assigning Targets to RolloutGroup failed", e);
|
log.warn(TRANSACTION_ASSIGNING_TARGETS_TO_ROLLOUT_GROUP_FAILED, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set to skip for some time
|
// set to skip for some time
|
||||||
@@ -839,7 +838,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
|
|||||||
} while (actionsCreated > 0);
|
} while (actionsCreated > 0);
|
||||||
|
|
||||||
} catch (final TransactionException e) {
|
} catch (final TransactionException e) {
|
||||||
log.warn("Transaction assigning Targets to RolloutGroup failed", e);
|
log.warn(TRANSACTION_ASSIGNING_TARGETS_TO_ROLLOUT_GROUP_FAILED, e);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return totalActionsCreated;
|
return totalActionsCreated;
|
||||||
@@ -878,7 +877,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
|
|||||||
// is already scheduled and a next action is created then cancel the
|
// is already scheduled and a next action is created then cancel the
|
||||||
// current scheduled action to cancel. E.g. a new scheduled action is
|
// current scheduled action to cancel. E.g. a new scheduled action is
|
||||||
// created.
|
// created.
|
||||||
final List<Long> targetIds = targets.stream().map(Target::getId).collect(Collectors.toList());
|
final List<Long> targetIds = targets.stream().map(Target::getId).toList();
|
||||||
deploymentManagement.cancelInactiveScheduledActionsForTargets(targetIds);
|
deploymentManagement.cancelInactiveScheduledActionsForTargets(targetIds);
|
||||||
return targets.stream()
|
return targets.stream()
|
||||||
.map(target -> {
|
.map(target -> {
|
||||||
|
|||||||
@@ -578,7 +578,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.CREATING);
|
RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.CREATING);
|
||||||
RolloutHelper.verifyRolloutGroupConditions(conditions);
|
RolloutHelper.verifyRolloutGroupConditions(conditions);
|
||||||
|
|
||||||
RolloutGroup lastSavedGroup = null;
|
JpaRolloutGroup lastSavedGroup = null;
|
||||||
if (amountOfGroups == 0) {
|
if (amountOfGroups == 0) {
|
||||||
if (dynamicRolloutGroupTemplate == null) {
|
if (dynamicRolloutGroupTemplate == null) {
|
||||||
throw new ConstraintDeclarationException(
|
throw new ConstraintDeclarationException(
|
||||||
|
|||||||
Reference in New Issue
Block a user