Fix rollout management cancel running action (#466)

* fix cancellation of wrong obsolete action during rollout-mgmt

Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>

* add unit test to verify rollout not cancel running action with same DS

Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
Michael Hirsch
2017-03-31 15:21:26 +02:00
committed by GitHub
parent 85212576c8
commit 09c56f3439
2 changed files with 48 additions and 8 deletions

View File

@@ -254,8 +254,9 @@ public class JpaDeploymentManagement implements DeploymentManagement {
targetIds.forEach(tIds -> targetRepository.setAssignedDistributionSetAndUpdateStatus(TargetUpdateStatus.PENDING,
set, System.currentTimeMillis(), currentUser, tIds));
final Map<String, JpaAction> targetIdsToActions = targets.stream().map(
t -> actionRepository.save(createTargetAction(targetsWithActionMap, t, set, rollout, rolloutGroup)))
final Map<String, JpaAction> targetIdsToActions = targets.stream()
.map(t -> actionRepository
.save(createTargetAction(targetsWithActionMap, t, set, rollout, rolloutGroup)))
.collect(Collectors.toMap(a -> a.getTarget().getControllerId(), Function.identity()));
// create initial action status when action is created so we remember
@@ -465,10 +466,6 @@ public class JpaDeploymentManagement implements DeploymentManagement {
}
private void startScheduledAction(final JpaAction action) {
// check if we need to override running update actions
final Set<Long> overrideObsoleteUpdateActions = overrideObsoleteUpdateActions(
Collections.singletonList(action.getTarget().getId()));
JpaTarget target = (JpaTarget) action.getTarget();
if (target.getAssignedDistributionSet() != null
@@ -482,6 +479,10 @@ public class JpaDeploymentManagement implements DeploymentManagement {
return;
}
// check if we need to override running update actions
final Set<Long> overrideObsoleteUpdateActions = overrideObsoleteUpdateActions(
Collections.singletonList(action.getTarget().getId()));
action.setActive(true);
action.setStatus(Status.RUNNING);
final JpaAction savedAction = actionRepository.save(action);
@@ -669,7 +670,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
final Long totalCount = entityManager.createQuery(countMsgQuery).getSingleResult();
final CriteriaQuery<String> msgQuery = cb.createQuery(String.class);
final Root<JpaActionStatus>as = msgQuery.from(JpaActionStatus.class);
final Root<JpaActionStatus> as = msgQuery.from(JpaActionStatus.class);
final ListJoin<JpaActionStatus, String> join = as.joinList("messages", JoinType.LEFT);
final CriteriaQuery<String> selMsgQuery = msgQuery.select(join);
selMsgQuery.where(cb.equal(as.get(JpaActionStatus_.id), actionStatusId));