introduced open actionIds in MgmtTargetAssignmentResponseBody (#864)
* introduced open actionIds in MgmtTargetAssignmentResponseBody Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed SonarQube issues Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * removed unused method parameter Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * updated documentation tests Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * added limit to the alreadyAssignedActions in the AssignmentResult Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * moved alreadyAssignedActions limitation to MgmtDistributionSetMapper Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed review findings Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * removed alreadyAssignedActions Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed sonarQube issues Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed compilation error Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed PR review findings Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed PR review findings Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * Renamed AssignmentResult to AbstractAssignmentResult Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed review findings Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed formatting Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * reverted method visibility Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com>
This commit is contained in:
committed by
Dominic Schabel
parent
973f1952c7
commit
d40b11d2ab
@@ -18,35 +18,24 @@ import java.util.List;
|
||||
* type of the assigned and unassigned {@link BaseEntity}s.
|
||||
*
|
||||
*/
|
||||
public class AssignmentResult<T extends BaseEntity> {
|
||||
public abstract class AbstractAssignmentResult<T extends BaseEntity> {
|
||||
|
||||
private final int total;
|
||||
private final int assigned;
|
||||
private final int alreadyAssigned;
|
||||
private final int unassigned;
|
||||
private final List<T> assignedEntity;
|
||||
private final List<T> unassignedEntity;
|
||||
private final List<? extends T> assignedEntity;
|
||||
private final List<? extends T> unassignedEntity;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param assigned
|
||||
* is the number of newly assigned elements.
|
||||
* @param alreadyAssigned
|
||||
* number of already assigned/ignored elements
|
||||
* @param unassigned
|
||||
* number of newly assigned elements
|
||||
* count of already assigned entities
|
||||
* @param assignedEntity
|
||||
* {@link List} of assigned entity.
|
||||
* @param unassignedEntity
|
||||
* {@link List} of unassigned entity.
|
||||
*/
|
||||
public AssignmentResult(final int assigned, final int alreadyAssigned, final int unassigned,
|
||||
final List<T> assignedEntity, final List<T> unassignedEntity) {
|
||||
this.assigned = assigned;
|
||||
public AbstractAssignmentResult(final int alreadyAssigned, final List<? extends T> assignedEntity,
|
||||
final List<? extends T> unassignedEntity) {
|
||||
this.alreadyAssigned = alreadyAssigned;
|
||||
total = assigned + alreadyAssigned;
|
||||
this.unassigned = unassigned;
|
||||
this.assignedEntity = assignedEntity;
|
||||
this.unassignedEntity = unassignedEntity;
|
||||
}
|
||||
@@ -55,14 +44,14 @@ public class AssignmentResult<T extends BaseEntity> {
|
||||
* @return number of newly assigned elements.
|
||||
*/
|
||||
public int getAssigned() {
|
||||
return assigned;
|
||||
return getAssignedEntity().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return total number (assigned and already assigned).
|
||||
*/
|
||||
public int getTotal() {
|
||||
return total;
|
||||
return getAssigned() + alreadyAssigned;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +65,7 @@ public class AssignmentResult<T extends BaseEntity> {
|
||||
* @return number of unsassigned elements
|
||||
*/
|
||||
public int getUnassigned() {
|
||||
return unassigned;
|
||||
return getUnassignedEntity().size();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -10,10 +10,6 @@ package org.eclipse.hawkbit.repository.model;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* A bean which holds a complex result of an service operation to combine the
|
||||
@@ -21,41 +17,24 @@ import org.springframework.util.CollectionUtils;
|
||||
* how much of the assignments had already been existed.
|
||||
*
|
||||
*/
|
||||
public class DistributionSetAssignmentResult extends AssignmentResult<Target> {
|
||||
|
||||
private final List<String> assignedTargets;
|
||||
private final List<Action> actions;
|
||||
public class DistributionSetAssignmentResult extends AbstractAssignmentResult<Action> {
|
||||
|
||||
private final DistributionSet distributionSet;
|
||||
|
||||
private final TargetManagement targetManagement;
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor.
|
||||
*
|
||||
* @param distributionSet
|
||||
* @param distributionSet
|
||||
* that has been assigned
|
||||
* @param assignedTargets
|
||||
* the target objects which have been assigned to the
|
||||
* distribution set
|
||||
* @param assigned
|
||||
* count of the assigned targets
|
||||
* @param alreadyAssigned
|
||||
* the count of the already assigned targets
|
||||
* @param actions
|
||||
* of the assignment
|
||||
* @param targetManagement
|
||||
* to retrieve the assigned targets
|
||||
* the the count of already assigned targets
|
||||
* @param assigned
|
||||
* the assigned actions
|
||||
*/
|
||||
public DistributionSetAssignmentResult(final DistributionSet distributionSet, final List<String> assignedTargets,
|
||||
final int assigned, final int alreadyAssigned, final List<Action> actions,
|
||||
final TargetManagement targetManagement) {
|
||||
super(assigned, alreadyAssigned, 0, Collections.emptyList(), Collections.emptyList());
|
||||
public DistributionSetAssignmentResult(final DistributionSet distributionSet, final int alreadyAssigned,
|
||||
final List<? extends Action> assigned) {
|
||||
super(alreadyAssigned, assigned, Collections.emptyList());
|
||||
this.distributionSet = distributionSet;
|
||||
this.assignedTargets = assignedTargets;
|
||||
this.actions = actions;
|
||||
this.targetManagement = targetManagement;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,32 +44,4 @@ public class DistributionSetAssignmentResult extends AssignmentResult<Target> {
|
||||
return distributionSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actionIds
|
||||
*/
|
||||
public List<Long> getActionIds() {
|
||||
if (actions == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return actions.stream().map(Action::getId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actions
|
||||
*/
|
||||
public List<Action> getActions() {
|
||||
if (actions == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Target> getAssignedEntity() {
|
||||
if (CollectionUtils.isEmpty(assignedTargets)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return targetManagement.getByControllerID(assignedTargets);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.List;
|
||||
* Result object for {@link DistributionSetTag} assignments.
|
||||
*
|
||||
*/
|
||||
public class DistributionSetTagAssignmentResult extends AssignmentResult<DistributionSet> {
|
||||
public class DistributionSetTagAssignmentResult extends AbstractAssignmentResult<DistributionSet> {
|
||||
|
||||
private final DistributionSetTag distributionSetTag;
|
||||
|
||||
@@ -24,20 +24,16 @@ public class DistributionSetTagAssignmentResult extends AssignmentResult<Distrib
|
||||
* @param alreadyAssigned
|
||||
* number of already assigned/ignored elements
|
||||
* @param assigned
|
||||
* number of newly assigned elements
|
||||
* newly assigned elements
|
||||
* @param unassigned
|
||||
* number of newly assigned elements
|
||||
* @param assignedDs
|
||||
* {@link List} of assigned {@link DistributionSet}s.
|
||||
* @param unassignedDs
|
||||
* {@link List} of unassigned {@link DistributionSet}s.
|
||||
* unassigned elements
|
||||
* @param distributionSetTag
|
||||
* the assigned or unassigned tag
|
||||
*/
|
||||
public DistributionSetTagAssignmentResult(final int alreadyAssigned, final int assigned, final int unassigned,
|
||||
final List<DistributionSet> assignedDs, final List<DistributionSet> unassignedDs,
|
||||
public DistributionSetTagAssignmentResult(final int alreadyAssigned,
|
||||
final List<DistributionSet> assigned, final List<DistributionSet> unassigned,
|
||||
final DistributionSetTag distributionSetTag) {
|
||||
super(assigned, alreadyAssigned, unassigned, assignedDs, unassignedDs);
|
||||
super(alreadyAssigned, assigned, unassigned);
|
||||
this.distributionSetTag = distributionSetTag;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.List;
|
||||
* Result object for {@link TargetTag} assignments.
|
||||
*
|
||||
*/
|
||||
public class TargetTagAssignmentResult extends AssignmentResult<Target> {
|
||||
public class TargetTagAssignmentResult extends AbstractAssignmentResult<Target> {
|
||||
|
||||
private final TargetTag targetTag;
|
||||
|
||||
@@ -22,21 +22,17 @@ public class TargetTagAssignmentResult extends AssignmentResult<Target> {
|
||||
* Constructor.
|
||||
*
|
||||
* @param alreadyAssigned
|
||||
* number of already assigned/ignored elements
|
||||
* count of already assigned (ignored) elements
|
||||
* @param assigned
|
||||
* number of newly assigned elements
|
||||
* @param unassigned
|
||||
* number of newly assigned elements
|
||||
* @param assignedTargets
|
||||
* {@link List} of assigned {@link Target}s.
|
||||
* @param unassignedTargets
|
||||
* @param unassigned
|
||||
* {@link List} of unassigned {@link Target}s.
|
||||
* @param targetTag
|
||||
* the assigned or unassigned tag
|
||||
*/
|
||||
public TargetTagAssignmentResult(final int alreadyAssigned, final int assigned, final int unassigned,
|
||||
final List<Target> assignedTargets, final List<Target> unassignedTargets, final TargetTag targetTag) {
|
||||
super(assigned, alreadyAssigned, unassigned, assignedTargets, unassignedTargets);
|
||||
public TargetTagAssignmentResult(final int alreadyAssigned, final List<? extends Target> assigned,
|
||||
final List<? extends Target> unassigned, final TargetTag targetTag) {
|
||||
super(alreadyAssigned, assigned, unassigned);
|
||||
this.targetTag = targetTag;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ public abstract class AbstractDsAssignmentStrategy {
|
||||
abstract List<JpaTarget> findTargetsForAssignment(final List<String> controllerIDs, final long distributionSetId);
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param set
|
||||
* @param targets
|
||||
*/
|
||||
|
||||
@@ -242,7 +242,7 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s that matches the queried externalRefs.
|
||||
*
|
||||
*
|
||||
* @param externalRefs
|
||||
* for which the actions need to be found
|
||||
* @param active
|
||||
@@ -518,7 +518,7 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
|
||||
/**
|
||||
* Updates the externalRef of an action by its actionId.
|
||||
*
|
||||
*
|
||||
* @param actionId
|
||||
* for which the externalRef is being updated.
|
||||
* @param externalRef
|
||||
|
||||
@@ -37,7 +37,6 @@ import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.RepositoryConstants;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException;
|
||||
@@ -122,7 +121,6 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
private final DistributionSetRepository distributionSetRepository;
|
||||
private final TargetRepository targetRepository;
|
||||
private final ActionStatusRepository actionStatusRepository;
|
||||
private final TargetManagement targetManagement;
|
||||
private final AuditorAware<String> auditorProvider;
|
||||
private final VirtualPropertyReplacer virtualPropertyReplacer;
|
||||
private final PlatformTransactionManager txManager;
|
||||
@@ -136,10 +134,9 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
|
||||
protected JpaDeploymentManagement(final EntityManager entityManager, final ActionRepository actionRepository,
|
||||
final DistributionSetRepository distributionSetRepository, final TargetRepository targetRepository,
|
||||
final ActionStatusRepository actionStatusRepository, final TargetManagement targetManagement,
|
||||
final AuditorAware<String> auditorProvider, final EventPublisherHolder eventPublisherHolder,
|
||||
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||
final PlatformTransactionManager txManager,
|
||||
final ActionStatusRepository actionStatusRepository, final AuditorAware<String> auditorProvider,
|
||||
final EventPublisherHolder eventPublisherHolder, final AfterTransactionCommitExecutor afterCommit,
|
||||
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
|
||||
final TenantConfigurationManagement tenantConfigurationManagement, final QuotaManagement quotaManagement,
|
||||
final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware, final Database database) {
|
||||
this.entityManager = entityManager;
|
||||
@@ -147,7 +144,6 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
this.distributionSetRepository = distributionSetRepository;
|
||||
this.targetRepository = targetRepository;
|
||||
this.actionStatusRepository = actionStatusRepository;
|
||||
this.targetManagement = targetManagement;
|
||||
this.auditorProvider = auditorProvider;
|
||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||
this.txManager = txManager;
|
||||
@@ -263,50 +259,70 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
final AbstractDsAssignmentStrategy assignmentStrategy) {
|
||||
|
||||
final JpaDistributionSet distributionSetEntity = getAndValidateDsById(dsID);
|
||||
final List<String> controllerIDs = getControllerIdsForAssignmentAndCheckQuota(targetsWithActionType,
|
||||
distributionSetEntity);
|
||||
final List<JpaTarget> targetEntities = assignmentStrategy.findTargetsForAssignment(controllerIDs,
|
||||
checkQuotaForAssignment(targetsWithActionType, distributionSetEntity);
|
||||
|
||||
final List<JpaTarget> targetEntities = assignmentStrategy.findTargetsForAssignment(
|
||||
targetsWithActionType.stream().map(TargetWithActionType::getControllerId).collect(Collectors.toList()),
|
||||
distributionSetEntity.getId());
|
||||
|
||||
if (targetEntities.isEmpty()) {
|
||||
// detaching as it is not necessary to persist the set itself
|
||||
entityManager.detach(distributionSetEntity);
|
||||
// return with nothing as all targets had the DS already assigned
|
||||
return new DistributionSetAssignmentResult(distributionSetEntity, Collections.emptyList(), 0,
|
||||
targetsWithActionType.size(), Collections.emptyList(), targetManagement);
|
||||
return allTargetsAlreadyAssignedResult(distributionSetEntity, targetsWithActionType.size());
|
||||
}
|
||||
|
||||
// split tIDs length into max entries in-statement because many database
|
||||
// have constraint of max entries in in-statements e.g. Oracle with
|
||||
// maximum 1000 elements, so we need to split the entries here and
|
||||
// execute multiple statements
|
||||
final List<List<Long>> targetEntitiesIdsChunks = Lists.partition(
|
||||
targetEntities.stream().map(Target::getId).collect(Collectors.toList()),
|
||||
Constants.MAX_ENTRIES_IN_STATEMENT);
|
||||
final List<JpaAction> assignedActions = doAssignDistributionSetToTargets(targetsWithActionType,
|
||||
actionMessage, assignmentStrategy, distributionSetEntity, targetEntities);
|
||||
return buildAssignmentResult(distributionSetEntity, assignedActions, targetsWithActionType.size());
|
||||
}
|
||||
|
||||
private DistributionSetAssignmentResult allTargetsAlreadyAssignedResult(
|
||||
final JpaDistributionSet distributionSetEntity, final int alreadyAssignedCount) {
|
||||
// detaching as it is not necessary to persist the set itself
|
||||
entityManager.detach(distributionSetEntity);
|
||||
// return with nothing as all targets had the DS already assigned
|
||||
return new DistributionSetAssignmentResult(distributionSetEntity, alreadyAssignedCount,
|
||||
Collections.emptyList());
|
||||
}
|
||||
|
||||
private List<JpaAction> doAssignDistributionSetToTargets(
|
||||
final Collection<TargetWithActionType> targetsWithActionType, final String actionMessage,
|
||||
final AbstractDsAssignmentStrategy assignmentStrategy, final JpaDistributionSet distributionSetEntity,
|
||||
final List<JpaTarget> targetEntities) {
|
||||
final List<List<Long>> targetEntitiesIdsChunks = getTargetEntitiesAsChunks(targetEntities);
|
||||
closeOrCancelActiveActions(assignmentStrategy, targetEntitiesIdsChunks);
|
||||
// cancel all scheduled actions which are in-active, these actions were
|
||||
// not active before and the manual assignment which has been done
|
||||
// cancels them
|
||||
targetEntitiesIdsChunks.forEach(this::cancelInactiveScheduledActionsForTargets);
|
||||
|
||||
setAssignedDistributionSetAndTargetUpdateStatus(assignmentStrategy, distributionSetEntity,
|
||||
targetEntitiesIdsChunks);
|
||||
|
||||
final Map<String, JpaAction> controllerIdsToActions = createActions(targetsWithActionType, targetEntities,
|
||||
assignmentStrategy, distributionSetEntity);
|
||||
final List<JpaAction> assignedActions = createActions(targetsWithActionType, targetEntities, assignmentStrategy,
|
||||
distributionSetEntity);
|
||||
// create initial action status when action is created so we remember
|
||||
// the initial running status because we will change the status
|
||||
// of the action itself and with this action status we have a nicer
|
||||
// action history.
|
||||
createActionsStatus(controllerIdsToActions.values(), assignmentStrategy, actionMessage);
|
||||
createActionsStatus(assignedActions, assignmentStrategy, actionMessage);
|
||||
|
||||
detachEntitiesAndSendTargetUpdatedEvents(distributionSetEntity, targetEntities, assignmentStrategy);
|
||||
return assignedActions;
|
||||
}
|
||||
|
||||
return new DistributionSetAssignmentResult(distributionSetEntity,
|
||||
targetEntities.stream().map(Target::getControllerId).collect(Collectors.toList()),
|
||||
targetEntities.size(), controllerIDs.size() - targetEntities.size(),
|
||||
Lists.newArrayList(controllerIdsToActions.values()), targetManagement);
|
||||
/**
|
||||
* split tIDs length into max entries in-statement because many database
|
||||
* have constraint of max entries in in-statements e.g. Oracle with maximum
|
||||
* 1000 elements, so we need to split the entries here and execute multiple
|
||||
* statements
|
||||
*/
|
||||
private static List<List<Long>> getTargetEntitiesAsChunks(final List<JpaTarget> targetEntities) {
|
||||
return Lists.partition(targetEntities.stream().map(Target::getId).collect(Collectors.toList()),
|
||||
Constants.MAX_ENTRIES_IN_STATEMENT);
|
||||
}
|
||||
|
||||
private static DistributionSetAssignmentResult buildAssignmentResult(final JpaDistributionSet distributionSet,
|
||||
final List<JpaAction> assignedActions, final int totalTargetsForAssignment) {
|
||||
int alreadyAssignedTargetsCount = totalTargetsForAssignment - assignedActions.size();
|
||||
|
||||
return new DistributionSetAssignmentResult(distributionSet, alreadyAssignedTargetsCount, assignedActions);
|
||||
}
|
||||
|
||||
private JpaDistributionSet getAndValidateDsById(final Long dsID) {
|
||||
@@ -321,17 +337,12 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
return distributionSet;
|
||||
}
|
||||
|
||||
private List<String> getControllerIdsForAssignmentAndCheckQuota(
|
||||
final Collection<TargetWithActionType> targetsWithActionType, final JpaDistributionSet distributionSet) {
|
||||
final List<String> controllerIDs = targetsWithActionType.stream().map(TargetWithActionType::getControllerId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
private void checkQuotaForAssignment(final Collection<TargetWithActionType> targetsWithActionType,
|
||||
final JpaDistributionSet distributionSet) {
|
||||
// enforce the 'max targets per manual assignment' quota
|
||||
if (!controllerIDs.isEmpty()) {
|
||||
assertMaxTargetsPerManualAssignmentQuota(distributionSet.getId(), controllerIDs.size());
|
||||
if (!targetsWithActionType.isEmpty()) {
|
||||
assertMaxTargetsPerManualAssignmentQuota(distributionSet.getId(), targetsWithActionType.size());
|
||||
}
|
||||
|
||||
return controllerIDs;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,15 +393,14 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
assignmentStrategy.setAssignedDistributionSetAndTargetStatus(set, targetIdsChunks, currentUser);
|
||||
}
|
||||
|
||||
private Map<String, JpaAction> createActions(final Collection<TargetWithActionType> targetsWithActionType,
|
||||
private List<JpaAction> createActions(final Collection<TargetWithActionType> targetsWithActionType,
|
||||
final List<JpaTarget> targets, final AbstractDsAssignmentStrategy assignmentStrategy,
|
||||
final JpaDistributionSet set) {
|
||||
final Map<String, TargetWithActionType> targetsWithActionMap = targetsWithActionType.stream()
|
||||
.collect(Collectors.toMap(TargetWithActionType::getControllerId, Function.identity()));
|
||||
|
||||
return targets.stream().map(trg -> assignmentStrategy.createTargetAction(targetsWithActionMap, trg, set))
|
||||
.filter(Objects::nonNull).map(actionRepository::save)
|
||||
.collect(Collectors.toMap(action -> action.getTarget().getControllerId(), Function.identity()));
|
||||
.filter(Objects::nonNull).map(actionRepository::save).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void createActionsStatus(final Collection<JpaAction> actions,
|
||||
@@ -590,7 +600,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
|
||||
@Override
|
||||
public Optional<Action> findAction(final long actionId) {
|
||||
return actionRepository.findById(actionId).map(a -> (Action) a);
|
||||
return actionRepository.findById(actionId).map(a -> a);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -703,8 +713,8 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
final CriteriaQuery<String> selMsgQuery = msgQuery.select(join);
|
||||
selMsgQuery.where(cb.equal(as.get(JpaActionStatus_.id), actionStatusId));
|
||||
|
||||
final List<String> result = entityManager.createQuery(selMsgQuery).setFirstResult((int) pageable.getOffset())
|
||||
.setMaxResults(pageable.getPageSize()).getResultList().stream().collect(Collectors.toList());
|
||||
final List<String> result = new ArrayList<>(entityManager.createQuery(selMsgQuery)
|
||||
.setFirstResult((int) pageable.getOffset()).setMaxResults(pageable.getPageSize()).getResultList());
|
||||
|
||||
return new PageImpl<>(result, pageable, totalCount);
|
||||
}
|
||||
@@ -810,4 +820,4 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
.runAsSystem(() -> tenantConfigurationManagement.getConfigurationValue(key, valueType).getValue());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,14 +188,13 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
toBeChangedDSs.add(set);
|
||||
}
|
||||
}
|
||||
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), 0,
|
||||
toBeChangedDSs.size(), Collections.emptyList(),
|
||||
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(),
|
||||
Collections.emptyList(),
|
||||
Collections.unmodifiableList(
|
||||
toBeChangedDSs.stream().map(distributionSetRepository::save).collect(Collectors.toList())),
|
||||
myTag);
|
||||
} else {
|
||||
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), toBeChangedDSs.size(),
|
||||
0,
|
||||
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(),
|
||||
Collections.unmodifiableList(
|
||||
toBeChangedDSs.stream().map(distributionSetRepository::save).collect(Collectors.toList())),
|
||||
Collections.emptyList(), myTag);
|
||||
@@ -386,7 +385,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
specList = Arrays.asList(DistributionSetSpecification.isDeleted(false),
|
||||
DistributionSetSpecification.isCompleted(complete));
|
||||
} else {
|
||||
specList = Arrays.asList(DistributionSetSpecification.isDeleted(false));
|
||||
specList = Collections.singletonList(DistributionSetSpecification.isDeleted(false));
|
||||
}
|
||||
|
||||
return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq);
|
||||
@@ -754,7 +753,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
public void delete(final long setId) {
|
||||
throwExceptionIfDistributionSetDoesNotExist(setId);
|
||||
|
||||
delete(Arrays.asList(setId));
|
||||
delete(Collections.singletonList(setId));
|
||||
}
|
||||
|
||||
private void throwExceptionIfDistributionSetDoesNotExist(final Long setId) {
|
||||
@@ -811,7 +810,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
|
||||
@Override
|
||||
public Optional<DistributionSet> get(final long id) {
|
||||
return distributionSetRepository.findById(id).map(d -> (DistributionSet) d);
|
||||
return distributionSetRepository.findById(id).map(d -> d);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -294,7 +294,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final Long targetId = getByControllerIdAndThrowIfNotFound(controllerId).getId();
|
||||
|
||||
return targetMetadataRepository.findById(new TargetMetadataCompositeKey(targetId, key))
|
||||
.map(t -> (TargetMetadata) t);
|
||||
.map(t -> t);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -470,14 +470,14 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
specList.add(TargetSpecifications
|
||||
.likeIdOrNameOrDescriptionOrAttributeValue(filterParams.getFilterBySearchText()));
|
||||
}
|
||||
if (isHasTagsFilterActive(filterParams)) {
|
||||
if (hasTagsFilterActive(filterParams)) {
|
||||
specList.add(TargetSpecifications.hasTags(filterParams.getFilterByTagNames(),
|
||||
filterParams.getSelectTargetWithNoTag()));
|
||||
}
|
||||
return specList;
|
||||
}
|
||||
|
||||
private static boolean isHasTagsFilterActive(final FilterParams filterParams) {
|
||||
private static boolean hasTagsFilterActive(final FilterParams filterParams) {
|
||||
return ((filterParams.getSelectTargetWithNoTag() != null) && filterParams.getSelectTargetWithNoTag())
|
||||
|| ((filterParams.getFilterByTagNames() != null) && (filterParams.getFilterByTagNames().length > 0));
|
||||
}
|
||||
@@ -520,7 +520,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
// all are already assigned -> unassign
|
||||
if (alreadyAssignedTargets.size() == allTargets.size()) {
|
||||
alreadyAssignedTargets.forEach(target -> target.removeTag(tag));
|
||||
return new TargetTagAssignmentResult(0, 0, alreadyAssignedTargets.size(), Collections.emptyList(),
|
||||
return new TargetTagAssignmentResult(0, Collections.emptyList(),
|
||||
Collections.unmodifiableList(alreadyAssignedTargets), tag);
|
||||
}
|
||||
|
||||
@@ -528,7 +528,6 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
// some or none are assigned -> assign
|
||||
allTargets.forEach(target -> target.addTag(tag));
|
||||
final TargetTagAssignmentResult result = new TargetTagAssignmentResult(alreadyAssignedTargets.size(),
|
||||
allTargets.size(), 0,
|
||||
Collections
|
||||
.unmodifiableList(allTargets.stream().map(targetRepository::save).collect(Collectors.toList())),
|
||||
Collections.emptyList(), tag);
|
||||
@@ -776,7 +775,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public Optional<Target> get(final long id) {
|
||||
return targetRepository.findById(id).map(t -> (Target) t);
|
||||
return targetRepository.findById(id).map(t -> t);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -59,7 +59,7 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
||||
|
||||
@Override
|
||||
void sendTargetUpdatedEvents(final DistributionSet set, final List<JpaTarget> targets) {
|
||||
targets.stream().forEach(target -> {
|
||||
targets.forEach(target -> {
|
||||
target.setUpdateStatus(TargetUpdateStatus.PENDING);
|
||||
sendTargetUpdatedEvent(target);
|
||||
});
|
||||
@@ -77,7 +77,7 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
||||
@Override
|
||||
void sendDeploymentEvents(final List<DistributionSetAssignmentResult> assignmentResults) {
|
||||
if (isMultiAssignmentsEnabled()) {
|
||||
sendDeploymentEvent(assignmentResults.stream().flatMap(result -> result.getActions().stream())
|
||||
sendDeploymentEvent(assignmentResults.stream().flatMap(result -> result.getAssignedEntity().stream())
|
||||
.collect(Collectors.toList()));
|
||||
} else {
|
||||
assignmentResults.forEach(this::sendDistributionSetAssignedEvent);
|
||||
@@ -170,7 +170,7 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
||||
|
||||
private DistributionSetAssignmentResult sendDistributionSetAssignedEvent(
|
||||
final DistributionSetAssignmentResult assignmentResult) {
|
||||
final List<Action> filteredActions = filterCancellations(assignmentResult.getActions())
|
||||
final List<Action> filteredActions = filterCancellations(assignmentResult.getAssignedEntity())
|
||||
.filter(action -> !hasPendingCancellations(action.getTarget())).collect(Collectors.toList());
|
||||
final DistributionSet set = assignmentResult.getDistributionSet();
|
||||
sendTargetAssignDistributionSetEvent(set.getTenant(), set.getId(), filteredActions);
|
||||
|
||||
@@ -666,16 +666,16 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
DeploymentManagement deploymentManagement(final EntityManager entityManager,
|
||||
final ActionRepository actionRepository, final DistributionSetRepository distributionSetRepository,
|
||||
final TargetRepository targetRepository, final ActionStatusRepository actionStatusRepository,
|
||||
final TargetManagement targetManagement, final AuditorAware<String> auditorProvider,
|
||||
final EventPublisherHolder eventPublisherHolder, final AfterTransactionCommitExecutor afterCommit,
|
||||
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
|
||||
final AuditorAware<String> auditorProvider, final EventPublisherHolder eventPublisherHolder,
|
||||
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||
final PlatformTransactionManager txManager,
|
||||
final TenantConfigurationManagement tenantConfigurationManagement, final QuotaManagement quotaManagement,
|
||||
final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware,
|
||||
final JpaProperties properties) {
|
||||
return new JpaDeploymentManagement(entityManager, actionRepository, distributionSetRepository, targetRepository,
|
||||
actionStatusRepository, targetManagement, auditorProvider, eventPublisherHolder, afterCommit,
|
||||
virtualPropertyReplacer, txManager, tenantConfigurationManagement, quotaManagement,
|
||||
systemSecurityContext, tenantAware, properties.getDatabase());
|
||||
actionStatusRepository, auditorProvider, eventPublisherHolder, afterCommit, virtualPropertyReplacer,
|
||||
txManager, tenantConfigurationManagement, quotaManagement, systemSecurityContext, tenantAware,
|
||||
properties.getDatabase());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -493,8 +493,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(
|
||||
controllerManagement.hasTargetArtifactAssigned(savedTarget.getControllerId(), artifact.getSha1Hash()))
|
||||
.isFalse();
|
||||
savedTarget = assignDistributionSet(ds.getId(), savedTarget.getControllerId()).getAssignedEntity().iterator()
|
||||
.next();
|
||||
savedTarget = getFirstAssignedTarget(assignDistributionSet(ds.getId(), savedTarget.getControllerId()));
|
||||
assertThat(
|
||||
controllerManagement.hasTargetArtifactAssigned(savedTarget.getControllerId(), artifact.getSha1Hash()))
|
||||
.isTrue();
|
||||
@@ -1056,7 +1055,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet testDs = testdataFactory.createDistributionSet("1");
|
||||
final List<Target> testTarget = testdataFactory.createTargets(1);
|
||||
|
||||
final Long actionId = assignDistributionSet(testDs, testTarget).getActionIds().get(0);
|
||||
final Long actionId = getFirstAssignedActionId(assignDistributionSet(testDs, testTarget));
|
||||
|
||||
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId)
|
||||
.status(Action.Status.RUNNING).messages(Lists.newArrayList("proceeding message 1")));
|
||||
@@ -1084,8 +1083,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
final int maxStatusEntries = quotaManagement.getMaxStatusEntriesPerAction() - 1;
|
||||
|
||||
// test for informational status
|
||||
final Long actionId1 = assignDistributionSet(testdataFactory.createDistributionSet("ds1"),
|
||||
testdataFactory.createTargets(1, "t1")).getActionIds().get(0);
|
||||
final Long actionId1 = getFirstAssignedActionId(assignDistributionSet(
|
||||
testdataFactory.createDistributionSet("ds1"), testdataFactory.createTargets(1, "t1")));
|
||||
assertThat(actionId1).isNotNull();
|
||||
for (int i = 0; i < maxStatusEntries; ++i) {
|
||||
controllerManagement.addInformationalActionStatus(entityFactory.actionStatus().create(actionId1)
|
||||
@@ -1095,8 +1094,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
.addInformationalActionStatus(entityFactory.actionStatus().create(actionId1).status(Status.WARNING)));
|
||||
|
||||
// test for update status (and mixed case)
|
||||
final Long actionId2 = assignDistributionSet(testdataFactory.createDistributionSet("ds2"),
|
||||
testdataFactory.createTargets(1, "t2")).getActionIds().get(0);
|
||||
final Long actionId2 = getFirstAssignedActionId(assignDistributionSet(
|
||||
testdataFactory.createDistributionSet("ds2"), testdataFactory.createTargets(1, "t2")));
|
||||
assertThat(actionId2).isNotEqualTo(actionId1);
|
||||
for (int i = 0; i < maxStatusEntries; ++i) {
|
||||
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId2)
|
||||
@@ -1118,8 +1117,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final int maxMessages = quotaManagement.getMaxMessagesPerActionStatus();
|
||||
|
||||
final Long actionId = assignDistributionSet(testdataFactory.createDistributionSet("ds1"),
|
||||
testdataFactory.createTargets(1)).getActionIds().get(0);
|
||||
final Long actionId = getFirstAssignedActionId(
|
||||
assignDistributionSet(testdataFactory.createDistributionSet("ds1"), testdataFactory.createTargets(1)));
|
||||
assertThat(actionId).isNotNull();
|
||||
|
||||
final List<String> messages = Lists.newArrayList();
|
||||
@@ -1331,7 +1330,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
testdataFactory.createTarget(knownControllerId);
|
||||
final DistributionSetAssignmentResult assignmentResult = deploymentManagement.assignDistributionSet(
|
||||
knownDistributionSet.getId(), ActionType.FORCED, 0, Collections.singleton(knownControllerId));
|
||||
final Long actionId = assignmentResult.getActionIds().get(0);
|
||||
final Long actionId = getFirstAssignedActionId(assignmentResult);
|
||||
controllerManagement.updateActionExternalRef(actionId, knownExternalref);
|
||||
|
||||
allExternalRef.add(knownExternalref);
|
||||
@@ -1432,7 +1431,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Long forcedDistributionSetId = testdataFactory.createDistributionSet("forcedDs1").getId();
|
||||
final DistributionSetAssignmentResult assignmentResult = assignDistributionSet(forcedDistributionSetId,
|
||||
DEFAULT_CONTROLLER_ID, Action.ActionType.SOFT);
|
||||
addUpdateActionStatus(assignmentResult.getActions().get(0).getId(), DEFAULT_CONTROLLER_ID, Status.FINISHED);
|
||||
addUpdateActionStatus(getFirstAssignedActionId(assignmentResult), DEFAULT_CONTROLLER_ID, Status.FINISHED);
|
||||
assertAssignedDistributionSetId(DEFAULT_CONTROLLER_ID, forcedDistributionSetId);
|
||||
assertInstalledDistributionSetId(DEFAULT_CONTROLLER_ID, forcedDistributionSetId);
|
||||
assertNoActiveActionsExistsForControllerId(DEFAULT_CONTROLLER_ID);
|
||||
@@ -1472,4 +1471,4 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(actionRepository.activeActionExistsForControllerId(controllerId)).isEqualTo(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,13 +98,14 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||
final Target target = testdataFactory.createTarget();
|
||||
final String dsName = "DistributionSet";
|
||||
|
||||
verifyThrownExceptionBy(() -> deploymentManagement.assignDistributionSet(NOT_EXIST_IDL,
|
||||
Arrays.asList(new TargetWithActionType(target.getControllerId()))), "DistributionSet");
|
||||
Collections.singletonList(new TargetWithActionType(target.getControllerId()))), dsName);
|
||||
verifyThrownExceptionBy(() -> deploymentManagement.assignDistributionSet(NOT_EXIST_IDL,
|
||||
Arrays.asList(new TargetWithActionType(target.getControllerId())), "xxx"), "DistributionSet");
|
||||
Collections.singletonList(new TargetWithActionType(target.getControllerId())), "xxx"), dsName);
|
||||
verifyThrownExceptionBy(() -> deploymentManagement.assignDistributionSet(NOT_EXIST_IDL, ActionType.FORCED,
|
||||
System.currentTimeMillis(), Arrays.asList(target.getControllerId())), "DistributionSet");
|
||||
System.currentTimeMillis(), Collections.singletonList(target.getControllerId())), dsName);
|
||||
|
||||
verifyThrownExceptionBy(() -> deploymentManagement.cancelAction(NOT_EXIST_IDL), "Action");
|
||||
verifyThrownExceptionBy(() -> deploymentManagement.countActionsByTarget(NOT_EXIST_ID), "Target");
|
||||
@@ -128,7 +129,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
new ArrayList<DistributionSetTag>());
|
||||
final List<Target> testTarget = testdataFactory.createTargets(1);
|
||||
// one action with one action status is generated
|
||||
final Long actionId = assignDistributionSet(testDs, testTarget).getActionIds().get(0);
|
||||
final Long actionId = getFirstAssignedActionId(assignDistributionSet(testDs, testTarget));
|
||||
final Action action = deploymentManagement.findActionWithDetails(actionId).get();
|
||||
|
||||
assertThat(action.getDistributionSet()).as("DistributionSet in action").isNotNull();
|
||||
@@ -145,7 +146,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
new ArrayList<DistributionSetTag>());
|
||||
final List<Target> testTarget = testdataFactory.createTargets(1);
|
||||
// one action with one action status is generated
|
||||
final Long actionId = assignDistributionSet(testDs, testTarget).getActionIds().get(0);
|
||||
final Long actionId = getFirstAssignedActionId(assignDistributionSet(testDs, testTarget));
|
||||
|
||||
// act
|
||||
final Slice<Action> actions = deploymentManagement.findActionsByTarget(testTarget.get(0).getControllerId(),
|
||||
@@ -190,11 +191,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Test verifies that action-states of an action are found by using id-based search.")
|
||||
public void findActionStatusByActionId() {
|
||||
final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
|
||||
new ArrayList<DistributionSetTag>());
|
||||
final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0", Collections.emptyList());
|
||||
final List<Target> testTarget = testdataFactory.createTargets(1);
|
||||
// one action with one action status is generated
|
||||
final Long actionId = assignDistributionSet(testDs, testTarget).getActionIds().get(0);
|
||||
final Long actionId = getFirstAssignedActionId(assignDistributionSet(testDs, testTarget));
|
||||
final Slice<Action> actions = deploymentManagement.findActionsByTarget(testTarget.get(0).getControllerId(),
|
||||
PAGE);
|
||||
final ActionStatus expectedActionStatus = ((JpaAction) actions.getContent().get(0)).getActionStatus().get(0);
|
||||
@@ -213,10 +213,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
new ArrayList<DistributionSetTag>());
|
||||
final List<Target> testTarget = testdataFactory.createTargets(1);
|
||||
// one action with one action status is generated
|
||||
final Long actionId = assignDistributionSet(testDs, testTarget).getActionIds().get(0);
|
||||
final Long actionId = getFirstAssignedActionId(assignDistributionSet(testDs, testTarget));
|
||||
// create action-status entry with one message
|
||||
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId)
|
||||
.status(Action.Status.FINISHED).messages(Arrays.asList("finished message")));
|
||||
.status(Action.Status.FINISHED).messages(Collections.singletonList("finished message")));
|
||||
final Page<ActionStatus> actionStates = deploymentManagement.findActionStatusByAction(PAGE, actionId);
|
||||
|
||||
// find newly created action-status entry with message
|
||||
@@ -465,12 +465,14 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final long current = System.currentTimeMillis();
|
||||
final List<Target> targets = deploymentManagement.offlineAssignedDistributionSet(ds.getId(), controllerIds)
|
||||
.getAssignedEntity();
|
||||
.getAssignedEntity().stream().map(Action::getTarget).collect(Collectors.toList());;
|
||||
assertThat(actionRepository.count()).isEqualTo(20);
|
||||
assertThat(actionRepository.findByDistributionSetId(PAGE, ds.getId())).as("Offline actions are not active")
|
||||
.allMatch(action -> !action.isActive());
|
||||
assertThat(targetManagement.findByInstalledDistributionSet(PAGE, ds.getId()).getContent()).containsAll(targets)
|
||||
.hasSize(10).containsAll(targetManagement.findByAssignedDistributionSet(PAGE, ds.getId()))
|
||||
|
||||
assertThat(targetManagement.findByInstalledDistributionSet(PAGE, ds.getId()).getContent())
|
||||
.usingElementComparator(controllerIdComparator()).containsAll(targets).hasSize(10)
|
||||
.containsAll(targetManagement.findByAssignedDistributionSet(PAGE, ds.getId()))
|
||||
.as("InstallationDate set").allMatch(target -> target.getInstallationDate() >= current)
|
||||
.as("TargetUpdateStatus IN_SYNC")
|
||||
.allMatch(target -> TargetUpdateStatus.IN_SYNC.equals(target.getUpdateStatus()))
|
||||
@@ -630,7 +632,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final SoftwareModule os = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final DistributionSet incomplete = distributionSetManagement.create(entityFactory.distributionSet().create()
|
||||
.name("incomplete").version("v1").type(standardDsType).modules(Arrays.asList(ah.getId())));
|
||||
.name("incomplete").version("v1").type(standardDsType).modules(Collections.singletonList(ah.getId())));
|
||||
|
||||
try {
|
||||
assignDistributionSet(incomplete, targets);
|
||||
@@ -698,7 +700,9 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// test the content of different lists
|
||||
assertThat(allFoundTargets).as("content of founded target is wrong").containsAll(deployedTargetsFromDB)
|
||||
.containsAll(undeployedTargetsFromDB);
|
||||
assertThat(deployedTargetsFromDB).as("content of deployed target is wrong").containsAll(savedDeployedTargets)
|
||||
|
||||
assertThat(deployedTargetsFromDB).as("content of deployed target is wrong")
|
||||
.usingElementComparator(controllerIdComparator()).containsAll(savedDeployedTargets)
|
||||
.doesNotContain(Iterables.toArray(undeployedTargetsFromDB, JpaTarget.class));
|
||||
assertThat(undeployedTargetsFromDB).as("content of undeployed target is wrong").containsAll(savedNakedTargets)
|
||||
.doesNotContain(Iterables.toArray(deployedTargetsFromDB, JpaTarget.class));
|
||||
@@ -769,15 +773,16 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// remove updActB from
|
||||
// activeActions, add a corresponding cancelAction and another
|
||||
// UpdateAction for dsA
|
||||
final Iterable<Target> deployed2DS = assignDistributionSet(dsA, deployResWithDsB.getDeployedTargets())
|
||||
.getAssignedEntity();
|
||||
final List<Target> deployed2DS = assignDistributionSet(dsA, deployResWithDsB.getDeployedTargets())
|
||||
.getAssignedEntity().stream().map(Action::getTarget).collect(Collectors.toList());
|
||||
actionRepository.findByDistributionSetId(pageRequest, dsA.getId()).getContent().get(1);
|
||||
|
||||
// get final updated version of targets
|
||||
final List<Target> deployResWithDsBTargets = targetManagement.getByControllerID(deployResWithDsB
|
||||
.getDeployedTargets().stream().map(Target::getControllerId).collect(Collectors.toList()));
|
||||
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").containsAll(deployResWithDsBTargets);
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").usingElementComparator(controllerIdComparator())
|
||||
.containsAll(deployResWithDsBTargets);
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").hasSameSizeAs(deployResWithDsBTargets);
|
||||
|
||||
for (final Target t_ : deployed2DS) {
|
||||
@@ -892,10 +897,11 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("a");
|
||||
final DistributionSet dsB = testdataFactory.createDistributionSet("b");
|
||||
List<Target> targs = Arrays.asList(testdataFactory.createTarget("target-id-A"));
|
||||
List<Target> targs = Collections.singletonList(testdataFactory.createTarget("target-id-A"));
|
||||
|
||||
// doing the assignment
|
||||
targs = assignDistributionSet(dsA, targs).getAssignedEntity();
|
||||
targs = assignDistributionSet(dsA, targs).getAssignedEntity().stream().map(Action::getTarget)
|
||||
.collect(Collectors.toList());
|
||||
Target targ = targetManagement.getByControllerID(targs.iterator().next().getControllerId()).get();
|
||||
|
||||
// checking the revisions of the created entities
|
||||
@@ -934,7 +940,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertEquals("wrong installed ds", dsA,
|
||||
deploymentManagement.getInstalledDistributionSet(targ.getControllerId()).get());
|
||||
|
||||
targs = assignDistributionSet(dsB.getId(), "target-id-A").getAssignedEntity();
|
||||
targs = assignDistributionSet(dsB.getId(), "target-id-A").getAssignedEntity().stream().map(Action::getTarget)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
targ = targs.iterator().next();
|
||||
|
||||
@@ -962,7 +969,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong")
|
||||
.isEqualTo(distributionSetManagement.getWithDetails(dsA.getId()).get().getOptLockRevision());
|
||||
|
||||
assignDistributionSet(dsA, Arrays.asList(targ));
|
||||
assignDistributionSet(dsA, Collections.singletonList(targ));
|
||||
|
||||
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong")
|
||||
.isEqualTo(distributionSetManagement.getWithDetails(dsA.getId()).get().getOptLockRevision());
|
||||
@@ -978,8 +985,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet(
|
||||
ds.getId(), ActionType.SOFT,
|
||||
org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME,
|
||||
Arrays.asList(target.getControllerId()));
|
||||
final Long actionId = assignDistributionSet.getActionIds().get(0);
|
||||
Collections.singletonList(target.getControllerId()));
|
||||
final Long actionId = getFirstAssignedActionId(assignDistributionSet);
|
||||
// verify preparation
|
||||
Action findAction = deploymentManagement.findAction(actionId).get();
|
||||
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.SOFT);
|
||||
@@ -1002,8 +1009,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet(
|
||||
ds.getId(), ActionType.FORCED,
|
||||
org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME,
|
||||
Arrays.asList(target.getControllerId()));
|
||||
final Long actionId = assignDistributionSet.getActionIds().get(0);
|
||||
Collections.singletonList(target.getControllerId()));
|
||||
final Long actionId = getFirstAssignedActionId(assignDistributionSet);
|
||||
// verify perparation
|
||||
Action findAction = deploymentManagement.findAction(actionId).get();
|
||||
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
|
||||
@@ -1016,6 +1023,50 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
findAction = deploymentManagement.findAction(actionId).get();
|
||||
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the computation of already assigned entities returned as a result of an assignment")
|
||||
public void testAlreadyAssignedAndAssignedActionsInAssignmentResult(){
|
||||
// create target1, distributionSet, assign ds to target1 and finish update (close all actions)
|
||||
final Action action = prepareFinishedUpdate("target1", "ds", false);
|
||||
final Target target2 = testdataFactory.createTarget("target2");
|
||||
final Target target3 = testdataFactory.createTarget("target3");
|
||||
|
||||
// assign ds to target2, but don't finish update (actions should be still open)
|
||||
assignDistributionSet(action.getDistributionSet().getId(), target2.getControllerId());
|
||||
|
||||
final DistributionSetAssignmentResult assignmentResult = deploymentManagement.assignDistributionSet(
|
||||
action.getDistributionSet().getId(),
|
||||
Arrays.asList(new TargetWithActionType(action.getTarget().getControllerId()),
|
||||
new TargetWithActionType(target3.getControllerId())));
|
||||
|
||||
assertThat(assignmentResult).isNotNull();
|
||||
assertThat(assignmentResult.getTotal()).as("Total count of assigned and already assigned targets").isEqualTo(2);
|
||||
assertThat(assignmentResult.getAssigned()).as("Total count of assigned targets").isEqualTo(1);
|
||||
assertThat(assignmentResult.getAlreadyAssigned()).as("Total count of already assigned targets").isEqualTo(1);
|
||||
assertThat(assignmentResult.getAssignedEntity()).isNotEmpty();
|
||||
assertThat(assignmentResult.getAssignedEntity()).allMatch(
|
||||
a -> a.getTarget().equals(target3) && a.getDistributionSet().equals(action.getDistributionSet()));
|
||||
assertThat(assignmentResult.getAssignedEntity())
|
||||
.noneMatch(a -> a.getTarget().getControllerId().equals("target1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify that the DistributionSetAssignmentResult not contains already assigned targets.")
|
||||
public void verifyDistributionSetAssignmentResultNotContainsAlreadyAssignedTargets() {
|
||||
final DistributionSet dsToTargetAssigned = testdataFactory.createDistributionSet("ds-3");
|
||||
|
||||
// create assigned DS
|
||||
final Target savedTarget = testdataFactory.createTarget();
|
||||
DistributionSetAssignmentResult assignmentResult = assignDistributionSet(dsToTargetAssigned.getId(),
|
||||
savedTarget.getControllerId());
|
||||
assertThat(assignmentResult.getAssignedEntity()).hasSize(1);
|
||||
|
||||
assignmentResult = assignDistributionSet(dsToTargetAssigned.getId(), savedTarget.getControllerId());
|
||||
assertThat(assignmentResult.getAssignedEntity()).hasSize(0);
|
||||
|
||||
assertThat(distributionSetRepository.findAll()).hasSize(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper methods that creates 2 lists of targets and a list of distribution
|
||||
@@ -1059,7 +1110,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// assigning all DistributionSet to the Target in the list
|
||||
// deployedTargets
|
||||
for (final DistributionSet ds : dsList) {
|
||||
deployedTargets = assignDistributionSet(ds, deployedTargets).getAssignedEntity();
|
||||
deployedTargets = assignDistributionSet(ds, deployedTargets).getAssignedEntity().stream()
|
||||
.map(Action::getTarget).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return new DeploymentResult(deployedTargets, nakedTargets, dsList, deployedTargetPrefix, undeployedTargetPrefix,
|
||||
|
||||
@@ -40,7 +40,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
@@ -993,23 +992,6 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(distributionSetManagement.findByCompleted(PAGE, true).getTotalElements()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify that the DistributionSetAssignmentResult not contains already assigned targets.")
|
||||
public void verifyDistributionSetAssignmentResultNotContainsAlreadyAssignedTargets() {
|
||||
final DistributionSet dsToTargetAssigned = testdataFactory.createDistributionSet("ds-3");
|
||||
|
||||
// create assigned DS
|
||||
final Target savedTarget = testdataFactory.createTarget();
|
||||
DistributionSetAssignmentResult assignmentResult = assignDistributionSet(dsToTargetAssigned.getId(),
|
||||
savedTarget.getControllerId());
|
||||
assertThat(assignmentResult.getAssignedEntity()).hasSize(1);
|
||||
|
||||
assignmentResult = assignDistributionSet(dsToTargetAssigned.getId(), savedTarget.getControllerId());
|
||||
assertThat(assignmentResult.getAssignedEntity()).hasSize(0);
|
||||
|
||||
assertThat(distributionSetRepository.findAll()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify that the find all by ids contains the entities which are looking for")
|
||||
@ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 12),
|
||||
|
||||
@@ -104,7 +104,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
testdataFactory.createTarget(knownControllerId);
|
||||
final DistributionSetAssignmentResult assignmentResult = deploymentManagement.assignDistributionSet(
|
||||
knownDistributionSet.getId(), ActionType.FORCED, 0, Collections.singleton(knownControllerId));
|
||||
final Long manuallyAssignedActionId = assignmentResult.getActionIds().get(0);
|
||||
final Long manuallyAssignedActionId = getFirstAssignedActionId(assignmentResult);
|
||||
|
||||
// create rollout with the same distribution set already assigned
|
||||
// start rollout
|
||||
@@ -144,7 +144,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
testdataFactory.createTarget(knownControllerId);
|
||||
final DistributionSetAssignmentResult assignmentResult = deploymentManagement.assignDistributionSet(
|
||||
firstDistributionSet.getId(), ActionType.FORCED, 0, Collections.singleton(knownControllerId));
|
||||
final Long manuallyAssignedActionId = assignmentResult.getActionIds().get(0);
|
||||
final Long manuallyAssignedActionId = getFirstAssignedActionId(assignmentResult);
|
||||
|
||||
// create rollout with the same distribution set already assigned
|
||||
// start rollout
|
||||
|
||||
@@ -96,7 +96,7 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
final String assignedB = targBs.iterator().next().getControllerId();
|
||||
assignDistributionSet(setA.getId(), assignedB);
|
||||
final String installedC = targCs.iterator().next().getControllerId();
|
||||
final Long actionId = assignDistributionSet(installedSet.getId(), assignedC).getActionIds().get(0);
|
||||
final Long actionId = getFirstAssignedActionId(assignDistributionSet(installedSet.getId(), assignedC));
|
||||
|
||||
// add attributes to match against only attribute value or attribute
|
||||
// value and name
|
||||
@@ -578,8 +578,10 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("a");
|
||||
|
||||
targAssigned = Lists.newLinkedList(assignDistributionSet(ds, targAssigned).getAssignedEntity());
|
||||
targInstalled = assignDistributionSet(ds, targInstalled).getAssignedEntity();
|
||||
targAssigned = assignDistributionSet(ds, targAssigned).getAssignedEntity().stream().map(Action::getTarget)
|
||||
.collect(Collectors.toList());
|
||||
targInstalled = assignDistributionSet(ds, targInstalled).getAssignedEntity().stream().map(Action::getTarget)
|
||||
.collect(Collectors.toList());
|
||||
targInstalled = testdataFactory
|
||||
.sendUpdateActionStatusToTargets(targInstalled, Status.FINISHED, Collections.singletonList("installed"))
|
||||
.stream().map(Action::getTarget).collect(Collectors.toList());
|
||||
@@ -598,7 +600,8 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
expected.addAll(targAssigned);
|
||||
expected.addAll(notAssigned);
|
||||
|
||||
assertThat(result.getContent()).containsExactly(expected.toArray(new Target[0]));
|
||||
assertThat(result.getContent()).usingElementComparator(controllerIdComparator())
|
||||
.containsExactly(expected.toArray(new Target[0]));
|
||||
|
||||
}
|
||||
|
||||
@@ -628,8 +631,10 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("a");
|
||||
|
||||
targAssigned = assignDistributionSet(ds, targAssigned).getAssignedEntity();
|
||||
targInstalled = assignDistributionSet(ds, targInstalled).getAssignedEntity();
|
||||
targAssigned = assignDistributionSet(ds, targAssigned).getAssignedEntity().stream().map(Action::getTarget)
|
||||
.collect(Collectors.toList());
|
||||
targInstalled = assignDistributionSet(ds, targInstalled).getAssignedEntity().stream().map(Action::getTarget)
|
||||
.collect(Collectors.toList());
|
||||
targInstalled = testdataFactory
|
||||
.sendUpdateActionStatusToTargets(targInstalled, Status.FINISHED, Collections.singletonList("installed"))
|
||||
.stream().map(Action::getTarget).collect(Collectors.toList());
|
||||
@@ -651,7 +656,8 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
.filter(item -> lastTargetQueryAlwaysOverdue.equals(item.getLastTargetQuery()))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
assertThat(result.getContent()).containsExactly(expected.toArray(new Target[0]));
|
||||
assertThat(result.getContent()).usingElementComparator(controllerIdComparator())
|
||||
.containsExactly(expected.toArray(new Target[0]));
|
||||
|
||||
}
|
||||
|
||||
@@ -701,8 +707,8 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
List<Target> installedtargets = testdataFactory.createTargets(10, "assigned", "assigned");
|
||||
|
||||
// set on installed and assign another one
|
||||
assignDistributionSet(installedSet, installedtargets).getActionIds().forEach(actionId -> controllerManagement
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(actionId).status(Status.FINISHED)));
|
||||
assignDistributionSet(installedSet, installedtargets).getAssignedEntity().forEach(action -> controllerManagement
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(action.getId()).status(Status.FINISHED)));
|
||||
assignDistributionSet(assignedSet, installedtargets);
|
||||
|
||||
// get final updated version of targets
|
||||
|
||||
@@ -478,7 +478,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSetAssignmentResult result = assignDistributionSet(set.getId(), "4711");
|
||||
|
||||
controllerManagement.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(result.getActionIds().get(0)).status(Status.FINISHED));
|
||||
entityFactory.actionStatus().create(getFirstAssignedActionId(result)).status(Status.FINISHED));
|
||||
assignDistributionSet(set2.getId(), "4711");
|
||||
|
||||
target = targetManagement.getByControllerID("4711").get();
|
||||
|
||||
@@ -59,7 +59,7 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
|
||||
testdataFactory.createTarget(knownControllerId);
|
||||
final DistributionSetAssignmentResult assignmentResult = deploymentManagement.assignDistributionSet(
|
||||
firstDistributionSet.getId(), ActionType.FORCED, 0, Collections.singleton(knownControllerId));
|
||||
final Long manuallyAssignedActionId = assignmentResult.getActionIds().get(0);
|
||||
final Long manuallyAssignedActionId = getFirstAssignedActionId(assignmentResult);
|
||||
|
||||
// target filter query that matches all targets
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
|
||||
@@ -80,8 +80,8 @@ public class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds1 = testdataFactory.createDistributionSet("ds1");
|
||||
final DistributionSet ds2 = testdataFactory.createDistributionSet("ds2");
|
||||
|
||||
final Long action1 = deploymentManagement.assignDistributionSet(ds1.getId(), ActionType.FORCED, 0,
|
||||
Collections.singletonList(trg1.getControllerId())).getActionIds().get(0);
|
||||
final Long action1 = getFirstAssignedActionId(deploymentManagement.assignDistributionSet(ds1.getId(),
|
||||
ActionType.FORCED, 0, Collections.singletonList(trg1.getControllerId())));
|
||||
deploymentManagement.assignDistributionSet(ds2.getId(), ActionType.FORCED, 0,
|
||||
Collections.singletonList(trg2.getControllerId()));
|
||||
|
||||
@@ -109,12 +109,12 @@ public class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds1 = testdataFactory.createDistributionSet("ds1");
|
||||
final DistributionSet ds2 = testdataFactory.createDistributionSet("ds2");
|
||||
|
||||
final Long action1 = deploymentManagement.assignDistributionSet(ds1.getId(), ActionType.FORCED, 0,
|
||||
Collections.singletonList(trg1.getControllerId())).getActionIds().get(0);
|
||||
final Long action2 = deploymentManagement.assignDistributionSet(ds2.getId(), ActionType.FORCED, 0,
|
||||
Collections.singletonList(trg2.getControllerId())).getActionIds().get(0);
|
||||
final Long action3 = deploymentManagement.assignDistributionSet(ds2.getId(), ActionType.FORCED, 0,
|
||||
Collections.singletonList(trg3.getControllerId())).getActionIds().get(0);
|
||||
final Long action1 = getFirstAssignedActionId(deploymentManagement.assignDistributionSet(ds1.getId(),
|
||||
ActionType.FORCED, 0, Collections.singletonList(trg1.getControllerId())));
|
||||
final Long action2 = getFirstAssignedActionId(deploymentManagement.assignDistributionSet(ds2.getId(),
|
||||
ActionType.FORCED, 0, Collections.singletonList(trg2.getControllerId())));
|
||||
final Long action3 = getFirstAssignedActionId(deploymentManagement.assignDistributionSet(ds2.getId(),
|
||||
ActionType.FORCED, 0, Collections.singletonList(trg3.getControllerId())));
|
||||
|
||||
assertThat(actionRepository.count()).isEqualTo(3);
|
||||
|
||||
@@ -144,12 +144,12 @@ public class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds1 = testdataFactory.createDistributionSet("ds1");
|
||||
final DistributionSet ds2 = testdataFactory.createDistributionSet("ds2");
|
||||
|
||||
final Long action1 = deploymentManagement.assignDistributionSet(ds1.getId(), ActionType.FORCED, 0,
|
||||
Collections.singletonList(trg1.getControllerId())).getActionIds().get(0);
|
||||
final Long action2 = deploymentManagement.assignDistributionSet(ds2.getId(), ActionType.FORCED, 0,
|
||||
Collections.singletonList(trg2.getControllerId())).getActionIds().get(0);
|
||||
final Long action3 = deploymentManagement.assignDistributionSet(ds2.getId(), ActionType.FORCED, 0,
|
||||
Collections.singletonList(trg3.getControllerId())).getActionIds().get(0);
|
||||
final Long action1 = getFirstAssignedActionId(deploymentManagement.assignDistributionSet(ds1.getId(),
|
||||
ActionType.FORCED, 0, Collections.singletonList(trg1.getControllerId())));
|
||||
final Long action2 = getFirstAssignedActionId(deploymentManagement.assignDistributionSet(ds2.getId(),
|
||||
ActionType.FORCED, 0, Collections.singletonList(trg2.getControllerId())));
|
||||
final Long action3 = getFirstAssignedActionId(deploymentManagement.assignDistributionSet(ds2.getId(),
|
||||
ActionType.FORCED, 0, Collections.singletonList(trg3.getControllerId())));
|
||||
|
||||
assertThat(actionRepository.count()).isEqualTo(3);
|
||||
|
||||
@@ -181,12 +181,12 @@ public class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds1 = testdataFactory.createDistributionSet("ds1");
|
||||
final DistributionSet ds2 = testdataFactory.createDistributionSet("ds2");
|
||||
|
||||
final Long action1 = deploymentManagement.assignDistributionSet(ds1.getId(), ActionType.FORCED, 0,
|
||||
Collections.singletonList(trg1.getControllerId())).getActionIds().get(0);
|
||||
final Long action2 = deploymentManagement.assignDistributionSet(ds2.getId(), ActionType.FORCED, 0,
|
||||
Collections.singletonList(trg2.getControllerId())).getActionIds().get(0);
|
||||
final Long action3 = deploymentManagement.assignDistributionSet(ds2.getId(), ActionType.FORCED, 0,
|
||||
Collections.singletonList(trg3.getControllerId())).getActionIds().get(0);
|
||||
final Long action1 = getFirstAssignedActionId(deploymentManagement.assignDistributionSet(ds1.getId(),
|
||||
ActionType.FORCED, 0, Collections.singletonList(trg1.getControllerId())));
|
||||
final Long action2 = getFirstAssignedActionId(deploymentManagement.assignDistributionSet(ds2.getId(),
|
||||
ActionType.FORCED, 0, Collections.singletonList(trg2.getControllerId())));
|
||||
final Long action3 = getFirstAssignedActionId(deploymentManagement.assignDistributionSet(ds2.getId(),
|
||||
ActionType.FORCED, 0, Collections.singletonList(trg3.getControllerId())));
|
||||
|
||||
assertThat(actionRepository.count()).isEqualTo(3);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.net.URI;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -321,8 +322,8 @@ public abstract class AbstractIntegrationTest {
|
||||
final boolean isRequiredMigrationStep) {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet(distributionSet, isRequiredMigrationStep);
|
||||
Target savedTarget = testdataFactory.createTarget(controllerId);
|
||||
savedTarget = assignDistributionSet(ds.getId(), savedTarget.getControllerId(), ActionType.FORCED)
|
||||
.getAssignedEntity().iterator().next();
|
||||
savedTarget = getFirstAssignedTarget(
|
||||
assignDistributionSet(ds.getId(), savedTarget.getControllerId(), ActionType.FORCED));
|
||||
Action savedAction = deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())
|
||||
.getContent().get(0);
|
||||
|
||||
@@ -434,4 +435,21 @@ public abstract class AbstractIntegrationTest {
|
||||
|
||||
return randomStringBuilder.toString();
|
||||
}
|
||||
|
||||
protected static Action getFirstAssignedAction(final DistributionSetAssignmentResult distributionSetAssignmentResult) {
|
||||
return distributionSetAssignmentResult.getAssignedEntity().stream().findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException("expected one assigned action, found none"));
|
||||
}
|
||||
|
||||
protected static Long getFirstAssignedActionId(final DistributionSetAssignmentResult distributionSetAssignmentResult) {
|
||||
return getFirstAssignedAction(distributionSetAssignmentResult).getId();
|
||||
}
|
||||
|
||||
protected static Target getFirstAssignedTarget(final DistributionSetAssignmentResult assignment) {
|
||||
return getFirstAssignedAction(assignment).getTarget();
|
||||
}
|
||||
|
||||
protected static Comparator<Target> controllerIdComparator() {
|
||||
return (o1, o2) -> o1.getControllerId().equals(o2.getControllerId()) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user