Remove unlimited collections from the repository API (#496)

* Started to get rid of unlimited collections

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Align API usage.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* fix compile issues.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix tests.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove comments

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Performance optimizations.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove dead code.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Allign method names

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Wait until the action update event is processed

Conflicts:
	hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java

Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>

* Started new tag APIs

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Quotas into central interface. Tag tests added. Event names fixed.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Simplified consumer run for every tenant.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* remove unused fields.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Alligned beans.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Deprecated client methods for old resources.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix new foreach method.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix transaction for foreach.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Extended DS creating to handle larger volumes. Fix on Readme.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fixed simulator bug and cleaned up tests.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix in sorting.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove configuration processor.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix wrong usage of sanitize.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Missing brackets.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix README API compatability.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix misinterpretation of pessimistic locking exceptions.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix stability sentence.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Code cleanup.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fixed page calculation

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-05-09 16:40:49 +02:00
committed by GitHub
parent aca87464bd
commit c18e9f515e
199 changed files with 3502 additions and 1607 deletions

View File

@@ -9,8 +9,8 @@
package org.eclipse.hawkbit.repository;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.validation.constraints.NotNull;
@@ -24,7 +24,6 @@ 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.ActionStatus;
import org.eclipse.hawkbit.repository.model.ActionWithStatusCount;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
@@ -71,6 +70,7 @@ public interface DeploymentManagement {
DistributionSetAssignmentResult assignDistributionSet(@NotNull Long dsID, @NotNull ActionType actionType,
long forcedTimestamp, @NotEmpty Collection<String> controllerIDs);
/**
* method assigns the {@link DistributionSet} to all {@link Target}s by
* their IDs with a specific {@link ActionType} and {@code forcetime}.
@@ -274,22 +274,6 @@ public interface DeploymentManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<ActionStatus> findActionStatusByAction(@NotNull Pageable pageReq, @NotNull Long actionId);
/**
* Retrieves all {@link ActionStatus} inclusive their messages by a specific
* {@link Action}.
*
* @param pageable
* the page request parameter for paging and sorting the result
* @param actionId
* the {@link Action} to retrieve the {@link ActionStatus} from
* @return a page of {@link ActionStatus} by a speciifc {@link Action}
*
* @throws EntityNotFoundException
* if action with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<ActionStatus> findActionStatusByActionWithMessages(@NotNull Pageable pageable, @NotNull Long actionId);
/**
* Retrieves all messages for an {@link ActionStatus}.
*
@@ -303,20 +287,6 @@ public interface DeploymentManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<String> findMessagesByActionStatusId(@NotNull Pageable pageable, @NotNull Long actionStatusId);
/**
* Retrieves all {@link Action}s of a specific target ordered by action ID.
*
* @param controllerId
* the target associated with the actions
* @return a list of actions associated with the given target ordered by
* action ID
*
* @throws EntityNotFoundException
* if target with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<ActionWithStatusCount> findActionsWithStatusCountByTargetOrderByIdDesc(@NotNull String controllerId);
/**
* Get the {@link Action} entity for given actionId with all lazy attributes
* (i.e. distributionSet, target, target.assignedDs).
@@ -331,7 +301,9 @@ public interface DeploymentManagement {
/**
* Retrieves all active {@link Action}s of a specific target ordered by
* action ID.
*
*
* @param pageable
* the page request parameter for paging and sorting the result
* @param controllerId
* the target associated with the actions
* @return a list of actions associated with the given target
@@ -340,12 +312,14 @@ public interface DeploymentManagement {
* if target with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<Action> findActiveActionsByTarget(@NotEmpty String controllerId);
Page<Action> findActiveActionsByTarget(@NotNull Pageable pageable, @NotEmpty String controllerId);
/**
* Retrieves all inactive {@link Action}s of a specific target ordered by
* action ID.
*
* @param pageable
* the page request parameter for paging and sorting the result
* @param controllerId
* the target associated with the actions
* @return a list of actions associated with the given target
@@ -354,7 +328,7 @@ public interface DeploymentManagement {
* if target with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<Action> findInActiveActionsByTarget(@NotEmpty String controllerId);
Page<Action> findInActiveActionsByTarget(@NotNull Pageable pageable, @NotEmpty String controllerId);
/**
* Force cancels given {@link Action} for given {@link Target}. Force

View File

@@ -363,17 +363,6 @@ public interface DistributionSetManagement {
Page<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId,
@NotNull String rsqlParam, @NotNull Pageable pageable);
/**
* Retrieves {@link DistributionSet} List for overview purposes (no
* {@link SoftwareModule}s and {@link DistributionSetTag}s).
*
* @param dist
* List of {@link DistributionSet} IDs to be found
* @return the found {@link DistributionSet}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
List<DistributionSet> findDistributionSetsAll(Collection<Long> dist);
/**
* finds all {@link DistributionSet}s.
*
@@ -420,6 +409,21 @@ public interface DistributionSetManagement {
Page<DistributionSet> findDistributionSetsAll(@NotNull String rsqlParam, @NotNull Pageable pageReq,
Boolean deleted);
/**
* finds all {@link DistributionSet}s.
*
* @param pageReq
* the pagination parameter
* @param deleted
* if TRUE, {@link DistributionSet}s marked as deleted are
* returned. If FALSE, on {@link DistributionSet}s not marked as
* deleted are returned. <code>null</code> if both are to be
* returned
* @return all found {@link DistributionSet}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSet> findDistributionSetsAll(@NotNull Pageable pageReq, Boolean deleted);
/**
* method retrieves all {@link DistributionSet}s from the repository in the
* following order:
@@ -458,6 +462,45 @@ public interface DistributionSetManagement {
Page<DistributionSet> findDistributionSetsByFilters(@NotNull Pageable pageable,
@NotNull DistributionSetFilter distributionSetFilter);
/**
* retrieves {@link DistributionSet}s by filtering on the given parameters.
*
* @param pageable
* page parameter
* @param tagId
* of the tag the DS are assigned to
* @return the page of found {@link DistributionSet}
*
* @throws RSQLParameterUnsupportedFieldException
* if a field in the RSQL string is used but not provided by the
* given {@code fieldNameProvider}
* @throws RSQLParameterSyntaxException
* if the RSQL syntax is wrong
*
* @throws EntityNotFoundException
* of distribution set tag with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSet> findDistributionSetsByTag(@NotNull final Pageable pageable, @NotNull final Long tagId);
/**
* retrieves {@link DistributionSet}s by filtering on the given parameters.
*
* @param pageable
* page parameter
* @param rsqlParam
* rsql query string
* @param tagId
* of the tag the DS are assigned to
* @return the page of found {@link DistributionSet}
*
* @throws EntityNotFoundException
* of distribution set tag with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSet> findDistributionSetsByTag(@NotNull final Pageable pageable, @NotNull String rsqlParam,
@NotNull final Long tagId);
/**
* @param id
* as {@link DistributionSetType#getId()}
@@ -556,20 +599,6 @@ public interface DistributionSetManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection<Long> dsIds, @NotNull String tagName);
/**
* Unassign all {@link DistributionSet} from a given
* {@link DistributionSetTag} .
*
* @param tagId
* to unassign all ds
* @return list of unassigned ds
*
* @throws EntityNotFoundException
* if tag with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
List<DistributionSet> unAssignAllDistributionSetsByTag(@NotNull Long tagId);
/**
* Unassigns a {@link SoftwareModule} form an existing
* {@link DistributionSet}.
@@ -731,6 +760,6 @@ public interface DistributionSetManagement {
* @return the found {@link DistributionSet}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
List<DistributionSet> findDistributionSetAllById(@NotEmpty Collection<Long> ids);
List<DistributionSet> findDistributionSetsById(@NotEmpty Collection<Long> ids);
}

View File

@@ -0,0 +1,39 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
/**
* Central service for defined limits of the repository.
*
*/
public interface QuotaManagement {
/**
* @return Maximum number of {@link ActionStatus} entries that the
* controller can report for an {@link Action}.
*/
int getMaxStatusEntriesPerAction();
/**
* @return maximum number of attributes that the controller can report;
*/
int getMaxAttributeEntriesPerTarget();
/**
* @return maximum number of allowed {@link RolloutGroup}s per
* {@link Rollout}.
*/
int getMaxRolloutGroupsPerRollout();
}

View File

@@ -82,7 +82,7 @@ public interface RolloutGroupManagement {
* Retrieves a page of {@link RolloutGroup}s filtered by a given
* {@link Rollout} and the an rsql filter.
*
* @param rollout
* @param rolloutId
* the rollout to filter the {@link RolloutGroup}s
* @param rsqlParam
* the specification to filter the result set based on attributes
@@ -98,7 +98,7 @@ public interface RolloutGroupManagement {
* if the RSQL syntax is wrong
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<RolloutGroup> findRolloutGroupsAll(@NotNull Long rollout, @NotNull String rsqlParam,
Page<RolloutGroup> findRolloutGroupsAll(@NotNull Long rolloutId, @NotNull String rsqlParam,
@NotNull Pageable pageable);
/**
@@ -114,6 +114,19 @@ public interface RolloutGroupManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<RolloutGroup> findRolloutGroupsByRolloutId(@NotNull Long rolloutId, @NotNull Pageable pageable);
/**
* Retrieves a page of {@link RolloutGroup}s filtered by a given
* {@link Rollout}.
*
* @param rolloutId
* the ID of the rollout to filter the {@link RolloutGroup}s
* @param pageable
* the page request to sort and limit the result
* @return a page of found {@link RolloutGroup}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
long countRolloutGroupsByRolloutId(@NotNull Long rolloutId);
/**
* Get targets of specified rollout group.
*

View File

@@ -334,6 +334,23 @@ public interface SoftwareManagement {
Page<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long moduleId,
@NotNull String rsqlParam, @NotNull Pageable pageable);
/**
* Finds all meta data by the given software module id.
*
* @param pageable
* pagination parameter
*
* @param moduleId
* the software module id to retrieve the meta data from
* @return page with found software module metadata
*
* @throws EntityNotFoundException
* of software module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Pageable pageable,
@NotNull Long moduleId);
/**
* Filter {@link SoftwareModule}s with given
* {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()}
@@ -522,25 +539,4 @@ public interface SoftwareManagement {
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleTypeUpdate update);
/**
* Finds all meta data by the given software module id.
*
* @param moduleId
* the software module id to retrieve the meta data from
*
*
* @throws RSQLParameterUnsupportedFieldException
* if a field in the RSQL string is used but not provided by the
* given {@code fieldNameProvider}
* @throws RSQLParameterSyntaxException
* if the RSQL syntax is wrong
* @return result of all meta data entries for a given software module id.
*
* @throws EntityNotFoundException
* of software module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
List<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long moduleId);
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository;
import java.util.List;
import java.util.function.Consumer;
import javax.validation.constraints.NotNull;
@@ -18,6 +18,8 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.model.TenantMetaData;
import org.eclipse.hawkbit.repository.report.model.SystemUsageReport;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
/**
@@ -44,10 +46,22 @@ public interface SystemManagement {
/**
*
* @param pageable
* for paging information
* @return list of all tenant names in the system.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
List<String> findTenants();
Page<String> findTenants(@NotNull Pageable pageable);
/**
* Runs consumer for each teant as
* {@link TenantAware#runAsTenant(String, org.eclipse.hawkbit.tenancy.TenantAware.TenantRunner)}
*
* @param consumer
* to run as teanant
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
void forEachTenant(Consumer<String> consumer);
/**
* Calculated system usage statistics, both overall for the entire system

View File

@@ -122,13 +122,6 @@ public interface TagManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
void deleteTargetTag(@NotEmpty String targetTagName);
/**
*
* @return all {@link DistributionSetTag}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
List<DistributionSetTag> findAllDistributionSetTags();
/**
* returns all {@link DistributionSetTag}s.
*
@@ -241,6 +234,22 @@ public interface TagManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Optional<TargetTag> findTargetTagById(@NotNull Long id);
/**
* Finds all {@link TargetTag} assigned to given {@link Target}.
*
* @param pageable
* information for page size, offset and sort order.
*
* @param setId
* of the {@link DistributionSet}
* @return page of the found {@link TargetTag}s
*
* @throws EntityNotFoundException
* if {@link DistributionSet} with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSetTag> findDistributionSetTagsByDistributionSet(@NotNull Pageable pageable, @NotNull Long setId);
/**
* Updates an existing {@link DistributionSetTag}.
*

View File

@@ -339,7 +339,7 @@ public interface TargetManagement {
* @return List of found{@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<Target> findTargetByControllerID(@NotEmpty Collection<String> controllerIDs);
List<Target> findTargetsByControllerID(@NotEmpty Collection<String> controllerIDs);
/**
* Find a {@link Target} based a given ID.
@@ -533,13 +533,41 @@ public interface TargetManagement {
/**
* Find targets by tag name.
*
* @param tagName
* tag name
*
* @param pageable
* the page request parameter for paging and sorting the result
* @param tagId
* tag ID
* @return list of matching targets
*
* @throws EntityNotFoundException
* if target tag with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<Target> findTargetsByTag(@NotEmpty String tagName);
Page<Target> findTargetsByTag(@NotNull Pageable pageable, @NotNull Long tagId);
/**
* Find targets by tag name.
*
* @param pageable
* the page request parameter for paging and sorting the result
* @param tagId
* tag ID
* @param rsqlParam
* in RSQL notation
*
* @return list of matching targets
*
* @throws EntityNotFoundException
* if target tag with given ID does not exist
* @throws RSQLParameterUnsupportedFieldException
* if a field in the RSQL string is used but not provided by the
* given {@code fieldNameProvider}
* @throws RSQLParameterSyntaxException
* if the RSQL syntax is wrong
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<Target> findTargetsByTag(@NotNull Pageable pageable, @NotNull String rsqlParam, @NotNull Long tagId);
/**
* Toggles {@link TargetTag} assignment to given {@link Target}s by means
@@ -559,19 +587,6 @@ public interface TargetManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
TargetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection<String> controllerIds, @NotEmpty String tagName);
/**
* Un-assign all {@link Target} from a given {@link TargetTag} .
*
* @param targetTagId
* to un-assign all targets
* @return list of unassigned targets
*
* @throws EntityNotFoundException
* if TAG with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
List<Target> unAssignAllTargetsByTag(@NotNull Long targetTagId);
/**
* Un-assign a {@link TargetTag} assignment to given {@link Target}.
*
@@ -623,7 +638,7 @@ public interface TargetManagement {
* @return the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<Target> findTargetAllById(@NotNull Collection<Long> ids);
List<Target> findTargetsById(@NotNull Collection<Long> ids);
/**
* Get controller attributes of given {@link Target}.

View File

@@ -14,14 +14,14 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTag;
* Defines the remote event for update a {@link DistributionSetTag}.
*
*/
public class DistributionSetTagUpdateEvent extends RemoteEntityEvent<DistributionSetTag> {
public class DistributionSetTagUpdatedEvent extends RemoteEntityEvent<DistributionSetTag> {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public DistributionSetTagUpdateEvent() {
public DistributionSetTagUpdatedEvent() {
// for serialization libs like jackson
}
@@ -33,7 +33,7 @@ public class DistributionSetTagUpdateEvent extends RemoteEntityEvent<Distributio
* @param applicationId
* the applicationID
*/
public DistributionSetTagUpdateEvent(final DistributionSetTag tag, final String applicationId) {
public DistributionSetTagUpdatedEvent(final DistributionSetTag tag, final String applicationId) {
super(tag, applicationId);
}
}

View File

@@ -14,14 +14,14 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
* Defines the remote event for updating a {@link DistributionSet}.
*
*/
public class DistributionSetUpdateEvent extends RemoteEntityEvent<DistributionSet> {
public class DistributionSetUpdatedEvent extends RemoteEntityEvent<DistributionSet> {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public DistributionSetUpdateEvent() {
public DistributionSetUpdatedEvent() {
// for serialization libs like jackson
}
@@ -33,7 +33,7 @@ public class DistributionSetUpdateEvent extends RemoteEntityEvent<DistributionSe
* @param applicationId
* the origin application id
*/
public DistributionSetUpdateEvent(final DistributionSet ds, final String applicationId) {
public DistributionSetUpdatedEvent(final DistributionSet ds, final String applicationId) {
super(ds, applicationId);
}
}

View File

@@ -14,14 +14,14 @@ import org.eclipse.hawkbit.repository.model.TargetTag;
* Defines the remote event for updating a {@link TargetTag}.
*
*/
public class TargetTagUpdateEvent extends RemoteEntityEvent<TargetTag> {
public class TargetTagUpdatedEvent extends RemoteEntityEvent<TargetTag> {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public TargetTagUpdateEvent() {
public TargetTagUpdatedEvent() {
// for serialization libs like jackson
}
@@ -33,7 +33,7 @@ public class TargetTagUpdateEvent extends RemoteEntityEvent<TargetTag> {
* @param applicationId
* the origin application id
*/
public TargetTagUpdateEvent(final TargetTag tag, final String applicationId) {
public TargetTagUpdatedEvent(final TargetTag tag, final String applicationId) {
super(tag, applicationId);
}
}

View File

@@ -8,7 +8,6 @@
*/
package org.eclipse.hawkbit.repository.model;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
@@ -45,11 +44,6 @@ public interface Action extends TenantAwareBaseEntity {
*/
ActionType getActionType();
/**
* @return list of {@link ActionStatus} entries.
*/
List<ActionStatus> getActionStatus();
/**
* @return {@link Target} of this {@link Action}.
*/

View File

@@ -8,7 +8,6 @@
*/
package org.eclipse.hawkbit.repository.model;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.eclipse.hawkbit.repository.model.Action.Status;
@@ -28,12 +27,6 @@ public interface ActionStatus extends TenantAwareBaseEntity {
*/
Long getOccurredAt();
/**
* @return immutable list of message entries that in the
* {@link ActionStatus}.
*/
List<String> getMessages();
/**
* @return {@link Action} this {@link ActionStatus} belongs to.
*/

View File

@@ -1,48 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.model;
/**
* View for querying {@link Action} include the count of the action's
* {@link ActionStatus} entries.
*
*/
public interface ActionWithStatusCount {
/**
* @return {@link Action}
*/
Action getAction();
/**
* @return {@link DistributionSet} ID.
*/
Long getDsId();
/**
* @return {@link DistributionSet} name.
*/
String getDsName();
/**
* @return {@link DistributionSet} version.
*/
String getDsVersion();
/**
* @return number of {@link ActionStatus} entries
*/
Long getActionStatusCount();
/**
* @return name of the {@link Rollout}.
*/
String getRolloutName();
}

View File

@@ -24,11 +24,6 @@ import java.util.Set;
*/
public interface DistributionSet extends NamedVersionedEntity {
/**
* @return immutable {@link Set} of assigned {@link DistributionSetTag}s.
*/
Set<DistributionSetTag> getTags();
/**
* @return <code>true</code> if the set is deleted and only kept for history
* purposes.

View File

@@ -69,7 +69,7 @@ public class DistributionSetAssignmentResult extends AssignmentResult<Target> {
return Collections.emptyList();
}
return targetManagement.findTargetByControllerID(assignedTargets);
return targetManagement.findTargetsByControllerID(assignedTargets);
}
}

View File

@@ -15,11 +15,7 @@ import java.util.Collection;
*/
public final class DistributionSetFilter {
/**
*
* Distribution set filter builder.
*
*
*
*/
public static class DistributionSetFilterBuilder {
private Boolean isDeleted;
@@ -81,6 +77,7 @@ public final class DistributionSetFilter {
}
}
private final Boolean isDeleted;
private final Boolean isComplete;
private final DistributionSetType type;

View File

@@ -8,18 +8,10 @@
*/
package org.eclipse.hawkbit.repository.model;
import java.util.List;
/**
* {@link Tag} of a {@link DistributionSet}.
*
*/
public interface DistributionSetTag extends Tag {
/**
* @return immutable {@link List} of {@link DistributionSet}s this
* {@link Tag} is assigned to.
*/
List<DistributionSet> getAssignedToDistributionSet();
}

View File

@@ -8,7 +8,6 @@
*/
package org.eclipse.hawkbit.repository.model;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
@@ -37,11 +36,6 @@ public interface Rollout extends NamedEntity {
*/
DistributionSet getDistributionSet();
/**
* @return immutable list of deployment groups of the rollout.
*/
List<RolloutGroup> getRolloutGroups();
/**
* @return rsql query that identifies the targets that are part of this
* rollout.

View File

@@ -8,17 +8,10 @@
*/
package org.eclipse.hawkbit.repository.model;
import java.util.List;
/**
* Target tag element.
*
*/
public interface TargetTag extends Tag {
/**
* @return immutable {@link List} of targets assigned to this {@link Tag}.
*/
List<Target> getAssignedToTargets();
}

View File

@@ -26,8 +26,8 @@ import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent;
@@ -35,7 +35,7 @@ import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedE
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
/**
@@ -66,7 +66,7 @@ public class EventType {
// target tag
TYPES.put(6, TargetTagCreatedEvent.class);
TYPES.put(7, TargetTagUpdateEvent.class);
TYPES.put(7, TargetTagUpdatedEvent.class);
TYPES.put(8, TargetTagDeletedEvent.class);
// action
@@ -75,12 +75,12 @@ public class EventType {
// distribution set
TYPES.put(11, DistributionSetCreatedEvent.class);
TYPES.put(12, DistributionSetUpdateEvent.class);
TYPES.put(12, DistributionSetUpdatedEvent.class);
TYPES.put(13, DistributionSetDeletedEvent.class);
// distribution set tag
TYPES.put(14, DistributionSetTagCreatedEvent.class);
TYPES.put(15, DistributionSetTagUpdateEvent.class);
TYPES.put(15, DistributionSetTagUpdatedEvent.class);
TYPES.put(16, DistributionSetTagDeletedEvent.class);
// rollout

View File

@@ -0,0 +1,46 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository;
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* {@link QuotaManagement} implementation based on spring boot
* {@link ConfigurationProperties}.
*
*/
public class PropertiesQuotaManagement implements QuotaManagement {
private final HawkbitSecurityProperties securityProperties;
/**
* @param securityProperties
* that holds the quota definitions
*/
public PropertiesQuotaManagement(final HawkbitSecurityProperties securityProperties) {
this.securityProperties = securityProperties;
}
@Override
public int getMaxStatusEntriesPerAction() {
return securityProperties.getDos().getMaxStatusEntriesPerAction();
}
@Override
public int getMaxAttributeEntriesPerTarget() {
return securityProperties.getDos().getMaxAttributeEntriesPerTarget();
}
@Override
public int getMaxRolloutGroupsPerRollout() {
return securityProperties.getDos().getMaxRolloutGroupsPerRollout();
}
}

View File

@@ -23,6 +23,7 @@ import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
* A collection of static helper methods for the {@link RolloutManagement}
*/
public final class RolloutHelper {
private RolloutHelper() {
}
@@ -68,12 +69,14 @@ public final class RolloutHelper {
*
* @param amountGroup
* amount of groups
* @param quotaManagement
* to retrieve maximum number of groups allowed
*/
public static void verifyRolloutGroupParameter(final int amountGroup) {
public static void verifyRolloutGroupParameter(final int amountGroup, final QuotaManagement quotaManagement) {
if (amountGroup <= 0) {
throw new ConstraintViolationException("the amountGroup must be greater than zero");
} else if (amountGroup > 500) {
throw new ConstraintViolationException("the amountGroup must not be greater than 500");
throw new ConstraintViolationException("the amount of groups cannot be lower than zero");
} else if (amountGroup > quotaManagement.getMaxRolloutGroupsPerRollout()) {
throw new ConstraintViolationException("the amount of groups cannot be greater than 500");
}
}
@@ -144,32 +147,12 @@ public final class RolloutHelper {
* the group to add
* @return list of groups
*/
public static List<Long> getGroupsByStatusIncludingGroup(final Rollout rollout,
public static List<Long> getGroupsByStatusIncludingGroup(final List<RolloutGroup> groups,
final RolloutGroup.RolloutGroupStatus status, final RolloutGroup group) {
return rollout.getRolloutGroups().stream()
.filter(innerGroup -> innerGroup.getStatus().equals(status) || innerGroup.equals(group))
return groups.stream().filter(innerGroup -> innerGroup.getStatus().equals(status) || innerGroup.equals(group))
.map(RolloutGroup::getId).collect(Collectors.toList());
}
/**
* Returns the groups of a rollout by their Ids order
*
* @param rollout
* the rollout
* @return ordered list of groups
*/
public static List<RolloutGroup> getOrderedGroups(final Rollout rollout) {
return rollout.getRolloutGroups().stream().sorted((group1, group2) -> {
if (group1.getId() < group2.getId()) {
return -1;
}
if (group1.getId() > group2.getId()) {
return 1;
}
return 0;
}).collect(Collectors.toList());
}
/**
* Creates an RSQL expression that matches all targets in the provided
* groups. Links all target filter queries with OR.

View File

@@ -8,10 +8,10 @@
*/
package org.eclipse.hawkbit.repository.builder;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
import java.util.Optional;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
/**
* Create and update builder DTO.
*

View File

@@ -172,7 +172,8 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
*/
@EntityGraph(value = "Action.ds", type = EntityGraphType.LOAD)
@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);
Page<Action> findByActiveAndTarget(Pageable pageable, @Param("target") String target,
@Param("active") boolean active);
/**
* Switches the status of actions from one specific status into another,

View File

@@ -17,11 +17,12 @@ import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
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.Rollout;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
@@ -38,13 +39,29 @@ public interface DistributionSetRepository
/**
* Finds {@link DistributionSet}s by assigned {@link Tag}.
*
* @param pageable
* paging and sorting information
*
* @param tag
* @param tagId
* to be found
* @return list of found {@link DistributionSet}s
*/
@Query(value = "Select Distinct ds from JpaDistributionSet ds join ds.tags dst where dst = :tag")
List<JpaDistributionSet> findByTag(@Param("tag") final DistributionSetTag tag);
@Query(value = "Select Distinct ds from JpaDistributionSet ds join ds.tags dst where dst.id = :tag")
Page<JpaDistributionSet> findByTag(Pageable pageable, @Param("tag") final Long tagId);
/**
* Finds {@link DistributionSet}s by assigned {@link Tag}.
*
* @param pageable
* paging and sorting information
*
* @param tagId
* to be found
* @return page of found {@link DistributionSet}s
*/
@Query(value = "Select Distinct ds from JpaDistributionSet ds join ds.tags dst where dst.id = :tagId")
Page<JpaDistributionSet> findByTagId(Pageable pageable, @Param("tagId") final Long tagId);
/**
* deletes the {@link DistributionSet}s with the given IDs.
@@ -147,9 +164,9 @@ public interface DistributionSetRepository
/**
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
* reasons (this is a "delete everything" query after all) we add the tenant manually to
* query even if this will by done by {@link EntityManager} anyhow. The DB
* should take care of optimizing this away.
* reasons (this is a "delete everything" query after all) we add the tenant
* manually to query even if this will by done by {@link EntityManager}
* anyhow. The DB should take care of optimizing this away.
*
* @param tenant
* to delete data from

View File

@@ -51,6 +51,16 @@ public interface DistributionSetTagRepository
*/
Optional<DistributionSetTag> findByNameEquals(final String tagName);
/**
* Checks if tag with given name exists.
*
* @param tagName
* to check for
* @return <code>true</code> is tag with given name exists
*/
@Query("SELECT CASE WHEN COUNT(t)>0 THEN 'true' ELSE 'false' END FROM JpaDistributionSetTag t WHERE t.name=:tagName")
boolean existsByName(@Param("tagName") String tagName);
/**
* Returns all instances of the type.
*

View File

@@ -20,6 +20,7 @@ import javax.persistence.criteria.Root;
import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.RepositoryConstants;
import org.eclipse.hawkbit.repository.RepositoryProperties;
import org.eclipse.hawkbit.repository.TargetManagement;
@@ -47,7 +48,6 @@ import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
@@ -92,7 +92,7 @@ public class JpaControllerManagement implements ControllerManagement {
private ActionStatusRepository actionStatusRepository;
@Autowired
private HawkbitSecurityProperties securityProperties;
private QuotaManagement quotaManagement;
@Autowired
private RepositoryProperties repositoryProperties;
@@ -313,15 +313,14 @@ public class JpaControllerManagement implements ControllerManagement {
private Action handleAddUpdateActionStatus(final JpaActionStatus actionStatus, final JpaAction action) {
LOG.debug("addUpdateActionStatus for action {}", action.getId());
JpaTarget target = (JpaTarget) action.getTarget();
switch (actionStatus.getStatus()) {
case ERROR:
target = DeploymentHelper.updateTargetInfo(target, TargetUpdateStatus.ERROR, false);
final JpaTarget target = DeploymentHelper.updateTargetInfo((JpaTarget) action.getTarget(),
TargetUpdateStatus.ERROR, false);
handleErrorOnAction(action, target);
break;
case FINISHED:
handleFinishedAndStoreInTargetStatus(target, action);
handleFinishedAndStoreInTargetStatus(action);
break;
default:
// information status entry - check for a potential DOS attack
@@ -332,7 +331,7 @@ public class JpaControllerManagement implements ControllerManagement {
actionStatus.setAction(action);
actionStatusRepository.save(actionStatus);
LOG.debug("addUpdateActionStatus {} for target {} is finished.", action, target.getId());
LOG.debug("addUpdateActionStatus for action {} isfinished.", action.getId());
return actionRepository.save(action);
}
@@ -346,21 +345,21 @@ public class JpaControllerManagement implements ControllerManagement {
}
private void checkForToManyStatusEntries(final JpaAction action) {
if (securityProperties.getDos().getMaxStatusEntriesPerAction() > 0) {
if (quotaManagement.getMaxStatusEntriesPerAction() > 0) {
final Long statusCount = actionStatusRepository.countByAction(action);
if (statusCount >= securityProperties.getDos().getMaxStatusEntriesPerAction()) {
if (statusCount >= quotaManagement.getMaxStatusEntriesPerAction()) {
LOG_DOS.error(
"Potential denial of service (DOS) attack identfied. More status entries in the system than permitted ({})!",
securityProperties.getDos().getMaxStatusEntriesPerAction());
throw new TooManyStatusEntriesException(
String.valueOf(securityProperties.getDos().getMaxStatusEntriesPerAction()));
quotaManagement.getMaxStatusEntriesPerAction());
throw new TooManyStatusEntriesException(String.valueOf(quotaManagement.getMaxStatusEntriesPerAction()));
}
}
}
private void handleFinishedAndStoreInTargetStatus(final JpaTarget target, final JpaAction action) {
private void handleFinishedAndStoreInTargetStatus(final JpaAction action) {
final JpaTarget target = (JpaTarget) action.getTarget();
action.setActive(false);
action.setStatus(Status.FINISHED);
final JpaDistributionSet ds = (JpaDistributionSet) entityManager.merge(action.getDistributionSet());
@@ -388,11 +387,11 @@ public class JpaControllerManagement implements ControllerManagement {
target.getControllerAttributes().putAll(data);
if (target.getControllerAttributes().size() > securityProperties.getDos().getMaxAttributeEntriesPerTarget()) {
if (target.getControllerAttributes().size() > quotaManagement.getMaxAttributeEntriesPerTarget()) {
LOG_DOS.info("Target tries to insert more than the allowed number of entries ({}). DOS attack anticipated!",
securityProperties.getDos().getMaxAttributeEntriesPerTarget());
quotaManagement.getMaxAttributeEntriesPerTarget());
throw new ToManyAttributeEntriesException(
String.valueOf(securityProperties.getDos().getMaxAttributeEntriesPerTarget()));
String.valueOf(quotaManagement.getMaxAttributeEntriesPerTarget()));
}
target.setRequestControllerAttributes(false);

View File

@@ -21,7 +21,6 @@ import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.ListJoin;
import javax.persistence.criteria.Root;
@@ -43,13 +42,10 @@ 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.JpaActionWithStatusCount;
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.JpaRollout;
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.JpaTarget_;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
@@ -58,7 +54,6 @@ 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.ActionStatus;
import org.eclipse.hawkbit.repository.model.ActionWithStatusCount;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
@@ -538,31 +533,6 @@ public class JpaDeploymentManagement implements DeploymentManagement {
return actionRepository.findByTargetControllerId(pageable, controllerId);
}
@Override
public List<ActionWithStatusCount> findActionsWithStatusCountByTargetOrderByIdDesc(final String controllerId) {
throwExceptionIfTargetDoesNotExist(controllerId);
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<JpaActionWithStatusCount> query = cb.createQuery(JpaActionWithStatusCount.class);
final Root<JpaAction> actionRoot = query.from(JpaAction.class);
final ListJoin<JpaAction, JpaActionStatus> actionStatusJoin = actionRoot.join(JpaAction_.actionStatus,
JoinType.LEFT);
final Join<JpaAction, JpaDistributionSet> actionDsJoin = actionRoot.join(JpaAction_.distributionSet);
final Join<JpaAction, JpaRollout> actionRolloutJoin = actionRoot.join(JpaAction_.rollout, JoinType.LEFT);
final CriteriaQuery<JpaActionWithStatusCount> multiselect = query.distinct(true).multiselect(
actionRoot.get(JpaAction_.id), actionRoot.get(JpaAction_.actionType), actionRoot.get(JpaAction_.active),
actionRoot.get(JpaAction_.forcedTime), actionRoot.get(JpaAction_.status),
actionRoot.get(JpaAction_.createdAt), actionRoot.get(JpaAction_.lastModifiedAt),
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).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 String controllerId,
final Pageable pageable) {
@@ -584,17 +554,17 @@ public class JpaDeploymentManagement implements DeploymentManagement {
}
@Override
public List<Action> findActiveActionsByTarget(final String controllerId) {
public Page<Action> findActiveActionsByTarget(final Pageable pageable, final String controllerId) {
throwExceptionIfTargetDoesNotExist(controllerId);
return actionRepository.findByActiveAndTarget(controllerId, true);
return actionRepository.findByActiveAndTarget(pageable, controllerId, true);
}
@Override
public List<Action> findInActiveActionsByTarget(final String controllerId) {
public Page<Action> findInActiveActionsByTarget(final Pageable pageable, final String controllerId) {
throwExceptionIfTargetDoesNotExist(controllerId);
return actionRepository.findByActiveAndTarget(controllerId, false);
return actionRepository.findByActiveAndTarget(pageable, controllerId, false);
}
@Override
@@ -645,15 +615,6 @@ public class JpaDeploymentManagement implements DeploymentManagement {
return actionStatusRepository.findByActionId(pageReq, actionId);
}
@Override
public Page<ActionStatus> findActionStatusByActionWithMessages(final Pageable pageReq, final Long actionId) {
if (!actionRepository.exists(actionId)) {
throw new EntityNotFoundException(Action.class, actionId);
}
return actionStatusRepository.getByActionId(pageReq, actionId);
}
@Override
public Page<String> findMessagesByActionStatusId(final Pageable pageable, final Long actionStatusId) {
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();

View File

@@ -125,6 +125,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Autowired
private SoftwareModuleTypeRepository softwareModuleTypeRepository;
@Autowired
private DistributionSetTagRepository distributionSetTagRepository;
@Override
public Optional<DistributionSet> findDistributionSetByIdWithDetails(final Long distid) {
return Optional.ofNullable(distributionSetRepository.findOne(DistributionSetSpecification.byId(distid)));
@@ -235,7 +238,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override
@Transactional
public void deleteDistributionSet(final Collection<Long> distributionSetIDs) {
final List<DistributionSet> setsFound = findDistributionSetAllById(distributionSetIDs);
final List<DistributionSet> setsFound = findDistributionSetsById(distributionSetIDs);
if (setsFound.size() < distributionSetIDs.size()) {
throw new EntityNotFoundException(DistributionSet.class, distributionSetIDs,
@@ -485,6 +488,17 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq);
}
@Override
public Page<DistributionSet> findDistributionSetsAll(final Pageable pageReq, final Boolean deleted) {
final List<Specification<JpaDistributionSet>> specList = new ArrayList<>(1);
if (deleted != null) {
specList.add(DistributionSetSpecification.isDeleted(deleted));
}
return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq);
}
@Override
public Page<DistributionSet> findDistributionSetsAllOrderedByLinkTarget(final Pageable pageable,
final DistributionSetFilterBuilder distributionSetFilterBuilder, final String assignedOrInstalled) {
@@ -536,12 +550,6 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public List<DistributionSet> findDistributionSetsAll(final Collection<Long> dist) {
return Collections
.unmodifiableList(distributionSetRepository.findAll(DistributionSetSpecification.byIds(dist)));
}
@Override
public Long countDistributionSetsAll() {
final Specification<JpaDistributionSet> spec = DistributionSetSpecification.isDeleted(Boolean.FALSE);
@@ -827,20 +835,6 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
.unmodifiableList(allDs.stream().map(distributionSetRepository::save).collect(Collectors.toList()));
}
@Override
@Transactional
public List<DistributionSet> unAssignAllDistributionSetsByTag(final Long dsTagId) {
final DistributionSetTag distributionSetTag = tagManagement.findDistributionSetTagById(dsTagId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId));
@SuppressWarnings({ "unchecked", "rawtypes" })
final Collection<JpaDistributionSet> distributionSets = (Collection) distributionSetTag
.getAssignedToDistributionSet();
return Collections.unmodifiableList(unAssignTag(distributionSets, distributionSetTag));
}
@Override
@Transactional
public DistributionSet unAssignTag(final Long dsId, final Long dsTagId) {
@@ -894,8 +888,36 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public List<DistributionSet> findDistributionSetAllById(final Collection<Long> ids) {
public List<DistributionSet> findDistributionSetsById(final Collection<Long> ids) {
return Collections.unmodifiableList(distributionSetRepository.findAll(ids));
}
@Override
public Page<DistributionSet> findDistributionSetsByTag(final Pageable pageable, final Long tagId) {
throwEntityNotFoundExceptionIfDsTagDoesNotExist(tagId);
return convertDsPage(distributionSetRepository.findByTag(pageable, tagId), pageable);
}
private void throwEntityNotFoundExceptionIfDsTagDoesNotExist(final Long tagId) {
if (!distributionSetTagRepository.exists(tagId)) {
throw new EntityNotFoundException(DistributionSetTag.class, tagId);
}
}
@Override
public Page<DistributionSet> findDistributionSetsByTag(final Pageable pageable, final String rsqlParam,
final Long tagId) {
throwEntityNotFoundExceptionIfDsTagDoesNotExist(tagId);
final Specification<JpaDistributionSet> spec = RSQLUtility.parse(rsqlParam, DistributionSetFields.class,
virtualPropertyReplacer);
return convertDsPage(distributionSetRepository.findAll((Specification<JpaDistributionSet>) (root, query,
cb) -> cb.and(DistributionSetSpecification.hasTag(tagId).toPredicate(root, query, cb),
spec.toPredicate(root, query, cb)),
pageable), pageable);
}
}

View File

@@ -86,6 +86,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
@Override
public Page<RolloutGroup> findRolloutGroupsByRolloutId(final Long rolloutId, final Pageable pageable) {
throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId);
return convertPage(rolloutGroupRepository.findByRolloutId(rolloutId, pageable), pageable);
}
@@ -100,6 +102,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
@Override
public Page<RolloutGroup> findRolloutGroupsAll(final Long rolloutId, final String rsqlParam,
final Pageable pageable) {
throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId);
final Specification<JpaRolloutGroup> specification = RSQLUtility.parse(rsqlParam, RolloutGroupFields.class,
virtualPropertyReplacer);
@@ -115,11 +118,15 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
pageable);
}
@Override
public Page<RolloutGroup> findAllRolloutGroupsWithDetailedStatus(final Long rolloutId, final Pageable pageable) {
private void throwEntityNotFoundExceptionIfRolloutDoesNotExist(final Long rolloutId) {
if (!rolloutRepository.exists(rolloutId)) {
throw new EntityNotFoundException(Rollout.class, rolloutId);
}
}
@Override
public Page<RolloutGroup> findAllRolloutGroupsWithDetailedStatus(final Long rolloutId, final Pageable pageable) {
throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId);
final Page<JpaRolloutGroup> rolloutGroups = rolloutGroupRepository.findByRolloutId(rolloutId, pageable);
final List<Long> rolloutGroupIds = rolloutGroups.getContent().stream().map(RolloutGroup::getId)
@@ -173,6 +180,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
public Page<Target> findRolloutGroupTargets(final Long rolloutGroupId, final String rsqlParam,
final Pageable pageable) {
throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId);
final Specification<JpaTarget> rsqlSpecification = RSQLUtility.parse(rsqlParam, TargetFields.class,
virtualPropertyReplacer);
@@ -253,4 +262,11 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
}
}
@Override
public long countRolloutGroupsByRolloutId(final Long rolloutId) {
throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId);
return rolloutGroupRepository.countByRolloutId(rolloutId);
}
}

View File

@@ -24,6 +24,7 @@ import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.repository.AbstractRolloutManagement;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.RolloutFields;
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
import org.eclipse.hawkbit.repository.RolloutHelper;
@@ -77,6 +78,8 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.integration.support.locks.LockRegistry;
import org.springframework.scheduling.annotation.Async;
@@ -129,6 +132,9 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
@Autowired
private EntityManager entityManager;
@Autowired
private QuotaManagement quotaManagement;
JpaRolloutManagement(final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
final RolloutGroupManagement rolloutGroupManagement,
final DistributionSetManagement distributionSetManagement, final ApplicationContext context,
@@ -175,7 +181,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
@Transactional
public Rollout createRollout(final RolloutCreate rollout, final int amountGroup,
final RolloutGroupConditions conditions) {
RolloutHelper.verifyRolloutGroupParameter(amountGroup);
RolloutHelper.verifyRolloutGroupParameter(amountGroup, quotaManagement);
final JpaRollout savedRollout = createRollout((JpaRollout) rollout.build());
return createRolloutGroups(amountGroup, conditions, savedRollout);
}
@@ -184,7 +190,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
@Transactional
public Rollout createRollout(final RolloutCreate rollout, final List<RolloutGroupCreate> groups,
final RolloutGroupConditions conditions) {
RolloutHelper.verifyRolloutGroupParameter(groups.size());
RolloutHelper.verifyRolloutGroupParameter(groups.size(), quotaManagement);
final JpaRollout savedRollout = createRollout((JpaRollout) rollout.build());
return createRolloutGroups(groups, conditions, savedRollout);
}
@@ -297,7 +303,10 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
private void handleCreateRollout(final JpaRollout rollout) {
LOGGER.debug("handleCreateRollout called for rollout {}", rollout.getId());
final List<RolloutGroup> rolloutGroups = RolloutHelper.getOrderedGroups(rollout);
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findRolloutGroupsByRolloutId(rollout.getId(),
new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout(), new Sort(Direction.ASC, "id")))
.getContent();
int readyGroups = 0;
int totalTargets = 0;
for (final RolloutGroup group : rolloutGroups) {
@@ -325,7 +334,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
}
}
private RolloutGroup fillRolloutGroupWithTargets(final Rollout rollout, final RolloutGroup group1) {
private RolloutGroup fillRolloutGroupWithTargets(final JpaRollout rollout, final RolloutGroup group1) {
RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.CREATING);
final JpaRolloutGroup group = (JpaRolloutGroup) group1;
@@ -338,8 +347,8 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
groupTargetFilter = baseFilter + ";" + group.getTargetFilterQuery();
}
final List<Long> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout, RolloutGroupStatus.READY,
group);
final List<Long> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout.getRolloutGroups(),
RolloutGroupStatus.READY, group);
final long targetsInGroupFilter = runInNewTransaction("countAllTargetsByTargetFilterQueryAndNotInRolloutGroups",
count -> targetManagement.countAllTargetsByTargetFilterQueryAndNotInRolloutGroups(readyGroups,
@@ -376,12 +385,12 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
}
}
private Long assignTargetsToGroupInNewTransaction(final Rollout rollout, final RolloutGroup group,
private Long assignTargetsToGroupInNewTransaction(final JpaRollout rollout, final RolloutGroup group,
final String targetFilter, final long limit) {
return runInNewTransaction("assignTargetsToRolloutGroup", status -> {
final PageRequest pageRequest = new PageRequest(0, Math.toIntExact(limit));
final List<Long> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout,
final List<Long> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout.getRolloutGroups(),
RolloutGroupStatus.READY, group);
final Page<Target> targets = targetManagement
.findAllTargetsByTargetFilterQueryAndNotInRolloutGroups(pageRequest, readyGroups, targetFilter);

View File

@@ -622,7 +622,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
return convertSmMdPage(
softwareModuleMetadataRepository
.findAll(
(Specification<JpaSoftwareModuleMetadata>) (root, query, cb) -> cb.and(
(root, query, cb) -> cb.and(
cb.equal(root.get(JpaSoftwareModuleMetadata_.softwareModule)
.get(JpaSoftwareModule_.id), softwareModuleId),
spec.toPredicate(root, query, cb)),
@@ -631,13 +631,13 @@ public class JpaSoftwareManagement implements SoftwareManagement {
}
@Override
public List<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(final Long softwareModuleId) {
public Page<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(final Pageable pageable,
final Long softwareModuleId) {
throwExceptionIfSoftwareModuleDoesNotExist(softwareModuleId);
return Collections.unmodifiableList(softwareModuleMetadataRepository
.findAll((Specification<JpaSoftwareModuleMetadata>) (root, query, cb) -> cb
.and(cb.equal(root.get(JpaSoftwareModuleMetadata_.softwareModule).get(JpaSoftwareModule_.id),
softwareModuleId))));
return convertSmMdPage(softwareModuleMetadataRepository.findAll((root, query, cb) -> cb.equal(
root.get(JpaSoftwareModuleMetadata_.softwareModule).get(JpaSoftwareModule_.id), softwareModuleId),
pageable), pageable);
}
@Override

View File

@@ -9,7 +9,9 @@
package org.eclipse.hawkbit.repository.jpa;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
@@ -32,6 +34,10 @@ import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.annotation.Propagation;
@@ -47,6 +53,8 @@ import org.springframework.validation.annotation.Validated;
@Transactional(readOnly = true)
@Validated
public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, SystemManagement {
private static final int MAX_TENANTS_QUERY = 500;
@Autowired
private EntityManager entityManager;
@@ -135,7 +143,7 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
}
private void usageStatsPerTenant(final SystemUsageReport report) {
final List<String> tenants = findTenants();
final List<String> tenants = findTenants(new PageRequest(0, MAX_TENANTS_QUERY)).getContent();
tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> {
report.addTenantData(systemStatsManagement.getStatsOfTenant());
@@ -192,8 +200,13 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
}
@Override
public List<String> findTenants() {
return tenantMetaDataRepository.findAll().stream().map(TenantMetaData::getTenant).collect(Collectors.toList());
public Page<String> findTenants(final Pageable pageable) {
final Page<JpaTenantMetaData> result = tenantMetaDataRepository.findAll(pageable);
return new PageImpl<>(
Collections.unmodifiableList(
result.getContent().stream().map(TenantMetaData::getTenant).collect(Collectors.toList())),
pageable, result.getTotalElements());
}
@Override
@@ -271,4 +284,20 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
public TenantMetaData getTenantMetadata(final Long tenantId) {
return tenantMetaDataRepository.findOne(tenantId);
}
@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void forEachTenant(final Consumer<String> consumer) {
Page<String> tenants;
Pageable query = new PageRequest(0, MAX_TENANTS_QUERY);
do {
tenants = findTenants(query);
tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> {
consumer.accept(tenant);
return null;
}));
} while (tenants.hasNext() && (query = tenants.nextPageable()) != null);
}
}

View File

@@ -25,7 +25,9 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.specifications.TagSpecification;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.springframework.beans.factory.annotation.Autowired;
@@ -85,17 +87,12 @@ public class JpaTagManagement implements TagManagement {
@Override
@Transactional
public void deleteTargetTag(final String targetTagName) {
final TargetTag tag = targetTagRepository.findByNameEquals(targetTagName)
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagName));
targetRepository.findByTag(tag.getId()).forEach(set -> {
set.removeTag(tag);
targetRepository.save(set);
});
if (!targetTagRepository.existsByName(targetTagName)) {
throw new EntityNotFoundException(TargetTag.class, targetTagName);
}
// finally delete the tag itself
targetTagRepository.deleteByName(targetTagName);
}
@Override
@@ -177,22 +174,13 @@ public class JpaTagManagement implements TagManagement {
@Override
@Transactional
public void deleteDistributionSetTag(final String tagName) {
final DistributionSetTag tag = distributionSetTagRepository.findByNameEquals(tagName)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName));
distributionSetRepository.findByTag(tag).forEach(set -> {
set.removeTag(tag);
distributionSetRepository.save(set);
});
if (!distributionSetTagRepository.existsByName(tagName)) {
throw new EntityNotFoundException(DistributionSetTag.class, tagName);
}
distributionSetTagRepository.deleteByName(tagName);
}
@Override
public List<DistributionSetTag> findAllDistributionSetTags() {
return Collections.unmodifiableList(distributionSetTagRepository.findAll());
}
@Override
public Optional<TargetTag> findTargetTagById(final Long id) {
return Optional.ofNullable(targetTagRepository.findOne(id));
@@ -223,7 +211,21 @@ public class JpaTagManagement implements TagManagement {
@Override
public Page<TargetTag> findAllTargetTags(final Pageable pageable, final String controllerId) {
if (!targetRepository.existsByControllerId(controllerId)) {
throw new EntityNotFoundException(Target.class, controllerId);
}
return convertTPage(targetTagRepository.findAll(TagSpecification.ofTarget(controllerId), pageable), pageable);
}
@Override
public Page<DistributionSetTag> findDistributionSetTagsByDistributionSet(final Pageable pageable,
final Long setId) {
if (!distributionSetRepository.exists(setId)) {
throw new EntityNotFoundException(DistributionSet.class, setId);
}
return convertDsPage(distributionSetTagRepository.findAll(TagSpecification.ofDistributionSet(setId), pageable),
pageable);
}
}

View File

@@ -113,7 +113,7 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public List<Target> findTargetByControllerID(final Collection<String> controllerIDs) {
public List<Target> findTargetsByControllerID(final Collection<String> controllerIDs) {
return Collections.unmodifiableList(
targetRepository.findAll(TargetSpecifications.byControllerIdWithAssignedDsInJoin(controllerIDs)));
}
@@ -376,41 +376,18 @@ public class JpaTargetManagement implements TargetManagement {
.unmodifiableList(allTargets.stream().map(targetRepository::save).collect(Collectors.toList()));
}
private List<Target> unAssignTag(final Collection<Target> targets, final TargetTag tag) {
@SuppressWarnings({ "unchecked", "rawtypes" })
final Collection<JpaTarget> toUnassign = (Collection) targets;
toUnassign.forEach(target -> target.removeTag(tag));
return Collections
.unmodifiableList(toUnassign.stream().map(targetRepository::save).collect(Collectors.toList()));
}
@Override
@Transactional
public List<Target> unAssignAllTargetsByTag(final Long targetTagId) {
final TargetTag tag = targetTagRepository.findById(targetTagId)
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));
if (tag.getAssignedToTargets().isEmpty()) {
return Collections.emptyList();
}
return unAssignTag(tag.getAssignedToTargets(), tag);
}
@Override
@Transactional
public Target unAssignTag(final String controllerID, final Long targetTagId) {
final Target target = targetRepository.findByControllerId(controllerID)
final JpaTarget target = (JpaTarget) targetRepository.findByControllerId(controllerID)
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerID));
final TargetTag tag = targetTagRepository.findById(targetTagId)
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));
final List<Target> unAssignTag = unAssignTag(Lists.newArrayList(target), tag);
return unAssignTag.isEmpty() ? null : unAssignTag.get(0);
target.removeTag(tag);
return targetRepository.save(target);
}
@Override
@@ -559,13 +536,28 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public List<Target> findTargetsByTag(final String tagName) {
final Optional<TargetTag> tag = targetTagRepository.findByNameEquals(tagName);
if (!tag.isPresent()) {
return Collections.emptyList();
}
public Page<Target> findTargetsByTag(final Pageable pageable, final Long tagId) {
throwEntityNotFoundExceptionIfTagDoesNotExist(tagId);
return Collections.unmodifiableList(targetRepository.findByTag(tag.get().getId()));
return convertPage(targetRepository.findByTag(pageable, tagId), pageable);
}
private void throwEntityNotFoundExceptionIfTagDoesNotExist(final Long tagId) {
if (!targetTagRepository.exists(tagId)) {
throw new EntityNotFoundException(TargetTag.class, tagId);
}
}
@Override
public Page<Target> findTargetsByTag(final Pageable pageable, final String rsqlParam, final Long tagId) {
throwEntityNotFoundExceptionIfTagDoesNotExist(tagId);
final Specification<JpaTarget> spec = RSQLUtility.parse(rsqlParam, TargetFields.class, virtualPropertyReplacer);
return convertPage(targetRepository.findAll((Specification<JpaTarget>) (root, query, cb) -> cb.and(
TargetSpecifications.hasTag(tagId).toPredicate(root, query, cb), spec.toPredicate(root, query, cb)),
pageable), pageable);
}
@Override
@@ -594,7 +586,7 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public List<Target> findTargetAllById(final Collection<Long> ids) {
public List<Target> findTargetsById(final Collection<Long> ids) {
return Collections.unmodifiableList(targetRepository.findAll(ids));
}

View File

@@ -24,6 +24,7 @@ import org.eclipse.hawkbit.repository.RepositoryProperties;
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
import org.eclipse.hawkbit.repository.RolloutManagement;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.PropertiesQuotaManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
@@ -63,6 +64,7 @@ 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.HawkbitSecurityProperties;
import org.eclipse.hawkbit.security.SecurityTokenGenerator;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.TenantAware;
@@ -123,6 +125,11 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
return new RsqlParserValidationOracle();
}
@Bean
PropertiesQuotaManagement staticQuotaManagement(final HawkbitSecurityProperties securityProperties) {
return new PropertiesQuotaManagement(securityProperties);
}
/**
* @param distributionSetManagement
* to loading the {@link DistributionSetType}
@@ -557,8 +564,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
AutoAssignScheduler autoAssignScheduler(final TenantAware tenantAware, final SystemManagement systemManagement,
final SystemSecurityContext systemSecurityContext, final AutoAssignChecker autoAssignChecker,
final LockRegistry lockRegistry) {
return new AutoAssignScheduler(tenantAware, systemManagement, systemSecurityContext, autoAssignChecker,
lockRegistry);
return new AutoAssignScheduler(systemManagement, systemSecurityContext, autoAssignChecker, lockRegistry);
}
/**
@@ -567,8 +573,6 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
* Note: does not activate in test profile, otherwise it is hard to test the
* rollout handling functionality.
*
* @param tenantAware
* to run as specific tenant
* @param systemManagement
* to find all tenants
* @param rolloutManagement
@@ -583,6 +587,6 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
@ConditionalOnProperty(prefix = "hawkbit.rollout.scheduler", name = "enabled", matchIfMissing = true)
RolloutScheduler rolloutScheduler(final TenantAware tenantAware, final SystemManagement systemManagement,
final RolloutManagement rolloutManagement, final SystemSecurityContext systemSecurityContext) {
return new RolloutScheduler(tenantAware, systemManagement, rolloutManagement, systemSecurityContext);
return new RolloutScheduler(systemManagement, rolloutManagement, systemSecurityContext);
}
}

View File

@@ -146,6 +146,16 @@ public interface RolloutGroupRepository
*/
Page<JpaRolloutGroup> findByRolloutId(final Long rolloutId, Pageable page);
/**
* Counts all {@link RolloutGroup} for a specific rollout.
*
* @param rolloutId
* the ID of the rollout to find the rollout groups
*
* @return the amount of found {@link RolloutGroup}s.
*/
long countByRolloutId(final Long rolloutId);
@Modifying
@Query("DELETE FROM JpaRolloutGroup g where g.id in :rolloutGroupIds")
void deleteByIds(@Param("rolloutGroupIds") List<Long> rolloutGroups);

View File

@@ -94,13 +94,16 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
/**
* Finds {@link Target}s by assigned {@link Tag}.
*
* @param page
* pages query and sorting information
*
* @param tagId
* to be found
* @return list of found targets
* @return page of found targets
*/
@Query(value = "SELECT DISTINCT t FROM JpaTarget t JOIN t.tags tt WHERE tt.id = :tag")
List<JpaTarget> findByTag(@Param("tag") final Long tagId);
Page<JpaTarget> findByTag(Pageable page, @Param("tag") final Long tagId);
/**
* Finds all {@link Target}s based on given {@link Target#getControllerId()}

View File

@@ -50,6 +50,16 @@ public interface TargetTagRepository
*/
Optional<TargetTag> findByNameEquals(String tagName);
/**
* Checks if tag with given name exists.
*
* @param tagName
* to check for
* @return <code>true</code> is tag with given name exists
*/
@Query("SELECT CASE WHEN COUNT(t)>0 THEN 'true' ELSE 'false' END FROM JpaTargetTag t WHERE t.name=:tagName")
boolean existsByName(@Param("tagName") String tagName);
/**
* Returns all instances of the type.
*

View File

@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.repository.jpa.aspects;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -25,16 +24,17 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.transaction.TransactionSystemException;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
@@ -54,8 +54,7 @@ public class ExceptionMappingAspectHandler implements Ordered {
* most specific mappable exception according to the type hierarchy of the
* exception.
*/
private static final List<Class<?>> MAPPED_EXCEPTION_ORDER = new ArrayList<>(4);
private static final List<Class<?>> MAPPED_EXCEPTION_ORDER = Lists.newArrayListWithExpectedSize(4);
@Autowired
private JpaVendorAdapter jpaVendorAdapter;
@@ -65,14 +64,14 @@ public class ExceptionMappingAspectHandler implements Ordered {
MAPPED_EXCEPTION_ORDER.add(DuplicateKeyException.class);
MAPPED_EXCEPTION_ORDER.add(DataIntegrityViolationException.class);
MAPPED_EXCEPTION_ORDER.add(ConcurrencyFailureException.class);
MAPPED_EXCEPTION_ORDER.add(OptimisticLockingFailureException.class);
MAPPED_EXCEPTION_ORDER.add(AccessDeniedException.class);
EXCEPTION_MAPPING.put(DuplicateKeyException.class.getName(), EntityAlreadyExistsException.class.getName());
EXCEPTION_MAPPING.put(DataIntegrityViolationException.class.getName(),
EntityAlreadyExistsException.class.getName());
EXCEPTION_MAPPING.put(ConcurrencyFailureException.class.getName(),
EXCEPTION_MAPPING.put(OptimisticLockingFailureException.class.getName(),
ConcurrentModificationException.class.getName());
EXCEPTION_MAPPING.put(AccessDeniedException.class.getName(), InsufficientPermissionException.class.getName());
}
@@ -86,10 +85,7 @@ public class ExceptionMappingAspectHandler implements Ordered {
* @throws Throwable
*/
@AfterThrowing(pointcut = "( execution( * org.springframework.transaction..*.*(..)) "
+ " || execution( * org.eclipse.hawkbit.repository.*.*(..)) "
+ " || execution( * org.eclipse.hawkbit.controller.*.*(..)) "
+ " || execution( * org.eclipse.hawkbit.rest.resource.*.*(..)) "
+ " || execution( * org.eclipse.hawkbit.service.*.*(..)) )", throwing = "ex")
+ " || execution( * org.eclipse.hawkbit.repository.*.*(..)) )", throwing = "ex")
// Exception for squid:S00112, squid:S1162
// It is a AspectJ proxy which deals with exceptions.
@SuppressWarnings({ "squid:S00112", "squid:S1162" })

View File

@@ -8,12 +8,10 @@
*/
package org.eclipse.hawkbit.repository.jpa.autoassign;
import java.util.List;
import java.util.concurrent.locks.Lock;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.support.locks.LockRegistry;
@@ -27,8 +25,6 @@ public class AutoAssignScheduler {
private static final String PROP_SCHEDULER_DELAY_PLACEHOLDER = "${hawkbit.autoassign.scheduler.fixedDelay:2000}";
private final TenantAware tenantAware;
private final SystemManagement systemManagement;
private final SystemSecurityContext systemSecurityContext;
@@ -40,8 +36,6 @@ public class AutoAssignScheduler {
/**
* Instantiates a new AutoAssignScheduler
*
* @param tenantAware
* to run as specific tenant
* @param systemManagement
* to find all tenants
* @param systemSecurityContext
@@ -51,10 +45,9 @@ public class AutoAssignScheduler {
* @param lockRegistry
* to acquire a lock per tenant
*/
public AutoAssignScheduler(final TenantAware tenantAware, final SystemManagement systemManagement,
public AutoAssignScheduler(final SystemManagement systemManagement,
final SystemSecurityContext systemSecurityContext, final AutoAssignChecker autoAssignChecker,
final LockRegistry lockRegistry) {
this.tenantAware = tenantAware;
this.systemManagement = systemManagement;
this.systemSecurityContext = systemSecurityContext;
this.autoAssignChecker = autoAssignChecker;
@@ -82,24 +75,17 @@ public class AutoAssignScheduler {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=355458. So
// iterate through all tenants and execute the rollout check for
// each tenant separately.
final List<String> tenants = systemManagement.findTenants();
LOGGER.info("Checking target filter queries for tenants: {}", tenants.size());
final Lock lock = lockRegistry.obtain("autoassign");
if (!lock.tryLock()) {
return null;
}
try {
for (final String tenant : tenants) {
tenantAware.runAsTenant(tenant, () -> {
autoAssignChecker.check();
return null;
});
}
systemManagement.forEachTenant(tenant -> autoAssignChecker.check());
} finally {
lock.unlock();
}
return null;
}
}

View File

@@ -131,7 +131,6 @@ public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Actio
return actionType;
}
@Override
public List<ActionStatus> getActionStatus() {
if (actionStatus == null) {
return Collections.emptyList();

View File

@@ -142,7 +142,6 @@ public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements
}
}
@Override
public List<String> getMessages() {
if (messages == null) {
messages = Collections.emptyList();

View File

@@ -1,112 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.jpa.model;
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.ActionStatus;
import org.eclipse.hawkbit.repository.model.ActionWithStatusCount;
/**
* Custom JPA Model for querying {@link Action} include the count of the
* action's {@link ActionStatus}.
*
*/
public class JpaActionWithStatusCount implements ActionWithStatusCount {
private final Long actionStatusCount;
private final Long dsId;
private final String dsName;
private final String dsVersion;
private final JpaAction action;
private final String rolloutName;
/**
* JPA constructor, the parameter are the result set columns of the custom
* query.
*
* @param actionId
* the ID of the action
* @param actionType
* the action type
* @param active
* the active attribute of the action
* @param forcedTime
* the forced time attribute of the action
* @param status
* the status attribute of the action
* @param actionCreatedAt
* the createdAt timestamp of the action
* @param actionLastModifiedAt
* the last modified timestamp of the action
* @param dsId
* the ID of the distributionset
* @param dsName
* the name of the distributionset
* @param dsVersion
* the version of the distributionset
* @param actionStatusCount
* the count of the action status for this action
* @param rolloutName
* the rollout name
*/
// Exception squid:S00107 - needed this way for JPA to fill the view
@SuppressWarnings("squid:S00107")
public JpaActionWithStatusCount(final Long actionId, final ActionType actionType, final boolean active,
final Long forcedTime, final Status status, final Long actionCreatedAt, final Long actionLastModifiedAt,
final Long dsId, final String dsName, final String dsVersion, final Long actionStatusCount,
final String rolloutName) {
this.dsId = dsId;
this.dsName = dsName;
this.dsVersion = dsVersion;
this.actionStatusCount = actionStatusCount;
this.rolloutName = rolloutName;
action = new JpaAction();
action.setActionType(actionType);
action.setActive(active);
action.setForcedTime(forcedTime);
action.setStatus(status);
action.setId(actionId);
action.setActionType(actionType);
action.setCreatedAt(actionCreatedAt);
action.setLastModifiedAt(actionLastModifiedAt);
}
@Override
public Action getAction() {
return action;
}
@Override
public Long getDsId() {
return dsId;
}
@Override
public String getDsName() {
return dsName;
}
@Override
public String getDsVersion() {
return dsVersion;
}
@Override
public Long getActionStatusCount() {
return actionStatusCount;
}
@Override
public String getRolloutName() {
return rolloutName;
}
}

View File

@@ -35,7 +35,7 @@ import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdatedEvent;
import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException;
import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException;
import org.eclipse.hawkbit.repository.model.Action;
@@ -174,7 +174,6 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
this(name, version, description, type, moduleList, false);
}
@Override
public Set<DistributionSetTag> getTags() {
if (tags == null) {
return Collections.emptySet();
@@ -339,7 +338,7 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
public void fireUpdateEvent(final DescriptorEvent descriptorEvent) {
publishEventWithEventPublisher(
new DistributionSetUpdateEvent(this, EventPublisherHolder.getInstance().getApplicationId()));
new DistributionSetUpdatedEvent(this, EventPublisherHolder.getInstance().getApplicationId()));
if (isSoftDeleted(descriptorEvent)) {
publishEventWithEventPublisher(new DistributionSetDeletedEvent(getTenant(), getId(), getClass().getName(),

View File

@@ -20,7 +20,7 @@ import javax.persistence.UniqueConstraint;
import org.eclipse.hawkbit.repository.event.remote.DistributionSetTagDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
@@ -64,7 +64,6 @@ public class JpaDistributionSetTag extends JpaTag implements DistributionSetTag,
// Default constructor for JPA.
}
@Override
public List<DistributionSet> getAssignedToDistributionSet() {
if (assignedToDistributionSet == null) {
return Collections.emptyList();
@@ -82,7 +81,7 @@ public class JpaDistributionSetTag extends JpaTag implements DistributionSetTag,
@Override
public void fireUpdateEvent(final DescriptorEvent descriptorEvent) {
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(
new DistributionSetTagUpdateEvent(this, EventPublisherHolder.getInstance().getApplicationId()));
new DistributionSetTagUpdatedEvent(this, EventPublisherHolder.getInstance().getApplicationId()));
}

View File

@@ -130,7 +130,6 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event
this.distributionSet = (JpaDistributionSet) distributionSet;
}
@Override
public List<RolloutGroup> getRolloutGroups() {
if (rolloutGroups == null) {
return Collections.emptyList();

View File

@@ -20,7 +20,7 @@ import javax.persistence.UniqueConstraint;
import org.eclipse.hawkbit.repository.event.remote.TargetTagDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
@@ -61,7 +61,6 @@ public class JpaTargetTag extends JpaTag implements TargetTag, EventAwareEntity
// Default constructor for JPA.
}
@Override
public List<Target> getAssignedToTargets() {
if (assignedToTargets == null) {
return Collections.emptyList();
@@ -80,7 +79,7 @@ public class JpaTargetTag extends JpaTag implements TargetTag, EventAwareEntity
@Override
public void fireUpdateEvent(final DescriptorEvent descriptorEvent) {
EventPublisherHolder.getInstance().getEventPublisher()
.publishEvent(new TargetTagUpdateEvent(this, EventPublisherHolder.getInstance().getApplicationId()));
.publishEvent(new TargetTagUpdatedEvent(this, EventPublisherHolder.getInstance().getApplicationId()));
}
@Override

View File

@@ -8,12 +8,9 @@
*/
package org.eclipse.hawkbit.repository.jpa.rollout;
import java.util.List;
import org.eclipse.hawkbit.repository.RolloutManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
@@ -29,8 +26,6 @@ public class RolloutScheduler {
private static final String PROP_SCHEDULER_DELAY_PLACEHOLDER = "${hawkbit.rollout.scheduler.fixedDelay:2000}";
private final TenantAware tenantAware;
private final SystemManagement systemManagement;
private final RolloutManagement rolloutManagement;
@@ -40,8 +35,6 @@ public class RolloutScheduler {
/**
* Constructor.
*
* @param tenantAware
* to run as specific tenant
* @param systemManagement
* to find all tenants
* @param rolloutManagement
@@ -49,9 +42,8 @@ public class RolloutScheduler {
* @param systemSecurityContext
* to run as system
*/
public RolloutScheduler(final TenantAware tenantAware, final SystemManagement systemManagement,
final RolloutManagement rolloutManagement, final SystemSecurityContext systemSecurityContext) {
this.tenantAware = tenantAware;
public RolloutScheduler(final SystemManagement systemManagement, final RolloutManagement rolloutManagement,
final SystemSecurityContext systemSecurityContext) {
this.systemManagement = systemManagement;
this.rolloutManagement = rolloutManagement;
this.systemSecurityContext = systemSecurityContext;
@@ -76,22 +68,9 @@ public class RolloutScheduler {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=355458. So
// iterate through all tenants and execute the rollout check for
// each tenant seperately.
final List<String> tenants = systemManagement.findTenants();
LOGGER.info("Checking rollouts for {} tenants", tenants.size());
for (final String tenant : tenants) {
tenantAware.runAsTenant(tenant, () -> {
try {
rolloutManagement.handleRollouts();
// We catch all potential runtime exceptions here to
// ensure that not all tenants are blocked if we have a
// problem with a rollout.
} catch (@SuppressWarnings("squid:S1166") final RuntimeException e) {
LOGGER.error("Failed to handle rollouts for tenant {}. I will move on to next tenant.", tenant,
e);
}
return null;
});
}
systemManagement.forEachTenant(tenant -> rolloutManagement.handleRollouts());
return null;
});
}

View File

@@ -78,7 +78,6 @@ public final class DistributionSetSpecification {
return (targetRoot, query, cb) -> {
final Predicate predicate = cb.equal(targetRoot.<Long> get(JpaDistributionSet_.id), distid);
targetRoot.fetch(JpaDistributionSet_.modules, JoinType.LEFT);
targetRoot.fetch(JpaDistributionSet_.tags, JoinType.LEFT);
targetRoot.fetch(JpaDistributionSet_.type, JoinType.LEFT);
query.distinct(true);
@@ -218,4 +217,20 @@ public final class DistributionSetSpecification {
};
}
/**
* {@link Specification} for retrieving {@link DistributionSet}s by tag.
*
* @param tagId
* the ID of the distribution set which must be assigned
* @return the {@link DistributionSet} {@link Specification}
*/
public static Specification<JpaDistributionSet> hasTag(final Long tagId) {
return (targetRoot, query, cb) -> {
final SetJoin<JpaDistributionSet, JpaDistributionSetTag> tags = targetRoot.join(JpaDistributionSet_.tags,
JoinType.LEFT);
return cb.equal(tags.get(JpaDistributionSetTag_.id), tagId);
};
}
}

View File

@@ -8,9 +8,6 @@
*/
package org.eclipse.hawkbit.repository.jpa.specifications;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Predicate;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType_;
@@ -28,24 +25,6 @@ public final class SoftwareModuleSpecification {
// utility class
}
/**
* {@link Specification} for retrieving {@link SoftwareModule}s by its ID
* attribute.
*
* @param moduleId
* to search for
* @return the {@link SoftwareModule} {@link Specification}
*/
public static Specification<JpaSoftwareModule> byId(final Long moduleId) {
return (targetRoot, query, cb) -> {
final Predicate predicate = cb.equal(targetRoot.<Long> get(JpaSoftwareModule_.id), moduleId);
targetRoot.fetch(JpaSoftwareModule_.type);
targetRoot.fetch(JpaSoftwareModule_.metadata, JoinType.LEFT);
query.distinct(true);
return predicate;
};
}
/**
* {@link Specification} for retrieving {@link SoftwareModule}s where its
* DELETED attribute is false.
@@ -57,8 +36,8 @@ public final class SoftwareModuleSpecification {
}
/**
* {@link Specification} for retrieving {@link SoftwareModule}s by
* "like name or like version".
* {@link Specification} for retrieving {@link SoftwareModule}s by "like
* name or like version".
*
* @param subString
* to be filtered on
@@ -71,8 +50,8 @@ public final class SoftwareModuleSpecification {
}
/**
* {@link Specification} for retrieving {@link SoftwareModule}s by
* "like name or like version".
* {@link Specification} for retrieving {@link SoftwareModule}s by "like
* name or like version".
*
* @param type
* to be filtered on

View File

@@ -10,11 +10,18 @@ package org.eclipse.hawkbit.repository.jpa.specifications;
import javax.persistence.criteria.Join;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag_;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.springframework.data.jpa.domain.Specification;
/**
@@ -28,13 +35,13 @@ public final class TagSpecification {
}
/**
* {@link Specification} for retrieving {@link DistributionSet}s by its
* DELETED attribute.
* {@link Specification} for retrieving {@link TargetTag}s by assigned
* {@link Target}.
*
* @param isDeleted
* TRUE/FALSE are compared to the attribute DELETED. If NULL the
* attribute is ignored
* @return the {@link DistributionSet} {@link Specification}
* @param controllerId
* of the target
*
* @return the {@link JpaTargetTag} {@link Specification}
*/
public static Specification<JpaTargetTag> ofTarget(final String controllerId) {
return (targetRoot, query, criteriaBuilder) -> {
@@ -47,4 +54,25 @@ public final class TagSpecification {
}
/**
* {@link Specification} for retrieving {@link DistributionSetTag}s by
* assigned {@link DistributionSet}.
*
* @param dsId
* of the distribution set
*
* @return the {@link JpaDistributionSetTag} {@link Specification}
*/
public static Specification<JpaDistributionSetTag> ofDistributionSet(final Long dsId) {
return (dsRoot, query, criteriaBuilder) -> {
final Join<JpaDistributionSetTag, JpaDistributionSet> tagJoin = dsRoot
.join(JpaDistributionSetTag_.assignedToDistributionSet);
query.distinct(true);
return criteriaBuilder.equal(tagJoin.get(JpaDistributionSet_.id), dsId);
};
}
}

View File

@@ -287,4 +287,19 @@ public final class TargetSpecifications {
return (targetRoot, query, cb) -> cb.equal(
targetRoot.get(JpaTarget_.installedDistributionSet).get(JpaDistributionSet_.id), distributionSetId);
}
/**
* {@link Specification} for retrieving {@link Target}s by tag.
*
* @param tagId
* the ID of the distribution set which must be assigned
* @return the {@link Target} {@link Specification}
*/
public static Specification<JpaTarget> hasTag(final Long tagId) {
return (targetRoot, query, cb) -> {
final SetJoin<JpaTarget, JpaTargetTag> tags = targetRoot.join(JpaTarget_.tags, JoinType.LEFT);
return cb.equal(tags.get(JpaTargetTag_.id), tagId);
};
}
}

View File

@@ -31,7 +31,7 @@ public class DistributionSetEventTest extends AbstractRemoteEntityEventTest<Dist
@Test
@Description("Verifies that the distribution set entity reloading by remote updated event works")
public void testDistributionSetUpdateEvent() {
assertAndCreateRemoteEvent(DistributionSetUpdateEvent.class);
assertAndCreateRemoteEvent(DistributionSetUpdatedEvent.class);
}
@Override

View File

@@ -31,7 +31,7 @@ public class DistributionSetTagEventTest extends AbstractRemoteEntityEventTest<D
@Test
@Description("Verifies that the distribution set tag entity reloading by remote updated event works")
public void testDistributionSetTagUpdateEvent() {
assertAndCreateRemoteEvent(DistributionSetTagUpdateEvent.class);
assertAndCreateRemoteEvent(DistributionSetTagUpdatedEvent.class);
}
@Override

View File

@@ -99,7 +99,7 @@ public class RolloutGroupEventTest extends AbstractRemoteEntityEventTest<Rollout
10, new RolloutGroupConditionBuilder().withDefaults()
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10").build());
return rolloutManagement.findRolloutById(entity.getId()).get().getRolloutGroups().get(0);
return rolloutGroupManagement.findRolloutGroupsByRolloutId(entity.getId(), PAGE).getContent().get(0);
}
}

View File

@@ -31,7 +31,7 @@ public class TargetTagEventTest extends AbstractRemoteEntityEventTest<TargetTag>
@Test
@Description("Verifies that the target tag entity reloading by remote updated event works")
public void testTargetTagUpdateEventt() {
assertAndCreateRemoteEvent(TargetTagUpdateEvent.class);
assertAndCreateRemoteEvent(TargetTagUpdatedEvent.class);
}
@Override

View File

@@ -98,7 +98,7 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
@Transactional(readOnly = true)
protected List<Action> findActionsByRolloutAndStatus(final Rollout rollout, final Action.Status actionStatus) {
return Lists.newArrayList(actionRepository.findByRolloutIdAndStatus(pageReq, rollout.getId(), actionStatus));
return Lists.newArrayList(actionRepository.findByRolloutIdAndStatus(PAGE, rollout.getId(), actionStatus));
}
protected static void verifyThrownExceptionBy(final ThrowingCallable tc, final String objectType) {

View File

@@ -76,7 +76,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> artifactManagement.deleteArtifact(NOT_EXIST_IDL), "Artifact");
verifyThrownExceptionBy(() -> artifactManagement.findArtifactBySoftwareModule(pageReq, NOT_EXIST_IDL),
verifyThrownExceptionBy(() -> artifactManagement.findArtifactBySoftwareModule(PAGE, NOT_EXIST_IDL),
"SoftwareModule");
assertThat(artifactManagement.findArtifactByFilename(NOT_EXIST_ID).isPresent()).isFalse();
@@ -260,12 +260,12 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
public void findArtifactBySoftwareModule() {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
assertThat(artifactManagement.findArtifactBySoftwareModule(pageReq, sm.getId())).isEmpty();
assertThat(artifactManagement.findArtifactBySoftwareModule(PAGE, sm.getId())).isEmpty();
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(),
"file1", false);
assertThat(artifactManagement.findArtifactBySoftwareModule(pageReq, sm.getId())).hasSize(1);
assertThat(artifactManagement.findArtifactBySoftwareModule(PAGE, sm.getId())).hasSize(1);
}
@Test

View File

@@ -138,7 +138,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
Action.Status.FINISHED, Action.Status.FINISHED, false);
assertThat(actionStatusRepository.count()).isEqualTo(6);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(6);
assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(6);
}
@Test
@@ -161,7 +161,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
Action.Status.FINISHED, Action.Status.FINISHED, false);
assertThat(actionStatusRepository.count()).isEqualTo(3);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(3);
assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(3);
}
@Test
@@ -186,7 +186,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
Action.Status.RUNNING, Action.Status.RUNNING, true);
assertThat(actionStatusRepository.count()).isEqualTo(1);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(1);
assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(1);
}
@@ -214,7 +214,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
Action.Status.CANCELED, Action.Status.FINISHED, false);
assertThat(actionStatusRepository.count()).isEqualTo(7);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(7);
assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(7);
}
@Test
@@ -241,7 +241,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
Action.Status.CANCELED, Action.Status.CANCELED, false);
assertThat(actionStatusRepository.count()).isEqualTo(7);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(7);
assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(7);
}
@Test
@@ -269,7 +269,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
Action.Status.RUNNING, Action.Status.CANCEL_REJECTED, true);
assertThat(actionStatusRepository.count()).isEqualTo(7);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(7);
assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(7);
}
@Test
@@ -297,7 +297,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
Action.Status.RUNNING, Action.Status.ERROR, true);
assertThat(actionStatusRepository.count()).isEqualTo(7);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(7);
assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(7);
}
@Step
@@ -308,7 +308,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
return deploymentManagement.findActiveActionsByTarget(TestdataFactory.DEFAULT_CONTROLLER_ID).get(0).getId();
return deploymentManagement.findActiveActionsByTarget(PAGE, TestdataFactory.DEFAULT_CONTROLLER_ID)
.getContent().get(0).getId();
}
@Step
@@ -366,7 +367,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
final Action action = deploymentManagement.findAction(actionId).get();
assertThat(action.getStatus()).isEqualTo(expectedActionActionStatus);
assertThat(action.isActive()).isEqualTo(actionActive);
final List<ActionStatus> actionStatusList = deploymentManagement.findActionStatusByAction(pageReq, actionId)
final List<ActionStatus> actionStatusList = deploymentManagement.findActionStatusByAction(PAGE, actionId)
.getContent();
assertThat(actionStatusList.get(actionStatusList.size() - 1).getStatus()).isEqualTo(expectedActionStatus);
if (actionActive) {
@@ -472,7 +473,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
Action.Status.ERROR, Action.Status.ERROR, false);
assertThat(actionStatusRepository.count()).isEqualTo(3);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(3);
assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(3);
}
@@ -507,7 +508,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
Action.Status.FINISHED, Action.Status.FINISHED, false);
assertThat(actionStatusRepository.count()).isEqualTo(3);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(3);
assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(3);
}
@@ -533,7 +534,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(actionStatusRepository.count()).isEqualTo(3);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action.getId()).getNumberOfElements())
assertThat(deploymentManagement.findActionStatusByAction(PAGE, action.getId()).getNumberOfElements())
.isEqualTo(3);
}
@@ -558,8 +559,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
// however, additional action status has been stored
assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(4);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action.getId()).getNumberOfElements())
assertThat(actionStatusRepository.findAll(PAGE).getNumberOfElements()).isEqualTo(4);
assertThat(deploymentManagement.findActionStatusByAction(PAGE, action.getId()).getNumberOfElements())
.isEqualTo(4);
}

View File

@@ -36,6 +36,7 @@ import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedExcepti
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.model.Action;
@@ -122,16 +123,15 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> deploymentManagement.countActionsByTarget(NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.countActionsByTarget("xxx", NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findActionsByDistributionSet(pageReq, NOT_EXIST_IDL),
verifyThrownExceptionBy(() -> deploymentManagement.findActionsByDistributionSet(PAGE, NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(() -> deploymentManagement.findActionsByTarget(NOT_EXIST_ID, pageReq), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findActionsByTarget("id==*", NOT_EXIST_ID, pageReq),
verifyThrownExceptionBy(() -> deploymentManagement.findActionsByTarget(NOT_EXIST_ID, PAGE), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findActionsByTarget("id==*", NOT_EXIST_ID, PAGE),
"Target");
verifyThrownExceptionBy(
() -> deploymentManagement.findActionsWithStatusCountByTargetOrderByIdDesc(NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findActiveActionsByTarget(NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findInActiveActionsByTarget(NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findActiveActionsByTarget(PAGE, NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findInActiveActionsByTarget(PAGE, NOT_EXIST_ID),
"Target");
verifyThrownExceptionBy(() -> deploymentManagement.forceQuitAction(NOT_EXIST_IDL), "Action");
verifyThrownExceptionBy(() -> deploymentManagement.forceTargetAction(NOT_EXIST_IDL), "Action");
}
@@ -164,7 +164,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// act
final Slice<Action> actions = deploymentManagement.findActionsByTarget(testTarget.get(0).getControllerId(),
pageReq);
PAGE);
final Long count = deploymentManagement.countActionsByTarget(testTarget.get(0).getControllerId());
assertThat(count).as("One Action for target").isEqualTo(1L).isEqualTo(actions.getContent().size());
@@ -180,11 +180,11 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// one action with one action status is generated
final Long actionId = assignDistributionSet(testDs, testTarget).getActions().get(0);
final Slice<Action> actions = deploymentManagement.findActionsByTarget(testTarget.get(0).getControllerId(),
pageReq);
final ActionStatus expectedActionStatus = actions.getContent().get(0).getActionStatus().get(0);
PAGE);
final ActionStatus expectedActionStatus = ((JpaAction) actions.getContent().get(0)).getActionStatus().get(0);
// act
final Page<ActionStatus> actionStates = deploymentManagement.findActionStatusByAction(pageReq, actionId);
final Page<ActionStatus> actionStates = deploymentManagement.findActionStatusByAction(PAGE, actionId);
assertThat(actionStates.getContent()).hasSize(1);
assertThat(actionStates.getContent().get(0)).as("Action-status of action").isEqualTo(expectedActionStatus);
@@ -201,14 +201,15 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// create action-status entry with one message
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId)
.status(Action.Status.FINISHED).messages(Lists.newArrayList("finished message")));
final Page<ActionStatus> actionStates = deploymentManagement.findActionStatusByAction(pageReq, actionId);
final Page<ActionStatus> actionStates = deploymentManagement.findActionStatusByAction(PAGE, actionId);
// find newly created action-status entry with message
final ActionStatus actionStatusWithMessage = actionStates.getContent().stream()
final JpaActionStatus actionStatusWithMessage = actionStates.getContent().stream().map(c -> (JpaActionStatus) c)
.filter(entry -> entry.getMessages() != null && entry.getMessages().size() > 0).findFirst().get();
final String expectedMsg = actionStatusWithMessage.getMessages().get(0);
// act
final Page<String> messages = deploymentManagement.findMessagesByActionStatusId(pageReq,
final Page<String> messages = deploymentManagement.findMessagesByActionStatusId(PAGE,
actionStatusWithMessage.getId());
assertThat(actionStates.getTotalElements()).as("Two action-states in total").isEqualTo(2L);
@@ -425,7 +426,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get())
.as("wrong assigned ds").isEqualTo(ds);
final JpaAction action = actionRepository
.findByTargetAndDistributionSet(pageReq, (JpaTarget) target, (JpaDistributionSet) ds).getContent()
.findByTargetAndDistributionSet(PAGE, (JpaTarget) target, (JpaDistributionSet) ds).getContent()
.get(0);
assertThat(action).as("action should not be null").isNotNull();
return action;
@@ -455,12 +456,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assignDistributionSet(ds, savedDeployedTargets);
// verify that one Action for each assignDistributionSet
assertThat(actionRepository.findAll(pageReq).getNumberOfElements()).as("wrong size of actions").isEqualTo(20);
assertThat(actionRepository.findAll(PAGE).getNumberOfElements()).as("wrong size of actions").isEqualTo(20);
final Iterable<Target> allFoundTargets = targetManagement.findTargetsAll(pageReq).getContent();
final Iterable<Target> allFoundTargets = targetManagement.findTargetsAll(PAGE).getContent();
// get final updated version of targets
savedDeployedTargets = targetManagement.findTargetByControllerID(
savedDeployedTargets = targetManagement.findTargetsByControllerID(
savedDeployedTargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
assertThat(allFoundTargets).as("founded targets are wrong").containsAll(savedDeployedTargets)
@@ -479,7 +480,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
for (final Target myt : savedDeployedTargets) {
final Target t = targetManagement.findTargetByControllerID(myt.getControllerId()).get();
final List<Action> activeActionsByTarget = deploymentManagement
.findActiveActionsByTarget(t.getControllerId());
.findActiveActionsByTarget(PAGE, t.getControllerId()).getContent();
assertThat(activeActionsByTarget).as("action should not be empty").isNotEmpty();
assertThat(t.getUpdateStatus()).as("wrong target update status").isEqualTo(TargetUpdateStatus.PENDING);
for (final Action ua : activeActionsByTarget) {
@@ -558,7 +559,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final Collection<JpaTarget> savedDeployedTargets = (Collection) deploymentResult.getDeployedTargets();
// retrieving all Actions created by the assignDistributionSet call
final Page<JpaAction> page = actionRepository.findAll(pageReq);
final Page<JpaAction> page = actionRepository.findAll(PAGE);
// and verify the number
assertThat(page.getTotalElements()).as("wrong size of actions")
.isEqualTo(noOfDeployedTargets * noOfDistributionSets);
@@ -653,7 +654,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
.as("installed ds is wrong").isEqualTo(dsA);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getUpdateStatus())
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(deploymentManagement.findActiveActionsByTarget(t.getControllerId()))
assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, t.getControllerId()))
.as("no actions should be active").hasSize(0);
}
@@ -666,7 +667,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
actionRepository.findByDistributionSetId(pageRequest, dsA.getId()).getContent().get(1);
// get final updated version of targets
final List<Target> deployResWithDsBTargets = targetManagement.findTargetByControllerID(deployResWithDsB
final List<Target> deployResWithDsBTargets = targetManagement.findTargetsByControllerID(deployResWithDsB
.getDeployedTargets().stream().map(Target::getControllerId).collect(Collectors.toList()));
assertThat(deployed2DS).as("deployed ds is wrong").containsAll(deployResWithDsBTargets);
@@ -724,7 +725,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// verify that deleted attribute is used correctly
List<DistributionSet> allFoundDS = distributionSetManagement
.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true).getContent();
.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true).getContent();
assertThat(allFoundDS.size()).as("no ds should be founded").isEqualTo(0);
allFoundDS = distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageRequest, true, true)
.getContent();
@@ -798,28 +799,28 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).get().getOptLockRevision());
// verifying that the assignment is correct
assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size())
assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements())
.as("Active target actions are wrong").isEqualTo(1);
assertThat(deploymentManagement.countActionsByTarget(targ.getControllerId())).as("Target actions are wrong")
.isEqualTo(1);
assertThat(targ.getUpdateStatus()).as("UpdateStatus of target is wrong").isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get())
.as("Assigned distribution set of target is wrong").isEqualTo(dsA);
assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet())
.as("Distribution set of actionn is wrong").isEqualTo(dsA);
assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet())
.as("Installed distribution set of action should be null").isNotNull();
assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getContent().get(0)
.getDistributionSet()).as("Distribution set of actionn is wrong").isEqualTo(dsA);
assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getContent().get(0)
.getDistributionSet()).as("Installed distribution set of action should be null").isNotNull();
final Page<Action> updAct = actionRepository.findByDistributionSetId(pageReq, dsA.getId());
final Page<Action> updAct = actionRepository.findByDistributionSetId(PAGE, dsA.getId());
controllerManagement.addUpdateActionStatus(
entityFactory.actionStatus().create(updAct.getContent().get(0).getId()).status(Status.FINISHED));
targ = targetManagement.findTargetByControllerID(targ.getControllerId()).get();
assertEquals("active target actions are wrong", 0,
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size());
deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements());
assertEquals("active actions are wrong", 1,
deploymentManagement.findInActiveActionsByTarget(targ.getControllerId()).size());
deploymentManagement.findInActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements());
assertEquals("tagret update status is not correct", TargetUpdateStatus.IN_SYNC, targ.getUpdateStatus());
assertEquals("wrong assigned ds", dsA,
@@ -832,15 +833,15 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
targ = targs.iterator().next();
assertEquals("active actions are wrong", 1,
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size());
deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements());
assertEquals("target status is wrong", TargetUpdateStatus.PENDING,
targetManagement.findTargetByControllerID(targ.getControllerId()).get().getUpdateStatus());
assertEquals("wrong assigned ds", dsB,
deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get());
assertEquals("Installed ds is wrong", dsA.getId(),
deploymentManagement.getInstalledDistributionSet(targ.getControllerId()).get().getId());
assertEquals("Active ds is wrong", dsB,
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet());
assertEquals("Active ds is wrong", dsB, deploymentManagement
.findActiveActionsByTarget(PAGE, targ.getControllerId()).getContent().get(0).getDistributionSet());
}
@@ -972,7 +973,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
if (event.getControllerId().equals(myt.getControllerId())) {
found = true;
final List<Action> activeActionsByTarget = deploymentManagement
.findActiveActionsByTarget(myt.getControllerId());
.findActiveActionsByTarget(PAGE, myt.getControllerId()).getContent();
assertThat(activeActionsByTarget).as("size of active actions for target is wrong").isNotEmpty();
assertThat(event.getActionId()).as("Action id in database and event do not match")
.isEqualTo(activeActionsByTarget.get(0).getId());

View File

@@ -29,6 +29,7 @@ import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
import org.eclipse.hawkbit.repository.model.Action.Status;
@@ -121,6 +122,12 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
() -> distributionSetManagement.assignTag(Lists.newArrayList(NOT_EXIST_IDL), dsTag.getId()),
"DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.findDistributionSetsByTag(PAGE, NOT_EXIST_IDL),
"DistributionSetTag");
verifyThrownExceptionBy(
() -> distributionSetManagement.findDistributionSetsByTag(PAGE, "name==*", NOT_EXIST_IDL),
"DistributionSetTag");
verifyThrownExceptionBy(
() -> distributionSetManagement.toggleTagAssignment(Lists.newArrayList(NOT_EXIST_IDL), dsTag.getName()),
"DistributionSet");
@@ -128,9 +135,6 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
() -> distributionSetManagement.toggleTagAssignment(Lists.newArrayList(set.getId()), NOT_EXIST_ID),
"DistributionSetTag");
verifyThrownExceptionBy(() -> distributionSetManagement.unAssignAllDistributionSetsByTag(NOT_EXIST_IDL),
"DistributionSetTag");
verifyThrownExceptionBy(() -> distributionSetManagement.unAssignTag(set.getId(), NOT_EXIST_IDL),
"DistributionSetTag");
@@ -168,11 +172,11 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
"DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement.findDistributionSetMetadataByDistributionSetId(NOT_EXIST_IDL, pageReq),
() -> distributionSetManagement.findDistributionSetMetadataByDistributionSetId(NOT_EXIST_IDL, PAGE),
"DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement
.findDistributionSetMetadataByDistributionSetId(NOT_EXIST_IDL, "name==*", pageReq), "DistributionSet");
.findDistributionSetMetadataByDistributionSetId(NOT_EXIST_IDL, "name==*", PAGE), "DistributionSet");
assertThatThrownBy(() -> distributionSetManagement.isDistributionSetInUse(NOT_EXIST_IDL))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining(NOT_EXIST_ID)
@@ -390,28 +394,28 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
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));
assignedDS.stream().map(c -> (JpaDistributionSet) c)
.forEach(ds -> assertThat(ds.getTags().size()).as("ds has wrong tag size").isEqualTo(1));
DistributionSetTag findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1").get();
assertThat(assignedDS.size()).as("assigned ds has wrong size")
.isEqualTo(findDistributionSetTag.getAssignedToDistributionSet().size());
final DistributionSet unAssignDS = distributionSetManagement.unAssignTag(assignDS.get(0),
findDistributionSetTag.getId());
assertThat(assignedDS.size()).as("assigned ds has wrong size").isEqualTo(
distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId()).getNumberOfElements());
final JpaDistributionSet unAssignDS = (JpaDistributionSet) distributionSetManagement
.unAssignTag(assignDS.get(0), 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").get();
assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).as("ds tag ds has wrong ds size")
.isEqualTo(3);
assertThat(distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId()).getNumberOfElements())
.as("ds tag ds has wrong ds size").isEqualTo(3);
final List<DistributionSet> unAssignTargets = distributionSetManagement
.unAssignAllDistributionSetsByTag(findDistributionSetTag.getId());
findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1").get();
assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).as("ds tag has wrong ds size")
.isEqualTo(0);
assertThat(unAssignTargets.size()).as("unassigned target has wrong size").isEqualTo(3);
unAssignTargets
.forEach(target -> assertThat(target.getTags().size()).as("target has wrong tag size").isEqualTo(0));
assertThat(distributionSetManagement
.findDistributionSetsByTag(PAGE, "name==" + unAssignDS.getName(), tag.getId()).getNumberOfElements())
.as("ds tag ds has wrong ds size").isEqualTo(0);
assertThat(distributionSetManagement
.findDistributionSetsByTag(PAGE, "name!=" + unAssignDS.getName(), tag.getId()).getNumberOfElements())
.as("ds tag ds has wrong ds size").isEqualTo(3);
}
@Test
@@ -559,14 +563,14 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// target first only has an assigned DS-three so check order correct
final List<DistributionSet> tFirstPin = distributionSetManagement.findDistributionSetsAllOrderedByLinkTarget(
pageReq, distributionSetFilterBuilder, tFirst.getControllerId()).getContent();
PAGE, distributionSetFilterBuilder, tFirst.getControllerId()).getContent();
assertThat(tFirstPin.get(0)).isEqualTo(dsThree);
assertThat(tFirstPin).hasSize(10);
// target second has installed DS-2 and assigned DS-4 so check order
// correct
final List<DistributionSet> tSecondPin = distributionSetManagement.findDistributionSetsAllOrderedByLinkTarget(
pageReq, distributionSetFilterBuilder, tSecond.getControllerId()).getContent();
PAGE, distributionSetFilterBuilder, tSecond.getControllerId()).getContent();
assertThat(tSecondPin.get(0)).isEqualTo(dsSecond);
assertThat(tSecondPin.get(1)).isEqualTo(dsFour);
assertThat(tFirstPin).hasSize(10);
@@ -624,7 +628,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
expected.add(dsNewType);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, getDistributionSetFilterBuilder().build()).getContent())
.findDistributionSetsByFilters(PAGE, getDistributionSetFilterBuilder().build()).getContent())
.hasSize(203).containsOnly(expected.toArray(new DistributionSet[0]));
DistributionSetFilterBuilder distributionSetFilterBuilder;
@@ -632,11 +636,11 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// search for not deleted
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.TRUE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1);
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(false);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent())
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(202);
// search for completed
@@ -648,61 +652,61 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(202)
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(202)
.containsOnly(expected.toArray(new DistributionSet[0]));
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.FALSE);
expected = new ArrayList<>();
expected.add(dsInComplete);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.containsOnly(expected.toArray(new DistributionSet[0]));
// search for type
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(newType);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1);
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(standardDsType);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent())
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(202);
// search for text
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setSearchText("%test2");
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent())
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(100);
// search for tags
distributionSetFilterBuilder = getDistributionSetFilterBuilder()
.setTagNames(Lists.newArrayList(dsTagA.getName()));
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent())
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(200);
distributionSetFilterBuilder = getDistributionSetFilterBuilder()
.setTagNames(Lists.newArrayList(dsTagB.getName()));
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent())
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(100);
distributionSetFilterBuilder = getDistributionSetFilterBuilder()
.setTagNames(Lists.newArrayList(dsTagA.getName(), dsTagB.getName()));
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent())
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(200);
distributionSetFilterBuilder = getDistributionSetFilterBuilder()
.setTagNames(Lists.newArrayList(dsTagC.getName(), dsTagB.getName()));
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent())
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(100);
distributionSetFilterBuilder = getDistributionSetFilterBuilder()
.setTagNames(Lists.newArrayList(dsTagC.getName()));
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
// combine deleted and complete
expected = new ArrayList<>();
@@ -713,14 +717,14 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setIsDeleted(Boolean.FALSE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(201)
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(201)
.containsOnly(expected.toArray(new DistributionSet[0]));
expected = new ArrayList<>();
expected.add(dsInComplete);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.FALSE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.containsOnly(expected.toArray(new DistributionSet[0]));
expected = new ArrayList<>();
@@ -728,13 +732,13 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setIsDeleted(Boolean.TRUE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.containsOnly(expected.toArray(new DistributionSet[0]));
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.TRUE)
.setIsComplete(Boolean.FALSE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
// combine deleted and complete and type
expected = new ArrayList<>();
@@ -743,7 +747,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.FALSE)
.setIsComplete(Boolean.TRUE).setType(standardDsType);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(200)
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(200)
.containsOnly(expected.toArray(new DistributionSet[0]));
expected = new ArrayList<>();
@@ -751,19 +755,19 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setType(standardDsType).setIsDeleted(Boolean.TRUE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.containsOnly(expected.toArray(new DistributionSet[0]));
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.TRUE)
.setIsComplete(Boolean.FALSE).setType(standardDsType);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
expected = new ArrayList<>();
expected.add(dsNewType);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setType(newType);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.containsOnly(expected.toArray(new DistributionSet[0]));
// combine deleted and complete and type and text
@@ -772,23 +776,23 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setType(standardDsType).setSearchText("%test2");
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(100)
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(100)
.containsOnly(expected.toArray(new DistributionSet[0]));
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setIsDeleted(Boolean.TRUE).setType(standardDsType).setSearchText("%test2");
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(standardDsType).setSearchText("%test2")
.setIsComplete(false).setIsDeleted(false);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(newType).setSearchText("%test2")
.setIsComplete(Boolean.TRUE).setIsDeleted(false);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
// combine deleted and complete and type and text and tag
expected = new ArrayList<>();
@@ -796,14 +800,14 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true).setType(standardDsType)
.setSearchText("%test2").setTagNames(Lists.newArrayList(dsTagA.getName()));
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(100)
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(100)
.containsOnly(expected.toArray(new DistributionSet[0]));
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(standardDsType).setSearchText("%test2")
.setTagNames(Lists.newArrayList(dsTagA.getName())).setIsComplete(Boolean.FALSE)
.setIsDeleted(Boolean.FALSE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
}
@@ -816,7 +820,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
public void findDistributionSetsWithoutLazy() {
testdataFactory.createDistributionSets(20);
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true))
.hasSize(20);
}
@@ -832,7 +836,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// not assigned so not marked as deleted but fully deleted
assertThat(distributionSetRepository.findAll()).hasSize(1);
assertThat(distributionSetManagement
.findDistributionSetsByDeletedAndOrCompleted(pageReq, Boolean.FALSE, Boolean.TRUE).getTotalElements())
.findDistributionSetsByDeletedAndOrCompleted(PAGE, Boolean.FALSE, Boolean.TRUE).getTotalElements())
.isEqualTo(1);
}
@@ -892,7 +896,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// not assigned so not marked as deleted
assertThat(distributionSetRepository.findAll()).hasSize(4);
assertThat(distributionSetManagement
.findDistributionSetsByDeletedAndOrCompleted(pageReq, Boolean.FALSE, Boolean.TRUE).getTotalElements())
.findDistributionSetsByDeletedAndOrCompleted(PAGE, Boolean.FALSE, Boolean.TRUE).getTotalElements())
.isEqualTo(2);
}
@@ -926,7 +930,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
testdataFactory.createDistributionSet("test" + i);
}
final List<DistributionSet> foundDs = distributionSetManagement.findDistributionSetAllById(searchIds);
final List<DistributionSet> foundDs = distributionSetManagement.findDistributionSetsById(searchIds);
assertThat(foundDs).hasSize(3);

View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.assertj.core.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.event.remote.RolloutDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.junit.Test;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Rollout Management")
public class RolloutGroupManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management get access reacts as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
public void nonExistingEntityAccessReturnsNotPresent() {
assertThat(rolloutGroupManagement.findRolloutGroupById(NOT_EXIST_IDL)).isNotPresent();
assertThat(rolloutGroupManagement.findRolloutGroupWithDetailedStatus(NOT_EXIST_IDL)).isNotPresent();
}
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = RolloutDeletedEvent.class, count = 0),
@Expect(type = RolloutGroupCreatedEvent.class, count = 10),
@Expect(type = RolloutGroupUpdatedEvent.class, count = 10),
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = RolloutUpdatedEvent.class, count = 1),
@Expect(type = TargetCreatedEvent.class, count = 10) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
testdataFactory.createRollout("xxx");
verifyThrownExceptionBy(() -> rolloutGroupManagement.countRolloutGroupsByRolloutId(NOT_EXIST_IDL), "Rollout");
verifyThrownExceptionBy(() -> rolloutGroupManagement.countTargetsOfRolloutsGroup(NOT_EXIST_IDL),
"RolloutGroup");
verifyThrownExceptionBy(
() -> rolloutGroupManagement.findAllRolloutGroupsWithDetailedStatus(NOT_EXIST_IDL, PAGE), "Rollout");
verifyThrownExceptionBy(() -> rolloutGroupManagement.findAllTargetsWithActionStatus(PAGE, NOT_EXIST_IDL),
"RolloutGroup");
verifyThrownExceptionBy(() -> rolloutGroupManagement.findRolloutGroupsAll(NOT_EXIST_IDL, "name==*", PAGE),
"Rollout");
verifyThrownExceptionBy(() -> rolloutGroupManagement.findRolloutGroupTargets(NOT_EXIST_IDL, PAGE),
"RolloutGroup");
verifyThrownExceptionBy(() -> rolloutGroupManagement.findRolloutGroupTargets(NOT_EXIST_IDL, "name==*", PAGE),
"RolloutGroup");
}
}

View File

@@ -10,9 +10,9 @@ package org.eclipse.hawkbit.repository.jpa;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.fail;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -36,7 +36,6 @@ import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
@@ -103,7 +102,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
// verify that manually created action is still running and action
// created from rollout is finished
final List<Action> actionsByKnownTarget = deploymentManagement.findActionsByTarget(knownControllerId, pageReq)
final List<Action> actionsByKnownTarget = deploymentManagement.findActionsByTarget(knownControllerId, PAGE)
.getContent();
// should be 2 actions, one manually and one from the rollout
assertThat(actionsByKnownTarget).hasSize(2);
@@ -164,7 +163,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
// verify the split of the target and targetGroup
final Page<RolloutGroup> rolloutGroups = rolloutGroupManagement
.findRolloutGroupsByRolloutId(createdRollout.getId(), pageReq);
.findRolloutGroupsByRolloutId(createdRollout.getId(), PAGE);
// we have total of #amountTargetsForRollout in rollouts splitted in
// group size #groupSize
assertThat(rolloutGroups).hasSize(amountGroups);
@@ -279,7 +278,7 @@ 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 Slice<JpaAction> runningActionsSlice = actionRepository.findByRolloutIdAndStatus(pageReq,
final Slice<JpaAction> runningActionsSlice = actionRepository.findByRolloutIdAndStatus(PAGE,
createdRollout.getId(), Status.RUNNING);
final List<JpaAction> runningActions = Lists.newArrayList(runningActionsSlice.iterator());
finishAction(runningActions.get(0));
@@ -301,7 +300,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
@Step("Finish one action of the rollout group and delete four targets")
private void finishActionAndDeleteTargetsOfSecondRunningGroup(final Rollout createdRollout) {
final Slice<JpaAction> runningActionsSlice = actionRepository.findByRolloutIdAndStatus(pageReq,
final Slice<JpaAction> runningActionsSlice = actionRepository.findByRolloutIdAndStatus(PAGE,
createdRollout.getId(), Status.RUNNING);
final List<JpaAction> runningActions = Lists.newArrayList(runningActionsSlice.iterator());
finishAction(runningActions.get(0));
@@ -313,7 +312,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
@Step("Delete all targets of the rollout group")
private void deleteAllTargetsFromThirdGroup(final Rollout createdRollout) {
final Slice<JpaAction> runningActionsSlice = actionRepository.findByRolloutIdAndStatus(pageReq,
final Slice<JpaAction> runningActionsSlice = actionRepository.findByRolloutIdAndStatus(PAGE,
createdRollout.getId(), Status.SCHEDULED);
final List<JpaAction> runningActions = Lists.newArrayList(runningActionsSlice.iterator());
targetManagement.deleteTargets(Lists.newArrayList(runningActions.get(0).getTarget().getId(),
@@ -325,7 +324,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
private void verifyRolloutAndAllGroupsAreFinished(final Rollout createdRollout) {
rolloutManagement.handleRollouts();
final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement
.findRolloutGroupsByRolloutId(createdRollout.getId(), pageReq).getContent();
.findRolloutGroupsByRolloutId(createdRollout.getId(), PAGE).getContent();
assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
assertThat(runningRolloutGroups.get(2).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
@@ -589,7 +588,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
// round(5/2)=3 targets SCHEDULED (Group 3)
// round(2/1)=2 targets SCHEDULED (Group 4)
createdRollout = rolloutManagement.findRolloutById(createdRollout.getId()).get();
final List<RolloutGroup> rolloutGroups = createdRollout.getRolloutGroups();
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement
.findRolloutGroupsByRolloutId(createdRollout.getId(), PAGE).getContent();
Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.FINISHED, 2L);
@@ -628,9 +628,10 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(runningActions.size()).isEqualTo(5);
// 5 targets are in the group and the DS has been assigned
final List<RolloutGroup> rolloutGroups = createdRollout.getRolloutGroups();
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement
.findRolloutGroupsByRolloutId(createdRollout.getId(), PAGE).getContent();
final Page<Target> targets = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0).getId(),
pageReq);
PAGE);
final List<Target> targetList = targets.getContent();
assertThat(targetList.size()).isEqualTo(5);
@@ -742,7 +743,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.FINISHED, 9L);
validateRolloutActionStatus(rolloutTwo.getId(), expectedTargetCountStatus);
changeStatusForAllRunningActions(rolloutTwo, Status.FINISHED);
final Page<Target> targetPage = targetManagement.findTargetByUpdateStatus(pageReq, TargetUpdateStatus.IN_SYNC);
final Page<Target> targetPage = targetManagement.findTargetByUpdateStatus(PAGE, TargetUpdateStatus.IN_SYNC);
final List<Target> targetList = targetPage.getContent();
// 15 targets in finished/IN_SYNC status and same DS assigned
assertThat(targetList.size()).isEqualTo(amountTargetsForRollout);
@@ -767,7 +768,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3);
rolloutManagement.handleRollouts();
// verify: 40% error but 60% finished -> should move to next group
final List<RolloutGroup> rolloutGruops = rolloutOne.getRolloutGroups();
final List<RolloutGroup> rolloutGruops = rolloutGroupManagement
.findRolloutGroupsByRolloutId(rolloutOne.getId(), PAGE).getContent();
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 5L);
validateRolloutGroupActionStatus(rolloutGruops.get(1), expectedTargetCountStatus);
@@ -792,8 +794,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutManagement.handleRollouts();
// verify: 40% error and 60% finished -> should not move to next group
// because successCondition 80%
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
final List<RolloutGroup> rolloutGruops = rolloutOne.getRolloutGroups();
final List<RolloutGroup> rolloutGruops = rolloutGroupManagement
.findRolloutGroupsByRolloutId(rolloutOne.getId(), PAGE).getContent();
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.SCHEDULED, 5L);
validateRolloutGroupActionStatus(rolloutGruops.get(1), expectedTargetCountStatus);
@@ -1000,14 +1002,17 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
float percent = rolloutGroupManagement
.findRolloutGroupWithDetailedStatus(myRollout.getRolloutGroups().get(0).getId()).get()
.getTotalTargetCountStatus().getFinishedPercent();
.findRolloutGroupWithDetailedStatus(rolloutGroupManagement
.findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent().get(0).getId())
.get().getTotalTargetCountStatus().getFinishedPercent();
assertThat(percent).isEqualTo(40);
changeStatusForRunningActions(myRollout, Status.FINISHED, 3);
rolloutManagement.handleRollouts();
percent = rolloutGroupManagement.findRolloutGroupWithDetailedStatus(myRollout.getRolloutGroups().get(0).getId())
percent = rolloutGroupManagement
.findRolloutGroupWithDetailedStatus(rolloutGroupManagement
.findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent().get(0).getId())
.get().getTotalTargetCountStatus().getFinishedPercent();
assertThat(percent).isEqualTo(100);
@@ -1015,7 +1020,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
changeStatusForAllRunningActions(myRollout, Status.ERROR);
rolloutManagement.handleRollouts();
percent = rolloutGroupManagement.findRolloutGroupWithDetailedStatus(myRollout.getRolloutGroups().get(1).getId())
percent = rolloutGroupManagement
.findRolloutGroupWithDetailedStatus(rolloutGroupManagement
.findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent().get(1).getId())
.get().getTotalTargetCountStatus().getFinishedPercent();
assertThat(percent).isEqualTo(80);
}
@@ -1043,7 +1050,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutManagement.handleRollouts();
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
final List<RolloutGroup> rolloutGroups = myRollout.getRolloutGroups();
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement
.findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent();
Page<Target> targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0).getId(),
rsqlParam, new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "controllerId")));
@@ -1075,13 +1083,10 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
try {
testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups, "id==notExisting",
distributionSet, successCondition, errorCondition);
fail("Was able to create a Rollout without targets.");
} catch (final ConstraintViolationException e) {
// OK
}
assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups,
"id==notExisting", distributionSet, successCondition, errorCondition))
.withMessageContaining("does not match any existing");
}
@@ -1100,14 +1105,10 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups, "id==dup-ro-*", distributionSet,
successCondition, errorCondition);
try {
testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups, "id==dup-ro-*", distributionSet,
successCondition, errorCondition);
fail("Was able to create a duplicate Rollout.");
} catch (final EntityAlreadyExistsException e) {
// OK
}
assertThatExceptionOfType(EntityAlreadyExistsException.class)
.isThrownBy(() -> testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups,
"id==dup-ro-*", distributionSet, successCondition, errorCondition))
.withMessageContaining("already exists in database");
}
@Test
@@ -1127,7 +1128,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
final List<RolloutGroup> groups = myRollout.getRolloutGroups();
final List<RolloutGroup> groups = rolloutGroupManagement
.findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent();
assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY);
assertThat(groups.get(0).getTotalTargets()).isEqualTo(1);
assertThat(groups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.READY);
@@ -1282,7 +1285,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING);
for (final RolloutGroup group : myRollout.getRolloutGroups()) {
for (final RolloutGroup group : rolloutGroupManagement.findRolloutGroupsByRolloutId(myRollout.getId(), PAGE)
.getContent()) {
assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.CREATING);
}
@@ -1297,7 +1301,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
assertThat(myRollout.getTotalTargets()).isEqualTo(amountTargetsInGroup1and2 + amountTargetsInGroup1);
final List<RolloutGroup> groups = myRollout.getRolloutGroups();
final List<RolloutGroup> groups = rolloutGroupManagement
.findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent();
;
assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY);
assertThat(groups.get(0).getTotalTargets()).isEqualTo(amountTargetsInGroup1);
@@ -1324,12 +1330,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutGroups.add(generateRolloutGroup(0, percentTargetsInGroup1, null));
rolloutGroups.add(generateRolloutGroup(1, percentTargetsInGroup2, null));
try {
rolloutManagement.createRollout(myRollout, rolloutGroups, conditions);
fail("Was able to create a Rollout with groups that are not addressing all targets");
} catch (final ConstraintViolationException e) {
// OK
}
assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> rolloutManagement.createRollout(myRollout, rolloutGroups, conditions))
.withMessageContaining("groups don't match");
}
@@ -1344,16 +1347,13 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().withDefaults().build();
final RolloutCreate myRollout = generateTargetsAndRollout(rolloutName, amountTargetsForRollout);
final List<RolloutGroupCreate> rolloutGroups = new ArrayList<>(2);
rolloutGroups.add(generateRolloutGroup(0, percentTargetsInGroup1, null));
rolloutGroups.add(generateRolloutGroup(1, percentTargetsInGroup2, null));
final List<RolloutGroupCreate> rolloutGroups = Arrays.asList(
generateRolloutGroup(0, percentTargetsInGroup1, null),
generateRolloutGroup(1, percentTargetsInGroup2, null));
try {
rolloutManagement.createRollout(myRollout, rolloutGroups, conditions);
fail("Was able to create a Rollout with groups that have illegal percentages");
} catch (final ConstraintViolationException e) {
// OK
}
assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> rolloutManagement.createRollout(myRollout, rolloutGroups, conditions))
.withMessageContaining("percentage has to be between 1 and 100");
}
@@ -1367,59 +1367,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().withDefaults().build();
final RolloutCreate myRollout = generateTargetsAndRollout(rolloutName, amountTargetsForRollout);
try {
rolloutManagement.createRollout(myRollout, illegalGroupAmount, conditions);
fail("Was able to create a Rollout with too many groups");
} catch (final ConstraintViolationException e) {
// OK
}
assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> rolloutManagement.createRollout(myRollout, illegalGroupAmount, conditions))
.withMessageContaining("not be greater than " + quotaManagement.getMaxRolloutGroupsPerRollout());
}
@Test
@Description("Verify Exception when a Rollout groups are queried for rollout that does not exist.")
public void findRolloutGroupsForRolloutThatDoesNotExist() throws Exception {
try {
rolloutGroupManagement.findAllRolloutGroupsWithDetailedStatus(1234L, pageReq);
fail("Was able to get Rollout group for rollout that does not exist.");
} catch (final EntityNotFoundException e) {
// OK
}
}
@Test
@Description("Verify Exception when targets are queried for rollout group that does not exist.")
public void findRolloutGroupTargetsForGroupThatDoesNotExist() throws Exception {
try {
rolloutGroupManagement.findRolloutGroupTargets(1234L, pageReq);
fail("Was able to get Rollout group targets for rollout group that does not exist.");
} catch (final EntityNotFoundException e) {
// OK
}
}
@Test
@Description("Verify Exception when targets are queried for rollout group that does not exist.")
public void findRolloutGroupTargetWithActionsForGroupThatDoesNotExist() throws Exception {
try {
rolloutGroupManagement.findAllTargetsWithActionStatus(pageReq, 1234L);
fail("Was able to get Rollout group targets for rollout group that does not exist.");
} catch (final EntityNotFoundException e) {
// OK
}
}
@Test
@Description("Verify Exception when targets are counted for rollout group that does not exist.")
public void countRolloutGroupTargetWithActionsForGroupThatDoesNotExist() throws Exception {
try {
rolloutGroupManagement.countTargetsOfRolloutsGroup(1234L);
fail("Was able to count Rollout group targets for rollout group that does not exist.");
} catch (final EntityNotFoundException e) {
// OK
}
}
@Test
@Description("Verify the start of a Rollout does not work during creation phase.")
public void createAndStartRolloutDuringCreationFails() throws Exception {
@@ -1445,12 +1398,10 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING);
try {
rolloutManagement.startRollout(myRollout.getId());
fail("Was able to start a Rollout in CREATING status");
} catch (final RolloutIllegalStateException e) {
// OK
}
final Long rolloutId = myRollout.getId();
assertThatExceptionOfType(RolloutIllegalStateException.class)
.isThrownBy(() -> rolloutManagement.startRollout(rolloutId))
.withMessageContaining("can only be started in state ready");
}
@@ -1506,7 +1457,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutManagement.handleRollouts();
// verify we have running actions
assertThat(actionRepository.findByRolloutIdAndStatus(pageReq, createdRollout.getId(), Status.RUNNING)
assertThat(actionRepository.findByRolloutIdAndStatus(PAGE, createdRollout.getId(), Status.RUNNING)
.getNumberOfElements()).isEqualTo(2);
// test
@@ -1523,16 +1474,16 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
.updateRollout(entityFactory.rollout().update(createdRollout.getId()).description("test")))
.withMessageContaining("" + createdRollout.getId());
assertThat(rolloutManagement.findAll(pageReq, true).getContent()).hasSize(1);
assertThat(rolloutManagement.findAll(pageReq, false).getContent()).hasSize(0);
assertThat(rolloutGroupManagement.findAllRolloutGroupsWithDetailedStatus(createdRollout.getId(), pageReq)
assertThat(rolloutManagement.findAll(PAGE, true).getContent()).hasSize(1);
assertThat(rolloutManagement.findAll(PAGE, false).getContent()).hasSize(0);
assertThat(rolloutGroupManagement.findAllRolloutGroupsWithDetailedStatus(createdRollout.getId(), PAGE)
.getContent()).hasSize(amountGroups);
// verify that all scheduled actions are deleted
assertThat(actionRepository.findByRolloutIdAndStatus(pageReq, deletedRollout.getId(), Status.SCHEDULED)
assertThat(actionRepository.findByRolloutIdAndStatus(PAGE, deletedRollout.getId(), Status.SCHEDULED)
.getNumberOfElements()).isEqualTo(0);
// verify that all running actions keep running
assertThat(actionRepository.findByRolloutIdAndStatus(pageReq, deletedRollout.getId(), Status.RUNNING)
assertThat(actionRepository.findByRolloutIdAndStatus(PAGE, deletedRollout.getId(), Status.RUNNING)
.getNumberOfElements()).isEqualTo(2);
}

View File

@@ -112,7 +112,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> softwareManagement.deleteSoftwareModuleType(NOT_EXIST_IDL), "SoftwareModuleType");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleByAssignedTo(pageReq, NOT_EXIST_IDL),
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleByAssignedTo(PAGE, NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(
@@ -122,11 +122,12 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleMetadata(NOT_EXIST_IDL, NOT_EXIST_ID),
"SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(NOT_EXIST_IDL),
verifyThrownExceptionBy(
() -> softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(PAGE, NOT_EXIST_IDL),
"SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(NOT_EXIST_IDL,
"name==*", pageReq), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModulesByType(pageReq, NOT_EXIST_IDL),
"name==*", PAGE), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModulesByType(PAGE, NOT_EXIST_IDL),
"SoftwareModule");
verifyThrownExceptionBy(
@@ -241,29 +242,29 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
ds = (JpaDistributionSet) assignSet(target, ds).getDistributionSet();
// standard searches
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType.getId()).getContent())
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "poky", osType.getId()).getContent())
.hasSize(1);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType.getId()).getContent().get(0))
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "poky", osType.getId()).getContent().get(0))
.isEqualTo(os);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType.getId()).getContent())
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "oracle%", runtimeType.getId()).getContent())
.hasSize(1);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType.getId()).getContent()
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "oracle%", runtimeType.getId()).getContent()
.get(0)).isEqualTo(jvm);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType.getId()).getContent())
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0.1", appType.getId()).getContent())
.hasSize(1);
assertThat(
softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType.getId()).getContent().get(0))
softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0.1", appType.getId()).getContent().get(0))
.isEqualTo(ah);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent())
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent())
.hasSize(2);
// no we search with on entity marked as deleted
softwareManagement.deleteSoftwareModule(
softwareModuleRepository.findByAssignedToAndType(pageReq, ds, appType).getContent().get(0).getId());
softwareModuleRepository.findByAssignedToAndType(PAGE, ds, appType).getContent().get(0).getId());
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent())
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent())
.hasSize(1);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent().get(0))
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent().get(0))
.isEqualTo(ah);
}
@@ -272,7 +273,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(ds);
final Action action = actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent().get(0);
final Action action = actionRepository.findByTargetAndDistributionSet(PAGE, target, ds).getContent().get(0);
assertThat(action).isNotNull();
return action;
}
@@ -297,7 +298,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
softwareManagement.deleteSoftwareModule(testdataFactory.createSoftwareModuleOs("deleted").getId());
testdataFactory.createSoftwareModuleApp();
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent())
assertThat(softwareManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent())
.as("Expected to find the following number of modules:").hasSize(2).as("with the following elements")
.contains(two, one);
}
@@ -319,18 +320,18 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests the successfull deletion of software module types. Both unused (hard delete) and used ones (soft delete).")
public void deleteAssignedAndUnassignedSoftwareModuleTypes() {
assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(3).contains(osType, runtimeType,
assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType, runtimeType,
appType);
SoftwareModuleType type = softwareManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("bundle").name("OSGi Bundle"));
assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(4).contains(osType, runtimeType,
assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(4).contains(osType, runtimeType,
appType, type);
// delete unassigned
softwareManagement.deleteSoftwareModuleType(type.getId());
assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(3).contains(osType, runtimeType,
assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType, runtimeType,
appType);
assertThat(softwareModuleTypeRepository.findAll()).hasSize(3).contains((JpaSoftwareModuleType) osType,
(JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType);
@@ -338,7 +339,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
type = softwareManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("bundle2").name("OSGi Bundle2"));
assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(4).contains(osType, runtimeType,
assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(4).contains(osType, runtimeType,
appType, type);
softwareManagement.createSoftwareModule(
@@ -346,7 +347,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// delete assigned
softwareManagement.deleteSoftwareModuleType(type.getId());
assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(3).contains(osType, runtimeType,
assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType, runtimeType,
appType);
assertThat(softwareModuleTypeRepository.findAll()).hasSize(4).contains((JpaSoftwareModuleType) osType,
@@ -397,7 +398,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// verify: assignedModule is marked as deleted
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId()).get();
assertTrue("The module should be flagged as deleted", assignedModule.isDeleted());
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(0);
assertThat(softwareModuleRepository.findAll()).hasSize(1);
// verify: binary data is deleted
@@ -437,7 +438,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// verify: assignedModule is marked as deleted
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId()).get();
assertTrue("The found module should be flagged deleted", assignedModule.isDeleted());
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(0);
assertThat(softwareModuleRepository.findAll()).hasSize(1);
// verify: binary data is deleted
@@ -538,7 +539,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
assertThat(moduleY).isNotNull();
assertTrue("The module should be flagged deleted", moduleX.isDeleted());
assertTrue("The module should be flagged deleted", moduleY.isDeleted());
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(0);
assertThat(softwareModuleRepository.findAll()).hasSize(2);
// verify: binary data of artifact is deleted
@@ -621,21 +622,21 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
softwareManagement.deleteSoftwareModule(deleted.getId());
// with filter on name, version and module type
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq,
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE,
set.getId(), "%found%", testType.getId()).getContent())
.as("Found modules with given name, given module type and the assigned ones first")
.containsExactly(new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true),
new AssignedSoftwareModule(unassigned, false));
// with filter on module type only
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq,
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE,
set.getId(), null, testType.getId()).getContent())
.as("Found modules with given module type and the assigned ones first").containsExactly(
new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(one, true),
new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(unassigned, false));
// without any filter
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq,
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE,
set.getId(), null, null).getContent()).as("Found modules with the assigned ones first").containsExactly(
new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(one, true),
new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(four, true),
@@ -773,7 +774,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.getId()).getContent())
assertThat(softwareManagement.findSoftwareModuleByAssignedTo(PAGE, set.getId()).getContent())
.as("Found this number of modules").hasSize(2);
}
@@ -882,13 +883,13 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
.createSoftwareModuleMetadata(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1))
.getSoftwareModule();
assertThat(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(ah.getId()))
.as("Contains the created metadata element")
.containsExactly(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1));
assertThat(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(new PageRequest(0, 100), ah.getId())
.getContent()).as("Contains the created metadata element")
.containsExactly(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1));
softwareManagement.deleteSoftwareModuleMetadata(ah.getId(), knownKey1);
assertThat(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(ah.getId()))
.as("Metadata elemenets are").isEmpty();
assertThat(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(new PageRequest(0, 100), ah.getId())
.getContent()).as("Metadata elemenets are").isEmpty();
}
@Test

View File

@@ -33,11 +33,11 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Ensures that findTenants returns all tenants and not only restricted to the tenant which currently is logged in")
public void findTenantsReturnsAllTenantsNotOnlyWhichLoggedIn() throws Exception {
assertThat(systemManagement.findTenants()).hasSize(1);
assertThat(systemManagement.findTenants(PAGE).getContent()).hasSize(1);
createTestTenantsForSystemStatistics(2, 0, 0, 0);
assertThat(systemManagement.findTenants()).hasSize(3);
assertThat(systemManagement.findTenants(PAGE).getContent()).hasSize(3);
}
@Test

View File

@@ -19,9 +19,9 @@ import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -64,16 +64,21 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = DistributionSetTagUpdateEvent.class, count = 0),
@Expect(type = TargetTagUpdateEvent.class, count = 0) })
@ExpectEvents({ @Expect(type = DistributionSetTagUpdatedEvent.class, count = 0),
@Expect(type = TargetTagUpdatedEvent.class, count = 0) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
verifyThrownExceptionBy(() -> tagManagement.deleteDistributionSetTag(NOT_EXIST_ID), "DistributionSetTag");
verifyThrownExceptionBy(() -> tagManagement.deleteTargetTag(NOT_EXIST_ID), "TargetTag");
verifyThrownExceptionBy(() -> tagManagement.findDistributionSetTagsByDistributionSet(PAGE, NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(() -> tagManagement.updateDistributionSetTag(entityFactory.tag().update(NOT_EXIST_IDL)),
"DistributionSetTag");
verifyThrownExceptionBy(() -> tagManagement.updateTargetTag(entityFactory.tag().update(NOT_EXIST_IDL)),
"TargetTag");
verifyThrownExceptionBy(() -> tagManagement.findAllTargetTags(PAGE, NOT_EXIST_ID), "Target");
}
@Test
@@ -118,7 +123,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
assertEquals("filter works not correct",
dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build())
distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
@@ -126,7 +131,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
assertEquals("filter works not correct",
dsBs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build())
distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
@@ -134,13 +139,13 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
assertEquals("filter works not correct",
dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build())
distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
.setTagNames(Lists.newArrayList(tagX.getName()));
assertEquals("filter works not correct", 0, distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getTotalElements());
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getTotalElements());
assertEquals("wrong tag size", 5, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown());
@@ -157,20 +162,20 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
assertEquals("filter works not correct",
dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build())
distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setTagNames(Lists.newArrayList(tagB.getName()));
assertEquals("filter works not correct", 0, distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getTotalElements());
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setTagNames(Lists.newArrayList(tagC.getName()));
assertEquals("filter works not correct",
dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build())
distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getTotalElements());
}
@@ -193,7 +198,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
assertThat(result.getAssigned()).isEqualTo(20);
assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement
.findDistributionSetsAll(groupA.stream().map(set -> set.getId()).collect(Collectors.toList())));
.findDistributionSetsById(groupA.stream().map(DistributionSet::getId).collect(Collectors.toList())));
assertThat(result.getUnassigned()).isEqualTo(0);
assertThat(result.getUnassignedEntity()).isEmpty();
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
@@ -203,7 +208,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
assertThat(result.getAlreadyAssigned()).isEqualTo(20);
assertThat(result.getAssigned()).isEqualTo(20);
assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement
.findDistributionSetsAll(groupB.stream().map(set -> set.getId()).collect(Collectors.toList())));
.findDistributionSetsById(groupB.stream().map(DistributionSet::getId).collect(Collectors.toList())));
assertThat(result.getUnassigned()).isEqualTo(0);
assertThat(result.getUnassignedEntity()).isEmpty();
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
@@ -214,8 +219,8 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
assertThat(result.getAssigned()).isEqualTo(0);
assertThat(result.getAssignedEntity()).isEmpty();
assertThat(result.getUnassigned()).isEqualTo(40);
assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement.findDistributionSetsAll(
concat(groupB, groupA).stream().map(set -> set.getId()).collect(Collectors.toList())));
assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement.findDistributionSetsById(
concat(groupB, groupA).stream().map(DistributionSet::getId).collect(Collectors.toList())));
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
}
@@ -234,7 +239,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
TargetTagAssignmentResult result = toggleTagAssignment(groupA, tag);
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
assertThat(result.getAssigned()).isEqualTo(20);
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetByControllerID(
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerID(
groupA.stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
assertThat(result.getUnassigned()).isEqualTo(0);
assertThat(result.getUnassignedEntity()).isEmpty();
@@ -244,7 +249,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
result = toggleTagAssignment(concat(groupA, groupB), tag);
assertThat(result.getAlreadyAssigned()).isEqualTo(20);
assertThat(result.getAssigned()).isEqualTo(20);
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetByControllerID(
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerID(
groupB.stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
assertThat(result.getUnassigned()).isEqualTo(0);
assertThat(result.getUnassignedEntity()).isEmpty();
@@ -256,7 +261,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
assertThat(result.getAssigned()).isEqualTo(0);
assertThat(result.getAssignedEntity()).isEmpty();
assertThat(result.getUnassigned()).isEqualTo(40);
assertThat(result.getUnassignedEntity()).containsAll(targetManagement.findTargetByControllerID(
assertThat(result.getUnassignedEntity()).containsAll(targetManagement.findTargetsByControllerID(
concat(groupB, groupA).stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
assertThat(result.getTargetTag()).isEqualTo(tag);
@@ -300,7 +305,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
final TargetTag toDelete = tags.iterator().next();
for (final Target target : targetRepository.findAll()) {
assertThat(tagManagement.findAllTargetTags(pageReq, target.getControllerId()).getContent())
assertThat(tagManagement.findAllTargetTags(PAGE, target.getControllerId()).getContent())
.contains(toDelete);
}
@@ -309,7 +314,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
// check
for (final Target target : targetRepository.findAll()) {
assertThat(tagManagement.findAllTargetTags(pageReq, target.getControllerId()).getContent())
assertThat(tagManagement.findAllTargetTags(PAGE, target.getControllerId()).getContent())
.doesNotContain(toDelete);
}
assertThat(targetTagRepository.findOne(toDelete.getId())).as("No tag should be found").isNull();
@@ -365,8 +370,8 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
final DistributionSetTag toDelete = tags.iterator().next();
for (final DistributionSet set : distributionSetRepository.findAll()) {
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).get().getTags())
.as("Wrong tag found").contains(toDelete);
assertThat(distributionSetRepository.findOne(set.getId()).getTags()).as("Wrong tag found")
.contains(toDelete);
}
// delete
@@ -374,10 +379,12 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
// check
assertThat(distributionSetTagRepository.findOne(toDelete.getId())).as("Deleted tag should be null").isNull();
assertThat(tagManagement.findAllDistributionSetTags()).as("Wrong size of tags after deletion").hasSize(19);
assertThat(tagManagement.findAllDistributionSetTags(PAGE).getContent())
.as("Wrong size of tags after deletion").hasSize(19);
for (final DistributionSet set : distributionSetRepository.findAll()) {
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).get().getTags())
.as("Wrong found tags").doesNotContain(toDelete);
assertThat(distributionSetRepository.findOne(set.getId()).getTags()).as("Wrong found tags")
.doesNotContain(toDelete);
}
}
@@ -448,7 +455,8 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
tagManagement.updateDistributionSetTag(entityFactory.tag().update(savedAssigned.getId()).name("test123"));
// check data
assertThat(tagManagement.findAllDistributionSetTags()).as("Wrong size of ds tags").hasSize(tags.size());
assertThat(tagManagement.findAllDistributionSetTags(PAGE).getContent()).as("Wrong size of ds tags")
.hasSize(tags.size());
assertThat(distributionSetTagRepository.findOne(savedAssigned.getId()).getName()).as("Wrong ds tag found")
.isEqualTo("test123");
}
@@ -459,7 +467,8 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
final List<DistributionSetTag> tags = createDsSetsWithTags();
// test
assertThat(tagManagement.findAllDistributionSetTags()).as("Wrong size of tags").hasSize(tags.size());
assertThat(tagManagement.findAllDistributionSetTags(PAGE).getContent()).as("Wrong size of tags")
.hasSize(tags.size());
assertThat(distributionSetTagRepository.findAll()).as("Wrong size of tags").hasSize(20);
}
@@ -479,6 +488,6 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
tags.forEach(tag -> toggleTagAssignment(sets, tag));
return tagManagement.findAllDistributionSetTags();
return tagManagement.findAllDistributionSetTags(PAGE).getContent();
}
}

View File

@@ -68,7 +68,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
verifyThrownExceptionBy(() -> targetFilterQueryManagement.deleteTargetFilterQuery(NOT_EXIST_IDL),
"TargetFilterQuery");
verifyThrownExceptionBy(() -> targetFilterQueryManagement.findTargetFilterQueryByAutoAssignDS(pageReq,
verifyThrownExceptionBy(() -> targetFilterQueryManagement.findTargetFilterQueryByAutoAssignDS(PAGE,
NOT_EXIST_IDL, "name==*"), "DistributionSet");
verifyThrownExceptionBy(

View File

@@ -107,11 +107,11 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
// get final updated version of targets
targAs = targetManagement
.findTargetByControllerID(targAs.stream().map(Target::getControllerId).collect(Collectors.toList()));
.findTargetsByControllerID(targAs.stream().map(Target::getControllerId).collect(Collectors.toList()));
targBs = targetManagement
.findTargetByControllerID(targBs.stream().map(Target::getControllerId).collect(Collectors.toList()));
.findTargetsByControllerID(targBs.stream().map(Target::getControllerId).collect(Collectors.toList()));
targCs = targetManagement
.findTargetByControllerID(targCs.stream().map(Target::getControllerId).collect(Collectors.toList()));
.findTargetsByControllerID(targCs.stream().map(Target::getControllerId).collect(Collectors.toList()));
// try to find several targets with different filter settings
verifyThat1TargetHasNameAndId("targ-A-special", targSpecialName.getControllerId());
@@ -123,14 +123,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
verifyThat0TargetsWithTagAndDescOrNameHasDS(targTagW, setA);
verifyThat0TargetsWithNameOrdescAndDSHaveTag(targTagX, setA);
verifyThat3TargetsHaveDSAssigned(setA,
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.findTargetByControllerID(assignedA).get());
List<Target> expected = concat(targAs, targBs, targCs, targDs);
expected.removeAll(
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
verifyThat397TargetsAreInStatusUnknown(unknown, expected);
expected = concat(targBs, targCs);
expected.removeAll(targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC)));
expected.removeAll(targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedB, assignedC)));
verifyThat198TargetsAreInStatusUnknownAndHaveGivenTags(targTagY, targTagW, unknown, expected);
verfyThat0TargetsAreInStatusUnknownAndHaveDSAssigned(setA, unknown);
expected = concat(targAs);
@@ -140,23 +140,23 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
expected.remove(targetManagement.findTargetByControllerID(assignedB).get());
verifyThat99TargetsWithGivenNameOrDescAndTagAreInStatusUnknown(targTagW, unknown, expected);
verifyThat3TargetsAreInStatusPending(pending,
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
verifyThat3TargetsWithGivenDSAreInPending(setA, pending,
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
verifyThat1TargetWithGivenNameOrDescAndDSIsInPending(setA, pending,
targetManagement.findTargetByControllerID(assignedA).get());
verifyThat1TargetWithGivenNameOrDescAndTagAndDSIsInPending(targTagW, setA, pending,
targetManagement.findTargetByControllerID(assignedB).get());
verifyThat2TargetsWithGivenTagAndDSIsInPending(targTagW, setA, pending,
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC)));
targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedB, assignedC)));
verifyThat2TargetsWithGivenTagAreInPending(targTagW, pending,
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC)));
targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedB, assignedC)));
verifyThat200targetsWithGivenTagAreInStatusPendingorUnknown(targTagW, both, concat(targBs, targCs));
verfiyThat1TargetAIsInStatusPendingAndHasDSInstalled(installedSet, pending,
targetManagement.findTargetByControllerID(installedC).get());
expected = concat(targBs, targCs);
expected.removeAll(targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC)));
expected.removeAll(targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedB, assignedC)));
verifyThat198TargetsAreInStatusUnknownAndOverdue(unknown, expected);
}
@@ -165,14 +165,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final List<TargetUpdateStatus> pending, final Target expected) {
final String query = "updatestatus==pending and installedds.name==" + installedSet.getName();
assertThat(targetManagement
.findTargetByFilters(pageReq, pending, null, null, installedSet.getId(), Boolean.FALSE, new String[0])
.findTargetByFilters(PAGE, pending, null, null, installedSet.getId(), Boolean.FALSE, new String[0])
.getContent()).as("has number of elements").hasSize(1)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null,
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@@ -182,13 +182,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final String query = "(updatestatus==pending or updatestatus==unknown) and tag==" + targTagW.getName();
assertThat(targetManagement
.findTargetByFilters(pageReq, both, null, null, null, Boolean.FALSE, targTagW.getName()).getContent())
.findTargetByFilters(PAGE, both, null, null, null, Boolean.FALSE, targTagW.getName()).getContent())
.as("has number of elements").hasSize(200).as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(both, null, null, 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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@Step
@@ -197,14 +197,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final String query = "updatestatus==pending and tag==" + targTagW.getName();
assertThat(targetManagement
.findTargetByFilters(pageReq, pending, null, null, null, Boolean.FALSE, targTagW.getName())
.findTargetByFilters(PAGE, pending, null, null, null, Boolean.FALSE, targTagW.getName())
.getContent()).as("has number of elements").hasSize(2)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, 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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@Step
@@ -214,14 +214,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
+ setA.getName() + ") and tag==" + targTagW.getName();
assertThat(targetManagement
.findTargetByFilters(pageReq, pending, null, null, setA.getId(), Boolean.FALSE, targTagW.getName())
.findTargetByFilters(PAGE, pending, null, null, setA.getId(), Boolean.FALSE, targTagW.getName())
.getContent()).as("has number of elements").hasSize(2)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null,
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@Step
@@ -230,14 +230,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final String query = "updatestatus==pending and (assignedds.name==" + setA.getName() + " or installedds.name=="
+ setA.getName() + ") and (name==*targ-B* or description==*targ-B*) and tag==" + targTagW.getName();
assertThat(targetManagement.findTargetByFilters(pageReq, pending, null, "%targ-B%", setA.getId(), Boolean.FALSE,
assertThat(targetManagement.findTargetByFilters(PAGE, pending, null, "%targ-B%", setA.getId(), Boolean.FALSE,
targTagW.getName()).getContent()).as("has number of elements").hasSize(1)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, "%targ-B%",
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@Step
@@ -247,14 +247,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
+ setA.getName() + ") and (name==*targ-A* or description==*targ-A*)";
assertThat(targetManagement
.findTargetByFilters(pageReq, pending, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0])
.findTargetByFilters(PAGE, pending, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0])
.getContent()).as("has number of elements").hasSize(1)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, "%targ-A%",
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@Step
@@ -264,14 +264,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
+ setA.getName() + ")";
assertThat(targetManagement
.findTargetByFilters(pageReq, pending, null, null, setA.getId(), Boolean.FALSE, new String[0])
.findTargetByFilters(PAGE, pending, null, null, setA.getId(), Boolean.FALSE, new String[0])
.getContent()).as("has number of elements").hasSize(3)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null,
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@Step
@@ -280,13 +280,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final String query = "updatestatus==pending";
assertThat(targetManagement
.findTargetByFilters(pageReq, pending, null, null, null, Boolean.FALSE, new String[0]).getContent())
.findTargetByFilters(PAGE, pending, null, null, null, Boolean.FALSE, new String[0]).getContent())
.as("has number of elements").hasSize(3).as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, 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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@Step
@@ -296,14 +296,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
+ targTagW.getName();
assertThat(targetManagement
.findTargetByFilters(pageReq, unknown, null, "%targ-B%", null, Boolean.FALSE, targTagW.getName())
.findTargetByFilters(PAGE, unknown, null, "%targ-B%", null, Boolean.FALSE, targTagW.getName())
.getContent()).as("has number of elements").hasSize(99)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, "%targ-B%",
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@Step
@@ -312,14 +312,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final String query = "updatestatus==unknown and (name==*targ-A* or description==*targ-A*)";
assertThat(targetManagement
.findTargetByFilters(pageReq, unknown, null, "%targ-A%", null, Boolean.FALSE, new String[0])
.findTargetByFilters(PAGE, unknown, null, "%targ-A%", null, Boolean.FALSE, new String[0])
.getContent()).as("has number of elements").hasSize(99)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, "%targ-A%",
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@@ -330,13 +330,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
+ setA.getName() + ")";
assertThat(targetManagement
.findTargetByFilters(pageReq, unknown, null, null, setA.getId(), Boolean.FALSE, new String[0])
.findTargetByFilters(PAGE, unknown, null, null, setA.getId(), Boolean.FALSE, new String[0])
.getContent()).as("has number of elements").hasSize(0)
.as("that number is also returned by count query")
.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());
.hasSize(targetManagement.findTargetsAll(query, PAGE).getContent().size());
}
@Step
@@ -345,14 +345,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final String query = "updatestatus==unknown and (tag==" + targTagY.getName() + " or tag==" + targTagW.getName()
+ ")";
assertThat(targetManagement.findTargetByFilters(pageReq, unknown, null, null, null, Boolean.FALSE,
assertThat(targetManagement.findTargetByFilters(PAGE, unknown, null, null, null, Boolean.FALSE,
targTagY.getName(), targTagW.getName()).getContent()).as("has number of elements").hasSize(198)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null, null,
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@Step
@@ -361,13 +361,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final String query = "updatestatus==unknown";
assertThat(targetManagement
.findTargetByFilters(pageReq, unknown, null, null, null, Boolean.FALSE, new String[0]).getContent())
.findTargetByFilters(PAGE, unknown, null, null, null, Boolean.FALSE, new String[0]).getContent())
.as("has number of elements").hasSize(397).as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null, 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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@@ -378,14 +378,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final String query = "lastcontrollerrequestat=le=${overdue_ts};updatestatus==UNKNOWN";
assertThat(targetManagement
.findTargetByFilters(pageReq, unknown, Boolean.TRUE, null, null, Boolean.FALSE, new String[0])
.findTargetByFilters(PAGE, unknown, Boolean.TRUE, null, null, Boolean.FALSE, new String[0])
.getContent()).as("has number of elements").hasSize(198)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, Boolean.TRUE, null,
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@Step
@@ -394,14 +394,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
+ " or installedds.name==" + setA.getName() + ")";
assertThat(targetManagement
.findTargetByFilters(pageReq, null, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0])
.findTargetByFilters(PAGE, null, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0])
.getContent()).as("has number of elements").hasSize(1)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-A%",
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@@ -410,14 +410,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final String query = "assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName();
assertThat(targetManagement
.findTargetByFilters(pageReq, null, null, null, setA.getId(), Boolean.FALSE, new String[0])
.findTargetByFilters(PAGE, null, null, null, setA.getId(), Boolean.FALSE, new String[0])
.getContent()).as("has number of elements").hasSize(3)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, null,
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@@ -426,13 +426,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final String query = "(name==*targ-C* or description==*targ-C*) and tag==" + targTagX.getName()
+ " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")";
assertThat(targetManagement
.findTargetByFilters(pageReq, null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagX.getName())
.findTargetByFilters(PAGE, null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagX.getName())
.getContent()).as("has number of elements").hasSize(0)
.as("that number is also returned by count query")
.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());
.hasSize(targetManagement.findTargetsAll(query, PAGE).getContent().size());
}
@@ -441,13 +441,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final String query = "(name==*targ-A* or description==*targ-A*) and tag==" + targTagW.getName()
+ " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")";
assertThat(targetManagement
.findTargetByFilters(pageReq, null, null, "%targ-A%", setA.getId(), Boolean.FALSE, targTagW.getName())
.findTargetByFilters(PAGE, null, null, "%targ-A%", setA.getId(), Boolean.FALSE, targTagW.getName())
.getContent()).as("has number of elements").hasSize(0)
.as("that number is also returned by count query")
.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());
.hasSize(targetManagement.findTargetsAll(query, PAGE).getContent().size());
}
@@ -457,24 +457,24 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final String query = "(name==*targ-c* or description==*targ-C*) and tag==" + targTagW.getName()
+ " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")";
assertThat(targetManagement
.findTargetByFilters(pageReq, null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagW.getName())
.findTargetByFilters(PAGE, null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagW.getName())
.getContent()).as("has number of elements").hasSize(1)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-C%",
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@Step
private void verifyThat1TargetHasNameAndId(final String name, final String controllerId) {
assertThat(targetManagement.findTargetByFilters(pageReq, null, null, name, null, Boolean.FALSE).getContent())
assertThat(targetManagement.findTargetByFilters(PAGE, 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)
assertThat(targetManagement.findTargetByFilters(PAGE, 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)));
@@ -485,14 +485,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
final TargetTag targTagW, final List<Target> expected) {
final String query = "(name==*targ-B* or description==*targ-B*) and (tag==" + targTagY.getName() + " or tag=="
+ targTagW.getName() + ")";
assertThat(targetManagement.findTargetByFilters(pageReq, null, null, "%targ-B%", null, Boolean.FALSE,
assertThat(targetManagement.findTargetByFilters(PAGE, null, null, "%targ-B%", null, Boolean.FALSE,
targTagY.getName(), targTagW.getName()).getContent()).as("has number of elements").hasSize(100)
.as("that number is also returned by count query")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-B%", null,
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@@ -507,26 +507,26 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
private void verifyThat200TargetsHaveTagD(final TargetTag targTagD, final List<Target> expected) {
final String query = "tag==" + targTagD.getName();
assertThat(targetManagement
.findTargetByFilters(pageReq, null, null, null, null, Boolean.FALSE, targTagD.getName()).getContent())
.findTargetByFilters(PAGE, null, null, null, null, Boolean.FALSE, targTagD.getName()).getContent())
.as("Expected number of results is").hasSize(200)
.as("and is expected number of results is equal to ")
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, null, null,
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());
.containsAll(targetManagement.findTargetsAll(query, PAGE).getContent());
}
@Step
private void verifyThatRepositoryContains400Targets() {
assertThat(
targetManagement.findTargetByFilters(pageReq, null, null, null, null, null, new String[0]).getContent())
targetManagement.findTargetByFilters(PAGE, null, null, null, null, null, new String[0]).getContent())
.as("Overall we expect that many targets in the repository").hasSize(400)
.as("which is also reflected by repository count")
.hasSize(Ints.saturatedCast(targetManagement.countTargetsAll()))
.as("which is also reflected by call without specification")
.containsAll(targetManagement.findTargetsAll(pageReq).getContent());
.containsAll(targetManagement.findTargetsAll(PAGE).getContent());
}
@@ -546,7 +546,7 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
.sendUpdateActionStatusToTargets(targInstalled, Status.FINISHED, Collections.singletonList("installed"))
.stream().map(Action::getTarget).collect(Collectors.toList());
final Slice<Target> result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(pageReq, ds.getId(),
final Slice<Target> result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(PAGE, ds.getId(),
new FilterParams(null, null, null, null, Boolean.FALSE, new String[0]));
final Comparator<TenantAwareBaseEntity> byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId());
@@ -594,9 +594,9 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
targInstalled = assignDistributionSet(ds, targInstalled).getAssignedEntity();
targInstalled = testdataFactory
.sendUpdateActionStatusToTargets(targInstalled, Status.FINISHED, Collections.singletonList("installed"))
.stream().map(action -> action.getTarget()).collect(Collectors.toList());
.stream().map(Action::getTarget).collect(Collectors.toList());
final Slice<Target> result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(pageReq, ds.getId(),
final Slice<Target> result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(PAGE, ds.getId(),
new FilterParams(null, null, Boolean.TRUE, null, Boolean.FALSE, new String[0]));
final Comparator<TenantAwareBaseEntity> byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId());
@@ -627,10 +627,10 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
assignDistributionSet(assignedSet, assignedtargets);
// get final updated version of targets
assignedtargets = targetManagement.findTargetByControllerID(
assignedtargets = targetManagement.findTargetsByControllerID(
assignedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
assertThat(targetManagement.findTargetByAssignedDistributionSet(assignedSet.getId(), pageReq))
assertThat(targetManagement.findTargetByAssignedDistributionSet(assignedSet.getId(), PAGE))
.as("Contains the assigned targets").containsAll(assignedtargets)
.as("and that means the following expected amount").hasSize(10);
@@ -648,7 +648,7 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
assignDistributionSet(assignedSet, assignedTargets);
final List<Target> result = targetManagement
.findAllTargetsByTargetFilterQueryAndNonDS(pageReq, assignedSet.getId(), tfq.getQuery()).getContent();
.findAllTargetsByTargetFilterQueryAndNonDS(PAGE, assignedSet.getId(), tfq.getQuery()).getContent();
assertThat(result).as("count of targets").hasSize(unassignedTargets.size()).as("contains all targets")
.containsAll(unassignedTargets);
@@ -668,10 +668,10 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
assignDistributionSet(assignedSet, installedtargets);
// get final updated version of targets
installedtargets = targetManagement.findTargetByControllerID(
installedtargets = targetManagement.findTargetsByControllerID(
installedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
assertThat(targetManagement.findTargetByInstalledDistributionSet(installedSet.getId(), pageReq))
assertThat(targetManagement.findTargetByInstalledDistributionSet(installedSet.getId(), PAGE))
.as("Contains the assigned targets").containsAll(installedtargets)
.as("and that means the following expected amount").hasSize(10);

View File

@@ -84,6 +84,10 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> targetManagement.assignTag(Lists.newArrayList(NOT_EXIST_ID), tag.getId()),
"Target");
verifyThrownExceptionBy(() -> targetManagement.findTargetsByTag(PAGE, NOT_EXIST_IDL), "TargetTag");
verifyThrownExceptionBy(() -> targetManagement.findTargetsByTag(PAGE, "name==*", NOT_EXIST_IDL),
"TargetTag");
verifyThrownExceptionBy(() -> targetManagement.countTargetByAssignedDistributionSet(NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(() -> targetManagement.countTargetByInstalledDistributionSet(NOT_EXIST_IDL),
@@ -99,21 +103,21 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> targetManagement.deleteTargets(Lists.newArrayList(NOT_EXIST_IDL)), "Target");
verifyThrownExceptionBy(
() -> targetManagement.findAllTargetsByTargetFilterQueryAndNonDS(pageReq, NOT_EXIST_IDL, "name==*"),
() -> targetManagement.findAllTargetsByTargetFilterQueryAndNonDS(PAGE, NOT_EXIST_IDL, "name==*"),
"DistributionSet");
verifyThrownExceptionBy(
() -> targetManagement.findAllTargetsInRolloutGroupWithoutAction(pageReq, NOT_EXIST_IDL),
() -> targetManagement.findAllTargetsInRolloutGroupWithoutAction(PAGE, NOT_EXIST_IDL),
"RolloutGroup");
verifyThrownExceptionBy(() -> targetManagement.findTargetByAssignedDistributionSet(NOT_EXIST_IDL, pageReq),
verifyThrownExceptionBy(() -> targetManagement.findTargetByAssignedDistributionSet(NOT_EXIST_IDL, PAGE),
"DistributionSet");
verifyThrownExceptionBy(
() -> targetManagement.findTargetByAssignedDistributionSet(NOT_EXIST_IDL, "name==*", pageReq),
() -> targetManagement.findTargetByAssignedDistributionSet(NOT_EXIST_IDL, "name==*", PAGE),
"DistributionSet");
verifyThrownExceptionBy(() -> targetManagement.findTargetByInstalledDistributionSet(NOT_EXIST_IDL, pageReq),
verifyThrownExceptionBy(() -> targetManagement.findTargetByInstalledDistributionSet(NOT_EXIST_IDL, PAGE),
"DistributionSet");
verifyThrownExceptionBy(
() -> targetManagement.findTargetByInstalledDistributionSet(NOT_EXIST_IDL, "name==*", pageReq),
() -> targetManagement.findTargetByInstalledDistributionSet(NOT_EXIST_IDL, "name==*", PAGE),
"DistributionSet");
verifyThrownExceptionBy(
@@ -122,7 +126,6 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(
() -> targetManagement.toggleTagAssignment(Lists.newArrayList(NOT_EXIST_ID), tag.getName()), "Target");
verifyThrownExceptionBy(() -> targetManagement.unAssignAllTargetsByTag(NOT_EXIST_IDL), "TargetTag");
verifyThrownExceptionBy(() -> targetManagement.unAssignTag(NOT_EXIST_ID, tag.getId()), "Target");
verifyThrownExceptionBy(() -> targetManagement.unAssignTag(target.getControllerId(), NOT_EXIST_IDL),
"TargetTag");
@@ -255,7 +258,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
@Description("Ensures that targets can assigned and unassigned to a target tag. Not exists target will be ignored for the assignment.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 4),
@Expect(type = TargetTagCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 8) })
@Expect(type = TargetUpdatedEvent.class, count = 5) })
public void assignAndUnassignTargetsToTag() {
final List<String> assignTarget = new ArrayList<>();
assignTarget.add(targetManagement.createTarget(entityFactory.target().create().controllerId("targetId123"))
@@ -272,26 +275,24 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
final List<Target> assignedTargets = targetManagement.assignTag(assignTarget, targetTag.getId());
assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4);
assignedTargets.forEach(target -> assertThat(
tagManagement.findAllTargetTags(pageReq, target.getControllerId()).getNumberOfElements()).isEqualTo(1));
tagManagement.findAllTargetTags(PAGE, target.getControllerId()).getNumberOfElements()).isEqualTo(1));
TargetTag findTargetTag = tagManagement.findTargetTag("Tag1").get();
assertThat(assignedTargets.size()).as("Assigned targets are wrong")
.isEqualTo(findTargetTag.getAssignedToTargets().size());
.isEqualTo(targetManagement.findTargetsByTag(PAGE, targetTag.getId()).getNumberOfElements());
final Target unAssignTarget = targetManagement.unAssignTag("targetId123", findTargetTag.getId());
assertThat(unAssignTarget.getControllerId()).as("Controller id is wrong").isEqualTo("targetId123");
assertThat(tagManagement.findAllTargetTags(pageReq, unAssignTarget.getControllerId())).as("Tag size is wrong")
assertThat(tagManagement.findAllTargetTags(PAGE, unAssignTarget.getControllerId())).as("Tag size is wrong")
.isEmpty();
findTargetTag = tagManagement.findTargetTag("Tag1").get();
assertThat(findTargetTag.getAssignedToTargets()).as("Assigned targets are wrong").hasSize(3);
assertThat(targetManagement.findTargetsByTag(PAGE, targetTag.getId())).as("Assigned targets are wrong")
.hasSize(3);
assertThat(targetManagement.findTargetsByTag(PAGE, "controllerId==targetId123", targetTag.getId()))
.as("Assigned targets are wrong").isEmpty();
assertThat(targetManagement.findTargetsByTag(PAGE, "controllerId==targetId1234", targetTag.getId()))
.as("Assigned targets are wrong").hasSize(1);
final List<Target> unAssignTargets = targetManagement.unAssignAllTargetsByTag(findTargetTag.getId());
findTargetTag = tagManagement.findTargetTag("Tag1").get();
assertThat(findTargetTag.getAssignedToTargets()).as("Unassigned targets are wrong").isEmpty();
assertThat(unAssignTargets).as("Unassigned targets are wrong").hasSize(3);
unAssignTargets.forEach(target -> assertThat(
tagManagement.findAllTargetTags(pageReq, unAssignTarget.getControllerId()).getNumberOfElements())
.isEqualTo(0));
}
@Test
@@ -426,7 +427,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
_target: for (final Target tl : targets) {
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get();
for (final Tag tt : tagManagement.findAllTargetTags(pageReq, tl.getControllerId())) {
for (final Tag tt : tagManagement.findAllTargetTags(PAGE, tl.getControllerId())) {
for (final Tag tag : tags) {
if (tag.getName().equals(tt.getName())) {
continue _target;
@@ -445,7 +446,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get();
for (final Tag tag : tags) {
for (final Tag tt : tagManagement.findAllTargetTags(pageReq, tl.getControllerId())) {
for (final Tag tt : tagManagement.findAllTargetTags(PAGE, tl.getControllerId())) {
if (tag.getName().equals(tt.getName())) {
fail("Target should have no tags");
}
@@ -577,15 +578,15 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
t2Tags.forEach(tag -> targetManagement.assignTag(Lists.newArrayList(t2.getControllerId()), tag.getId()));
final Target t11 = targetManagement.findTargetByControllerID(t1.getControllerId()).get();
assertThat(tagManagement.findAllTargetTags(pageReq, t11.getControllerId()).getContent()).as("Tag size is wrong")
assertThat(tagManagement.findAllTargetTags(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong")
.hasSize(noT1Tags).containsAll(t1Tags);
assertThat(tagManagement.findAllTargetTags(pageReq, t11.getControllerId()).getContent()).as("Tag size is wrong")
assertThat(tagManagement.findAllTargetTags(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong")
.hasSize(noT1Tags).doesNotContain(Iterables.toArray(t2Tags, TargetTag.class));
final Target t21 = targetManagement.findTargetByControllerID(t2.getControllerId()).get();
assertThat(tagManagement.findAllTargetTags(pageReq, t21.getControllerId()).getContent()).as("Tag size is wrong")
assertThat(tagManagement.findAllTargetTags(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong")
.hasSize(noT2Tags).containsAll(t2Tags);
assertThat(tagManagement.findAllTargetTags(pageReq, t21.getControllerId()).getContent()).as("Tag size is wrong")
assertThat(tagManagement.findAllTargetTags(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong")
.hasSize(noT2Tags).doesNotContain(Iterables.toArray(t1Tags, TargetTag.class));
}
@@ -731,7 +732,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
final String[] tagNames = null;
final List<Target> targetsListWithNoTag = targetManagement
.findTargetByFilters(pageReq, null, null, null, null, Boolean.TRUE, tagNames).getContent();
.findTargetByFilters(PAGE, null, null, null, null, Boolean.TRUE, tagNames).getContent();
assertThat(50L).as("Total targets").isEqualTo(targetManagement.countTargetsAll());
assertThat(25).as("Targets with no tag").isEqualTo(targetsListWithNoTag.size());
@@ -766,7 +767,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
testdataFactory.createTargets(25, "target-id-B", "first description");
final Page<Target> foundTargets = targetManagement.findTargetsAll(rsqlFilter, pageReq);
final Page<Target> foundTargets = targetManagement.findTargetsAll(rsqlFilter, PAGE);
assertThat(targetManagement.countTargetsAll()).as("Total targets").isEqualTo(50L);
assertThat(foundTargets.getTotalElements()).as("Targets in RSQL filter").isEqualTo(27L);
@@ -782,7 +783,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
testdataFactory.createTarget("test" + i);
}
final List<Target> foundDs = targetManagement.findTargetAllById(searchIds);
final List<Target> foundDs = targetManagement.findTargetsById(searchIds);
assertThat(foundDs).hasSize(3);

View File

@@ -145,7 +145,7 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
final int count) {
final List<Long> targetIds = targets.stream().map(Target::getId).collect(Collectors.toList());
final Slice<Target> targetsAll = targetManagement.findTargetsAll(pageReq);
final Slice<Target> targetsAll = targetManagement.findTargetsAll(PAGE);
assertThat(targetsAll).as("Count of targets").hasSize(count);
for (final Target target : targetsAll) {

View File

@@ -40,7 +40,9 @@ public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest {
final DistributionSet dsA = testdataFactory.createDistributionSet("");
rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
rollout = rolloutManagement.findRolloutById(rollout.getId()).get();
this.rolloutGroupId = rollout.getRolloutGroups().get(0).getId();
this.rolloutGroupId = rolloutGroupManagement.findRolloutGroupsByRolloutId(rollout.getId(), PAGE).getContent()
.get(0).getId();
}
@Test

View File

@@ -25,7 +25,6 @@ import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
@@ -181,7 +180,7 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
}
private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) {
final Page<Target> findTargetPage = targetManagement.findTargetsAll(rsqlParam, new PageRequest(0, 100));
final Page<Target> findTargetPage = targetManagement.findTargetsAll(rsqlParam, PAGE);
final long countTargetsAll = findTargetPage.getTotalElements();
assertThat(findTargetPage).isNotNull();
assertThat(countTargetsAll).isEqualTo(expcetedTargets);

View File

@@ -73,7 +73,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
createTargetForTenant(controllerAnotherTenant, anotherTenant);
// find all targets for current tenant "mytenant"
final Slice<Target> findTargetsAll = targetManagement.findTargetsAll(pageReq);
final Slice<Target> findTargetsAll = targetManagement.findTargetsAll(PAGE);
// no target has been created for "mytenant"
assertThat(findTargetsAll).hasSize(0);
@@ -92,11 +92,12 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
final String controllerAnotherTenant = "anotherController";
createTargetForTenant(controllerAnotherTenant, anotherTenant);
assertThat(systemManagement.findTenants()).as("Expected number if tenants before deletion is").hasSize(3);
assertThat(systemManagement.findTenants(PAGE)).as("Expected number if tenants before deletion is")
.hasSize(3);
systemManagement.deleteTenant(anotherTenant);
assertThat(systemManagement.findTenants()).as("Expected number if tenants after deletion is").hasSize(2);
assertThat(systemManagement.findTenants(PAGE)).as("Expected number if tenants after deletion is").hasSize(2);
}
@Test
@@ -106,9 +107,9 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
// logged in tenant mytenant - check if tenant default data is
// autogenerated
assertThat(distributionSetManagement.findDistributionSetTypesAll(pageReq)).isEmpty();
assertThat(distributionSetManagement.findDistributionSetTypesAll(PAGE)).isEmpty();
assertThat(systemManagement.getTenantMetadata().getTenant().toUpperCase()).isEqualTo("mytenant".toUpperCase());
assertThat(distributionSetManagement.findDistributionSetTypesAll(pageReq)).isNotEmpty();
assertThat(distributionSetManagement.findDistributionSetTypesAll(PAGE)).isNotEmpty();
// check that the cache is not getting in the way, i.e. "bumlux" results
// in bumlux and not
@@ -174,7 +175,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
private Slice<Target> findTargetsForTenant(final String tenant) throws Exception {
return securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant),
() -> targetManagement.findTargetsAll(pageReq));
() -> targetManagement.findTargetsAll(PAGE));
}
private void deleteTargetsForTenant(final String tenant, final Collection<Long> targetIds) throws Exception {
@@ -191,7 +192,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
private Page<DistributionSet> findDistributionSetForTenant(final String tenant) throws Exception {
return securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant),
() -> distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true));
() -> distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true));
}
}

View File

@@ -27,6 +27,7 @@ import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.RepositoryConstants;
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
import org.eclipse.hawkbit.repository.RolloutManagement;
@@ -100,7 +101,7 @@ import com.google.common.collect.Lists;
public abstract class AbstractIntegrationTest implements EnvironmentAware {
private static final Logger LOG = LoggerFactory.getLogger(AbstractIntegrationTest.class);
protected static final Pageable pageReq = new PageRequest(0, 400, new Sort(Direction.ASC, "id"));
protected static final Pageable PAGE = new PageRequest(0, 400, new Sort(Direction.ASC, "id"));
/**
* Constant for MediaType HAL with encoding UTF-8. Necessary since Spring
@@ -176,6 +177,9 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
@Autowired
protected TenantAwareCacheManager cacheManager;
@Autowired
protected QuotaManagement quotaManagement;
protected MockMvc mvc;
protected SoftwareModuleType osType;
@@ -258,7 +262,8 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
Target savedTarget = testdataFactory.createTarget(controllerId);
savedTarget = assignDistributionSet(ds.getId(), savedTarget.getControllerId()).getAssignedEntity().iterator()
.next();
Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0);
Action savedAction = deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())
.getContent().get(0);
savedAction = controllerManagement.addUpdateActionStatus(
entityFactory.actionStatus().create(savedAction.getId()).status(Action.Status.RUNNING));

View File

@@ -15,10 +15,15 @@ import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
public class JpaTestRepositoryManagement implements TestRepositoryManagement {
private static final Logger LOGGER = LoggerFactory.getLogger(JpaTestRepositoryManagement.class);
private static final Pageable PAGE = new PageRequest(0, 400, new Sort(Direction.ASC, "id"));
private final TenantAwareCacheManager cacheManager;
@@ -50,7 +55,8 @@ public class JpaTestRepositoryManagement implements TestRepositoryManagement {
}
public void deleteAllRepos() {
final List<String> tenants = systemSecurityContext.runAsSystem(() -> systemManagement.findTenants());
final List<String> tenants = systemSecurityContext
.runAsSystem(() -> systemManagement.findTenants(PAGE).getContent());
tenants.forEach(tenant -> {
try {
systemSecurityContext.runAsSystem(() -> {

View File

@@ -345,6 +345,26 @@ public class TestdataFactory {
return createDistributionSets("", number);
}
/**
* Create a list of {@link DistributionSet}s without modules, i.e.
* incomplete.
*
* @param number
* of {@link DistributionSet}s to create
* @return {@link List} of {@link DistributionSet} entities
*/
public List<DistributionSet> createDistributionSetsWithoutModules(final int number) {
final List<DistributionSet> sets = Lists.newArrayListWithExpectedSize(number);
for (int i = 0; i < number; i++) {
sets.add(distributionSetManagement.createDistributionSet(
entityFactory.distributionSet().create().name("DS" + i).version(DEFAULT_VERSION + "." + i)
.description(LOREM.words(10)).type(findOrCreateDefaultTestDsType())));
}
return sets;
}
/**
* Creates {@link DistributionSet}s in repository including three
* {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}