Skip to content

Commit

Permalink
Remove unused group repo methods (eclipse-hawkbit#2263)
Browse files Browse the repository at this point in the history
Signed-off-by: Avgustin Marinov <[email protected]>
  • Loading branch information
avgustinmm authored Feb 4, 2025
1 parent 4e59c6c commit 46caed1
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,27 +286,27 @@ Slice<Target> findByFailedRolloutAndNotInRolloutGroups(@NotNull Pageable pageReq
* that are not assigned to one of the {@link RolloutGroup}s and are compatible
* with the passed {@link DistributionSetType}.
*
* @param groups the list of {@link RolloutGroup}s
* @param rsqlParam filter definition in RSQL syntax
* @param groups the list of {@link RolloutGroup}s
* @param distributionSetType type of the {@link DistributionSet} the targets must be compatible
* with
* @return count of the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ)
long countByRsqlAndNotInRolloutGroupsAndCompatibleAndUpdatable(@NotEmpty Collection<Long> groups,
@NotNull String rsqlParam, @NotNull DistributionSetType distributionSetType);
long countByRsqlAndNotInRolloutGroupsAndCompatibleAndUpdatable(@NotNull String rsqlParam, @NotEmpty Collection<Long> groups,
@NotNull DistributionSetType distributionSetType);

/**
* Counts all targets with failed actions for specific Rollout and that are not
* assigned to one of the {@link RolloutGroup}s and are compatible with the
* passed {@link DistributionSetType}.
*
* @param groups the list of {@link RolloutGroup}s
* @param rolloutId rolloutId of the rollout to be retried.
* @param groups the list of {@link RolloutGroup}s
* @return count of the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ)
long countByFailedRolloutAndNotInRolloutGroups(@NotEmpty Collection<Long> groups, @NotNull String rolloutId);
long countByFailedRolloutAndNotInRolloutGroups(@NotNull String rolloutId, @NotEmpty Collection<Long> groups);

/**
* Finds all targets of the provided {@link RolloutGroup} that have no Action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public static void verifyRolloutInStatus(final Rollout rollout, final Rollout.Ro
*/
public static List<Long> getGroupsByStatusIncludingGroup(
final List<RolloutGroup> groups, final RolloutGroup.RolloutGroupStatus status, final RolloutGroup group) {
return groups.stream().filter(innerGroup -> innerGroup.getStatus() == status || innerGroup.equals(group))
return groups.stream()
.filter(innerGroup -> innerGroup.getStatus() == status || innerGroup.equals(group))
.map(RolloutGroup::getId).toList();
}

Expand Down Expand Up @@ -215,8 +216,8 @@ public static void verifyRemainingTargets(final long targetCount) {

public static void checkIfRolloutCanStarted(final Rollout rollout, final Rollout mergedRollout) {
if (Rollout.RolloutStatus.READY != mergedRollout.getStatus()) {
throw new RolloutIllegalStateException("Rollout can only be started in state ready but current state is "
+ rollout.getStatus().name().toLowerCase());
throw new RolloutIllegalStateException("Rollout can only be started in state ready but current state is " +
rollout.getStatus().name().toLowerCase());
}
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,12 @@ public boolean exists(final long rolloutId) {
public void pauseRollout(final long rolloutId) {
final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId);
if (RolloutStatus.RUNNING != rollout.getStatus()) {
throw new RolloutIllegalStateException("Rollout can only be paused in state running but current state is "
+ rollout.getStatus().name().toLowerCase());
}
// setting the complete rollout only in paused state. This is sufficient
// due the currently running groups will be completed and new groups are
// not started until rollout goes back to running state again. The
// periodically check for running rollouts will skip rollouts in pause
// state.
throw new RolloutIllegalStateException("Rollout can only be paused in state running but current state is " +
rollout.getStatus().name().toLowerCase());
}
// setting the complete rollout only in paused state. This is sufficient due the currently running groups will be completed and
// new groups are not started until rollout goes back to running state again. The periodically check for running rollouts will skip
// rollouts in pause state.
rollout.setStatus(RolloutStatus.PAUSED);
rolloutRepository.save(rollout);
}
Expand All @@ -355,8 +353,8 @@ public void pauseRollout(final long rolloutId) {
public void resumeRollout(final long rolloutId) {
final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId);
if (RolloutStatus.PAUSED != rollout.getStatus()) {
throw new RolloutIllegalStateException("Rollout can only be resumed in state paused but current state is "
+ rollout.getStatus().name().toLowerCase());
throw new RolloutIllegalStateException("Rollout can only be resumed in state paused but current state is " +
rollout.getStatus().name().toLowerCase());
}
rollout.setStatus(RolloutStatus.RUNNING);
rolloutRepository.save(rollout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ public Slice<Target> findByFailedRolloutAndNotInRolloutGroups(Pageable pageReque
}

@Override
public long countByRsqlAndNotInRolloutGroupsAndCompatibleAndUpdatable(final Collection<Long> groups,
final String targetFilterQuery, final DistributionSetType dsType) {
public long countByRsqlAndNotInRolloutGroupsAndCompatibleAndUpdatable(final String targetFilterQuery, final Collection<Long> groups,
final DistributionSetType dsType) {
return targetRepository.count(AccessController.Operation.UPDATE,
combineWithAnd(List.of(
RSQLUtility.buildRsqlSpecification(targetFilterQuery, TargetFields.class,
Expand All @@ -349,7 +349,7 @@ public long countByRsqlAndNotInRolloutGroupsAndCompatibleAndUpdatable(final Coll
}

@Override
public long countByFailedRolloutAndNotInRolloutGroups(Collection<Long> groups, String rolloutId) {
public long countByFailedRolloutAndNotInRolloutGroups(String rolloutId, Collection<Long> groups) {
final List<Specification<JpaTarget>> specList = Arrays.asList(
TargetSpecifications.failedActionsForRollout(rolloutId),
TargetSpecifications.isNotInRolloutGroups(groups));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,18 @@
* The repository interface for the {@link RolloutGroup} model.
*/
@Transactional(readOnly = true)
public interface RolloutGroupRepository
extends BaseEntityRepository<JpaRolloutGroup> {
public interface RolloutGroupRepository extends BaseEntityRepository<JpaRolloutGroup> {

/**
* Retrieves all {@link RolloutGroup} referring a specific rollout in the
* order of creating them. ID ASC.
* Retrieves all {@link RolloutGroup} referring a specific rollout in the order of creating them. ID ASC.
*
* @param rollout the rollout the rolloutgroups belong to
* @return the rollout groups belonging to a rollout ordered by ID ASC.
*/
List<JpaRolloutGroup> findByRolloutOrderByIdAsc(JpaRollout rollout);

/**
* Retrieves all {@link RolloutGroup} referring a specific rollout in a
* specific {@link RolloutGroupStatus}.
* Retrieves all {@link RolloutGroup} referring a specific rollout in a specific {@link RolloutGroupStatus}.
*
* @param rollout the rollout the rolloutgroup belong to
* @param status the status of the rollout groups
Expand All @@ -51,54 +48,17 @@ public interface RolloutGroupRepository
List<JpaRolloutGroup> findByRolloutAndStatus(Rollout rollout, RolloutGroupStatus status);

/**
* Counts all {@link RolloutGroup} referring a specific rollout in specific
* {@link RolloutGroupStatus}s. An in-clause statement does not work with
* the spring-data, so this is specific usecase regarding to the
* rollout-management to find out rolloutgroups which are in specific
* states.
*
* @param rolloutId the ID of the rollout the rolloutgroup belong to
* @param rolloutGroupStatus1 the status of the rollout groups
* @param rolloutGroupStatus2 the status of the rollout groups
* @return the count of rollout groups belonging to a rollout in specific
* status
*/
@Query("SELECT COUNT(r.id) FROM JpaRolloutGroup r WHERE r.rollout.id = :rolloutId and (r.status = :status1 or r.status = :status2)")
Long countByRolloutIdAndStatusOrStatus(@Param("rolloutId") long rolloutId,
@Param("status1") RolloutGroupStatus rolloutGroupStatus1,
@Param("status2") RolloutGroupStatus rolloutGroupStatus2);

/**
* Counts all rollout-groups refering to a given {@link Rollout} by its ID
* and groups which not having the given status.
*
* @param rolloutId the ID of the rollout refering the groups
* @param status1 the status which the groups should not have
* @param status2 the status which the groups should not have
* @param status2 the status which the groups should not have
* @return count of rollout-groups referning a rollout and not in the given
* states
*/
long countByRolloutIdAndStatusNotAndStatusNotAndStatusNot(@Param("rolloutId") long rolloutId,
@Param("status1") RolloutGroup.RolloutGroupStatus status1,
@Param("status2") RolloutGroup.RolloutGroupStatus status2,
@Param("status3") RolloutGroup.RolloutGroupStatus status3);

/**
* Retrieves all {@link RolloutGroup} for a specific parent in a specific
* status. Retrieves the child rolloutgroup for a specific status.
* Retrieves all {@link RolloutGroup} for a specific parent in a specific status. Retrieves the child rolloutgroup for a specific status.
*
* @param rolloutGroupId the rolloutgroupId to find the parents
* @param status the status of the rolloutgroups
* @return The child {@link RolloutGroup}s in a specific status
*/
@Query("SELECT g FROM JpaRolloutGroup g WHERE g.parent.id=:rolloutGroupId and g.status=:status")
List<JpaRolloutGroup> findByParentIdAndStatus(@Param("rolloutGroupId") long rolloutGroupId,
@Param("status") RolloutGroupStatus status);
List<JpaRolloutGroup> findByParentIdAndStatus(@Param("rolloutGroupId") long rolloutGroupId, @Param("status") RolloutGroupStatus status);

/**
* Updates all {@link RolloutGroup#getStatus()} of children for given
* parent.
* Updates all {@link RolloutGroup#getStatus()} of children for given parent.
*
* @param parent the parent rolloutgroup
* @param status the status of the rolloutgroups
Expand All @@ -109,24 +69,11 @@ List<JpaRolloutGroup> findByParentIdAndStatus(@Param("rolloutGroupId") long roll
void setStatusForChildren(@Param("status") RolloutGroupStatus status, @Param("parent") RolloutGroup parent);

/**
* Retrieves all {@link RolloutGroup} for a specific rollout and status not
* having ordered by ID DESC, latest top.
*
* @param rollout the rollout the rolloutgroup belong to
* @param notStatus the status which the rolloutgroup should not have
* @return rolloutgroup referring to a rollout and not having a specific
* status ordered by ID DESC.
*/
List<JpaRolloutGroup> findByRolloutAndStatusNotOrderByIdDesc(JpaRollout rollout, RolloutGroupStatus notStatus);

/**
* Retrieves all {@link RolloutGroup}s for a specific rollout and status not
* having.
* Retrieves all {@link RolloutGroup}s for a specific rollout and status not having.
*
* @param rollout the rollout the rolloutgroup belong to
* @param status the status which the rolloutgroup should not have
* @return rolloutgroup referring to a rollout and not having a specific
* status.
* @return rolloutgroup referring to a rollout and not having a specific status.
*/
List<JpaRolloutGroup> findByRolloutAndStatusNotIn(JpaRollout rollout, Collection<RolloutGroupStatus> status);

Expand All @@ -147,7 +94,19 @@ List<JpaRolloutGroup> findByParentIdAndStatus(@Param("rolloutGroupId") long roll
*/
long countByRolloutId(Long rolloutId);

@Modifying
@Query("DELETE FROM JpaRolloutGroup g where g.id in :rolloutGroupIds")
void deleteByIds(@Param("rolloutGroupIds") List<Long> rolloutGroups);
}
/**
* Counts all {@link RolloutGroup} referring a specific rollout in specific {@link RolloutGroupStatus}s. An in-clause statement
* does not work with the spring-data, so this is specific usecase regarding the rollout-management to find out rolloutgroups which are
* in specific states.
*
* @param rolloutId the ID of the rollout the rolloutgroup belong to
* @param rolloutGroupStatus1 the status of the rollout groups
* @param rolloutGroupStatus2 the status of the rollout groups
* @return the count of rollout groups belonging to a rollout in specific status
*/
@Query("SELECT COUNT(r.id) FROM JpaRolloutGroup r WHERE r.rollout.id = :rolloutId and (r.status = :status1 or r.status = :status2)")
Long countByRolloutIdAndStatusOrStatus(
@Param("rolloutId") long rolloutId,
@Param("status1") RolloutGroupStatus rolloutGroupStatus1,
@Param("status2") RolloutGroupStatus rolloutGroupStatus2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void countByActionsInRolloutGroupPermissionsCheck() {
@Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")
void countByRsqlAndNotInRolloutGroupsAndCompatibleAndUpdatablePermissionsCheck() {
assertPermissions(() -> targetManagement.countByRsqlAndNotInRolloutGroupsAndCompatibleAndUpdatable(List.of(1L), "controllerId==id",
assertPermissions(() -> targetManagement.countByRsqlAndNotInRolloutGroupsAndCompatibleAndUpdatable("controllerId==id", List.of(1L),
entityFactory.distributionSetType().create().build()), List.of(SpPermission.READ_TARGET, SpPermission.READ_ROLLOUT));
}

Expand All @@ -177,7 +177,7 @@ void findByFailedRolloutAndNotInRolloutGroupsPermissionsCheck() {
@Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")
void countByFailedRolloutAndNotInRolloutGroupsPermissionsCheck() {
assertPermissions(() -> targetManagement.countByFailedRolloutAndNotInRolloutGroups(List.of(1L), "1"),
assertPermissions(() -> targetManagement.countByFailedRolloutAndNotInRolloutGroups("1", List.of(1L)),
List.of(SpPermission.READ_TARGET, SpPermission.READ_ROLLOUT));
}

Expand Down
3 changes: 2 additions & 1 deletion hawkbit-simple-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
frontend
bundles
bundles
package-lock.json

0 comments on commit 46caed1

Please sign in to comment.