Repository API query signatures Entity free (#403)
* Migrated target management queries to IDs inetsead of full entities Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Added missing comment. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * refactored target,DS,cont,deploy,rg mangement. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Adde versioning documentation. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Rollout, Dist and Software mgmt refactored Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Readded line that was remove by incident. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fixed broken tests. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Query management refactored Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fix bug of auto assign DS delete Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Switch to collection Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fixed compile error Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Small glitches Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fixed test after merge Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -61,11 +61,11 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
*
|
||||
* @param pageable
|
||||
* page parameters
|
||||
* @param ds
|
||||
* @param dsId
|
||||
* the {@link DistributionSet} on which will be filtered
|
||||
* @return the found {@link Action}s
|
||||
*/
|
||||
Page<Action> findByDistributionSet(final Pageable pageable, final JpaDistributionSet ds);
|
||||
Page<Action> findByDistributionSetId(final Pageable pageable, final Long dsId);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s which are referring the given
|
||||
@@ -73,11 +73,11 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
*
|
||||
* @param pageable
|
||||
* page parameters
|
||||
* @param target
|
||||
* @param controllerId
|
||||
* the target to find assigned actions
|
||||
* @return the found {@link Action}s
|
||||
*/
|
||||
Slice<Action> findByTarget(Pageable pageable, JpaTarget target);
|
||||
Slice<Action> findByTargetControllerId(Pageable pageable, String controllerId);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s which are active and referring to the given
|
||||
@@ -97,7 +97,7 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
*
|
||||
* @param sort
|
||||
* order
|
||||
* @param target
|
||||
* @param controllerId
|
||||
* the target to find assigned actions
|
||||
* @param active
|
||||
* the action active flag
|
||||
@@ -105,7 +105,7 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
* @return the found {@link Action}
|
||||
*/
|
||||
@EntityGraph(value = "Action.ds", type = EntityGraphType.LOAD)
|
||||
Optional<Action> findFirstByTargetAndActive(final Sort sort, final JpaTarget target, boolean active);
|
||||
Optional<Action> findFirstByTargetControllerIdAndActive(final Sort sort, final String controllerId, boolean active);
|
||||
|
||||
/**
|
||||
* Retrieves latest {@link Action} for given target and
|
||||
@@ -162,8 +162,8 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
* @return a list of actions ordered by action ID
|
||||
*/
|
||||
@EntityGraph(value = "Action.ds", type = EntityGraphType.LOAD)
|
||||
@Query("Select a from JpaAction a where a.target = :target and a.active= :active order by a.id")
|
||||
List<Action> findByActiveAndTarget(@Param("target") JpaTarget target, @Param("active") boolean active);
|
||||
@Query("Select a from JpaAction a where a.target.controllerId = :target and a.active= :active order by a.id")
|
||||
List<Action> findByActiveAndTarget(@Param("target") String target, @Param("active") boolean active);
|
||||
|
||||
/**
|
||||
* Switches the status of actions from one specific status into another,
|
||||
@@ -203,11 +203,11 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
/**
|
||||
* Counts all {@link Action}s referring to the given target.
|
||||
*
|
||||
* @param target
|
||||
* @param controllerId
|
||||
* the target to count the {@link Action}s
|
||||
* @return the count of actions referring to the given target
|
||||
*/
|
||||
Long countByTarget(JpaTarget target);
|
||||
Long countByTargetControllerId(String controllerId);
|
||||
|
||||
/**
|
||||
* Counts all {@link Action}s referring to the given DistributionSet.
|
||||
@@ -216,7 +216,7 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
* DistributionSet to count the {@link Action}s from
|
||||
* @return the count of actions referring to the given distributionSet
|
||||
*/
|
||||
Long countByDistributionSet(JpaDistributionSet distributionSet);
|
||||
Long countByDistributionSetId(Long distributionSet);
|
||||
|
||||
/**
|
||||
* Counts all actions referring to a given rollout and rolloutgroup which
|
||||
@@ -303,13 +303,13 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
/**
|
||||
* Retrieves all actions for a specific rollout and in a specific status.
|
||||
*
|
||||
* @param rollout
|
||||
* @param rolloutId
|
||||
* the rollout the actions beglong to
|
||||
* @param actionStatus
|
||||
* the status of the actions
|
||||
* @return the actions referring a specific rollout an in a specific status
|
||||
*/
|
||||
List<Action> findByRolloutAndStatus(JpaRollout rollout, Status actionStatus);
|
||||
List<Action> findByRolloutIdAndStatus(Long rolloutId, Status actionStatus);
|
||||
|
||||
/**
|
||||
* Get list of objects which has details of status and count of targets in
|
||||
|
||||
@@ -44,11 +44,11 @@ public interface ActionStatusRepository
|
||||
*
|
||||
* @param pageReq
|
||||
* parameters
|
||||
* @param action
|
||||
* @param actionId
|
||||
* of the status entries
|
||||
* @return pages list of {@link ActionStatus} entries
|
||||
*/
|
||||
Page<ActionStatus> findByAction(Pageable pageReq, JpaAction action);
|
||||
Page<ActionStatus> findByActionId(Pageable pageReq, Long actionId);
|
||||
|
||||
/**
|
||||
* Finds all status updates for the defined action and target including
|
||||
@@ -58,11 +58,11 @@ public interface ActionStatusRepository
|
||||
* for page configuration
|
||||
* @param target
|
||||
* to look for
|
||||
* @param action
|
||||
* @param actionId
|
||||
* to look for
|
||||
* @return Page with found targets
|
||||
*/
|
||||
@EntityGraph(value = "ActionStatus.withMessages", type = EntityGraphType.LOAD)
|
||||
Page<ActionStatus> getByAction(Pageable pageReq, JpaAction action);
|
||||
Page<ActionStatus> getByActionId(Pageable pageReq, Long actionId);
|
||||
|
||||
}
|
||||
|
||||
@@ -11,10 +11,8 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
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.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -89,7 +87,7 @@ public interface DistributionSetRepository
|
||||
* @return list of {@link DistributionSet#getId()}
|
||||
*/
|
||||
@Query("select ac.distributionSet.id from JpaAction ac where ac.distributionSet.id in :ids")
|
||||
List<Long> findAssignedToTargetDistributionSetsById(@Param("ids") Long... ids);
|
||||
List<Long> findAssignedToTargetDistributionSetsById(@Param("ids") Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* Finds {@link DistributionSet}s based on given ID that are assigned yet to
|
||||
@@ -100,7 +98,7 @@ public interface DistributionSetRepository
|
||||
* @return list of {@link DistributionSet#getId()}
|
||||
*/
|
||||
@Query("select ra.distributionSet.id from JpaRollout ra where ra.distributionSet.id in :ids")
|
||||
List<Long> findAssignedToRolloutDistributionSetsById(@Param("ids") Long... ids);
|
||||
List<Long> findAssignedToRolloutDistributionSetsById(@Param("ids") Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* Finds the distribution set for a specific action.
|
||||
@@ -109,17 +107,17 @@ public interface DistributionSetRepository
|
||||
* the action associated with the distribution set to find
|
||||
* @return the distribution set associated with the given action
|
||||
*/
|
||||
@Query("select DISTINCT d from JpaDistributionSet d join fetch d.modules m join d.actions a where a = :action")
|
||||
JpaDistributionSet findByAction(@Param("action") JpaAction action);
|
||||
@Query("select DISTINCT d from JpaDistributionSet d join fetch d.modules m join d.actions a where a.id = :action")
|
||||
JpaDistributionSet findByActionId(@Param("action") Long action);
|
||||
|
||||
/**
|
||||
* Counts {@link DistributionSet} instances of given type in the repository.
|
||||
*
|
||||
* @param type
|
||||
* @param typeId
|
||||
* to search for
|
||||
* @return number of found {@link DistributionSet}s
|
||||
*/
|
||||
long countByType(JpaDistributionSetType type);
|
||||
long countByTypeId(Long typeId);
|
||||
|
||||
/**
|
||||
* Counts {@link DistributionSet} with given
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.artifact.repository.ArtifactRepository;
|
||||
import org.eclipse.hawkbit.artifact.repository.ArtifactStoreException;
|
||||
@@ -104,10 +105,14 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public boolean clearArtifactBinary(final Artifact existing) {
|
||||
public boolean clearArtifactBinary(final Long existing) {
|
||||
return clearArtifactBinary(Optional.ofNullable(localArtifactRepository.findOne(existing))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Artifact with given ID" + existing + " not found.")));
|
||||
}
|
||||
|
||||
for (final Artifact lArtifact : localArtifactRepository
|
||||
.findByGridFsFileName(((JpaArtifact) existing).getGridFsFileName())) {
|
||||
private boolean clearArtifactBinary(final JpaArtifact existing) {
|
||||
|
||||
for (final Artifact lArtifact : localArtifactRepository.findByGridFsFileName(existing.getGridFsFileName())) {
|
||||
if (!lArtifact.getSoftwareModule().isDeleted()
|
||||
&& Long.compare(lArtifact.getSoftwareModule().getId(), existing.getSoftwareModule().getId()) != 0) {
|
||||
return false;
|
||||
@@ -115,8 +120,8 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
}
|
||||
|
||||
try {
|
||||
LOG.debug("deleting artifact from repository {}", ((JpaArtifact) existing).getGridFsFileName());
|
||||
artifactRepository.deleteBySha1(((JpaArtifact) existing).getGridFsFileName());
|
||||
LOG.debug("deleting artifact from repository {}", existing.getGridFsFileName());
|
||||
artifactRepository.deleteBySha1(existing.getGridFsFileName());
|
||||
return true;
|
||||
} catch (final ArtifactStoreException e) {
|
||||
throw new ArtifactDeleteFailedException(e);
|
||||
@@ -166,10 +171,13 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DbArtifact loadArtifactBinary(final Artifact artifact) {
|
||||
final DbArtifact result = artifactRepository.getArtifactBySha1(((JpaArtifact) artifact).getGridFsFileName());
|
||||
public DbArtifact loadArtifactBinary(final Long artifactId) {
|
||||
final JpaArtifact artifact = Optional.ofNullable(localArtifactRepository.findOne(artifactId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Artifact with given id " + artifactId + " not found."));
|
||||
|
||||
final DbArtifact result = artifactRepository.getArtifactBySha1(artifact.getGridFsFileName());
|
||||
if (result == null) {
|
||||
throw new GridFSDBFileNotFoundException(((JpaArtifact) artifact).getGridFsFileName());
|
||||
throw new GridFSDBFileNotFoundException(artifact.getGridFsFileName());
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecuto
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
@@ -45,7 +46,6 @@ import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
@@ -135,12 +135,10 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public Target updateLastTargetQuery(final String controllerId, final URI address) {
|
||||
final Target target = targetRepository.findByControllerId(controllerId);
|
||||
if (target == null) {
|
||||
throw new EntityNotFoundException(controllerId);
|
||||
}
|
||||
final Target target = Optional.ofNullable(targetRepository.findByControllerId(controllerId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Target with given ID " + controllerId + " not found"));
|
||||
|
||||
return updateLastTargetQuery(target.getTargetInfo(), address).getTarget();
|
||||
return updateTargetStatus(target.getTargetInfo(), null, System.currentTimeMillis(), address).getTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,7 +156,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTargetArtifactAssigned(final String controllerId, final Artifact localArtifact) {
|
||||
public boolean hasTargetArtifactAssigned(final String controllerId, final Long localArtifact) {
|
||||
final Target target = targetRepository.findByControllerId(controllerId);
|
||||
if (target == null) {
|
||||
return false;
|
||||
@@ -167,7 +165,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTargetArtifactAssigned(final Long targetId, final Artifact localArtifact) {
|
||||
public boolean hasTargetArtifactAssigned(final Long targetId, final Long localArtifact) {
|
||||
final Target target = targetRepository.findOne(targetId);
|
||||
if (target == null) {
|
||||
return false;
|
||||
@@ -176,10 +174,11 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Action> findOldestActiveActionByTarget(final Target target) {
|
||||
public Optional<Action> findOldestActiveActionByTarget(final String controllerId) {
|
||||
// used in favorite to findFirstByTargetAndActiveOrderByIdAsc due to
|
||||
// DATAJPA-841 issue.
|
||||
return actionRepository.findFirstByTargetAndActive(new Sort(Direction.ASC, "id"), (JpaTarget) target, true);
|
||||
return actionRepository.findFirstByTargetControllerIdAndActive(new Sort(Direction.ASC, "id"), controllerId,
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -208,13 +207,10 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
return result;
|
||||
}
|
||||
|
||||
return updateLastTargetQuery(target.getTargetInfo(), address).getTarget();
|
||||
return updateTargetStatus(target.getTargetInfo(), null, System.currentTimeMillis(), address).getTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public TargetInfo updateTargetStatus(final TargetInfo targetInfo, final TargetUpdateStatus status,
|
||||
private TargetInfo updateTargetStatus(final TargetInfo targetInfo, final TargetUpdateStatus status,
|
||||
final Long lastTargetQuery, final URI address) {
|
||||
final JpaTargetInfo mtargetInfo = (JpaTargetInfo) entityManager.merge(targetInfo);
|
||||
if (status != null) {
|
||||
@@ -431,22 +427,24 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public Action registerRetrieved(final Action action, final String message) {
|
||||
return handleRegisterRetrieved((JpaAction) action, message);
|
||||
public Action registerRetrieved(final Long actionId, final String message) {
|
||||
return handleRegisterRetrieved(actionId, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers retrieved status for given {@link Target} and {@link Action} if
|
||||
* it does not exist yet.
|
||||
*
|
||||
* @param action
|
||||
* @param actionId
|
||||
* to the handle status for
|
||||
* @param message
|
||||
* for the status
|
||||
* @return the updated action in case the status has been changed to
|
||||
* {@link Status#RETRIEVED}
|
||||
*/
|
||||
private Action handleRegisterRetrieved(final JpaAction action, final String message) {
|
||||
private Action handleRegisterRetrieved(final Long actionId, final String message) {
|
||||
final JpaAction action = Optional.ofNullable(actionRepository.findById(actionId)).orElseThrow(
|
||||
() -> new EntityNotFoundException("Actionw ith given ID " + actionId + " doesn not exist."));
|
||||
// do a manual query with CriteriaBuilder to avoid unnecessary field
|
||||
// queries and an extra
|
||||
// count query made by spring-data when using pageable requests, we
|
||||
@@ -458,7 +456,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
final Root<JpaActionStatus> actionStatusRoot = queryActionStatus.from(JpaActionStatus.class);
|
||||
final CriteriaQuery<Object[]> query = queryActionStatus
|
||||
.multiselect(actionStatusRoot.get(JpaActionStatus_.id), actionStatusRoot.get(JpaActionStatus_.status))
|
||||
.where(cb.equal(actionStatusRoot.get(JpaActionStatus_.action), action))
|
||||
.where(cb.equal(actionStatusRoot.get(JpaActionStatus_.action).get(JpaAction_.id), actionId))
|
||||
.orderBy(cb.desc(actionStatusRoot.get(JpaActionStatus_.id)));
|
||||
final List<Object[]> resultList = entityManager.createQuery(query).setFirstResult(0).setMaxResults(1)
|
||||
.getResultList();
|
||||
@@ -480,9 +478,8 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
// we modify the action status and the controller won't get the
|
||||
// cancel job anymore.
|
||||
if (!action.isCancelingOrCanceled()) {
|
||||
final JpaAction actionMerge = entityManager.merge(action);
|
||||
actionMerge.setStatus(Status.RETRIEVED);
|
||||
return actionRepository.save(actionMerge);
|
||||
action.setStatus(Status.RETRIEVED);
|
||||
return actionRepository.save(action);
|
||||
}
|
||||
}
|
||||
return action;
|
||||
@@ -507,13 +504,6 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
.orElseThrow(() -> new EntityNotFoundException("Action with ID " + actionId + " not found!"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public TargetInfo updateLastTargetQuery(final TargetInfo target, final URI address) {
|
||||
return updateTargetStatus(target, null, System.currentTimeMillis(), address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadProgress(final Long statusId, final Long requestedBytes, final Long shippedBytesSinceLast,
|
||||
final Long shippedBytesOverall) {
|
||||
@@ -527,7 +517,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Target findByTargetId(final long targetId) {
|
||||
public Target findByTargetId(final Long targetId) {
|
||||
return targetRepository.findOne(targetId);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -51,6 +52,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
@@ -85,7 +87,6 @@ import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
@@ -180,20 +181,6 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
return assignDistributionSetToTargets(set, targets, null, null, actionMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
public DistributionSetAssignmentResult assignDistributionSet(final Long dsID,
|
||||
final Collection<TargetWithActionType> targets, final Rollout rollout, final RolloutGroup rolloutGroup) {
|
||||
final JpaDistributionSet set = distributoinSetRepository.findOne(dsID);
|
||||
if (set == null) {
|
||||
throw new EntityNotFoundException(
|
||||
String.format("no %s with id %d found", DistributionSet.class.getSimpleName(), dsID));
|
||||
}
|
||||
|
||||
return assignDistributionSetToTargets(set, targets, (JpaRollout) rollout, (JpaRolloutGroup) rolloutGroup, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* method assigns the {@link DistributionSet} to all {@link Target}s by
|
||||
* their IDs with a specific {@link ActionType} and {@code forcetime}.
|
||||
@@ -375,22 +362,25 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
public Action cancelAction(final Action action, final Target target) {
|
||||
LOG.debug("cancelAction({}, {})", action, target);
|
||||
public Action cancelAction(final Long actionId) {
|
||||
LOG.debug("cancelAction({})", actionId);
|
||||
|
||||
final JpaAction action = Optional.ofNullable(actionRepository.findOne(actionId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Action with given ID " + actionId + " not found"));
|
||||
|
||||
if (action.isCancelingOrCanceled()) {
|
||||
throw new CancelActionNotAllowedException("Actions in canceling or canceled state cannot be canceled");
|
||||
}
|
||||
final JpaAction myAction = (JpaAction) entityManager.merge(action);
|
||||
|
||||
if (myAction.isActive()) {
|
||||
if (action.isActive()) {
|
||||
LOG.debug("action ({}) was still active. Change to {}.", action, Status.CANCELING);
|
||||
myAction.setStatus(Status.CANCELING);
|
||||
action.setStatus(Status.CANCELING);
|
||||
|
||||
// document that the status has been retrieved
|
||||
actionStatusRepository.save(new JpaActionStatus(myAction, Status.CANCELING, System.currentTimeMillis(),
|
||||
actionStatusRepository.save(new JpaActionStatus(action, Status.CANCELING, System.currentTimeMillis(),
|
||||
"manual cancelation requested"));
|
||||
final Action saveAction = actionRepository.save(myAction);
|
||||
cancelAssignDistributionSetEvent(target, myAction.getId());
|
||||
final Action saveAction = actionRepository.save(action);
|
||||
cancelAssignDistributionSetEvent(action.getTarget(), action.getId());
|
||||
|
||||
return saveAction;
|
||||
} else {
|
||||
@@ -421,15 +411,16 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
public Action forceQuitAction(final Action action) {
|
||||
final JpaAction mergedAction = (JpaAction) entityManager.merge(action);
|
||||
public Action forceQuitAction(final Long actionId) {
|
||||
final JpaAction action = Optional.ofNullable(actionRepository.findOne(actionId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Action with given ID " + actionId + " not found"));
|
||||
|
||||
if (!mergedAction.isCancelingOrCanceled()) {
|
||||
if (!action.isCancelingOrCanceled()) {
|
||||
throw new ForceQuitActionNotAllowedException(
|
||||
"Action [id: " + action.getId() + "] is not canceled yet and cannot be force quit");
|
||||
}
|
||||
|
||||
if (!mergedAction.isActive()) {
|
||||
if (!action.isActive()) {
|
||||
throw new ForceQuitActionNotAllowedException(
|
||||
"Action [id: " + action.getId() + "] is not active and cannot be force quit");
|
||||
}
|
||||
@@ -437,39 +428,13 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
LOG.warn("action ({}) was still activ and has been force quite.", action);
|
||||
|
||||
// document that the status has been retrieved
|
||||
actionStatusRepository.save(new JpaActionStatus(mergedAction, Status.CANCELED, System.currentTimeMillis(),
|
||||
actionStatusRepository.save(new JpaActionStatus(action, Status.CANCELED, System.currentTimeMillis(),
|
||||
"A force quit has been performed."));
|
||||
|
||||
DeploymentHelper.successCancellation(mergedAction, actionRepository, targetRepository, targetInfoRepository,
|
||||
DeploymentHelper.successCancellation(action, actionRepository, targetRepository, targetInfoRepository,
|
||||
entityManager);
|
||||
|
||||
return actionRepository.save(mergedAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
public void createScheduledAction(final Collection<Target> targets, final DistributionSet distributionSet,
|
||||
final ActionType actionType, final Long forcedTime, final Rollout rollout,
|
||||
final RolloutGroup rolloutGroup) {
|
||||
// cancel all current scheduled actions for this target. E.g. an action
|
||||
// is already scheduled and a next action is created then cancel the
|
||||
// current scheduled action to cancel. E.g. a new scheduled action is
|
||||
// created.
|
||||
final List<Long> targetIds = targets.stream().map(t -> t.getId()).collect(Collectors.toList());
|
||||
actionRepository.switchStatus(Action.Status.CANCELED, targetIds, false, Action.Status.SCHEDULED);
|
||||
targets.forEach(target -> {
|
||||
final JpaAction action = new JpaAction();
|
||||
action.setTarget(target);
|
||||
action.setActive(false);
|
||||
action.setDistributionSet(distributionSet);
|
||||
action.setActionType(actionType);
|
||||
action.setForcedTime(forcedTime);
|
||||
action.setStatus(Status.SCHEDULED);
|
||||
action.setRollout(rollout);
|
||||
action.setRolloutGroup(rolloutGroup);
|
||||
actionRepository.save(action);
|
||||
});
|
||||
return actionRepository.save(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -517,14 +482,6 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED)
|
||||
public Action startScheduledAction(final Long actionId) {
|
||||
final JpaAction action = actionRepository.findById(actionId);
|
||||
return startScheduledAction(action);
|
||||
}
|
||||
|
||||
private Action startScheduledAction(final JpaAction action) {
|
||||
// check if we need to override running update actions
|
||||
final Set<Long> overrideObsoleteUpdateActions = overrideObsoleteUpdateActions(
|
||||
@@ -595,17 +552,12 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Action> findActionsByTarget(final Pageable pageable, final Target target) {
|
||||
return actionRepository.findByTarget(pageable, (JpaTarget) target);
|
||||
public Slice<Action> findActionsByTarget(final String controllerId, final Pageable pageable) {
|
||||
return actionRepository.findByTargetControllerId(pageable, controllerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Action> findActionsByTarget(final Target target) {
|
||||
return Collections.unmodifiableList(actionRepository.findByTarget(target));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ActionWithStatusCount> findActionsWithStatusCountByTargetOrderByIdDesc(final Target target) {
|
||||
public List<ActionWithStatusCount> findActionsWithStatusCountByTargetOrderByIdDesc(final String controllerId) {
|
||||
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
|
||||
final CriteriaQuery<JpaActionWithStatusCount> query = cb.createQuery(JpaActionWithStatusCount.class);
|
||||
final Root<JpaAction> actionRoot = query.from(JpaAction.class);
|
||||
@@ -621,24 +573,25 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
actionDsJoin.get(JpaDistributionSet_.id), actionDsJoin.get(JpaDistributionSet_.name),
|
||||
actionDsJoin.get(JpaDistributionSet_.version), cb.count(actionStatusJoin),
|
||||
actionRolloutJoin.get(JpaRollout_.name));
|
||||
multiselect.where(cb.equal(actionRoot.get(JpaAction_.target), target));
|
||||
multiselect.where(cb.equal(actionRoot.get(JpaAction_.target).get(JpaTarget_.controllerId), controllerId));
|
||||
multiselect.orderBy(cb.desc(actionRoot.get(JpaAction_.id)));
|
||||
multiselect.groupBy(actionRoot.get(JpaAction_.id));
|
||||
return Collections.unmodifiableList(entityManager.createQuery(multiselect).getResultList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Action> findActionsByTarget(final String rsqlParam, final Target target, final Pageable pageable) {
|
||||
public Page<Action> findActionsByTarget(final String rsqlParam, final String controllerId,
|
||||
final Pageable pageable) {
|
||||
|
||||
final Specification<JpaAction> byTargetSpec = createSpecificationFor(target, rsqlParam);
|
||||
final Specification<JpaAction> byTargetSpec = createSpecificationFor(controllerId, rsqlParam);
|
||||
final Page<JpaAction> actions = actionRepository.findAll(byTargetSpec, pageable);
|
||||
return convertAcPage(actions, pageable);
|
||||
}
|
||||
|
||||
private Specification<JpaAction> createSpecificationFor(final Target target, final String rsqlParam) {
|
||||
private Specification<JpaAction> createSpecificationFor(final String controllerId, final String rsqlParam) {
|
||||
final Specification<JpaAction> spec = RSQLUtility.parse(rsqlParam, ActionFields.class, virtualPropertyReplacer);
|
||||
return (root, query, cb) -> cb.and(spec.toPredicate(root, query, cb),
|
||||
cb.equal(root.get(JpaAction_.target), target));
|
||||
cb.equal(root.get(JpaAction_.target).get(JpaTarget_.controllerId), controllerId));
|
||||
}
|
||||
|
||||
private static Page<Action> convertAcPage(final Page<JpaAction> findAll, final Pageable pageable) {
|
||||
@@ -646,28 +599,23 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Action> findActionsByTarget(final Target foundTarget, final Pageable pageable) {
|
||||
return actionRepository.findByTarget(pageable, (JpaTarget) foundTarget);
|
||||
public List<Action> findActiveActionsByTarget(final String controllerId) {
|
||||
return actionRepository.findByActiveAndTarget(controllerId, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Action> findActiveActionsByTarget(final Target target) {
|
||||
return actionRepository.findByActiveAndTarget((JpaTarget) target, true);
|
||||
public List<Action> findInActiveActionsByTarget(final String controllerId) {
|
||||
return actionRepository.findByActiveAndTarget(controllerId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Action> findInActiveActionsByTarget(final Target target) {
|
||||
return actionRepository.findByActiveAndTarget((JpaTarget) target, false);
|
||||
public Long countActionsByTarget(final String controllerId) {
|
||||
return actionRepository.countByTargetControllerId(controllerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countActionsByTarget(final Target target) {
|
||||
return actionRepository.countByTarget((JpaTarget) target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countActionsByTarget(final String rsqlParam, final Target target) {
|
||||
return actionRepository.count(createSpecificationFor(target, rsqlParam));
|
||||
public Long countActionsByTarget(final String rsqlParam, final String controllerId) {
|
||||
return actionRepository.count(createSpecificationFor(controllerId, rsqlParam));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -683,18 +631,13 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ActionStatus> findActionStatusByAction(final Pageable pageReq, final Action action) {
|
||||
return actionStatusRepository.findByAction(pageReq, (JpaAction) action);
|
||||
public Page<ActionStatus> findActionStatusByAction(final Pageable pageReq, final Long actionId) {
|
||||
return actionStatusRepository.findByActionId(pageReq, actionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ActionStatus> findActionStatusByActionWithMessages(final Pageable pageReq, final Action action) {
|
||||
return actionStatusRepository.getByAction(pageReq, (JpaAction) action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Action> findActionsByRolloutAndStatus(final Rollout rollout, final Action.Status actionStatus) {
|
||||
return actionRepository.findByRolloutAndStatus((JpaRollout) rollout, actionStatus);
|
||||
public Page<ActionStatus> findActionStatusByActionWithMessages(final Pageable pageReq, final Long actionId) {
|
||||
return actionStatusRepository.getByActionId(pageReq, actionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -717,8 +660,8 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Action> findActionsByDistributionSet(final Pageable pageable, final DistributionSet ds) {
|
||||
return actionRepository.findByDistributionSet(pageable, (JpaDistributionSet) ds);
|
||||
public Slice<Action> findActionsByDistributionSet(final Pageable pageable, final Long dsId) {
|
||||
return actionRepository.findByDistributionSetId(pageable, dsId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
@@ -36,9 +37,7 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaDistributionSetCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaDistributionSetTypeCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.DsMetadataCompositeKey;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata_;
|
||||
@@ -50,7 +49,6 @@ import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetTypeSpecification;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
|
||||
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.DistributionSetFilter.DistributionSetFilterBuilder;
|
||||
@@ -114,9 +112,6 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
private AfterTransactionCommitExecutor afterCommit;
|
||||
|
||||
@Autowired
|
||||
private TenantAware tenantAware;
|
||||
|
||||
@@ -195,14 +190,14 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
|
||||
if (update.isRequiredMigrationStep() != null
|
||||
&& !update.isRequiredMigrationStep().equals(set.isRequiredMigrationStep())) {
|
||||
checkDistributionSetIsAssignedToTargets(set);
|
||||
checkDistributionSetIsAssignedToTargets(update.getId());
|
||||
set.setRequiredMigrationStep(update.isRequiredMigrationStep());
|
||||
}
|
||||
|
||||
if (update.getType() != null) {
|
||||
final DistributionSetType type = findDistributionSetTypeWithExceptionIfNotFound(update.getType());
|
||||
if (!type.getId().equals(set.getType().getId())) {
|
||||
checkDistributionSetIsAssignedToTargets(set);
|
||||
checkDistributionSetIsAssignedToTargets(update.getId());
|
||||
|
||||
set.setType(type);
|
||||
}
|
||||
@@ -251,7 +246,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteDistributionSet(final Long... distributionSetIDs) {
|
||||
public void deleteDistributionSet(final Collection<Long> distributionSetIDs) {
|
||||
final List<Long> assigned = distributionSetRepository
|
||||
.findAssignedToTargetDistributionSetsById(distributionSetIDs);
|
||||
assigned.addAll(distributionSetRepository.findAssignedToRolloutDistributionSetsById(distributionSetIDs));
|
||||
@@ -264,7 +259,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
}
|
||||
|
||||
// mark the rest as hard delete
|
||||
final List<Long> toHardDelete = Arrays.stream(distributionSetIDs).filter(setId -> !assigned.contains(setId))
|
||||
final List<Long> toHardDelete = distributionSetIDs.stream().filter(setId -> !assigned.contains(setId))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// hard delete the rest if exists
|
||||
@@ -274,10 +269,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
distributionSetRepository.deleteByIdIn(toHardDelete);
|
||||
}
|
||||
|
||||
Arrays.stream(distributionSetIDs)
|
||||
.forEach(dsId -> eventPublisher
|
||||
.publishEvent(new DistributionSetDeletedEvent(tenantAware.getCurrentTenant(), dsId,
|
||||
JpaDistributionSet.class.getName(), applicationContext.getId())));
|
||||
distributionSetIDs.forEach(
|
||||
dsId -> eventPublisher.publishEvent(new DistributionSetDeletedEvent(tenantAware.getCurrentTenant(),
|
||||
dsId, JpaDistributionSet.class.getName(), applicationContext.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -316,7 +310,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
throw new EntityNotFoundException("Not all given software modules where found.");
|
||||
}
|
||||
|
||||
checkDistributionSetIsAssignedToTargets(set);
|
||||
checkDistributionSetIsAssignedToTargets(setId);
|
||||
|
||||
modules.forEach(set::addModule);
|
||||
|
||||
@@ -330,7 +324,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
final JpaDistributionSet set = findDistributionSetAndThrowExceptionIfNotFound(setId);
|
||||
final JpaSoftwareModule module = findSoftwareModuleAndThrowExceptionIfNotFound(moduleId);
|
||||
|
||||
checkDistributionSetIsAssignedToTargets(set);
|
||||
checkDistributionSetIsAssignedToTargets(setId);
|
||||
|
||||
set.removeModule(module);
|
||||
|
||||
@@ -349,7 +343,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
update.getColour().ifPresent(type::setColour);
|
||||
|
||||
if (hasModules(update)) {
|
||||
checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(type);
|
||||
checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(update.getId());
|
||||
|
||||
update.getMandatory().ifPresent(
|
||||
mand -> softwareModuleTypeRepository.findByIdIn(mand).forEach(type::addMandatoryModuleType));
|
||||
@@ -378,7 +372,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
throw new EntityNotFoundException("Not all given software module types where found.");
|
||||
}
|
||||
|
||||
checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(type);
|
||||
checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(dsTypeId);
|
||||
|
||||
modules.forEach(type::addMandatoryModuleType);
|
||||
|
||||
@@ -399,18 +393,17 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
throw new EntityNotFoundException("Not all given software module types where found.");
|
||||
}
|
||||
|
||||
checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(type);
|
||||
checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(dsTypeId);
|
||||
|
||||
modules.forEach(type::addOptionalModuleType);
|
||||
|
||||
return distributionSetTypeRepository.save(type);
|
||||
}
|
||||
|
||||
private void checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(final JpaDistributionSetType type) {
|
||||
if (distributionSetRepository.countByType(type) > 0) {
|
||||
private void checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(final Long type) {
|
||||
if (distributionSetRepository.countByTypeId(type) > 0) {
|
||||
throw new EntityReadOnlyException(String.format(
|
||||
"distribution set type %s is already assigned to distribution sets and cannot be changed",
|
||||
type.getName()));
|
||||
"distribution set type %s is already assigned to distribution sets and cannot be changed", type));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -421,7 +414,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
public DistributionSetType unassignSoftwareModuleType(final Long dsTypeId, final Long softwareModuleTypeId) {
|
||||
final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(dsTypeId);
|
||||
|
||||
checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(type);
|
||||
checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(dsTypeId);
|
||||
|
||||
type.removeModuleType(softwareModuleTypeId);
|
||||
|
||||
@@ -604,15 +597,17 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteDistributionSetType(final DistributionSetType ty) {
|
||||
final JpaDistributionSetType type = (JpaDistributionSetType) ty;
|
||||
public void deleteDistributionSetType(final Long typeId) {
|
||||
|
||||
if (distributionSetRepository.countByType(type) > 0) {
|
||||
final JpaDistributionSetType toDelete = entityManager.merge(type);
|
||||
final JpaDistributionSetType toDelete = Optional.ofNullable(distributionSetTypeRepository.findOne(typeId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"DistributionSet Type with given ID " + typeId + " does not exist"));
|
||||
|
||||
if (distributionSetRepository.countByTypeId(typeId) > 0) {
|
||||
toDelete.setDeleted(true);
|
||||
distributionSetTypeRepository.save(toDelete);
|
||||
} else {
|
||||
distributionSetTypeRepository.delete(type.getId());
|
||||
distributionSetTypeRepository.delete(typeId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -725,13 +720,13 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSet findDistributionSetByAction(final Action action) {
|
||||
return distributionSetRepository.findByAction((JpaAction) action);
|
||||
public DistributionSet findDistributionSetByAction(final Long actionId) {
|
||||
return distributionSetRepository.findByActionId(actionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDistributionSetInUse(final DistributionSet distributionSet) {
|
||||
return actionRepository.countByDistributionSet((JpaDistributionSet) distributionSet) > 0;
|
||||
public boolean isDistributionSetInUse(final Long setId) {
|
||||
return actionRepository.countByDistributionSetId(setId) > 0;
|
||||
}
|
||||
|
||||
private static List<Specification<JpaDistributionSet>> buildDistributionSetSpecifications(
|
||||
@@ -776,11 +771,10 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
return specList;
|
||||
}
|
||||
|
||||
private void checkDistributionSetIsAssignedToTargets(final JpaDistributionSet distributionSet) {
|
||||
if (actionRepository.countByDistributionSet(distributionSet) > 0) {
|
||||
throw new EntityReadOnlyException(
|
||||
String.format("distribution set %s:%s is already assigned to targets and cannot be changed",
|
||||
distributionSet.getName(), distributionSet.getVersion()));
|
||||
private void checkDistributionSetIsAssignedToTargets(final Long distributionSet) {
|
||||
if (actionRepository.countByDistributionSetId(distributionSet) > 0) {
|
||||
throw new EntityReadOnlyException(String.format(
|
||||
"distribution set %s is already assigned to targets and cannot be changed", distributionSet));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -822,10 +816,15 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public List<DistributionSet> assignTag(final Collection<Long> dsIds, final DistributionSetTag tag) {
|
||||
public List<DistributionSet> assignTag(final Collection<Long> dsIds, final Long dsTagId) {
|
||||
final List<JpaDistributionSet> allDs = findDistributionSetListWithDetails(dsIds);
|
||||
|
||||
allDs.forEach(ds -> ds.addTag(tag));
|
||||
final DistributionSetTag distributionSetTag = Optional
|
||||
.ofNullable(tagManagement.findDistributionSetTagById(dsTagId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"DistributionSet Tag with given ID " + dsTagId + " not found."));
|
||||
|
||||
allDs.forEach(ds -> ds.addTag(distributionSetTag));
|
||||
|
||||
return Collections
|
||||
.unmodifiableList(allDs.stream().map(distributionSetRepository::save).collect(Collectors.toList()));
|
||||
@@ -834,19 +833,34 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public List<DistributionSet> unAssignAllDistributionSetsByTag(final DistributionSetTag tag) {
|
||||
public List<DistributionSet> unAssignAllDistributionSetsByTag(final Long dsTagId) {
|
||||
|
||||
final DistributionSetTag distributionSetTag = Optional
|
||||
.ofNullable(tagManagement.findDistributionSetTagById(dsTagId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"DistributionSet Tag with given ID " + dsTagId + " not found."));
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
final Collection<JpaDistributionSet> distributionSets = (Collection) tag.getAssignedToDistributionSet();
|
||||
final Collection<JpaDistributionSet> distributionSets = (Collection) distributionSetTag
|
||||
.getAssignedToDistributionSet();
|
||||
|
||||
return Collections.unmodifiableList(unAssignTag(distributionSets, tag));
|
||||
return Collections.unmodifiableList(unAssignTag(distributionSets, distributionSetTag));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public DistributionSet unAssignTag(final Long dsId, final DistributionSetTag distributionSetTag) {
|
||||
public DistributionSet unAssignTag(final Long dsId, final Long dsTagId) {
|
||||
final List<JpaDistributionSet> allDs = findDistributionSetListWithDetails(Arrays.asList(dsId));
|
||||
|
||||
if (allDs.isEmpty()) {
|
||||
throw new EntityNotFoundException("DistributionSet with given ID " + dsId + " not found.");
|
||||
}
|
||||
|
||||
final DistributionSetTag distributionSetTag = Optional
|
||||
.ofNullable(tagManagement.findDistributionSetTagById(dsTagId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"DistributionSet Tag with given ID " + dsTagId + " not found."));
|
||||
final List<JpaDistributionSet> unAssignTag = unAssignTag(allDs, distributionSetTag);
|
||||
return unAssignTag.isEmpty() ? null : unAssignTag.get(0);
|
||||
}
|
||||
@@ -869,22 +883,17 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteDistributionSet(final DistributionSet set) {
|
||||
deleteDistributionSet(set.getId());
|
||||
public void deleteDistributionSet(final Long setId) {
|
||||
if (!distributionSetRepository.exists(setId)) {
|
||||
throw new EntityNotFoundException("DistributionSet with given ID " + setId + " does not exist.");
|
||||
}
|
||||
|
||||
deleteDistributionSet(Lists.newArrayList(setId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public DistributionSetTagAssignmentResult toggleTagAssignment(final Collection<DistributionSet> sets,
|
||||
final DistributionSetTag tag) {
|
||||
return toggleTagAssignment(sets.stream().map(DistributionSet::getId).collect(Collectors.toList()),
|
||||
tag.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countDistributionSetsByType(final DistributionSetType type) {
|
||||
return distributionSetRepository.countByType((JpaDistributionSetType) type);
|
||||
public Long countDistributionSetsByType(final Long typeId) {
|
||||
return distributionSetRepository.countByTypeId(typeId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
@@ -25,6 +26,7 @@ import javax.validation.constraints.NotNull;
|
||||
import org.eclipse.hawkbit.repository.RolloutGroupFields;
|
||||
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
|
||||
@@ -149,7 +151,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Target> findRolloutGroupTargets(final RolloutGroup rolloutGroup, final String rsqlParam,
|
||||
public Page<Target> findRolloutGroupTargets(final Long rolloutGroupId, final String rsqlParam,
|
||||
final Pageable pageable) {
|
||||
|
||||
final Specification<JpaTarget> rsqlSpecification = RSQLUtility.parse(rsqlParam, TargetFields.class,
|
||||
@@ -158,19 +160,25 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
return convertTPage(targetRepository.findAll((root, query, criteriaBuilder) -> {
|
||||
final ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = root.join(JpaTarget_.rolloutTargetGroup);
|
||||
return criteriaBuilder.and(rsqlSpecification.toPredicate(root, query, criteriaBuilder),
|
||||
criteriaBuilder.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup));
|
||||
criteriaBuilder.equal(
|
||||
rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id),
|
||||
rolloutGroupId));
|
||||
}, pageable), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Target> findRolloutGroupTargets(final RolloutGroup rolloutGroup, final Pageable page) {
|
||||
public Page<Target> findRolloutGroupTargets(final Long rolloutGroupId, final Pageable page) {
|
||||
final JpaRolloutGroup rolloutGroup = Optional.ofNullable(rolloutGroupRepository.findOne(rolloutGroupId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"Rollout Group with given ID " + rolloutGroupId + " not found."));
|
||||
|
||||
if (isRolloutStatusReady(rolloutGroup)) {
|
||||
// in case of status ready the action has not been created yet and
|
||||
// the relation information between target and rollout-group is
|
||||
// stored in the #TargetRolloutGroup.
|
||||
return targetRepository.findByRolloutTargetGroupRolloutGroupId(rolloutGroup.getId(), page);
|
||||
return targetRepository.findByRolloutTargetGroupRolloutGroupId(rolloutGroupId, page);
|
||||
}
|
||||
return targetRepository.findByActionsRolloutGroup((JpaRolloutGroup) rolloutGroup, page);
|
||||
return targetRepository.findByActionsRolloutGroupId(rolloutGroupId, page);
|
||||
}
|
||||
|
||||
private static boolean isRolloutStatusReady(final RolloutGroup rolloutGroup) {
|
||||
@@ -179,7 +187,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
|
||||
@Override
|
||||
public Page<TargetWithActionStatus> findAllTargetsWithActionStatus(final PageRequest pageRequest,
|
||||
final RolloutGroup rolloutGroup) {
|
||||
final Long rolloutGroupId) {
|
||||
|
||||
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
|
||||
final CriteriaQuery<Object[]> query = cb.createQuery(Object[].class);
|
||||
@@ -193,12 +201,13 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
final Root<RolloutTargetGroup> countQueryFrom = countQuery.distinct(true).from(RolloutTargetGroup.class);
|
||||
countQueryFrom.join(RolloutTargetGroup_.target);
|
||||
countQueryFrom.join(RolloutTargetGroup_.actions, JoinType.LEFT);
|
||||
countQuery.select(cb.count(countQueryFrom))
|
||||
.where(cb.equal(countQueryFrom.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup));
|
||||
countQuery.select(cb.count(countQueryFrom)).where(cb
|
||||
.equal(countQueryFrom.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id), rolloutGroupId));
|
||||
final Long totalCount = entityManager.createQuery(countQuery).getSingleResult();
|
||||
|
||||
final CriteriaQuery<Object[]> multiselect = query.multiselect(targetJoin, actionJoin.get(JpaAction_.status))
|
||||
.where(cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup));
|
||||
.where(cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id),
|
||||
rolloutGroupId));
|
||||
final List<TargetWithActionStatus> targetWithActionStatus = entityManager.createQuery(multiselect)
|
||||
.setFirstResult(pageRequest.getOffset()).setMaxResults(pageRequest.getPageSize()).getResultList()
|
||||
.stream().map(o -> new TargetWithActionStatus((Target) o[0], (Action.Status) o[1]))
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -32,6 +33,7 @@ import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException;
|
||||
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_;
|
||||
@@ -41,6 +43,7 @@ import org.eclipse.hawkbit.repository.jpa.rollout.condition.RolloutGroupConditio
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus;
|
||||
@@ -336,8 +339,8 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
groupTargetFilter = baseFilter + ";" + group.getTargetFilterQuery();
|
||||
}
|
||||
|
||||
final List<RolloutGroup> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout,
|
||||
RolloutGroupStatus.READY, group);
|
||||
final List<Long> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout, RolloutGroupStatus.READY,
|
||||
group);
|
||||
|
||||
final long targetsInGroupFilter = targetManagement
|
||||
.countAllTargetsByTargetFilterQueryAndNotInRolloutGroups(readyGroups, groupTargetFilter);
|
||||
@@ -383,7 +386,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
|
||||
return runInNewCountingTransaction("assignTargetsToRolloutGroup", status -> {
|
||||
final PageRequest pageRequest = new PageRequest(0, Math.toIntExact(limit));
|
||||
final List<RolloutGroup> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout,
|
||||
final List<Long> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout,
|
||||
RolloutGroupStatus.READY, group);
|
||||
final Page<Target> targets = targetManagement
|
||||
.findAllTargetsByTargetFilterQueryAndNotInRolloutGroups(pageRequest, readyGroups, targetFilter);
|
||||
@@ -558,16 +561,57 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
final ActionType actionType = rollout.getActionType();
|
||||
final long forceTime = rollout.getForcedTime();
|
||||
|
||||
final Page<Target> targets = targetManagement.findAllTargetsInRolloutGroupWithoutAction(pageRequest, group);
|
||||
final Page<Target> targets = targetManagement.findAllTargetsInRolloutGroupWithoutAction(pageRequest,
|
||||
groupId);
|
||||
if (targets.getTotalElements() > 0) {
|
||||
deploymentManagement.createScheduledAction(targets.getContent(), distributionSet, actionType, forceTime,
|
||||
rollout, group);
|
||||
createScheduledAction(targets.getContent(), distributionSet, actionType, forceTime, rollout, group);
|
||||
}
|
||||
|
||||
return targets.getNumberOfElements();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an action entry into the action repository. In case of existing
|
||||
* scheduled actions the scheduled actions gets canceled. A scheduled action
|
||||
* is created in-active.
|
||||
*
|
||||
* @param targets
|
||||
* the targets to create scheduled actions for
|
||||
* @param distributionSet
|
||||
* the distribution set for the actions
|
||||
* @param actionType
|
||||
* the action type for the action
|
||||
* @param forcedTime
|
||||
* the forcedTime of the action
|
||||
* @param rollout
|
||||
* the roll out for this action
|
||||
* @param rolloutGroup
|
||||
* the roll out group for this action
|
||||
*/
|
||||
private void createScheduledAction(final Collection<Target> targets, final DistributionSet distributionSet,
|
||||
final ActionType actionType, final Long forcedTime, final Rollout rollout,
|
||||
final RolloutGroup rolloutGroup) {
|
||||
// cancel all current scheduled actions for this target. E.g. an action
|
||||
// is already scheduled and a next action is created then cancel the
|
||||
// current scheduled action to cancel. E.g. a new scheduled action is
|
||||
// created.
|
||||
final List<Long> targetIds = targets.stream().map(t -> t.getId()).collect(Collectors.toList());
|
||||
actionRepository.switchStatus(Action.Status.CANCELED, targetIds, false, Action.Status.SCHEDULED);
|
||||
targets.forEach(target -> {
|
||||
final JpaAction action = new JpaAction();
|
||||
action.setTarget(target);
|
||||
action.setActive(false);
|
||||
action.setDistributionSet(distributionSet);
|
||||
action.setActionType(actionType);
|
||||
action.setForcedTime(forcedTime);
|
||||
action.setStatus(Status.SCHEDULED);
|
||||
action.setRollout(rollout);
|
||||
action.setRolloutGroup(rolloutGroup);
|
||||
actionRepository.save(action);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@Modifying
|
||||
@@ -903,7 +947,11 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFinishedPercentForRunningGroup(final Long rolloutId, final RolloutGroup rolloutGroup) {
|
||||
public float getFinishedPercentForRunningGroup(final Long rolloutId, final Long rolloutGroupId) {
|
||||
final RolloutGroup rolloutGroup = Optional.ofNullable(rolloutGroupRepository.findOne(rolloutGroupId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"Rollout group with given ID " + rolloutGroupId + " not found."));
|
||||
|
||||
final long totalGroup = rolloutGroup.getTotalTargets();
|
||||
final Long finished = actionRepository.countByRolloutIdAndRolloutGroupIdAndStatus(rolloutId,
|
||||
rolloutGroup.getId(), Action.Status.FINISHED);
|
||||
|
||||
@@ -55,7 +55,6 @@ import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecifica
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.AssignedSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
@@ -204,9 +203,9 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
|
||||
@Override
|
||||
public SoftwareModule findSoftwareModuleByNameAndVersion(final String name, final String version,
|
||||
final SoftwareModuleType type) {
|
||||
final Long typeId) {
|
||||
|
||||
return softwareModuleRepository.findOneByNameAndVersionAndType(name, version, (JpaSoftwareModuleType) type);
|
||||
return softwareModuleRepository.findOneByNameAndVersionAndTypeId(name, version, typeId);
|
||||
}
|
||||
|
||||
private boolean isUnassigned(final JpaSoftwareModule bsmMerged) {
|
||||
@@ -225,7 +224,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
|
||||
private void deleteGridFsArtifacts(final JpaSoftwareModule swModule) {
|
||||
for (final Artifact localArtifact : swModule.getArtifacts()) {
|
||||
artifactManagement.clearArtifactBinary(localArtifact);
|
||||
artifactManagement.clearArtifactBinary(localArtifact.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,22 +491,23 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteSoftwareModuleType(final SoftwareModuleType ty) {
|
||||
final JpaSoftwareModuleType type = (JpaSoftwareModuleType) ty;
|
||||
public void deleteSoftwareModuleType(final Long typeId) {
|
||||
final JpaSoftwareModuleType toDelete = Optional.ofNullable(softwareModuleTypeRepository.findOne(typeId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"Software Module Type with giben ID " + typeId + " does not exist."));
|
||||
|
||||
if (softwareModuleRepository.countByType(type) > 0
|
||||
|| distributionSetTypeRepository.countByElementsSmType(type) > 0) {
|
||||
final JpaSoftwareModuleType toDelete = entityManager.merge(type);
|
||||
if (softwareModuleRepository.countByType(toDelete) > 0
|
||||
|| distributionSetTypeRepository.countByElementsSmType(toDelete) > 0) {
|
||||
toDelete.setDeleted(true);
|
||||
softwareModuleTypeRepository.save(toDelete);
|
||||
} else {
|
||||
softwareModuleTypeRepository.delete(type.getId());
|
||||
softwareModuleTypeRepository.delete(toDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SoftwareModule> findSoftwareModuleByAssignedTo(final Pageable pageable, final DistributionSet set) {
|
||||
return softwareModuleRepository.findByAssignedTo(pageable, (JpaDistributionSet) set);
|
||||
public Page<SoftwareModule> findSoftwareModuleByAssignedTo(final Pageable pageable, final Long setId) {
|
||||
return softwareModuleRepository.findByAssignedToId(pageable, setId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -97,7 +97,7 @@ public class JpaTagManagement implements TagManagement {
|
||||
public void deleteTargetTag(final String targetTagName) {
|
||||
final JpaTargetTag tag = targetTagRepository.findByNameEquals(targetTagName);
|
||||
|
||||
targetRepository.findByTag(tag).forEach(set -> {
|
||||
targetRepository.findByTag(tag.getId()).forEach(set -> {
|
||||
set.removeTag(tag);
|
||||
targetRepository.save(set);
|
||||
});
|
||||
|
||||
@@ -13,8 +13,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryFields;
|
||||
@@ -45,6 +43,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* JPA implementation of {@link TargetFilterQueryManagement}.
|
||||
@@ -54,18 +53,24 @@ import com.google.common.base.Strings;
|
||||
@Validated
|
||||
public class JpaTargetFilterQueryManagement implements TargetFilterQueryManagement {
|
||||
|
||||
@Autowired
|
||||
private TargetFilterQueryRepository targetFilterQueryRepository;
|
||||
private final TargetFilterQueryRepository targetFilterQueryRepository;
|
||||
|
||||
private final VirtualPropertyReplacer virtualPropertyReplacer;
|
||||
|
||||
private final DistributionSetManagement distributionSetManagement;
|
||||
|
||||
@Autowired
|
||||
private VirtualPropertyReplacer virtualPropertyReplacer;
|
||||
JpaTargetFilterQueryManagement(final TargetFilterQueryRepository targetFilterQueryRepository,
|
||||
final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||
final DistributionSetManagement distributionSetManagement) {
|
||||
this.targetFilterQueryRepository = targetFilterQueryRepository;
|
||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||
this.distributionSetManagement = distributionSetManagement;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private DistributionSetManagement distributionSetManagement;
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@Override
|
||||
public TargetFilterQuery createTargetFilterQuery(final TargetFilterQueryCreate c) {
|
||||
final JpaTargetFilterQueryCreate create = (JpaTargetFilterQueryCreate) c;
|
||||
|
||||
@@ -109,8 +114,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TargetFilterQuery> findTargetFilterQueryByFilter(@NotNull final Pageable pageable,
|
||||
final String rsqlFilter) {
|
||||
public Page<TargetFilterQuery> findTargetFilterQueryByFilter(final Pageable pageable, final String rsqlFilter) {
|
||||
List<Specification<JpaTargetFilterQuery>> specList = Collections.emptyList();
|
||||
if (!Strings.isNullOrEmpty(rsqlFilter)) {
|
||||
specList = Collections.singletonList(
|
||||
@@ -120,18 +124,14 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TargetFilterQuery> findTargetFilterQueryByAutoAssignDS(@NotNull final Pageable pageable,
|
||||
final DistributionSet distributionSet) {
|
||||
return findTargetFilterQueryByAutoAssignDS(pageable, distributionSet, null);
|
||||
}
|
||||
public Page<TargetFilterQuery> findTargetFilterQueryByAutoAssignDS(final Pageable pageable, final Long setId,
|
||||
final String rsqlFilter) {
|
||||
final List<Specification<JpaTargetFilterQuery>> specList = Lists.newArrayListWithExpectedSize(2);
|
||||
|
||||
final DistributionSet distributionSet = findDistributionSetAndThrowExceptionIfNotFound(setId);
|
||||
|
||||
specList.add(TargetFilterQuerySpecification.byAutoAssignDS(distributionSet));
|
||||
|
||||
@Override
|
||||
public Page<TargetFilterQuery> findTargetFilterQueryByAutoAssignDS(@NotNull final Pageable pageable,
|
||||
final DistributionSet distributionSet, final String rsqlFilter) {
|
||||
final List<Specification<JpaTargetFilterQuery>> specList = new ArrayList<>(2);
|
||||
if (distributionSet != null) {
|
||||
specList.add(TargetFilterQuerySpecification.byAutoAssignDS(distributionSet));
|
||||
}
|
||||
if (!Strings.isNullOrEmpty(rsqlFilter)) {
|
||||
specList.add(RSQLUtility.parse(rsqlFilter, TargetFilterQueryFields.class, virtualPropertyReplacer));
|
||||
}
|
||||
@@ -139,7 +139,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TargetFilterQuery> findTargetFilterQueryWithAutoAssignDS(@NotNull final Pageable pageable) {
|
||||
public Page<TargetFilterQuery> findTargetFilterQueryWithAutoAssignDS(final Pageable pageable) {
|
||||
final List<Specification<JpaTargetFilterQuery>> specList = Collections
|
||||
.singletonList(TargetFilterQuerySpecification.withAutoAssignDS());
|
||||
return convertPage(findTargetFilterQueryByCriteriaAPI(pageable, specList), pageable);
|
||||
|
||||
@@ -49,7 +49,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.TargetIdName;
|
||||
@@ -90,6 +89,9 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Autowired
|
||||
private TargetRepository targetRepository;
|
||||
|
||||
@Autowired
|
||||
private TargetFilterQueryRepository targetFilterQueryRepository;
|
||||
|
||||
@Autowired
|
||||
private TargetTagRepository targetTagRepository;
|
||||
|
||||
@@ -160,7 +162,12 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Target> findTargetsAll(final TargetFilterQuery targetFilterQuery, final Pageable pageable) {
|
||||
public Slice<Target> findTargetsByTargetFilterQuery(final Long targetFilterQueryId, final Pageable pageable) {
|
||||
final TargetFilterQuery targetFilterQuery = Optional
|
||||
.ofNullable(targetFilterQueryRepository.findOne(targetFilterQueryId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"TargetFilterQuery with given ID" + targetFilterQueryId + " not found"));
|
||||
|
||||
return findTargetsBySpec(
|
||||
RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class, virtualPropertyReplacer), pageable);
|
||||
}
|
||||
@@ -203,13 +210,6 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return targetRepository.save(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteTargets(final Long... targetIDs) {
|
||||
deleteTargets(Lists.newArrayList(targetIDs));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@@ -220,6 +220,18 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
targetId, JpaTarget.class.getName(), applicationContext.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteTarget(final String controllerID) {
|
||||
final Long targetId = Optional.ofNullable(targetRepository.findByControllerId(controllerID))
|
||||
.orElseThrow(
|
||||
() -> new EntityNotFoundException("Target with given ID " + controllerID + " does not exist."))
|
||||
.getId();
|
||||
|
||||
targetRepository.delete(targetId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Target> findTargetByAssignedDistributionSet(final Long distributionSetID, final Pageable pageReq) {
|
||||
return targetRepository.findByAssignedDistributionSetId(pageReq, distributionSetID);
|
||||
@@ -340,14 +352,6 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return targetRepository.count(SpecificationsBuilder.combineWithAnd(specList));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public TargetTagAssignmentResult toggleTagAssignment(final Collection<Target> targets, final TargetTag tag) {
|
||||
return toggleTagAssignment(
|
||||
targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), tag.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@@ -384,10 +388,13 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public List<Target> assignTag(final Collection<String> controllerIds, final TargetTag tag) {
|
||||
public List<Target> assignTag(final Collection<String> controllerIds, final Long tagId) {
|
||||
final List<JpaTarget> allTargets = targetRepository
|
||||
.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(controllerIds));
|
||||
|
||||
final JpaTargetTag tag = Optional.ofNullable(targetTagRepository.findOne(tagId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Tag with given ID " + tagId + "does not exist"));
|
||||
|
||||
allTargets.forEach(target -> target.addTag(tag));
|
||||
return Collections
|
||||
.unmodifiableList(allTargets.stream().map(targetRepository::save).collect(Collectors.toList()));
|
||||
@@ -406,17 +413,29 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public List<Target> unAssignAllTargetsByTag(final TargetTag tag) {
|
||||
public List<Target> unAssignAllTargetsByTag(final Long targetTagId) {
|
||||
|
||||
final TargetTag tag = Optional.ofNullable(targetTagRepository.findOne(targetTagId)).orElseThrow(
|
||||
() -> new EntityNotFoundException("TargetTag with given ID " + targetTagId + " does not exist."));
|
||||
|
||||
if (tag.getAssignedToTargets().isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return unAssignTag(tag.getAssignedToTargets(), tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public Target unAssignTag(final String controllerID, final TargetTag targetTag) {
|
||||
public Target unAssignTag(final String controllerID, final Long targetTagId) {
|
||||
final List<Target> allTargets = Collections.unmodifiableList(targetRepository
|
||||
.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(Arrays.asList(controllerID))));
|
||||
final List<Target> unAssignTag = unAssignTag(allTargets, targetTag);
|
||||
|
||||
final TargetTag tag = Optional.ofNullable(targetTagRepository.findOne(targetTagId)).orElseThrow(
|
||||
() -> new EntityNotFoundException("TargetTag with given ID " + targetTagId + " does not exist."));
|
||||
|
||||
final List<Target> unAssignTag = unAssignTag(allTargets, tag);
|
||||
return unAssignTag.isEmpty() ? null : unAssignTag.get(0);
|
||||
}
|
||||
|
||||
@@ -489,16 +508,6 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return targetRepository.countByTargetInfoInstalledDistributionSetId(distId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TargetIdName> findAllTargetIds() {
|
||||
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
|
||||
final CriteriaQuery<TargetIdName> query = cb.createQuery(TargetIdName.class);
|
||||
final Root<JpaTarget> targetRoot = query.from(JpaTarget.class);
|
||||
return entityManager.createQuery(query.multiselect(targetRoot.get(JpaTarget_.id),
|
||||
targetRoot.get(JpaTarget_.controllerId), targetRoot.get(JpaTarget_.name))).getResultList();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TargetIdName> findAllTargetIdsByFilters(final Pageable pageRequest,
|
||||
final Collection<TargetUpdateStatus> filterByStatus, final Boolean overdueState,
|
||||
@@ -535,7 +544,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public List<TargetIdName> findAllTargetIdsByTargetFilterQuery(final Pageable pageRequest,
|
||||
final TargetFilterQuery targetFilterQuery) {
|
||||
final String targetFilterQuery) {
|
||||
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
|
||||
final CriteriaQuery<Object[]> query = cb.createQuery(Object[].class);
|
||||
final Root<JpaTarget> targetRoot = query.from(JpaTarget.class);
|
||||
@@ -548,7 +557,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final CriteriaQuery<Object[]> multiselect = query.multiselect(targetRoot.get(JpaTarget_.id),
|
||||
targetRoot.get(JpaTarget_.controllerId), targetRoot.get(JpaTarget_.name), targetRoot.get(sortProperty));
|
||||
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class,
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
|
||||
virtualPropertyReplacer);
|
||||
final Predicate[] specificationsForMultiSelect = specificationsToPredicate(Lists.newArrayList(spec), targetRoot,
|
||||
multiselect, cb);
|
||||
@@ -565,9 +574,9 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public Page<Target> findAllTargetsByTargetFilterQueryAndNonDS(@NotNull final Pageable pageRequest,
|
||||
final Long distributionSetId, @NotNull final TargetFilterQuery targetFilterQuery) {
|
||||
final Long distributionSetId, @NotNull final String targetFilterQuery) {
|
||||
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class,
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
|
||||
virtualPropertyReplacer);
|
||||
|
||||
return findTargetsBySpec(
|
||||
@@ -579,8 +588,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Target> findAllTargetsByTargetFilterQueryAndNotInRolloutGroups(@NotNull final Pageable pageRequest,
|
||||
final List<RolloutGroup> groups, @NotNull final String targetFilterQuery) {
|
||||
public Page<Target> findAllTargetsByTargetFilterQueryAndNotInRolloutGroups(final Pageable pageRequest,
|
||||
final Collection<Long> groups, final String targetFilterQuery) {
|
||||
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
|
||||
virtualPropertyReplacer);
|
||||
@@ -592,28 +601,26 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public Page<Target> findAllTargetsInRolloutGroupWithoutAction(@NotNull final Pageable pageRequest,
|
||||
@NotNull final RolloutGroup group) {
|
||||
@NotNull final Long group) {
|
||||
return findTargetsBySpec(
|
||||
(root, cq, cb) -> TargetSpecifications.hasNoActionInRolloutGroup(group).toPredicate(root, cq, cb),
|
||||
pageRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countAllTargetsByTargetFilterQueryAndNotInRolloutGroups(final List<RolloutGroup> groups,
|
||||
@NotNull final String targetFilterQuery) {
|
||||
public Long countAllTargetsByTargetFilterQueryAndNotInRolloutGroups(final Collection<Long> groups,
|
||||
final String targetFilterQuery) {
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
|
||||
virtualPropertyReplacer);
|
||||
final List<Specification<JpaTarget>> specList = new ArrayList<>(2);
|
||||
specList.add(spec);
|
||||
specList.add(TargetSpecifications.isNotInRolloutGroups(groups));
|
||||
final List<Specification<JpaTarget>> specList = Lists.newArrayList(spec,
|
||||
TargetSpecifications.isNotInRolloutGroups(groups));
|
||||
|
||||
return countByCriteriaAPI(specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countTargetsByTargetFilterQueryAndNonDS(final Long distributionSetId,
|
||||
@NotNull final TargetFilterQuery targetFilterQuery) {
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class,
|
||||
public Long countTargetsByTargetFilterQueryAndNonDS(final Long distributionSetId, final String targetFilterQuery) {
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
|
||||
virtualPropertyReplacer);
|
||||
final List<Specification<JpaTarget>> specList = new ArrayList<>(2);
|
||||
specList.add(spec);
|
||||
@@ -654,11 +661,16 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public List<Target> findTargetsByTag(final String tagName) {
|
||||
final JpaTargetTag tag = targetTagRepository.findByNameEquals(tagName);
|
||||
return Collections.unmodifiableList(targetRepository.findByTag(tag));
|
||||
return Collections.unmodifiableList(targetRepository.findByTag(tag.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countTargetByTargetFilterQuery(final TargetFilterQuery targetFilterQuery) {
|
||||
public Long countTargetByTargetFilterQuery(final Long targetFilterQueryId) {
|
||||
final TargetFilterQuery targetFilterQuery = Optional
|
||||
.ofNullable(targetFilterQueryRepository.findOne(targetFilterQueryId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"TargetFilterQuery with given ID" + targetFilterQueryId + " not found"));
|
||||
|
||||
final Specification<JpaTarget> specs = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class,
|
||||
virtualPropertyReplacer);
|
||||
return targetRepository.count(specs);
|
||||
|
||||
@@ -61,6 +61,7 @@ import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder;
|
||||
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
|
||||
import org.eclipse.hawkbit.repository.rsql.RsqlValidationOracle;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.security.SecurityTokenGenerator;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
@@ -354,13 +355,24 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaTargetFilterQueryManagement} bean.
|
||||
*
|
||||
* @param targetFilterQueryRepository
|
||||
* to query entity access
|
||||
* @param virtualPropertyReplacer
|
||||
* for RSQL handling
|
||||
* @param distributionSetManagement
|
||||
* for auto assign DS access
|
||||
*
|
||||
* @return a new {@link TargetFilterQueryManagement}
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public TargetFilterQueryManagement targetFilterQueryManagement() {
|
||||
return new JpaTargetFilterQueryManagement();
|
||||
public TargetFilterQueryManagement targetFilterQueryManagement(
|
||||
final TargetFilterQueryRepository targetFilterQueryRepository,
|
||||
final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||
final DistributionSetManagement distributionSetManagement) {
|
||||
return new JpaTargetFilterQueryManagement(targetFilterQueryRepository, virtualPropertyReplacer,
|
||||
distributionSetManagement);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -176,11 +176,11 @@ final class RolloutHelper {
|
||||
* the group to add
|
||||
* @return list of groups
|
||||
*/
|
||||
static List<RolloutGroup> getGroupsByStatusIncludingGroup(final Rollout rollout,
|
||||
static List<Long> getGroupsByStatusIncludingGroup(final Rollout rollout,
|
||||
final RolloutGroup.RolloutGroupStatus status, final RolloutGroup group) {
|
||||
return rollout.getRolloutGroups().stream()
|
||||
.filter(innerGroup -> innerGroup.getStatus().equals(status) || innerGroup.equals(group))
|
||||
.collect(Collectors.toList());
|
||||
.map(RolloutGroup::getId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,12 +50,12 @@ public interface SoftwareModuleRepository
|
||||
* to be filtered on
|
||||
* @param version
|
||||
* to be filtered on
|
||||
* @param type
|
||||
* @param typeId
|
||||
* to be filtered on
|
||||
* @return the found {@link SoftwareModule} with the given name AND version
|
||||
* AND type
|
||||
*/
|
||||
JpaSoftwareModule findOneByNameAndVersionAndType(String name, String version, JpaSoftwareModuleType type);
|
||||
JpaSoftwareModule findOneByNameAndVersionAndTypeId(String name, String version, Long typeId);
|
||||
|
||||
/**
|
||||
* deletes the {@link SoftwareModule}s with the given IDs.
|
||||
@@ -77,12 +77,12 @@ public interface SoftwareModuleRepository
|
||||
/**
|
||||
* @param pageable
|
||||
* the page request to page the result set
|
||||
* @param set
|
||||
* @param setId
|
||||
* to search for
|
||||
* @return all {@link SoftwareModule}s that are assigned to given
|
||||
* {@link DistributionSet}.
|
||||
*/
|
||||
Page<SoftwareModule> findByAssignedTo(Pageable pageable, JpaDistributionSet set);
|
||||
Page<SoftwareModule> findByAssignedToId(Pageable pageable, Long setId);
|
||||
|
||||
/**
|
||||
* @param pageable
|
||||
|
||||
@@ -12,9 +12,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
@@ -63,12 +61,12 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
|
||||
/**
|
||||
* Finds {@link Target}s by assigned {@link Tag}.
|
||||
*
|
||||
* @param tag
|
||||
* @param tagId
|
||||
* to be found
|
||||
* @return list of found targets
|
||||
*/
|
||||
@Query(value = "SELECT DISTINCT t FROM JpaTarget t JOIN t.tags tt WHERE tt = :tag")
|
||||
List<JpaTarget> findByTag(@Param("tag") final JpaTargetTag tag);
|
||||
@Query(value = "SELECT DISTINCT t FROM JpaTarget t JOIN t.tags tt WHERE tt.id = :tag")
|
||||
List<JpaTarget> findByTag(@Param("tag") final Long tagId);
|
||||
|
||||
/**
|
||||
* Finds all {@link Target}s based on given {@link Target#getControllerId()}
|
||||
@@ -190,11 +188,11 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
|
||||
* Finds all targets related to a target rollout group stored for a specific
|
||||
* rollout.
|
||||
*
|
||||
* @param rolloutGroup
|
||||
* @param rolloutGroupId
|
||||
* the rollout group the targets should belong to
|
||||
* @param page
|
||||
* the page request parameter
|
||||
* @return a page of all targets related to a rollout group
|
||||
*/
|
||||
Page<Target> findByActionsRolloutGroup(JpaRolloutGroup rolloutGroup, Pageable page);
|
||||
Page<Target> findByActionsRolloutGroupId(Long rolloutGroupId, Pageable page);
|
||||
}
|
||||
|
||||
@@ -77,8 +77,9 @@ public class AutoAssignChecker {
|
||||
* @param transactionManager
|
||||
* to run transactions
|
||||
*/
|
||||
public AutoAssignChecker(TargetFilterQueryManagement targetFilterQueryManagement, TargetManagement targetManagement,
|
||||
DeploymentManagement deploymentManagement, PlatformTransactionManager transactionManager) {
|
||||
public AutoAssignChecker(final TargetFilterQueryManagement targetFilterQueryManagement,
|
||||
final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
|
||||
final PlatformTransactionManager transactionManager) {
|
||||
this.targetFilterQueryManagement = targetFilterQueryManagement;
|
||||
this.targetManagement = targetManagement;
|
||||
this.deploymentManagement = deploymentManagement;
|
||||
@@ -97,12 +98,12 @@ public class AutoAssignChecker {
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public void check() {
|
||||
|
||||
PageRequest pageRequest = new PageRequest(0, PAGE_SIZE);
|
||||
final PageRequest pageRequest = new PageRequest(0, PAGE_SIZE);
|
||||
|
||||
Page<TargetFilterQuery> filterQueries = targetFilterQueryManagement
|
||||
final Page<TargetFilterQuery> filterQueries = targetFilterQueryManagement
|
||||
.findTargetFilterQueryWithAutoAssignDS(pageRequest);
|
||||
|
||||
for (TargetFilterQuery filterQuery : filterQueries) {
|
||||
for (final TargetFilterQuery filterQuery : filterQueries) {
|
||||
checkByTargetFilterQueryAndAssignDS(filterQuery);
|
||||
}
|
||||
|
||||
@@ -116,9 +117,9 @@ public class AutoAssignChecker {
|
||||
* @param targetFilterQuery
|
||||
* the target filter query
|
||||
*/
|
||||
private void checkByTargetFilterQueryAndAssignDS(TargetFilterQuery targetFilterQuery) {
|
||||
private void checkByTargetFilterQueryAndAssignDS(final TargetFilterQuery targetFilterQuery) {
|
||||
try {
|
||||
DistributionSet distributionSet = targetFilterQuery.getAutoAssignDistributionSet();
|
||||
final DistributionSet distributionSet = targetFilterQuery.getAutoAssignDistributionSet();
|
||||
|
||||
int count;
|
||||
do {
|
||||
@@ -142,11 +143,12 @@ public class AutoAssignChecker {
|
||||
* distribution set id to assign
|
||||
* @return count of targets
|
||||
*/
|
||||
private int runTransactionalAssignment(TargetFilterQuery targetFilterQuery, Long dsId) {
|
||||
private int runTransactionalAssignment(final TargetFilterQuery targetFilterQuery, final Long dsId) {
|
||||
final String actionMessage = String.format(ACTION_MESSAGE, targetFilterQuery.getName());
|
||||
return transactionTemplate.execute(status -> {
|
||||
List<TargetWithActionType> targets = getTargetsWithActionType(targetFilterQuery, dsId, PAGE_SIZE);
|
||||
int count = targets.size();
|
||||
final List<TargetWithActionType> targets = getTargetsWithActionType(targetFilterQuery.getQuery(), dsId,
|
||||
PAGE_SIZE);
|
||||
final int count = targets.size();
|
||||
if (count > 0) {
|
||||
deploymentManagement.assignDistributionSet(dsId, targets, actionMessage);
|
||||
}
|
||||
@@ -167,10 +169,10 @@ public class AutoAssignChecker {
|
||||
* maximum amount of targets to retrieve
|
||||
* @return list of targets with action type
|
||||
*/
|
||||
private List<TargetWithActionType> getTargetsWithActionType(TargetFilterQuery targetFilterQuery, Long dsId,
|
||||
int count) {
|
||||
Page<Target> targets = targetManagement.findAllTargetsByTargetFilterQueryAndNonDS(new PageRequest(0, count),
|
||||
dsId, targetFilterQuery);
|
||||
private List<TargetWithActionType> getTargetsWithActionType(final String targetFilterQuery, final Long dsId,
|
||||
final int count) {
|
||||
final Page<Target> targets = targetManagement
|
||||
.findAllTargetsByTargetFilterQueryAndNonDS(new PageRequest(0, count), dsId, targetFilterQuery);
|
||||
|
||||
return targets.getContent().stream().map(t -> new TargetWithActionType(t.getControllerId(),
|
||||
Action.ActionType.FORCED, RepositoryModelConstants.NO_FORCE_TIME)).collect(Collectors.toList());
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
@@ -49,15 +48,13 @@ public final class ActionSpecifications {
|
||||
* assigned
|
||||
* @return a specification to use with spring JPA
|
||||
*/
|
||||
public static Specification<JpaAction> hasTargetAssignedArtifact(final Target target,
|
||||
final Artifact localArtifact) {
|
||||
public static Specification<JpaAction> hasTargetAssignedArtifact(final Target target, final Long localArtifact) {
|
||||
return (actionRoot, query, criteriaBuilder) -> {
|
||||
final Join<JpaAction, JpaDistributionSet> dsJoin = actionRoot.join(JpaAction_.distributionSet);
|
||||
final SetJoin<JpaDistributionSet, JpaSoftwareModule> modulesJoin = dsJoin.join(JpaDistributionSet_.modules);
|
||||
final ListJoin<JpaSoftwareModule, JpaArtifact> artifactsJoin = modulesJoin
|
||||
.join(JpaSoftwareModule_.artifacts);
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.filename), localArtifact.getFilename()),
|
||||
return criteriaBuilder.and(criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.id), localArtifact),
|
||||
criteriaBuilder.equal(actionRoot.get(JpaAction_.target), target));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo_;
|
||||
@@ -135,14 +136,13 @@ public final class TargetSpecifications {
|
||||
public static Specification<JpaTarget> isOverdue(final long overdueTimestamp) {
|
||||
return (targetRoot, query, cb) -> {
|
||||
final Join<JpaTarget, JpaTargetInfo> targetInfoJoin = targetRoot.join(JpaTarget_.targetInfo);
|
||||
return cb.lessThanOrEqualTo(
|
||||
targetInfoJoin.get(JpaTargetInfo_.lastTargetQuery), overdueTimestamp);
|
||||
return cb.lessThanOrEqualTo(targetInfoJoin.get(JpaTargetInfo_.lastTargetQuery), overdueTimestamp);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link Target}s by
|
||||
* "like controllerId or like name or like description".
|
||||
* {@link Specification} for retrieving {@link Target}s by "like
|
||||
* controllerId or like name or like description".
|
||||
*
|
||||
* @param searchText
|
||||
* to be filtered on
|
||||
@@ -158,8 +158,8 @@ public final class TargetSpecifications {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link Target}s by
|
||||
* "like controllerId".
|
||||
* {@link Specification} for retrieving {@link Target}s by "like
|
||||
* controllerId".
|
||||
*
|
||||
* @param distributionId
|
||||
* to be filtered on
|
||||
@@ -195,8 +195,8 @@ public final class TargetSpecifications {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link Target}s by
|
||||
* "has no tag names"or "has at least on of the given tag names".
|
||||
* {@link Specification} for retrieving {@link Target}s by "has no tag
|
||||
* names"or "has at least on of the given tag names".
|
||||
*
|
||||
* @param tagNames
|
||||
* to be filtered on
|
||||
@@ -242,8 +242,8 @@ public final class TargetSpecifications {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link Target}s that don't have the given
|
||||
* distribution set in their action history
|
||||
* {@link Specification} for retrieving {@link Target}s that don't have the
|
||||
* given distribution set in their action history
|
||||
*
|
||||
* @param distributionSetId
|
||||
* the ID of the distribution set which must not be assigned
|
||||
@@ -267,11 +267,12 @@ public final class TargetSpecifications {
|
||||
* the {@link RolloutGroup}s
|
||||
* @return the {@link Target} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaTarget> isNotInRolloutGroups(final List<RolloutGroup> groups) {
|
||||
public static Specification<JpaTarget> isNotInRolloutGroups(final Collection<Long> groups) {
|
||||
return (targetRoot, query, cb) -> {
|
||||
ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = targetRoot.join(JpaTarget_.rolloutTargetGroup,
|
||||
JoinType.LEFT);
|
||||
Predicate inRolloutGroups = rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup).in(groups);
|
||||
final ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = targetRoot
|
||||
.join(JpaTarget_.rolloutTargetGroup, JoinType.LEFT);
|
||||
final Predicate inRolloutGroups = rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup)
|
||||
.get(JpaRolloutGroup_.id).in(groups);
|
||||
rolloutTargetJoin.on(inRolloutGroups);
|
||||
return cb.isNull(rolloutTargetJoin.get(RolloutTargetGroup_.target));
|
||||
};
|
||||
@@ -285,14 +286,15 @@ public final class TargetSpecifications {
|
||||
* the {@link RolloutGroup}
|
||||
* @return the {@link Target} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaTarget> hasNoActionInRolloutGroup(final RolloutGroup group) {
|
||||
public static Specification<JpaTarget> hasNoActionInRolloutGroup(final Long group) {
|
||||
return (targetRoot, query, cb) -> {
|
||||
ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = targetRoot.join(JpaTarget_.rolloutTargetGroup,
|
||||
JoinType.INNER);
|
||||
rolloutTargetJoin.on(cb.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup), group));
|
||||
final ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = targetRoot
|
||||
.join(JpaTarget_.rolloutTargetGroup, JoinType.INNER);
|
||||
rolloutTargetJoin.on(
|
||||
cb.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id), group));
|
||||
|
||||
final ListJoin<JpaTarget, JpaAction> actionsJoin = targetRoot.join(JpaTarget_.actions, JoinType.LEFT);
|
||||
actionsJoin.on(cb.equal(actionsJoin.get(JpaAction_.rolloutGroup), group));
|
||||
actionsJoin.on(cb.equal(actionsJoin.get(JpaAction_.rolloutGroup).get(JpaRolloutGroup_.id), group));
|
||||
|
||||
return cb.isNull(actionsJoin.get(JpaAction_.id));
|
||||
};
|
||||
|
||||
@@ -8,15 +8,22 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -83,7 +90,18 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
|
||||
protected TenantConfigurationProperties tenantConfigurationProperties;
|
||||
|
||||
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
|
||||
public List<Action> findActionsByRolloutAndStatus(final Rollout rollout, final Action.Status actionStatus) {
|
||||
return actionRepository.findByRolloutAndStatus((JpaRollout) rollout, actionStatus);
|
||||
protected List<Action> findActionsByRolloutAndStatus(final Rollout rollout, final Action.Status actionStatus) {
|
||||
return actionRepository.findByRolloutIdAndStatus(rollout.getId(), actionStatus);
|
||||
}
|
||||
|
||||
protected TargetTagAssignmentResult toggleTagAssignment(final Collection<Target> targets, final TargetTag tag) {
|
||||
return targetManagement.toggleTagAssignment(
|
||||
targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), tag.getName());
|
||||
}
|
||||
|
||||
public DistributionSetTagAssignmentResult toggleTagAssignment(final Collection<DistributionSet> sets,
|
||||
final DistributionSetTag tag) {
|
||||
return distributionSetManagement.toggleTagAssignment(
|
||||
sets.stream().map(DistributionSet::getId).collect(Collectors.toList()), tag.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
testdataFactory.createSoftwareModuleOs().getId(), "file1", false);
|
||||
|
||||
try (InputStream fileInputStream = artifactManagement.loadArtifactBinary(result).getFileInputStream()) {
|
||||
try (InputStream fileInputStream = artifactManagement.loadArtifactBinary(result.getId()).getFileInputStream()) {
|
||||
assertTrue("The stored binary matches the given binary",
|
||||
IOUtils.contentEquals(new ByteArrayInputStream(random), fileInputStream));
|
||||
}
|
||||
@@ -225,7 +225,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Trys and fails to load an artifact without required permission. Checks if expected InsufficientPermissionException is thrown.")
|
||||
public void loadArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() {
|
||||
try {
|
||||
artifactManagement.loadArtifactBinary(new JpaArtifact());
|
||||
artifactManagement.loadArtifactBinary(1L);
|
||||
fail("Should not have worked with missing permission.");
|
||||
} catch (final InsufficientPermissionException e) {
|
||||
|
||||
|
||||
@@ -59,7 +59,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
savedTarget = assignDistributionSet(ds.getId(), savedTarget.getControllerId()).getAssignedEntity().iterator()
|
||||
.next();
|
||||
final JpaAction savedAction = (JpaAction) deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
|
||||
final JpaAction savedAction = (JpaAction) deploymentManagement
|
||||
.findActiveActionsByTarget(savedTarget.getControllerId()).get(0);
|
||||
|
||||
assertThat(targetManagement.findTargetByControllerID(savedTarget.getControllerId()).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
@@ -75,7 +76,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(3);
|
||||
assertThat(deploymentManagement.findActionStatusByAction(pageReq, savedAction).getNumberOfElements())
|
||||
assertThat(deploymentManagement.findActionStatusByAction(pageReq, savedAction.getId()).getNumberOfElements())
|
||||
.isEqualTo(3);
|
||||
}
|
||||
|
||||
@@ -105,7 +106,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
Target savedTarget = testdataFactory.createTarget();
|
||||
savedTarget = assignDistributionSet(ds.getId(), savedTarget.getControllerId()).getAssignedEntity().iterator()
|
||||
.next();
|
||||
Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
|
||||
Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0);
|
||||
|
||||
// test and verify
|
||||
savedAction = controllerManagament.addUpdateActionStatus(
|
||||
@@ -153,7 +154,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(3);
|
||||
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action).getNumberOfElements()).isEqualTo(3);
|
||||
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action.getId()).getNumberOfElements())
|
||||
.isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,7 +172,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(4);
|
||||
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action).getNumberOfElements()).isEqualTo(4);
|
||||
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action.getId()).getNumberOfElements())
|
||||
.isEqualTo(4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
actionStatusRepository.save(new JpaActionStatus(action, Status.RUNNING, System.currentTimeMillis()));
|
||||
|
||||
final List<ActionWithStatusCount> findActionsWithStatusCountByTarget = deploymentManagement
|
||||
.findActionsWithStatusCountByTargetOrderByIdDesc(testTarget.get(0));
|
||||
.findActionsWithStatusCountByTargetOrderByIdDesc(testTarget.get(0).getControllerId());
|
||||
|
||||
assertThat(findActionsWithStatusCountByTarget).as("wrong action size").hasSize(1);
|
||||
assertThat(findActionsWithStatusCountByTarget.get(0).getActionStatusCount()).as("wrong action status size")
|
||||
@@ -134,7 +134,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSetTag tag = tagManagement
|
||||
.createDistributionSetTag(entityFactory.tag().create().name("Tag1"));
|
||||
|
||||
final List<DistributionSet> assignedDS = distributionSetManagement.assignTag(assignDS, tag);
|
||||
final List<DistributionSet> assignedDS = distributionSetManagement.assignTag(assignDS, tag.getId());
|
||||
assertThat(assignedDS.size()).as("assigned ds has wrong size").isEqualTo(4);
|
||||
assignedDS.forEach(ds -> assertThat(ds.getTags().size()).as("ds has wrong tag size").isEqualTo(1));
|
||||
|
||||
@@ -142,11 +142,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(assignedDS.size()).as("assigned ds has wrong size")
|
||||
.isEqualTo(findDistributionSetTag.getAssignedToDistributionSet().size());
|
||||
|
||||
assertThat(distributionSetManagement.unAssignTag(Long.valueOf(100), findDistributionSetTag))
|
||||
.as("unassign tag result should be null").isNull();
|
||||
|
||||
final DistributionSet unAssignDS = distributionSetManagement.unAssignTag(assignDS.get(0),
|
||||
findDistributionSetTag);
|
||||
findDistributionSetTag.getId());
|
||||
assertThat(unAssignDS.getId()).as("unassigned ds is wrong").isEqualTo(assignDS.get(0));
|
||||
assertThat(unAssignDS.getTags().size()).as("unassigned ds has wrong tag size").isEqualTo(0);
|
||||
findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1");
|
||||
@@ -154,7 +151,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.isEqualTo(3);
|
||||
|
||||
final List<DistributionSet> unAssignTargets = distributionSetManagement
|
||||
.unAssignAllDistributionSetsByTag(findDistributionSetTag);
|
||||
.unAssignAllDistributionSetsByTag(findDistributionSetTag.getId());
|
||||
findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1");
|
||||
assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).as("ds tag has wrong ds size")
|
||||
.isEqualTo(0);
|
||||
@@ -178,10 +175,9 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
targets = assignDistributionSet(cancelDs, targets).getAssignedEntity();
|
||||
targets = assignDistributionSet(cancelDs2, targets).getAssignedEntity();
|
||||
|
||||
targetManagement.findAllTargetIds().forEach(targetIdName -> {
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(
|
||||
targetManagement.findTargetByControllerID(targetIdName.getControllerId())))
|
||||
.as("active action has wrong size").hasSize(2);
|
||||
targetManagement.findTargetsAll(pageReq).getContent().forEach(targetIdName -> {
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(targetIdName.getControllerId()))
|
||||
.as("active action has wrong size").hasSize(2);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -208,8 +204,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(5);
|
||||
|
||||
// we cancel second -> back to first
|
||||
deploymentManagement.cancelAction(secondAction,
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()));
|
||||
deploymentManagement.cancelAction(secondAction.getId());
|
||||
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId());
|
||||
// confirm cancellation
|
||||
controllerManagement.addCancelActionStatus(
|
||||
@@ -221,8 +216,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
// we cancel first -> back to installed
|
||||
deploymentManagement.cancelAction(firstAction,
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()));
|
||||
deploymentManagement.cancelAction(firstAction.getId());
|
||||
firstAction = (JpaAction) deploymentManagement.findActionWithDetails(firstAction.getId());
|
||||
// confirm cancellation
|
||||
controllerManagement.addCancelActionStatus(
|
||||
@@ -257,8 +251,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(5);
|
||||
|
||||
// we cancel first -> second is left
|
||||
deploymentManagement.cancelAction(firstAction,
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()));
|
||||
deploymentManagement.cancelAction(firstAction.getId());
|
||||
// confirm cancellation
|
||||
firstAction = (JpaAction) deploymentManagement.findActionWithDetails(firstAction.getId());
|
||||
controllerManagement.addCancelActionStatus(
|
||||
@@ -270,8 +263,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.as("wrong target update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
// we cancel second -> remain assigned until finished cancellation
|
||||
deploymentManagement.cancelAction(secondAction,
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()));
|
||||
deploymentManagement.cancelAction(secondAction.getId());
|
||||
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId());
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(8);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
|
||||
@@ -308,10 +300,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
target = targetManagement.findTargetByControllerID(target.getControllerId());
|
||||
|
||||
// force quit assignment
|
||||
deploymentManagement.cancelAction(assigningAction, target);
|
||||
deploymentManagement.cancelAction(assigningAction.getId());
|
||||
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId());
|
||||
|
||||
deploymentManagement.forceQuitAction(assigningAction);
|
||||
deploymentManagement.forceQuitAction(assigningAction.getId());
|
||||
|
||||
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId());
|
||||
|
||||
@@ -343,7 +335,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// force quit assignment
|
||||
try {
|
||||
deploymentManagement.forceQuitAction(assigningAction);
|
||||
deploymentManagement.forceQuitAction(assigningAction.getId());
|
||||
fail("expected ForceQuitActionNotAllowedException");
|
||||
} catch (final ForceQuitActionNotAllowedException ex) {
|
||||
}
|
||||
@@ -404,12 +396,14 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
for (final Target myt : savedNakedTargets) {
|
||||
final Target t = targetManagement.findTargetByControllerID(myt.getControllerId());
|
||||
assertThat(deploymentManagement.findActionsByTarget(t)).as("action should be empty").isEmpty();
|
||||
assertThat(deploymentManagement.countActionsByTarget(t.getControllerId())).as("action should be empty")
|
||||
.isEqualTo(0L);
|
||||
}
|
||||
|
||||
for (final Target myt : savedDeployedTargets) {
|
||||
final Target t = targetManagement.findTargetByControllerID(myt.getControllerId());
|
||||
final List<Action> activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(t);
|
||||
final List<Action> activeActionsByTarget = deploymentManagement
|
||||
.findActiveActionsByTarget(t.getControllerId());
|
||||
assertThat(activeActionsByTarget).as("action should not be empty").isNotEmpty();
|
||||
assertThat(t.getTargetInfo().getUpdateStatus()).as("wrong target update status")
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
@@ -544,9 +538,9 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final JpaDistributionSet dsC = (JpaDistributionSet) deployResWithDsC.getDistributionSets().get(0);
|
||||
|
||||
// retrieving the UpdateActions created by the assignments
|
||||
actionRepository.findByDistributionSet(pageRequest, dsA).getContent().get(0);
|
||||
actionRepository.findByDistributionSet(pageRequest, dsB).getContent().get(0);
|
||||
actionRepository.findByDistributionSet(pageRequest, dsC).getContent().get(0);
|
||||
actionRepository.findByDistributionSetId(pageRequest, dsA.getId()).getContent().get(0);
|
||||
actionRepository.findByDistributionSetId(pageRequest, dsB.getId()).getContent().get(0);
|
||||
actionRepository.findByDistributionSetId(pageRequest, dsC.getId()).getContent().get(0);
|
||||
|
||||
// verifying the correctness of the assignments
|
||||
for (final Target t : deployResWithDsA.getDeployedTargets()) {
|
||||
@@ -581,7 +575,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.getInstalledDistributionSet()).as("installed ds is wrong").isEqualTo(dsA);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(t)).as("no actions should be active").hasSize(0);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(t.getControllerId()))
|
||||
.as("no actions should be active").hasSize(0);
|
||||
}
|
||||
|
||||
// deploy dsA to the target which already have dsB deployed -> must
|
||||
@@ -590,7 +585,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// UpdateAction for dsA
|
||||
final Iterable<Target> deployed2DS = assignDistributionSet(dsA, deployResWithDsB.getDeployedTargets())
|
||||
.getAssignedEntity();
|
||||
actionRepository.findByDistributionSet(pageRequest, dsA).getContent().get(1);
|
||||
actionRepository.findByDistributionSetId(pageRequest, dsA.getId()).getContent().get(1);
|
||||
|
||||
// get final updated version of targets
|
||||
final List<Target> deployResWithDsBTargets = targetManagement.findTargetByControllerID(deployResWithDsB
|
||||
@@ -661,8 +656,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
Collections.singletonList("blabla alles gut"));
|
||||
}
|
||||
// try to delete again
|
||||
distributionSetManagement.deleteDistributionSet(deploymentResult.getDistributionSetIDs()
|
||||
.toArray(new Long[deploymentResult.getDistributionSetIDs().size()]));
|
||||
distributionSetManagement.deleteDistributionSet(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
|
||||
@@ -699,9 +693,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetManagement.countTargetsAll()).as("size of targets is wrong").isNotZero();
|
||||
assertThat(actionStatusRepository.count()).as("size of action status is wrong").isNotZero();
|
||||
|
||||
targetManagement
|
||||
.deleteTargets(deploymentResult.getUndeployedTargetIDs().toArray(new Long[noOfUndeployedTargets]));
|
||||
targetManagement.deleteTargets(deploymentResult.getDeployedTargetIDs().toArray(new Long[noOfDeployedTargets]));
|
||||
targetManagement.deleteTargets(deploymentResult.getUndeployedTargetIDs());
|
||||
targetManagement.deleteTargets(deploymentResult.getDeployedTargetIDs());
|
||||
|
||||
assertThat(targetManagement.countTargetsAll()).as("size of targets should be zero").isZero();
|
||||
assertThat(actionStatusRepository.count()).as("size of action status is wrong").isZero();
|
||||
@@ -726,25 +719,28 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
|
||||
|
||||
// verifying that the assignment is correct
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(targ).size()).as("Active target actions are wrong")
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size())
|
||||
.as("Active target actions are wrong").isEqualTo(1);
|
||||
assertThat(deploymentManagement.countActionsByTarget(targ.getControllerId())).as("Target actions are wrong")
|
||||
.isEqualTo(1);
|
||||
assertThat(deploymentManagement.findActionsByTarget(targ).size()).as("Target actions are wrong").isEqualTo(1);
|
||||
assertThat(targ.getTargetInfo().getUpdateStatus()).as("UpdateStatus of target is wrong")
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targ.getAssignedDistributionSet()).as("Assigned distribution set of target is wrong").isEqualTo(dsA);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(targ).get(0).getDistributionSet())
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet())
|
||||
.as("Distribution set of actionn is wrong").isEqualTo(dsA);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(targ).get(0).getDistributionSet())
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet())
|
||||
.as("Installed distribution set of action should be null").isNotNull();
|
||||
|
||||
final Page<Action> updAct = actionRepository.findByDistributionSet(pageReq, (JpaDistributionSet) dsA);
|
||||
final Page<Action> updAct = actionRepository.findByDistributionSetId(pageReq, dsA.getId());
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(updAct.getContent().get(0).getId()).status(Status.FINISHED));
|
||||
|
||||
targ = targetManagement.findTargetByControllerID(targ.getControllerId());
|
||||
|
||||
assertEquals("active target actions are wrong", 0, deploymentManagement.findActiveActionsByTarget(targ).size());
|
||||
assertEquals("active actions are wrong", 1, deploymentManagement.findInActiveActionsByTarget(targ).size());
|
||||
assertEquals("active target actions are wrong", 0,
|
||||
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size());
|
||||
assertEquals("active actions are wrong", 1,
|
||||
deploymentManagement.findInActiveActionsByTarget(targ.getControllerId()).size());
|
||||
|
||||
assertEquals("tagret update status is not correct", TargetUpdateStatus.IN_SYNC,
|
||||
targ.getTargetInfo().getUpdateStatus());
|
||||
@@ -755,7 +751,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
targ = targs.iterator().next();
|
||||
|
||||
assertEquals("active actions are wrong", 1, deploymentManagement.findActiveActionsByTarget(targ).size());
|
||||
assertEquals("active actions are wrong", 1,
|
||||
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size());
|
||||
assertEquals("target status is wrong", TargetUpdateStatus.PENDING,
|
||||
targetManagement.findTargetByControllerID(targ.getControllerId()).getTargetInfo().getUpdateStatus());
|
||||
assertEquals("wrong assigned ds", dsB, targ.getAssignedDistributionSet());
|
||||
@@ -763,7 +760,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
targetManagement.findTargetByControllerIDWithDetails(targ.getControllerId()).getTargetInfo()
|
||||
.getInstalledDistributionSet().getId());
|
||||
assertEquals("Active ds is wrong", dsB,
|
||||
deploymentManagement.findActiveActionsByTarget(targ).get(0).getDistributionSet());
|
||||
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet());
|
||||
|
||||
}
|
||||
|
||||
@@ -892,7 +889,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
for (final TargetAssignDistributionSetEvent event : events) {
|
||||
if (event.getControllerId().equals(myt.getControllerId())) {
|
||||
found = true;
|
||||
final List<Action> activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(myt);
|
||||
final List<Action> activeActionsByTarget = deploymentManagement
|
||||
.findActiveActionsByTarget(myt.getControllerId());
|
||||
assertThat(activeActionsByTarget).as("size of active actions for target is wrong").isNotEmpty();
|
||||
assertThat(event.getActionId()).as("Action id in database and event do not match")
|
||||
.isEqualTo(activeActionsByTarget.get(0).getId());
|
||||
|
||||
@@ -149,7 +149,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
entityFactory.distributionSetType().create().key("delete").name("to be deleted"));
|
||||
|
||||
assertThat(distributionSetTypeRepository.findAll()).contains(hardDelete);
|
||||
distributionSetManagement.deleteDistributionSetType(hardDelete);
|
||||
distributionSetManagement.deleteDistributionSetType(hardDelete.getId());
|
||||
|
||||
assertThat(distributionSetTypeRepository.findAll()).doesNotContain(hardDelete);
|
||||
}
|
||||
@@ -165,7 +165,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
distributionSetManagement.createDistributionSet(
|
||||
entityFactory.distributionSet().create().name("softdeleted").version("1").type(softDelete.getKey()));
|
||||
|
||||
distributionSetManagement.deleteDistributionSetType(softDelete);
|
||||
distributionSetManagement.deleteDistributionSetType(softDelete.getId());
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").isDeleted()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@@ -430,14 +430,14 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
dsDeleted.getModules().stream().map(SoftwareModule::getId).collect(Collectors.toList())));
|
||||
|
||||
assignDistributionSet(dsDeleted, Lists.newArrayList(testdataFactory.createTargets(5)));
|
||||
distributionSetManagement.deleteDistributionSet(dsDeleted);
|
||||
distributionSetManagement.deleteDistributionSet(dsDeleted.getId());
|
||||
dsDeleted = distributionSetManagement.findDistributionSetById(dsDeleted.getId());
|
||||
|
||||
ds100Group1 = distributionSetManagement.toggleTagAssignment(ds100Group1, dsTagA).getAssignedEntity();
|
||||
ds100Group1 = toggleTagAssignment(ds100Group1, dsTagA).getAssignedEntity();
|
||||
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName());
|
||||
ds100Group1 = distributionSetManagement.toggleTagAssignment(ds100Group1, dsTagB).getAssignedEntity();
|
||||
ds100Group1 = toggleTagAssignment(ds100Group1, dsTagB).getAssignedEntity();
|
||||
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName());
|
||||
ds100Group2 = distributionSetManagement.toggleTagAssignment(ds100Group2, dsTagA).getAssignedEntity();
|
||||
ds100Group2 = toggleTagAssignment(ds100Group2, dsTagA).getAssignedEntity();
|
||||
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName());
|
||||
|
||||
// check setup
|
||||
@@ -722,7 +722,8 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// delete assigned ds
|
||||
assertThat(distributionSetRepository.findAll()).hasSize(4);
|
||||
distributionSetManagement.deleteDistributionSet(dsToTargetAssigned.getId(), dsToRolloutAssigned.getId());
|
||||
distributionSetManagement
|
||||
.deleteDistributionSet(Lists.newArrayList(dsToTargetAssigned.getId(), dsToRolloutAssigned.getId()));
|
||||
|
||||
// not assigned so not marked as deleted
|
||||
assertThat(distributionSetRepository.findAll()).hasSize(4);
|
||||
|
||||
@@ -139,8 +139,7 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Target createTarget = testdataFactory.createTarget("t" + month);
|
||||
final DistributionSetAssignmentResult result = assignDistributionSet(distributionSet,
|
||||
Lists.newArrayList(createTarget));
|
||||
controllerManagament.registerRetrieved(
|
||||
deploymentManagement.findActionWithDetails(result.getActions().get(0)),
|
||||
controllerManagament.registerRetrieved(result.getActions().get(0),
|
||||
"Controller retrieved update action and should start now the download.");
|
||||
}
|
||||
DataReportSeries<LocalDate> feedbackReceivedOverTime = reportManagement
|
||||
@@ -161,8 +160,7 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Target createTarget = testdataFactory.createTarget("t2" + month);
|
||||
final DistributionSetAssignmentResult result = assignDistributionSet(distributionSet,
|
||||
Lists.newArrayList(createTarget));
|
||||
controllerManagament.registerRetrieved(
|
||||
deploymentManagement.findActionWithDetails(result.getActions().get(0)),
|
||||
controllerManagament.registerRetrieved(result.getActions().get(0),
|
||||
"Controller retrieved update action and should start now the download.");
|
||||
}
|
||||
feedbackReceivedOverTime = reportManagement.feedbackReceivedOverTime(DateTypes.perMonth(), from, to);
|
||||
|
||||
@@ -202,13 +202,13 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Step("Finish three actions of the rollout group and delete two targets")
|
||||
private void finishActionAndDeleteTargetsOfFirstRunningGroup(final Rollout createdRollout) {
|
||||
// finish group one by finishing targets and deleting targets
|
||||
final List<Action> runningActions = deploymentManagement.findActionsByRolloutAndStatus(createdRollout,
|
||||
final List<Action> runningActions = actionRepository.findByRolloutIdAndStatus(createdRollout.getId(),
|
||||
Status.RUNNING);
|
||||
finishAction(runningActions.get(0));
|
||||
finishAction(runningActions.get(1));
|
||||
finishAction(runningActions.get(2));
|
||||
targetManagement.deleteTargets(runningActions.get(3).getTarget().getId(),
|
||||
runningActions.get(4).getTarget().getId());
|
||||
targetManagement.deleteTargets(Lists.newArrayList(runningActions.get(3).getTarget().getId(),
|
||||
runningActions.get(4).getTarget().getId()));
|
||||
}
|
||||
|
||||
@Step("Check the status of the rollout groups, second group should be in running status")
|
||||
@@ -223,22 +223,22 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Step("Finish one action of the rollout group and delete four targets")
|
||||
private void finishActionAndDeleteTargetsOfSecondRunningGroup(final Rollout createdRollout) {
|
||||
final List<Action> runningActions = deploymentManagement.findActionsByRolloutAndStatus(createdRollout,
|
||||
final List<Action> runningActions = actionRepository.findByRolloutIdAndStatus(createdRollout.getId(),
|
||||
Status.RUNNING);
|
||||
finishAction(runningActions.get(0));
|
||||
targetManagement.deleteTargets(runningActions.get(1).getTarget().getId(),
|
||||
runningActions.get(2).getTarget().getId(), runningActions.get(3).getTarget().getId(),
|
||||
runningActions.get(4).getTarget().getId());
|
||||
targetManagement.deleteTargets(
|
||||
Lists.newArrayList(runningActions.get(1).getTarget().getId(), runningActions.get(2).getTarget().getId(),
|
||||
runningActions.get(3).getTarget().getId(), runningActions.get(4).getTarget().getId()));
|
||||
|
||||
}
|
||||
|
||||
@Step("Delete all targets of the rollout group")
|
||||
private void deleteAllTargetsFromThirdGroup(final Rollout createdRollout) {
|
||||
final List<Action> runningActions = deploymentManagement.findActionsByRolloutAndStatus(createdRollout,
|
||||
final List<Action> runningActions = actionRepository.findByRolloutIdAndStatus(createdRollout.getId(),
|
||||
Status.SCHEDULED);
|
||||
targetManagement.deleteTargets(runningActions.get(0).getTarget().getId(),
|
||||
targetManagement.deleteTargets(Lists.newArrayList(runningActions.get(0).getTarget().getId(),
|
||||
runningActions.get(1).getTarget().getId(), runningActions.get(2).getTarget().getId(),
|
||||
runningActions.get(3).getTarget().getId(), runningActions.get(4).getTarget().getId());
|
||||
runningActions.get(3).getTarget().getId(), runningActions.get(4).getTarget().getId()));
|
||||
}
|
||||
|
||||
@Step("Check the status of the rollout groups and the rollout")
|
||||
@@ -549,7 +549,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// 5 targets are in the group and the DS has been assigned
|
||||
final List<RolloutGroup> rolloutGroups = createdRollout.getRolloutGroups();
|
||||
final Page<Target> targets = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0),
|
||||
final Page<Target> targets = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0).getId(),
|
||||
new OffsetBasedPageRequest(0, 20, new Sort(Direction.ASC, "id")));
|
||||
final List<Target> targetList = targets.getContent();
|
||||
assertThat(targetList.size()).isEqualTo(5);
|
||||
@@ -922,14 +922,14 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
|
||||
float percent = rolloutManagement.getFinishedPercentForRunningGroup(myRollout.getId(),
|
||||
myRollout.getRolloutGroups().get(0));
|
||||
myRollout.getRolloutGroups().get(0).getId());
|
||||
assertThat(percent).isEqualTo(40);
|
||||
|
||||
changeStatusForRunningActions(myRollout, Status.FINISHED, 3);
|
||||
rolloutManagement.checkRunningRollouts(0);
|
||||
|
||||
percent = rolloutManagement.getFinishedPercentForRunningGroup(myRollout.getId(),
|
||||
myRollout.getRolloutGroups().get(0));
|
||||
myRollout.getRolloutGroups().get(0).getId());
|
||||
assertThat(percent).isEqualTo(100);
|
||||
|
||||
changeStatusForRunningActions(myRollout, Status.FINISHED, 4);
|
||||
@@ -937,7 +937,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.checkRunningRollouts(0);
|
||||
|
||||
percent = rolloutManagement.getFinishedPercentForRunningGroup(myRollout.getId(),
|
||||
myRollout.getRolloutGroups().get(1));
|
||||
myRollout.getRolloutGroups().get(1).getId());
|
||||
assertThat(percent).isEqualTo(80);
|
||||
}
|
||||
|
||||
@@ -966,19 +966,19 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
final List<RolloutGroup> rolloutGroups = myRollout.getRolloutGroups();
|
||||
|
||||
Page<Target> targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0), rsqlParam,
|
||||
new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "controllerId")));
|
||||
Page<Target> targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0).getId(),
|
||||
rsqlParam, new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "controllerId")));
|
||||
final List<Target> targetlistGroup1 = targetPage.getContent();
|
||||
assertThat(targetlistGroup1.size()).isEqualTo(5);
|
||||
assertThat(targetlistGroup1.get(0).getControllerId()).isEqualTo("MyRollout--00000");
|
||||
|
||||
targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(1), rsqlParam,
|
||||
targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(1).getId(), rsqlParam,
|
||||
new OffsetBasedPageRequest(0, 100, new Sort(Direction.DESC, "controllerId")));
|
||||
final List<Target> targetlistGroup2 = targetPage.getContent();
|
||||
assertThat(targetlistGroup2.size()).isEqualTo(5);
|
||||
assertThat(targetlistGroup2.get(0).getControllerId()).isEqualTo("MyRollout--00009");
|
||||
|
||||
targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(2), rsqlParam,
|
||||
targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(2).getId(), rsqlParam,
|
||||
new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "controllerId")));
|
||||
final List<Target> targetlistGroup3 = targetPage.getContent();
|
||||
assertThat(targetlistGroup3.size()).isEqualTo(5);
|
||||
|
||||
@@ -249,7 +249,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
appType, type);
|
||||
|
||||
// delete unassigned
|
||||
softwareManagement.deleteSoftwareModuleType(type);
|
||||
softwareManagement.deleteSoftwareModuleType(type.getId());
|
||||
assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(3).contains(osType, runtimeType,
|
||||
appType);
|
||||
assertThat(softwareModuleTypeRepository.findAll()).hasSize(3).contains((JpaSoftwareModuleType) osType,
|
||||
@@ -265,7 +265,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
entityFactory.softwareModule().create().type(type).name("Test SM").version("1.0"));
|
||||
|
||||
// delete assigned
|
||||
softwareManagement.deleteSoftwareModuleType(type);
|
||||
softwareManagement.deleteSoftwareModuleType(type.getId());
|
||||
assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(3).contains(osType, runtimeType,
|
||||
appType);
|
||||
|
||||
@@ -348,7 +348,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
assignDistributionSet(disSet, Lists.newArrayList(target));
|
||||
|
||||
// [STEP4]: Delete the DistributionSet
|
||||
distributionSetManagement.deleteDistributionSet(disSet);
|
||||
distributionSetManagement.deleteDistributionSet(disSet.getId());
|
||||
|
||||
// [STEP5]: Delete the assigned SoftwareModule
|
||||
softwareManagement.deleteSoftwareModule(assignedModule.getId());
|
||||
@@ -694,7 +694,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
.create().name("set").version("1").modules(Lists.newArrayList(one.getId(), deleted.getId())));
|
||||
softwareManagement.deleteSoftwareModule(deleted.getId());
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleByAssignedTo(pageReq, set).getContent())
|
||||
assertThat(softwareManagement.findSoftwareModuleByAssignedTo(pageReq, set.getId()).getContent())
|
||||
.as("Found this number of modules").hasSize(2);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,22 +68,22 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSetTag tagX = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("X"));
|
||||
final DistributionSetTag tagY = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("Y"));
|
||||
|
||||
distributionSetManagement.toggleTagAssignment(dsAs, tagA);
|
||||
distributionSetManagement.toggleTagAssignment(dsBs, tagB);
|
||||
distributionSetManagement.toggleTagAssignment(dsCs, tagC);
|
||||
toggleTagAssignment(dsAs, tagA);
|
||||
toggleTagAssignment(dsBs, tagB);
|
||||
toggleTagAssignment(dsCs, tagC);
|
||||
|
||||
distributionSetManagement.toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagA.getName()));
|
||||
distributionSetManagement.toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagB.getName()));
|
||||
toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagA.getName()));
|
||||
toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagB.getName()));
|
||||
|
||||
distributionSetManagement.toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagA.getName()));
|
||||
distributionSetManagement.toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagC.getName()));
|
||||
toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagA.getName()));
|
||||
toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagC.getName()));
|
||||
|
||||
distributionSetManagement.toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagB.getName()));
|
||||
distributionSetManagement.toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagC.getName()));
|
||||
toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagB.getName()));
|
||||
toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagC.getName()));
|
||||
|
||||
distributionSetManagement.toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagA.getName()));
|
||||
distributionSetManagement.toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagB.getName()));
|
||||
distributionSetManagement.toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagC.getName()));
|
||||
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagA.getName()));
|
||||
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagB.getName()));
|
||||
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagC.getName()));
|
||||
|
||||
DistributionSetFilterBuilder distributionSetFilterBuilder;
|
||||
|
||||
@@ -164,7 +164,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
.createDistributionSetTag(entityFactory.tag().create().name("tag1").description("tagdesc1"));
|
||||
|
||||
// toggle A only -> A is now assigned
|
||||
DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(groupA, tag);
|
||||
DistributionSetTagAssignmentResult result = toggleTagAssignment(groupA, tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement
|
||||
@@ -174,7 +174,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
|
||||
|
||||
// toggle A+B -> A is still assigned and B is assigned as well
|
||||
result = distributionSetManagement.toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
result = toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement
|
||||
@@ -184,7 +184,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
|
||||
|
||||
// toggle A+B -> both unassigned
|
||||
result = distributionSetManagement.toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
result = toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssignedEntity()).isEmpty();
|
||||
@@ -206,7 +206,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
.createTargetTag(entityFactory.tag().create().name("tag1").description("tagdesc1"));
|
||||
|
||||
// toggle A only -> A is now assigned
|
||||
TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(groupA, tag);
|
||||
TargetTagAssignmentResult result = toggleTagAssignment(groupA, tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
|
||||
@@ -216,7 +216,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(result.getTargetTag()).isEqualTo(tag);
|
||||
|
||||
// toggle A+B -> A is still assigned and B is assigned as well
|
||||
result = targetManagement.toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
result = toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
|
||||
@@ -226,7 +226,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(result.getTargetTag()).isEqualTo(tag);
|
||||
|
||||
// toggle A+B -> both unassigned
|
||||
result = targetManagement.toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
result = toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssignedEntity()).isEmpty();
|
||||
@@ -439,7 +439,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<Target> targets = testdataFactory.createTargets(20);
|
||||
final Iterable<TargetTag> tags = testdataFactory.createTargetTags(20, "");
|
||||
|
||||
tags.forEach(tag -> targetManagement.toggleTagAssignment(targets, tag));
|
||||
tags.forEach(tag -> toggleTagAssignment(targets, tag));
|
||||
|
||||
return targetTagRepository.findAll();
|
||||
}
|
||||
@@ -449,7 +449,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Collection<DistributionSet> sets = testdataFactory.createDistributionSets(20);
|
||||
final Iterable<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(20);
|
||||
|
||||
tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(sets, tag));
|
||||
tags.forEach(tag -> toggleTagAssignment(sets, tag));
|
||||
|
||||
return tagManagement.findAllDistributionSetTags();
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
|
||||
assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet());
|
||||
|
||||
distributionSetManagement.deleteDistributionSet(distributionSet);
|
||||
distributionSetManagement.deleteDistributionSet(distributionSet.getId());
|
||||
|
||||
// Check if auto assign distribution set is null
|
||||
tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
|
||||
@@ -181,7 +181,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
|
||||
assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet());
|
||||
|
||||
distributionSetManagement.deleteDistributionSet(distributionSet);
|
||||
distributionSetManagement.deleteDistributionSet(distributionSet.getId());
|
||||
|
||||
// Check if distribution set is still in the database with deleted flag
|
||||
assertTrue("Distribution set should be deleted",
|
||||
@@ -225,7 +225,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
|
||||
// check if find works
|
||||
Page<TargetFilterQuery> tfqList = targetFilterQueryManagement
|
||||
.findTargetFilterQueryByAutoAssignDS(new PageRequest(0, 500), distributionSet);
|
||||
.findTargetFilterQueryByAutoAssignDS(new PageRequest(0, 500), distributionSet.getId(), null);
|
||||
assertThat(1L).as("Target filter query").isEqualTo(tfqList.getTotalElements());
|
||||
|
||||
assertEquals("Returns correct target filter query", tfq.getId(), tfqList.iterator().next().getId());
|
||||
@@ -234,7 +234,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
|
||||
// check if find works for two
|
||||
tfqList = targetFilterQueryManagement.findTargetFilterQueryByAutoAssignDS(new PageRequest(0, 500),
|
||||
distributionSet);
|
||||
distributionSet.getId(), null);
|
||||
assertThat(2L).as("Target filter query count").isEqualTo(tfqList.getTotalElements());
|
||||
Iterator<TargetFilterQuery> iterator = tfqList.iterator();
|
||||
assertEquals("Returns correct target filter query 1", tfq.getId(), iterator.next().getId());
|
||||
@@ -242,7 +242,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
|
||||
// check if find works with name filter
|
||||
tfqList = targetFilterQueryManagement.findTargetFilterQueryByAutoAssignDS(new PageRequest(0, 500),
|
||||
distributionSet, "name==" + filterName);
|
||||
distributionSet.getId(), "name==" + filterName);
|
||||
assertThat(1L).as("Target filter query count").isEqualTo(tfqList.getTotalElements());
|
||||
|
||||
assertEquals("Returns correct target filter query", tfq2.getId(), tfqList.iterator().next().getId());
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.FilterParams;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -65,7 +64,7 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
final String targetDsAIdPref = "targ-A";
|
||||
List<Target> targAs = testdataFactory.createTargets(100, targetDsAIdPref,
|
||||
targetDsAIdPref.concat(" description"), lastTargetQueryNotOverdue);
|
||||
targAs = targetManagement.toggleTagAssignment(targAs, targTagX).getAssignedEntity();
|
||||
targAs = toggleTagAssignment(targAs, targTagX).getAssignedEntity();
|
||||
|
||||
final Target targSpecialName = targetManagement
|
||||
.updateTarget(entityFactory.target().update(targAs.get(0).getControllerId()).name("targ-A-special"));
|
||||
@@ -74,15 +73,15 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
List<Target> targBs = testdataFactory.createTargets(100, targetDsBIdPref,
|
||||
targetDsBIdPref.concat(" description"), lastTargetQueryAlwaysOverdue);
|
||||
|
||||
targBs = targetManagement.toggleTagAssignment(targBs, targTagY).getAssignedEntity();
|
||||
targBs = targetManagement.toggleTagAssignment(targBs, targTagW).getAssignedEntity();
|
||||
targBs = toggleTagAssignment(targBs, targTagY).getAssignedEntity();
|
||||
targBs = toggleTagAssignment(targBs, targTagW).getAssignedEntity();
|
||||
|
||||
final String targetDsCIdPref = "targ-C";
|
||||
List<Target> targCs = testdataFactory.createTargets(100, targetDsCIdPref,
|
||||
targetDsCIdPref.concat(" description"), lastTargetQueryAlwaysOverdue);
|
||||
|
||||
targCs = targetManagement.toggleTagAssignment(targCs, targTagZ).getAssignedEntity();
|
||||
targCs = targetManagement.toggleTagAssignment(targCs, targTagW).getAssignedEntity();
|
||||
targCs = toggleTagAssignment(targCs, targTagZ).getAssignedEntity();
|
||||
targCs = toggleTagAssignment(targCs, targTagW).getAssignedEntity();
|
||||
|
||||
final String targetDsDIdPref = "targ-D";
|
||||
final List<Target> targDs = testdataFactory.createTargets(100, targetDsDIdPref,
|
||||
@@ -175,15 +174,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
installedSet.getId(), Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsExactly(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, installedSet.getId(),
|
||||
Boolean.FALSE, new String[0])).as("has number of elements").hasSize(1)
|
||||
.as("and contains the following elements").containsExactly(expectedIdName)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query)));
|
||||
.as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
|
||||
}
|
||||
|
||||
@@ -201,15 +198,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
Boolean.FALSE, targTagW.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, both, null, null, null, Boolean.FALSE,
|
||||
targTagW.getName())).as("has number of elements").hasSize(200).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new JpaTargetFilterQuery("test", query)));
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
private static List<TargetIdName> convertToIdNames(final List<Target> expected) {
|
||||
@@ -236,15 +230,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
Boolean.FALSE, targTagW.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, null, Boolean.FALSE,
|
||||
targTagW.getName())).as("has number of elements").hasSize(2).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new JpaTargetFilterQuery("test", query)));
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -262,15 +253,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
setA.getId(), Boolean.FALSE, targTagW.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, null, Boolean.FALSE,
|
||||
targTagW.getName())).as("has number of elements").hasSize(2).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new JpaTargetFilterQuery("test", query)));
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -287,15 +275,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
setA.getId(), Boolean.FALSE, targTagW.getName())))
|
||||
.as("and contains the following elements").containsExactly(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, "%targ-B%", setA.getId(),
|
||||
Boolean.FALSE, targTagW.getName())).as("has number of elements").hasSize(1)
|
||||
.as("and contains the following elements").containsExactly(expectedIdName)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query)));
|
||||
.as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -313,15 +299,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
setA.getId(), Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsExactly(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, "%targ-A%", setA.getId(),
|
||||
Boolean.FALSE, new String[0])).as("has number of elements").hasSize(1)
|
||||
.as("and contains the following elements").containsExactly(expectedIdName)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query)));
|
||||
.as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -339,15 +323,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
setA.getId(), Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, setA.getId(), Boolean.FALSE,
|
||||
new String[0])).as("has number of elements").hasSize(3).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new JpaTargetFilterQuery("test", query)));
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -363,15 +344,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, null, Boolean.FALSE,
|
||||
new String[0])).as("has number of elements").hasSize(3).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new JpaTargetFilterQuery("test", query)));
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -389,15 +367,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
null, Boolean.FALSE, targTagW.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, "%targ-B%", null, Boolean.FALSE,
|
||||
targTagW.getName())).as("has number of elements").hasSize(99).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new JpaTargetFilterQuery("test", query)));
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -414,15 +389,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
null, Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, "%targ-A%", null, Boolean.FALSE,
|
||||
new String[0])).as("has number of elements").hasSize(99).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new JpaTargetFilterQuery("test", query)));
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -438,14 +410,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null,
|
||||
setA.getId(), Boolean.FALSE, new String[0])))
|
||||
.as("and filter query returns the same result")
|
||||
.hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size())
|
||||
.as("and NAMED filter query returns the same result").hasSize(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent().size());
|
||||
.hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, null, setA.getId(), Boolean.FALSE,
|
||||
new String[0])).as("has number of elements").hasSize(0)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query)));
|
||||
.as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -462,15 +432,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
Boolean.FALSE, targTagY.getName(), targTagW.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, null, null, Boolean.FALSE,
|
||||
targTagY.getName(), targTagW.getName())).as("has number of elements").hasSize(198)
|
||||
.as("and contains the following elements").containsAll(expectedIdNames)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query)));
|
||||
.as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -486,15 +454,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, null, null, Boolean.FALSE,
|
||||
new String[0])).as("has number of elements").hasSize(397).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new JpaTargetFilterQuery("test", query)));
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -512,15 +477,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
null, Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, Boolean.TRUE, null, null, Boolean.FALSE,
|
||||
new String[0])).as("has number of elements").hasSize(198).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new JpaTargetFilterQuery("test", query)));
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -537,15 +499,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
setA.getId(), Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsExactly(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, null, "%targ-A%", setA.getId(),
|
||||
Boolean.FALSE, new String[0])).as("has number of elements").hasSize(1)
|
||||
.as("and contains the following elements").containsExactly(expectedIdName)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query)));
|
||||
.as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -561,15 +521,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
setA.getId(), Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, null, null, setA.getId(), Boolean.FALSE,
|
||||
new String[0])).as("has number of elements").hasSize(3).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new JpaTargetFilterQuery("test", query)));
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -583,14 +540,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-C%",
|
||||
setA.getId(), Boolean.FALSE, targTagX.getName())))
|
||||
.as("and filter query returns the same result")
|
||||
.hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size())
|
||||
.as("and NAMED filter query returns the same result").hasSize(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent().size());
|
||||
.hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, null, "%targ-C%", setA.getId(),
|
||||
Boolean.FALSE, targTagX.getName())).as("has number of elements").hasSize(0)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query)));
|
||||
.as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -604,14 +559,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-A%",
|
||||
setA.getId(), Boolean.FALSE, targTagW.getName())))
|
||||
.as("and filter query returns the same result")
|
||||
.hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size())
|
||||
.as("and NAMED filter query returns the same result").hasSize(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent().size());
|
||||
.hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, null, "%targ-A%", setA.getId(),
|
||||
Boolean.FALSE, targTagW.getName())).as("has number of elements").hasSize(0)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query)));
|
||||
.as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -628,32 +581,25 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
setA.getId(), Boolean.FALSE, targTagW.getName())))
|
||||
.as("and contains the following elements").containsExactly(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, null, "%targ-C%", setA.getId(),
|
||||
Boolean.FALSE, targTagW.getName())).as("has number of elements").hasSize(1)
|
||||
.as("and contains the following elements").containsExactly(expectedIdName)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query)));
|
||||
.as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat1TargetHasNameAndId(final String name, final String controllerId) {
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, null, null, name, null, Boolean.FALSE)
|
||||
.getContent()).as("has number of elements").hasSize(1)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, name,
|
||||
null, Boolean.FALSE)));
|
||||
assertThat(targetManagement.findTargetByFilters(pageReq, null, null, name, null, Boolean.FALSE).getContent())
|
||||
.as("has number of elements").hasSize(1).as("that number is also returned by count query").hasSize(Ints
|
||||
.saturatedCast(targetManagement.countTargetByFilters(null, null, name, null, Boolean.FALSE)));
|
||||
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, null, null, controllerId, null, Boolean.FALSE)
|
||||
.getContent()).as("has number of elements").hasSize(1)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, controllerId,
|
||||
null, Boolean.FALSE)));
|
||||
assertThat(targetManagement.findTargetByFilters(pageReq, null, null, controllerId, null, Boolean.FALSE)
|
||||
.getContent()).as("has number of elements").hasSize(1).as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(
|
||||
targetManagement.countTargetByFilters(null, null, controllerId, null, Boolean.FALSE)));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -669,15 +615,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
Boolean.FALSE, targTagY.getName(), targTagW.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, null, "%targ-B%", null, Boolean.FALSE,
|
||||
targTagY.getName(), targTagW.getName())).as("has number of elements").hasSize(100)
|
||||
.as("and contains the following elements").containsAll(expectedIdNames)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query)));
|
||||
.as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
|
||||
}
|
||||
|
||||
@@ -700,15 +644,12 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
Boolean.FALSE, targTagD.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent());
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, null, null, null, Boolean.FALSE,
|
||||
targTagD.getName())).as("has number of elements").hasSize(200).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new JpaTargetFilterQuery("test", query)));
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, query));
|
||||
|
||||
}
|
||||
|
||||
@@ -842,7 +783,7 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
assignDistributionSet(assignedSet, assignedTargets);
|
||||
|
||||
final List<Target> result = targetManagement
|
||||
.findAllTargetsByTargetFilterQueryAndNonDS(pageReq, assignedSet.getId(), tfq).getContent();
|
||||
.findAllTargetsByTargetFilterQueryAndNonDS(pageReq, assignedSet.getId(), tfq.getQuery()).getContent();
|
||||
assertThat(result).as("count of targets").hasSize(unassignedTargets.size()).as("contains all targets")
|
||||
.containsAll(unassignedTargets);
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetIdName;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.test.matcher.Expect;
|
||||
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
|
||||
@@ -195,7 +194,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final TargetTag targetTag = tagManagement.createTargetTag(entityFactory.tag().create().name("Tag1"));
|
||||
|
||||
final List<Target> assignedTargets = targetManagement.assignTag(assignTarget, targetTag);
|
||||
final List<Target> assignedTargets = targetManagement.assignTag(assignTarget, targetTag.getId());
|
||||
assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4);
|
||||
assignedTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(1));
|
||||
|
||||
@@ -203,16 +202,16 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(assignedTargets.size()).as("Assigned targets are wrong")
|
||||
.isEqualTo(findTargetTag.getAssignedToTargets().size());
|
||||
|
||||
assertThat(targetManagement.unAssignTag("NotExist", findTargetTag)).as("Unassign target does not work")
|
||||
assertThat(targetManagement.unAssignTag("NotExist", findTargetTag.getId())).as("Unassign target does not work")
|
||||
.isNull();
|
||||
|
||||
final Target unAssignTarget = targetManagement.unAssignTag("targetId123", findTargetTag);
|
||||
final Target unAssignTarget = targetManagement.unAssignTag("targetId123", findTargetTag.getId());
|
||||
assertThat(unAssignTarget.getControllerId()).as("Controller id is wrong").isEqualTo("targetId123");
|
||||
assertThat(unAssignTarget.getTags()).as("Tag size is wrong").isEmpty();
|
||||
findTargetTag = tagManagement.findTargetTag("Tag1");
|
||||
assertThat(findTargetTag.getAssignedToTargets()).as("Assigned targets are wrong").hasSize(3);
|
||||
|
||||
final List<Target> unAssignTargets = targetManagement.unAssignAllTargetsByTag(findTargetTag);
|
||||
final List<Target> unAssignTargets = targetManagement.unAssignAllTargetsByTag(findTargetTag.getId());
|
||||
findTargetTag = tagManagement.findTargetTag("Tag1");
|
||||
assertThat(findTargetTag.getAssignedToTargets()).as("Unassigned targets are wrong").isEmpty();
|
||||
assertThat(unAssignTargets).as("Unassigned targets are wrong").hasSize(3);
|
||||
@@ -226,12 +225,12 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
public void deleteAndCreateTargets() {
|
||||
Target target = targetManagement.createTarget(entityFactory.target().create().controllerId("targetId123"));
|
||||
assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(1);
|
||||
targetManagement.deleteTargets(target.getId());
|
||||
targetManagement.deleteTargets(Lists.newArrayList(target.getId()));
|
||||
assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0);
|
||||
|
||||
target = createTargetWithAttributes("4711");
|
||||
assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(1);
|
||||
targetManagement.deleteTargets(target.getId());
|
||||
targetManagement.deleteTargets(Lists.newArrayList(target.getId()));
|
||||
assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0);
|
||||
|
||||
final List<Long> targets = new ArrayList<>();
|
||||
@@ -241,7 +240,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
targets.add(createTargetWithAttributes("" + (i * i + 1000)).getId());
|
||||
}
|
||||
assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(10);
|
||||
targetManagement.deleteTargets(targets.toArray(new Long[targets.size()]));
|
||||
targetManagement.deleteTargets(targets);
|
||||
assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0);
|
||||
}
|
||||
|
||||
@@ -522,7 +521,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
targetManagement.deleteTargets(extra.getId());
|
||||
targetManagement.deleteTarget(extra.getControllerId());
|
||||
|
||||
final int numberToDelete = 50;
|
||||
final Iterable<Target> targetsToDelete = limit(firstList, numberToDelete);
|
||||
@@ -550,11 +549,11 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final int noT1Tags = 3;
|
||||
final List<TargetTag> t1Tags = testdataFactory.createTargetTags(noT1Tags, "tag1");
|
||||
|
||||
t1Tags.forEach(tag -> targetManagement.assignTag(Lists.newArrayList(t1.getControllerId()), tag));
|
||||
t1Tags.forEach(tag -> targetManagement.assignTag(Lists.newArrayList(t1.getControllerId()), tag.getId()));
|
||||
|
||||
final Target t2 = testdataFactory.createTarget("id-2");
|
||||
final List<TargetTag> t2Tags = testdataFactory.createTargetTags(noT2Tags, "tag2");
|
||||
t2Tags.forEach(tag -> targetManagement.assignTag(Lists.newArrayList(t2.getControllerId()), tag));
|
||||
t2Tags.forEach(tag -> targetManagement.assignTag(Lists.newArrayList(t2.getControllerId()), tag.getId()));
|
||||
|
||||
final Target t11 = targetManagement.findTargetByControllerID(t1.getControllerId());
|
||||
assertThat(t11.getTags()).as("Tag size is wrong").hasSize(noT1Tags).containsAll(t1Tags);
|
||||
@@ -587,16 +586,16 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
tagManagement.createTargetTag(entityFactory.tag().create().name("X"));
|
||||
|
||||
// doing different assignments
|
||||
targetManagement.toggleTagAssignment(tagATargets, tagA);
|
||||
targetManagement.toggleTagAssignment(tagBTargets, tagB);
|
||||
targetManagement.toggleTagAssignment(tagCTargets, tagC);
|
||||
toggleTagAssignment(tagATargets, tagA);
|
||||
toggleTagAssignment(tagBTargets, tagB);
|
||||
toggleTagAssignment(tagCTargets, tagC);
|
||||
|
||||
targetManagement.toggleTagAssignment(tagABTargets, tagA);
|
||||
targetManagement.toggleTagAssignment(tagABTargets, tagB);
|
||||
toggleTagAssignment(tagABTargets, tagA);
|
||||
toggleTagAssignment(tagABTargets, tagB);
|
||||
|
||||
targetManagement.toggleTagAssignment(tagABCTargets, tagA);
|
||||
targetManagement.toggleTagAssignment(tagABCTargets, tagB);
|
||||
targetManagement.toggleTagAssignment(tagABCTargets, tagC);
|
||||
toggleTagAssignment(tagABCTargets, tagA);
|
||||
toggleTagAssignment(tagABCTargets, tagB);
|
||||
toggleTagAssignment(tagABCTargets, tagC);
|
||||
|
||||
assertThat(targetManagement.countTargetByFilters(null, null, null, null, Boolean.FALSE, "X"))
|
||||
.as("Target count is wrong").isEqualTo(0);
|
||||
@@ -655,20 +654,20 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<Target> targBCs = testdataFactory.createTargets(7, "target-id-BC", "first description");
|
||||
final List<Target> targABCs = testdataFactory.createTargets(17, "target-id-ABC", "first description");
|
||||
|
||||
targetManagement.toggleTagAssignment(targAs, targTagA);
|
||||
targetManagement.toggleTagAssignment(targABs, targTagA);
|
||||
targetManagement.toggleTagAssignment(targACs, targTagA);
|
||||
targetManagement.toggleTagAssignment(targABCs, targTagA);
|
||||
toggleTagAssignment(targAs, targTagA);
|
||||
toggleTagAssignment(targABs, targTagA);
|
||||
toggleTagAssignment(targACs, targTagA);
|
||||
toggleTagAssignment(targABCs, targTagA);
|
||||
|
||||
targetManagement.toggleTagAssignment(targBs, targTagB);
|
||||
targetManagement.toggleTagAssignment(targABs, targTagB);
|
||||
targetManagement.toggleTagAssignment(targBCs, targTagB);
|
||||
targetManagement.toggleTagAssignment(targABCs, targTagB);
|
||||
toggleTagAssignment(targBs, targTagB);
|
||||
toggleTagAssignment(targABs, targTagB);
|
||||
toggleTagAssignment(targBCs, targTagB);
|
||||
toggleTagAssignment(targABCs, targTagB);
|
||||
|
||||
targetManagement.toggleTagAssignment(targCs, targTagC);
|
||||
targetManagement.toggleTagAssignment(targACs, targTagC);
|
||||
targetManagement.toggleTagAssignment(targBCs, targTagC);
|
||||
targetManagement.toggleTagAssignment(targABCs, targTagC);
|
||||
toggleTagAssignment(targCs, targTagC);
|
||||
toggleTagAssignment(targACs, targTagC);
|
||||
toggleTagAssignment(targBCs, targTagC);
|
||||
toggleTagAssignment(targABCs, targTagC);
|
||||
|
||||
checkTargetHasTags(true, targAs, targTagA);
|
||||
checkTargetHasTags(true, targBs, targTagB);
|
||||
@@ -677,10 +676,10 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
checkTargetHasTags(true, targBCs, targTagB, targTagC);
|
||||
checkTargetHasTags(true, targABCs, targTagA, targTagB, targTagC);
|
||||
|
||||
targetManagement.toggleTagAssignment(targCs, targTagC);
|
||||
targetManagement.toggleTagAssignment(targACs, targTagC);
|
||||
targetManagement.toggleTagAssignment(targBCs, targTagC);
|
||||
targetManagement.toggleTagAssignment(targABCs, targTagC);
|
||||
toggleTagAssignment(targCs, targTagC);
|
||||
toggleTagAssignment(targACs, targTagC);
|
||||
toggleTagAssignment(targBCs, targTagC);
|
||||
toggleTagAssignment(targABCs, targTagC);
|
||||
|
||||
checkTargetHasTags(true, targAs, targTagA); // 0
|
||||
checkTargetHasTags(true, targBs, targTagB);
|
||||
@@ -704,7 +703,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final List<Target> targAs = testdataFactory.createTargets(25, "target-id-A", "first description");
|
||||
|
||||
targetManagement.toggleTagAssignment(targAs, targTagA);
|
||||
toggleTagAssignment(targAs, targTagA);
|
||||
|
||||
assertThat(targetManagement.findTargetsByControllerIDsWithTags(
|
||||
targAs.stream().map(Target::getControllerId).collect(Collectors.toList()))).as("Target count is wrong")
|
||||
@@ -718,21 +717,6 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.as("Tags not correctly assigned").containsOnly(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test the optimized quere for retrieving all ID/name pairs of targets.")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 25) })
|
||||
public void findAllTargetIdNamePaiss() {
|
||||
final List<Target> targAs = testdataFactory.createTargets(25, "target-id-A", "first description");
|
||||
final String[] createdTargetIds = targAs.stream().map(Target::getControllerId)
|
||||
.toArray(size -> new String[size]);
|
||||
|
||||
final List<TargetIdName> findAllTargetIdNames = targetManagement.findAllTargetIds();
|
||||
final List<String> findAllTargetIds = findAllTargetIdNames.stream().map(TargetIdName::getControllerId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat(findAllTargetIds).as("Target list has wrong content").containsOnly(createdTargetIds);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test that NO TAG functionality which gives all targets with no tag assigned.")
|
||||
@ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1),
|
||||
@@ -742,7 +726,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final TargetTag targTagA = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-A-Tag"));
|
||||
final List<Target> targAs = testdataFactory.createTargets(25, "target-id-A", "first description");
|
||||
targetManagement.toggleTagAssignment(targAs, targTagA);
|
||||
toggleTagAssignment(targAs, targTagA);
|
||||
|
||||
testdataFactory.createTargets(25, "target-id-B", "first description");
|
||||
|
||||
@@ -750,7 +734,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<Target> targetsListWithNoTag = targetManagement
|
||||
.findTargetByFilters(pageReq, null, null, null, null, Boolean.TRUE, tagNames).getContent();
|
||||
|
||||
assertThat(50).as("Total targets").isEqualTo(targetManagement.findAllTargetIds().size());
|
||||
assertThat(50L).as("Total targets").isEqualTo(targetManagement.countTargetsAll());
|
||||
assertThat(25).as("Targets with no tag").isEqualTo(targetsListWithNoTag.size());
|
||||
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
|
||||
verifyThatTargetsHaveDistributionSetAssignment(setB, targets.subList(10, 20), targetsCount);
|
||||
|
||||
// Count the number of targets that will be assigned with setA
|
||||
assertThat(targetManagement.countTargetsByTargetFilterQueryAndNonDS(setA.getId(), targetFilterQuery))
|
||||
assertThat(targetManagement.countTargetsByTargetFilterQueryAndNonDS(setA.getId(), targetFilterQuery.getQuery()))
|
||||
.isEqualTo(90);
|
||||
|
||||
// Run the check
|
||||
|
||||
@@ -82,7 +82,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
public void targetDeletedEventIsPublished() throws InterruptedException {
|
||||
final Target createdTarget = testdataFactory.createTarget("12345");
|
||||
|
||||
targetManagement.deleteTargets(createdTarget.getId());
|
||||
targetManagement.deleteTarget("12345");
|
||||
|
||||
final TargetDeletedEvent targetDeletedEvent = eventListener.waitForEvent(TargetDeletedEvent.class, 1,
|
||||
TimeUnit.SECONDS);
|
||||
@@ -106,7 +106,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
public void distributionSetDeletedEventIsPublished() throws InterruptedException {
|
||||
final DistributionSet createDistributionSet = testdataFactory.createDistributionSet();
|
||||
|
||||
distributionSetManagement.deleteDistributionSet(createDistributionSet);
|
||||
distributionSetManagement.deleteDistributionSet(createDistributionSet.getId());
|
||||
|
||||
final DistributionSetDeletedEvent dsDeletedEvent = eventListener.waitForEvent(DistributionSetDeletedEvent.class,
|
||||
1, TimeUnit.SECONDS);
|
||||
|
||||
@@ -105,7 +105,7 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
final SoftwareModuleType type = softwareManagement
|
||||
.createSoftwareModuleType(entityFactory.softwareModuleType().create().name("test").key("test"));
|
||||
|
||||
softwareManagement.deleteSoftwareModuleType(type);
|
||||
softwareManagement.deleteSoftwareModuleType(type.getId());
|
||||
assertThat(entityInterceptor.getEntity()).isNotNull();
|
||||
assertThat(entityInterceptor.getEntity()).isEqualTo(type);
|
||||
}
|
||||
|
||||
@@ -83,9 +83,9 @@ public class RSQLActionFieldsTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) {
|
||||
|
||||
final Slice<Action> findEnitity = deploymentManagement.findActionsByTarget(rsqlParam, target,
|
||||
final Slice<Action> findEnitity = deploymentManagement.findActionsByTarget(rsqlParam, target.getControllerId(),
|
||||
new PageRequest(0, 100));
|
||||
final long countAllEntities = deploymentManagement.countActionsByTarget(rsqlParam, target);
|
||||
final long countAllEntities = deploymentManagement.countActionsByTarget(rsqlParam, target.getControllerId());
|
||||
assertThat(findEnitity).isNotNull();
|
||||
assertThat(countAllEntities).isEqualTo(expectedEntities);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest {
|
||||
tagManagement.createDistributionSetTag(entityFactory.tag().create().name("Tag3"));
|
||||
tagManagement.createDistributionSetTag(entityFactory.tag().create().name("Tag4"));
|
||||
|
||||
distributionSetManagement.assignTag(Arrays.asList(ds.getId(), ds2.getId()), targetTag);
|
||||
distributionSetManagement.assignTag(Arrays.asList(ds.getId(), ds2.getId()), targetTag.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -64,7 +64,8 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
tagManagement.createTargetTag(entityFactory.tag().create().name("Tag3"));
|
||||
tagManagement.createTargetTag(entityFactory.tag().create().name("Tag4"));
|
||||
|
||||
targetManagement.assignTag(Arrays.asList(target.getControllerId(), target2.getControllerId()), targetTag);
|
||||
targetManagement.assignTag(Arrays.asList(target.getControllerId(), target2.getControllerId()),
|
||||
targetTag.getId());
|
||||
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ package org.eclipse.hawkbit.repository.jpa.tenancy;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
@@ -19,6 +21,8 @@ import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
@@ -122,12 +126,12 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
final Target createTargetForTenant = createTargetForTenant(controllerAnotherTenant, anotherTenant);
|
||||
|
||||
// ensure target cannot be deleted by 'mytenant'
|
||||
targetManagement.deleteTargets(createTargetForTenant.getId());
|
||||
targetManagement.deleteTargets(Lists.newArrayList(createTargetForTenant.getId()));
|
||||
Slice<Target> targetsForAnotherTenant = findTargetsForTenant(anotherTenant);
|
||||
assertThat(targetsForAnotherTenant).hasSize(1);
|
||||
|
||||
// ensure another tenant can delete the target
|
||||
deleteTargetsForTenant(anotherTenant, createTargetForTenant.getId());
|
||||
deleteTargetsForTenant(anotherTenant, Lists.newArrayList(createTargetForTenant.getId()));
|
||||
targetsForAnotherTenant = findTargetsForTenant(anotherTenant);
|
||||
assertThat(targetsForAnotherTenant).hasSize(0);
|
||||
}
|
||||
@@ -165,7 +169,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
() -> targetManagement.findTargetsAll(pageReq));
|
||||
}
|
||||
|
||||
private void deleteTargetsForTenant(final String tenant, final Long... targetIds) throws Exception {
|
||||
private void deleteTargetsForTenant(final String tenant, final Collection<Long> targetIds) throws Exception {
|
||||
securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant), () -> {
|
||||
targetManagement.deleteTargets(targetIds);
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user