Refactor DS Management (#2591)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -588,7 +588,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
systemSecurityContext.runAsSystem(() ->
|
||||
distributionSetManagement.findByNameAndVersion(distributionName, version).map(
|
||||
distributionSet -> deploymentManagement.offlineAssignedDistributionSets(
|
||||
List.of(Map.entry(controllerId, distributionSet.getId())), controllerId))
|
||||
controllerId, List.of(Map.entry(controllerId, distributionSet.getId()))))
|
||||
.orElseThrow(() ->
|
||||
new EntityNotFoundException(DistributionSet.class, Map.entry(distributionName, version))));
|
||||
|
||||
|
||||
@@ -180,40 +180,41 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
|
||||
@Override
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
public List<DistributionSetAssignmentResult> assignDistributionSets(final String initiatedBy,
|
||||
final List<DeploymentRequest> deploymentRequests, final String actionMessage) {
|
||||
public List<DistributionSetAssignmentResult> assignDistributionSets(
|
||||
final String initiatedBy, final List<DeploymentRequest> deploymentRequests, final String actionMessage) {
|
||||
return assignDistributionSets0(initiatedBy, deploymentRequests, actionMessage);
|
||||
}
|
||||
|
||||
private List<DistributionSetAssignmentResult> assignDistributionSets0(final String initiatedBy,
|
||||
final List<DeploymentRequest> deploymentRequests, final String actionMessage) {
|
||||
private List<DistributionSetAssignmentResult> assignDistributionSets0(
|
||||
final String initiatedBy, final List<DeploymentRequest> deploymentRequests, final String actionMessage) {
|
||||
WeightValidationHelper.usingContext(systemSecurityContext, tenantConfigurationManagement).validate(deploymentRequests);
|
||||
return assignDistributionSets(initiatedBy, deploymentRequests, actionMessage, onlineDsAssignmentStrategy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DistributionSetAssignmentResult> offlineAssignedDistributionSets(final Collection<Entry<String, Long>> assignments,
|
||||
final String initiatedBy) {
|
||||
public List<DistributionSetAssignmentResult> offlineAssignedDistributionSets(
|
||||
final String initiatedBy, final Collection<Entry<String, Long>> assignments) {
|
||||
final Collection<Entry<String, Long>> distinctAssignments = assignments.stream().distinct().toList();
|
||||
enforceMaxAssignmentsPerRequest(distinctAssignments.size());
|
||||
|
||||
final List<DeploymentRequest> deploymentRequests = distinctAssignments.stream()
|
||||
.map(entry -> DeploymentManagement.deploymentRequest(entry.getKey(), entry.getValue()).build()).toList();
|
||||
|
||||
return assignDistributionSets(auditorAware.getCurrentAuditor().orElse(tenantAware.getCurrentUsername()), deploymentRequests, null,
|
||||
return assignDistributionSets(
|
||||
auditorAware.getCurrentAuditor().orElse(tenantAware.getCurrentUsername()), deploymentRequests, null,
|
||||
offlineDsAssignmentStrategy);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
public List<DistributionSetAssignmentResult> offlineAssignedDistributionSets(final Collection<Entry<String, Long>> assignments) {
|
||||
return offlineAssignedDistributionSets(assignments, tenantAware.getCurrentUsername());
|
||||
return offlineAssignedDistributionSets(tenantAware.getCurrentUsername(), assignments);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
@Retryable(retryFor = {
|
||||
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Action cancelAction(final long actionId) {
|
||||
return cancelAction0(actionId);
|
||||
}
|
||||
@@ -452,7 +453,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
startScheduledActions(groupScheduledActions.getContent());
|
||||
return groupScheduledActions.getTotalElements();
|
||||
}
|
||||
}) > 0) ;
|
||||
}) > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -483,7 +484,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = false)
|
||||
@Transactional
|
||||
public int deleteActionsByStatusAndLastModifiedBefore(final Set<Status> status, final long lastModified) {
|
||||
if (status.isEmpty()) {
|
||||
return 0;
|
||||
@@ -590,8 +591,9 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
return template;
|
||||
}
|
||||
|
||||
private List<DistributionSetAssignmentResult> assignDistributionSets(final String initiatedBy,
|
||||
final List<DeploymentRequest> deploymentRequests, final String actionMessage, final AbstractDsAssignmentStrategy strategy) {
|
||||
private List<DistributionSetAssignmentResult> assignDistributionSets(
|
||||
final String initiatedBy, final List<DeploymentRequest> deploymentRequests, final String actionMessage,
|
||||
final AbstractDsAssignmentStrategy strategy) {
|
||||
final List<DeploymentRequest> validatedRequests = validateAndFilterRequestForAssignments(deploymentRequests);
|
||||
final Map<Long, List<TargetWithActionType>> assignmentsByDsIds = convertRequest(validatedRequests);
|
||||
|
||||
@@ -720,10 +722,15 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
private DistributionSetAssignmentResult assignDistributionSetToTargets(
|
||||
final String initiatedBy, final Long dsId, final Collection<TargetWithActionType> targetsWithActionType, final String actionMessage,
|
||||
final AbstractDsAssignmentStrategy assignmentStrategy) {
|
||||
JpaDistributionSet distributionSet = distributionSetManagement.getValidAndComplete(dsId);
|
||||
if (distributionSetManagement.isImplicitLockApplicable(distributionSet)) {
|
||||
// without new transaction DS changed event is not thrown
|
||||
distributionSet = DeploymentHelper.runInNewTransaction(txManager, "Implicit lock", status -> distributionSetManagement.lock(dsId));
|
||||
final JpaDistributionSet dsValidAndComplete = distributionSetManagement.getValidAndComplete(dsId);
|
||||
final JpaDistributionSet distributionSet;
|
||||
if (distributionSetManagement.shouldLockImplicitly(dsValidAndComplete)) {
|
||||
// implicitly lock, for some reason no update happen if lock in same transaction
|
||||
distributionSet = DeploymentHelper.runInNewTransaction(
|
||||
txManager, "lockDistributionSet-" + dsId,
|
||||
status -> distributionSetManagement.lock(dsValidAndComplete));
|
||||
} else {
|
||||
distributionSet = dsValidAndComplete;
|
||||
}
|
||||
|
||||
final List<String> providedTargetIds = targetsWithActionType.stream().map(TargetWithActionType::getControllerId).distinct().toList();
|
||||
@@ -766,8 +773,8 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
// not active before and the manual assignment which has been done cancels them
|
||||
targetEntitiesIdsChunks.forEach(this::cancelInactiveScheduledActionsForTargets);
|
||||
setAssignedDistributionSetAndTargetUpdateStatus(assignmentStrategy, distributionSetEntity, targetEntitiesIdsChunks);
|
||||
final Map<TargetWithActionType, JpaAction> assignedActions = createActions(targetsWithActionType, targetEntities, distributionSetEntity,
|
||||
assignmentStrategy, initiatedBy);
|
||||
final Map<TargetWithActionType, JpaAction> assignedActions =
|
||||
createActions(targetsWithActionType, targetEntities, distributionSetEntity, assignmentStrategy, initiatedBy);
|
||||
// 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.
|
||||
@@ -820,7 +827,8 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
return persistedActions;
|
||||
}
|
||||
|
||||
private void createActionsStatus(final Map<TargetWithActionType, JpaAction> actions, final AbstractDsAssignmentStrategy assignmentStrategy,
|
||||
private void createActionsStatus(
|
||||
final Map<TargetWithActionType, JpaAction> actions, final AbstractDsAssignmentStrategy assignmentStrategy,
|
||||
final String actionMessage) {
|
||||
actionStatusRepository.saveAll(actions.entrySet().stream().map(entry -> {
|
||||
final JpaAction action = entry.getValue();
|
||||
|
||||
@@ -132,10 +132,10 @@ public class JpaDistributionSetInvalidationManagement implements DistributionSet
|
||||
private void invalidateDistributionSet(final long setId, final CancelationType cancelationType, final boolean cancelRollouts) {
|
||||
final DistributionSet distributionSet = distributionSetManagement.getOrElseThrowException(setId);
|
||||
if (!distributionSet.isComplete()) {
|
||||
throw new IncompleteDistributionSetException("Distribution set of type "
|
||||
+ distributionSet.getType().getKey() + " is incomplete: " + distributionSet.getId());
|
||||
throw new IncompleteDistributionSetException(
|
||||
"Distribution set of type " + distributionSet.getType().getKey() + " is incomplete: " + distributionSet.getId());
|
||||
}
|
||||
((DistributionSetManagement)distributionSetManagement).invalidate(distributionSet);
|
||||
distributionSetManagement.invalidate(distributionSet);
|
||||
log.debug("Distribution set {} marked as invalid.", setId);
|
||||
|
||||
// rollout cancellation should only be permitted with UPDATE_ROLLOUT permission
|
||||
|
||||
@@ -13,7 +13,6 @@ import static org.eclipse.hawkbit.repository.jpa.configuration.Constants.TX_RT_D
|
||||
import static org.eclipse.hawkbit.repository.jpa.configuration.Constants.TX_RT_MAX;
|
||||
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.IMPLICIT_LOCK_ENABLED;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -26,12 +25,10 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetFields;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
@@ -39,12 +36,10 @@ import org.eclipse.hawkbit.repository.exception.DeletedException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
|
||||
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository;
|
||||
@@ -52,16 +47,11 @@ import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetTagRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.SoftwareModuleRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetFilterQueryRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RsqlUtility;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.QuotaHelper;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Statistic;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
@@ -70,13 +60,10 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProp
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.retry.annotation.Backoff;
|
||||
import org.springframework.retry.annotation.Retryable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@Service
|
||||
@@ -86,10 +73,8 @@ public class JpaDistributionSetManagement
|
||||
implements DistributionSetManagement<JpaDistributionSet> {
|
||||
|
||||
private final DistributionSetTagManagement<JpaDistributionSetTag> distributionSetTagManagement;
|
||||
private final DistributionSetTypeManagement<JpaDistributionSetType> distributionSetTypeManagement;
|
||||
private final SoftwareModuleRepository softwareModuleRepository;
|
||||
private final DistributionSetTagRepository distributionSetTagRepository;
|
||||
private final TargetRepository targetRepository;
|
||||
private final TargetFilterQueryRepository targetFilterQueryRepository;
|
||||
private final ActionRepository actionRepository;
|
||||
private final QuotaManagement quotaManagement;
|
||||
@@ -101,10 +86,8 @@ public class JpaDistributionSetManagement
|
||||
final DistributionSetRepository jpaRepository,
|
||||
final EntityManager entityManager,
|
||||
final DistributionSetTagManagement<JpaDistributionSetTag> distributionSetTagManagement,
|
||||
final DistributionSetTypeManagement<JpaDistributionSetType> distributionSetTypeManagement,
|
||||
final SoftwareModuleRepository softwareModuleRepository,
|
||||
final DistributionSetTagRepository distributionSetTagRepository,
|
||||
final TargetRepository targetRepository,
|
||||
final TargetFilterQueryRepository targetFilterQueryRepository,
|
||||
final ActionRepository actionRepository,
|
||||
final QuotaManagement quotaManagement,
|
||||
@@ -113,10 +96,8 @@ public class JpaDistributionSetManagement
|
||||
final RepositoryProperties repositoryProperties) {
|
||||
super(jpaRepository, entityManager);
|
||||
this.distributionSetTagManagement = distributionSetTagManagement;
|
||||
this.distributionSetTypeManagement = distributionSetTypeManagement;
|
||||
this.softwareModuleRepository = softwareModuleRepository;
|
||||
this.distributionSetTagRepository = distributionSetTagRepository;
|
||||
this.targetRepository = targetRepository;
|
||||
this.targetFilterQueryRepository = targetFilterQueryRepository;
|
||||
this.actionRepository = actionRepository;
|
||||
this.quotaManagement = quotaManagement;
|
||||
@@ -133,11 +114,11 @@ public class JpaDistributionSetManagement
|
||||
if (Boolean.TRUE.equals(update.getLocked())) {
|
||||
if (!distributionSet.isLocked()) {
|
||||
lockSoftwareModules(distributionSet);
|
||||
distributionSet.lock();
|
||||
distributionSet.setLocked(true);
|
||||
}
|
||||
} else if (Boolean.FALSE.equals(update.getLocked())) {
|
||||
if (distributionSet.isLocked()) {
|
||||
distributionSet.unlock();
|
||||
distributionSet.setLocked(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,16 +154,80 @@ public class JpaDistributionSetManagement
|
||||
return jpaRepository.findOne(jpaRepository.byIdSpec(id), JpaDistributionSet_.GRAPH_DISTRIBUTION_SET_DETAIL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpaDistributionSet getOrElseThrowException(final long id) {
|
||||
return getById(id);
|
||||
}
|
||||
|
||||
// implicitly lock a distribution set if not already locked and implicit lock is enabled and not to skip
|
||||
@Override
|
||||
@Transactional
|
||||
public void invalidate(final JpaDistributionSet distributionSet) {
|
||||
distributionSet.invalidate();
|
||||
jpaRepository.save(distributionSet);
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = TX_RT_MAX, backoff = @Backoff(delay = TX_RT_DELAY))
|
||||
public boolean shouldLockImplicitly(final DistributionSet distributionSet) {
|
||||
final JpaDistributionSet jpaDistributionSet = toJpaDistributionSet(distributionSet);
|
||||
if (jpaDistributionSet.isLocked()) {
|
||||
// already locked
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Boolean.FALSE.equals(tenantConfigHelper.getConfigValue(IMPLICIT_LOCK_ENABLED, Boolean.class))) {
|
||||
// implicit lock disabled
|
||||
return false;
|
||||
}
|
||||
|
||||
final List<String> skipForTags = repositoryProperties.getSkipImplicitLockForTags();
|
||||
if (!ObjectUtils.isEmpty(skipForTags)) {
|
||||
final Set<DistributionSetTag> tags = jpaDistributionSet.getTags();
|
||||
if (!ObjectUtils.isEmpty(tags)) {
|
||||
for (final DistributionSetTag tag : tags) {
|
||||
if (skipForTags.contains(tag.getName())) {
|
||||
// has a skip tag
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// finally - implicitly lock
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpaDistributionSet getOrElseThrowException(final long id) {
|
||||
return getById(id);
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = TX_RT_MAX, backoff = @Backoff(delay = TX_RT_DELAY))
|
||||
public JpaDistributionSet lock(final DistributionSet distributionSet) {
|
||||
final JpaDistributionSet jpaDistributionSet = toJpaDistributionSet(distributionSet);
|
||||
if (distributionSet.isLocked()) {
|
||||
return jpaDistributionSet;
|
||||
} else {
|
||||
if (!jpaDistributionSet.isComplete()) {
|
||||
throw new IncompleteDistributionSetException("Could not be locked while incomplete!");
|
||||
}
|
||||
lockSoftwareModules(jpaDistributionSet);
|
||||
jpaDistributionSet.setLocked(true);
|
||||
return jpaRepository.save(jpaDistributionSet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = TX_RT_MAX, backoff = @Backoff(delay = TX_RT_DELAY))
|
||||
public JpaDistributionSet unlock(final DistributionSet distributionSet) {
|
||||
final JpaDistributionSet jpaDistributionSet = toJpaDistributionSet(distributionSet);
|
||||
if (jpaDistributionSet.isLocked()) {
|
||||
jpaDistributionSet.setLocked(false);
|
||||
return jpaRepository.save(jpaDistributionSet);
|
||||
} else {
|
||||
return jpaDistributionSet;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public JpaDistributionSet invalidate(final DistributionSet distributionSet) {
|
||||
final JpaDistributionSet jpaDistributionSet = toJpaDistributionSet(distributionSet);
|
||||
jpaDistributionSet.invalidate();
|
||||
return jpaRepository.save(jpaDistributionSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -245,51 +290,6 @@ public class JpaDistributionSetManagement
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = TX_RT_MAX, backoff = @Backoff(delay = TX_RT_DELAY))
|
||||
public JpaDistributionSet lock(final long id) {
|
||||
final JpaDistributionSet distributionSet = getById(id);
|
||||
if (distributionSet.isLocked()) {
|
||||
return distributionSet;
|
||||
} else {
|
||||
lockSoftwareModules(distributionSet);
|
||||
distributionSet.lock();
|
||||
return jpaRepository.save(distributionSet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = TX_RT_MAX, backoff = @Backoff(delay = TX_RT_DELAY))
|
||||
public JpaDistributionSet unlock(final long id) {
|
||||
final JpaDistributionSet distributionSet = getById(id);
|
||||
if (distributionSet.isLocked()) {
|
||||
distributionSet.unlock();
|
||||
return jpaRepository.save(distributionSet);
|
||||
} else {
|
||||
return distributionSet;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<JpaDistributionSet> findByAction(final long actionId) {
|
||||
return actionRepository
|
||||
.findById(actionId)
|
||||
.map(action -> {
|
||||
if (!targetRepository.exists(TargetSpecifications.hasId(action.getTarget().getId()))) {
|
||||
throw new InsufficientPermissionException("Target not accessible (or not found)!");
|
||||
}
|
||||
return jpaRepository
|
||||
.findOne(DistributionSetSpecification.byIdFetch(action.getDistributionSet().getId()))
|
||||
.orElseThrow(() ->
|
||||
new InsufficientPermissionException("DistributionSet not accessible (or not found)!"));
|
||||
})
|
||||
.or(() -> {
|
||||
throw new EntityNotFoundException(Action.class, actionId);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<JpaDistributionSet> findByNameAndVersion(final String distributionName, final String version) {
|
||||
return jpaRepository.findOne(DistributionSetSpecification.equalsNameAndVersionIgnoreCase(distributionName, version));
|
||||
@@ -311,35 +311,6 @@ public class JpaDistributionSetManagement
|
||||
return distributionSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpaDistributionSet getValid(final long id) {
|
||||
return getValid0(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<JpaDistributionSet> findByCompleted(final Boolean complete, final Pageable pageReq) {
|
||||
final List<Specification<JpaDistributionSet>> specifications = buildSpecsByComplete(complete);
|
||||
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(jpaRepository, specifications, pageReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByCompleted(final Boolean complete) {
|
||||
return JpaManagementHelper.countBySpec(jpaRepository, buildSpecsByComplete(complete));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<JpaDistributionSet> findByDistributionSetFilter(final DistributionSetFilter distributionSetFilter, final Pageable pageable) {
|
||||
final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications(distributionSetFilter);
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(jpaRepository, specList, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByDistributionSetFilter(@NotNull final DistributionSetFilter distributionSetFilter) {
|
||||
final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications(distributionSetFilter);
|
||||
return JpaManagementHelper.countBySpec(jpaRepository, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<JpaDistributionSet> findByTag(final long tagId, final Pageable pageable) {
|
||||
assertDsTagExists(tagId);
|
||||
@@ -357,20 +328,6 @@ public class JpaDistributionSetManagement
|
||||
pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByTypeId(final long typeId) {
|
||||
if (!distributionSetTypeManagement.exists(typeId)) {
|
||||
throw new EntityNotFoundException(DistributionSetType.class, typeId);
|
||||
}
|
||||
return jpaRepository.count(DistributionSetSpecification.byType(typeId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse(final long id) {
|
||||
assertDistributionSetExists(id);
|
||||
return actionRepository.countByDistributionSetId(id) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Statistic> countRolloutsByStatusForDistributionSet(final Long id) {
|
||||
assertDistributionSetExists(id);
|
||||
@@ -400,70 +357,6 @@ public class JpaDistributionSetManagement
|
||||
QuotaHelper.assertAssignmentQuota(requested, maxMetaData, String.class, DistributionSet.class);
|
||||
}
|
||||
|
||||
// check if it shall implicitly lock a distribution set
|
||||
boolean isImplicitLockApplicable(final DistributionSet distributionSet) {
|
||||
final JpaDistributionSet jpaDistributionSet = (JpaDistributionSet) distributionSet;
|
||||
if (jpaDistributionSet.isLocked()) {
|
||||
// already locked
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Boolean.FALSE.equals(tenantConfigHelper.getConfigValue(IMPLICIT_LOCK_ENABLED, Boolean.class))) {
|
||||
// implicit lock disabled
|
||||
return false;
|
||||
}
|
||||
|
||||
final List<String> skipForTags = repositoryProperties.getSkipImplicitLockForTags();
|
||||
if (!ObjectUtils.isEmpty(skipForTags)) {
|
||||
final Set<DistributionSetTag> tags = jpaDistributionSet.getTags();
|
||||
if (!ObjectUtils.isEmpty(tags)) {
|
||||
for (final DistributionSetTag tag : tags) {
|
||||
if (skipForTags.contains(tag.getName())) {
|
||||
// has a skip tag
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// finally - implicit lock is applicable
|
||||
return true;
|
||||
}
|
||||
|
||||
private static List<Specification<JpaDistributionSet>> buildDistributionSetSpecifications(
|
||||
final DistributionSetFilter distributionSetFilter) {
|
||||
final List<Specification<JpaDistributionSet>> specList = new ArrayList<>(10);
|
||||
|
||||
if (distributionSetFilter.getIsComplete() != null) {
|
||||
specList.add(DistributionSetSpecification.isCompleted(distributionSetFilter.getIsComplete()));
|
||||
}
|
||||
if (distributionSetFilter.getIsDeleted() != null) {
|
||||
specList.add(DistributionSetSpecification.isDeleted(distributionSetFilter.getIsDeleted()));
|
||||
}
|
||||
if (distributionSetFilter.getIsValid() != null) {
|
||||
specList.add(DistributionSetSpecification.isValid(distributionSetFilter.getIsValid()));
|
||||
}
|
||||
if (distributionSetFilter.getTypeId() != null) {
|
||||
specList.add(DistributionSetSpecification.byType(distributionSetFilter.getTypeId()));
|
||||
}
|
||||
if (!ObjectUtils.isEmpty(distributionSetFilter.getSearchText())) {
|
||||
final String[] dsFilterNameAndVersionEntries = JpaManagementHelper
|
||||
.getFilterNameAndVersionEntries(distributionSetFilter.getSearchText().trim());
|
||||
specList.add(DistributionSetSpecification.likeNameAndVersion(dsFilterNameAndVersionEntries[0], dsFilterNameAndVersionEntries[1]));
|
||||
}
|
||||
if (hasTagsFilterActive(distributionSetFilter)) {
|
||||
specList.add(DistributionSetSpecification.hasTags(
|
||||
distributionSetFilter.getTagNames(), distributionSetFilter.getSelectDSWithNoTag()));
|
||||
}
|
||||
return specList;
|
||||
}
|
||||
|
||||
private static boolean hasTagsFilterActive(final DistributionSetFilter distributionSetFilter) {
|
||||
final boolean isNoTagActive = Boolean.TRUE.equals(distributionSetFilter.getSelectDSWithNoTag());
|
||||
final boolean isAtLeastOneTagActive = !CollectionUtils.isEmpty(distributionSetFilter.getTagNames());
|
||||
return isNoTagActive || isAtLeastOneTagActive;
|
||||
}
|
||||
|
||||
private static Collection<Long> notFound(final Collection<Long> distributionSetIds, final List<JpaDistributionSet> foundDistributionSets) {
|
||||
final Map<Long, JpaDistributionSet> foundDistributionSetMap = foundDistributionSets.stream()
|
||||
.collect(Collectors.toMap(JpaDistributionSet::getId, Function.identity()));
|
||||
@@ -507,15 +400,6 @@ public class JpaDistributionSetManagement
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
|
||||
}
|
||||
|
||||
private List<Specification<JpaDistributionSet>> buildSpecsByComplete(final Boolean complete) {
|
||||
final List<Specification<JpaDistributionSet>> specifications = new ArrayList<>();
|
||||
specifications.add(DistributionSetSpecification.isNotDeleted());
|
||||
if (complete != null) {
|
||||
specifications.add(DistributionSetSpecification.isCompleted(complete));
|
||||
}
|
||||
return specifications;
|
||||
}
|
||||
|
||||
private void assertSoftwareModuleQuota(final Long id, final int requested) {
|
||||
QuotaHelper.assertAssignmentQuota(id, requested, quotaManagement.getMaxSoftwareModulesPerDistributionSet(),
|
||||
SoftwareModule.class, DistributionSet.class, softwareModuleRepository::countByAssignedToId);
|
||||
@@ -544,6 +428,14 @@ public class JpaDistributionSetManagement
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, id));
|
||||
}
|
||||
|
||||
private JpaDistributionSet toJpaDistributionSet(final DistributionSet distributionSet) {
|
||||
if (distributionSet instanceof JpaDistributionSet jpaDistributionSet) {
|
||||
return entityManager.merge(jpaDistributionSet); // if from
|
||||
} else {
|
||||
return getById(distributionSet.getId());
|
||||
}
|
||||
}
|
||||
|
||||
private void assertDistributionSetExists(final long id) {
|
||||
if (!jpaRepository.existsById(id)) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, id);
|
||||
|
||||
@@ -43,39 +43,9 @@ public class JpaDistributionSetTagManagement
|
||||
extends AbstractJpaRepositoryManagement<JpaDistributionSetTag, DistributionSetTagManagement.Create, DistributionSetTagManagement.Update, DistributionSetTagRepository, DistributionSetTagFields>
|
||||
implements DistributionSetTagManagement<JpaDistributionSetTag> {
|
||||
|
||||
private final DistributionSetRepository distributionSetRepository;
|
||||
|
||||
protected JpaDistributionSetTagManagement(
|
||||
final DistributionSetTagRepository distributionSetTagRepository,
|
||||
final EntityManager entityManager,
|
||||
final DistributionSetRepository distributionSetRepository) {
|
||||
final EntityManager entityManager) {
|
||||
super(distributionSetTagRepository, entityManager);
|
||||
this.distributionSetRepository = distributionSetRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<JpaDistributionSetTag> findByName(final String name) {
|
||||
return jpaRepository.findByNameEquals(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<JpaDistributionSetTag> findByDistributionSet(final long distributionSetId, final Pageable pageable) {
|
||||
if (!distributionSetRepository.existsById(distributionSetId)) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, distributionSetId);
|
||||
}
|
||||
|
||||
return JpaManagementHelper.findAllWithCountBySpec(jpaRepository,
|
||||
Collections.singletonList(TagSpecification.ofDistributionSet(distributionSetId)), pageable
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = TX_RT_MAX, backoff = @Backoff(delay = TX_RT_DELAY))
|
||||
public void delete(final String tagName) {
|
||||
final JpaDistributionSetTag dsTag = jpaRepository
|
||||
.findOne(DistributionSetTagSpecifications.byName(tagName))
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName));
|
||||
jpaRepository.delete(dsTag);
|
||||
}
|
||||
}
|
||||
@@ -564,8 +564,8 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
rollout.setTotalTargets(totalTargets);
|
||||
}
|
||||
|
||||
if (((JpaDistributionSetManagement) distributionSetManagement).isImplicitLockApplicable(distributionSet)) {
|
||||
distributionSetManagement.lock(distributionSet.getId());
|
||||
if (distributionSetManagement.shouldLockImplicitly(distributionSet)) {
|
||||
distributionSetManagement.lock(distributionSet);
|
||||
}
|
||||
|
||||
if (rollout.getWeight().isEmpty()) {
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.eclipse.hawkbit.repository.exception.InvalidAutoAssignActionTypeExcep
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetFilterQueryRepository;
|
||||
@@ -164,11 +163,10 @@ class JpaTargetFilterQueryManagement
|
||||
} else {
|
||||
WeightValidationHelper.usingContext(systemSecurityContext, tenantConfigurationManagement).validate(update);
|
||||
assertMaxTargetsQuota(targetFilterQuery.getQuery(), targetFilterQuery.getName(), update.dsId());
|
||||
final JpaDistributionSet distributionSet = (JpaDistributionSet) distributionSetManagement
|
||||
.getValidAndComplete(update.dsId());
|
||||
|
||||
if (((JpaDistributionSetManagement) distributionSetManagement).isImplicitLockApplicable(distributionSet)) {
|
||||
distributionSetManagement.lock(distributionSet.getId());
|
||||
DistributionSet distributionSet = distributionSetManagement.getValidAndComplete(update.dsId());
|
||||
if (distributionSetManagement.shouldLockImplicitly(distributionSet)) {
|
||||
distributionSet = distributionSetManagement.lock(distributionSet);
|
||||
}
|
||||
|
||||
targetFilterQuery.setAutoAssignDistributionSet(distributionSet);
|
||||
|
||||
@@ -20,6 +20,7 @@ import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
|
||||
@@ -29,6 +30,7 @@ import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED) // Default constructor needed for JPA entities
|
||||
@Setter
|
||||
@Getter
|
||||
@ToString(callSuper = true)
|
||||
@MappedSuperclass
|
||||
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities
|
||||
@SuppressWarnings("squid:S2160")
|
||||
|
||||
@@ -16,12 +16,18 @@ import jakarta.persistence.MappedSuperclass;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
|
||||
|
||||
/**
|
||||
* Extension for {@link NamedEntity} that are versioned.
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@ToString(callSuper = true)
|
||||
@MappedSuperclass
|
||||
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities
|
||||
@SuppressWarnings("squid:S2160")
|
||||
@@ -50,13 +56,4 @@ public abstract class AbstractJpaNamedVersionedEntity extends AbstractJpaNamedEn
|
||||
AbstractJpaNamedVersionedEntity() {
|
||||
// Default constructor needed for JPA entities
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(final String version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +124,7 @@ public class JpaDistributionSet
|
||||
@Column(name = "complete")
|
||||
private boolean complete;
|
||||
|
||||
@Setter
|
||||
@Column(name = "locked")
|
||||
private boolean locked;
|
||||
|
||||
@@ -213,31 +214,18 @@ public class JpaDistributionSet
|
||||
return tags.remove(tag);
|
||||
}
|
||||
|
||||
public void lock() {
|
||||
if (!isComplete()) {
|
||||
throw new IncompleteDistributionSetException("Could not be locked while incomplete!");
|
||||
}
|
||||
locked = true;
|
||||
}
|
||||
|
||||
public void unlock() {
|
||||
locked = false;
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
this.valid = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireCreateEvent() {
|
||||
publishEventWithEventPublisher(
|
||||
new DistributionSetCreatedEvent(this));
|
||||
publishEventWithEventPublisher(new DistributionSetCreatedEvent(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireUpdateEvent() {
|
||||
publishEventWithEventPublisher(
|
||||
new DistributionSetUpdatedEvent(this, complete));
|
||||
publishEventWithEventPublisher(new DistributionSetUpdatedEvent(this, complete));
|
||||
|
||||
if (deleted) {
|
||||
publishEventWithEventPublisher(new DistributionSetDeletedEvent(getTenant(), getId(), getClass()));
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaStatistic;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
@@ -65,16 +64,6 @@ public interface DistributionSetRepository extends BaseEntityRepository<JpaDistr
|
||||
@Query(value = "SELECT COUNT(f.autoAssignDistributionSet) FROM JpaTargetFilterQuery f WHERE f.autoAssignDistributionSet.id = :dsId GROUP BY f.autoAssignDistributionSet")
|
||||
Long countAutoAssignmentsForDistributionSet(@Param("dsId") Long dsId);
|
||||
|
||||
/**
|
||||
* Finds {@link DistributionSet}s where given {@link SoftwareModule} is assigned.
|
||||
* <p/>
|
||||
* No access control applied.
|
||||
*
|
||||
* @param moduleId to search for
|
||||
* @return {@link List} of found {@link DistributionSet}s
|
||||
*/
|
||||
Long countByModulesId(Long moduleId);
|
||||
|
||||
/**
|
||||
* Finds {@link DistributionSet}s based on given ID that are assigned yet to an {@link Action}, i.e. in use.
|
||||
* <p/>
|
||||
|
||||
@@ -30,14 +30,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public interface DistributionSetTagRepository
|
||||
extends BaseEntityRepository<JpaDistributionSetTag> {
|
||||
|
||||
/**
|
||||
* find {@link DistributionSetTag} by its name.
|
||||
*
|
||||
* @param tagName to filter on
|
||||
* @return the {@link DistributionSetTag} if found, otherwise null
|
||||
*/
|
||||
Optional<JpaDistributionSetTag> findByNameEquals(String tagName);
|
||||
|
||||
/**
|
||||
* Returns all instances of the type.
|
||||
*
|
||||
@@ -58,4 +50,4 @@ public interface DistributionSetTagRepository
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaDistributionSetTag t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
}
|
||||
}
|
||||
@@ -38,17 +38,6 @@ public interface DistributionSetTypeRepository extends BaseEntityRepository<JpaD
|
||||
*/
|
||||
long countByElementsSmType(JpaSoftwareModuleType softwareModuleType);
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety reasons (this is a "delete everything" query after all) we add
|
||||
* the tenant manually to query even if this will by done by {@link EntityManager} anyhow. The DB should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant to delete data from
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaDistributionSetType t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
|
||||
/**
|
||||
* Counts the {@link SoftwareModuleType}s which are associated with the addressed {@link DistributionSetType}.
|
||||
* <p/>
|
||||
@@ -59,4 +48,15 @@ public interface DistributionSetTypeRepository extends BaseEntityRepository<JpaD
|
||||
*/
|
||||
@Query("SELECT COUNT (e.smType) FROM DistributionSetTypeElement e WHERE e.dsType.id = :id")
|
||||
long countSmTypesById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety reasons (this is a "delete everything" query after all) we add
|
||||
* the tenant manually to query even if this will by done by {@link EntityManager} anyhow. The DB should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant to delete data from
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("DELETE FROM JpaDistributionSetType t WHERE t.tenant = :tenant")
|
||||
void deleteByTenant(@Param("tenant") String tenant);
|
||||
}
|
||||
@@ -14,8 +14,10 @@ import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.run
|
||||
import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.withUser;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.stream.StreamSupport;
|
||||
@@ -50,9 +52,13 @@ import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetTagRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetTypeRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TenantMetaDataRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -67,10 +73,15 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.orm.jpa.vendor.Database;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@Slf4j
|
||||
@ContextConfiguration(classes = { JpaRepositoryConfiguration.class, TestConfiguration.class })
|
||||
@@ -86,9 +97,6 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
|
||||
SpPermission.UPDATE_REPOSITORY, SpPermission.DELETE_REPOSITORY, SpPermission.READ_TARGET, SpPermission.CREATE_TARGET,
|
||||
SpPermission.UPDATE_TARGET, SpPermission.DELETE_TARGET);
|
||||
|
||||
@PersistenceContext
|
||||
protected EntityManager entityManager;
|
||||
|
||||
@Autowired
|
||||
protected TargetRepository targetRepository;
|
||||
@Autowired
|
||||
@@ -307,4 +315,43 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
|
||||
private JpaRollout refresh(final Rollout rollout) {
|
||||
return rolloutRepository.findById(rollout.getId()).get();
|
||||
}
|
||||
|
||||
protected Slice<JpaDistributionSet> findDsByDistributionSetFilter(final DistributionSetFilter distributionSetFilter, final Pageable pageable) {
|
||||
final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications(distributionSetFilter);
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetRepository, specList, pageable);
|
||||
}
|
||||
|
||||
private static List<Specification<JpaDistributionSet>> buildDistributionSetSpecifications(
|
||||
final DistributionSetFilter distributionSetFilter) {
|
||||
final List<Specification<JpaDistributionSet>> specList = new ArrayList<>(10);
|
||||
|
||||
if (distributionSetFilter.getIsComplete() != null) {
|
||||
specList.add(DistributionSetSpecification.isCompleted(distributionSetFilter.getIsComplete()));
|
||||
}
|
||||
if (distributionSetFilter.getIsDeleted() != null) {
|
||||
specList.add(DistributionSetSpecification.isDeleted(distributionSetFilter.getIsDeleted()));
|
||||
}
|
||||
if (distributionSetFilter.getIsValid() != null) {
|
||||
specList.add(DistributionSetSpecification.isValid(distributionSetFilter.getIsValid()));
|
||||
}
|
||||
if (distributionSetFilter.getTypeId() != null) {
|
||||
specList.add(DistributionSetSpecification.byType(distributionSetFilter.getTypeId()));
|
||||
}
|
||||
if (!ObjectUtils.isEmpty(distributionSetFilter.getSearchText())) {
|
||||
final String[] dsFilterNameAndVersionEntries = JpaManagementHelper
|
||||
.getFilterNameAndVersionEntries(distributionSetFilter.getSearchText().trim());
|
||||
specList.add(DistributionSetSpecification.likeNameAndVersion(dsFilterNameAndVersionEntries[0], dsFilterNameAndVersionEntries[1]));
|
||||
}
|
||||
if (hasTagsFilterActive(distributionSetFilter)) {
|
||||
specList.add(DistributionSetSpecification.hasTags(
|
||||
distributionSetFilter.getTagNames(), distributionSetFilter.getSelectDSWithNoTag()));
|
||||
}
|
||||
return specList;
|
||||
}
|
||||
|
||||
private static boolean hasTagsFilterActive(final DistributionSetFilter distributionSetFilter) {
|
||||
final boolean isNoTagActive = Boolean.TRUE.equals(distributionSetFilter.getSelectDSWithNoTag());
|
||||
final boolean isAtLeastOneTagActive = !CollectionUtils.isEmpty(distributionSetFilter.getTagNames());
|
||||
return isNoTagActive || isAtLeastOneTagActive;
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,6 @@ class DistributionSetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet hidden = testdataFactory.createDistributionSet();
|
||||
|
||||
final Action permittedAction = testdataFactory.performAssignment(permitted);
|
||||
final Action hiddenAction = testdataFactory.performAssignment(hidden);
|
||||
|
||||
runAs(withUser("user",
|
||||
READ_REPOSITORY,
|
||||
@@ -74,15 +73,6 @@ class DistributionSetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(distributionSetManagement.findByRsql("name==*", Pageable.unpaged()).get().map(Identifiable::getId)
|
||||
.toList()).containsOnly(permittedActionId);
|
||||
|
||||
// verify distributionSetManagement#findByCompleted
|
||||
assertThat(distributionSetManagement.findByCompleted(true, Pageable.unpaged()).get().map(Identifiable::getId)
|
||||
.toList()).containsOnly(permittedActionId);
|
||||
|
||||
// verify distributionSetManagement#findByDistributionSetFilter
|
||||
assertThat(distributionSetManagement
|
||||
.findByDistributionSetFilter(DistributionSetFilter.builder().isDeleted(false).build(), Pageable.unpaged())
|
||||
.get().map(Identifiable::getId).toList()).containsOnly(permittedActionId);
|
||||
|
||||
// verify distributionSetManagement#get
|
||||
assertThat(distributionSetManagement.get(permittedActionId)).isPresent();
|
||||
final Long hiddenId = hidden.getId();
|
||||
@@ -92,11 +82,6 @@ class DistributionSetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(distributionSetManagement.getWithDetails(permittedActionId)).isPresent();
|
||||
assertThat(distributionSetManagement.getWithDetails(hiddenId)).isEmpty();
|
||||
|
||||
// verify distributionSetManagement#get
|
||||
assertThat(distributionSetManagement.getValid(permittedActionId).getId()).isEqualTo(permittedActionId);
|
||||
assertThatThrownBy(() -> distributionSetManagement.getValid(hiddenId))
|
||||
.as("Distribution set should not be found.").isInstanceOf(EntityNotFoundException.class);
|
||||
|
||||
// verify distributionSetManagement#get
|
||||
final List<Long> allActionIds = Arrays.asList(permittedActionId, hiddenId);
|
||||
assertThatThrownBy(() -> distributionSetManagement.get(allActionIds))
|
||||
@@ -105,12 +90,6 @@ class DistributionSetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
// verify distributionSetManagement#getByNameAndVersion
|
||||
assertThat(distributionSetManagement.findByNameAndVersion(permitted.getName(), permitted.getVersion())).isPresent();
|
||||
assertThat(distributionSetManagement.findByNameAndVersion(hidden.getName(), hidden.getVersion())).isEmpty();
|
||||
|
||||
// verify distributionSetManagement#getByAction
|
||||
assertThat(distributionSetManagement.findByAction(permittedAction.getId())).isPresent();
|
||||
final Long hiddenActionId = hiddenAction.getId();
|
||||
assertThatThrownBy(() -> distributionSetManagement.findByAction(hiddenActionId))
|
||||
.as("Action is hidden.").isInstanceOf(InsufficientPermissionException.class);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -254,9 +233,9 @@ class DistributionSetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet readOnly = testdataFactory.createDistributionSet();
|
||||
final DistributionSet hidden = testdataFactory.createDistributionSet();
|
||||
// has to lock them, otherwise implicit lock shall be made which require DistributionSet update permissions
|
||||
distributionSetManagement.lock(permitted.getId());
|
||||
distributionSetManagement.lock(readOnly.getId());
|
||||
distributionSetManagement.lock(hidden.getId());
|
||||
distributionSetManagement.lock(permitted);
|
||||
distributionSetManagement.lock(readOnly);
|
||||
distributionSetManagement.lock(hidden);
|
||||
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.create(TargetFilterQueryManagement.Create.builder().name("test").query("id==*").build());
|
||||
|
||||
@@ -196,8 +196,8 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void verifyTargetAssignment() {
|
||||
final Long dsId = testdataFactory.createDistributionSet("myDs").getId();
|
||||
distributionSetManagement.lock(dsId);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("myDs");
|
||||
distributionSetManagement.lock(ds);
|
||||
|
||||
final Target permittedTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device01").status(TargetUpdateStatus.REGISTERED));
|
||||
@@ -214,6 +214,7 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
READ_TARGET + "/controllerId==" + permittedTarget.getControllerId(),
|
||||
UPDATE_TARGET + "/controllerId==" + permittedTarget.getControllerId(),
|
||||
READ_REPOSITORY), () -> {
|
||||
final Long dsId = ds.getId();
|
||||
assertThat(assignDistributionSet(dsId, permittedTarget.getControllerId()).getAssigned()).isEqualTo(1);
|
||||
// assigning of not allowed target behaves as not found
|
||||
assertThatThrownBy(() -> assignDistributionSet(dsId, hiddenTargetControllerId)).isInstanceOf(AssertionError.class);
|
||||
@@ -233,10 +234,10 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void verifyTargetAssignmentOnNonUpdatableTarget() {
|
||||
final Long firstDsId = testdataFactory.createDistributionSet("myDs").getId();
|
||||
distributionSetManagement.lock(firstDsId);
|
||||
final DistributionSet firstDs = testdataFactory.createDistributionSet("myDs");
|
||||
distributionSetManagement.lock(firstDs);
|
||||
final DistributionSet secondDs = testdataFactory.createDistributionSet("anotherDs");
|
||||
distributionSetManagement.lock(secondDs.getId());
|
||||
distributionSetManagement.lock(secondDs);
|
||||
|
||||
final Target manageableTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device01").status(TargetUpdateStatus.REGISTERED));
|
||||
@@ -247,6 +248,7 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
READ_TARGET + "/controllerId==" + manageableTarget.getControllerId() + " or controllerId==" + readOnlyTarget.getControllerId(),
|
||||
UPDATE_TARGET + "/controllerId==" + manageableTarget.getControllerId(),
|
||||
READ_REPOSITORY), () -> {
|
||||
final Long firstDsId = firstDs.getId();
|
||||
// assignment is permitted for manageableTarget
|
||||
assertThat(assignDistributionSet(firstDsId, manageableTarget.getControllerId()).getAssigned()).isEqualTo(1);
|
||||
|
||||
@@ -267,7 +269,7 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void verifyRolloutTargetScope() {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("myDs");
|
||||
distributionSetManagement.lock(ds.getId());
|
||||
distributionSetManagement.lock(ds);
|
||||
|
||||
final String[] updateTargetControllerIds = { "update1", "update2", "update3" };
|
||||
final List<Target> updateTargets = testdataFactory.createTargets(updateTargetControllerIds);
|
||||
@@ -307,7 +309,7 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void verifyAutoAssignmentTargetScope() {
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
|
||||
distributionSetManagement.lock(distributionSet.getId());
|
||||
distributionSetManagement.lock(distributionSet);
|
||||
|
||||
final String[] updateTargetControllerIds = { "update1", "update2", "update3" };
|
||||
final List<Target> updateTargets = testdataFactory.createTargets(updateTargetControllerIds);
|
||||
|
||||
@@ -63,7 +63,7 @@ class DeploymentManagementSecurityTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void offlineAssignedDistributionSetsWithInitiatedByPermissionsCheck() {
|
||||
assertPermissions(() -> deploymentManagement.offlineAssignedDistributionSets(List.of(), "initiator"),
|
||||
assertPermissions(() -> deploymentManagement.offlineAssignedDistributionSets("initiator", List.of()),
|
||||
List.of(SpPermission.READ_REPOSITORY, SpPermission.UPDATE_TARGET));
|
||||
}
|
||||
|
||||
|
||||
@@ -1356,7 +1356,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
// verify that deleted attribute is used correctly
|
||||
List<? extends DistributionSet> allFoundDS = distributionSetManagement.findByCompleted(true, PAGE).getContent();
|
||||
List<? extends DistributionSet> allFoundDS = distributionSetManagement.findAll(PAGE).getContent();
|
||||
assertThat(allFoundDS).as("no ds should be founded").isEmpty();
|
||||
|
||||
assertThat(distributionSetRepository.findAll(SpecificationsBuilder.combineWithAnd(Arrays
|
||||
@@ -1368,16 +1368,13 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// try to delete again
|
||||
distributionSetManagement.delete(deploymentResult.getDistributionSetIDs());
|
||||
// verify that the result is the same, even though distributionSet dsA
|
||||
// has been installed
|
||||
// successfully and no activeAction is referring to created distribution
|
||||
// sets
|
||||
allFoundDS = distributionSetManagement.findByCompleted(true, pageRequest).getContent();
|
||||
// verify that the result is the same, even though distributionSet dsA has been installed
|
||||
// successfully and no activeAction is referring to created distribution sets
|
||||
allFoundDS = distributionSetManagement.findAll(pageRequest).getContent();
|
||||
assertThat(allFoundDS).as("no ds should be founded").isEmpty();
|
||||
assertThat(distributionSetRepository.findAll(SpecificationsBuilder.combineWithAnd(Arrays
|
||||
.asList(DistributionSetSpecification.isDeleted(true), DistributionSetSpecification.isCompleted(true))),
|
||||
PAGE).getContent()).as("wrong size of founded ds").hasSize(noOfDistributionSets);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,11 +14,8 @@ import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractRepositoryManagementSecurityTest;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
@@ -119,10 +116,8 @@ class DistributionSetManagementSecurityTest
|
||||
*/
|
||||
@Test
|
||||
void lockPermissionsCheck() {
|
||||
assertPermissions(() -> {
|
||||
distributionSetManagement.lock(1L);
|
||||
return null;
|
||||
}, List.of(SpPermission.UPDATE_REPOSITORY));
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet();
|
||||
assertPermissions(() -> distributionSetManagement.lock(ds), List.of(SpPermission.UPDATE_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,18 +125,8 @@ class DistributionSetManagementSecurityTest
|
||||
*/
|
||||
@Test
|
||||
void unlockPermissionsCheck() {
|
||||
assertPermissions(() -> {
|
||||
distributionSetManagement.unlock(1L);
|
||||
return null;
|
||||
}, List.of(SpPermission.UPDATE_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void getByActionPermissionsCheck() {
|
||||
assertPermissions(() -> distributionSetManagement.findByAction(1L), List.of(SpPermission.READ_REPOSITORY));
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet();
|
||||
assertPermissions(() -> distributionSetManagement.unlock(ds), List.of(SpPermission.UPDATE_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,14 +153,6 @@ class DistributionSetManagementSecurityTest
|
||||
assertPermissions(() -> distributionSetManagement.getValidAndComplete(1L), List.of(SpPermission.READ_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void getValidPermissionsCheck() {
|
||||
assertPermissions(() -> distributionSetManagement.getValid(1L), List.of(SpPermission.READ_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@@ -184,40 +161,6 @@ class DistributionSetManagementSecurityTest
|
||||
assertPermissions(() -> distributionSetManagement.getOrElseThrowException(1L), List.of(SpPermission.READ_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void findByCompletedPermissionsCheck() {
|
||||
assertPermissions(() -> distributionSetManagement.findByCompleted(true, PAGE), List.of(SpPermission.READ_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void countByCompletedPermissionsCheck() {
|
||||
assertPermissions(() -> distributionSetManagement.countByCompleted(true), List.of(SpPermission.READ_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void findByDistributionSetFilterPermissionsCheck() {
|
||||
assertPermissions(() -> distributionSetManagement.findByDistributionSetFilter(DistributionSetFilter.builder().build(), PAGE),
|
||||
List.of(SpPermission.READ_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void countByDistributionSetFilterPermissionsCheck() {
|
||||
assertPermissions(() -> distributionSetManagement.countByDistributionSetFilter(DistributionSetFilter.builder().build()),
|
||||
List.of(SpPermission.READ_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@@ -234,14 +177,6 @@ class DistributionSetManagementSecurityTest
|
||||
assertPermissions(() -> distributionSetManagement.findByRsqlAndTag("rsql", 1L, PAGE), List.of(SpPermission.READ_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void isInUsePermissionsCheck() {
|
||||
assertPermissions(() -> distributionSetManagement.isInUse(1L), List.of(SpPermission.READ_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@@ -250,14 +185,6 @@ class DistributionSetManagementSecurityTest
|
||||
assertPermissions(() -> distributionSetManagement.unassignSoftwareModule(1L, 1L), List.of(SpPermission.UPDATE_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void countByTypeIdPermissionsCheck() {
|
||||
assertPermissions(() -> distributionSetManagement.countByTypeId(1L), List.of(SpPermission.READ_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@@ -287,13 +214,8 @@ class DistributionSetManagementSecurityTest
|
||||
*/
|
||||
@Test
|
||||
void invalidatePermissionsCheck() {
|
||||
final DistributionSetType dsType = distributionSetTypeManagement.create(DistributionSetTypeManagement.Create.builder()
|
||||
.key("type").name("name").build());
|
||||
final DistributionSet ds = distributionSetManagement.create(DistributionSetManagement.Create.builder()
|
||||
.type(dsType).name("test").version("1.0.0").build());
|
||||
assertPermissions(() -> {
|
||||
((DistributionSetManagement) distributionSetManagement).invalidate(ds);
|
||||
return null;
|
||||
}, List.of(SpPermission.UPDATE_REPOSITORY, SpPermission.READ_REPOSITORY));
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet();
|
||||
assertPermissions(() -> distributionSetManagement.invalidate(ds),
|
||||
List.of(SpPermission.UPDATE_REPOSITORY, SpPermission.READ_REPOSITORY));
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,6 @@ import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdated
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
|
||||
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
|
||||
@@ -117,8 +116,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
verifyThrownExceptionBy(
|
||||
() -> distributionSetManagement.assignSoftwareModules(set.getId(), singletonList(NOT_EXIST_IDL)), "SoftwareModule");
|
||||
|
||||
verifyThrownExceptionBy(() -> distributionSetManagement.countByTypeId(NOT_EXIST_IDL), "DistributionSet");
|
||||
|
||||
verifyThrownExceptionBy(() -> distributionSetManagement.unassignSoftwareModule(NOT_EXIST_IDL, module.getId()), "DistributionSet");
|
||||
verifyThrownExceptionBy(() -> distributionSetManagement.unassignSoftwareModule(set.getId(), NOT_EXIST_IDL), "SoftwareModule");
|
||||
|
||||
@@ -143,27 +140,17 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
verifyThrownExceptionBy(() -> distributionSetManagement.deleteMetadata(NOT_EXIST_IDL, "xxx"), "DistributionSet");
|
||||
verifyThrownExceptionBy(() -> distributionSetManagement.deleteMetadata(set.getId(), NOT_EXIST_ID), "DistributionSet");
|
||||
|
||||
verifyThrownExceptionBy(() -> distributionSetManagement.findByAction(NOT_EXIST_IDL), "Action");
|
||||
|
||||
verifyThrownExceptionBy(() -> distributionSetManagement.getMetadata(NOT_EXIST_IDL).get("xxx"), "DistributionSet");
|
||||
|
||||
verifyThrownExceptionBy(() -> distributionSetManagement.getMetadata(NOT_EXIST_IDL).get(PAGE), "DistributionSet");
|
||||
|
||||
assertThatThrownBy(() -> distributionSetManagement.isInUse(NOT_EXIST_IDL))
|
||||
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining(NOT_EXIST_ID)
|
||||
.hasMessageContaining("DistributionSet");
|
||||
verifyThrownExceptionBy(() -> distributionSetManagement.getMetadata(NOT_EXIST_IDL), "DistributionSet");
|
||||
|
||||
verifyThrownExceptionBy(
|
||||
() -> distributionSetManagement.update(DistributionSetManagement.Update.builder().id(NOT_EXIST_IDL).build()),
|
||||
"DistributionSet");
|
||||
|
||||
verifyThrownExceptionBy(() -> distributionSetManagement.createMetadata(NOT_EXIST_IDL, "xxx", "xxx"), "DistributionSet");
|
||||
|
||||
verifyThrownExceptionBy(() -> distributionSetManagement.getOrElseThrowException(NOT_EXIST_IDL), "DistributionSet");
|
||||
|
||||
verifyThrownExceptionBy(() -> distributionSetManagement.getValidAndComplete(NOT_EXIST_IDL), "DistributionSet");
|
||||
|
||||
verifyThrownExceptionBy(() -> distributionSetManagement.getValid(NOT_EXIST_IDL), "DistributionSet");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,7 +292,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.as("ds has wrong tag size")
|
||||
.hasSize(1));
|
||||
|
||||
final DistributionSetTag findDistributionSetTag = getOrThrow(distributionSetTagManagement.findByName(TAG1_NAME));
|
||||
final DistributionSetTag findDistributionSetTag = getOrThrow(distributionSetTagManagement.get(tag.getId()));
|
||||
|
||||
assertThat(assignedDS)
|
||||
.as("assigned ds has wrong size")
|
||||
@@ -315,7 +302,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.unassignTag(List.of(assignDS.get(0)), findDistributionSetTag.getId()).get(0);
|
||||
assertThat(unAssignDS.getId()).as("unassigned ds is wrong").isEqualTo(assignDS.get(0));
|
||||
assertThat(unAssignDS.getTags()).as("unassigned ds has wrong tag size").isEmpty();
|
||||
assertThat(distributionSetTagManagement.findByName(TAG1_NAME)).isPresent();
|
||||
assertThat(distributionSetTagManagement.get(tag.getId())).isPresent();
|
||||
assertThat(distributionSetManagement.findByTag(tag.getId(), PAGE).getNumberOfElements())
|
||||
.as("ds tag ds has wrong ds size").isEqualTo(3);
|
||||
|
||||
@@ -534,7 +521,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(reloadedDS.getLastModifiedAt()).isPositive();
|
||||
|
||||
// verify updated meta data is the updated value
|
||||
assertThat(distributionSetManagement.getMetadata(ds.getId()).get(knownKey)).isEqualTo(knownUpdateValue);
|
||||
assertThat(distributionSetManagement.getMetadata(ds.getId())).containsEntry(knownKey, knownUpdateValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -578,11 +565,11 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
dsDeleted = getOrThrow(distributionSetManagement.get(dsDeleted.getId()));
|
||||
|
||||
dsGroup1 = assignTag(dsGroup1, dsTagA);
|
||||
dsTagA = getOrThrow(distributionSetTagRepository.findByNameEquals(dsTagA.getName()));
|
||||
dsTagA = getOrThrow(distributionSetTagRepository.findById(dsTagA.getId()));
|
||||
dsGroup1 = assignTag(dsGroup1, dsTagB);
|
||||
dsTagA = getOrThrow(distributionSetTagRepository.findByNameEquals(dsTagA.getName()));
|
||||
dsTagA = getOrThrow(distributionSetTagRepository.findById(dsTagA.getId()));
|
||||
dsGroup2 = assignTag(dsGroup2, dsTagA);
|
||||
dsTagA = getOrThrow(distributionSetTagRepository.findByNameEquals(dsTagA.getName()));
|
||||
dsTagA = getOrThrow(distributionSetTagRepository.findById(dsTagA.getId()));
|
||||
|
||||
final List<? extends DistributionSet> allDistributionSets = Stream
|
||||
.of(dsGroup1, dsGroup2, Arrays.asList(dsDeleted, dsInComplete, dsNewType)).flatMap(Collection::stream)
|
||||
@@ -607,33 +594,19 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
validateDeletedAndCompletedAndTypeAndSearchTextAndTag(dsGroup2, dsTagA, dsGroup2Prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple DS load without the related data that should be loaded lazy.
|
||||
*/
|
||||
@Test
|
||||
void findDistributionSetsWithoutLazy() {
|
||||
testdataFactory.createDistributionSets(20);
|
||||
|
||||
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).hasSize(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Locks a DS.
|
||||
*/
|
||||
@Test
|
||||
void lockDistributionSet() {
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
|
||||
assertThat(
|
||||
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(true))
|
||||
.isFalse();
|
||||
distributionSetManagement.lock(distributionSet.getId());
|
||||
assertThat(
|
||||
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false))
|
||||
.isTrue();
|
||||
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(true)).isFalse();
|
||||
distributionSetManagement.lock(distributionSet);
|
||||
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false)).isTrue();
|
||||
// assert software modules are locked
|
||||
assertThat(distributionSet.getModules().size()).isNotZero();
|
||||
distributionSetManagement.getWithDetails(distributionSet.getId()).map(DistributionSet::getModules)
|
||||
.orElseThrow().forEach(module -> assertThat(module.isLocked()).isTrue());
|
||||
distributionSetManagement.getWithDetails(distributionSet.getId()).map(DistributionSet::getModules).orElseThrow()
|
||||
.forEach(module -> assertThat(module.isLocked()).isTrue());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -642,11 +615,8 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void deleteUnassignedLockedDistributionSet() {
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
|
||||
distributionSetManagement.lock(distributionSet.getId());
|
||||
assertThat(
|
||||
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked)
|
||||
.orElse(false))
|
||||
.isTrue();
|
||||
distributionSetManagement.lock(distributionSet);
|
||||
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false)).isTrue();
|
||||
|
||||
distributionSetManagement.delete(distributionSet.getId());
|
||||
assertThat(distributionSetManagement.get(distributionSet.getId())).isEmpty();
|
||||
@@ -658,11 +628,8 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void deleteAssignedLockedDistributionSet() {
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
|
||||
distributionSetManagement.lock(distributionSet.getId());
|
||||
assertThat(
|
||||
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked)
|
||||
.orElse(false))
|
||||
.isTrue();
|
||||
distributionSetManagement.lock(distributionSet);
|
||||
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false)).isTrue();
|
||||
|
||||
final Target target = testdataFactory.createTarget();
|
||||
assignDistributionSet(distributionSet.getId(), target.getControllerId());
|
||||
@@ -676,21 +643,15 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void unlockDistributionSet() {
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
|
||||
distributionSetManagement.lock(distributionSet.getId());
|
||||
assertThat(
|
||||
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked)
|
||||
.orElse(false))
|
||||
.isTrue();
|
||||
distributionSetManagement.unlock(distributionSet.getId());
|
||||
assertThat(
|
||||
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked)
|
||||
.orElse(true))
|
||||
.isFalse();
|
||||
DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
|
||||
distributionSet = distributionSetManagement.lock(distributionSet);
|
||||
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false)).isTrue();
|
||||
distributionSet = distributionSetManagement.unlock(distributionSet);
|
||||
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(true)).isFalse();
|
||||
// assert software modules are not unlocked
|
||||
assertThat(distributionSet.getModules().size()).isNotZero();
|
||||
distributionSetManagement.getWithDetails(distributionSet.getId()).map(DistributionSet::getModules)
|
||||
.orElseThrow().forEach(module -> assertThat(module.isLocked()).isTrue());
|
||||
distributionSetManagement.getWithDetails(distributionSet.getId()).map(DistributionSet::getModules).orElseThrow()
|
||||
.forEach(module -> assertThat(module.isLocked()).isTrue());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -701,8 +662,8 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
|
||||
final int softwareModuleCount = distributionSet.getModules().size();
|
||||
assertThat(softwareModuleCount).isNotZero();
|
||||
distributionSetManagement.lock(distributionSet);
|
||||
final Long distributionSetId = distributionSet.getId();
|
||||
distributionSetManagement.lock(distributionSetId);
|
||||
assertThat(distributionSetManagement.get(distributionSetId).map(DistributionSet::isLocked).orElse(false)).isTrue();
|
||||
|
||||
// try add
|
||||
@@ -710,16 +671,16 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThatExceptionOfType(LockedException.class)
|
||||
.as("Attempt to modify a locked DS software modules should throw an exception")
|
||||
.isThrownBy(() -> distributionSetManagement.assignSoftwareModules(distributionSetId, moduleIds));
|
||||
assertThat(distributionSetManagement.getWithDetails(distributionSetId).get().getModules())
|
||||
assertThat(distributionSetManagement.getWithDetails(distributionSetId).orElseThrow().getModules())
|
||||
.as("Software module shall not be added to a locked DS.")
|
||||
.hasSize(softwareModuleCount);
|
||||
|
||||
// try remove
|
||||
final Long fisrtModuleId = distributionSet.getModules().stream().findFirst().get().getId();
|
||||
final Long firstModuleId = distributionSet.getModules().stream().findFirst().orElseThrow().getId();
|
||||
assertThatExceptionOfType(LockedException.class)
|
||||
.as("Attempt to modify a locked DS software modules should throw an exception")
|
||||
.isThrownBy(() -> distributionSetManagement.unassignSoftwareModule(distributionSetId, fisrtModuleId));
|
||||
assertThat(distributionSetManagement.getWithDetails(distributionSetId).get().getModules())
|
||||
.isThrownBy(() -> distributionSetManagement.unassignSoftwareModule(distributionSetId, firstModuleId));
|
||||
assertThat(distributionSetManagement.getWithDetails(distributionSetId).orElseThrow().getModules())
|
||||
.as("Software module shall not be removed from a locked DS.")
|
||||
.hasSize(softwareModuleCount);
|
||||
}
|
||||
@@ -729,11 +690,11 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
void isImplicitLockApplicableForDistributionSet() {
|
||||
void shouldLockImplicitlyForDistributionSet() {
|
||||
final JpaDistributionSetManagement distributionSetManagement = (JpaDistributionSetManagement) (DistributionSetManagement) this.distributionSetManagement;
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-non-skip");
|
||||
// assert that implicit lock is applicable for non skip tags
|
||||
assertThat(distributionSetManagement.isImplicitLockApplicable(distributionSet)).isTrue();
|
||||
assertThat(distributionSetManagement.shouldLockImplicitly(distributionSet)).isTrue();
|
||||
|
||||
assertThat(repositoryProperties.getSkipImplicitLockForTags().size()).isNotZero();
|
||||
final List<? extends DistributionSetTag> skipTags = distributionSetTagManagement.create(
|
||||
@@ -750,7 +711,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
distributionSetManagement.assignTag(List.of(distributionSetWithSkipTag.getId()), skipTag.getId());
|
||||
distributionSetWithSkipTag = distributionSetManagement.get(distributionSetWithSkipTag.getId()).orElseThrow();
|
||||
// assert that implicit lock isn't applicable for skip tags
|
||||
assertThat(distributionSetManagement.isImplicitLockApplicable(distributionSetWithSkipTag)).isFalse();
|
||||
assertThat(distributionSetManagement.shouldLockImplicitly(distributionSetWithSkipTag)).isFalse();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -759,12 +720,12 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void lockIncompleteDistributionSetFails() {
|
||||
final long incompleteDistributionSetId = testdataFactory.createIncompleteDistributionSet().getId();
|
||||
final DistributionSet incompleteDistributionSet = testdataFactory.createIncompleteDistributionSet();
|
||||
assertThatExceptionOfType(IncompleteDistributionSetException.class)
|
||||
.as("Locking an incomplete distribution set should throw an exception")
|
||||
.isThrownBy(() -> distributionSetManagement.lock(incompleteDistributionSetId));
|
||||
.isThrownBy(() -> distributionSetManagement.lock(incompleteDistributionSet));
|
||||
assertThat(
|
||||
distributionSetManagement.get(incompleteDistributionSetId).map(DistributionSet::isLocked).orElse(true))
|
||||
distributionSetManagement.get(incompleteDistributionSet.getId()).map(DistributionSet::isLocked).orElse(true))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@@ -781,7 +742,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
distributionSetManagement.delete(ds1.getId());
|
||||
// not assigned so not marked as deleted but fully deleted
|
||||
assertThat(distributionSetRepository.findAll()).hasSize(1);
|
||||
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).hasSize(1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -851,7 +811,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// not assigned so not marked as deleted
|
||||
assertThat(distributionSetRepository.findAll()).hasSize(4);
|
||||
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).hasSize(2);
|
||||
assertThat(distributionSetManagement.findAll(PAGE)).hasSize(2);
|
||||
assertThat(distributionSetManagement.findByRsql("name==*", PAGE)).hasSize(2);
|
||||
assertThat(distributionSetManagement.count()).isEqualTo(2);
|
||||
@@ -887,10 +846,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void verifyGetValid() {
|
||||
final Long distributionSetId = testdataFactory.createAndInvalidateDistributionSet().getId();
|
||||
|
||||
assertThatExceptionOfType(InvalidDistributionSetException.class)
|
||||
.as("Invalid distributionSet should throw an exception")
|
||||
.isThrownBy(() -> distributionSetManagement.getValid(distributionSetId));
|
||||
assertThatExceptionOfType(InvalidDistributionSetException.class)
|
||||
.as("Invalid distributionSet should throw an exception")
|
||||
.isThrownBy(() -> distributionSetManagement.getValidAndComplete(distributionSetId));
|
||||
@@ -1098,7 +1053,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void validateDeleted(final DistributionSet deletedDistributionSet, final int notDeletedSize) {
|
||||
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(DistributionSetFilter.builder().isDeleted(Boolean.TRUE),
|
||||
singletonList(deletedDistributionSet));
|
||||
|
||||
@@ -1107,7 +1061,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void validateCompleted(final DistributionSet dsIncomplete, final int completedSize) {
|
||||
|
||||
assertThatFilterHasSizeAndDoesNotContainDistributionSet(
|
||||
DistributionSetFilter.builder().isComplete(Boolean.TRUE), completedSize, dsIncomplete);
|
||||
|
||||
@@ -1115,8 +1068,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
DistributionSetFilter.builder().isComplete(Boolean.FALSE), singletonList(dsIncomplete));
|
||||
}
|
||||
|
||||
private void validateType(final DistributionSetType newType, final DistributionSet dsNewType,
|
||||
final int standardDsTypeSize) {
|
||||
private void validateType(final DistributionSetType newType, final DistributionSet dsNewType, final int standardDsTypeSize) {
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(DistributionSetFilter.builder().typeId(newType.getId()),
|
||||
singletonList(dsNewType));
|
||||
assertThatFilterHasSizeAndDoesNotContainDistributionSet(
|
||||
@@ -1277,19 +1229,17 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
private void assertThatFilterContainsOnlyGivenDistributionSets(final DistributionSetFilterBuilder filterBuilder,
|
||||
final List<? extends DistributionSet> distributionSets) {
|
||||
final int expectedDsSize = distributionSets.size();
|
||||
assertThat(((DistributionSetManagement)distributionSetManagement).findByDistributionSetFilter(filterBuilder.build(), PAGE).getContent())
|
||||
.hasSize(expectedDsSize).containsOnly(distributionSets.toArray(new DistributionSet[expectedDsSize]));
|
||||
assertThat(findDsByDistributionSetFilter(filterBuilder.build(), PAGE).getContent())
|
||||
.hasSize(expectedDsSize).containsOnly(distributionSets.toArray(new JpaDistributionSet[expectedDsSize]));
|
||||
}
|
||||
|
||||
private void assertThatFilterDoesNotContainAnyDistributionSet(final DistributionSetFilterBuilder filterBuilder) {
|
||||
assertThat(distributionSetManagement.findByDistributionSetFilter(filterBuilder.build(), PAGE).getContent())
|
||||
.isEmpty();
|
||||
assertThat(findDsByDistributionSetFilter(filterBuilder.build(), PAGE).getContent()).isEmpty();
|
||||
}
|
||||
|
||||
private void assertThatFilterHasSizeAndDoesNotContainDistributionSet(
|
||||
final DistributionSetFilterBuilder filterBuilder, final int size, final DistributionSet ds) {
|
||||
assertThat(((DistributionSetManagement)distributionSetManagement).findByDistributionSetFilter(filterBuilder.build(), PAGE).getContent())
|
||||
.hasSize(size).doesNotContain(ds);
|
||||
assertThat((List)findDsByDistributionSetFilter(filterBuilder.build(), PAGE).getContent()).hasSize(size).doesNotContain(ds);
|
||||
}
|
||||
|
||||
// can be removed with java-11
|
||||
|
||||
@@ -41,32 +41,4 @@ class DistributionSetTagManagementSecurityTest
|
||||
protected DistributionSetTagManagement.Update getUpdateObject() {
|
||||
return DistributionSetTagManagement.Update.builder().id(1L).name("tag").build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void getByNameWitPermissionWorks() {
|
||||
assertPermissions(() -> distributionSetTagManagement.findByName("tagName"), List.of(SpPermission.READ_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void findByDistributionSetPermissionsCheck() {
|
||||
assertPermissions(() -> distributionSetTagManagement.findByDistributionSet(1L, Pageable.unpaged()),
|
||||
List.of(SpPermission.READ_REPOSITORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void deleteDistributionSetTagPermissionsCheck() {
|
||||
assertPermissions(() -> {
|
||||
distributionSetTagManagement.delete("tagName");
|
||||
return null;
|
||||
}, List.of(SpPermission.DELETE_REPOSITORY));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,15 +45,12 @@ import org.springframework.data.domain.Pageable;
|
||||
*/
|
||||
class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private static final Random RND = new Random();
|
||||
|
||||
/**
|
||||
* Verifies that management get access reacts as specified on calls for non existing entities by means of Optional not present.
|
||||
*/
|
||||
@Test
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||
void nonExistingEntityAccessReturnsNotPresent() {
|
||||
assertThat(distributionSetTagManagement.findByName(NOT_EXIST_ID)).isNotPresent();
|
||||
assertThat(distributionSetTagManagement.get(NOT_EXIST_IDL)).isNotPresent();
|
||||
}
|
||||
|
||||
@@ -66,8 +63,7 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = DistributionSetTagUpdatedEvent.class, count = 0),
|
||||
@Expect(type = TargetTagUpdatedEvent.class, count = 0) })
|
||||
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||
verifyThrownExceptionBy(() -> distributionSetTagManagement.delete(NOT_EXIST_ID), "DistributionSetTag");
|
||||
verifyThrownExceptionBy(() -> distributionSetTagManagement.findByDistributionSet(NOT_EXIST_IDL, PAGE), "DistributionSet");
|
||||
verifyThrownExceptionBy(() -> distributionSetTagManagement.delete(NOT_EXIST_IDL), "DistributionSetTag");
|
||||
verifyThrownExceptionBy(() -> distributionSetTagManagement.update(
|
||||
DistributionSetTagManagement.Update.builder().id(NOT_EXIST_IDL).build()), "DistributionSetTag");
|
||||
}
|
||||
@@ -95,18 +91,18 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
assignTag(dsBs, tagB);
|
||||
assignTag(dsCs, tagC);
|
||||
|
||||
assignTag(dsABs, distributionSetTagManagement.findByName(tagA.getName()).get());
|
||||
assignTag(dsABs, distributionSetTagManagement.findByName(tagB.getName()).get());
|
||||
assignTag(dsABs, distributionSetTagManagement.get(tagA.getId()).orElseThrow());
|
||||
assignTag(dsABs, distributionSetTagManagement.get(tagB.getId()).orElseThrow());
|
||||
|
||||
assignTag(dsACs, distributionSetTagManagement.findByName(tagA.getName()).get());
|
||||
assignTag(dsACs, distributionSetTagManagement.findByName(tagC.getName()).get());
|
||||
assignTag(dsACs, distributionSetTagManagement.get(tagA.getId()).orElseThrow());
|
||||
assignTag(dsACs, distributionSetTagManagement.get(tagC.getId()).orElseThrow());
|
||||
|
||||
assignTag(dsBCs, distributionSetTagManagement.findByName(tagB.getName()).get());
|
||||
assignTag(dsBCs, distributionSetTagManagement.findByName(tagC.getName()).get());
|
||||
assignTag(dsBCs, distributionSetTagManagement.get(tagB.getId()).orElseThrow());
|
||||
assignTag(dsBCs, distributionSetTagManagement.get(tagC.getId()).orElseThrow());
|
||||
|
||||
assignTag(dsABCs, distributionSetTagManagement.findByName(tagA.getName()).get());
|
||||
assignTag(dsABCs, distributionSetTagManagement.findByName(tagB.getName()).get());
|
||||
assignTag(dsABCs, distributionSetTagManagement.findByName(tagC.getName()).get());
|
||||
assignTag(dsABCs, distributionSetTagManagement.get(tagA.getId()).orElseThrow());
|
||||
assignTag(dsABCs, distributionSetTagManagement.get(tagB.getId()).orElseThrow());
|
||||
assignTag(dsABCs, distributionSetTagManagement.get(tagC.getId()).orElseThrow());
|
||||
|
||||
// search for not deleted
|
||||
final DistributionSetFilter.DistributionSetFilterBuilder distributionSetFilterBuilder = getDistributionSetFilterBuilder()
|
||||
@@ -121,11 +117,11 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
Stream.empty());
|
||||
|
||||
assertThat(distributionSetTagRepository.findAll()).hasSize(5);
|
||||
distributionSetTagManagement.delete(tagY.getName());
|
||||
distributionSetTagManagement.delete(tagY.getId());
|
||||
assertThat(distributionSetTagRepository.findAll()).hasSize(4);
|
||||
distributionSetTagManagement.delete(tagX.getName());
|
||||
distributionSetTagManagement.delete(tagX.getId());
|
||||
assertThat(distributionSetTagRepository.findAll()).hasSize(3);
|
||||
distributionSetTagManagement.delete(tagB.getName());
|
||||
distributionSetTagManagement.delete(tagB.getId());
|
||||
assertThat(distributionSetTagRepository.findAll()).hasSize(2);
|
||||
|
||||
verifyExpectedFilteredDistributionSets(distributionSetFilterBuilder.tagNames(Arrays.asList(tagA.getName())),
|
||||
@@ -217,11 +213,11 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Tag tag = distributionSetTagManagement
|
||||
.create(DistributionSetTagManagement.Create.builder().name("kai1").description("kai2").colour("colour").build());
|
||||
|
||||
assertThat(distributionSetTagRepository.findByNameEquals("kai1").get().getDescription()).as("wrong tag found")
|
||||
assertThat(distributionSetTagRepository.findById(tag.getId()).orElseThrow().getDescription()).as("wrong tag found")
|
||||
.isEqualTo("kai2");
|
||||
assertThat(distributionSetTagManagement.findByName("kai1").get().getColour()).as("wrong tag found")
|
||||
assertThat(distributionSetTagManagement.get(tag.getId()).orElseThrow().getColour()).as("wrong tag found")
|
||||
.isEqualTo("colour");
|
||||
assertThat(distributionSetTagManagement.get(tag.getId()).get().getColour()).as("wrong tag found")
|
||||
assertThat(distributionSetTagManagement.get(tag.getId()).orElseThrow().getColour()).as("wrong tag found")
|
||||
.isEqualTo("colour");
|
||||
}
|
||||
|
||||
@@ -240,7 +236,7 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
// delete
|
||||
distributionSetTagManagement.delete(tags.iterator().next().getName());
|
||||
distributionSetTagManagement.delete(tags.iterator().next().getId());
|
||||
|
||||
// check
|
||||
assertThat(distributionSetTagRepository.findById(toDelete.getId())).as("Deleted tag should be null")
|
||||
@@ -321,8 +317,7 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private void verifyExpectedFilteredDistributionSets(final DistributionSetFilter.DistributionSetFilterBuilder distributionSetFilterBuilder,
|
||||
final Stream<Collection<DistributionSet>> expectedFilteredDistributionSets) {
|
||||
final Collection<Long> retrievedFilteredDsIds = distributionSetManagement
|
||||
.findByDistributionSetFilter(distributionSetFilterBuilder.build(), PAGE).stream()
|
||||
final Collection<Long> retrievedFilteredDsIds = findDsByDistributionSetFilter(distributionSetFilterBuilder.build(), PAGE).stream()
|
||||
.map(DistributionSet::getId).toList();
|
||||
final Collection<Long> expectedFilteredDsIds = expectedFilteredDistributionSets.flatMap(Collection::stream)
|
||||
.map(DistributionSet::getId).toList();
|
||||
|
||||
@@ -1424,11 +1424,11 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
* Verify the creation and the start of a rollout.
|
||||
*/
|
||||
@Test
|
||||
void createScheduledRollout() throws Exception {
|
||||
void createScheduledRollout() {
|
||||
final String rolloutName = "scheduledRolloutTest";
|
||||
testdataFactory.createTargets(50, rolloutName + "-", rolloutName);
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
|
||||
distributionSetManagement.lock(distributionSet.getId());
|
||||
distributionSetManagement.lock(distributionSet);
|
||||
|
||||
final WithUser userWithoutHandleRollout = SecurityContextSwitch.withUser(
|
||||
"user_without_handle_rollout",
|
||||
|
||||
@@ -194,18 +194,16 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(softwareModuleManagement.findByTextAndType("oracle", runtimeType.getId(), PAGE).getContent())
|
||||
.hasSize(1);
|
||||
assertThat(
|
||||
softwareModuleManagement.findByTextAndType("oracle", runtimeType.getId(), PAGE).getContent().get(0))
|
||||
.isEqualTo(jvm);
|
||||
softwareModuleManagement.findByTextAndType("oracle", runtimeType.getId(), PAGE).getContent().get(0)).isEqualTo(jvm);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(":1.0.1", appType.getId(), PAGE).getContent()).hasSize(1)
|
||||
.first().isEqualTo(ah);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(":1.0", appType.getId(), PAGE).getContent()).hasSize(2);
|
||||
|
||||
distributionSetManagement.unlock(ds.getId()); // otherwise delete will be rejected as a part of a locked DS
|
||||
distributionSetManagement.unlock(ds); // otherwise delete will be rejected as a part of a locked DS
|
||||
softwareModuleManagement.delete(ah2.getId());
|
||||
|
||||
assertThat(softwareModuleManagement.findByTextAndType(":1.0", appType.getId(), PAGE).getContent()).hasSize(1);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(":1.0", appType.getId(), PAGE).getContent().get(0))
|
||||
.isEqualTo(ah);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(":1.0", appType.getId(), PAGE).getContent().get(0)).isEqualTo(ah);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -429,16 +427,16 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
|
||||
|
||||
// [STEP3]: Assign SoftwareModuleX to DistributionSetX and to target
|
||||
final DistributionSet disSetX = testdataFactory.createDistributionSet(Set.of(moduleX), "X");
|
||||
assignDistributionSet(disSetX, Collections.singletonList(target));
|
||||
final DistributionSet disSetX = assignDistributionSet(testdataFactory.createDistributionSet(Set.of(moduleX), "X"), List.of(target))
|
||||
.getDistributionSet();
|
||||
|
||||
// [STEP4]: Assign SoftwareModuleY to DistributionSet and to target
|
||||
final DistributionSet disSetY = testdataFactory.createDistributionSet(Set.of(moduleY), "Y");
|
||||
assignDistributionSet(disSetY, Collections.singletonList(target));
|
||||
final DistributionSet disSetY = assignDistributionSet(testdataFactory.createDistributionSet(Set.of(moduleY), "Y"), List.of(target))
|
||||
.getDistributionSet();
|
||||
|
||||
// [STEP5]: Delete SoftwareModuleX
|
||||
distributionSetManagement.unlock(disSetX.getId()); // otherwise delete will be rejected as a part of a locked DS
|
||||
distributionSetManagement.unlock(disSetY.getId()); // otherwise delete will be rejected as a part of a locked DS
|
||||
distributionSetManagement.unlock(disSetX); // otherwise delete will be rejected as a part of a locked DS
|
||||
distributionSetManagement.unlock(disSetY); // otherwise delete will be rejected as a part of a locked DS
|
||||
softwareModuleManagement.delete(moduleX.getId());
|
||||
|
||||
// [STEP6]: Delete SoftwareModuleY
|
||||
@@ -757,10 +755,8 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
// try to delete while DS is not locked
|
||||
softwareModuleManagement.delete(modules.get(0).getId());
|
||||
|
||||
distributionSetManagement.lock(distributionSet.getId());
|
||||
assertThat(
|
||||
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false))
|
||||
.isTrue();
|
||||
distributionSetManagement.lock(distributionSet);
|
||||
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false)).isTrue();
|
||||
|
||||
// try to delete SM of a locked DS
|
||||
final Long moduleId = modules.get(1).getId();
|
||||
@@ -772,7 +768,7 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
implicitLock(ds);
|
||||
assertThat(targetManagement.getByControllerID(target.getControllerId()).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerID(target.getControllerId()).orElseThrow().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
final Optional<DistributionSet> assignedDistributionSet = deploymentManagement
|
||||
.getAssignedDistributionSet(target.getControllerId());
|
||||
|
||||
@@ -28,9 +28,8 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
/**
|
||||
* Multi-Tenancy tests which testing the CRUD operations of entities that all
|
||||
* CRUD-Operations are tenant aware and cannot access or delete entities not
|
||||
* belonging to the current tenant.
|
||||
* Multi-Tenancy tests which testing the CRUD operations of entities that all CRUD-Operations are tenant aware and cannot access
|
||||
* or delete entities not belonging to the current tenant.
|
||||
* <p/>
|
||||
* Feature: Component Tests - Repository<br/>
|
||||
* Story: Multi Tenancy
|
||||
@@ -201,6 +200,6 @@ class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private Slice<? extends DistributionSet> findDistributionSetForTenant(final String tenant) throws Exception {
|
||||
return runAsTenant(tenant, () -> distributionSetManagement.findByCompleted(true, PAGE));
|
||||
return runAsTenant(tenant, () -> distributionSetManagement.findAll(PAGE));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user