Remove DMF API dependency from security integration (#604)
* Dmf security token out of API. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Allow to override dispatching routines. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * TargetAssign event is bulk ready. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Completed Javadoc. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * readibility and fix serialization bug. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fix sonar issue. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Simplify artifact management usage. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -407,7 +407,8 @@ public interface DeploymentManagement {
|
||||
* @return the amount of started actions
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
long startScheduledActionsByRolloutGroupParent(@NotNull Long rolloutId, Long rolloutGroupParentId);
|
||||
long startScheduledActionsByRolloutGroupParent(@NotNull Long rolloutId, @NotNull Long distributionSetId,
|
||||
Long rolloutGroupParentId);
|
||||
|
||||
/**
|
||||
* All {@link ActionStatus} entries in the repository.
|
||||
|
||||
@@ -8,15 +8,13 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
/**
|
||||
* TenantAwareEvent that gets sent when a distribution set gets assigned to a
|
||||
@@ -26,13 +24,9 @@ public class TargetAssignDistributionSetEvent extends RemoteTenantAwareEvent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long actionId;
|
||||
private long distributionSetId;
|
||||
|
||||
private Long distributionSetId;
|
||||
|
||||
private String controllerId;
|
||||
|
||||
private transient Collection<SoftwareModule> modules;
|
||||
private final Map<String, Long> actions = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
@@ -43,61 +37,35 @@ public class TargetAssignDistributionSetEvent extends RemoteTenantAwareEvent {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param action
|
||||
* the action
|
||||
*
|
||||
* @param tenant
|
||||
* of the event
|
||||
* @param distributionSetId
|
||||
* of the set that was assigned
|
||||
* @param a
|
||||
* the actions and the targets
|
||||
* @param applicationId
|
||||
* the application id.
|
||||
*/
|
||||
public TargetAssignDistributionSetEvent(final Action action, final String applicationId) {
|
||||
this(action.getTenant(), action.getId(), action.getDistributionSet().getId(),
|
||||
action.getTarget().getControllerId(), applicationId);
|
||||
this.modules = action.getDistributionSet().getModules();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param tenant
|
||||
* the event belongs to
|
||||
* @param actionId
|
||||
* to the action
|
||||
* @param distributionSetId
|
||||
* of the assigned {@link DistributionSet}
|
||||
* @param controllerId
|
||||
* of the assignment {@link Target}
|
||||
* @param applicationId
|
||||
*/
|
||||
public TargetAssignDistributionSetEvent(final String tenant, final Long actionId, final Long distributionSetId,
|
||||
final String controllerId, final String applicationId) {
|
||||
super(actionId, tenant, applicationId);
|
||||
this.actionId = actionId;
|
||||
public TargetAssignDistributionSetEvent(final String tenant, final long distributionSetId, final List<Action> a,
|
||||
final String applicationId) {
|
||||
super(distributionSetId, tenant, applicationId);
|
||||
this.distributionSetId = distributionSetId;
|
||||
this.controllerId = controllerId;
|
||||
actions.putAll(a.stream().filter(action -> action.getDistributionSet().getId().longValue() == distributionSetId)
|
||||
.collect(Collectors.toMap(action -> action.getTarget().getControllerId(), Action::getId)));
|
||||
|
||||
}
|
||||
|
||||
public Long getActionId() {
|
||||
return actionId;
|
||||
}
|
||||
|
||||
public String getControllerId() {
|
||||
return controllerId;
|
||||
public TargetAssignDistributionSetEvent(final Action action, final String applicationId) {
|
||||
this(action.getTenant(), action.getDistributionSet().getId(), Arrays.asList(action), applicationId);
|
||||
}
|
||||
|
||||
public Long getDistributionSetId() {
|
||||
return distributionSetId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return modules if Event has been published by same node otherwise empty.
|
||||
*/
|
||||
@JsonIgnore
|
||||
public Collection<SoftwareModule> getModules() {
|
||||
if (modules == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return modules;
|
||||
public Map<String, Long> getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.springframework.util.MimeType;
|
||||
|
||||
import io.protostuff.LinkedBuffer;
|
||||
import io.protostuff.ProtobufIOUtil;
|
||||
import io.protostuff.ProtostuffIOUtil;
|
||||
import io.protostuff.Schema;
|
||||
import io.protostuff.runtime.RuntimeSchema;
|
||||
|
||||
@@ -127,7 +126,7 @@ public class BusProtoStuffMessageConverter extends AbstractMessageConverter {
|
||||
@SuppressWarnings("unchecked")
|
||||
final Schema<Object> schema = (Schema<Object>) RuntimeSchema.getSchema(serializeClass);
|
||||
final LinkedBuffer buffer = LinkedBuffer.allocate();
|
||||
return writeProtoBuf(payload, schema, buffer);
|
||||
return ProtobufIOUtil.toByteArray(payload, schema, buffer);
|
||||
}
|
||||
|
||||
private static byte[] writeClassHeader(final Class<?> clazz) {
|
||||
@@ -140,17 +139,6 @@ public class BusProtoStuffMessageConverter extends AbstractMessageConverter {
|
||||
final Schema<Object> schema = (Schema<Object>) RuntimeSchema
|
||||
.getSchema((Class<? extends Object>) EventType.class);
|
||||
final LinkedBuffer buffer = LinkedBuffer.allocate();
|
||||
return writeProtoBuf(clazzEventType, schema, buffer);
|
||||
}
|
||||
|
||||
private static byte[] writeProtoBuf(final Object payload, final Schema<Object> schema, final LinkedBuffer buffer) {
|
||||
final byte[] serializeByte;
|
||||
try {
|
||||
serializeByte = ProtostuffIOUtil.toByteArray(payload, schema, buffer);
|
||||
} finally {
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
return serializeByte;
|
||||
return ProtobufIOUtil.toByteArray(clazzEventType, schema, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* {@link DistributionSet} to {@link Target} assignment strategy as utility for
|
||||
@@ -109,6 +110,8 @@ public abstract class AbstractDsAssignmentStrategy {
|
||||
/**
|
||||
* Handles event sending related to the assignment.
|
||||
*
|
||||
* @param set
|
||||
* that has been assigned
|
||||
* @param targets
|
||||
* to send events for
|
||||
* @param targetIdsCancelList
|
||||
@@ -117,12 +120,17 @@ public abstract class AbstractDsAssignmentStrategy {
|
||||
* mapping of {@link Target#getControllerId()} to new
|
||||
* {@link Action} that was created as part of the assignment.
|
||||
*/
|
||||
abstract void sendAssignmentEvents(final List<JpaTarget> targets, final Set<Long> targetIdsCancelList,
|
||||
final Map<String, JpaAction> controllerIdsToActions);
|
||||
abstract void sendAssignmentEvents(DistributionSet set, final List<JpaTarget> targets,
|
||||
final Set<Long> targetIdsCancelList, final Map<String, JpaAction> controllerIdsToActions);
|
||||
|
||||
protected void sendTargetAssignDistributionSetEvent(final Action action) {
|
||||
afterCommit.afterCommit(() -> eventPublisher
|
||||
.publishEvent(new TargetAssignDistributionSetEvent(action, applicationContext.getId())));
|
||||
protected void sendTargetAssignDistributionSetEvent(final String tenant, final long distributionSetId,
|
||||
final List<Action> actions) {
|
||||
if (CollectionUtils.isEmpty(actions)) {
|
||||
return;
|
||||
}
|
||||
|
||||
afterCommit.afterCommit(() -> eventPublisher.publishEvent(
|
||||
new TargetAssignDistributionSetEvent(tenant, distributionSetId, actions, applicationContext.getId())));
|
||||
}
|
||||
|
||||
protected void sendTargetUpdatedEvent(final JpaTarget target) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
@@ -24,7 +25,6 @@ import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.JoinType;
|
||||
import javax.persistence.criteria.ListJoin;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
@@ -80,6 +80,7 @@ import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -306,7 +307,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
// detaching as the entity has been updated by the JPQL query above
|
||||
targets.forEach(entityManager::detach);
|
||||
|
||||
assignmentStrategy.sendAssignmentEvents(targets, targetIdsCancellList, targetIdsToActions);
|
||||
assignmentStrategy.sendAssignmentEvents(set, targets, targetIdsCancellList, targetIdsToActions);
|
||||
|
||||
return new DistributionSetAssignmentResult(
|
||||
targets.stream().map(Target::getControllerId).collect(Collectors.toList()), targets.size(),
|
||||
@@ -373,13 +374,13 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long startScheduledActionsByRolloutGroupParent(@NotNull final Long rolloutId,
|
||||
public long startScheduledActionsByRolloutGroupParent(final Long rolloutId, final Long distributionSetId,
|
||||
final Long rolloutGroupParentId) {
|
||||
long totalActionsCount = 0L;
|
||||
long lastStartedActionsCount;
|
||||
do {
|
||||
lastStartedActionsCount = startScheduledActionsByRolloutGroupParentInNewTransaction(rolloutId,
|
||||
rolloutGroupParentId, ACTION_PAGE_LIMIT);
|
||||
distributionSetId, rolloutGroupParentId, ACTION_PAGE_LIMIT);
|
||||
totalActionsCount += lastStartedActionsCount;
|
||||
} while (lastStartedActionsCount > 0);
|
||||
|
||||
@@ -387,7 +388,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
}
|
||||
|
||||
private long startScheduledActionsByRolloutGroupParentInNewTransaction(final Long rolloutId,
|
||||
final Long rolloutGroupParentId, final int limit) {
|
||||
final Long distributionSetId, final Long rolloutGroupParentId, final int limit) {
|
||||
final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
||||
def.setName("startScheduledActions-" + rolloutId);
|
||||
def.setReadOnly(false);
|
||||
@@ -396,7 +397,21 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
final Page<Action> rolloutGroupActions = findActionsByRolloutAndRolloutGroupParent(rolloutId,
|
||||
rolloutGroupParentId, limit);
|
||||
|
||||
rolloutGroupActions.map(action -> (JpaAction) action).forEach(this::startScheduledAction);
|
||||
if (rolloutGroupActions.getContent().isEmpty()) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
final String tenant = rolloutGroupActions.getContent().get(0).getTenant();
|
||||
|
||||
final List<Action> targetAssignments = rolloutGroupActions.getContent().stream()
|
||||
.map(action -> (JpaAction) action).map(this::closeActionIfSetWasAlreadyAssigned)
|
||||
.filter(Objects::nonNull).map(this::startScheduledActionIfNoCancelationHasToBeHandledFirst)
|
||||
.filter(Objects::nonNull).collect(Collectors.toList());
|
||||
|
||||
if (!CollectionUtils.isEmpty(targetAssignments)) {
|
||||
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetAssignDistributionSetEvent(tenant,
|
||||
distributionSetId, targetAssignments, applicationContext.getId())));
|
||||
}
|
||||
|
||||
return rolloutGroupActions.getTotalElements();
|
||||
});
|
||||
@@ -415,9 +430,8 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
}
|
||||
}
|
||||
|
||||
private void startScheduledAction(final JpaAction action) {
|
||||
JpaTarget target = (JpaTarget) action.getTarget();
|
||||
|
||||
private JpaAction closeActionIfSetWasAlreadyAssigned(final JpaAction action) {
|
||||
final JpaTarget target = (JpaTarget) action.getTarget();
|
||||
if (target.getAssignedDistributionSet() != null
|
||||
&& action.getDistributionSet().getId().equals(target.getAssignedDistributionSet().getId())) {
|
||||
// the target has already the distribution set assigned, we don't
|
||||
@@ -426,9 +440,13 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
action.setActive(false);
|
||||
setSkipActionStatus(action);
|
||||
actionRepository.save(action);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
private JpaAction startScheduledActionIfNoCancelationHasToBeHandledFirst(final JpaAction action) {
|
||||
// check if we need to override running update actions
|
||||
final List<Long> overrideObsoleteUpdateActions = onlineDsAssignmentStrategy
|
||||
.overrideObsoleteUpdateActions(Collections.singletonList(action.getTarget().getId()));
|
||||
@@ -439,7 +457,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
|
||||
actionStatusRepository.save(onlineDsAssignmentStrategy.createActionStatus(savedAction, null));
|
||||
|
||||
target = (JpaTarget) entityManager.merge(savedAction.getTarget());
|
||||
final JpaTarget target = (JpaTarget) entityManager.merge(savedAction.getTarget());
|
||||
|
||||
target.setAssignedDistributionSet(savedAction.getDistributionSet());
|
||||
target.setUpdateStatus(TargetUpdateStatus.PENDING);
|
||||
@@ -447,10 +465,11 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
|
||||
// in case we canceled an action before for this target, then don't fire
|
||||
// assignment event
|
||||
if (!overrideObsoleteUpdateActions.contains(savedAction.getId())) {
|
||||
afterCommit.afterCommit(() -> eventPublisher
|
||||
.publishEvent(new TargetAssignDistributionSetEvent(savedAction, applicationContext.getId())));
|
||||
if (overrideObsoleteUpdateActions.contains(savedAction.getId())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return savedAction;
|
||||
}
|
||||
|
||||
private void setSkipActionStatus(final JpaAction action) {
|
||||
|
||||
@@ -367,8 +367,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
RolloutGroupStatus.READY, group);
|
||||
|
||||
final long targetsInGroupFilter = runInNewTransaction("countAllTargetsByTargetFilterQueryAndNotInRolloutGroups",
|
||||
count -> targetManagement.countByRsqlAndNotInRolloutGroups(readyGroups,
|
||||
groupTargetFilter));
|
||||
count -> targetManagement.countByRsqlAndNotInRolloutGroups(readyGroups, groupTargetFilter));
|
||||
final long expectedInGroup = Math.round(group.getTargetPercentage() / 100 * (double) targetsInGroupFilter);
|
||||
final long currentlyInGroup = runInNewTransaction("countRolloutTargetGroupByRolloutGroup",
|
||||
count -> rolloutTargetGroupRepository.countByRolloutGroup(group));
|
||||
@@ -408,8 +407,8 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
final PageRequest pageRequest = new PageRequest(0, Math.toIntExact(limit));
|
||||
final List<Long> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout.getRolloutGroups(),
|
||||
RolloutGroupStatus.READY, group);
|
||||
final Page<Target> targets = targetManagement
|
||||
.findByTargetFilterQueryAndNotInRolloutGroups(pageRequest, readyGroups, targetFilter);
|
||||
final Page<Target> targets = targetManagement.findByTargetFilterQueryAndNotInRolloutGroups(pageRequest,
|
||||
readyGroups, targetFilter);
|
||||
|
||||
createAssignmentOfTargetsToGroup(targets, group);
|
||||
|
||||
@@ -461,7 +460,8 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
throw new RolloutIllegalStateException("First Group is not the first group.");
|
||||
}
|
||||
|
||||
deploymentManagement.startScheduledActionsByRolloutGroupParent(rollout.getId(), null);
|
||||
deploymentManagement.startScheduledActionsByRolloutGroupParent(rollout.getId(),
|
||||
rollout.getDistributionSet().getId(), null);
|
||||
|
||||
rolloutGroup.setStatus(RolloutGroupStatus.RUNNING);
|
||||
rolloutGroupRepository.save(rolloutGroup);
|
||||
@@ -530,8 +530,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
final ActionType actionType = rollout.getActionType();
|
||||
final long forceTime = rollout.getForcedTime();
|
||||
|
||||
final Page<Target> targets = targetManagement.findByInRolloutGroupWithoutAction(pageRequest,
|
||||
groupId);
|
||||
final Page<Target> targets = targetManagement.findByInRolloutGroupWithoutAction(pageRequest, groupId);
|
||||
if (targets.getTotalElements() > 0) {
|
||||
createScheduledAction(targets.getContent(), distributionSet, actionType, forceTime, rollout, group);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -48,8 +49,8 @@ public class OfflineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
void sendAssignmentEvents(final List<JpaTarget> targets, final Set<Long> targetIdsCancellList,
|
||||
final Map<String, JpaAction> targetIdsToActions) {
|
||||
void sendAssignmentEvents(final DistributionSet set, final List<JpaTarget> targets,
|
||||
final Set<Long> targetIdsCancellList, final Map<String, JpaAction> targetIdsToActions) {
|
||||
|
||||
targets.forEach(target -> {
|
||||
target.setUpdateStatus(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
@@ -21,7 +21,10 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -44,18 +47,19 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
void sendAssignmentEvents(final List<JpaTarget> targets, final Set<Long> targetIdsCancellList,
|
||||
final Map<String, JpaAction> targetIdsToActions) {
|
||||
void sendAssignmentEvents(final DistributionSet set, final List<JpaTarget> targets,
|
||||
final Set<Long> targetIdsCancellList, final Map<String, JpaAction> targetIdsToActions) {
|
||||
|
||||
targets.forEach(target -> {
|
||||
final List<Action> actions = targets.stream().map(target -> {
|
||||
target.setUpdateStatus(TargetUpdateStatus.PENDING);
|
||||
sendTargetUpdatedEvent(target);
|
||||
if (targetIdsCancellList.contains(target.getId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendTargetAssignDistributionSetEvent(targetIdsToActions.get(target.getControllerId()));
|
||||
});
|
||||
return target;
|
||||
}).filter(target -> !targetIdsCancellList.contains(target.getId())).map(Target::getControllerId)
|
||||
.map(targetIdsToActions::get).collect(Collectors.toList());
|
||||
|
||||
sendTargetAssignDistributionSetEvent(set.getTenant(), set.getId(), actions);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -56,8 +56,8 @@ public class StartNextGroupRolloutGroupSuccessAction implements RolloutGroupActi
|
||||
// retrieve all actions according to the parent group of the finished
|
||||
// rolloutGroup, so retrieve all child-group actions which need to be
|
||||
// started.
|
||||
final long countOfStartedActions = deploymentManagement
|
||||
.startScheduledActionsByRolloutGroupParent(rollout.getId(), rolloutGroup.getId());
|
||||
final long countOfStartedActions = deploymentManagement.startScheduledActionsByRolloutGroupParent(
|
||||
rollout.getId(), rollout.getDistributionSet().getId(), rolloutGroup.getId());
|
||||
logger.debug("{} Next actions started for rollout {} and parent group {}", countOfStartedActions, rollout,
|
||||
rolloutGroup);
|
||||
if (countOfStartedActions > 0) {
|
||||
|
||||
@@ -10,6 +10,10 @@ package org.eclipse.hawkbit.repository.event.remote;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.AbstractMap.SimpleImmutableEntry;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
@@ -50,8 +54,8 @@ public class RemoteTenantAwareEventTest extends AbstractRemoteEventTest {
|
||||
generateAction.setStatus(Status.RUNNING);
|
||||
final Action action = actionRepository.save(generateAction);
|
||||
|
||||
final TargetAssignDistributionSetEvent assignmentEvent = new TargetAssignDistributionSetEvent(action,
|
||||
serviceMatcher.getServiceId());
|
||||
final TargetAssignDistributionSetEvent assignmentEvent = new TargetAssignDistributionSetEvent(
|
||||
action.getTenant(), dsA.getId(), Arrays.asList(action), serviceMatcher.getServiceId());
|
||||
|
||||
TargetAssignDistributionSetEvent underTest = (TargetAssignDistributionSetEvent) createProtoStuffEvent(
|
||||
assignmentEvent);
|
||||
@@ -63,12 +67,11 @@ public class RemoteTenantAwareEventTest extends AbstractRemoteEventTest {
|
||||
|
||||
private void assertTargetAssignDistributionSetEvent(final Action action,
|
||||
final TargetAssignDistributionSetEvent underTest) {
|
||||
assertThat(underTest.getActionId()).isNotNull();
|
||||
assertThat(underTest.getControllerId()).isNotNull();
|
||||
assertThat(underTest.getDistributionSetId()).isNotNull();
|
||||
|
||||
assertThat(underTest.getActionId()).isEqualTo(action.getId());
|
||||
assertThat(underTest.getControllerId()).isEqualTo(action.getTarget().getControllerId());
|
||||
final Entry<String, Long> entry = new SimpleImmutableEntry(action.getTarget().getControllerId(),
|
||||
action.getId());
|
||||
|
||||
assertThat(underTest.getActions()).containsExactly(entry);
|
||||
assertThat(underTest.getDistributionSetId()).isEqualTo(action.getDistributionSet().getId());
|
||||
}
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Test verifies that an assignment with automatic cancelation works correctly even if the update is split into multiple partitions on the database.")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = Constants.MAX_ENTRIES_IN_STATEMENT + 10),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 2 * (Constants.MAX_ENTRIES_IN_STATEMENT + 10)),
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = Constants.MAX_ENTRIES_IN_STATEMENT + 10),
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
|
||||
@Expect(type = ActionCreatedEvent.class, count = 2 * (Constants.MAX_ENTRIES_IN_STATEMENT + 10)),
|
||||
@Expect(type = CancelTargetAssignmentEvent.class, count = Constants.MAX_ENTRIES_IN_STATEMENT + 10),
|
||||
@Expect(type = ActionUpdatedEvent.class, count = Constants.MAX_ENTRIES_IN_STATEMENT + 10),
|
||||
@@ -437,7 +437,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 20), @Expect(type = ActionCreatedEvent.class, count = 20),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 2),
|
||||
@Expect(type = SoftwareModuleCreatedEvent.class, count = 6),
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 10) })
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1) })
|
||||
public void assignedDistributionSet() {
|
||||
final List<String> controllerIds = testdataFactory.createTargets(10).stream().map(Target::getControllerId)
|
||||
.collect(Collectors.toList());
|
||||
@@ -468,7 +468,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = ActionUpdatedEvent.class, count = 10),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 2),
|
||||
@Expect(type = SoftwareModuleCreatedEvent.class, count = 6),
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 20) })
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 2) })
|
||||
public void assigneDistributionSetAndAutoCloseActiveActions() {
|
||||
tenantConfigurationManagement
|
||||
.addOrUpdateConfiguration(TenantConfigurationKey.REPOSITORY_ACTIONS_AUTOCLOSE_ENABLED, true);
|
||||
@@ -517,7 +517,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Simple deployment or distribution set to target assignment test.")
|
||||
public void assignDistributionSet2Targets() throws InterruptedException {
|
||||
eventHandlerStub.setExpectedNumberOfEvents(20);
|
||||
eventHandlerStub.setExpectedNumberOfEvents(1);
|
||||
|
||||
final String myCtrlIDPref = "myCtrlID";
|
||||
final Iterable<Target> savedNakedTargets = testdataFactory.createTargets(10, myCtrlIDPref, "first description");
|
||||
@@ -595,7 +595,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet nowComplete = distributionSetManagement.assignSoftwareModules(incomplete.getId(),
|
||||
Sets.newHashSet(os.getId()));
|
||||
|
||||
eventHandlerStub.setExpectedNumberOfEvents(10);
|
||||
eventHandlerStub.setExpectedNumberOfEvents(1);
|
||||
|
||||
assertThat(assignDistributionSet(nowComplete, targets).getAssigned()).as("assign ds doesn't work")
|
||||
.isEqualTo(10);
|
||||
@@ -606,6 +606,14 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Multiple deployments or distribution set to target assignment test. Expected behaviour is that a new deployment "
|
||||
+ "overides unfinished old one which are canceled as part of the operation.")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 5 + 4),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 3 * 4),
|
||||
@Expect(type = ActionCreatedEvent.class, count = 3 * 4),
|
||||
@Expect(type = ActionUpdatedEvent.class, count = 4 * 2),
|
||||
@Expect(type = CancelTargetAssignmentEvent.class, count = 4 * 2),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 3),
|
||||
@Expect(type = SoftwareModuleCreatedEvent.class, count = 9),
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1) })
|
||||
public void mutipleDeployments() throws InterruptedException {
|
||||
final String undeployedTargetPrefix = "undep-T";
|
||||
final int noOfUndeployedTargets = 5;
|
||||
@@ -615,8 +623,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final int noOfDistributionSets = 3;
|
||||
|
||||
// Each of the four targets get one assignment (4 * 1 = 4)
|
||||
final int expectedNumberOfEventsForAssignment = 4;
|
||||
// One assigment per DS
|
||||
final int expectedNumberOfEventsForAssignment = 1;
|
||||
eventHandlerStub.setExpectedNumberOfEvents(expectedNumberOfEventsForAssignment);
|
||||
|
||||
// Each of the four targets get two more assignment the which are
|
||||
@@ -641,10 +649,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// only records retrieved from the DB can be evaluated to be sure that
|
||||
// all fields are
|
||||
// populated;
|
||||
final Iterable<JpaTarget> allFoundTargets = targetRepository.findAll();
|
||||
final List<JpaTarget> allFoundTargets = targetRepository.findAll();
|
||||
|
||||
final Iterable<JpaTarget> deployedTargetsFromDB = targetRepository.findAll(deployedTargetIDs);
|
||||
final Iterable<JpaTarget> undeployedTargetsFromDB = targetRepository.findAll(undeployedTargetIDs);
|
||||
final List<JpaTarget> deployedTargetsFromDB = targetRepository.findAll(deployedTargetIDs);
|
||||
final List<JpaTarget> undeployedTargetsFromDB = targetRepository.findAll(undeployedTargetIDs);
|
||||
|
||||
// test that number of Targets
|
||||
assertThat(allFoundTargets.spliterator().getExactSizeIfKnown()).as("number of target is wrong")
|
||||
@@ -1029,33 +1037,23 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
deployedTargets = assignDistributionSet(ds, deployedTargets).getAssignedEntity();
|
||||
}
|
||||
|
||||
final DeploymentResult deploymentResult = new DeploymentResult(deployedTargets, nakedTargets, dsList,
|
||||
deployedTargetPrefix, undeployedTargetPrefix, distributionSetPrefix);
|
||||
return deploymentResult;
|
||||
return new DeploymentResult(deployedTargets, nakedTargets, dsList, deployedTargetPrefix, undeployedTargetPrefix,
|
||||
distributionSetPrefix);
|
||||
|
||||
}
|
||||
|
||||
private void assertTargetAssignDistributionSetEvents(final List<Target> targets, final DistributionSet ds,
|
||||
final List<TargetAssignDistributionSetEvent> events) {
|
||||
assertThat(events).isNotEmpty();
|
||||
for (final Target myt : targets) {
|
||||
boolean found = false;
|
||||
for (final TargetAssignDistributionSetEvent event : events) {
|
||||
if (event.getControllerId().equals(myt.getControllerId())) {
|
||||
found = true;
|
||||
final List<Action> activeActionsByTarget = deploymentManagement
|
||||
.findActiveActionsByTarget(PAGE, myt.getControllerId()).getContent();
|
||||
assertThat(activeActionsByTarget).as("size of active actions for target is wrong").isNotEmpty();
|
||||
assertThat(event.getActionId()).as("Action id in database and event do not match")
|
||||
.isEqualTo(activeActionsByTarget.get(0).getId());
|
||||
assertThat(events).hasSize(1);
|
||||
final TargetAssignDistributionSetEvent event = events.get(0);
|
||||
assertThat(event).isNotNull();
|
||||
assertThat(event.getDistributionSetId()).isEqualTo(ds.getId());
|
||||
|
||||
assertThat(distributionSetManagement.get(event.getDistributionSetId()).get().getModules())
|
||||
.as("softwaremodule size is not correct")
|
||||
.containsOnly(ds.getModules().toArray(new SoftwareModule[ds.getModules().size()]));
|
||||
}
|
||||
}
|
||||
assertThat(found).as("No event found for controller " + myt.getControllerId()).isTrue();
|
||||
}
|
||||
assertThat(event.getActions()).isEqualTo(targets.stream()
|
||||
.map(target -> deploymentManagement.findActiveActionsByTarget(PAGE, target.getControllerId())
|
||||
.getContent())
|
||||
.flatMap(List::stream)
|
||||
.collect(Collectors.toMap(action -> action.getTarget().getControllerId(), Action::getId)));
|
||||
}
|
||||
|
||||
private class DeploymentResult {
|
||||
|
||||
@@ -164,8 +164,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
amountOtherTargets, amountGroups, successCondition, errorCondition);
|
||||
|
||||
// verify the split of the target and targetGroup
|
||||
final Page<RolloutGroup> rolloutGroups = rolloutGroupManagement
|
||||
.findByRollout(PAGE, createdRollout.getId());
|
||||
final Page<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(PAGE, createdRollout.getId());
|
||||
// we have total of #amountTargetsForRollout in rollouts splitted in
|
||||
// group size #groupSize
|
||||
assertThat(rolloutGroups).hasSize(amountGroups);
|
||||
@@ -183,8 +182,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
successCondition, errorCondition);
|
||||
|
||||
// verify first group is running
|
||||
final RolloutGroup firstGroup = rolloutGroupManagement.findByRollout(new OffsetBasedPageRequest(0, 1, new Sort(Direction.ASC, "id")),
|
||||
createdRollout.getId()).getContent().get(0);
|
||||
final RolloutGroup firstGroup = rolloutGroupManagement
|
||||
.findByRollout(new OffsetBasedPageRequest(0, 1, new Sort(Direction.ASC, "id")), createdRollout.getId())
|
||||
.getContent().get(0);
|
||||
assertThat(firstGroup.getStatus()).isEqualTo(RolloutGroupStatus.RUNNING);
|
||||
|
||||
// verify other groups are scheduled
|
||||
@@ -224,15 +224,17 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
// verify that now the first and the second group are in running state
|
||||
final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement.findByRollout(
|
||||
new OffsetBasedPageRequest(0, 2, new Sort(Direction.ASC, "id")), createdRollout.getId()).getContent();
|
||||
final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement
|
||||
.findByRollout(new OffsetBasedPageRequest(0, 2, new Sort(Direction.ASC, "id")), createdRollout.getId())
|
||||
.getContent();
|
||||
runningRolloutGroups.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.RUNNING)
|
||||
.as("group should be in running state because it should be started but it is in " + group.getStatus()
|
||||
+ " state"));
|
||||
|
||||
// verify that the other groups are still in schedule state
|
||||
final List<RolloutGroup> scheduledRolloutGroups = rolloutGroupManagement.findByRollout(
|
||||
new OffsetBasedPageRequest(2, 10, new Sort(Direction.ASC, "id")), createdRollout.getId()).getContent();
|
||||
final List<RolloutGroup> scheduledRolloutGroups = rolloutGroupManagement
|
||||
.findByRollout(new OffsetBasedPageRequest(2, 10, new Sort(Direction.ASC, "id")), createdRollout.getId())
|
||||
.getContent();
|
||||
scheduledRolloutGroups.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.SCHEDULED)
|
||||
.as("group should be in scheduled state because it should not be started but it is in "
|
||||
+ group.getStatus() + " state"));
|
||||
@@ -293,8 +295,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Step("Check the status of the rollout groups, second group should be in running status")
|
||||
private void checkSecondGroupStatusIsRunning(final Rollout createdRollout) {
|
||||
rolloutManagement.handleRollouts();
|
||||
final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement.findByRollout(
|
||||
new OffsetBasedPageRequest(0, 10, new Sort(Direction.ASC, "id")), createdRollout.getId()).getContent();
|
||||
final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement
|
||||
.findByRollout(new OffsetBasedPageRequest(0, 10, new Sort(Direction.ASC, "id")), createdRollout.getId())
|
||||
.getContent();
|
||||
assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
|
||||
assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING);
|
||||
assertThat(runningRolloutGroups.get(2).getStatus()).isEqualTo(RolloutGroupStatus.SCHEDULED);
|
||||
@@ -330,8 +333,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
|
||||
assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
|
||||
assertThat(runningRolloutGroups.get(2).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
|
||||
assertThat(rolloutManagement.get(createdRollout.getId()).get().getStatus())
|
||||
.isEqualTo(RolloutStatus.FINISHED);
|
||||
assertThat(rolloutManagement.get(createdRollout.getId()).get().getStatus()).isEqualTo(RolloutStatus.FINISHED);
|
||||
|
||||
}
|
||||
|
||||
@@ -370,8 +372,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(rollout.getStatus()).isEqualTo(RolloutStatus.PAUSED);
|
||||
|
||||
// the first rollout group should be in error state
|
||||
final List<RolloutGroup> errorGroup = rolloutGroupManagement.findByRollout(
|
||||
new OffsetBasedPageRequest(0, 1, new Sort(Direction.ASC, "id")), createdRollout.getId()).getContent();
|
||||
final List<RolloutGroup> errorGroup = rolloutGroupManagement
|
||||
.findByRollout(new OffsetBasedPageRequest(0, 1, new Sort(Direction.ASC, "id")), createdRollout.getId())
|
||||
.getContent();
|
||||
assertThat(errorGroup).hasSize(1);
|
||||
assertThat(errorGroup.get(0).getStatus()).isEqualTo(RolloutGroupStatus.ERROR);
|
||||
|
||||
@@ -418,15 +421,15 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.resumeRollout(createdRollout.getId());
|
||||
|
||||
// the rollout should be running again
|
||||
assertThat(rolloutManagement.get(createdRollout.getId()).get().getStatus())
|
||||
.isEqualTo(RolloutStatus.RUNNING);
|
||||
assertThat(rolloutManagement.get(createdRollout.getId()).get().getStatus()).isEqualTo(RolloutStatus.RUNNING);
|
||||
|
||||
// checking rollouts again
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
// next group should be running again after resuming the rollout
|
||||
final List<RolloutGroup> resumedGroups = rolloutGroupManagement.findByRollout(
|
||||
new OffsetBasedPageRequest(1, 1, new Sort(Direction.ASC, "id")), createdRollout.getId()).getContent();
|
||||
final List<RolloutGroup> resumedGroups = rolloutGroupManagement
|
||||
.findByRollout(new OffsetBasedPageRequest(1, 1, new Sort(Direction.ASC, "id")), createdRollout.getId())
|
||||
.getContent();
|
||||
assertThat(resumedGroups).hasSize(1);
|
||||
assertThat(resumedGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING);
|
||||
}
|
||||
@@ -590,8 +593,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
// round(5/2)=3 targets SCHEDULED (Group 3)
|
||||
// round(2/1)=2 targets SCHEDULED (Group 4)
|
||||
createdRollout = rolloutManagement.get(createdRollout.getId()).get();
|
||||
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement
|
||||
.findByRollout(PAGE, createdRollout.getId()).getContent();
|
||||
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(PAGE, createdRollout.getId())
|
||||
.getContent();
|
||||
|
||||
Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
|
||||
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.FINISHED, 2L);
|
||||
@@ -630,9 +633,10 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(runningActions.size()).isEqualTo(5);
|
||||
|
||||
// 5 targets are in the group and the DS has been assigned
|
||||
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement
|
||||
.findByRollout(PAGE, createdRollout.getId()).getContent();
|
||||
final Page<Target> targets = rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE, rolloutGroups.get(0).getId());
|
||||
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(PAGE, createdRollout.getId())
|
||||
.getContent();
|
||||
final Page<Target> targets = rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE,
|
||||
rolloutGroups.get(0).getId());
|
||||
final List<Target> targetList = targets.getContent();
|
||||
assertThat(targetList.size()).isEqualTo(5);
|
||||
|
||||
@@ -769,8 +773,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3);
|
||||
rolloutManagement.handleRollouts();
|
||||
// verify: 40% error but 60% finished -> should move to next group
|
||||
final List<RolloutGroup> rolloutGruops = rolloutGroupManagement
|
||||
.findByRollout(PAGE, rolloutOne.getId()).getContent();
|
||||
final List<RolloutGroup> rolloutGruops = rolloutGroupManagement.findByRollout(PAGE, rolloutOne.getId())
|
||||
.getContent();
|
||||
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
|
||||
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 5L);
|
||||
validateRolloutGroupActionStatus(rolloutGruops.get(1), expectedTargetCountStatus);
|
||||
@@ -795,8 +799,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.handleRollouts();
|
||||
// verify: 40% error and 60% finished -> should not move to next group
|
||||
// because successCondition 80%
|
||||
final List<RolloutGroup> rolloutGruops = rolloutGroupManagement
|
||||
.findByRollout(PAGE, rolloutOne.getId()).getContent();
|
||||
final List<RolloutGroup> rolloutGruops = rolloutGroupManagement.findByRollout(PAGE, rolloutOne.getId())
|
||||
.getContent();
|
||||
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
|
||||
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.SCHEDULED, 5L);
|
||||
validateRolloutGroupActionStatus(rolloutGruops.get(1), expectedTargetCountStatus);
|
||||
@@ -868,8 +872,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
changeStatusForAllRunningActions(rolloutD, Status.FINISHED);
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
final Page<Rollout> rolloutPage = rolloutManagement.findAllWithDetailedStatus(
|
||||
new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "name")), false);
|
||||
final Page<Rollout> rolloutPage = rolloutManagement
|
||||
.findAllWithDetailedStatus(new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "name")), false);
|
||||
final List<Rollout> rolloutList = rolloutPage.getContent();
|
||||
|
||||
// validate rolloutA -> 6 running and 6 ready
|
||||
@@ -1003,8 +1007,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
myRollout = rolloutManagement.get(myRollout.getId()).get();
|
||||
|
||||
float percent = rolloutGroupManagement
|
||||
.getWithDetailedStatus(rolloutGroupManagement
|
||||
.findByRollout(PAGE, myRollout.getId()).getContent().get(0).getId())
|
||||
.getWithDetailedStatus(
|
||||
rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()).getContent().get(0).getId())
|
||||
.get().getTotalTargetCountStatus().getFinishedPercent();
|
||||
assertThat(percent).isEqualTo(40);
|
||||
|
||||
@@ -1012,8 +1016,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
percent = rolloutGroupManagement
|
||||
.getWithDetailedStatus(rolloutGroupManagement
|
||||
.findByRollout(PAGE, myRollout.getId()).getContent().get(0).getId())
|
||||
.getWithDetailedStatus(
|
||||
rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()).getContent().get(0).getId())
|
||||
.get().getTotalTargetCountStatus().getFinishedPercent();
|
||||
assertThat(percent).isEqualTo(100);
|
||||
|
||||
@@ -1022,8 +1026,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
percent = rolloutGroupManagement
|
||||
.getWithDetailedStatus(rolloutGroupManagement
|
||||
.findByRollout(PAGE, myRollout.getId()).getContent().get(1).getId())
|
||||
.getWithDetailedStatus(
|
||||
rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()).getContent().get(1).getId())
|
||||
.get().getTotalTargetCountStatus().getFinishedPercent();
|
||||
assertThat(percent).isEqualTo(80);
|
||||
}
|
||||
@@ -1054,25 +1058,25 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
"Target belongs into rollout");
|
||||
|
||||
myRollout = rolloutManagement.get(myRollout.getId()).get();
|
||||
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement
|
||||
.findByRollout(PAGE, myRollout.getId()).getContent();
|
||||
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(PAGE, myRollout.getId())
|
||||
.getContent();
|
||||
|
||||
Page<Target> targetPage = rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(new OffsetBasedPageRequest(0, 100),
|
||||
rolloutGroups.get(0).getId(), rsqlParam);
|
||||
Page<Target> targetPage = rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(
|
||||
new OffsetBasedPageRequest(0, 100), rolloutGroups.get(0).getId(), rsqlParam);
|
||||
final List<Target> targetlistGroup1 = targetPage.getContent();
|
||||
assertThat(targetlistGroup1.size()).isEqualTo(5);
|
||||
assertThat(targetlistGroup1.stream().map(Target::getControllerId).collect(Collectors.toList()))
|
||||
.are(targetBelongsInRollout);
|
||||
|
||||
targetPage = rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(new OffsetBasedPageRequest(0, 100), rolloutGroups.get(1).getId(),
|
||||
rsqlParam);
|
||||
targetPage = rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(new OffsetBasedPageRequest(0, 100),
|
||||
rolloutGroups.get(1).getId(), rsqlParam);
|
||||
final List<Target> targetlistGroup2 = targetPage.getContent();
|
||||
assertThat(targetlistGroup2.size()).isEqualTo(5);
|
||||
assertThat(targetlistGroup2.stream().map(Target::getControllerId).collect(Collectors.toList()))
|
||||
.are(targetBelongsInRollout);
|
||||
|
||||
targetPage = rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(new OffsetBasedPageRequest(0, 100), rolloutGroups.get(2).getId(),
|
||||
rsqlParam);
|
||||
targetPage = rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(new OffsetBasedPageRequest(0, 100),
|
||||
rolloutGroups.get(2).getId(), rsqlParam);
|
||||
final List<Target> targetlistGroup3 = targetPage.getContent();
|
||||
assertThat(targetlistGroup3.size()).isEqualTo(5);
|
||||
assertThat(targetlistGroup3.stream().map(Target::getControllerId).collect(Collectors.toList()))
|
||||
@@ -1135,8 +1139,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
|
||||
|
||||
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(PAGE, myRollout.getId())
|
||||
.getContent();
|
||||
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()).getContent();
|
||||
|
||||
assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY);
|
||||
assertThat(groups.get(0).getTotalTargets()).isEqualTo(1);
|
||||
@@ -1228,8 +1231,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
|
||||
|
||||
// schedule rollout auto start into the future
|
||||
rolloutManagement.update(
|
||||
entityFactory.rollout().update(myRollout.getId()).startAt(System.currentTimeMillis() + 60000));
|
||||
rolloutManagement
|
||||
.update(entityFactory.rollout().update(myRollout.getId()).startAt(System.currentTimeMillis() + 60000));
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
// rollout should not have been started
|
||||
@@ -1237,8 +1240,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
|
||||
|
||||
// schedule to now
|
||||
rolloutManagement
|
||||
.update(entityFactory.rollout().update(myRollout.getId()).startAt(System.currentTimeMillis()));
|
||||
rolloutManagement.update(entityFactory.rollout().update(myRollout.getId()).startAt(System.currentTimeMillis()));
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
myRollout = rolloutManagement.get(myRollout.getId()).get();
|
||||
@@ -1292,8 +1294,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
myRollout = rolloutManagement.get(myRollout.getId()).get();
|
||||
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING);
|
||||
for (final RolloutGroup group : rolloutGroupManagement.findByRollout(PAGE, myRollout.getId())
|
||||
.getContent()) {
|
||||
for (final RolloutGroup group : rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()).getContent()) {
|
||||
assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.CREATING);
|
||||
}
|
||||
|
||||
@@ -1308,8 +1309,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
|
||||
assertThat(myRollout.getTotalTargets()).isEqualTo(amountTargetsInGroup1and2 + amountTargetsInGroup1);
|
||||
|
||||
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(PAGE, myRollout.getId())
|
||||
.getContent();
|
||||
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()).getContent();
|
||||
;
|
||||
assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY);
|
||||
assertThat(groups.get(0).getTotalTargets()).isEqualTo(amountTargetsInGroup1);
|
||||
@@ -1446,7 +1446,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = RolloutUpdatedEvent.class, count = 6),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
||||
@Expect(type = TargetCreatedEvent.class, count = 25), @Expect(type = TargetUpdatedEvent.class, count = 2),
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 2),
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
|
||||
@Expect(type = RolloutGroupCreatedEvent.class, count = 5),
|
||||
@Expect(type = RolloutGroupDeletedEvent.class, count = 5),
|
||||
@Expect(type = ActionCreatedEvent.class, count = 10), @Expect(type = ActionUpdatedEvent.class, count = 2),
|
||||
@@ -1485,8 +1485,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(rolloutManagement.findAll(PAGE, true).getContent()).hasSize(1);
|
||||
assertThat(rolloutManagement.findAll(PAGE, false).getContent()).hasSize(0);
|
||||
assertThat(rolloutGroupManagement.findByRolloutWithDetailedStatus(PAGE, createdRollout.getId())
|
||||
.getContent()).hasSize(amountGroups);
|
||||
assertThat(rolloutGroupManagement.findByRolloutWithDetailedStatus(PAGE, createdRollout.getId()).getContent())
|
||||
.hasSize(amountGroups);
|
||||
|
||||
// verify that all scheduled actions are deleted
|
||||
assertThat(actionRepository.findByRolloutIdAndStatus(PAGE, deletedRollout.getId(), Status.SCHEDULED)
|
||||
@@ -1516,8 +1516,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private void validateRolloutGroupActionStatus(final RolloutGroup rolloutGroup,
|
||||
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus) {
|
||||
final RolloutGroup rolloutGroupWithDetail = rolloutGroupManagement
|
||||
.getWithDetailedStatus(rolloutGroup.getId()).get();
|
||||
final RolloutGroup rolloutGroupWithDetail = rolloutGroupManagement.getWithDetailedStatus(rolloutGroup.getId())
|
||||
.get();
|
||||
validateStatus(rolloutGroupWithDetail.getTotalTargetCountStatus(), expectedTargetCountStatus);
|
||||
}
|
||||
|
||||
|
||||
@@ -132,8 +132,7 @@ public class EventVerifier extends AbstractTestExecutionListener {
|
||||
}
|
||||
|
||||
if (event instanceof TargetAssignDistributionSetEvent) {
|
||||
assertThat(((TargetAssignDistributionSetEvent) event).getActionId()).isNotNull();
|
||||
assertThat(((TargetAssignDistributionSetEvent) event).getControllerId()).isNotEmpty();
|
||||
assertThat(((TargetAssignDistributionSetEvent) event).getActions()).isNotEmpty();
|
||||
assertThat(((TargetAssignDistributionSetEvent) event).getDistributionSetId()).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user