hawkBit repository uses Optional on single entity find/get requests (#435)
* Repo returns optionals. * Improved exception handling for collection usage in repo queries. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -62,13 +62,8 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easytesting</groupId>
|
||||
<artifactId>fest-assert-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easytesting</groupId>
|
||||
<artifactId>fest-assert</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -9,17 +9,17 @@
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
@@ -119,7 +119,8 @@ public interface ArtifactManagement {
|
||||
* of the {@link Artifact} that has to be deleted.
|
||||
* @throws ArtifactDeleteFailedException
|
||||
* if deletion failed (MongoDB is not available)
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if artifact with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
void deleteArtifact(@NotNull Long id);
|
||||
@@ -129,12 +130,11 @@ public interface ArtifactManagement {
|
||||
*
|
||||
* @param id
|
||||
* to search for
|
||||
* @return found {@link Artifact} or <code>null</code> is it could not be
|
||||
* found.
|
||||
* @return found {@link Artifact}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_CONTROLLER)
|
||||
Artifact findArtifact(@NotNull Long id);
|
||||
Optional<Artifact> findArtifact(@NotNull Long id);
|
||||
|
||||
/**
|
||||
* Find by artifact by software module id and filename.
|
||||
@@ -143,11 +143,11 @@ public interface ArtifactManagement {
|
||||
* file name
|
||||
* @param softwareModuleId
|
||||
* software module id.
|
||||
* @return Artifact if artifact present
|
||||
* @return found {@link Artifact}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_CONTROLLER)
|
||||
List<Artifact> findByFilenameAndSoftwareModule(@NotNull String filename, @NotNull Long softwareModuleId);
|
||||
Optional<Artifact> findByFilenameAndSoftwareModule(@NotNull String filename, @NotNull Long softwareModuleId);
|
||||
|
||||
/**
|
||||
* Find all local artifact by sha1 and return the first artifact.
|
||||
@@ -158,7 +158,7 @@ public interface ArtifactManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_CONTROLLER)
|
||||
Artifact findFirstArtifactBySHA1(@NotNull String sha1);
|
||||
Optional<Artifact> findFirstArtifactBySHA1(@NotNull String sha1);
|
||||
|
||||
/**
|
||||
* Searches for {@link Artifact} with given file name.
|
||||
@@ -169,7 +169,7 @@ public interface ArtifactManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_CONTROLLER)
|
||||
List<Artifact> findArtifactByFilename(@NotNull String filename);
|
||||
Optional<Artifact> findArtifactByFilename(@NotNull String filename);
|
||||
|
||||
/**
|
||||
* Get local artifact for a base software module.
|
||||
|
||||
@@ -106,6 +106,9 @@ public interface ControllerManagement {
|
||||
* @throws TooManyStatusEntriesException
|
||||
* if more than the allowed number of status entries are
|
||||
* inserted
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if action status not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||
Action addUpdateActionStatus(@NotNull ActionStatusCreate create);
|
||||
@@ -117,9 +120,6 @@ public interface ControllerManagement {
|
||||
* @param controllerId
|
||||
* identifies the target to retrieve the actions from
|
||||
* @return a list of actions assigned to given target which are active
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if target with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||
Optional<Action> findOldestActiveActionByTarget(@NotNull String controllerId);
|
||||
@@ -133,7 +133,7 @@ public interface ControllerManagement {
|
||||
* @return the corresponding {@link Action}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||
Action findActionWithDetails(@NotNull Long actionId);
|
||||
Optional<Action> findActionWithDetails(@NotNull Long actionId);
|
||||
|
||||
/**
|
||||
* register new target in the repository (plug-and-play).
|
||||
@@ -149,19 +149,19 @@ public interface ControllerManagement {
|
||||
|
||||
/**
|
||||
* Retrieves last {@link Action} for a download of an artifact of given
|
||||
* module and target.
|
||||
* module and target if exists and is not canceled.
|
||||
*
|
||||
* @param controllerId
|
||||
* to look for
|
||||
* @param module
|
||||
* that should be assigned to the target
|
||||
* @param moduleId
|
||||
* of the the {@link SoftwareModule} that should be assigned to
|
||||
* the target
|
||||
* @return last {@link Action} for given combination
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if action for given combination could not be found
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||
Action getActionForDownloadByTargetAndSoftwareModule(@NotEmpty String controllerId, @NotNull SoftwareModule module);
|
||||
Optional<Action> getActionForDownloadByTargetAndSoftwareModule(@NotEmpty String controllerId,
|
||||
@NotNull Long moduleId);
|
||||
|
||||
/**
|
||||
* @return current {@link TenantConfigurationKey#POLLING_TIME_INTERVAL}.
|
||||
@@ -271,7 +271,7 @@ public interface ControllerManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_SYSTEM_CODE)
|
||||
Target findByControllerId(@NotEmpty String controllerId);
|
||||
Optional<Target> findByControllerId(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* Finds {@link Target} based on given ID returns found Target without
|
||||
@@ -285,6 +285,6 @@ public interface ControllerManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_SYSTEM_CODE)
|
||||
Target findByTargetId(@NotNull Long targetId);
|
||||
Optional<Target> findByTargetId(@NotNull Long targetId);
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@@ -123,12 +124,11 @@ public interface DeploymentManagement {
|
||||
* @param actionId
|
||||
* to be canceled
|
||||
*
|
||||
* @return generated {@link Action} or <code>null</code> if not active on
|
||||
* given {@link Target}.
|
||||
* @return canceled {@link Action}
|
||||
*
|
||||
* @throws CancelActionNotAllowedException
|
||||
* in case the given action is not active or is already a cancel
|
||||
* action
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if action with given ID does not exist
|
||||
*/
|
||||
@@ -181,9 +181,10 @@ public interface DeploymentManagement {
|
||||
* @param actionId
|
||||
* to be id of the action
|
||||
* @return the corresponding {@link Action}
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Action findAction(@NotNull Long actionId);
|
||||
Optional<Action> findAction(@NotNull Long actionId);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s from repository.
|
||||
@@ -242,6 +243,7 @@ public interface DeploymentManagement {
|
||||
* @param pageable
|
||||
* the pageable request to limit, sort the actions
|
||||
* @return a slice of actions found for a specific target
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Slice<Action> findActionsByTarget(@NotEmpty String controllerId, @NotNull Pageable pageable);
|
||||
@@ -255,6 +257,9 @@ public interface DeploymentManagement {
|
||||
* @param actionId
|
||||
* to be filtered on
|
||||
* @return the corresponding {@link Page} of {@link ActionStatus}
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if action with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Page<ActionStatus> findActionStatusByAction(@NotNull Pageable pageReq, @NotNull Long actionId);
|
||||
@@ -268,6 +273,9 @@ public interface DeploymentManagement {
|
||||
* @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);
|
||||
@@ -292,7 +300,7 @@ public interface DeploymentManagement {
|
||||
* @return the corresponding {@link Action}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Action findActionWithDetails(@NotNull Long actionId);
|
||||
Optional<Action> findActionWithDetails(@NotNull Long actionId);
|
||||
|
||||
/**
|
||||
* Retrieves all active {@link Action}s of a specific target ordered by
|
||||
@@ -325,8 +333,8 @@ public interface DeploymentManagement {
|
||||
* @param actionId
|
||||
* to be canceled
|
||||
*
|
||||
* @return generated {@link Action} or <code>null</code> if not active on
|
||||
* {@link Target}.
|
||||
* @return quite {@link Action}
|
||||
*
|
||||
* @throws CancelActionNotAllowedException
|
||||
* in case the given action is not active
|
||||
*
|
||||
@@ -343,6 +351,9 @@ public interface DeploymentManagement {
|
||||
* @param actionId
|
||||
* the ID of the action
|
||||
* @return the updated or the found {@link Action}
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if action with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
|
||||
Action forceTargetAction(@NotNull Long actionId);
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@@ -60,7 +61,7 @@ public interface DistributionSetManagement {
|
||||
* @return the updated {@link DistributionSet}.
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if given module does not exist
|
||||
* if (at least one) given module does not exist
|
||||
*
|
||||
* @throws EntityReadOnlyException
|
||||
* if use tries to change the {@link DistributionSet} s while
|
||||
@@ -86,7 +87,8 @@ public interface DistributionSetManagement {
|
||||
* @return list of assigned ds
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if tag with given ID does not exist
|
||||
* if tag with given ID does not exist or (at least one) of the
|
||||
* distribution sets.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
List<DistributionSet> assignTag(@NotEmpty Collection<Long> dsIds, @NotNull Long tagId);
|
||||
@@ -108,6 +110,9 @@ public interface DistributionSetManagement {
|
||||
* to look for
|
||||
*
|
||||
* @return number of {@link DistributionSet}s
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if type with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Long countDistributionSetsByType(@NotNull Long typeId);
|
||||
@@ -214,9 +219,13 @@ public interface DistributionSetManagement {
|
||||
* result means that they cannot be assigned anymore to any targets. (define
|
||||
* e.g. findByDeletedFalse())
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param setId
|
||||
* to delete
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if given {@link DistributionSet} does not exist
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
void deleteDistributionSet(@NotNull Long setId);
|
||||
@@ -228,6 +237,9 @@ public interface DistributionSetManagement {
|
||||
*
|
||||
* @param dsIds
|
||||
* to be deleted
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if (at least one) given distribution set does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
void deleteDistributionSet(@NotEmpty Collection<Long> dsIds);
|
||||
@@ -264,9 +276,12 @@ public interface DistributionSetManagement {
|
||||
* @param actionId
|
||||
* the action associated with the distribution set
|
||||
* @return the distribution set which is associated with the action
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if action with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
DistributionSet findDistributionSetByAction(@NotNull Long actionId);
|
||||
Optional<DistributionSet> findDistributionSetByAction(@NotNull Long actionId);
|
||||
|
||||
/**
|
||||
* Find {@link DistributionSet} based on given ID without details, e.g.
|
||||
@@ -274,10 +289,11 @@ public interface DistributionSetManagement {
|
||||
*
|
||||
* @param distid
|
||||
* to look for.
|
||||
* @return {@link DistributionSet} or <code>null</code> if it does not exist
|
||||
* @return {@link DistributionSet}
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
DistributionSet findDistributionSetById(@NotNull Long distid);
|
||||
Optional<DistributionSet> findDistributionSetById(@NotNull Long distid);
|
||||
|
||||
/**
|
||||
* Find {@link DistributionSet} based on given ID including (lazy loaded)
|
||||
@@ -288,10 +304,10 @@ public interface DistributionSetManagement {
|
||||
*
|
||||
* @param distid
|
||||
* to look for.
|
||||
* @return {@link DistributionSet} or <code>null</code> if it does not exist
|
||||
* @return {@link DistributionSet}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
DistributionSet findDistributionSetByIdWithDetails(@NotNull Long distid);
|
||||
Optional<DistributionSet> findDistributionSetByIdWithDetails(@NotNull Long distid);
|
||||
|
||||
/**
|
||||
* Find distribution set by name and version.
|
||||
@@ -303,7 +319,8 @@ public interface DistributionSetManagement {
|
||||
* @return the page with the found {@link DistributionSet}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
DistributionSet findDistributionSetByNameAndVersion(@NotEmpty String distributionName, @NotEmpty String version);
|
||||
Optional<DistributionSet> findDistributionSetByNameAndVersion(@NotEmpty String distributionName,
|
||||
@NotEmpty String version);
|
||||
|
||||
/**
|
||||
* finds all meta data by the given distribution set id.
|
||||
@@ -314,21 +331,14 @@ public interface DistributionSetManagement {
|
||||
* the page request to page the result
|
||||
* @return a paged result of all meta data entries for a given distribution
|
||||
* set id
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Page<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId,
|
||||
@NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Finds all meta data by the given distribution set id.
|
||||
*
|
||||
* @param distributionSetId
|
||||
* the distribution set id to retrieve the meta data from
|
||||
* @return list of distributionSetMetadata for a given distribution set Id.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
List<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId);
|
||||
|
||||
/**
|
||||
* finds all meta data by the given distribution set id.
|
||||
*
|
||||
@@ -346,6 +356,9 @@ public interface DistributionSetManagement {
|
||||
* given {@code fieldNameProvider}
|
||||
* @throws RSQLParameterSyntaxException
|
||||
* if the RSQL syntax is wrong
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* of distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Page<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId,
|
||||
@@ -449,27 +462,27 @@ public interface DistributionSetManagement {
|
||||
/**
|
||||
* @param id
|
||||
* as {@link DistributionSetType#getId()}
|
||||
* @return {@link DistributionSetType} if found or <code>null</code> if not
|
||||
* @return {@link DistributionSetType}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
DistributionSetType findDistributionSetTypeById(@NotNull Long id);
|
||||
Optional<DistributionSetType> findDistributionSetTypeById(@NotNull Long id);
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* as {@link DistributionSetType#getKey()}
|
||||
* @return {@link DistributionSetType} if found or <code>null</code> if not
|
||||
* @return {@link DistributionSetType}
|
||||
*/
|
||||
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
DistributionSetType findDistributionSetTypeByKey(@NotEmpty String key);
|
||||
Optional<DistributionSetType> findDistributionSetTypeByKey(@NotEmpty String key);
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* as {@link DistributionSetType#getName()}
|
||||
* @return {@link DistributionSetType} if found or <code>null</code> if not
|
||||
* @return {@link DistributionSetType}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
DistributionSetType findDistributionSetTypeByName(@NotEmpty String name);
|
||||
Optional<DistributionSetType> findDistributionSetTypeByName(@NotEmpty String name);
|
||||
|
||||
/**
|
||||
* @param pageable
|
||||
@@ -506,11 +519,9 @@ public interface DistributionSetManagement {
|
||||
* @param key
|
||||
* of the meta data element
|
||||
* @return the found DistributionSetMetadata or {@code null} if not exits
|
||||
* @throws EntityNotFoundException
|
||||
* in case the meta data does not exists for the given key
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
DistributionSetMetadata findDistributionSetMetadata(@NotNull Long setId, @NotEmpty String key);
|
||||
Optional<DistributionSetMetadata> findDistributionSetMetadata(@NotNull Long setId, @NotEmpty String key);
|
||||
|
||||
/**
|
||||
* Checks if a {@link DistributionSet} is currently in use by a target in
|
||||
@@ -536,6 +547,9 @@ public interface DistributionSetManagement {
|
||||
* to toggle
|
||||
* @return {@link DistributionSetTagAssignmentResult} with all meta data of
|
||||
* the assignment outcome.
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if given tag does not exist or (at least one) module
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection<Long> dsIds, @NotNull String tagName);
|
||||
@@ -715,6 +729,6 @@ public interface DistributionSetManagement {
|
||||
* @return the found {@link DistributionSet}s
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
List<DistributionSet> findDistributionSetAllById(@NotNull Collection<Long> ids);
|
||||
List<DistributionSet> findDistributionSetAllById(@NotEmpty Collection<Long> ids);
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
@@ -67,9 +69,10 @@ public interface RolloutGroupManagement {
|
||||
* the ID of the rollout group to find
|
||||
* @return the found {@link RolloutGroup} by its ID or {@code null} if it
|
||||
* does not exists
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
|
||||
RolloutGroup findRolloutGroupById(@NotNull Long rolloutGroupId);
|
||||
Optional<RolloutGroup> findRolloutGroupById(@NotNull Long rolloutGroupId);
|
||||
|
||||
/**
|
||||
* Retrieves a page of {@link RolloutGroup}s filtered by a given
|
||||
@@ -151,9 +154,10 @@ public interface RolloutGroupManagement {
|
||||
* @param rolloutGroupId
|
||||
* rollout group id
|
||||
* @return rolloutGroup with details of targets count for different statuses
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
|
||||
RolloutGroup findRolloutGroupWithDetailedStatus(@NotNull Long rolloutGroupId);
|
||||
Optional<RolloutGroup> findRolloutGroupWithDetailedStatus(@NotNull Long rolloutGroupId);
|
||||
|
||||
/**
|
||||
* Count targets of rollout group.
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@@ -45,8 +45,8 @@ public interface RolloutManagement {
|
||||
|
||||
/**
|
||||
* Checking running rollouts. Rollouts which are checked updating the
|
||||
* lastCheck to indicate that the current instance
|
||||
* is handling the specific rollout. This code should run as system-code.
|
||||
* lastCheck to indicate that the current instance is handling the specific
|
||||
* rollout. This code should run as system-code.
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
@@ -58,9 +58,8 @@ public interface RolloutManagement {
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* This method is intended to be called by a scheduler.
|
||||
* And must be running in an transaction so it's
|
||||
* splitted from the scheduler.
|
||||
* This method is intended to be called by a scheduler. And must be running
|
||||
* in an transaction so it's splitted from the scheduler.
|
||||
*
|
||||
* Rollouts which are currently running are investigated, by means the
|
||||
* error- and finish condition of running groups in this rollout are
|
||||
@@ -292,7 +291,7 @@ public interface RolloutManagement {
|
||||
* not exists
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
|
||||
Rollout findRolloutById(@NotNull Long rolloutId);
|
||||
Optional<Rollout> findRolloutById(@NotNull Long rolloutId);
|
||||
|
||||
/**
|
||||
* Retrieves a specific rollout by its name.
|
||||
@@ -303,7 +302,7 @@ public interface RolloutManagement {
|
||||
* does not exists
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
|
||||
Rollout findRolloutByName(@NotNull String rolloutName);
|
||||
Optional<Rollout> findRolloutByName(@NotEmpty String rolloutName);
|
||||
|
||||
/**
|
||||
* Get count of targets in different status in rollout.
|
||||
@@ -311,10 +310,21 @@ public interface RolloutManagement {
|
||||
* @param rolloutId
|
||||
* rollout id
|
||||
* @return rollout details of targets count for different statuses
|
||||
*
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
|
||||
Rollout findRolloutWithDetailedStatus(@NotNull Long rolloutId);
|
||||
Optional<Rollout> findRolloutWithDetailedStatus(@NotNull Long rolloutId);
|
||||
|
||||
/**
|
||||
* Checks if rollout with given ID exists.
|
||||
*
|
||||
* @param rolloutId
|
||||
* rollout id
|
||||
*
|
||||
* @return <code>true</code> if rollout exists
|
||||
*/
|
||||
boolean exists(@NotNull Long rolloutId);
|
||||
|
||||
/***
|
||||
* Get finished percentage details for a specified group which is in running
|
||||
@@ -378,7 +388,7 @@ public interface RolloutManagement {
|
||||
* all actions are created and the first group is started. The rollout
|
||||
* itself will be then also in {@link RolloutStatus#RUNNING}.
|
||||
*
|
||||
* @param rollout
|
||||
* @param rolloutId
|
||||
* the rollout to be started
|
||||
*
|
||||
* @return started rollout
|
||||
@@ -390,7 +400,7 @@ public interface RolloutManagement {
|
||||
* ready rollouts can be started.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE)
|
||||
Rollout startRollout(@NotNull Long rollout);
|
||||
Rollout startRollout(@NotNull Long rolloutId);
|
||||
|
||||
/**
|
||||
* Update rollout details.
|
||||
@@ -399,6 +409,10 @@ public interface RolloutManagement {
|
||||
* rollout to be updated
|
||||
*
|
||||
* @return Rollout updated rollout
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if rollout or DS with given IDs do not exist
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE)
|
||||
Rollout updateRollout(@NotNull RolloutUpdate update);
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@@ -50,6 +51,9 @@ public interface SoftwareManagement {
|
||||
* @param typeId
|
||||
* to filter the result by type
|
||||
* @return number of found {@link SoftwareModule}s
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if software module type with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Long countSoftwareModuleByFilters(String searchText, Long typeId);
|
||||
@@ -77,6 +81,9 @@ public interface SoftwareManagement {
|
||||
* @return SoftwareModule
|
||||
* @throws EntityAlreadyExistsException
|
||||
* if a given entity already exists
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* of given software module type does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
|
||||
List<SoftwareModule> createSoftwareModule(@NotNull Collection<SoftwareModuleCreate> creates);
|
||||
@@ -88,6 +95,9 @@ public interface SoftwareManagement {
|
||||
* @return SoftwareModule
|
||||
* @throws EntityAlreadyExistsException
|
||||
* if a given entity already exists
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* of given software module type does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
|
||||
SoftwareModule createSoftwareModule(@NotNull SoftwareModuleCreate create);
|
||||
@@ -103,6 +113,8 @@ public interface SoftwareManagement {
|
||||
* @throws EntityAlreadyExistsException
|
||||
* in case one of the meta data entry already exists for the
|
||||
* specific key
|
||||
* @throws EntityNotFoundException
|
||||
* if software module with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
List<SoftwareModuleMetadata> createSoftwareModuleMetadata(@NotNull Long moduleId,
|
||||
@@ -119,6 +131,8 @@ public interface SoftwareManagement {
|
||||
* @throws EntityAlreadyExistsException
|
||||
* in case the meta data entry already exists for the specific
|
||||
* key
|
||||
* @throws EntityNotFoundException
|
||||
* if software module with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
SoftwareModuleMetadata createSoftwareModuleMetadata(@NotNull Long moduleId, @NotNull MetaData metadata);
|
||||
@@ -159,6 +173,9 @@ public interface SoftwareManagement {
|
||||
* where meta data has to be deleted
|
||||
* @param key
|
||||
* of the metda data element
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* of module or metadata entry does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
void deleteSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key);
|
||||
@@ -168,6 +185,9 @@ public interface SoftwareManagement {
|
||||
*
|
||||
* @param moduleIds
|
||||
* of the Software Modules to be deleted
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if (at least one) module with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
void deleteSoftwareModules(@NotNull Collection<Long> moduleIds);
|
||||
@@ -179,7 +199,7 @@ public interface SoftwareManagement {
|
||||
* to delete
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* not found is type with giben ID does not exist
|
||||
* not found is type with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
void deleteSoftwareModuleType(@NotNull Long typeId);
|
||||
@@ -191,6 +211,9 @@ public interface SoftwareManagement {
|
||||
* to search for
|
||||
* @return all {@link SoftwareModule}s that are assigned to given
|
||||
* {@link DistributionSet}.
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Page<SoftwareModule> findSoftwareModuleByAssignedTo(@NotNull Pageable pageable, @NotNull Long setId);
|
||||
@@ -207,6 +230,9 @@ public interface SoftwareManagement {
|
||||
* @param typeId
|
||||
* to be filtered as "like" on {@link SoftwareModule#getType()}
|
||||
* @return the page of found {@link SoftwareModule}
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if given software module type does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Slice<SoftwareModule> findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText, Long typeId);
|
||||
@@ -227,12 +253,12 @@ public interface SoftwareManagement {
|
||||
*
|
||||
* @param id
|
||||
* to search for
|
||||
* @return the found {@link SoftwareModule}s or <code>null</code> if not
|
||||
* found.
|
||||
* @return the found {@link SoftwareModule}s
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_CONTROLLER)
|
||||
SoftwareModule findSoftwareModuleById(@NotNull Long id);
|
||||
Optional<SoftwareModule> findSoftwareModuleById(@NotNull Long id);
|
||||
|
||||
/**
|
||||
* retrieves {@link SoftwareModule} by their name AND version AND type..
|
||||
@@ -243,10 +269,13 @@ public interface SoftwareManagement {
|
||||
* of the {@link SoftwareModule}
|
||||
* @param typeId
|
||||
* of the {@link SoftwareModule}
|
||||
* @return the found {@link SoftwareModule} or <code>null</code>
|
||||
* @return the found {@link SoftwareModule}
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if software module type with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty String name, @NotEmpty String version,
|
||||
Optional<SoftwareModule> findSoftwareModuleByNameAndVersion(@NotEmpty String name, @NotEmpty String version,
|
||||
@NotNull Long typeId);
|
||||
|
||||
/**
|
||||
@@ -257,11 +286,9 @@ public interface SoftwareManagement {
|
||||
* @param key
|
||||
* of the meta data element
|
||||
* @return the found SoftwareModuleMetadata or {@code null} if not exits
|
||||
* @throws EntityNotFoundException
|
||||
* in case the meta data does not exists for the given key
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key);
|
||||
Optional<SoftwareModuleMetadata> findSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key);
|
||||
|
||||
/**
|
||||
* finds all meta data by the given software module id.
|
||||
@@ -272,6 +299,9 @@ public interface SoftwareManagement {
|
||||
* the page request to page the result
|
||||
* @return a paged result of all meta data entries for a given software
|
||||
* module id
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if software module with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Page<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long swId,
|
||||
@@ -294,6 +324,8 @@ public interface SoftwareManagement {
|
||||
* given {@code fieldNameProvider}
|
||||
* @throws RSQLParameterSyntaxException
|
||||
* if the RSQL syntax is wrong
|
||||
* @throws EntityNotFoundException
|
||||
* if software module with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Page<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long moduleId,
|
||||
@@ -318,6 +350,9 @@ public interface SoftwareManagement {
|
||||
* @param typeId
|
||||
* filtered as "equal" on {@link SoftwareModule#getType()}
|
||||
* @return the page of found {@link SoftwareModule}
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if given software module type does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Slice<AssignedSoftwareModule> findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
|
||||
@@ -371,6 +406,9 @@ public interface SoftwareManagement {
|
||||
* @param typeId
|
||||
* to be filtered on
|
||||
* @return the found {@link SoftwareModule}s
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if software module type with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Slice<SoftwareModule> findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull Long typeId);
|
||||
@@ -383,7 +421,7 @@ public interface SoftwareManagement {
|
||||
* {@link SoftwareModuleType#getId()}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
SoftwareModuleType findSoftwareModuleTypeById(@NotNull Long id);
|
||||
Optional<SoftwareModuleType> findSoftwareModuleTypeById(@NotNull Long id);
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -393,7 +431,7 @@ public interface SoftwareManagement {
|
||||
* {@link SoftwareModuleType#getKey()}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
SoftwareModuleType findSoftwareModuleTypeByKey(@NotEmpty String key);
|
||||
Optional<SoftwareModuleType> findSoftwareModuleTypeByKey(@NotEmpty String key);
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -403,7 +441,7 @@ public interface SoftwareManagement {
|
||||
* {@link SoftwareModuleType#getName()}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
SoftwareModuleType findSoftwareModuleTypeByName(@NotNull String name);
|
||||
Optional<SoftwareModuleType> findSoftwareModuleTypeByName(@NotNull String name);
|
||||
|
||||
/**
|
||||
* @param pageable
|
||||
@@ -443,6 +481,9 @@ public interface SoftwareManagement {
|
||||
* if given module does not exist
|
||||
*
|
||||
* @return the saved Entity.
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if fiven {@link SoftwareModule} does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
SoftwareModule updateSoftwareModule(@NotNull SoftwareModuleUpdate update);
|
||||
@@ -455,8 +496,8 @@ public interface SoftwareManagement {
|
||||
* @param metadata
|
||||
* the meta data entry to be updated
|
||||
*
|
||||
*
|
||||
* @return the updated meta data entry
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* in case the meta data entry does not exists and cannot be
|
||||
* updated
|
||||
@@ -492,6 +533,9 @@ public interface SoftwareManagement {
|
||||
* @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);
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@@ -102,6 +103,9 @@ public interface TagManagement {
|
||||
*
|
||||
* @param tagName
|
||||
* to be deleted
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if tag with given name does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
void deleteDistributionSetTag(@NotEmpty String tagName);
|
||||
@@ -111,6 +115,9 @@ public interface TagManagement {
|
||||
*
|
||||
* @param targetTagName
|
||||
* tag name of the {@link TargetTag} to be deleted
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if tag with given name does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
|
||||
void deleteTargetTag(@NotEmpty String targetTagName);
|
||||
@@ -150,12 +157,6 @@ public interface TagManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Page<DistributionSetTag> findAllDistributionSetTags(@NotNull String rsqlParam, @NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* @return all {@link TargetTag}s
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
List<TargetTag> findAllTargetTags();
|
||||
|
||||
/**
|
||||
* returns all {@link TargetTag}s.
|
||||
*
|
||||
@@ -190,41 +191,40 @@ public interface TagManagement {
|
||||
*
|
||||
* @param name
|
||||
* to look for.
|
||||
* @return {@link DistributionSet} or <code>null</code> if it does not exist
|
||||
* @return {@link DistributionSet}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
DistributionSetTag findDistributionSetTag(@NotEmpty String name);
|
||||
Optional<DistributionSetTag> findDistributionSetTag(@NotEmpty String name);
|
||||
|
||||
/**
|
||||
* Finds {@link DistributionSetTag} by given id.
|
||||
*
|
||||
* @param id
|
||||
* to search for
|
||||
* @return the found {@link DistributionSetTag}s or <code>null</code> if not
|
||||
* found.
|
||||
* @return the found {@link DistributionSetTag}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
DistributionSetTag findDistributionSetTagById(@NotNull Long id);
|
||||
Optional<DistributionSetTag> findDistributionSetTagById(@NotNull Long id);
|
||||
|
||||
/**
|
||||
* Find {@link TargetTag} based on given Name.
|
||||
*
|
||||
* @param name
|
||||
* to look for.
|
||||
* @return {@link TargetTag} or <code>null</code> if it does not exist
|
||||
* @return {@link TargetTag}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
TargetTag findTargetTag(@NotEmpty String name);
|
||||
Optional<TargetTag> findTargetTag(@NotEmpty String name);
|
||||
|
||||
/**
|
||||
* Finds {@link TargetTag} by given id.
|
||||
*
|
||||
* @param id
|
||||
* to search for
|
||||
* @return the found {@link TargetTag}s or <code>null</code> if not found.
|
||||
* @return the found {@link TargetTag}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
TargetTag findTargetTagById(@NotNull Long id);
|
||||
Optional<TargetTag> findTargetTagById(@NotNull Long id);
|
||||
|
||||
/**
|
||||
* Updates an existing {@link DistributionSetTag}.
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
@@ -42,6 +44,9 @@ public interface TargetFilterQueryManagement {
|
||||
*
|
||||
* @param targetFilterQueryId
|
||||
* IDs of target filter query to be deleted
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if filter with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
|
||||
void deleteTargetFilterQuery(@NotNull Long targetFilterQueryId);
|
||||
@@ -118,7 +123,7 @@ public interface TargetFilterQueryManagement {
|
||||
* @return the page with the found {@link TargetFilterQuery}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Page<TargetFilterQuery> findTargetFilterQueryByQuery(@NotNull Pageable pageable, String query);
|
||||
Page<TargetFilterQuery> findTargetFilterQueryByQuery(@NotNull Pageable pageable, @NotNull String query);
|
||||
|
||||
/**
|
||||
* Retrieves all target filter query which {@link TargetFilterQuery}.
|
||||
@@ -159,7 +164,7 @@ public interface TargetFilterQueryManagement {
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
TargetFilterQuery findTargetFilterQueryById(@NotNull Long targetFilterQueryId);
|
||||
Optional<TargetFilterQuery> findTargetFilterQueryById(@NotNull Long targetFilterQueryId);
|
||||
|
||||
/**
|
||||
* Find target filter query by name.
|
||||
@@ -170,7 +175,7 @@ public interface TargetFilterQueryManagement {
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
TargetFilterQuery findTargetFilterQueryByName(@NotNull String targetFilterQueryName);
|
||||
Optional<TargetFilterQuery> findTargetFilterQueryByName(@NotNull String targetFilterQueryName);
|
||||
|
||||
/**
|
||||
* updates the {@link TargetFilterQuery}.
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@@ -64,6 +65,9 @@ public interface TargetManagement {
|
||||
* to search for
|
||||
*
|
||||
* @return number of found {@link Target}s.
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
@@ -94,6 +98,9 @@ public interface TargetManagement {
|
||||
* flag to select targets with no tag assigned
|
||||
*
|
||||
* @return the found number {@link Target}s
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Long countTargetByFilters(Collection<TargetUpdateStatus> status, Boolean overdueState, String searchText,
|
||||
@@ -106,6 +113,9 @@ public interface TargetManagement {
|
||||
* @param distId
|
||||
* to search for
|
||||
* @return number of found {@link Target}s.
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
@@ -175,10 +185,13 @@ public interface TargetManagement {
|
||||
*
|
||||
* @param targetIDs
|
||||
* the IDs of the targets to be deleted
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if (at least one) of the given target IDs does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
|
||||
void deleteTargets(@NotEmpty Collection<Long> targetIDs);
|
||||
|
||||
|
||||
/**
|
||||
* Deletes target with the given IDs.
|
||||
*
|
||||
@@ -203,10 +216,13 @@ public interface TargetManagement {
|
||||
* @param rsqlParam
|
||||
* filter definition in RSQL syntax
|
||||
* @return a page of the found {@link Target}s
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Page<Target> findAllTargetsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest, Long distributionSetId,
|
||||
@NotNull String rsqlParam);
|
||||
Page<Target> findAllTargetsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest,
|
||||
@NotNull Long distributionSetId, @NotNull String rsqlParam);
|
||||
|
||||
/**
|
||||
* Counts all targets for all the given parameter {@link TargetFilterQuery}
|
||||
@@ -218,6 +234,9 @@ public interface TargetManagement {
|
||||
* @param rsqlParam
|
||||
* filter definition in RSQL syntax
|
||||
* @return the count of found {@link Target}s
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Long countTargetsByTargetFilterQueryAndNonDS(@NotNull Long distributionSetId, @NotNull String rsqlParam);
|
||||
@@ -261,6 +280,9 @@ public interface TargetManagement {
|
||||
* @param group
|
||||
* the {@link RolloutGroup}
|
||||
* @return the found {@link Target}s
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if rollout group with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Page<Target> findAllTargetsInRolloutGroupWithoutAction(@NotNull Pageable pageRequest, @NotNull Long group);
|
||||
@@ -276,6 +298,9 @@ public interface TargetManagement {
|
||||
* @param pageReq
|
||||
* page parameter
|
||||
* @return the found {@link Target}s
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
|
||||
Page<Target> findTargetByAssignedDistributionSet(@NotNull Long distributionSetID, @NotNull Pageable pageReq);
|
||||
@@ -297,7 +322,8 @@ public interface TargetManagement {
|
||||
* given {@code fieldNameProvider}
|
||||
* @throws RSQLParameterSyntaxException
|
||||
* if the RSQL syntax is wrong
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
|
||||
Page<Target> findTargetByAssignedDistributionSet(@NotNull Long distributionSetID, @NotNull String rsqlParam,
|
||||
@@ -322,10 +348,10 @@ public interface TargetManagement {
|
||||
*
|
||||
* @param controllerId
|
||||
* to look for.
|
||||
* @return {@link Target} or <code>null</code> if it does not exist
|
||||
* @return {@link Target}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Target findTargetByControllerID(@NotEmpty String controllerId);
|
||||
Optional<Target> findTargetByControllerID(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* Find {@link Target} based on given ID returns found Target with details,
|
||||
@@ -337,10 +363,10 @@ public interface TargetManagement {
|
||||
*
|
||||
* @param controllerId
|
||||
* to look for.
|
||||
* @return {@link Target} or <code>null</code> if it does not exist
|
||||
* @return {@link Target}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Target findTargetByControllerIDWithDetails(@NotEmpty String controllerId);
|
||||
Optional<Target> findTargetByControllerIDWithDetails(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* Filter {@link Target}s for all the given parameters. If all parameters
|
||||
@@ -369,6 +395,9 @@ public interface TargetManagement {
|
||||
* flag to select targets with no tag assigned
|
||||
*
|
||||
* @return the found {@link Target}s
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Slice<Target> findTargetByFilters(@NotNull Pageable pageable, Collection<TargetUpdateStatus> status,
|
||||
@@ -385,6 +414,9 @@ public interface TargetManagement {
|
||||
* @param pageReq
|
||||
* page parameter
|
||||
* @return the found {@link Target}s
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
|
||||
Page<Target> findTargetByInstalledDistributionSet(@NotNull Long distributionSetID, @NotNull Pageable pageReq);
|
||||
@@ -407,6 +439,9 @@ public interface TargetManagement {
|
||||
* given {@code fieldNameProvider}
|
||||
* @throws RSQLParameterSyntaxException
|
||||
* if the RSQL syntax is wrong
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
|
||||
Page<Target> findTargetByInstalledDistributionSet(@NotNull Long distributionSetId, @NotNull String rsqlParam,
|
||||
@@ -506,6 +541,9 @@ public interface TargetManagement {
|
||||
* non-null value; filters are AND-gated
|
||||
* @return a paged result {@link Page} of the {@link Target}s in a defined
|
||||
* order.
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if distribution set with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Slice<Target> findTargetsAllOrderByLinkedDistributionSet(@NotNull Pageable pageable,
|
||||
@@ -546,6 +584,9 @@ public interface TargetManagement {
|
||||
* @param tagName
|
||||
* to toggle
|
||||
* @return TagAssigmentResult with all meta data of the assignment outcome.
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if tag with given name does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
|
||||
TargetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection<String> targetIds, @NotEmpty String tagName);
|
||||
@@ -600,10 +641,10 @@ public interface TargetManagement {
|
||||
*
|
||||
* @param id
|
||||
* to look for
|
||||
* @return {@link Target} or <code>null</code> if it does not exist
|
||||
* @return {@link Target}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Target findTargetById(Long id);
|
||||
Optional<Target> findTargetById(Long id);
|
||||
|
||||
/**
|
||||
* Retrieves all targets without details, i.e. NO {@link Target#getTags()}
|
||||
|
||||
@@ -8,15 +8,17 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.exception;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
|
||||
/**
|
||||
* the {@link EntityNotFoundException} is thrown when a entity is tried find but
|
||||
* not found.
|
||||
*
|
||||
*
|
||||
*
|
||||
* the {@link EntityNotFoundException} is thrown when a entity queried but not
|
||||
* found.
|
||||
*/
|
||||
public class EntityNotFoundException extends AbstractServerRtException {
|
||||
|
||||
@@ -58,7 +60,51 @@ public class EntityNotFoundException extends AbstractServerRtException {
|
||||
* @param message
|
||||
* of the exception
|
||||
*/
|
||||
public EntityNotFoundException(final String message) {
|
||||
protected EntityNotFoundException(final String message) {
|
||||
super(message, THIS_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameterized constructor for {@link BaseEntity} not found.
|
||||
*
|
||||
* @param type
|
||||
* of the entity that was not found
|
||||
*
|
||||
* @param enityId
|
||||
* of the {@link BaseEntity}
|
||||
*/
|
||||
public EntityNotFoundException(final Class<? extends BaseEntity> type, final Object enityId) {
|
||||
this(type.getSimpleName() + " with given identifier {" + enityId + "} does not exist.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameterized constructor for {@link MetaData} not found.
|
||||
*
|
||||
* @param type
|
||||
* of the entity that was not found
|
||||
* @param enityId
|
||||
* of the {@link BaseEntity} the {@link MetaData} was for
|
||||
* @param key
|
||||
* for the {@link MetaData} entry
|
||||
*/
|
||||
public EntityNotFoundException(final Class<? extends MetaData> type, final Long enityId, final String key) {
|
||||
this(type.getSimpleName() + " for given entity {" + enityId + "} and with key {" + key + "} does not exist.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameterized constructor for a list of {@link BaseEntity}s not found.
|
||||
*
|
||||
* @param type
|
||||
* of the entity that was not found
|
||||
*
|
||||
* @param expected
|
||||
* collection of the {@link BaseEntity#getId()}s
|
||||
* @param found
|
||||
* collection of the {@link BaseEntity#getId()}s
|
||||
*/
|
||||
public EntityNotFoundException(final Class<? extends BaseEntity> type, final Collection<Long> expected,
|
||||
final Collection<Long> found) {
|
||||
this(type.getSimpleName() + "s with given identifiers {" + expected.stream().filter(id -> !found.contains(id))
|
||||
.map(String::valueOf).collect(Collectors.joining(",")) + "} do not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.exception;
|
||||
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
|
||||
/**
|
||||
* the {@link SoftwareModuleNotAssignedToTargetException} is thrown when a
|
||||
* {@link SoftwareModule} is requested as part of an {@link Action} that has
|
||||
* however never been assigned to the {@link Target}.
|
||||
*/
|
||||
public class SoftwareModuleNotAssignedToTargetException extends EntityNotFoundException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param moduleId
|
||||
* thats is not assigned to given {@link Target}
|
||||
* @param controllerId
|
||||
* of the {@link Target} where given {@link SoftwareModule} is
|
||||
* not part of
|
||||
*/
|
||||
public SoftwareModuleNotAssignedToTargetException(final Long moduleId, final String controllerId) {
|
||||
super("No assignment found for " + SoftwareModule.class.getSimpleName() + " with id {" + moduleId + "} to "
|
||||
+ Target.class.getSimpleName() + " with id {" + controllerId + "}.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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.exception;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
|
||||
/**
|
||||
* the {@link SoftwareModuleTypeNotInDistributionSetTypeException} is thrown
|
||||
* when a {@link SoftwareModuleType} is requested as part of a
|
||||
* {@link DistributionSetType} but actually neither
|
||||
* {@link DistributionSetType#getMandatoryModuleTypes()} or
|
||||
* {@link DistributionSetType#getOptionalModuleTypes()}.
|
||||
*/
|
||||
public class SoftwareModuleTypeNotInDistributionSetTypeException extends EntityNotFoundException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param moduleTypeId
|
||||
* thats is not part of given {@link DistributionSetType}
|
||||
* @param distributionSetTypeId
|
||||
* of the {@link DistributionSetType} where given
|
||||
* {@link SoftwareModuleType} is not part of
|
||||
*/
|
||||
public SoftwareModuleTypeNotInDistributionSetTypeException(final Long moduleTypeId,
|
||||
final Long distributionSetTypeId) {
|
||||
super(SoftwareModuleType.class.getSimpleName() + " with id {" + moduleTypeId + "} is not part of "
|
||||
+ DistributionSetType.class.getSimpleName() + " with id {" + distributionSetTypeId + "}.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,10 +12,7 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Operations to be executed by the target. Usually a software update. Other
|
||||
* supported actions are the cancellation of a running update action or a
|
||||
* refresh request for target attributes.
|
||||
*
|
||||
* Update operations to be executed by the target.
|
||||
*/
|
||||
public interface Action extends TenantAwareBaseEntity {
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package org.eclipse.hawkbit.repository.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -57,10 +58,10 @@ public interface DistributionSet extends NamedVersionedEntity {
|
||||
*
|
||||
* @param type
|
||||
* to search for
|
||||
* @return SoftwareModule of given type or <code>null</code> if not found.
|
||||
* @return SoftwareModule of given type
|
||||
*/
|
||||
default SoftwareModule findFirstModuleByType(final SoftwareModuleType type) {
|
||||
return getModules().stream().filter(module -> module.getType().equals(type)).findFirst().orElse(null);
|
||||
default Optional<SoftwareModule> findFirstModuleByType(final SoftwareModuleType type) {
|
||||
return getModules().stream().filter(module -> module.getType().equals(type)).findAny();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -73,7 +73,7 @@ public interface DistributionSetType extends NamedEntity {
|
||||
*/
|
||||
default boolean containsMandatoryModuleType(final Long softwareModuleTypeId) {
|
||||
return getMandatoryModuleTypes().stream().filter(element -> element.getId().equals(softwareModuleTypeId))
|
||||
.findFirst().isPresent();
|
||||
.findAny().isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +98,7 @@ public interface DistributionSetType extends NamedEntity {
|
||||
*/
|
||||
default boolean containsOptionalModuleType(final Long softwareModuleTypeId) {
|
||||
return getOptionalModuleTypes().stream().filter(element -> element.getId().equals(softwareModuleTypeId))
|
||||
.findFirst().isPresent();
|
||||
.findAny().isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,11 +23,7 @@ public interface SoftwareModule extends NamedVersionedEntity {
|
||||
* @return found {@link Artifact}
|
||||
*/
|
||||
default Optional<Artifact> getArtifact(final Long artifactId) {
|
||||
if (getArtifacts().isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return getArtifacts().stream().filter(artifact -> artifact.getId().equals(artifactId)).findFirst();
|
||||
return getArtifacts().stream().filter(artifact -> artifact.getId().equals(artifactId)).findAny();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,12 +32,8 @@ public interface SoftwareModule extends NamedVersionedEntity {
|
||||
* @return found {@link Artifact}
|
||||
*/
|
||||
default Optional<Artifact> getArtifactByFilename(final String fileName) {
|
||||
if (getArtifacts().isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return getArtifacts().stream().filter(artifact -> artifact.getFilename().equalsIgnoreCase(fileName.trim()))
|
||||
.findFirst();
|
||||
.findAny();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -37,23 +37,8 @@
|
||||
|
||||
<!-- TEST -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easytesting</groupId>
|
||||
<artifactId>fest-assert-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easytesting</groupId>
|
||||
<artifactId>fest-assert</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -137,7 +137,7 @@ public class EventType {
|
||||
*/
|
||||
public static EventType from(final Class<?> clazz) {
|
||||
final Optional<Integer> foundEventType = TYPES.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().equals(clazz)).map(entry -> entry.getKey()).findFirst();
|
||||
.filter(entry -> entry.getValue().equals(clazz)).map(entry -> entry.getKey()).findAny();
|
||||
if (!foundEventType.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.event;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.RemoteEntityEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.fest.assertions.api.Assertions;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -109,16 +109,6 @@
|
||||
<artifactId>allure-junit-adaptor</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easytesting</groupId>
|
||||
<artifactId>fest-assert-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easytesting</groupId>
|
||||
<artifactId>fest-assert</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
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.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
@@ -53,7 +52,7 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
* @return the found {@link Action}
|
||||
*/
|
||||
@EntityGraph(value = "Action.all", type = EntityGraphType.LOAD)
|
||||
JpaAction findById(Long actionId);
|
||||
Optional<Action> getById(Long actionId);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s which are referring the given
|
||||
@@ -113,14 +112,14 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
*
|
||||
* @param targetId
|
||||
* to search for
|
||||
* @param module
|
||||
* @param moduleId
|
||||
* to search for
|
||||
* @return action if there is one with assigned target and module is part of
|
||||
* assigned {@link DistributionSet}.
|
||||
*/
|
||||
@Query("Select a from JpaAction a join a.distributionSet ds join ds.modules modul where a.target.controllerId = :target and modul = :module order by a.id desc")
|
||||
@Query("Select a from JpaAction a join a.distributionSet ds join ds.modules modul where a.target.controllerId = :target and modul.id = :module order by a.id desc")
|
||||
List<Action> findActionByTargetAndSoftwareModule(@Param("target") final String targetId,
|
||||
@Param("module") JpaSoftwareModule module);
|
||||
@Param("module") Long moduleId);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s which are referring the given
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaTenantAwareBaseEntity;
|
||||
import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
@@ -41,4 +43,13 @@ public interface BaseEntityRepository<T extends AbstractJpaTenantAwareBaseEntity
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
void deleteByTenantIgnoreCase(String tenant);
|
||||
|
||||
/**
|
||||
* Retrieves an {@link BaseEntity} by its id.
|
||||
*
|
||||
* @param id
|
||||
* to search for
|
||||
* @return {@link BaseEntity}
|
||||
*/
|
||||
Optional<T> findById(I id);
|
||||
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
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;
|
||||
@@ -42,7 +42,7 @@ public interface DistributionSetRepository
|
||||
* @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 JpaDistributionSetTag tag);
|
||||
List<JpaDistributionSet> findByTag(@Param("tag") final DistributionSetTag tag);
|
||||
|
||||
/**
|
||||
* deletes the {@link DistributionSet}s with the given IDs.
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -44,7 +45,7 @@ public interface DistributionSetTagRepository
|
||||
* to filter on
|
||||
* @return the {@link DistributionSetTag} if found, otherwise null
|
||||
*/
|
||||
JpaDistributionSetTag findByNameEquals(final String tagName);
|
||||
Optional<DistributionSetTag> findByNameEquals(final String tagName);
|
||||
|
||||
/**
|
||||
* Returns all instances of the type.
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.artifact.repository.ArtifactRepository;
|
||||
@@ -105,9 +104,9 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public boolean clearArtifactBinary(final Long existing) {
|
||||
return clearArtifactBinary(Optional.ofNullable(localArtifactRepository.findOne(existing))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Artifact with given ID" + existing + " not found.")));
|
||||
public boolean clearArtifactBinary(final Long artifactId) {
|
||||
return clearArtifactBinary(localArtifactRepository.findById(artifactId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Artifact.class, artifactId)));
|
||||
}
|
||||
|
||||
private boolean clearArtifactBinary(final JpaArtifact existing) {
|
||||
@@ -132,11 +131,8 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteArtifact(final Long id) {
|
||||
final JpaArtifact existing = localArtifactRepository.findOne(id);
|
||||
|
||||
if (null == existing) {
|
||||
return;
|
||||
}
|
||||
final JpaArtifact existing = (JpaArtifact) findArtifact(id)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Artifact.class, id));
|
||||
|
||||
clearArtifactBinary(existing);
|
||||
|
||||
@@ -146,23 +142,23 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Artifact findArtifact(final Long id) {
|
||||
return localArtifactRepository.findOne(id);
|
||||
public Optional<Artifact> findArtifact(final Long id) {
|
||||
return Optional.ofNullable(localArtifactRepository.findOne(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Artifact> findByFilenameAndSoftwareModule(final String filename, final Long softwareModuleId) {
|
||||
return localArtifactRepository.findByFilenameAndSoftwareModuleId(filename, softwareModuleId);
|
||||
public Optional<Artifact> findByFilenameAndSoftwareModule(final String filename, final Long softwareModuleId) {
|
||||
return localArtifactRepository.findFirstByFilenameAndSoftwareModuleId(filename, softwareModuleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Artifact findFirstArtifactBySHA1(final String sha1Hash) {
|
||||
public Optional<Artifact> findFirstArtifactBySHA1(final String sha1Hash) {
|
||||
return localArtifactRepository.findFirstBySha1Hash(sha1Hash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Artifact> findArtifactByFilename(final String filename) {
|
||||
return localArtifactRepository.findByFilename(filename);
|
||||
public Optional<Artifact> findArtifactByFilename(final String filename) {
|
||||
return localArtifactRepository.findFirstByFilename(filename);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -208,7 +204,7 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
|
||||
if (softwareModule == null) {
|
||||
LOG.debug("no software module with ID {} exists", moduleId);
|
||||
throw new EntityNotFoundException("Software Module: " + moduleId);
|
||||
throw new EntityNotFoundException(SoftwareModule.class, moduleId);
|
||||
}
|
||||
return softwareModule;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||
@@ -47,7 +46,6 @@ import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
@@ -133,33 +131,31 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public Target updateLastTargetQuery(final String controllerId, final URI address) {
|
||||
final Target target = Optional.ofNullable(targetRepository.findByControllerId(controllerId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Target with given ID " + controllerId + " not found"));
|
||||
final Target target = targetRepository.findByControllerId(controllerId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
|
||||
|
||||
return updateTargetStatus(target.getTargetInfo(), null, System.currentTimeMillis(), address).getTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action getActionForDownloadByTargetAndSoftwareModule(final String controllerId,
|
||||
final SoftwareModule module) {
|
||||
final List<Action> action = actionRepository.findActionByTargetAndSoftwareModule(controllerId,
|
||||
(JpaSoftwareModule) module);
|
||||
public Optional<Action> getActionForDownloadByTargetAndSoftwareModule(final String controllerId,
|
||||
final Long moduleId) {
|
||||
final List<Action> action = actionRepository.findActionByTargetAndSoftwareModule(controllerId, moduleId);
|
||||
|
||||
if (action.isEmpty() || action.get(0).isCancelingOrCanceled()) {
|
||||
throw new EntityNotFoundException(
|
||||
"No assigment found for module " + module.getId() + " to target " + controllerId);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return action.get(0);
|
||||
return Optional.ofNullable(action.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTargetArtifactAssigned(final String controllerId, final String sha1Hash) {
|
||||
final Target target = targetRepository.findByControllerId(controllerId);
|
||||
if (target == null) {
|
||||
final Optional<Target> target = targetRepository.findByControllerId(controllerId);
|
||||
if (!target.isPresent()) {
|
||||
return false;
|
||||
}
|
||||
return actionRepository.count(ActionSpecifications.hasTargetAssignedArtifact(target, sha1Hash)) > 0;
|
||||
return actionRepository.count(ActionSpecifications.hasTargetAssignedArtifact(target.get(), sha1Hash)) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -180,8 +176,8 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action findActionWithDetails(final Long actionId) {
|
||||
return getActionAndThrowExceptionIfNotFound(actionId);
|
||||
public Optional<Action> findActionWithDetails(final Long actionId) {
|
||||
return actionRepository.getById(actionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -388,11 +384,8 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public Target updateControllerAttributes(final String controllerId, final Map<String, String> data) {
|
||||
final JpaTarget target = targetRepository.findByControllerId(controllerId);
|
||||
|
||||
if (target == null) {
|
||||
throw new EntityNotFoundException(controllerId);
|
||||
}
|
||||
final JpaTarget target = (JpaTarget) targetRepository.findByControllerId(controllerId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
|
||||
|
||||
final JpaTargetInfo targetInfo = (JpaTargetInfo) target.getTargetInfo();
|
||||
targetInfo.getControllerAttributes().putAll(data);
|
||||
@@ -435,8 +428,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
* {@link Status#RETRIEVED}
|
||||
*/
|
||||
private Action handleRegisterRetrieved(final Long actionId, final String message) {
|
||||
final JpaAction action = Optional.ofNullable(actionRepository.findById(actionId)).orElseThrow(
|
||||
() -> new EntityNotFoundException("Actionw ith given ID " + actionId + " doesn not exist."));
|
||||
final JpaAction action = getActionAndThrowExceptionIfNotFound(actionId);
|
||||
// do a manual query with CriteriaBuilder to avoid unnecessary field
|
||||
// queries and an extra
|
||||
// count query made by spring-data when using pageable requests, we
|
||||
@@ -492,8 +484,8 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
private JpaAction getActionAndThrowExceptionIfNotFound(final Long actionId) {
|
||||
return Optional.ofNullable(actionRepository.findById(actionId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Action with ID " + actionId + " not found!"));
|
||||
return actionRepository.findById(actionId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -504,13 +496,13 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Target findByControllerId(final String controllerId) {
|
||||
public Optional<Target> findByControllerId(final String controllerId) {
|
||||
return targetRepository.findByControllerId(controllerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Target findByTargetId(final Long targetId) {
|
||||
return targetRepository.findOne(targetId);
|
||||
public Optional<Target> findByTargetId(final Long targetId) {
|
||||
return Optional.ofNullable(targetRepository.findOne(targetId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -174,8 +174,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
final Collection<TargetWithActionType> targets, final String actionMessage) {
|
||||
final JpaDistributionSet set = distributoinSetRepository.findOne(dsID);
|
||||
if (set == null) {
|
||||
throw new EntityNotFoundException(
|
||||
String.format("no %s with id %d found", DistributionSet.class.getSimpleName(), dsID));
|
||||
throw new EntityNotFoundException(DistributionSet.class, dsID);
|
||||
}
|
||||
|
||||
return assignDistributionSetToTargets(set, targets, null, null, actionMessage);
|
||||
@@ -365,8 +364,8 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
public Action cancelAction(final Long actionId) {
|
||||
LOG.debug("cancelAction({})", actionId);
|
||||
|
||||
final JpaAction action = Optional.ofNullable(actionRepository.findOne(actionId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Action with given ID " + actionId + " not found"));
|
||||
final JpaAction action = actionRepository.findById(actionId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
|
||||
|
||||
if (action.isCancelingOrCanceled()) {
|
||||
throw new CancelActionNotAllowedException("Actions in canceling or canceled state cannot be canceled");
|
||||
@@ -412,8 +411,8 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
public Action forceQuitAction(final Long actionId) {
|
||||
final JpaAction action = Optional.ofNullable(actionRepository.findOne(actionId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Action with given ID " + actionId + " not found"));
|
||||
final JpaAction action = actionRepository.findById(actionId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
|
||||
|
||||
if (!action.isCancelingOrCanceled()) {
|
||||
throw new ForceQuitActionNotAllowedException(
|
||||
@@ -542,13 +541,13 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action findAction(final Long actionId) {
|
||||
return actionRepository.findOne(actionId);
|
||||
public Optional<Action> findAction(final Long actionId) {
|
||||
return Optional.ofNullable(actionRepository.findOne(actionId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action findActionWithDetails(final Long actionId) {
|
||||
return actionRepository.findById(actionId);
|
||||
public Optional<Action> findActionWithDetails(final Long actionId) {
|
||||
return actionRepository.getById(actionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -622,8 +621,10 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public Action forceTargetAction(final Long actionId) {
|
||||
final JpaAction action = actionRepository.findOne(actionId);
|
||||
if (action != null && !action.isForced()) {
|
||||
final JpaAction action = actionRepository.findById(actionId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
|
||||
|
||||
if (!action.isForced()) {
|
||||
action.setActionType(ActionType.FORCED);
|
||||
return actionRepository.save(action);
|
||||
}
|
||||
@@ -632,11 +633,19 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
|
||||
@Override
|
||||
public Page<ActionStatus> findActionStatusByAction(final Pageable pageReq, final Long actionId) {
|
||||
if (!actionRepository.exists(actionId)) {
|
||||
throw new EntityNotFoundException(Action.class, actionId);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetTypeSpecification;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
|
||||
@@ -56,6 +57,8 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -125,22 +128,28 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
private SoftwareModuleTypeRepository softwareModuleTypeRepository;
|
||||
|
||||
@Override
|
||||
public DistributionSet findDistributionSetByIdWithDetails(final Long distid) {
|
||||
return distributionSetRepository.findOne(DistributionSetSpecification.byId(distid));
|
||||
public Optional<DistributionSet> findDistributionSetByIdWithDetails(final Long distid) {
|
||||
return Optional.ofNullable(distributionSetRepository.findOne(DistributionSetSpecification.byId(distid)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSet findDistributionSetById(final Long distid) {
|
||||
return distributionSetRepository.findOne(distid);
|
||||
public Optional<DistributionSet> findDistributionSetById(final Long distid) {
|
||||
return Optional.ofNullable(distributionSetRepository.findOne(distid));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public DistributionSetTagAssignmentResult toggleTagAssignment(final Collection<Long> dsIds, final String tagName) {
|
||||
|
||||
final List<JpaDistributionSet> sets = findDistributionSetListWithDetails(dsIds);
|
||||
final DistributionSetTag myTag = tagManagement.findDistributionSetTag(tagName);
|
||||
|
||||
if (sets.size() < dsIds.size()) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, dsIds,
|
||||
sets.stream().map(DistributionSet::getId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
final DistributionSetTag myTag = tagManagement.findDistributionSetTag(tagName)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName));
|
||||
|
||||
DistributionSetTagAssignmentResult result;
|
||||
|
||||
@@ -207,46 +216,37 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
}
|
||||
|
||||
private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final String distributionSetTypekey) {
|
||||
|
||||
final DistributionSetType module = findDistributionSetTypeByKey(distributionSetTypekey);
|
||||
if (module == null) {
|
||||
throw new EntityNotFoundException(
|
||||
"DistributionSetType with key {" + distributionSetTypekey + "} does not exist");
|
||||
}
|
||||
return module;
|
||||
return findDistributionSetTypeByKey(distributionSetTypekey)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distributionSetTypekey));
|
||||
}
|
||||
|
||||
private JpaDistributionSetType findDistributionSetTypeAndThrowExceptionIfNotFound(final Long setId) {
|
||||
final JpaDistributionSetType set = (JpaDistributionSetType) findDistributionSetTypeById(setId);
|
||||
return (JpaDistributionSetType) findDistributionSetTypeById(setId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, setId));
|
||||
|
||||
if (set == null) {
|
||||
throw new EntityNotFoundException("Distribution set type cannot be updated as it does not exixt" + setId);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
private JpaDistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) {
|
||||
final JpaDistributionSet set = (JpaDistributionSet) findDistributionSetById(setId);
|
||||
|
||||
if (set == null) {
|
||||
throw new EntityNotFoundException("Distribution set cannot be updated as it does not exixt" + setId);
|
||||
}
|
||||
return set;
|
||||
return (JpaDistributionSet) findDistributionSetById(setId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId));
|
||||
}
|
||||
|
||||
private JpaSoftwareModule findSoftwareModuleAndThrowExceptionIfNotFound(final Long moduleId) {
|
||||
final JpaSoftwareModule module = softwareModuleRepository.findOne(moduleId);
|
||||
|
||||
if (module == null) {
|
||||
throw new EntityNotFoundException("Distribution set cannot be updated as it does not exixt" + moduleId);
|
||||
}
|
||||
return module;
|
||||
return Optional.ofNullable(softwareModuleRepository.findOne(moduleId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, moduleId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteDistributionSet(final Collection<Long> distributionSetIDs) {
|
||||
final List<DistributionSet> setsFound = findDistributionSetAllById(distributionSetIDs);
|
||||
|
||||
if (setsFound.size() < distributionSetIDs.size()) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, distributionSetIDs,
|
||||
setsFound.stream().map(DistributionSet::getId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
final List<Long> assigned = distributionSetRepository
|
||||
.findAssignedToTargetDistributionSetsById(distributionSetIDs);
|
||||
assigned.addAll(distributionSetRepository.findAssignedToRolloutDistributionSetsById(distributionSetIDs));
|
||||
@@ -303,15 +303,17 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public DistributionSet assignSoftwareModules(final Long setId, final Collection<Long> moduleIds) {
|
||||
final JpaDistributionSet set = findDistributionSetAndThrowExceptionIfNotFound(setId);
|
||||
|
||||
final Collection<JpaSoftwareModule> modules = softwareModuleRepository.findByIdIn(moduleIds);
|
||||
|
||||
if (modules.size() < moduleIds.size()) {
|
||||
throw new EntityNotFoundException("Not all given software modules where found.");
|
||||
throw new EntityNotFoundException(SoftwareModule.class, moduleIds,
|
||||
modules.stream().map(SoftwareModule::getId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
checkDistributionSetIsAssignedToTargets(setId);
|
||||
|
||||
final JpaDistributionSet set = findDistributionSetAndThrowExceptionIfNotFound(setId);
|
||||
modules.forEach(set::addModule);
|
||||
|
||||
return distributionSetRepository.save(set);
|
||||
@@ -363,15 +365,15 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public DistributionSetType assignMandatorySoftwareModuleTypes(final Long dsTypeId,
|
||||
final Collection<Long> softwareModulesTypeIds) {
|
||||
final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(dsTypeId);
|
||||
|
||||
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository
|
||||
.findByIdIn(softwareModulesTypeIds);
|
||||
|
||||
if (modules.size() < softwareModulesTypeIds.size()) {
|
||||
throw new EntityNotFoundException("Not all given software module types where found.");
|
||||
throw new EntityNotFoundException(SoftwareModuleType.class, softwareModulesTypeIds,
|
||||
modules.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(dsTypeId);
|
||||
checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(dsTypeId);
|
||||
|
||||
modules.forEach(type::addMandatoryModuleType);
|
||||
@@ -384,17 +386,17 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public DistributionSetType assignOptionalSoftwareModuleTypes(final Long dsTypeId,
|
||||
final Collection<Long> softwareModulesTypeIds) {
|
||||
final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(dsTypeId);
|
||||
|
||||
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository
|
||||
.findByIdIn(softwareModulesTypeIds);
|
||||
|
||||
if (modules.size() < softwareModulesTypeIds.size()) {
|
||||
throw new EntityNotFoundException("Not all given software module types where found.");
|
||||
throw new EntityNotFoundException(SoftwareModuleType.class, softwareModulesTypeIds,
|
||||
modules.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(dsTypeId);
|
||||
checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(dsTypeId);
|
||||
|
||||
modules.forEach(type::addOptionalModuleType);
|
||||
|
||||
return distributionSetTypeRepository.save(type);
|
||||
@@ -545,10 +547,11 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSet findDistributionSetByNameAndVersion(final String distributionName, final String version) {
|
||||
public Optional<DistributionSet> findDistributionSetByNameAndVersion(final String distributionName,
|
||||
final String version) {
|
||||
final Specification<JpaDistributionSet> spec = DistributionSetSpecification
|
||||
.equalsNameAndVersionIgnoreCase(distributionName, version);
|
||||
return distributionSetRepository.findOne(spec);
|
||||
return Optional.ofNullable(distributionSetRepository.findOne(spec));
|
||||
|
||||
}
|
||||
|
||||
@@ -571,18 +574,20 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSetType findDistributionSetTypeByName(final String name) {
|
||||
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name));
|
||||
public Optional<DistributionSetType> findDistributionSetTypeByName(final String name) {
|
||||
return Optional
|
||||
.ofNullable(distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSetType findDistributionSetTypeById(final Long id) {
|
||||
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byId(id));
|
||||
public Optional<DistributionSetType> findDistributionSetTypeById(final Long typeId) {
|
||||
return Optional
|
||||
.ofNullable(distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byId(typeId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSetType findDistributionSetTypeByKey(final String key) {
|
||||
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key));
|
||||
public Optional<DistributionSetType> findDistributionSetTypeByKey(final String key) {
|
||||
return Optional.ofNullable(distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -599,9 +604,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteDistributionSetType(final Long typeId) {
|
||||
|
||||
final JpaDistributionSetType toDelete = Optional.ofNullable(distributionSetTypeRepository.findOne(typeId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"DistributionSet Type with given ID " + typeId + " does not exist"));
|
||||
final JpaDistributionSetType toDelete = distributionSetTypeRepository.findById(typeId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, typeId));
|
||||
|
||||
if (distributionSetRepository.countByTypeId(typeId) > 0) {
|
||||
toDelete.setDeleted(true);
|
||||
@@ -634,7 +638,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
|
||||
// check if exists otherwise throw entity not found exception
|
||||
final JpaDistributionSetMetadata toUpdate = (JpaDistributionSetMetadata) findDistributionSetMetadata(dsId,
|
||||
md.getKey());
|
||||
md.getKey()).orElseThrow(
|
||||
() -> new EntityNotFoundException(DistributionSetMetadata.class, dsId, md.getKey()));
|
||||
toUpdate.setValue(md.getValue());
|
||||
// touch it to update the lock revision because we are modifying the
|
||||
// DS indirectly
|
||||
@@ -645,9 +650,32 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Override
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@Modifying
|
||||
public void deleteDistributionSetMetadata(final Long distributionSet, final String key) {
|
||||
touch(distributionSet);
|
||||
distributionSetMetadataRepository.delete(new DsMetadataCompositeKey(distributionSet, key));
|
||||
public void deleteDistributionSetMetadata(final Long distributionSetId, final String key) {
|
||||
final JpaDistributionSetMetadata metadata = (JpaDistributionSetMetadata) findDistributionSetMetadata(
|
||||
distributionSetId, key).orElseThrow(
|
||||
() -> new EntityNotFoundException(DistributionSetMetadata.class, distributionSetId, key));
|
||||
|
||||
touch(metadata.getDistributionSet());
|
||||
distributionSetMetadataRepository.delete(metadata.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the latest distribution set based on DS ID after the
|
||||
* metadata changes for that distribution set.
|
||||
*
|
||||
* @param ds
|
||||
* is the DS to touch
|
||||
*/
|
||||
private JpaDistributionSet touch(final DistributionSet ds) {
|
||||
|
||||
// merge base distribution set so optLockRevision gets updated and audit
|
||||
// log written because
|
||||
// modifying metadata is modifying the base distribution set itself for
|
||||
// auditing purposes.
|
||||
final JpaDistributionSet result = entityManager.merge((JpaDistributionSet) ds);
|
||||
result.setLastModifiedAt(0L);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -655,24 +683,20 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
* metadata changes for that distribution set.
|
||||
*
|
||||
* @param distId
|
||||
* Distribution set
|
||||
* of the DS to touch
|
||||
*/
|
||||
private JpaDistributionSet touch(final Long distId) {
|
||||
final DistributionSet latestDistributionSet = findDistributionSetAndThrowExceptionIfNotFound(distId);
|
||||
|
||||
// merge base distribution set so optLockRevision gets updated and audit
|
||||
// log written because
|
||||
// modifying metadata is modifying the base distribution set itself for
|
||||
// auditing purposes.
|
||||
final JpaDistributionSet result = entityManager.merge((JpaDistributionSet) latestDistributionSet);
|
||||
result.setLastModifiedAt(0L);
|
||||
|
||||
return result;
|
||||
return touch(findDistributionSetById(distId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, distId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(final Long distributionSetId,
|
||||
final Pageable pageable) {
|
||||
if (!distributionSetRepository.exists(distributionSetId)) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, distributionSetId);
|
||||
}
|
||||
|
||||
return convertMdPage(distributionSetMetadataRepository
|
||||
.findAll((Specification<JpaDistributionSetMetadata>) (root, query, cb) -> cb.equal(
|
||||
root.get(JpaDistributionSetMetadata_.distributionSet).get(JpaDistributionSet_.id),
|
||||
@@ -680,18 +704,14 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(final Long distributionSetId) {
|
||||
return Collections.unmodifiableList(distributionSetMetadataRepository
|
||||
.findAll((Specification<JpaDistributionSetMetadata>) (root, query, cb) -> cb.equal(
|
||||
root.get(JpaDistributionSetMetadata_.distributionSet).get(JpaDistributionSet_.id),
|
||||
distributionSetId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(final Long distributionSetId,
|
||||
final String rsqlParam, final Pageable pageable) {
|
||||
|
||||
if (!distributionSetRepository.exists(distributionSetId)) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, distributionSetId);
|
||||
}
|
||||
|
||||
final Specification<JpaDistributionSetMetadata> spec = RSQLUtility.parse(rsqlParam,
|
||||
DistributionSetMetadataFields.class, virtualPropertyReplacer);
|
||||
|
||||
@@ -710,18 +730,18 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSetMetadata findDistributionSetMetadata(final Long distributionSet, final String key) {
|
||||
final DistributionSetMetadata findOne = distributionSetMetadataRepository
|
||||
.findOne(new DsMetadataCompositeKey(distributionSet, key));
|
||||
if (findOne == null) {
|
||||
throw new EntityNotFoundException("Metadata with key '" + key + "' does not exist");
|
||||
}
|
||||
return findOne;
|
||||
public Optional<DistributionSetMetadata> findDistributionSetMetadata(final Long distributionSet, final String key) {
|
||||
return Optional.ofNullable(
|
||||
distributionSetMetadataRepository.findOne(new DsMetadataCompositeKey(distributionSet, key)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSet findDistributionSetByAction(final Long actionId) {
|
||||
return distributionSetRepository.findByActionId(actionId);
|
||||
public Optional<DistributionSet> findDistributionSetByAction(final Long actionId) {
|
||||
if (!actionRepository.exists(actionId)) {
|
||||
throw new EntityNotFoundException(Action.class, actionId);
|
||||
}
|
||||
|
||||
return Optional.ofNullable(distributionSetRepository.findByActionId(actionId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -819,10 +839,13 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
public List<DistributionSet> assignTag(final Collection<Long> dsIds, final Long dsTagId) {
|
||||
final List<JpaDistributionSet> allDs = findDistributionSetListWithDetails(dsIds);
|
||||
|
||||
final DistributionSetTag distributionSetTag = Optional
|
||||
.ofNullable(tagManagement.findDistributionSetTagById(dsTagId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"DistributionSet Tag with given ID " + dsTagId + " not found."));
|
||||
if (allDs.size() < dsIds.size()) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, dsIds,
|
||||
allDs.stream().map(DistributionSet::getId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
final DistributionSetTag distributionSetTag = tagManagement.findDistributionSetTagById(dsTagId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId));
|
||||
|
||||
allDs.forEach(ds -> ds.addTag(distributionSetTag));
|
||||
|
||||
@@ -835,10 +858,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public List<DistributionSet> unAssignAllDistributionSetsByTag(final Long dsTagId) {
|
||||
|
||||
final DistributionSetTag distributionSetTag = Optional
|
||||
.ofNullable(tagManagement.findDistributionSetTagById(dsTagId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"DistributionSet Tag with given ID " + dsTagId + " not found."));
|
||||
final DistributionSetTag distributionSetTag = tagManagement.findDistributionSetTagById(dsTagId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId));
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
final Collection<JpaDistributionSet> distributionSets = (Collection) distributionSetTag
|
||||
@@ -854,13 +875,11 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
final List<JpaDistributionSet> allDs = findDistributionSetListWithDetails(Arrays.asList(dsId));
|
||||
|
||||
if (allDs.isEmpty()) {
|
||||
throw new EntityNotFoundException("DistributionSet with given ID " + dsId + " not found.");
|
||||
throw new EntityNotFoundException(DistributionSet.class, dsId);
|
||||
}
|
||||
|
||||
final DistributionSetTag distributionSetTag = Optional
|
||||
.ofNullable(tagManagement.findDistributionSetTagById(dsTagId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"DistributionSet Tag with given ID " + dsTagId + " not found."));
|
||||
final DistributionSetTag distributionSetTag = tagManagement.findDistributionSetTagById(dsTagId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId));
|
||||
final List<JpaDistributionSet> unAssignTag = unAssignTag(allDs, distributionSetTag);
|
||||
return unAssignTag.isEmpty() ? null : unAssignTag.get(0);
|
||||
}
|
||||
@@ -885,7 +904,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteDistributionSet(final Long setId) {
|
||||
if (!distributionSetRepository.exists(setId)) {
|
||||
throw new EntityNotFoundException("DistributionSet with given ID " + setId + " does not exist.");
|
||||
throw new EntityNotFoundException(DistributionSet.class, setId);
|
||||
}
|
||||
|
||||
deleteDistributionSet(Lists.newArrayList(setId));
|
||||
@@ -893,6 +912,10 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
|
||||
@Override
|
||||
public Long countDistributionSetsByType(final Long typeId) {
|
||||
if (!distributionSetTypeRepository.exists(typeId)) {
|
||||
throw new EntityNotFoundException(DistributionSetType.class, typeId);
|
||||
}
|
||||
|
||||
return distributionSetRepository.countByTypeId(typeId);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,8 +78,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
private VirtualPropertyReplacer virtualPropertyReplacer;
|
||||
|
||||
@Override
|
||||
public RolloutGroup findRolloutGroupById(final Long rolloutGroupId) {
|
||||
return rolloutGroupRepository.findOne(rolloutGroupId);
|
||||
public Optional<RolloutGroup> findRolloutGroupById(final Long rolloutGroupId) {
|
||||
return Optional.ofNullable(rolloutGroupRepository.findOne(rolloutGroupId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,14 +131,21 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolloutGroup findRolloutGroupWithDetailedStatus(final Long rolloutGroupId) {
|
||||
final JpaRolloutGroup rolloutGroup = (JpaRolloutGroup) findRolloutGroupById(rolloutGroupId);
|
||||
public Optional<RolloutGroup> findRolloutGroupWithDetailedStatus(final Long rolloutGroupId) {
|
||||
final Optional<RolloutGroup> rolloutGroup = findRolloutGroupById(rolloutGroupId);
|
||||
|
||||
if (!rolloutGroup.isPresent()) {
|
||||
return rolloutGroup;
|
||||
}
|
||||
|
||||
final JpaRolloutGroup jpaRolloutGroup = (JpaRolloutGroup) rolloutGroup.get();
|
||||
|
||||
final List<TotalTargetCountActionStatus> rolloutStatusCountItems = actionRepository
|
||||
.getStatusCountByRolloutGroupId(rolloutGroupId);
|
||||
|
||||
final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(rolloutStatusCountItems,
|
||||
Long.valueOf(rolloutGroup.getTotalTargets()));
|
||||
rolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus);
|
||||
Long.valueOf(jpaRolloutGroup.getTotalTargets()));
|
||||
jpaRolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus);
|
||||
return rolloutGroup;
|
||||
|
||||
}
|
||||
@@ -168,9 +175,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
|
||||
@Override
|
||||
public Page<Target> findRolloutGroupTargets(final Long rolloutGroupId, final Pageable page) {
|
||||
final JpaRolloutGroup rolloutGroup = Optional.ofNullable(rolloutGroupRepository.findOne(rolloutGroupId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"Rollout Group with given ID " + rolloutGroupId + " not found."));
|
||||
final JpaRolloutGroup rolloutGroup = rolloutGroupRepository.findById(rolloutGroupId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, rolloutGroupId));
|
||||
|
||||
if (isRolloutStatusReady(rolloutGroup)) {
|
||||
// in case of status ready the action has not been created yet and
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.validation.ConstraintDeclarationException;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -34,6 +33,7 @@ import org.eclipse.hawkbit.repository.builder.RolloutUpdate;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent;
|
||||
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.RolloutIllegalStateException;
|
||||
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
@@ -147,7 +147,6 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
|
||||
@Override
|
||||
public Page<Rollout> findAllByPredicate(final String rsqlParam, final Pageable pageable) {
|
||||
|
||||
final Specification<JpaRollout> specification = RSQLUtility.parse(rsqlParam, RolloutFields.class,
|
||||
virtualPropertyReplacer);
|
||||
|
||||
@@ -156,8 +155,8 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rollout findRolloutById(final Long rolloutId) {
|
||||
return rolloutRepository.findOne(rolloutId);
|
||||
public Optional<Rollout> findRolloutById(final Long rolloutId) {
|
||||
return Optional.ofNullable(rolloutRepository.findOne(rolloutId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,9 +180,9 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
}
|
||||
|
||||
private JpaRollout createRollout(final JpaRollout rollout) {
|
||||
final JpaRollout existingRollout = rolloutRepository.findByName(rollout.getName());
|
||||
if (existingRollout != null) {
|
||||
throw new EntityAlreadyExistsException(existingRollout.getName());
|
||||
final Optional<Rollout> existingRollout = rolloutRepository.findByName(rollout.getName());
|
||||
if (existingRollout.isPresent()) {
|
||||
throw new EntityAlreadyExistsException(existingRollout.get().getName());
|
||||
}
|
||||
|
||||
final Long totalTargets = targetManagement.countTargetByTargetFilterQuery(rollout.getTargetFilterQuery());
|
||||
@@ -294,8 +293,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@Modifying
|
||||
public void fillRolloutGroupsWithTargets(final Long rolloutId) {
|
||||
final JpaRollout rollout = Optional.ofNullable(rolloutRepository.findOne(rolloutId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Rollout with id " + rolloutId + " not found."));
|
||||
final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(rolloutId);
|
||||
|
||||
RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.CREATING);
|
||||
|
||||
@@ -409,7 +407,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
throw new ConstraintDeclarationException("Rollout target filter does not match any targets");
|
||||
}
|
||||
|
||||
RolloutGroupsValidation validation = validateTargetsInGroups(groups, baseFilter, totalTargets);
|
||||
final RolloutGroupsValidation validation = validateTargetsInGroups(groups, baseFilter, totalTargets);
|
||||
|
||||
return totalTargets - validation.getTargetsInGroups();
|
||||
}
|
||||
@@ -433,14 +431,14 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
final long totalTargets) {
|
||||
final List<Long> groupTargetCounts = new ArrayList<>(groups.size());
|
||||
final Map<String, Long> targetFilterCounts = groups.stream()
|
||||
.map(group -> RolloutHelper.getGroupTargetFilter(baseFilter, group)).distinct().collect(Collectors
|
||||
.toMap(Function.identity(), filter -> targetManagement.countTargetByTargetFilterQuery(filter)));
|
||||
.map(group -> RolloutHelper.getGroupTargetFilter(baseFilter, group)).distinct()
|
||||
.collect(Collectors.toMap(Function.identity(), targetManagement::countTargetByTargetFilterQuery));
|
||||
|
||||
long unusedTargetsCount = 0;
|
||||
|
||||
for (int i = 0; i < groups.size(); i++) {
|
||||
final RolloutGroup group = groups.get(i);
|
||||
String groupTargetFilter = RolloutHelper.getGroupTargetFilter(baseFilter, group);
|
||||
final String groupTargetFilter = RolloutHelper.getGroupTargetFilter(baseFilter, group);
|
||||
RolloutHelper.verifyRolloutGroupTargetPercentage(group.getTargetPercentage());
|
||||
|
||||
final long targetsInGroupFilter = targetFilterCounts.get(groupTargetFilter);
|
||||
@@ -474,8 +472,8 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
return 0;
|
||||
}
|
||||
final List<RolloutGroup> previousGroups = groups.subList(0, groupIndex);
|
||||
String overlappingTargetsFilter = RolloutHelper.getOverlappingWithGroupsTargetFilter(baseFilter, previousGroups,
|
||||
group);
|
||||
final String overlappingTargetsFilter = RolloutHelper.getOverlappingWithGroupsTargetFilter(baseFilter,
|
||||
previousGroups, group);
|
||||
|
||||
if (targetFilterCounts.containsKey(overlappingTargetsFilter)) {
|
||||
return targetFilterCounts.get(overlappingTargetsFilter);
|
||||
@@ -490,8 +488,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@Modifying
|
||||
public Rollout startRollout(final Long rolloutId) {
|
||||
final JpaRollout rollout = Optional.ofNullable(rolloutRepository.findOne(rolloutId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Rollout with id " + rolloutId + " not found."));
|
||||
final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(rolloutId);
|
||||
RolloutHelper.checkIfRolloutCanStarted(rollout, rollout);
|
||||
rollout.setStatus(RolloutStatus.STARTING);
|
||||
rollout.setLastCheck(0);
|
||||
@@ -516,7 +513,6 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
jpaRollout.setStatus(RolloutStatus.RUNNING);
|
||||
jpaRollout.setLastCheck(0);
|
||||
rolloutRepository.save(jpaRollout);
|
||||
|
||||
}
|
||||
|
||||
private boolean ensureAllGroupsAreScheduled(final Rollout rollout) {
|
||||
@@ -534,12 +530,6 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
/**
|
||||
* Schedules a group of the rollout. Scheduled Actions are created to
|
||||
* achieve this. The creation of those Actions is allowed to fail.
|
||||
*
|
||||
* @param rollout
|
||||
* the Rollout
|
||||
* @param group
|
||||
* the RolloutGroup
|
||||
* @return whether the complete group was scheduled
|
||||
*/
|
||||
private boolean scheduleRolloutGroup(final JpaRollout rollout, final JpaRolloutGroup group) {
|
||||
final long targetsInGroup = rolloutTargetGroupRepository.countByRolloutGroup(group);
|
||||
@@ -599,19 +589,6 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
* Creates an action entry into the action repository. In case of existing
|
||||
* scheduled actions the scheduled actions gets canceled. A scheduled action
|
||||
* is created in-active.
|
||||
*
|
||||
* @param targets
|
||||
* the targets to create scheduled actions for
|
||||
* @param distributionSet
|
||||
* the distribution set for the actions
|
||||
* @param actionType
|
||||
* the action type for the action
|
||||
* @param forcedTime
|
||||
* the forcedTime of the action
|
||||
* @param rollout
|
||||
* the roll out for this action
|
||||
* @param rolloutGroup
|
||||
* the roll out group for this action
|
||||
*/
|
||||
private void createScheduledAction(final Collection<Target> targets, final DistributionSet distributionSet,
|
||||
final ActionType actionType, final Long forcedTime, final Rollout rollout,
|
||||
@@ -620,7 +597,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
// is already scheduled and a next action is created then cancel the
|
||||
// current scheduled action to cancel. E.g. a new scheduled action is
|
||||
// created.
|
||||
final List<Long> targetIds = targets.stream().map(t -> t.getId()).collect(Collectors.toList());
|
||||
final List<Long> targetIds = targets.stream().map(Target::getId).collect(Collectors.toList());
|
||||
actionRepository.switchStatus(Action.Status.CANCELED, targetIds, false, Action.Status.SCHEDULED);
|
||||
targets.forEach(target -> {
|
||||
final JpaAction action = new JpaAction();
|
||||
@@ -640,8 +617,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@Modifying
|
||||
public void pauseRollout(final Long rolloutId) {
|
||||
final JpaRollout rollout = Optional.ofNullable(rolloutRepository.findOne(rolloutId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Rollout with id " + rolloutId + " not found."));
|
||||
final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(rolloutId);
|
||||
if (rollout.getStatus() != RolloutStatus.RUNNING) {
|
||||
throw new RolloutIllegalStateException("Rollout can only be paused in state running but current state is "
|
||||
+ rollout.getStatus().name().toLowerCase());
|
||||
@@ -659,8 +635,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@Modifying
|
||||
public void resumeRollout(final Long rolloutId) {
|
||||
final JpaRollout rollout = Optional.ofNullable(rolloutRepository.findOne(rolloutId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Rollout with id " + rolloutId + " not found."));
|
||||
final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(rolloutId);
|
||||
if (!(RolloutStatus.PAUSED.equals(rollout.getStatus()))) {
|
||||
throw new RolloutIllegalStateException("Rollout can only be resumed in state paused but current state is "
|
||||
+ rollout.getStatus().name().toLowerCase());
|
||||
@@ -855,7 +830,6 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
startFirstRolloutGroup(rollout);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -876,7 +850,6 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
startRollout(rollout.getId());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private List<JpaRollout> getRolloutsToCheckForStatus(final long delayBetweenChecks, final RolloutStatus status) {
|
||||
@@ -891,7 +864,6 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
}
|
||||
|
||||
return rolloutRepository.findByLastCheckAndStatus(lastCheck, status);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -913,7 +885,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rollout findRolloutByName(final String rolloutName) {
|
||||
public Optional<Rollout> findRolloutByName(final String rolloutName) {
|
||||
return rolloutRepository.findByName(rolloutName);
|
||||
}
|
||||
|
||||
@@ -922,8 +894,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
@Modifying
|
||||
public Rollout updateRollout(final RolloutUpdate u) {
|
||||
final GenericRolloutUpdate update = (GenericRolloutUpdate) u;
|
||||
final JpaRollout rollout = Optional.ofNullable(rolloutRepository.findOne(update.getId()))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Rollout with id " + update.getId() + " not found."));
|
||||
final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(update.getId());
|
||||
|
||||
update.getName().ifPresent(rollout::setName);
|
||||
update.getDescription().ifPresent(rollout::setDescription);
|
||||
@@ -931,32 +902,40 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
update.getForcedTime().ifPresent(rollout::setForcedTime);
|
||||
update.getStartAt().ifPresent(rollout::setStartAt);
|
||||
update.getSet().ifPresent(setId -> {
|
||||
final DistributionSet set = distributionSetManagement.findDistributionSetById(setId);
|
||||
if (set == null) {
|
||||
throw new EntityNotFoundException("Distribution set cannot be set as it does not exists" + setId);
|
||||
}
|
||||
final DistributionSet set = distributionSetManagement.findDistributionSetById(setId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId));
|
||||
|
||||
rollout.setDistributionSet(set);
|
||||
});
|
||||
|
||||
return rolloutRepository.save(rollout);
|
||||
}
|
||||
|
||||
private JpaRollout getRolloutAndThrowExceptionIfNotFound(final Long rolloutId) {
|
||||
return rolloutRepository.findById(rolloutId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Rollout> findAllRolloutsWithDetailedStatus(final Pageable pageable) {
|
||||
final Page<JpaRollout> rollouts = rolloutRepository.findAll(pageable);
|
||||
setRolloutStatusDetails(rollouts);
|
||||
return RolloutHelper.convertPage(rollouts, pageable);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rollout findRolloutWithDetailedStatus(final Long rolloutId) {
|
||||
final Rollout rollout = findRolloutById(rolloutId);
|
||||
public Optional<Rollout> findRolloutWithDetailedStatus(final Long rolloutId) {
|
||||
final Optional<Rollout> rollout = findRolloutById(rolloutId);
|
||||
|
||||
if (!rollout.isPresent()) {
|
||||
return rollout;
|
||||
}
|
||||
|
||||
final List<TotalTargetCountActionStatus> rolloutStatusCountItems = actionRepository
|
||||
.getStatusCountByRolloutId(rolloutId);
|
||||
final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(rolloutStatusCountItems,
|
||||
rollout.getTotalTargets());
|
||||
((JpaRollout) rollout).setTotalTargetCountStatus(totalTargetCountStatus);
|
||||
rollout.get().getTotalTargets());
|
||||
((JpaRollout) rollout.get()).setTotalTargetCountStatus(totalTargetCountStatus);
|
||||
return rollout;
|
||||
}
|
||||
|
||||
@@ -966,8 +945,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
}
|
||||
|
||||
private void setRolloutStatusDetails(final Slice<JpaRollout> rollouts) {
|
||||
final List<Long> rolloutIds = rollouts.getContent().stream().map(rollout -> rollout.getId())
|
||||
.collect(Collectors.toList());
|
||||
final List<Long> rolloutIds = rollouts.getContent().stream().map(Rollout::getId).collect(Collectors.toList());
|
||||
final Map<Long, List<TotalTargetCountActionStatus>> allStatesForRollout = getStatusCountItemForRollout(
|
||||
rolloutIds);
|
||||
|
||||
@@ -980,20 +958,24 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
|
||||
@Override
|
||||
public float getFinishedPercentForRunningGroup(final Long rolloutId, final Long rolloutGroupId) {
|
||||
final RolloutGroup rolloutGroup = Optional.ofNullable(rolloutGroupRepository.findOne(rolloutGroupId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"Rollout group with given ID " + rolloutGroupId + " not found."));
|
||||
final RolloutGroup rolloutGroup = rolloutGroupRepository.findById(rolloutGroupId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, rolloutGroupId));
|
||||
|
||||
final long totalGroup = rolloutGroup.getTotalTargets();
|
||||
final Long finished = actionRepository.countByRolloutIdAndRolloutGroupIdAndStatus(rolloutId,
|
||||
rolloutGroup.getId(), Action.Status.FINISHED);
|
||||
if (totalGroup == 0) {
|
||||
// in case e.g. targets has been deleted we don't have any actions
|
||||
// left for this group, so the group is finished
|
||||
return 100;
|
||||
}
|
||||
|
||||
final Long finished = actionRepository.countByRolloutIdAndRolloutGroupIdAndStatus(rolloutId,
|
||||
rolloutGroup.getId(), Action.Status.FINISHED);
|
||||
// calculate threshold
|
||||
return ((float) finished / (float) totalGroup) * 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(final Long rolloutId) {
|
||||
return rolloutRepository.exists(rolloutId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecifica
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.AssignedSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
@@ -122,9 +123,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
public SoftwareModule updateSoftwareModule(final SoftwareModuleUpdate u) {
|
||||
final GenericSoftwareModuleUpdate update = (GenericSoftwareModuleUpdate) u;
|
||||
|
||||
final JpaSoftwareModule module = Optional.ofNullable(softwareModuleRepository.findOne(update.getId()))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"Software module cannot be updated as it does not exixt" + update.getId()));
|
||||
final JpaSoftwareModule module = softwareModuleRepository.findById(update.getId())
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, update.getId()));
|
||||
|
||||
update.getDescription().ifPresent(module::setDescription);
|
||||
update.getVendor().ifPresent(module::setVendor);
|
||||
@@ -138,7 +138,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
public SoftwareModuleType updateSoftwareModuleType(final SoftwareModuleTypeUpdate u) {
|
||||
final GenericSoftwareModuleTypeUpdate update = (GenericSoftwareModuleTypeUpdate) u;
|
||||
|
||||
final JpaSoftwareModuleType type = findSoftwareModuleTypeAndThrowExceptionIfNotFound(update.getId());
|
||||
final JpaSoftwareModuleType type = (JpaSoftwareModuleType) findSoftwareModuleTypeById(update.getId())
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, update.getId()));
|
||||
|
||||
update.getDescription().ifPresent(type::setDescription);
|
||||
update.getColour().ifPresent(type::setColour);
|
||||
@@ -146,15 +147,6 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
return softwareModuleTypeRepository.save(type);
|
||||
}
|
||||
|
||||
private JpaSoftwareModuleType findSoftwareModuleTypeAndThrowExceptionIfNotFound(final Long smTypeid) {
|
||||
final JpaSoftwareModuleType set = softwareModuleTypeRepository.findOne(smTypeid);
|
||||
|
||||
if (set == null) {
|
||||
throw new EntityNotFoundException("Software module type cannot be updated as it does not exixt" + smTypeid);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@@ -173,6 +165,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
|
||||
@Override
|
||||
public Slice<SoftwareModule> findSoftwareModulesByType(final Pageable pageable, final Long typeId) {
|
||||
throwExceptionIfSoftwareModuleTypeDoesNotExist(typeId);
|
||||
|
||||
final List<Specification<JpaSoftwareModule>> specList = Lists.newArrayListWithExpectedSize(2);
|
||||
|
||||
@@ -182,6 +175,12 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList), pageable);
|
||||
}
|
||||
|
||||
private void throwExceptionIfSoftwareModuleTypeDoesNotExist(final Long typeId) {
|
||||
if (!softwareModuleTypeRepository.exists(typeId)) {
|
||||
throw new EntityNotFoundException(SoftwareModuleType.class, typeId);
|
||||
}
|
||||
}
|
||||
|
||||
private static Slice<SoftwareModule> convertSmPage(final Slice<JpaSoftwareModule> findAll,
|
||||
final Pageable pageable) {
|
||||
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, 0);
|
||||
@@ -197,14 +196,16 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModule findSoftwareModuleById(final Long id) {
|
||||
return softwareModuleRepository.findOne(id);
|
||||
public Optional<SoftwareModule> findSoftwareModuleById(final Long id) {
|
||||
return Optional.ofNullable(softwareModuleRepository.findOne(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModule findSoftwareModuleByNameAndVersion(final String name, final String version,
|
||||
public Optional<SoftwareModule> findSoftwareModuleByNameAndVersion(final String name, final String version,
|
||||
final Long typeId) {
|
||||
|
||||
throwExceptionIfSoftwareModuleTypeDoesNotExist(typeId);
|
||||
|
||||
return softwareModuleRepository.findOneByNameAndVersionAndTypeId(name, version, typeId);
|
||||
}
|
||||
|
||||
@@ -233,6 +234,12 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteSoftwareModules(final Collection<Long> ids) {
|
||||
final List<JpaSoftwareModule> swModulesToDelete = softwareModuleRepository.findByIdIn(ids);
|
||||
|
||||
if (swModulesToDelete.size() < ids.size()) {
|
||||
throw new EntityNotFoundException(SoftwareModule.class, ids,
|
||||
swModulesToDelete.stream().map(SoftwareModule::getId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
final Set<Long> assignedModuleIds = new HashSet<>();
|
||||
swModulesToDelete.forEach(swModule -> {
|
||||
|
||||
@@ -329,6 +336,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
}
|
||||
|
||||
if (null != typeId) {
|
||||
throwExceptionIfSoftwareModuleTypeDoesNotExist(typeId);
|
||||
|
||||
spec = SoftwareModuleSpecification.equalType(typeId);
|
||||
specList.add(spec);
|
||||
}
|
||||
@@ -393,8 +402,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
Predicate[] unassignedSpec;
|
||||
if (!assignedSoftwareModules.isEmpty()) {
|
||||
unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, typeId), unassignedRoot,
|
||||
unassignedQuery, cb, cb.not(unassignedRoot.get(JpaSoftwareModule_.id)
|
||||
.in(assignedSoftwareModules.stream().map(sw -> sw.getId()).collect(Collectors.toList()))));
|
||||
unassignedQuery, cb, cb.not(unassignedRoot.get(JpaSoftwareModule_.id).in(
|
||||
assignedSoftwareModules.stream().map(SoftwareModule::getId).collect(Collectors.toList()))));
|
||||
} else {
|
||||
unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, typeId), unassignedRoot,
|
||||
unassignedQuery, cb);
|
||||
@@ -412,13 +421,14 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
return new SliceImpl<>(resultList);
|
||||
}
|
||||
|
||||
private static List<Specification<JpaSoftwareModule>> buildSpecificationList(final String searchText,
|
||||
final Long typeId) {
|
||||
private List<Specification<JpaSoftwareModule>> buildSpecificationList(final String searchText, final Long typeId) {
|
||||
final List<Specification<JpaSoftwareModule>> specList = Lists.newArrayListWithExpectedSize(3);
|
||||
if (!Strings.isNullOrEmpty(searchText)) {
|
||||
specList.add(SoftwareModuleSpecification.likeNameOrVersion(searchText));
|
||||
}
|
||||
if (typeId != null) {
|
||||
throwExceptionIfSoftwareModuleTypeDoesNotExist(typeId);
|
||||
|
||||
specList.add(SoftwareModuleSpecification.equalType(typeId));
|
||||
}
|
||||
specList.add(SoftwareModuleSpecification.isDeletedFalse());
|
||||
@@ -447,6 +457,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
}
|
||||
|
||||
if (null != typeId) {
|
||||
throwExceptionIfSoftwareModuleTypeDoesNotExist(typeId);
|
||||
|
||||
spec = SoftwareModuleSpecification.equalType(typeId);
|
||||
specList.add(spec);
|
||||
}
|
||||
@@ -465,17 +477,17 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModuleType findSoftwareModuleTypeByKey(final String key) {
|
||||
public Optional<SoftwareModuleType> findSoftwareModuleTypeByKey(final String key) {
|
||||
return softwareModuleTypeRepository.findByKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModuleType findSoftwareModuleTypeById(final Long id) {
|
||||
return softwareModuleTypeRepository.findOne(id);
|
||||
public Optional<SoftwareModuleType> findSoftwareModuleTypeById(final Long smTypeId) {
|
||||
return Optional.ofNullable(softwareModuleTypeRepository.findOne(smTypeId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModuleType findSoftwareModuleTypeByName(final String name) {
|
||||
public Optional<SoftwareModuleType> findSoftwareModuleTypeByName(final String name) {
|
||||
return softwareModuleTypeRepository.findByName(name);
|
||||
}
|
||||
|
||||
@@ -492,9 +504,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteSoftwareModuleType(final Long typeId) {
|
||||
final JpaSoftwareModuleType toDelete = Optional.ofNullable(softwareModuleTypeRepository.findOne(typeId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"Software Module Type with giben ID " + typeId + " does not exist."));
|
||||
final JpaSoftwareModuleType toDelete = softwareModuleTypeRepository.findById(typeId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, typeId));
|
||||
|
||||
if (softwareModuleRepository.countByType(toDelete) > 0
|
||||
|| distributionSetTypeRepository.countByElementsSmType(toDelete) > 0) {
|
||||
@@ -507,6 +518,10 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
|
||||
@Override
|
||||
public Page<SoftwareModule> findSoftwareModuleByAssignedTo(final Pageable pageable, final Long setId) {
|
||||
if (!distributionSetRepository.exists(setId)) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, setId);
|
||||
}
|
||||
|
||||
return softwareModuleRepository.findByAssignedToId(pageable, setId);
|
||||
}
|
||||
|
||||
@@ -548,11 +563,12 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
public SoftwareModuleMetadata updateSoftwareModuleMetadata(final Long moduleId, final MetaData md) {
|
||||
|
||||
// check if exists otherwise throw entity not found exception
|
||||
final JpaSoftwareModuleMetadata metadata = findSoftwareModuleMetadata(
|
||||
new SwMetadataCompositeKey(moduleId, md.getKey()));
|
||||
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) findSoftwareModuleMetadata(moduleId,
|
||||
md.getKey()).orElseThrow(
|
||||
() -> new EntityNotFoundException(SoftwareModuleMetadata.class, moduleId, md.getKey()));
|
||||
metadata.setValue(md.getValue());
|
||||
|
||||
touch(moduleId);
|
||||
touch(metadata.getSoftwareModule());
|
||||
return softwareModuleMetadataRepository.save(metadata);
|
||||
}
|
||||
|
||||
@@ -560,40 +576,63 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
* Method to get the latest module based on ID after the metadata changes
|
||||
* for that module.
|
||||
*
|
||||
* @param distributionSet
|
||||
* Distribution set
|
||||
* @param latestModule
|
||||
* module to touch
|
||||
*/
|
||||
private JpaSoftwareModule touch(final Long moduleId) {
|
||||
final JpaSoftwareModule latestModule = softwareModuleRepository.findOne(moduleId);
|
||||
|
||||
private JpaSoftwareModule touch(final SoftwareModule latestModule) {
|
||||
// merge base distribution set so optLockRevision gets updated and audit
|
||||
// log written because
|
||||
// modifying metadata is modifying the base distribution set itself for
|
||||
// auditing purposes.
|
||||
final JpaSoftwareModule result = entityManager.merge(latestModule);
|
||||
final JpaSoftwareModule result = entityManager.merge((JpaSoftwareModule) latestModule);
|
||||
result.setLastModifiedAt(0L);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the latest module based on ID after the metadata changes
|
||||
* for that module.
|
||||
*
|
||||
* @param moduleId
|
||||
* of the module to touch
|
||||
*/
|
||||
private JpaSoftwareModule touch(final Long moduleId) {
|
||||
return touch(findSoftwareModuleById(moduleId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, moduleId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@Modifying
|
||||
public void deleteSoftwareModuleMetadata(final Long moduleId, final String key) {
|
||||
touch(moduleId);
|
||||
softwareModuleMetadataRepository.delete(new SwMetadataCompositeKey(moduleId, key));
|
||||
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) findSoftwareModuleMetadata(moduleId, key)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, moduleId, key));
|
||||
|
||||
touch(metadata.getSoftwareModule());
|
||||
softwareModuleMetadataRepository.delete(metadata.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(final Long swId,
|
||||
final Pageable pageable) {
|
||||
throwExceptionIfSoftwareModuleDoesNotExist(swId);
|
||||
|
||||
return softwareModuleMetadataRepository.findBySoftwareModuleId(swId, pageable);
|
||||
}
|
||||
|
||||
private void throwExceptionIfSoftwareModuleDoesNotExist(final Long swId) {
|
||||
if (!softwareModuleRepository.exists(swId)) {
|
||||
throw new EntityNotFoundException(SoftwareModule.class, swId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(final Long softwareModuleId,
|
||||
final String rsqlParam, final Pageable pageable) {
|
||||
|
||||
throwExceptionIfSoftwareModuleDoesNotExist(softwareModuleId);
|
||||
|
||||
final Specification<JpaSoftwareModuleMetadata> spec = RSQLUtility.parse(rsqlParam,
|
||||
SoftwareModuleMetadataFields.class, virtualPropertyReplacer);
|
||||
return convertSmMdPage(
|
||||
@@ -609,6 +648,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
|
||||
@Override
|
||||
public List<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(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),
|
||||
@@ -616,16 +657,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModuleMetadata findSoftwareModuleMetadata(final Long moduleId, final String key) {
|
||||
return findSoftwareModuleMetadata(new SwMetadataCompositeKey(moduleId, key));
|
||||
}
|
||||
|
||||
private JpaSoftwareModuleMetadata findSoftwareModuleMetadata(final SwMetadataCompositeKey id) {
|
||||
final JpaSoftwareModuleMetadata findOne = softwareModuleMetadataRepository.findOne(id);
|
||||
if (findOne == null) {
|
||||
throw new EntityNotFoundException("Metadata with key '" + id.getKey() + "' does not exist");
|
||||
}
|
||||
return findOne;
|
||||
public Optional<SoftwareModuleMetadata> findSoftwareModuleMetadata(final Long moduleId, final String key) {
|
||||
return Optional.ofNullable(softwareModuleMetadataRepository.findOne(new SwMetadataCompositeKey(moduleId, key)));
|
||||
}
|
||||
|
||||
private void checkAndThrowAlreadyExistsIfSoftwareModuleMetadataExists(final SwMetadataCompositeKey metadataId) {
|
||||
|
||||
@@ -62,7 +62,7 @@ public class JpaTagManagement implements TagManagement {
|
||||
private VirtualPropertyReplacer virtualPropertyReplacer;
|
||||
|
||||
@Override
|
||||
public TargetTag findTargetTag(final String name) {
|
||||
public Optional<TargetTag> findTargetTag(final String name) {
|
||||
return targetTagRepository.findByNameEquals(name);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class JpaTagManagement implements TagManagement {
|
||||
|
||||
final JpaTargetTag targetTag = create.buildTargetTag();
|
||||
|
||||
if (findTargetTag(targetTag.getName()) != null) {
|
||||
if (findTargetTag(targetTag.getName()).isPresent()) {
|
||||
throw new EntityAlreadyExistsException();
|
||||
}
|
||||
|
||||
@@ -95,7 +95,8 @@ public class JpaTagManagement implements TagManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteTargetTag(final String targetTagName) {
|
||||
final JpaTargetTag tag = targetTagRepository.findByNameEquals(targetTagName);
|
||||
final TargetTag tag = targetTagRepository.findByNameEquals(targetTagName)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagName));
|
||||
|
||||
targetRepository.findByTag(tag.getId()).forEach(set -> {
|
||||
set.removeTag(tag);
|
||||
@@ -107,11 +108,6 @@ public class JpaTagManagement implements TagManagement {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TargetTag> findAllTargetTags() {
|
||||
return Collections.unmodifiableList(targetTagRepository.findAll());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TargetTag> findAllTargetTags(final String rsqlParam, final Pageable pageable) {
|
||||
|
||||
@@ -139,8 +135,8 @@ public class JpaTagManagement implements TagManagement {
|
||||
public TargetTag updateTargetTag(final TagUpdate u) {
|
||||
final GenericTagUpdate update = (GenericTagUpdate) u;
|
||||
|
||||
final JpaTargetTag tag = Optional.ofNullable(targetTagRepository.findOne(update.getId()))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Target tag with ID " + update.getId() + " not found"));
|
||||
final JpaTargetTag tag = targetTagRepository.findById(update.getId())
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, update.getId()));
|
||||
|
||||
update.getName().ifPresent(tag::setName);
|
||||
update.getDescription().ifPresent(tag::setDescription);
|
||||
@@ -155,9 +151,8 @@ public class JpaTagManagement implements TagManagement {
|
||||
public DistributionSetTag updateDistributionSetTag(final TagUpdate u) {
|
||||
final GenericTagUpdate update = (GenericTagUpdate) u;
|
||||
|
||||
final JpaDistributionSetTag tag = Optional.ofNullable(distributionSetTagRepository.findOne(update.getId()))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"Distribution set tag with ID " + update.getId() + " not found"));
|
||||
final JpaDistributionSetTag tag = distributionSetTagRepository.findById(update.getId())
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, update.getId()));
|
||||
|
||||
update.getName().ifPresent(tag::setName);
|
||||
update.getDescription().ifPresent(tag::setDescription);
|
||||
@@ -167,7 +162,7 @@ public class JpaTagManagement implements TagManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSetTag findDistributionSetTag(final String name) {
|
||||
public Optional<DistributionSetTag> findDistributionSetTag(final String name) {
|
||||
return distributionSetTagRepository.findByNameEquals(name);
|
||||
}
|
||||
|
||||
@@ -179,7 +174,7 @@ public class JpaTagManagement implements TagManagement {
|
||||
|
||||
final JpaDistributionSetTag distributionSetTag = create.buildDistributionSetTag();
|
||||
|
||||
if (distributionSetTagRepository.findByNameEquals(distributionSetTag.getName()) != null) {
|
||||
if (distributionSetTagRepository.findByNameEquals(distributionSetTag.getName()).isPresent()) {
|
||||
throw new EntityAlreadyExistsException();
|
||||
}
|
||||
|
||||
@@ -203,7 +198,8 @@ public class JpaTagManagement implements TagManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteDistributionSetTag(final String tagName) {
|
||||
final JpaDistributionSetTag tag = distributionSetTagRepository.findByNameEquals(tagName);
|
||||
final DistributionSetTag tag = distributionSetTagRepository.findByNameEquals(tagName)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName));
|
||||
|
||||
distributionSetRepository.findByTag(tag).forEach(set -> {
|
||||
set.removeTag(tag);
|
||||
@@ -219,13 +215,13 @@ public class JpaTagManagement implements TagManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetTag findTargetTagById(final Long id) {
|
||||
return targetTagRepository.findOne(id);
|
||||
public Optional<TargetTag> findTargetTagById(final Long id) {
|
||||
return Optional.ofNullable(targetTagRepository.findOne(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSetTag findDistributionSetTagById(final Long id) {
|
||||
return distributionSetTagRepository.findOne(id);
|
||||
public Optional<DistributionSetTag> findDistributionSetTagById(final Long id) {
|
||||
return Optional.ofNullable(distributionSetTagRepository.findOne(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -76,7 +76,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
|
||||
final JpaTargetFilterQuery query = create.build();
|
||||
|
||||
if (targetFilterQueryRepository.findByName(query.getName()) != null) {
|
||||
if (targetFilterQueryRepository.findByName(query.getName()).isPresent()) {
|
||||
throw new EntityAlreadyExistsException(query.getName());
|
||||
}
|
||||
return targetFilterQueryRepository.save(query);
|
||||
@@ -86,6 +86,9 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteTargetFilterQuery(final Long targetFilterQueryId) {
|
||||
findTargetFilterQueryById(targetFilterQueryId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId));
|
||||
|
||||
targetFilterQueryRepository.delete(targetFilterQueryId);
|
||||
}
|
||||
|
||||
@@ -165,13 +168,13 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetFilterQuery findTargetFilterQueryByName(final String targetFilterQueryName) {
|
||||
public Optional<TargetFilterQuery> findTargetFilterQueryByName(final String targetFilterQueryName) {
|
||||
return targetFilterQueryRepository.findByName(targetFilterQueryName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetFilterQuery findTargetFilterQueryById(final Long targetFilterQueryId) {
|
||||
return targetFilterQueryRepository.findOne(targetFilterQueryId);
|
||||
public Optional<TargetFilterQuery> findTargetFilterQueryById(final Long targetFilterQueryId) {
|
||||
return Optional.ofNullable(targetFilterQueryRepository.findOne(targetFilterQueryId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -201,18 +204,13 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
}
|
||||
|
||||
private JpaDistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) {
|
||||
final JpaDistributionSet set = (JpaDistributionSet) distributionSetManagement
|
||||
.findDistributionSetByIdWithDetails(setId);
|
||||
|
||||
if (set == null) {
|
||||
throw new EntityNotFoundException("Distribution set cannot be updated as it does not exixt" + setId);
|
||||
}
|
||||
return set;
|
||||
return (JpaDistributionSet) distributionSetManagement.findDistributionSetByIdWithDetails(setId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId));
|
||||
}
|
||||
|
||||
private JpaTargetFilterQuery findTargetFilterQueryOrThrowExceptionIfNotFound(final Long queryId) {
|
||||
return Optional.ofNullable(targetFilterQueryRepository.findOne(queryId)).orElseThrow(
|
||||
() -> new EntityNotFoundException("TargetFilterQuery with given ID " + queryId + " not found!"));
|
||||
return targetFilterQueryRepository.findById(queryId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, queryId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -48,6 +48,8 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
@@ -85,6 +87,12 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Autowired
|
||||
private TargetRepository targetRepository;
|
||||
|
||||
@Autowired
|
||||
private RolloutGroupRepository rolloutGroupRepository;
|
||||
|
||||
@Autowired
|
||||
private DistributionSetRepository distributionSetRepository;
|
||||
|
||||
@Autowired
|
||||
private TargetFilterQueryRepository targetFilterQueryRepository;
|
||||
|
||||
@@ -110,25 +118,29 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
private VirtualPropertyReplacer virtualPropertyReplacer;
|
||||
|
||||
@Override
|
||||
public Target findTargetByControllerID(final String controllerId) {
|
||||
public Optional<Target> findTargetByControllerID(final String controllerId) {
|
||||
return targetRepository.findByControllerId(controllerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Target findTargetByControllerIDWithDetails(final String controllerId) {
|
||||
final Target result = targetRepository.findByControllerId(controllerId);
|
||||
public Optional<Target> findTargetByControllerIDWithDetails(final String controllerId) {
|
||||
final Optional<Target> result = targetRepository.findByControllerId(controllerId);
|
||||
// load lazy relations
|
||||
if (result != null) {
|
||||
result.getTargetInfo().getControllerAttributes().size();
|
||||
if (result.getTargetInfo() != null && result.getTargetInfo().getInstalledDistributionSet() != null) {
|
||||
result.getTargetInfo().getInstalledDistributionSet().getName();
|
||||
result.getTargetInfo().getInstalledDistributionSet().getModules().size();
|
||||
}
|
||||
if (result.getAssignedDistributionSet() != null) {
|
||||
result.getAssignedDistributionSet().getName();
|
||||
result.getAssignedDistributionSet().getModules().size();
|
||||
}
|
||||
if (!result.isPresent()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result.get().getTargetInfo().getControllerAttributes().size();
|
||||
if (result.get().getTargetInfo() != null
|
||||
&& result.get().getTargetInfo().getInstalledDistributionSet() != null) {
|
||||
result.get().getTargetInfo().getInstalledDistributionSet().getName();
|
||||
result.get().getTargetInfo().getInstalledDistributionSet().getModules().size();
|
||||
}
|
||||
if (result.get().getAssignedDistributionSet() != null) {
|
||||
result.get().getAssignedDistributionSet().getName();
|
||||
result.get().getAssignedDistributionSet().getModules().size();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -159,10 +171,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public Slice<Target> findTargetsByTargetFilterQuery(final Long targetFilterQueryId, final Pageable pageable) {
|
||||
final TargetFilterQuery targetFilterQuery = Optional
|
||||
.ofNullable(targetFilterQueryRepository.findOne(targetFilterQueryId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"TargetFilterQuery with given ID" + targetFilterQueryId + " not found"));
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryRepository.findById(targetFilterQueryId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId));
|
||||
|
||||
return findTargetsBySpec(
|
||||
RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class, virtualPropertyReplacer), pageable);
|
||||
@@ -192,9 +202,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
public Target updateTarget(final TargetUpdate u) {
|
||||
final JpaTargetUpdate update = (JpaTargetUpdate) u;
|
||||
|
||||
final JpaTarget target = Optional.ofNullable(targetRepository.findByControllerId(update.getControllerId()))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"Target with ID " + update.getControllerId() + " not found."));
|
||||
final JpaTarget target = (JpaTarget) targetRepository.findByControllerId(update.getControllerId())
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, update.getControllerId()));
|
||||
|
||||
target.setNew(false);
|
||||
|
||||
@@ -210,6 +219,13 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteTargets(final Collection<Long> targetIDs) {
|
||||
final List<JpaTarget> targets = targetRepository.findAll(targetIDs);
|
||||
|
||||
if (targets.size() < targetIDs.size()) {
|
||||
throw new EntityNotFoundException(Target.class, targetIDs,
|
||||
targets.stream().map(Target::getId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
targetRepository.deleteByIdIn(targetIDs);
|
||||
|
||||
targetIDs.forEach(targetId -> eventPublisher.publishEvent(new TargetDeletedEvent(tenantAware.getCurrentTenant(),
|
||||
@@ -220,22 +236,23 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteTarget(final String controllerID) {
|
||||
final Long targetId = Optional.ofNullable(targetRepository.findByControllerId(controllerID))
|
||||
.orElseThrow(
|
||||
() -> new EntityNotFoundException("Target with given ID " + controllerID + " does not exist."))
|
||||
.getId();
|
||||
final Target target = targetRepository.findByControllerId(controllerID)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerID));
|
||||
|
||||
targetRepository.delete(targetId);
|
||||
targetRepository.delete(target.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Target> findTargetByAssignedDistributionSet(final Long distributionSetID, final Pageable pageReq) {
|
||||
throwEntityNotFoundIfDsDoesNotExist(distributionSetID);
|
||||
|
||||
return targetRepository.findByAssignedDistributionSetId(pageReq, distributionSetID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Target> findTargetByAssignedDistributionSet(final Long distributionSetID, final String rsqlParam,
|
||||
final Pageable pageReq) {
|
||||
throwEntityNotFoundIfDsDoesNotExist(distributionSetID);
|
||||
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(rsqlParam, TargetFields.class, virtualPropertyReplacer);
|
||||
|
||||
@@ -248,6 +265,12 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
pageReq);
|
||||
}
|
||||
|
||||
private void throwEntityNotFoundIfDsDoesNotExist(final Long distributionSetID) {
|
||||
if (!distributionSetRepository.exists(distributionSetID)) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, distributionSetID);
|
||||
}
|
||||
}
|
||||
|
||||
private static Page<Target> convertPage(final Page<JpaTarget> findAll, final Pageable pageable) {
|
||||
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
|
||||
}
|
||||
@@ -258,12 +281,14 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public Page<Target> findTargetByInstalledDistributionSet(final Long distributionSetID, final Pageable pageReq) {
|
||||
throwEntityNotFoundIfDsDoesNotExist(distributionSetID);
|
||||
return targetRepository.findByTargetInfoInstalledDistributionSetId(pageReq, distributionSetID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Target> findTargetByInstalledDistributionSet(final Long distributionSetId, final String rsqlParam,
|
||||
final Pageable pageable) {
|
||||
throwEntityNotFoundIfDsDoesNotExist(distributionSetId);
|
||||
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(rsqlParam, TargetFields.class, virtualPropertyReplacer);
|
||||
|
||||
@@ -303,7 +328,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return countByCriteriaAPI(specList);
|
||||
}
|
||||
|
||||
private static List<Specification<JpaTarget>> buildSpecificationList(final FilterParams filterParams,
|
||||
private List<Specification<JpaTarget>> buildSpecificationList(final FilterParams filterParams,
|
||||
final boolean fetch) {
|
||||
final List<Specification<JpaTarget>> specList = new ArrayList<>();
|
||||
if (filterParams.getFilterByStatus() != null && !filterParams.getFilterByStatus().isEmpty()) {
|
||||
@@ -313,6 +338,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
specList.add(TargetSpecifications.isOverdue(TimestampCalculator.calculateOverdueTimestamp()));
|
||||
}
|
||||
if (filterParams.getFilterByDistributionId() != null) {
|
||||
throwEntityNotFoundIfDsDoesNotExist(filterParams.getFilterByDistributionId());
|
||||
|
||||
specList.add(TargetSpecifications
|
||||
.hasInstalledOrAssignedDistributionSet(filterParams.getFilterByDistributionId()));
|
||||
}
|
||||
@@ -352,7 +379,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public TargetTagAssignmentResult toggleTagAssignment(final Collection<String> targetIds, final String tagName) {
|
||||
final TargetTag tag = targetTagRepository.findByNameEquals(tagName);
|
||||
final TargetTag tag = targetTagRepository.findByNameEquals(tagName)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, tagName));
|
||||
final List<JpaTarget> alreadyAssignedTargets = targetRepository.findByTagNameAndControllerIdIn(tagName,
|
||||
targetIds);
|
||||
final List<JpaTarget> allTargets = targetRepository
|
||||
@@ -388,8 +416,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final List<JpaTarget> allTargets = targetRepository
|
||||
.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(controllerIds));
|
||||
|
||||
final JpaTargetTag tag = Optional.ofNullable(targetTagRepository.findOne(tagId))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Tag with given ID " + tagId + "does not exist"));
|
||||
final JpaTargetTag tag = targetTagRepository.findById(tagId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, tagId));
|
||||
|
||||
allTargets.forEach(target -> target.addTag(tag));
|
||||
return Collections
|
||||
@@ -411,8 +439,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public List<Target> unAssignAllTargetsByTag(final Long targetTagId) {
|
||||
|
||||
final TargetTag tag = Optional.ofNullable(targetTagRepository.findOne(targetTagId)).orElseThrow(
|
||||
() -> new EntityNotFoundException("TargetTag with given ID " + targetTagId + " does not exist."));
|
||||
final TargetTag tag = targetTagRepository.findById(targetTagId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));
|
||||
|
||||
if (tag.getAssignedToTargets().isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
@@ -428,8 +456,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final List<Target> allTargets = Collections.unmodifiableList(targetRepository
|
||||
.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(Arrays.asList(controllerID))));
|
||||
|
||||
final TargetTag tag = Optional.ofNullable(targetTagRepository.findOne(targetTagId)).orElseThrow(
|
||||
() -> new EntityNotFoundException("TargetTag with given ID " + targetTagId + " does not exist."));
|
||||
final TargetTag tag = targetTagRepository.findById(targetTagId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));
|
||||
|
||||
final List<Target> unAssignTag = unAssignTag(allTargets, tag);
|
||||
return unAssignTag.isEmpty() ? null : unAssignTag.get(0);
|
||||
@@ -438,7 +466,6 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public Slice<Target> findTargetsAllOrderByLinkedDistributionSet(final Pageable pageable,
|
||||
final Long orderByDistributionId, final FilterParams filterParams) {
|
||||
|
||||
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
|
||||
final CriteriaQuery<JpaTarget> query = cb.createQuery(JpaTarget.class);
|
||||
final Root<JpaTarget> targetRoot = query.from(JpaTarget.class);
|
||||
@@ -496,17 +523,22 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public Long countTargetByAssignedDistributionSet(final Long distId) {
|
||||
throwEntityNotFoundIfDsDoesNotExist(distId);
|
||||
|
||||
return targetRepository.countByAssignedDistributionSetId(distId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countTargetByInstalledDistributionSet(final Long distId) {
|
||||
throwEntityNotFoundIfDsDoesNotExist(distId);
|
||||
|
||||
return targetRepository.countByTargetInfoInstalledDistributionSetId(distId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Target> findAllTargetsByTargetFilterQueryAndNonDS(@NotNull final Pageable pageRequest,
|
||||
final Long distributionSetId, @NotNull final String targetFilterQuery) {
|
||||
public Page<Target> findAllTargetsByTargetFilterQueryAndNonDS(final Pageable pageRequest,
|
||||
final Long distributionSetId, final String targetFilterQuery) {
|
||||
throwEntityNotFoundIfDsDoesNotExist(distributionSetId);
|
||||
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
|
||||
virtualPropertyReplacer);
|
||||
@@ -534,6 +566,10 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public Page<Target> findAllTargetsInRolloutGroupWithoutAction(@NotNull final Pageable pageRequest,
|
||||
@NotNull final Long group) {
|
||||
if (!rolloutGroupRepository.exists(group)) {
|
||||
throw new EntityNotFoundException(RolloutGroup.class, group);
|
||||
}
|
||||
|
||||
return findTargetsBySpec(
|
||||
(root, cq, cb) -> TargetSpecifications.hasNoActionInRolloutGroup(group).toPredicate(root, cq, cb),
|
||||
pageRequest);
|
||||
@@ -552,6 +588,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public Long countTargetsByTargetFilterQueryAndNonDS(final Long distributionSetId, final String targetFilterQuery) {
|
||||
throwEntityNotFoundIfDsDoesNotExist(distributionSetId);
|
||||
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
|
||||
virtualPropertyReplacer);
|
||||
final List<Specification<JpaTarget>> specList = new ArrayList<>(2);
|
||||
@@ -569,7 +607,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
final JpaTarget target = create.build();
|
||||
|
||||
if (targetRepository.findByControllerId(target.getControllerId()) != null) {
|
||||
if (targetRepository.findByControllerId(target.getControllerId()).isPresent()) {
|
||||
throw new EntityAlreadyExistsException();
|
||||
}
|
||||
|
||||
@@ -592,16 +630,18 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public List<Target> findTargetsByTag(final String tagName) {
|
||||
final JpaTargetTag tag = targetTagRepository.findByNameEquals(tagName);
|
||||
return Collections.unmodifiableList(targetRepository.findByTag(tag.getId()));
|
||||
final Optional<TargetTag> tag = targetTagRepository.findByNameEquals(tagName);
|
||||
if (!tag.isPresent()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(targetRepository.findByTag(tag.get().getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countTargetByTargetFilterQuery(final Long targetFilterQueryId) {
|
||||
final TargetFilterQuery targetFilterQuery = Optional
|
||||
.ofNullable(targetFilterQueryRepository.findOne(targetFilterQueryId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(
|
||||
"TargetFilterQuery with given ID" + targetFilterQueryId + " not found"));
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryRepository.findById(targetFilterQueryId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId));
|
||||
|
||||
final Specification<JpaTarget> specs = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class,
|
||||
virtualPropertyReplacer);
|
||||
@@ -619,8 +659,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Target findTargetById(final Long id) {
|
||||
return targetRepository.findOne(id);
|
||||
public Optional<Target> findTargetById(final Long id) {
|
||||
return Optional.ofNullable(targetRepository.findOne(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -61,7 +61,7 @@ public interface LocalArtifactRepository extends BaseEntityRepository<JpaArtifac
|
||||
* to search
|
||||
* @return {@link Artifact} the first in the result list
|
||||
*/
|
||||
JpaArtifact findFirstBySha1Hash(String sha1Hash);
|
||||
Optional<Artifact> findFirstBySha1Hash(String sha1Hash);
|
||||
|
||||
/**
|
||||
* Searches for a {@link Artifact} based user provided filename at upload.
|
||||
@@ -70,7 +70,7 @@ public interface LocalArtifactRepository extends BaseEntityRepository<JpaArtifac
|
||||
* to search
|
||||
* @return list of {@link Artifact}.
|
||||
*/
|
||||
List<Artifact> findByFilename(String filename);
|
||||
Optional<Artifact> findFirstByFilename(String filename);
|
||||
|
||||
/**
|
||||
* Searches for local artifact for a base software module.
|
||||
@@ -94,6 +94,6 @@ public interface LocalArtifactRepository extends BaseEntityRepository<JpaArtifac
|
||||
* selected software module id
|
||||
* @return list of {@link Artifact}.
|
||||
*/
|
||||
List<Artifact> findByFilenameAndSoftwareModuleId(final String filename, final Long softwareModuleId);
|
||||
Optional<Artifact> findFirstByFilenameAndSoftwareModuleId(final String filename, final Long softwareModuleId);
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
@@ -67,5 +68,5 @@ public interface RolloutRepository
|
||||
* the rollout name
|
||||
* @return {@link Rollout} for specific name
|
||||
*/
|
||||
JpaRollout findByName(String name);
|
||||
Optional<Rollout> findByName(String name);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
@@ -55,7 +56,7 @@ public interface SoftwareModuleRepository
|
||||
* @return the found {@link SoftwareModule} with the given name AND version
|
||||
* AND type
|
||||
*/
|
||||
JpaSoftwareModule findOneByNameAndVersionAndTypeId(String name, String version, Long typeId);
|
||||
Optional<SoftwareModule> findOneByNameAndVersionAndTypeId(String name, String version, Long typeId);
|
||||
|
||||
/**
|
||||
* deletes the {@link SoftwareModule}s with the given IDs.
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -52,7 +53,7 @@ public interface SoftwareModuleTypeRepository
|
||||
* @return all {@link SoftwareModuleType}s in the repository with given
|
||||
* {@link SoftwareModuleType#getKey()}
|
||||
*/
|
||||
JpaSoftwareModuleType findByKey(String key);
|
||||
Optional<SoftwareModuleType> findByKey(String key);
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -61,7 +62,7 @@ public interface SoftwareModuleTypeRepository
|
||||
* @return all {@link SoftwareModuleType}s in the repository with given
|
||||
* {@link SoftwareModuleType#getName()}
|
||||
*/
|
||||
JpaSoftwareModuleType findByName(String name);
|
||||
Optional<SoftwareModuleType> findByName(String name);
|
||||
|
||||
/**
|
||||
* retrieves all software module types with a given
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -32,7 +34,7 @@ public interface TargetFilterQueryRepository
|
||||
* @param name
|
||||
* @return custom target filter
|
||||
*/
|
||||
TargetFilterQuery findByName(final String name);
|
||||
Optional<TargetFilterQuery> findByName(final String name);
|
||||
|
||||
/**
|
||||
* Find list of all custom target filters.
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
@@ -44,7 +45,7 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
|
||||
* @return found {@link Target} or <code>null</code> if not found.
|
||||
*/
|
||||
@EntityGraph(value = "Target.detail", type = EntityGraphType.LOAD)
|
||||
JpaTarget findByControllerId(String controllerID);
|
||||
Optional<Target> findByControllerId(String controllerID);
|
||||
|
||||
/**
|
||||
* Deletes the {@link Target}s with the given target IDs.
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
@@ -43,7 +44,7 @@ public interface TargetTagRepository
|
||||
* to filter on
|
||||
* @return the {@link TargetTag} if found, otherwise null
|
||||
*/
|
||||
JpaTargetTag findByNameEquals(String tagName);
|
||||
Optional<TargetTag> findByNameEquals(String tagName);
|
||||
|
||||
/**
|
||||
* Returns all instances of the type.
|
||||
|
||||
@@ -47,14 +47,8 @@ public class JpaDistributionSetCreate extends AbstractDistributionSetUpdateCreat
|
||||
}
|
||||
|
||||
private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final String distributionSetTypekey) {
|
||||
|
||||
final DistributionSetType module = distributionSetManagement
|
||||
.findDistributionSetTypeByKey(distributionSetTypekey);
|
||||
if (module == null) {
|
||||
throw new EntityNotFoundException(
|
||||
"DistributionSetType with key {" + distributionSetTypekey + "} does not exist");
|
||||
}
|
||||
return module;
|
||||
return distributionSetManagement.findDistributionSetTypeByKey(distributionSetTypekey)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distributionSetTypekey));
|
||||
}
|
||||
|
||||
private Collection<SoftwareModule> findSoftwareModuleWithExceptionIfNotFound(
|
||||
@@ -65,8 +59,7 @@ public class JpaDistributionSetCreate extends AbstractDistributionSetUpdateCreat
|
||||
|
||||
final Collection<SoftwareModule> module = softwareManagement.findSoftwareModulesById(softwareModuleId);
|
||||
if (module.size() < softwareModuleId.size()) {
|
||||
throw new EntityNotFoundException(
|
||||
"Some SoftwareModules out of the range {" + softwareModuleId + "} due not exist");
|
||||
throw new EntityNotFoundException(SoftwareModule.class, softwareModuleId);
|
||||
}
|
||||
|
||||
return module;
|
||||
|
||||
@@ -51,8 +51,7 @@ public class JpaDistributionSetTypeCreate extends AbstractDistributionSetTypeUpd
|
||||
final Collection<SoftwareModuleType> module = softwareManagement
|
||||
.findSoftwareModuleTypesById(softwareModuleTypeId);
|
||||
if (module.size() < softwareModuleTypeId.size()) {
|
||||
throw new EntityNotFoundException(
|
||||
"SoftwareModules types out of the range {" + softwareModuleTypeId + "} due not exist");
|
||||
throw new EntityNotFoundException(SoftwareModuleType.class, softwareModuleTypeId);
|
||||
}
|
||||
|
||||
return module;
|
||||
|
||||
@@ -44,11 +44,7 @@ public class JpaRolloutCreate extends AbstractRolloutUpdateCreate<RolloutCreate>
|
||||
}
|
||||
|
||||
private DistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) {
|
||||
final DistributionSet set = distributionSetManagement.findDistributionSetById(setId);
|
||||
|
||||
if (set == null) {
|
||||
throw new EntityNotFoundException("Distribution set cannot be set as it does not exixt" + setId);
|
||||
}
|
||||
return set;
|
||||
return distributionSetManagement.findDistributionSetById(setId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,12 +39,7 @@ public class JpaSoftwareModuleCreate extends AbstractSoftwareModuleUpdateCreate<
|
||||
throw new ConstraintViolationException("type cannot be null");
|
||||
}
|
||||
|
||||
final SoftwareModuleType smType = softwareManagement.findSoftwareModuleTypeByKey(type.trim());
|
||||
|
||||
if (smType == null) {
|
||||
throw new EntityNotFoundException(type.trim());
|
||||
}
|
||||
|
||||
return smType;
|
||||
return softwareManagement.findSoftwareModuleTypeByKey(type.trim())
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, type.trim()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,12 +36,8 @@ public class JpaTargetFilterQueryCreate extends AbstractTargetFilterQueryUpdateC
|
||||
}
|
||||
|
||||
private DistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) {
|
||||
final DistributionSet set = distributionSetManagement.findDistributionSetById(setId);
|
||||
|
||||
if (set == null) {
|
||||
throw new EntityNotFoundException("Distribution set cannot be set as it does not exixt" + setId);
|
||||
}
|
||||
return set;
|
||||
return distributionSetManagement.findDistributionSetById(setId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Actio
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "distribution_set", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_ds"))
|
||||
@NotNull
|
||||
private JpaDistributionSet distributionSet;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
|
||||
@@ -268,7 +268,7 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
|
||||
checkTypeCompatability(softwareModule);
|
||||
|
||||
final Optional<SoftwareModule> found = modules.stream()
|
||||
.filter(module -> module.getId().equals(softwareModule.getId())).findFirst();
|
||||
.filter(module -> module.getId().equals(softwareModule.getId())).findAny();
|
||||
|
||||
if (found.isPresent()) {
|
||||
return false;
|
||||
@@ -279,7 +279,7 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
|
||||
|
||||
if (allready >= softwareModule.getType().getMaxAssignments()) {
|
||||
modules.stream().filter(module -> module.getType().getKey().equals(softwareModule.getType().getKey()))
|
||||
.findFirst().map(modules::remove);
|
||||
.findAny().map(modules::remove);
|
||||
}
|
||||
|
||||
if (modules.add(softwareModule)) {
|
||||
@@ -308,7 +308,7 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
|
||||
}
|
||||
|
||||
final Optional<SoftwareModule> found = modules.stream()
|
||||
.filter(module -> module.getId().equals(softwareModule.getId())).findFirst();
|
||||
.filter(module -> module.getId().equals(softwareModule.getId())).findAny();
|
||||
|
||||
if (found.isPresent()) {
|
||||
modules.remove(found.get());
|
||||
|
||||
@@ -170,7 +170,7 @@ public class JpaDistributionSetType extends AbstractJpaNamedEntity implements Di
|
||||
|
||||
// check if this was in the list before before
|
||||
final Optional<DistributionSetTypeElement> existing = elements.stream()
|
||||
.filter(element -> element.getSmType().getKey().equals(smType.getKey())).findFirst();
|
||||
.filter(element -> element.getSmType().getKey().equals(smType.getKey())).findAny();
|
||||
|
||||
if (existing.isPresent()) {
|
||||
existing.get().setMandatory(mandatory);
|
||||
@@ -187,7 +187,7 @@ public class JpaDistributionSetType extends AbstractJpaNamedEntity implements Di
|
||||
}
|
||||
|
||||
// we search by id (standard equals compares also revison)
|
||||
elements.stream().filter(element -> element.getSmType().getId().equals(smTypeId)).findFirst()
|
||||
elements.stream().filter(element -> element.getSmType().getId().equals(smTypeId)).findAny()
|
||||
.ifPresent(elements::remove);
|
||||
|
||||
return this;
|
||||
|
||||
@@ -235,7 +235,7 @@ public final class RSQLUtility {
|
||||
|
||||
private Optional<Join<Object, Object>> findCurrentJoinOfType(final Class<?> type) {
|
||||
return getCurrentJoins().stream()
|
||||
.filter(j -> type.equals(j.getJavaType())).findFirst();
|
||||
.filter(j -> type.equals(j.getJavaType())).findAny();
|
||||
}
|
||||
|
||||
private void addCurrentJoin(Join<Object, Object> join) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
@@ -44,6 +44,7 @@ public class ActionEventTest extends AbstractRemoteEntityEventTest<Action> {
|
||||
generateAction.setActionType(ActionType.FORCED);
|
||||
final Target target = testdataFactory.createTarget("Test");
|
||||
generateAction.setTarget(target);
|
||||
generateAction.setDistributionSet(testdataFactory.createDistributionSet());
|
||||
return actionRepository.save(generateAction);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class RolloutGroupEventTest extends AbstractRemoteEntityEventTest<Rollout
|
||||
10, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10").build());
|
||||
|
||||
return rolloutManagement.findRolloutById(entity.getId()).getRolloutGroups().get(0);
|
||||
return rolloutManagement.findRolloutById(entity.getId()).get().getRolloutGroups().get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -60,16 +60,13 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
|
||||
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
JpaSoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareModuleRepository.save(sm);
|
||||
|
||||
JpaSoftwareModule sm2 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2",
|
||||
"version 2", null, null);
|
||||
JpaSoftwareModule sm2 = new JpaSoftwareModule(osType, "name 2", "version 2", null, null);
|
||||
sm2 = softwareModuleRepository.save(sm2);
|
||||
|
||||
JpaSoftwareModule sm3 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 3",
|
||||
"version 3", null, null);
|
||||
JpaSoftwareModule sm3 = new JpaSoftwareModule(osType, "name 3", "version 3", null, null);
|
||||
sm3 = softwareModuleRepository.save(sm3);
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
@@ -91,22 +88,21 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(result).isNotEqualTo(result2);
|
||||
assertThat(((JpaArtifact) result).getSha1Hash()).isEqualTo(((JpaArtifact) result2).getSha1Hash());
|
||||
|
||||
assertThat(artifactManagement.findArtifactByFilename("file1").get(0).getSha1Hash())
|
||||
assertThat(artifactManagement.findArtifactByFilename("file1").get().getSha1Hash())
|
||||
.isEqualTo(HashGeneratorUtils.generateSHA1(random));
|
||||
assertThat(artifactManagement.findArtifactByFilename("file1").get(0).getMd5Hash())
|
||||
assertThat(artifactManagement.findArtifactByFilename("file1").get().getMd5Hash())
|
||||
.isEqualTo(HashGeneratorUtils.generateMD5(random));
|
||||
|
||||
assertThat(artifactRepository.findAll()).hasSize(4);
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize(3);
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleById(sm.getId()).getArtifacts()).hasSize(3);
|
||||
assertThat(softwareManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts()).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests hard delete directly on repository.")
|
||||
public void hardDeleteSoftwareModule() throws NoSuchAlgorithmException, IOException {
|
||||
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
JpaSoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareModuleRepository.save(sm);
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
@@ -129,12 +125,10 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Tests the deletion of a local artifact including metadata.")
|
||||
public void deleteArtifact() throws NoSuchAlgorithmException, IOException {
|
||||
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
JpaSoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareModuleRepository.save(sm);
|
||||
|
||||
JpaSoftwareModule sm2 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2",
|
||||
"version 2", null, null);
|
||||
JpaSoftwareModule sm2 = new JpaSoftwareModule(osType, "name 2", "version 2", null, null);
|
||||
sm2 = softwareModuleRepository.save(sm2);
|
||||
|
||||
assertThat(artifactRepository.findAll()).isEmpty();
|
||||
@@ -168,12 +162,10 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Test the deletion of an artifact metadata where the binary is still linked to another "
|
||||
+ "metadata element. The expected result is that the metadata is deleted but the binary kept.")
|
||||
public void deleteDuplicateArtifacts() throws NoSuchAlgorithmException, IOException {
|
||||
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
JpaSoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareModuleRepository.save(sm);
|
||||
|
||||
JpaSoftwareModule sm2 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2",
|
||||
"version 2", null, null);
|
||||
JpaSoftwareModule sm2 = new JpaSoftwareModule(osType, "name 2", "version 2", null, null);
|
||||
sm2 = softwareModuleRepository.save(sm2);
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
@@ -202,7 +194,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024),
|
||||
testdataFactory.createSoftwareModuleOs().getId(), "file1", false);
|
||||
|
||||
assertThat(artifactManagement.findArtifact(result.getId())).isEqualTo(result);
|
||||
assertThat(artifactManagement.findArtifact(result.getId()).get()).isEqualTo(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -250,12 +242,12 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
public void findByFilenameAndSoftwareModule() {
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).isEmpty();
|
||||
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId()).isPresent()).isFalse();
|
||||
|
||||
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false);
|
||||
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false);
|
||||
|
||||
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).hasSize(1);
|
||||
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId()).isPresent()).isTrue();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -241,8 +241,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Long dsId = testdataFactory.createDistributionSet().getId();
|
||||
testdataFactory.createTarget();
|
||||
assignDistributionSet(dsId, TestdataFactory.DEFAULT_CONTROLLER_ID);
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
return deploymentManagement.findActiveActionsByTarget(TestdataFactory.DEFAULT_CONTROLLER_ID).get(0).getId();
|
||||
}
|
||||
@@ -296,10 +296,10 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
private void assertActionStatus(final Long actionId, final String controllerId,
|
||||
final TargetUpdateStatus expectedTargetUpdateStatus, final Action.Status expectedActionActionStatus,
|
||||
final Action.Status expectedActionStatus, final boolean actionActive) {
|
||||
final TargetUpdateStatus targetStatus = targetManagement.findTargetByControllerID(controllerId).getTargetInfo()
|
||||
.getUpdateStatus();
|
||||
final TargetUpdateStatus targetStatus = targetManagement.findTargetByControllerID(controllerId).get()
|
||||
.getTargetInfo().getUpdateStatus();
|
||||
assertThat(targetStatus).isEqualTo(expectedTargetUpdateStatus);
|
||||
final Action action = deploymentManagement.findAction(actionId);
|
||||
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)
|
||||
@@ -326,9 +326,9 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// create two artifacts with identical SHA1 hash
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "file1", false);
|
||||
ds.findFirstModuleByType(osType).get().getId(), "file1", false);
|
||||
final Artifact artifact2 = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds2.findFirstModuleByType(osType).getId(), "file1", false);
|
||||
ds2.findFirstModuleByType(osType).get().getId(), "file1", false);
|
||||
assertThat(artifact.getSha1Hash()).isEqualTo(artifact2.getSha1Hash());
|
||||
|
||||
assertThat(
|
||||
@@ -462,8 +462,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
entityFactory.actionStatus().create(action.getId()).status(Action.Status.RUNNING));
|
||||
|
||||
// nothing changed as "feedback after close" is disabled
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
assertThat(actionStatusRepository.count()).isEqualTo(3);
|
||||
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action.getId()).getNumberOfElements())
|
||||
@@ -487,8 +487,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
entityFactory.actionStatus().create(action.getId()).status(Action.Status.RUNNING));
|
||||
|
||||
// nothing changed as "feedback after close" is disabled
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
// however, additional action status has been stored
|
||||
assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(4);
|
||||
@@ -514,7 +514,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
testData.put("test1", "testdata1");
|
||||
controllerManagament.updateControllerAttributes(controllerId, testData);
|
||||
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId);
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
|
||||
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
|
||||
.isEqualTo(testData);
|
||||
}
|
||||
@@ -525,7 +525,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
testData.put("test2", "testdata20");
|
||||
controllerManagament.updateControllerAttributes(controllerId, testData);
|
||||
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId);
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
|
||||
testData.put("test1", "testdata1");
|
||||
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
|
||||
.isEqualTo(testData);
|
||||
@@ -538,7 +538,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
controllerManagament.updateControllerAttributes(controllerId, testData);
|
||||
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId);
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
|
||||
testData.put("test2", "testdata20");
|
||||
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
|
||||
.isEqualTo(testData);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -22,9 +22,9 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ActionStatusFields;
|
||||
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException;
|
||||
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
@@ -92,7 +92,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<Target> testTarget = testdataFactory.createTargets(1);
|
||||
// one action with one action status is generated
|
||||
final Long actionId = assignDistributionSet(testDs, testTarget).getActions().get(0);
|
||||
final Action action = deploymentManagement.findActionWithDetails(actionId);
|
||||
final Action action = deploymentManagement.findActionWithDetails(actionId).get();
|
||||
|
||||
assertThat(action.getDistributionSet()).as("DistributionSet in action").isNotNull();
|
||||
assertThat(action.getTarget()).as("Target in action").isNotNull();
|
||||
@@ -109,7 +109,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<Target> testTarget = testdataFactory.createTargets(1);
|
||||
// one action with one action status is generated
|
||||
final Action action = deploymentManagement
|
||||
.findActionWithDetails(assignDistributionSet(testDs, testTarget).getActions().get(0));
|
||||
.findActionWithDetails(assignDistributionSet(testDs, testTarget).getActions().get(0)).get();
|
||||
// save 2 action status
|
||||
actionStatusRepository.save(new JpaActionStatus(action, Status.RETRIEVED, System.currentTimeMillis()));
|
||||
actionStatusRepository.save(new JpaActionStatus(action, Status.RUNNING, System.currentTimeMillis()));
|
||||
@@ -123,15 +123,34 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that distribution sets can assigned and unassigned to a distribution set tag. Not exists distribution set will be ignored for the assignment.")
|
||||
public void assignAndUnassignDistributionSetToTag() {
|
||||
final List<Long> assignDS = new ArrayList<>();
|
||||
@Description("Ensures that tag to distribution set assignment that does not exist will cause EntityNotFoundException.")
|
||||
public void assignDistributionSetToTagThatDoesNotExistThrowsException() {
|
||||
final List<Long> assignDS = Lists.newArrayListWithExpectedSize(5);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", new ArrayList<DistributionSetTag>())
|
||||
.getId());
|
||||
assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", Collections.emptyList()).getId());
|
||||
}
|
||||
// not exists
|
||||
assignDS.add(Long.valueOf(100));
|
||||
|
||||
final DistributionSetTag tag = tagManagement
|
||||
.createDistributionSetTag(entityFactory.tag().create().name("Tag1"));
|
||||
|
||||
try {
|
||||
distributionSetManagement.assignTag(assignDS, tag.getId());
|
||||
fail("It should not be possible to assign a DS that does not exist");
|
||||
} catch (final EntityNotFoundException e) {
|
||||
// Ok
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that distribution sets can assigned and unassigned to a distribution set tag.")
|
||||
public void assignAndUnassignDistributionSetToTag() {
|
||||
final List<Long> assignDS = Lists.newArrayListWithExpectedSize(4);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", Collections.emptyList()).getId());
|
||||
}
|
||||
|
||||
final DistributionSetTag tag = tagManagement
|
||||
.createDistributionSetTag(entityFactory.tag().create().name("Tag1"));
|
||||
|
||||
@@ -139,7 +158,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
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));
|
||||
|
||||
DistributionSetTag findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1");
|
||||
DistributionSetTag findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1").get();
|
||||
assertThat(assignedDS.size()).as("assigned ds has wrong size")
|
||||
.isEqualTo(findDistributionSetTag.getAssignedToDistributionSet().size());
|
||||
|
||||
@@ -147,13 +166,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
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");
|
||||
findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1").get();
|
||||
assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).as("ds tag ds has wrong ds size")
|
||||
.isEqualTo(3);
|
||||
|
||||
final List<DistributionSet> unAssignTargets = distributionSetManagement
|
||||
.unAssignAllDistributionSetsByTag(findDistributionSetTag.getId());
|
||||
findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1");
|
||||
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);
|
||||
@@ -194,7 +213,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet dsInstalled = action.getDistributionSet();
|
||||
|
||||
// check initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
.as("target has update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
// assign the two sets in a row
|
||||
@@ -206,26 +225,26 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// we cancel second -> back to first
|
||||
deploymentManagement.cancelAction(secondAction.getId());
|
||||
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId());
|
||||
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId()).get();
|
||||
// confirm cancellation
|
||||
controllerManagement.addCancelActionStatus(
|
||||
entityFactory.actionStatus().create(secondAction.getId()).status(Status.CANCELED));
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of actions status").hasSize(7);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).as("wrong ds")
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet()).as("wrong ds")
|
||||
.isEqualTo(dsFirst);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
// we cancel first -> back to installed
|
||||
deploymentManagement.cancelAction(firstAction.getId());
|
||||
firstAction = (JpaAction) deploymentManagement.findActionWithDetails(firstAction.getId());
|
||||
firstAction = (JpaAction) deploymentManagement.findActionWithDetails(firstAction.getId()).get();
|
||||
// confirm cancellation
|
||||
controllerManagement.addCancelActionStatus(
|
||||
entityFactory.actionStatus().create(firstAction.getId()).status(Status.CANCELED));
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(9);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(dsInstalled);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
@@ -241,7 +260,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet dsInstalled = action.getDistributionSet();
|
||||
|
||||
// check initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
// assign the two sets in a row
|
||||
@@ -254,28 +273,28 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// we cancel first -> second is left
|
||||
deploymentManagement.cancelAction(firstAction.getId());
|
||||
// confirm cancellation
|
||||
firstAction = (JpaAction) deploymentManagement.findActionWithDetails(firstAction.getId());
|
||||
firstAction = (JpaAction) deploymentManagement.findActionWithDetails(firstAction.getId()).get();
|
||||
controllerManagement.addCancelActionStatus(
|
||||
entityFactory.actionStatus().create(firstAction.getId()).status(Status.CANCELED));
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(7);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(dsSecond);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
.as("wrong target update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
// we cancel second -> remain assigned until finished cancellation
|
||||
deploymentManagement.cancelAction(secondAction.getId());
|
||||
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId());
|
||||
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId()).get();
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(8);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(dsSecond);
|
||||
// confirm cancellation
|
||||
controllerManagement.addCancelActionStatus(
|
||||
entityFactory.actionStatus().create(secondAction.getId()).status(Status.CANCELED));
|
||||
// cancelled success -> back to dsInstalled
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
|
||||
.as("wrong installed ds").isEqualTo(dsInstalled);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
@@ -289,7 +308,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
|
||||
|
||||
// verify initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
Action assigningAction = assignSet(target, ds);
|
||||
@@ -298,21 +317,21 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(actionRepository.findAll()).as("wrong size of action").hasSize(2);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(4);
|
||||
|
||||
target = targetManagement.findTargetByControllerID(target.getControllerId());
|
||||
target = targetManagement.findTargetByControllerID(target.getControllerId()).get();
|
||||
|
||||
// force quit assignment
|
||||
deploymentManagement.cancelAction(assigningAction.getId());
|
||||
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId());
|
||||
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId()).get();
|
||||
|
||||
deploymentManagement.forceQuitAction(assigningAction.getId());
|
||||
|
||||
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId());
|
||||
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId()).get();
|
||||
|
||||
// verify
|
||||
assertThat(assigningAction.getStatus()).as("wrong size of status").isEqualTo(Status.CANCELED);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(dsInstalled);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
.as("wrong target update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
@@ -325,7 +344,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
|
||||
|
||||
// verify initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
final Action assigningAction = assignSet(target, ds);
|
||||
@@ -344,11 +363,11 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private JpaAction assignSet(final Target target, final DistributionSet ds) {
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTargetInfo()
|
||||
.getUpdateStatus()).as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()).getTargetInfo().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(ds);
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()).get().getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(ds);
|
||||
final JpaAction action = actionRepository
|
||||
.findByTargetAndDistributionSet(pageReq, (JpaTarget) target, (JpaDistributionSet) ds).getContent()
|
||||
.get(0);
|
||||
@@ -396,13 +415,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.doesNotContain(Iterables.toArray(savedDeployedTargets, Target.class));
|
||||
|
||||
for (final Target myt : savedNakedTargets) {
|
||||
final Target t = targetManagement.findTargetByControllerID(myt.getControllerId());
|
||||
final Target t = targetManagement.findTargetByControllerID(myt.getControllerId()).get();
|
||||
assertThat(deploymentManagement.countActionsByTarget(t.getControllerId())).as("action should be empty")
|
||||
.isEqualTo(0L);
|
||||
}
|
||||
|
||||
for (final Target myt : savedDeployedTargets) {
|
||||
final Target t = targetManagement.findTargetByControllerID(myt.getControllerId());
|
||||
final Target t = targetManagement.findTargetByControllerID(myt.getControllerId()).get();
|
||||
final List<Action> activeActionsByTarget = deploymentManagement
|
||||
.findActiveActionsByTarget(t.getControllerId());
|
||||
assertThat(activeActionsByTarget).as("action should not be empty").isNotEmpty();
|
||||
@@ -546,20 +565,20 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// verifying the correctness of the assignments
|
||||
for (final Target t : deployResWithDsA.getDeployedTargets()) {
|
||||
assertThat(t.getAssignedDistributionSet().getId()).as("assignment is not correct").isEqualTo(dsA.getId());
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
|
||||
}
|
||||
for (final Target t : deployResWithDsB.getDeployedTargets()) {
|
||||
assertThat(t.getAssignedDistributionSet().getId()).as("assigned ds is wrong").isEqualTo(dsB.getId());
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
|
||||
}
|
||||
for (final Target t : deployResWithDsC.getDeployedTargets()) {
|
||||
assertThat(t.getAssignedDistributionSet().getId()).isEqualTo(dsC.getId());
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getInstalledDistributionSet()).as("installed ds should not be null").isNull();
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getUpdateStatus()).as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
}
|
||||
|
||||
final List<Target> updatedTsDsA = testdataFactory
|
||||
@@ -570,12 +589,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// verify, that dsA is deployed correctly
|
||||
assertThat(updatedTsDsA).as("ds is not deployed correctly").isEqualTo(deployResWithDsA.getDeployedTargets());
|
||||
for (final Target t_ : updatedTsDsA) {
|
||||
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId());
|
||||
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId()).get();
|
||||
assertThat(t.getAssignedDistributionSet()).as("assigned ds is wrong").isEqualTo(dsA);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getInstalledDistributionSet()).as("installed ds is wrong").isEqualTo(dsA);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getUpdateStatus()).as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(t.getControllerId()))
|
||||
.as("no actions should be active").hasSize(0);
|
||||
}
|
||||
@@ -596,12 +615,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").hasSameSizeAs(deployResWithDsBTargets);
|
||||
|
||||
for (final Target t_ : deployed2DS) {
|
||||
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId());
|
||||
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId()).get();
|
||||
assertThat(t.getAssignedDistributionSet()).as("assigned ds is wrong").isEqualTo(dsA);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getUpdateStatus()).as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -630,16 +649,16 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DeploymentResult deploymentResult = prepareComplexRepo(undeployedTargetPrefix, noOfUndeployedTargets,
|
||||
deployedTargetPrefix, noOfDeployedTargets, noOfDistributionSets, "myTestDS");
|
||||
|
||||
DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
distributionSetManagement.deleteDistributionSet(dsA.getId());
|
||||
dsA = distributionSetManagement.findDistributionSetById(dsA.getId());
|
||||
assertThat(dsA).as("ds should be null").isNull();
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetById(dsA.getId()).isPresent()).isFalse();
|
||||
|
||||
// // verify that the ds is not physically deleted
|
||||
for (final DistributionSet ds : deploymentResult.getDistributionSets()) {
|
||||
distributionSetManagement.deleteDistributionSet(ds.getId());
|
||||
final DistributionSet foundDS = distributionSetManagement.findDistributionSetById(ds.getId());
|
||||
final DistributionSet foundDS = distributionSetManagement.findDistributionSetById(ds.getId()).get();
|
||||
assertThat(foundDS).as("founded should not be null").isNotNull();
|
||||
assertThat(foundDS.isDeleted()).as("found ds should be deleted").isTrue();
|
||||
}
|
||||
@@ -711,13 +730,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// doing the assignment
|
||||
targs = assignDistributionSet(dsA, targs).getAssignedEntity();
|
||||
Target targ = targetManagement.findTargetByControllerID(targs.iterator().next().getControllerId());
|
||||
Target targ = targetManagement.findTargetByControllerID(targs.iterator().next().getControllerId()).get();
|
||||
|
||||
// checking the revisions of the created entities
|
||||
// verifying that the revision of the object and the revision within the
|
||||
// DB has not changed
|
||||
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).get().getOptLockRevision());
|
||||
|
||||
// verifying that the assignment is correct
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size())
|
||||
@@ -736,7 +755,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(updAct.getContent().get(0).getId()).status(Status.FINISHED));
|
||||
|
||||
targ = targetManagement.findTargetByControllerID(targ.getControllerId());
|
||||
targ = targetManagement.findTargetByControllerID(targ.getControllerId()).get();
|
||||
|
||||
assertEquals("active target actions are wrong", 0,
|
||||
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size());
|
||||
@@ -754,11 +773,11 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertEquals("active actions are wrong", 1,
|
||||
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size());
|
||||
assertEquals("target status is wrong", TargetUpdateStatus.PENDING,
|
||||
targetManagement.findTargetByControllerID(targ.getControllerId()).getTargetInfo().getUpdateStatus());
|
||||
assertEquals("target status is wrong", TargetUpdateStatus.PENDING, targetManagement
|
||||
.findTargetByControllerID(targ.getControllerId()).get().getTargetInfo().getUpdateStatus());
|
||||
assertEquals("wrong assigned ds", dsB, targ.getAssignedDistributionSet());
|
||||
assertEquals("Installed ds is wrong", dsA.getId(),
|
||||
targetManagement.findTargetByControllerIDWithDetails(targ.getControllerId()).getTargetInfo()
|
||||
targetManagement.findTargetByControllerIDWithDetails(targ.getControllerId()).get().getTargetInfo()
|
||||
.getInstalledDistributionSet().getId());
|
||||
assertEquals("Active ds is wrong", dsB,
|
||||
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet());
|
||||
@@ -774,12 +793,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Target targ = testdataFactory.createTarget("target-id-A");
|
||||
|
||||
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).get().getOptLockRevision());
|
||||
|
||||
assignDistributionSet(dsA, Lists.newArrayList(targ));
|
||||
|
||||
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).get().getOptLockRevision());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -793,16 +812,17 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
ds.getId(), ActionType.SOFT,
|
||||
org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME,
|
||||
Lists.newArrayList(target.getControllerId()));
|
||||
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0));
|
||||
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0))
|
||||
.get();
|
||||
// verify preparation
|
||||
Action findAction = deploymentManagement.findAction(action.getId());
|
||||
Action findAction = deploymentManagement.findAction(action.getId()).get();
|
||||
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.SOFT);
|
||||
|
||||
// test
|
||||
deploymentManagement.forceTargetAction(action.getId());
|
||||
|
||||
// verify test
|
||||
findAction = deploymentManagement.findAction(action.getId());
|
||||
findAction = deploymentManagement.findAction(action.getId()).get();
|
||||
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
|
||||
}
|
||||
|
||||
@@ -817,9 +837,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
ds.getId(), ActionType.FORCED,
|
||||
org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME,
|
||||
Lists.newArrayList(target.getControllerId()));
|
||||
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0));
|
||||
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0))
|
||||
.get();
|
||||
// verify perparation
|
||||
Action findAction = deploymentManagement.findAction(action.getId());
|
||||
Action findAction = deploymentManagement.findAction(action.getId()).get();
|
||||
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
|
||||
|
||||
// test
|
||||
@@ -827,7 +848,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// verify test
|
||||
assertThat(forceTargetAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
|
||||
findAction = deploymentManagement.findAction(action.getId());
|
||||
findAction = deploymentManagement.findAction(action.getId()).get();
|
||||
assertThat(findAction.getActionType()).as("action type is wrong").isEqualTo(ActionType.FORCED);
|
||||
}
|
||||
|
||||
@@ -896,7 +917,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(event.getActionId()).as("Action id in database and event do not match")
|
||||
.isEqualTo(activeActionsByTarget.get(0).getId());
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetById(event.getDistributionSetId())
|
||||
assertThat(distributionSetManagement.findDistributionSetById(event.getDistributionSetId()).get()
|
||||
.getModules()).as("softwaremodule size is not correct")
|
||||
.containsOnly(ds.getModules().toArray(new SoftwareModule[ds.getModules().size()]));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -18,6 +18,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.DistributionSetCreate;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
|
||||
@@ -39,7 +40,6 @@ import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.test.matcher.Expect;
|
||||
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.fest.assertions.core.Condition;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -64,25 +64,29 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
public void updateUnassignedDistributionSetTypeModules() {
|
||||
DistributionSetType updatableType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.isEmpty();
|
||||
assertThat(
|
||||
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
|
||||
.isEmpty();
|
||||
|
||||
// add OS
|
||||
updatableType = distributionSetManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
|
||||
Sets.newHashSet(osType.getId()));
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.containsOnly(osType);
|
||||
assertThat(
|
||||
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
|
||||
.containsOnly(osType);
|
||||
|
||||
// add JVM
|
||||
updatableType = distributionSetManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
|
||||
Sets.newHashSet(runtimeType.getId()));
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.containsOnly(osType, runtimeType);
|
||||
assertThat(
|
||||
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
|
||||
.containsOnly(osType, runtimeType);
|
||||
|
||||
// remove OS
|
||||
updatableType = distributionSetManagement.unassignSoftwareModuleType(updatableType.getId(), osType.getId());
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.containsOnly(runtimeType);
|
||||
assertThat(
|
||||
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
|
||||
.containsOnly(runtimeType);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,17 +94,18 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
public void updateAssignedDistributionSetTypeMetaData() {
|
||||
final DistributionSetType nonUpdatableType = distributionSetManagement.createDistributionSetType(entityFactory
|
||||
.distributionSetType().create().key("updatableType").name("to be deleted").colour("test123"));
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.isEmpty();
|
||||
assertThat(
|
||||
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
|
||||
.isEmpty();
|
||||
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
|
||||
.version("1").type(nonUpdatableType.getKey()));
|
||||
|
||||
distributionSetManagement.updateDistributionSetType(
|
||||
entityFactory.distributionSetType().update(nonUpdatableType.getId()).description("a new description"));
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getDescription())
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getDescription())
|
||||
.isEqualTo("a new description");
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getColour())
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getColour())
|
||||
.isEqualTo("test123");
|
||||
}
|
||||
|
||||
@@ -109,8 +114,9 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
public void addModuleToAssignedDistributionSetTypeFails() {
|
||||
final DistributionSetType nonUpdatableType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.isEmpty();
|
||||
assertThat(
|
||||
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
|
||||
.isEmpty();
|
||||
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
|
||||
.version("1").type(nonUpdatableType.getKey()));
|
||||
|
||||
@@ -129,8 +135,9 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
public void removeModuleToAssignedDistributionSetTypeFails() {
|
||||
DistributionSetType nonUpdatableType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.isEmpty();
|
||||
assertThat(
|
||||
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
|
||||
.isEmpty();
|
||||
|
||||
nonUpdatableType = distributionSetManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(),
|
||||
Sets.newHashSet(osType.getId()));
|
||||
@@ -170,7 +177,8 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
entityFactory.distributionSet().create().name("softdeleted").version("1").type(softDelete.getKey()));
|
||||
|
||||
distributionSetManagement.deleteDistributionSetType(softDelete.getId());
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").isDeleted()).isEqualTo(true);
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").get().isDeleted())
|
||||
.isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -251,7 +259,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// assign target
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
|
||||
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get();
|
||||
|
||||
// not allowed as it is assigned now
|
||||
try {
|
||||
@@ -264,7 +272,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
// not allowed as it is assigned now
|
||||
try {
|
||||
ds = distributionSetManagement.unassignSoftwareModule(ds.getId(),
|
||||
ds.findFirstModuleByType(appType).getId());
|
||||
ds.findFirstModuleByType(appType).get().getId());
|
||||
fail("Expected EntityReadOnlyException");
|
||||
} catch (final EntityReadOnlyException e) {
|
||||
|
||||
@@ -303,19 +311,19 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
// update data
|
||||
// legal update of module addition
|
||||
distributionSetManagement.assignSoftwareModules(ds.getId(), Sets.newHashSet(os.getId()));
|
||||
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
|
||||
assertThat(ds.findFirstModuleByType(osType)).isEqualTo(os);
|
||||
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get();
|
||||
assertThat(ds.findFirstModuleByType(osType).get()).isEqualTo(os);
|
||||
|
||||
// legal update of module removal
|
||||
distributionSetManagement.unassignSoftwareModule(ds.getId(), ds.findFirstModuleByType(appType).getId());
|
||||
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
|
||||
assertThat(ds.findFirstModuleByType(appType)).isNull();
|
||||
distributionSetManagement.unassignSoftwareModule(ds.getId(), ds.findFirstModuleByType(appType).get().getId());
|
||||
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get();
|
||||
assertThat(ds.findFirstModuleByType(appType).isPresent()).isFalse();
|
||||
|
||||
// Update description
|
||||
distributionSetManagement
|
||||
.updateDistributionSet(entityFactory.distributionSet().update(ds.getId()).name("a new name")
|
||||
.description("a new description").version("a new version").requiredMigrationStep(true));
|
||||
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
|
||||
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get();
|
||||
assertThat(ds.getDescription()).isEqualTo("a new description");
|
||||
assertThat(ds.getName()).isEqualTo("a new name");
|
||||
assertThat(ds.getVersion()).isEqualTo("a new version");
|
||||
@@ -338,7 +346,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
// create an DS meta data entry
|
||||
createDistributionSetMetadata(ds.getId(), new JpaDistributionSetMetadata(knownKey, ds, knownValue));
|
||||
|
||||
DistributionSet changedLockRevisionDS = distributionSetManagement.findDistributionSetById(ds.getId());
|
||||
DistributionSet changedLockRevisionDS = distributionSetManagement.findDistributionSetById(ds.getId()).get();
|
||||
assertThat(changedLockRevisionDS.getOptLockRevision()).isEqualTo(2);
|
||||
|
||||
Thread.sleep(100);
|
||||
@@ -349,7 +357,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
// we are updating the sw meta data so also modifying the base software
|
||||
// module so opt lock
|
||||
// revision must be three
|
||||
changedLockRevisionDS = distributionSetManagement.findDistributionSetById(ds.getId());
|
||||
changedLockRevisionDS = distributionSetManagement.findDistributionSetById(ds.getId()).get();
|
||||
assertThat(changedLockRevisionDS.getOptLockRevision()).isEqualTo(3);
|
||||
assertThat(changedLockRevisionDS.getLastModifiedAt()).isGreaterThan(0L);
|
||||
|
||||
@@ -435,14 +443,14 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assignDistributionSet(dsDeleted, Lists.newArrayList(testdataFactory.createTargets(5)));
|
||||
distributionSetManagement.deleteDistributionSet(dsDeleted.getId());
|
||||
dsDeleted = distributionSetManagement.findDistributionSetById(dsDeleted.getId());
|
||||
dsDeleted = distributionSetManagement.findDistributionSetById(dsDeleted.getId()).get();
|
||||
|
||||
ds100Group1 = toggleTagAssignment(ds100Group1, dsTagA).getAssignedEntity();
|
||||
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName());
|
||||
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName()).get();
|
||||
ds100Group1 = toggleTagAssignment(ds100Group1, dsTagB).getAssignedEntity();
|
||||
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName());
|
||||
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName()).get();
|
||||
ds100Group2 = toggleTagAssignment(ds100Group2, dsTagA).getAssignedEntity();
|
||||
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName());
|
||||
dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName()).get();
|
||||
|
||||
// check setup
|
||||
assertThat(distributionSetRepository.findAll()).hasSize(203);
|
||||
@@ -655,11 +663,8 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Deltes a DS that is no in use. Expected behaviour is a hard delete on the database.")
|
||||
public void deleteUnassignedDistributionSet() {
|
||||
DistributionSet ds1 = testdataFactory.createDistributionSet("ds-1");
|
||||
DistributionSet ds2 = testdataFactory.createDistributionSet("ds-2");
|
||||
|
||||
ds1 = distributionSetManagement.findDistributionSetByNameAndVersion(ds1.getName(), ds1.getVersion());
|
||||
ds2 = distributionSetManagement.findDistributionSetByNameAndVersion(ds2.getName(), ds2.getVersion());
|
||||
final DistributionSet ds1 = testdataFactory.createDistributionSet("ds-1");
|
||||
testdataFactory.createDistributionSet("ds-2");
|
||||
|
||||
// delete a ds
|
||||
assertThat(distributionSetRepository.findAll()).hasSize(2);
|
||||
@@ -707,17 +712,12 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Deletes a DS that is in use by either target assignment or rollout. Expected behaviour is a soft delete on the database, i.e. only marked as "
|
||||
+ "deleted, kept as reference but unavailable for future use..")
|
||||
public void deleteAssignedDistributionSet() {
|
||||
DistributionSet ds1 = testdataFactory.createDistributionSet("ds-1");
|
||||
DistributionSet ds2 = testdataFactory.createDistributionSet("ds-2");
|
||||
DistributionSet dsToTargetAssigned = testdataFactory.createDistributionSet("ds-3");
|
||||
testdataFactory.createDistributionSet("ds-1");
|
||||
testdataFactory.createDistributionSet("ds-2");
|
||||
final DistributionSet dsToTargetAssigned = testdataFactory.createDistributionSet("ds-3");
|
||||
final DistributionSet dsToRolloutAssigned = testdataFactory.createDistributionSet("ds-4");
|
||||
|
||||
ds1 = distributionSetManagement.findDistributionSetByNameAndVersion(ds1.getName(), ds1.getVersion());
|
||||
ds2 = distributionSetManagement.findDistributionSetByNameAndVersion(ds2.getName(), ds2.getVersion());
|
||||
|
||||
// create assigned DS
|
||||
dsToTargetAssigned = distributionSetManagement.findDistributionSetByNameAndVersion(dsToTargetAssigned.getName(),
|
||||
dsToTargetAssigned.getVersion());
|
||||
final Target savedTarget = testdataFactory.createTarget();
|
||||
assignDistributionSet(dsToTargetAssigned.getId(), savedTarget.getControllerId());
|
||||
|
||||
@@ -739,11 +739,9 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verify that the DistributionSetAssignmentResult not contains already assigned targets.")
|
||||
public void verifyDistributionSetAssignmentResultNotContainsAlreadyAssignedTargets() {
|
||||
DistributionSet dsToTargetAssigned = testdataFactory.createDistributionSet("ds-3");
|
||||
final DistributionSet dsToTargetAssigned = testdataFactory.createDistributionSet("ds-3");
|
||||
|
||||
// create assigned DS
|
||||
dsToTargetAssigned = distributionSetManagement.findDistributionSetByNameAndVersion(dsToTargetAssigned.getName(),
|
||||
dsToTargetAssigned.getVersion());
|
||||
final Target savedTarget = testdataFactory.createTarget();
|
||||
DistributionSetAssignmentResult assignmentResult = assignDistributionSet(dsToTargetAssigned.getId(),
|
||||
savedTarget.getControllerId());
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.fest.assertions.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.fest.assertions.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -196,7 +196,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
// Run here, because scheduler is disabled during tests
|
||||
rolloutManagement.checkStartingRollouts(0);
|
||||
|
||||
return rolloutManagement.findRolloutById(createdRollout.getId());
|
||||
return rolloutManagement.findRolloutById(createdRollout.getId()).get();
|
||||
}
|
||||
|
||||
@Step("Finish three actions of the rollout group and delete two targets")
|
||||
@@ -249,7 +249,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
|
||||
assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
|
||||
assertThat(runningRolloutGroups.get(2).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
|
||||
assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).getStatus())
|
||||
assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).get().getStatus())
|
||||
.isEqualTo(RolloutStatus.FINISHED);
|
||||
|
||||
}
|
||||
@@ -284,7 +284,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
// and should execute the error action
|
||||
rolloutManagement.checkRunningRollouts(0);
|
||||
|
||||
final Rollout rollout = rolloutManagement.findRolloutById(createdRollout.getId());
|
||||
final Rollout rollout = rolloutManagement.findRolloutById(createdRollout.getId()).get();
|
||||
// the rollout itself should be in paused based on the error action
|
||||
assertThat(rollout.getStatus()).isEqualTo(RolloutStatus.PAUSED);
|
||||
|
||||
@@ -324,7 +324,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
// and should execute the error action
|
||||
rolloutManagement.checkRunningRollouts(0);
|
||||
|
||||
final Rollout rollout = rolloutManagement.findRolloutById(createdRollout.getId());
|
||||
final Rollout rollout = rolloutManagement.findRolloutById(createdRollout.getId()).get();
|
||||
// the rollout itself should be in paused based on the error action
|
||||
assertThat(rollout.getStatus()).isEqualTo(RolloutStatus.PAUSED);
|
||||
|
||||
@@ -337,7 +337,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.resumeRollout(createdRollout.getId());
|
||||
|
||||
// the rollout should be running again
|
||||
assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).getStatus())
|
||||
assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).get().getStatus())
|
||||
.isEqualTo(RolloutStatus.RUNNING);
|
||||
|
||||
// checking rollouts again
|
||||
@@ -370,7 +370,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.checkRunningRollouts(0);
|
||||
// finish running actions, 2 actions should be finished
|
||||
assertThat(changeStatusForAllRunningActions(createdRollout, Status.FINISHED)).isEqualTo(2);
|
||||
assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).getStatus())
|
||||
assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).get().getStatus())
|
||||
.isEqualTo(RolloutStatus.RUNNING);
|
||||
|
||||
}
|
||||
@@ -385,7 +385,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.FINISHED));
|
||||
|
||||
// verify that rollout itself is in finished state
|
||||
final Rollout findRolloutById = rolloutManagement.findRolloutById(createdRollout.getId());
|
||||
final Rollout findRolloutById = rolloutManagement.findRolloutById(createdRollout.getId()).get();
|
||||
assertThat(findRolloutById.getStatus()).isEqualTo(RolloutStatus.FINISHED);
|
||||
}
|
||||
|
||||
@@ -508,7 +508,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
// round(7/3)=2 targets running (Group 3)
|
||||
// round(5/2)=3 targets SCHEDULED (Group 3)
|
||||
// round(2/1)=2 targets SCHEDULED (Group 4)
|
||||
createdRollout = rolloutManagement.findRolloutById(createdRollout.getId());
|
||||
createdRollout = rolloutManagement.findRolloutById(createdRollout.getId()).get();
|
||||
final List<RolloutGroup> rolloutGroups = createdRollout.getRolloutGroups();
|
||||
|
||||
Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
|
||||
@@ -542,7 +542,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
successCondition, errorCondition);
|
||||
final DistributionSet ds = createdRollout.getDistributionSet();
|
||||
|
||||
createdRollout = rolloutManagement.findRolloutById(createdRollout.getId());
|
||||
createdRollout = rolloutManagement.findRolloutById(createdRollout.getId()).get();
|
||||
// 5 targets are running
|
||||
final List<Action> runningActions = findActionsByRolloutAndStatus(createdRollout, Status.RUNNING);
|
||||
assertThat(runningActions.size()).isEqualTo(5);
|
||||
@@ -584,7 +584,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
Rollout rolloutOne = createAndStartRollout(amountTargetsForRollout, amountOtherTargets, amountGroups,
|
||||
successCondition, errorCondition);
|
||||
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
|
||||
|
||||
final DistributionSet dsForRolloutTwo = testdataFactory.createDistributionSet("dsForRolloutTwo");
|
||||
|
||||
@@ -626,7 +626,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
successCondition, errorCondition);
|
||||
final DistributionSet distributionSet = rolloutOne.getDistributionSet();
|
||||
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
|
||||
changeStatusForRunningActions(rolloutOne, Status.ERROR, 2);
|
||||
changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3);
|
||||
rolloutManagement.checkRunningRollouts(0);
|
||||
@@ -643,7 +643,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.ERROR, 6L);
|
||||
validateRolloutActionStatus(rolloutOne.getId(), expectedTargetCountStatus);
|
||||
// rollout is finished
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
|
||||
assertThat(rolloutOne.getStatus()).isEqualTo(RolloutStatus.FINISHED);
|
||||
|
||||
final int amountGroupsForRolloutTwo = 1;
|
||||
@@ -655,7 +655,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
// Run here, because scheduler is disabled during tests
|
||||
rolloutManagement.checkStartingRollouts(0);
|
||||
|
||||
rolloutTwo = rolloutManagement.findRolloutById(rolloutTwo.getId());
|
||||
rolloutTwo = rolloutManagement.findRolloutById(rolloutTwo.getId()).get();
|
||||
// 6 error targets are know running
|
||||
expectedTargetCountStatus = createInitStatusMap();
|
||||
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 6L);
|
||||
@@ -684,7 +684,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
Rollout rolloutOne = createAndStartRollout(amountTargetsForRollout, amountOtherTargets, amountGroups,
|
||||
successCondition, errorCondition);
|
||||
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
|
||||
changeStatusForRunningActions(rolloutOne, Status.ERROR, 2);
|
||||
changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3);
|
||||
rolloutManagement.checkRunningRollouts(0);
|
||||
@@ -708,13 +708,13 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
Rollout rolloutOne = createAndStartRollout(amountTargetsForRollout, amountOtherTargets, amountGroups,
|
||||
successCondition, errorCondition);
|
||||
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
|
||||
changeStatusForRunningActions(rolloutOne, Status.ERROR, 2);
|
||||
changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3);
|
||||
rolloutManagement.checkRunningRollouts(0);
|
||||
// verify: 40% error and 60% finished -> should not move to next group
|
||||
// because successCondition 80%
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
|
||||
final List<RolloutGroup> rolloutGruops = rolloutOne.getRolloutGroups();
|
||||
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
|
||||
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.SCHEDULED, 5L);
|
||||
@@ -733,12 +733,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
Rollout rolloutOne = createAndStartRollout(amountTargetsForRollout, amountOtherTargets, amountGroups,
|
||||
successCondition, errorCondition);
|
||||
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
|
||||
changeStatusForRunningActions(rolloutOne, Status.ERROR, 2);
|
||||
changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3);
|
||||
rolloutManagement.checkRunningRollouts(0);
|
||||
// verify: 40% error -> should pause because errorCondition is 20%
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get();
|
||||
assertThat(RolloutStatus.PAUSED).isEqualTo(rolloutOne.getStatus());
|
||||
}
|
||||
|
||||
@@ -896,7 +896,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Rollout rolloutCreated = createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout,
|
||||
amountGroups, successCondition, errorCondition, rolloutName, "RolloutA");
|
||||
|
||||
final Rollout rolloutFound = rolloutManagement.findRolloutByName(rolloutName);
|
||||
final Rollout rolloutFound = rolloutManagement.findRolloutByName(rolloutName).get();
|
||||
assertThat(rolloutCreated).isEqualTo(rolloutFound);
|
||||
|
||||
}
|
||||
@@ -919,7 +919,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
changeStatusForRunningActions(myRollout, Status.FINISHED, 2);
|
||||
rolloutManagement.checkRunningRollouts(0);
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
|
||||
|
||||
float percent = rolloutManagement.getFinishedPercentForRunningGroup(myRollout.getId(),
|
||||
myRollout.getRolloutGroups().get(0).getId());
|
||||
@@ -963,7 +963,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
// Run here, because scheduler is disabled during tests
|
||||
rolloutManagement.checkStartingRollouts(0);
|
||||
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
|
||||
final List<RolloutGroup> rolloutGroups = myRollout.getRolloutGroups();
|
||||
|
||||
Page<Target> targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0).getId(),
|
||||
@@ -1070,7 +1070,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(MultipleInvokeHelper.doWithTimeout(new RolloutStatusCallable(myRollout.getId()),
|
||||
conditionRolloutStatus, 15000, 500)).as("Rollout status").isNotNull();
|
||||
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.RUNNING);
|
||||
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
|
||||
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 1L);
|
||||
@@ -1099,7 +1099,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
rolloutManagement.checkReadyRollouts(0);
|
||||
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
|
||||
|
||||
rolloutManagement.startRollout(myRollout.getId());
|
||||
@@ -1112,7 +1112,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(MultipleInvokeHelper.doWithTimeout(new RolloutStatusCallable(myRollout.getId()),
|
||||
conditionRolloutTargetCount, 15000, 500)).as("Rollout status").isNotNull();
|
||||
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.RUNNING);
|
||||
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
|
||||
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 100L);
|
||||
@@ -1144,15 +1144,15 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.checkReadyRollouts(0);
|
||||
|
||||
// rollout should not have been started
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
|
||||
|
||||
// schedule to now
|
||||
rolloutManagement.updateRollout(
|
||||
entityFactory.rollout().update(myRollout.getId()).startAt(System.currentTimeMillis()));
|
||||
rolloutManagement
|
||||
.updateRollout(entityFactory.rollout().update(myRollout.getId()).startAt(System.currentTimeMillis()));
|
||||
rolloutManagement.checkReadyRollouts(0);
|
||||
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.STARTING);
|
||||
|
||||
// Run here, because scheduler is disabled during tests
|
||||
@@ -1163,7 +1163,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(MultipleInvokeHelper.doWithTimeout(new RolloutStatusCallable(myRollout.getId()),
|
||||
conditionRolloutTargetCount, 15000, 500)).as("Rollout status").isNotNull();
|
||||
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.RUNNING);
|
||||
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
|
||||
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 100L);
|
||||
@@ -1200,7 +1200,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutGroups.add(generateRolloutGroup(2, percentTargetsInGroup3, null));
|
||||
|
||||
Rollout myRollout = rolloutManagement.createRollout(rolloutcreate, rolloutGroups, conditions);
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
|
||||
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING);
|
||||
for (final RolloutGroup group : myRollout.getRolloutGroups()) {
|
||||
@@ -1214,7 +1214,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
rolloutManagement.fillRolloutGroupsWithTargets(myRollout.getId());
|
||||
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
|
||||
assertThat(myRollout.getTotalTargets()).isEqualTo(amountTargetsInGroup1and2 + amountTargetsInGroup1);
|
||||
|
||||
@@ -1318,7 +1318,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
.set(distributionSet);
|
||||
|
||||
Rollout myRollout = rolloutManagement.createRollout(rolloutToCreate, amountGroups, conditions);
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get();
|
||||
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING);
|
||||
|
||||
@@ -1351,13 +1351,13 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
private void validateRolloutGroupActionStatus(final RolloutGroup rolloutGroup,
|
||||
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus) {
|
||||
final RolloutGroup rolloutGroupWithDetail = rolloutGroupManagement
|
||||
.findRolloutGroupWithDetailedStatus(rolloutGroup.getId());
|
||||
.findRolloutGroupWithDetailedStatus(rolloutGroup.getId()).get();
|
||||
validateStatus(rolloutGroupWithDetail.getTotalTargetCountStatus(), expectedTargetCountStatus);
|
||||
}
|
||||
|
||||
private void validateRolloutActionStatus(final Long rolloutId,
|
||||
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus) {
|
||||
final Rollout rolloutWithDetail = rolloutManagement.findRolloutWithDetailedStatus(rolloutId);
|
||||
final Rollout rolloutWithDetail = rolloutManagement.findRolloutWithDetailedStatus(rolloutId).get();
|
||||
validateStatus(rolloutWithDetail.getTotalTargetCountStatus(), expectedTargetCountStatus);
|
||||
}
|
||||
|
||||
@@ -1447,7 +1447,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Override
|
||||
public RolloutStatus call() throws Exception {
|
||||
|
||||
final Rollout myRollout = rolloutManagement.findRolloutById(rolloutId);
|
||||
final Rollout myRollout = rolloutManagement.findRolloutById(rolloutId).get();
|
||||
return myRollout.getStatus();
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -23,7 +23,6 @@ import javax.validation.ConstraintViolationException;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
|
||||
@@ -187,11 +186,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()).getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getAssignedDistributionSet())
|
||||
.isEqualTo(ds);
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()).get().getAssignedDistributionSet())
|
||||
.isEqualTo(ds);
|
||||
final Action action = actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent().get(0);
|
||||
assertThat(action).isNotNull();
|
||||
return action;
|
||||
@@ -290,7 +289,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
// verify: SoftwareModule is deleted
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize(0);
|
||||
assertThat(softwareManagement.findSoftwareModuleById(unassignedModule.getId())).isNull();
|
||||
assertThat(softwareManagement.findSoftwareModuleById(unassignedModule.getId()).isPresent()).isFalse();
|
||||
|
||||
// verify: binary data of artifact is deleted
|
||||
assertArtfiactNull(artifact1, artifact2);
|
||||
@@ -315,7 +314,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
// verify: assignedModule is marked as deleted
|
||||
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId());
|
||||
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId()).get();
|
||||
assertTrue("The module should be flagged as deleted", assignedModule.isDeleted());
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize(1);
|
||||
@@ -355,7 +354,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
// verify: assignedModule is marked as deleted
|
||||
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId());
|
||||
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId()).get();
|
||||
assertTrue("The found module should be flagged deleted", assignedModule.isDeleted());
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize(1);
|
||||
@@ -383,7 +382,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// [STEP2]: Create newArtifactX and add it to SoftwareModuleX
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
|
||||
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId());
|
||||
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId()).get();
|
||||
final Artifact artifactX = moduleX.getArtifacts().iterator().next();
|
||||
|
||||
// [STEP3]: Create SoftwareModuleY and add the same ArtifactX
|
||||
@@ -391,7 +390,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// [STEP4]: Assign the same ArtifactX to SoftwareModuleY
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
|
||||
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId());
|
||||
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId()).get();
|
||||
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
|
||||
|
||||
// [STEP5]: Delete SoftwareModuleX
|
||||
@@ -400,8 +399,8 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
// verify: SoftwareModuleX is deleted, and ModuelY still exists
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize(1);
|
||||
assertThat(softwareManagement.findSoftwareModuleById(moduleX.getId())).isNull();
|
||||
assertThat(softwareManagement.findSoftwareModuleById(moduleY.getId())).isNotNull();
|
||||
assertThat(softwareManagement.findSoftwareModuleById(moduleX.getId()).isPresent()).isFalse();
|
||||
assertThat(softwareManagement.findSoftwareModuleById(moduleY.getId()).isPresent()).isTrue();
|
||||
|
||||
// verify: binary data of artifact is not deleted
|
||||
assertArtfiactNotNull(artifactY);
|
||||
@@ -425,14 +424,14 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0);
|
||||
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
|
||||
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId());
|
||||
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId()).get();
|
||||
final Artifact artifactX = moduleX.getArtifacts().iterator().next();
|
||||
|
||||
// [STEP2]: Create SoftwareModuleY and add the same ArtifactX
|
||||
SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0);
|
||||
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
|
||||
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId());
|
||||
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId()).get();
|
||||
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
|
||||
|
||||
// [STEP3]: Assign SoftwareModuleX to DistributionSetX and to target
|
||||
@@ -450,8 +449,8 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
softwareManagement.deleteSoftwareModule(moduleY.getId());
|
||||
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId());
|
||||
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId());
|
||||
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId()).get();
|
||||
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId()).get();
|
||||
|
||||
// verify: SoftwareModuleX and SofwtareModule are marked as deleted
|
||||
assertThat(moduleX).isNotNull();
|
||||
@@ -483,7 +482,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
// Verify correct Creation of SoftwareModule and corresponding artifacts
|
||||
softwareModule = softwareManagement.findSoftwareModuleById(softwareModule.getId());
|
||||
softwareModule = softwareManagement.findSoftwareModuleById(softwareModule.getId()).get();
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize((int) countSoftwareModule + 1);
|
||||
|
||||
final List<Artifact> artifacts = softwareModule.getArtifacts();
|
||||
@@ -623,7 +622,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.softwareModuleType().create().key("thetype2").name("anothername"));
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleTypeByName("thename")).as("Type with given name")
|
||||
assertThat(softwareManagement.findSoftwareModuleTypeByName("thename").get()).as("Type with given name")
|
||||
.isEqualTo(found);
|
||||
}
|
||||
|
||||
@@ -718,7 +717,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<SoftwareModuleMetadata> softwareModuleMetadata = softwareManagement
|
||||
.createSoftwareModuleMetadata(ah.getId(), Lists.newArrayList(swMetadata1, swMetadata2));
|
||||
|
||||
final SoftwareModule changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId());
|
||||
final SoftwareModule changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId()).get();
|
||||
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2);
|
||||
|
||||
assertThat(softwareModuleMetadata).hasSize(2);
|
||||
@@ -770,7 +769,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
// base software module should have now the opt lock revision one
|
||||
// because we are modifying the
|
||||
// base software module
|
||||
SoftwareModule changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId());
|
||||
SoftwareModule changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId()).get();
|
||||
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2);
|
||||
|
||||
// update the software module metadata
|
||||
@@ -780,7 +779,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
// we are updating the sw meta data so also modiying the base software
|
||||
// module so opt lock
|
||||
// revision must be two
|
||||
changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId());
|
||||
changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId()).get();
|
||||
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(3);
|
||||
|
||||
// verify updated meta data contains the updated value
|
||||
@@ -823,12 +822,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
.createSoftwareModuleMetadata(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1))
|
||||
.getSoftwareModule();
|
||||
|
||||
try {
|
||||
softwareManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist");
|
||||
fail("should not have worked as module metadata with that key does not exist");
|
||||
} catch (final EntityNotFoundException e) {
|
||||
|
||||
}
|
||||
assertThat(softwareManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist").isPresent()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.report.model.TenantUsage;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithSpringAuthorityRule;
|
||||
@@ -131,9 +131,7 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void createTestArtifact(final byte[] random) {
|
||||
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
sm = softwareModuleRepository.save(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -72,18 +72,18 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
toggleTagAssignment(dsBs, tagB);
|
||||
toggleTagAssignment(dsCs, tagC);
|
||||
|
||||
toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagA.getName()));
|
||||
toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagB.getName()));
|
||||
toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagA.getName()).get());
|
||||
toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagB.getName()).get());
|
||||
|
||||
toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagA.getName()));
|
||||
toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagC.getName()));
|
||||
toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagA.getName()).get());
|
||||
toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagC.getName()).get());
|
||||
|
||||
toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagB.getName()));
|
||||
toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagC.getName()));
|
||||
toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagB.getName()).get());
|
||||
toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagC.getName()).get());
|
||||
|
||||
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagA.getName()));
|
||||
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagB.getName()));
|
||||
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagC.getName()));
|
||||
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagA.getName()).get());
|
||||
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagB.getName()).get());
|
||||
toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagC.getName()).get());
|
||||
|
||||
DistributionSetFilterBuilder distributionSetFilterBuilder;
|
||||
|
||||
@@ -259,9 +259,11 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Tag tag = tagManagement
|
||||
.createTargetTag(entityFactory.tag().create().name("kai1").description("kai2").colour("colour"));
|
||||
|
||||
assertThat(targetTagRepository.findByNameEquals("kai1").getDescription()).as("wrong tag ed").isEqualTo("kai2");
|
||||
assertThat(tagManagement.findTargetTag("kai1").getColour()).as("wrong tag found").isEqualTo("colour");
|
||||
assertThat(tagManagement.findTargetTagById(tag.getId()).getColour()).as("wrong tag found").isEqualTo("colour");
|
||||
assertThat(targetTagRepository.findByNameEquals("kai1").get().getDescription()).as("wrong tag ed")
|
||||
.isEqualTo("kai2");
|
||||
assertThat(tagManagement.findTargetTag("kai1").get().getColour()).as("wrong tag found").isEqualTo("colour");
|
||||
assertThat(tagManagement.findTargetTagById(tag.getId()).get().getColour()).as("wrong tag found")
|
||||
.isEqualTo("colour");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,7 +275,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
final TargetTag toDelete = tags.iterator().next();
|
||||
|
||||
for (final Target target : targetRepository.findAll()) {
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getTags())
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTags())
|
||||
.contains(toDelete);
|
||||
}
|
||||
|
||||
@@ -282,7 +284,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// check
|
||||
for (final Target target : targetRepository.findAll()) {
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getTags())
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTags())
|
||||
.doesNotContain(toDelete);
|
||||
}
|
||||
assertThat(targetTagRepository.findOne(toDelete.getId())).as("No tag should be found").isNull();
|
||||
@@ -314,10 +316,11 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Tag tag = tagManagement.createDistributionSetTag(
|
||||
entityFactory.tag().create().name("kai1").description("kai2").colour("colour"));
|
||||
|
||||
assertThat(distributionSetTagRepository.findByNameEquals("kai1").getDescription()).as("wrong tag found")
|
||||
assertThat(distributionSetTagRepository.findByNameEquals("kai1").get().getDescription()).as("wrong tag found")
|
||||
.isEqualTo("kai2");
|
||||
assertThat(tagManagement.findDistributionSetTag("kai1").getColour()).as("wrong tag found").isEqualTo("colour");
|
||||
assertThat(tagManagement.findDistributionSetTagById(tag.getId()).getColour()).as("wrong tag found")
|
||||
assertThat(tagManagement.findDistributionSetTag("kai1").get().getColour()).as("wrong tag found")
|
||||
.isEqualTo("colour");
|
||||
assertThat(tagManagement.findDistributionSetTagById(tag.getId()).get().getColour()).as("wrong tag found")
|
||||
.isEqualTo("colour");
|
||||
}
|
||||
|
||||
@@ -337,7 +340,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSetTag toDelete = tags.iterator().next();
|
||||
|
||||
for (final DistributionSet set : distributionSetRepository.findAll()) {
|
||||
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).getTags())
|
||||
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).get().getTags())
|
||||
.as("Wrong tag found").contains(toDelete);
|
||||
}
|
||||
|
||||
@@ -348,7 +351,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(distributionSetTagRepository.findOne(toDelete.getId())).as("Deleted tag should be null").isNull();
|
||||
assertThat(tagManagement.findAllDistributionSetTags()).as("Wrong size of tags after deletion").hasSize(19);
|
||||
for (final DistributionSet set : distributionSetRepository.findAll()) {
|
||||
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).getTags())
|
||||
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).get().getTags())
|
||||
.as("Wrong found tags").doesNotContain(toDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -47,7 +48,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
||||
assertEquals("Retrieved newly created custom target filter", targetFilterQuery,
|
||||
targetFilterQueryManagement.findTargetFilterQueryByName(filterName));
|
||||
targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,8 +99,8 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
||||
targetFilterQueryManagement.deleteTargetFilterQuery(targetFilterQuery.getId());
|
||||
assertEquals("Returns null as the target filter is deleted", null,
|
||||
targetFilterQueryManagement.findTargetFilterQueryById(targetFilterQuery.getId()));
|
||||
assertFalse("Returns null as the target filter is deleted",
|
||||
targetFilterQueryManagement.findTargetFilterQueryById(targetFilterQuery.getId()).isPresent());
|
||||
|
||||
}
|
||||
|
||||
@@ -114,7 +115,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
targetFilterQueryManagement.updateTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().update(targetFilterQuery.getId()).query(newQuery));
|
||||
assertEquals("Returns updated target filter query", newQuery,
|
||||
targetFilterQueryManagement.findTargetFilterQueryByName(filterName).getQuery());
|
||||
targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get().getQuery());
|
||||
|
||||
}
|
||||
|
||||
@@ -130,7 +131,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(targetFilterQuery.getId(),
|
||||
distributionSet.getId());
|
||||
|
||||
final TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
|
||||
final TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get();
|
||||
|
||||
assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet());
|
||||
|
||||
@@ -149,13 +150,13 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
distributionSet.getId());
|
||||
|
||||
// Check if target filter query is there
|
||||
TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
|
||||
TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get();
|
||||
assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet());
|
||||
|
||||
distributionSetManagement.deleteDistributionSet(distributionSet.getId());
|
||||
|
||||
// Check if auto assign distribution set is null
|
||||
tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
|
||||
tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get();
|
||||
assertNotNull("Returns target filter query", tfq);
|
||||
assertNull("Returns distribution set as null", tfq.getAutoAssignDistributionSet());
|
||||
|
||||
@@ -178,17 +179,17 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
.getId(), distributionSet.getId());
|
||||
|
||||
// Check if target filter query is there with the distribution set
|
||||
TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
|
||||
TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get();
|
||||
assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet());
|
||||
|
||||
distributionSetManagement.deleteDistributionSet(distributionSet.getId());
|
||||
|
||||
// Check if distribution set is still in the database with deleted flag
|
||||
assertTrue("Distribution set should be deleted",
|
||||
distributionSetManagement.findDistributionSetById(distributionSet.getId()).isDeleted());
|
||||
distributionSetManagement.findDistributionSetById(distributionSet.getId()).get().isDeleted());
|
||||
|
||||
// Check if auto assign distribution set is null
|
||||
tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
|
||||
tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get();
|
||||
assertNotNull("Returns target filter query", tfq);
|
||||
assertNull("Returns distribution set as null", tfq.getAutoAssignDistributionSet());
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
@@ -118,12 +118,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
verifyThatRepositoryContains400Targets();
|
||||
verifyThat200TargetsHaveTagD(targTagW, concat(targBs, targCs));
|
||||
verifyThat100TargetsContainsGivenTextAndHaveTagAssigned(targTagY, targTagW, targBs);
|
||||
verifyThat1TargetHasTagHasDescOrNameAndDs(targTagW, setA, targetManagement.findTargetByControllerID(assignedC));
|
||||
verifyThat1TargetHasTagHasDescOrNameAndDs(targTagW, setA,
|
||||
targetManagement.findTargetByControllerID(assignedC).get());
|
||||
verifyThat0TargetsWithTagAndDescOrNameHasDS(targTagW, setA);
|
||||
verifyThat0TargetsWithNameOrdescAndDSHaveTag(targTagX, setA);
|
||||
verifyThat3TargetsHaveDSAssigned(setA,
|
||||
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
|
||||
verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.findTargetByControllerID(assignedA));
|
||||
verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.findTargetByControllerID(assignedA).get());
|
||||
List<Target> expected = concat(targAs, targBs, targCs, targDs);
|
||||
expected.removeAll(
|
||||
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
|
||||
@@ -133,26 +134,26 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
verifyThat198TargetsAreInStatusUnknownAndHaveGivenTags(targTagY, targTagW, unknown, expected);
|
||||
verfyThat0TargetsAreInStatusUnknownAndHaveDSAssigned(setA, unknown);
|
||||
expected = concat(targAs);
|
||||
expected.remove(targetManagement.findTargetByControllerID(assignedA));
|
||||
expected.remove(targetManagement.findTargetByControllerID(assignedA).get());
|
||||
verifyThat99TargetsWithNameOrDescriptionAreInGivenStatus(unknown, expected);
|
||||
expected = concat(targBs);
|
||||
expected.remove(targetManagement.findTargetByControllerID(assignedB));
|
||||
expected.remove(targetManagement.findTargetByControllerID(assignedB).get());
|
||||
verifyThat99TargetsWithGivenNameOrDescAndTagAreInStatusUnknown(targTagW, unknown, expected);
|
||||
verifyThat3TargetsAreInStatusPending(pending,
|
||||
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
|
||||
verifyThat3TargetsWithGivenDSAreInPending(setA, pending,
|
||||
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
|
||||
verifyThat1TargetWithGivenNameOrDescAndDSIsInPending(setA, pending,
|
||||
targetManagement.findTargetByControllerID(assignedA));
|
||||
targetManagement.findTargetByControllerID(assignedA).get());
|
||||
verifyThat1TargetWithGivenNameOrDescAndTagAndDSIsInPending(targTagW, setA, pending,
|
||||
targetManagement.findTargetByControllerID(assignedB));
|
||||
targetManagement.findTargetByControllerID(assignedB).get());
|
||||
verifyThat2TargetsWithGivenTagAndDSIsInPending(targTagW, setA, pending,
|
||||
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC)));
|
||||
verifyThat2TargetsWithGivenTagAreInPending(targTagW, pending,
|
||||
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC)));
|
||||
verifyThat200targetsWithGivenTagAreInStatusPendingorUnknown(targTagW, both, concat(targBs, targCs));
|
||||
verfiyThat1TargetAIsInStatusPendingAndHasDSInstalled(installedSet, pending,
|
||||
targetManagement.findTargetByControllerID(installedC));
|
||||
targetManagement.findTargetByControllerID(installedC).get());
|
||||
|
||||
expected = concat(targBs, targCs);
|
||||
expected.removeAll(targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC)));
|
||||
|
||||
@@ -12,7 +12,7 @@ import static com.google.common.collect.Iterables.limit;
|
||||
import static com.google.common.collect.Iterables.toArray;
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -197,7 +197,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4);
|
||||
assignedTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(1));
|
||||
|
||||
TargetTag findTargetTag = tagManagement.findTargetTag("Tag1");
|
||||
TargetTag findTargetTag = tagManagement.findTargetTag("Tag1").get();
|
||||
assertThat(assignedTargets.size()).as("Assigned targets are wrong")
|
||||
.isEqualTo(findTargetTag.getAssignedToTargets().size());
|
||||
|
||||
@@ -207,11 +207,11 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Target unAssignTarget = targetManagement.unAssignTag("targetId123", findTargetTag.getId());
|
||||
assertThat(unAssignTarget.getControllerId()).as("Controller id is wrong").isEqualTo("targetId123");
|
||||
assertThat(unAssignTarget.getTags()).as("Tag size is wrong").isEmpty();
|
||||
findTargetTag = tagManagement.findTargetTag("Tag1");
|
||||
findTargetTag = tagManagement.findTargetTag("Tag1").get();
|
||||
assertThat(findTargetTag.getAssignedToTargets()).as("Assigned targets are wrong").hasSize(3);
|
||||
|
||||
final List<Target> unAssignTargets = targetManagement.unAssignAllTargetsByTag(findTargetTag.getId());
|
||||
findTargetTag = tagManagement.findTargetTag("Tag1");
|
||||
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(target.getTags().size()).isEqualTo(0));
|
||||
@@ -250,7 +250,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId(controllerId));
|
||||
controllerManagament.updateControllerAttributes(controllerId, testData);
|
||||
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId);
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
|
||||
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
|
||||
.isEqualTo(testData);
|
||||
return target;
|
||||
@@ -287,7 +287,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
entityFactory.actionStatus().create(result.getActions().get(0)).status(Status.FINISHED));
|
||||
assignDistributionSet(set2.getId(), "4711");
|
||||
|
||||
target = targetManagement.findTargetByControllerIDWithDetails("4711");
|
||||
target = targetManagement.findTargetByControllerIDWithDetails("4711").get();
|
||||
// read data
|
||||
|
||||
assertThat(targetManagement.countTargetByAssignedDistributionSet(set.getId())).as("Target count is wrong")
|
||||
@@ -308,7 +308,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Ensures that repositoy returns null if given controller ID does not exist without exception.")
|
||||
public void findTargetByControllerIDWithDetailsReturnsNullForNonexisting() {
|
||||
assertThat(targetManagement.findTargetByControllerIDWithDetails("dsfsdfsdfsd")).as("Expected as").isNull();
|
||||
assertThat(targetManagement.findTargetByControllerIDWithDetails("dsfsdfsdfsd").isPresent()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -354,7 +354,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
private void checkTargetHasTags(final boolean strict, final Iterable<Target> targets, final TargetTag... tags) {
|
||||
_target: for (final Target tl : targets) {
|
||||
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId());
|
||||
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get();
|
||||
|
||||
for (final Tag tt : t.getTags()) {
|
||||
for (final Tag tag : tags) {
|
||||
@@ -372,7 +372,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private void checkTargetHasNotTags(final Iterable<Target> targets, final TargetTag... tags) {
|
||||
for (final Target tl : targets) {
|
||||
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId());
|
||||
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get();
|
||||
|
||||
for (final Tag tag : tags) {
|
||||
for (final Tag tt : t.getTags()) {
|
||||
@@ -412,7 +412,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
modifiedAt = savedTarget.getLastModifiedAt();
|
||||
|
||||
final Target foundTarget = targetManagement.findTargetByControllerID(savedTarget.getControllerId());
|
||||
final Target foundTarget = targetManagement.findTargetByControllerID(savedTarget.getControllerId()).get();
|
||||
assertNotNull("The target should not be null", foundTarget);
|
||||
assertThat(myCtrlID).as("ControllerId compared with saved controllerId")
|
||||
.isEqualTo(foundTarget.getControllerId());
|
||||
@@ -506,12 +506,12 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<TargetTag> t2Tags = testdataFactory.createTargetTags(noT2Tags, "tag2");
|
||||
t2Tags.forEach(tag -> targetManagement.assignTag(Lists.newArrayList(t2.getControllerId()), tag.getId()));
|
||||
|
||||
final Target t11 = targetManagement.findTargetByControllerID(t1.getControllerId());
|
||||
final Target t11 = targetManagement.findTargetByControllerID(t1.getControllerId()).get();
|
||||
assertThat(t11.getTags()).as("Tag size is wrong").hasSize(noT1Tags).containsAll(t1Tags);
|
||||
assertThat(t11.getTags()).as("Tag size is wrong").hasSize(noT1Tags)
|
||||
.doesNotContain(Iterables.toArray(t2Tags, TargetTag.class));
|
||||
|
||||
final Target t21 = targetManagement.findTargetByControllerID(t2.getControllerId());
|
||||
final Target t21 = targetManagement.findTargetByControllerID(t2.getControllerId()).get();
|
||||
assertThat(t21.getTags()).as("Tag size is wrong").hasSize(noT2Tags).containsAll(t2Tags);
|
||||
assertThat(t21.getTags()).as("Tag size is wrong").hasSize(noT2Tags)
|
||||
.doesNotContain(Iterables.toArray(t1Tags, TargetTag.class));
|
||||
@@ -697,7 +697,8 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
controllerManagament.findOrRegisterTargetIfItDoesNotexist(knownTargetControllerId, new URI("http://127.0.0.1"));
|
||||
|
||||
securityRule.runAs(WithSpringAuthorityRule.withUser("bumlux", "READ_TARGET"), () -> {
|
||||
final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId);
|
||||
final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId)
|
||||
.get();
|
||||
assertThat(findTargetByControllerID).isNotNull();
|
||||
assertThat(findTargetByControllerID.getTargetInfo()).isNotNull();
|
||||
assertThat(findTargetByControllerID.getTargetInfo().getPollStatus()).isNotNull();
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.fest.assertions.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Duration;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.autoassign;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -8,12 +8,13 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.event;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.eclipse.hawkbit.repository.event.TenantAwareEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.SoftwareModuleDeletedEvent;
|
||||
@@ -28,7 +29,6 @@ import org.eclipse.hawkbit.repository.jpa.event.RepositoryEntityEventTest.Reposi
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.fest.assertions.api.Assertions;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder;
|
||||
@@ -54,7 +54,8 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final Target targetToBeCreated = testdataFactory.createTarget("targetToBeCreated");
|
||||
|
||||
final Target loadedTarget = targetManagement.findTargetByControllerID(targetToBeCreated.getControllerId());
|
||||
final Target loadedTarget = targetManagement.findTargetByControllerID(targetToBeCreated.getControllerId())
|
||||
.get();
|
||||
assertThat(postLoadEntityListener.getEntity()).isNotNull();
|
||||
assertThat(postLoadEntityListener.getEntity()).isEqualTo(loadedTarget);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.RolloutGroupFields;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
@@ -39,7 +39,7 @@ public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest {
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
|
||||
rollout = rolloutManagement.findRolloutById(rollout.getId());
|
||||
rollout = rolloutManagement.findRolloutById(rollout.getId()).get();
|
||||
this.rolloutGroupId = rollout.getRolloutGroups().get(0).getId();
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest {
|
||||
final String targetFilterQuery) {
|
||||
return rolloutManagement.createRollout(
|
||||
entityFactory.rollout().create()
|
||||
.set(distributionSetManagement.findDistributionSetById(distributionSetId)).name(name)
|
||||
.set(distributionSetManagement.findDistributionSetById(distributionSetId).get()).name(name)
|
||||
.targetFilterQuery(targetFilterQuery),
|
||||
amountGroups, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.Constants;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TagFields;
|
||||
import org.eclipse.hawkbit.repository.builder.TagCreate;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.specifications;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
|
||||
@@ -8,10 +8,12 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.tenancy;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
@@ -126,7 +128,13 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
final Target createTargetForTenant = createTargetForTenant(controllerAnotherTenant, anotherTenant);
|
||||
|
||||
// ensure target cannot be deleted by 'mytenant'
|
||||
targetManagement.deleteTargets(Lists.newArrayList(createTargetForTenant.getId()));
|
||||
try {
|
||||
targetManagement.deleteTargets(Lists.newArrayList(createTargetForTenant.getId()));
|
||||
fail("mytenant should not have been able to delete target of anotherTenant");
|
||||
} catch (final EntityNotFoundException ex) {
|
||||
// ok
|
||||
}
|
||||
|
||||
Slice<Target> targetsForAnotherTenant = findTargetsForTenant(anotherTenant);
|
||||
assertThat(targetsForAnotherTenant).hasSize(1);
|
||||
|
||||
|
||||
@@ -109,11 +109,6 @@
|
||||
<groupId>io.protostuff</groupId>
|
||||
<artifactId>protostuff-runtime</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easytesting</groupId>
|
||||
<artifactId>fest-assert-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
|
||||
@@ -254,7 +254,7 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
}
|
||||
|
||||
protected Long getOsModule(final DistributionSet ds) {
|
||||
return ds.findFirstModuleByType(osType).getId();
|
||||
return ds.findFirstModuleByType(osType).get().getId();
|
||||
}
|
||||
|
||||
protected Action prepareFinishedUpdate() {
|
||||
@@ -291,7 +291,7 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
// Run here, because Scheduler is disabled during tests
|
||||
rolloutManagement.fillRolloutGroupsWithTargets(rollout.getId());
|
||||
|
||||
return rolloutManagement.findRolloutById(rollout.getId());
|
||||
return rolloutManagement.findRolloutById(rollout.getId()).get();
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
@@ -314,7 +314,7 @@ public class TestdataFactory {
|
||||
|
||||
tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(Arrays.asList(set.getId()), tag.getName()));
|
||||
|
||||
return distributionSetManagement.findDistributionSetById(set.getId());
|
||||
return distributionSetManagement.findDistributionSetById(set.getId()).get();
|
||||
|
||||
}
|
||||
|
||||
@@ -529,7 +529,7 @@ public class TestdataFactory {
|
||||
entityFactory.softwareModule().update(module.getId()).description("Updated " + DEFAULT_DESCRIPTION)));
|
||||
|
||||
// load also lazy stuff
|
||||
return distributionSetManagement.findDistributionSetByIdWithDetails(set.getId());
|
||||
return distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -560,15 +560,9 @@ public class TestdataFactory {
|
||||
* @return persisted {@link DistributionSetType}
|
||||
*/
|
||||
public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName) {
|
||||
final DistributionSetType findDistributionSetTypeByname = distributionSetManagement
|
||||
.findDistributionSetTypeByKey(dsTypeKey);
|
||||
|
||||
if (findDistributionSetTypeByname != null) {
|
||||
return findDistributionSetTypeByname;
|
||||
}
|
||||
|
||||
return distributionSetManagement.createDistributionSetType(entityFactory.distributionSetType().create()
|
||||
.key(dsTypeKey).name(dsTypeName).description(LOREM.words(10)).colour("black"));
|
||||
return distributionSetManagement.findDistributionSetTypeByKey(dsTypeKey)
|
||||
.orElseGet(() -> distributionSetManagement.createDistributionSetType(entityFactory.distributionSetType()
|
||||
.create().key(dsTypeKey).name(dsTypeName).description(LOREM.words(10)).colour("black")));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -588,17 +582,11 @@ public class TestdataFactory {
|
||||
*/
|
||||
public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName,
|
||||
final Collection<SoftwareModuleType> mandatory, final Collection<SoftwareModuleType> optional) {
|
||||
final DistributionSetType findDistributionSetTypeByname = distributionSetManagement
|
||||
.findDistributionSetTypeByKey(dsTypeKey);
|
||||
|
||||
if (findDistributionSetTypeByname != null) {
|
||||
return findDistributionSetTypeByname;
|
||||
}
|
||||
|
||||
return distributionSetManagement.createDistributionSetType(entityFactory.distributionSetType().create()
|
||||
.key(dsTypeKey).name(dsTypeName).description(LOREM.words(10)).colour("black")
|
||||
.optional(optional.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()))
|
||||
.mandatory(mandatory.stream().map(SoftwareModuleType::getId).collect(Collectors.toList())));
|
||||
return distributionSetManagement.findDistributionSetTypeByKey(dsTypeKey)
|
||||
.orElseGet(() -> distributionSetManagement.createDistributionSetType(entityFactory.distributionSetType()
|
||||
.create().key(dsTypeKey).name(dsTypeName).description(LOREM.words(10)).colour("black")
|
||||
.optional(optional.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()))
|
||||
.mandatory(mandatory.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()))));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -627,12 +615,9 @@ public class TestdataFactory {
|
||||
* @return persisted {@link SoftwareModuleType}
|
||||
*/
|
||||
public SoftwareModuleType findOrCreateSoftwareModuleType(final String key, final int maxAssignments) {
|
||||
final SoftwareModuleType findSoftwareModuleTypeByKey = softwareManagement.findSoftwareModuleTypeByKey(key);
|
||||
if (findSoftwareModuleTypeByKey != null) {
|
||||
return findSoftwareModuleTypeByKey;
|
||||
}
|
||||
return softwareManagement.createSoftwareModuleType(entityFactory.softwareModuleType().create().key(key)
|
||||
.name(key).description(LOREM.words(10)).maxAssignments(maxAssignments));
|
||||
return softwareManagement.findSoftwareModuleTypeByKey(key)
|
||||
.orElseGet(() -> softwareManagement.createSoftwareModuleType(entityFactory.softwareModuleType().create()
|
||||
.key(key).name(key).description(LOREM.words(10)).maxAssignments(maxAssignments)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user