Remove unused TargetWithActionStatus and its retrieval methods (#2142)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-12-11 14:14:35 +02:00
committed by GitHub
parent d8c8e80125
commit b6fa00cc3e
13 changed files with 114 additions and 413 deletions

View File

@@ -220,16 +220,16 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
final Page<RolloutGroup> rolloutGroups; final Page<RolloutGroup> rolloutGroups;
if (rsqlParam != null) { if (rsqlParam != null) {
if (isFullMode) { if (isFullMode) {
rolloutGroups = this.rolloutGroupManagement.findByRolloutAndRsqlWithDetailedStatus(pageable, rolloutGroups = this.rolloutGroupManagement.findByRolloutAndRsqlWithDetailedStatus(rolloutId, rsqlParam, pageable
rolloutId, rsqlParam); );
} else { } else {
rolloutGroups = this.rolloutGroupManagement.findByRolloutAndRsql(pageable, rolloutId, rsqlParam); rolloutGroups = this.rolloutGroupManagement.findByRolloutAndRsql(rolloutId, rsqlParam, pageable);
} }
} else { } else {
if (isFullMode) { if (isFullMode) {
rolloutGroups = this.rolloutGroupManagement.findByRolloutWithDetailedStatus(pageable, rolloutId); rolloutGroups = this.rolloutGroupManagement.findByRolloutWithDetailedStatus(rolloutId, pageable);
} else { } else {
rolloutGroups = this.rolloutGroupManagement.findByRollout(pageable, rolloutId); rolloutGroups = this.rolloutGroupManagement.findByRollout(rolloutId, pageable);
} }
} }
@@ -269,7 +269,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
rolloutGroupTargets = this.rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(pageable, groupId, rolloutGroupTargets = this.rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(pageable, groupId,
rsqlParam); rsqlParam);
} else { } else {
final Page<Target> pageTargets = this.rolloutGroupManagement.findTargetsOfRolloutGroup(pageable, groupId); final Page<Target> pageTargets = this.rolloutGroupManagement.findTargetsOfRolloutGroup(groupId, pageable);
rolloutGroupTargets = pageTargets; rolloutGroupTargets = pageTargets;
} }
final List<MgmtTarget> rest = MgmtTargetMapper.toResponse(rolloutGroupTargets.getContent(), tenantConfigHelper); final List<MgmtTarget> rest = MgmtTargetMapper.toResponse(rolloutGroupTargets.getContent(), tenantConfigHelper);

View File

@@ -136,7 +136,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final DistributionSet dsA = testdataFactory.createDistributionSet(""); final DistributionSet dsA = testdataFactory.createDistributionSet("");
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*"); final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
final RolloutGroup firstRolloutGroup = rolloutGroupManagement final RolloutGroup firstRolloutGroup = rolloutGroupManagement
.findByRollout(PageRequest.of(0, 1), rollout.getId()).getContent().get(0); .findByRollout(rollout.getId(), PageRequest.of(0, 1)).getContent().get(0);
mvc.perform(get(MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING + "/{rolloutId}/deploygroups/{deployGroupId}/targets", mvc.perform(get(MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING + "/{rolloutId}/deploygroups/{deployGroupId}/targets",
rollout.getId(), firstRolloutGroup.getId()).param("offset", "0").param("limit", "2") rollout.getId(), firstRolloutGroup.getId()).param("offset", "0").param("limit", "2")
@@ -485,10 +485,10 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
rolloutHandler.handleAll(); rolloutHandler.handleAll();
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(PAGE, rollout.getId()).getContent(); final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(rollout.getId(), PAGE).getContent();
groups.forEach(group -> { groups.forEach(group -> {
if (!group.isDynamic()) { if (!group.isDynamic()) {
rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE, group.getId()) rolloutGroupManagement.findTargetsOfRolloutGroup(group.getId(), PAGE)
.forEach(target -> deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE) .forEach(target -> deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE)
.forEach(action -> { .forEach(action -> {
deploymentManagement.cancelAction(action.getId()); deploymentManagement.cancelAction(action.getId());
@@ -768,7 +768,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final List<Rollout> content = rolloutManagement.findAll(PAGE, false).getContent(); final List<Rollout> content = rolloutManagement.findAll(PAGE, false).getContent();
assertThat(content).hasSizeGreaterThan(0).allSatisfy(rollout -> { assertThat(content).hasSizeGreaterThan(0).allSatisfy(rollout -> {
assertThat(rolloutGroupManagement.findByRollout(PAGE, rollout.getId())) assertThat(rolloutGroupManagement.findByRollout(rollout.getId(), PAGE))
.describedAs("Confirmation required flag depends on feature active.") .describedAs("Confirmation required flag depends on feature active.")
.allMatch(group -> group.isConfirmationRequired() == confirmationFlowActive); .allMatch(group -> group.isConfirmationRequired() == confirmationFlowActive);
}); });
@@ -805,7 +805,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final List<Rollout> content = rolloutManagement.findAll(PAGE, false).getContent(); final List<Rollout> content = rolloutManagement.findAll(PAGE, false).getContent();
assertThat(content).hasSize(1).allSatisfy(rollout -> { assertThat(content).hasSize(1).allSatisfy(rollout -> {
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(PAGE, rollout.getId()).getContent(); final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(rollout.getId(), PAGE).getContent();
assertThat(groups).hasSize(2).allMatch(group -> { assertThat(groups).hasSize(2).allMatch(group -> {
if (group.getName().equals("Group1")) { if (group.getName().equals("Group1")) {
return group.isConfirmationRequired(); return group.isConfirmationRequired();
@@ -848,7 +848,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final List<Rollout> content = rolloutManagement.findAll(PAGE, false).getContent(); final List<Rollout> content = rolloutManagement.findAll(PAGE, false).getContent();
assertThat(content).hasSize(1).allSatisfy(rollout -> { assertThat(content).hasSize(1).allSatisfy(rollout -> {
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(PAGE, rollout.getId()).getContent(); final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(rollout.getId(), PAGE).getContent();
assertThat(groups).hasSize(2).allMatch(group -> { assertThat(groups).hasSize(2).allMatch(group -> {
if (group.getName().equals("Group1")) { if (group.getName().equals("Group1")) {
return !group.isConfirmationRequired(); return !group.isConfirmationRequired();
@@ -1026,7 +1026,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
rolloutHandler.handleAll(); rolloutHandler.handleAll();
final RolloutGroup firstGroup = rolloutGroupManagement final RolloutGroup firstGroup = rolloutGroupManagement
.findByRollout(PageRequest.of(0, 1, Direction.ASC, "id"), rollout1.getId()).getContent().get(0); .findByRollout(rollout1.getId(), PageRequest.of(0, 1, Direction.ASC, "id")).getContent().get(0);
// make request for firstGroupId and the rolloutId of the second rollout (the one with no groups) // make request for firstGroupId and the rolloutId of the second rollout (the one with no groups)
mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout2.getId(), firstGroup.getId()) mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout2.getId(), firstGroup.getId())
@@ -1240,9 +1240,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build()); .successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
final RolloutGroup firstGroup = rolloutGroupManagement final RolloutGroup firstGroup = rolloutGroupManagement
.findByRollout(PageRequest.of(0, 1, Direction.ASC, "id"), rollout.getId()).getContent().get(0); .findByRollout(rollout.getId(), PageRequest.of(0, 1, Direction.ASC, "id")).getContent().get(0);
final RolloutGroup secondGroup = rolloutGroupManagement final RolloutGroup secondGroup = rolloutGroupManagement
.findByRollout(PageRequest.of(1, 1, Direction.ASC, "id"), rollout.getId()).getContent().get(0); .findByRollout(rollout.getId(), PageRequest.of(1, 1, Direction.ASC, "id")).getContent().get(0);
retrieveAndVerifyRolloutGroupInCreating(rollout, firstGroup); retrieveAndVerifyRolloutGroupInCreating(rollout, firstGroup);
retrieveAndVerifyRolloutGroupInReady(rollout, firstGroup); retrieveAndVerifyRolloutGroupInReady(rollout, firstGroup);
@@ -1262,7 +1262,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*"); final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
final RolloutGroup firstGroup = rolloutGroupManagement final RolloutGroup firstGroup = rolloutGroupManagement
.findByRollout(PageRequest.of(0, 1, Direction.ASC, "id"), rollout.getId()).getContent().get(0); .findByRollout(rollout.getId(), PageRequest.of(0, 1, Direction.ASC, "id")).getContent().get(0);
// retrieve targets from the first rollout group with known ID // retrieve targets from the first rollout group with known ID
mvc.perform( mvc.perform(
@@ -1287,9 +1287,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*"); final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
final RolloutGroup firstGroup = rolloutGroupManagement final RolloutGroup firstGroup = rolloutGroupManagement
.findByRollout(PageRequest.of(0, 1, Direction.ASC, "id"), rollout.getId()).getContent().get(0); .findByRollout(rollout.getId(), PageRequest.of(0, 1, Direction.ASC, "id")).getContent().get(0);
final String targetInGroup = rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE, firstGroup.getId()) final String targetInGroup = rolloutGroupManagement.findTargetsOfRolloutGroup(firstGroup.getId(), PAGE)
.getContent().get(0).getControllerId(); .getContent().get(0).getControllerId();
// retrieve targets from the first rollout group with known ID // retrieve targets from the first rollout group with known ID
@@ -1320,7 +1320,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
rolloutHandler.handleAll(); rolloutHandler.handleAll();
final RolloutGroup firstGroup = rolloutGroupManagement final RolloutGroup firstGroup = rolloutGroupManagement
.findByRollout(PageRequest.of(0, 1, Direction.ASC, "id"), rollout.getId()).getContent().get(0); .findByRollout(rollout.getId(), PageRequest.of(0, 1, Direction.ASC, "id")).getContent().get(0);
// retrieve targets from the first rollout group with known ID // retrieve targets from the first rollout group with known ID
mvc.perform( mvc.perform(
@@ -1573,7 +1573,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()); .andExpect(status().isOk());
final List<RolloutGroupStatus> groupStatus = rolloutGroupManagement.findByRollout(PAGE, rollout.getId()) final List<RolloutGroupStatus> groupStatus = rolloutGroupManagement.findByRollout(rollout.getId(), PAGE)
.getContent().stream().map(RolloutGroup::getStatus).collect(Collectors.toList()); .getContent().stream().map(RolloutGroup::getStatus).collect(Collectors.toList());
assertThat(groupStatus).containsExactly(RolloutGroupStatus.RUNNING, RolloutGroupStatus.RUNNING, assertThat(groupStatus).containsExactly(RolloutGroupStatus.RUNNING, RolloutGroupStatus.RUNNING,
RolloutGroupStatus.SCHEDULED, RolloutGroupStatus.SCHEDULED); RolloutGroupStatus.SCHEDULED, RolloutGroupStatus.SCHEDULED);

View File

@@ -20,7 +20,6 @@ import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldExc
import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetWithActionStatus;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
@@ -31,94 +30,67 @@ import org.springframework.security.access.prepost.PreAuthorize;
public interface RolloutGroupManagement { public interface RolloutGroupManagement {
/** /**
* Retrieves a page of {@link RolloutGroup}s filtered by a given * Retrieves a page of {@link RolloutGroup}s filtered by a given {@link Rollout} with the detailed status.
* {@link Rollout} with the detailed status.
* *
* @param pageable the page request to sort and limit the result
* @param rolloutId the ID of the rollout to filter the {@link RolloutGroup}s * @param rolloutId the ID of the rollout to filter the {@link RolloutGroup}s
* @param pageable the page request to sort and limit the result
* @return a page of found {@link RolloutGroup}s * @return a page of found {@link RolloutGroup}s
* @throws EntityNotFoundException of rollout with given ID does not exist * @throws EntityNotFoundException of rollout with given ID does not exist
*/ */
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<RolloutGroup> findByRolloutWithDetailedStatus(@NotNull Pageable pageable, long rolloutId); Page<RolloutGroup> findByRolloutWithDetailedStatus(long rolloutId, @NotNull Pageable pageable);
/**
* Find all targets with action status by rollout group id. The action
* status might be {@code null} if for the target within the rollout no
* actions as been created, e.g. the target already had assigned the same
* distribution set we do not create an action for it but the target is in
* the result list of the rollout-group.
*
* @param pageable the page request to sort and limit the result
* @param rolloutGroupId rollout group
* @return {@link TargetWithActionStatus} target with action status
* @throws EntityNotFoundException if rollout group with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ)
Page<TargetWithActionStatus> findAllTargetsOfRolloutGroupWithActionStatus(@NotNull Pageable pageable,
long rolloutGroupId);
/** /**
* Retrieves a single {@link RolloutGroup} by its ID. * Retrieves a single {@link RolloutGroup} by its ID.
* *
* @param rolloutGroupId the ID of the rollout group to find * @param rolloutGroupId the ID of the rollout group to find
* @return the found {@link RolloutGroup} by its ID or {@code null} if it * @return the found {@link RolloutGroup} by its ID or {@code null} if it does not exist
* does not exists
*/ */
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Optional<RolloutGroup> get(long rolloutGroupId); Optional<RolloutGroup> get(long rolloutGroupId);
/** /**
* Retrieves a page of {@link RolloutGroup}s filtered by a given * Retrieves a page of {@link RolloutGroup}s filtered by a given {@link Rollout} and an RSQL filter.
* {@link Rollout} and the an rsql filter.
* *
* @param pageable the page request to sort and limit the result
* @param rolloutId the rollout to filter the {@link RolloutGroup}s * @param rolloutId the rollout to filter the {@link RolloutGroup}s
* @param rsqlParam the specification to filter the result set based on attributes * @param rsqlParam the specification to filter the result set based on attributes of the {@link RolloutGroup}
* of the {@link RolloutGroup} * @param pageable the page request to sort and limit the result
* @return a page of found {@link RolloutGroup}s * @return a page of found {@link RolloutGroup}s
* @throws RSQLParameterUnsupportedFieldException if a field in the RSQL string is used but not provided by the * @throws RSQLParameterUnsupportedFieldException if a field in the RSQL string is used but not provided by the
* given {@code fieldNameProvider} * given {@code fieldNameProvider}
* @throws RSQLParameterSyntaxException if the RSQL syntax is wrong * @throws RSQLParameterSyntaxException if the RSQL syntax is wrong
*/ */
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<RolloutGroup> findByRolloutAndRsql(@NotNull Pageable pageable, long rolloutId, Page<RolloutGroup> findByRolloutAndRsql(long rolloutId, @NotNull String rsqlParam, @NotNull Pageable pageable);
@NotNull String rsqlParam);
/** /**
* Retrieves a page of {@link RolloutGroup}s filtered by a given * Retrieves a page of {@link RolloutGroup}s filtered by a given {@link Rollout} and a rsql filter with detailed status.
* {@link Rollout} and a rsql filter with detailed status.
* *
* @param pageable the page request to sort and limit the result
* @param rolloutId the rollout to filter the {@link RolloutGroup}s * @param rolloutId the rollout to filter the {@link RolloutGroup}s
* @param rsqlParam the specification to filter the result set based on attributes * @param rsqlParam the specification to filter the result set based on attributes of the {@link RolloutGroup}
* of the {@link RolloutGroup} * @param pageable the page request to sort and limit the result
* @return a page of found {@link RolloutGroup}s * @return a page of found {@link RolloutGroup}s
* @throws RSQLParameterUnsupportedFieldException if a field in the RSQL string is used but not provided by the * @throws RSQLParameterUnsupportedFieldException if a field in the RSQL string is used but not provided by the
* given {@code fieldNameProvider} * given {@code fieldNameProvider}
* @throws RSQLParameterSyntaxException if the RSQL syntax is wrong * @throws RSQLParameterSyntaxException if the RSQL syntax is wrong
*/ */
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<RolloutGroup> findByRolloutAndRsqlWithDetailedStatus(@NotNull Pageable pageable, long rolloutId, Page<RolloutGroup> findByRolloutAndRsqlWithDetailedStatus(long rolloutId, @NotNull String rsqlParam, @NotNull Pageable pageable);
@NotNull String rsqlParam);
/** /**
* Retrieves a page of {@link RolloutGroup}s filtered by a given * Retrieves a page of {@link RolloutGroup}s filtered by a given {@link Rollout}.
* {@link Rollout}.
* *
* @param pageable the page request to sort and limit the result
* @param rolloutId the ID of the rollout to filter the {@link RolloutGroup}s * @param rolloutId the ID of the rollout to filter the {@link RolloutGroup}s
* @param pageable the page request to sort and limit the result
* @return a page of found {@link RolloutGroup}s * @return a page of found {@link RolloutGroup}s
*/ */
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<RolloutGroup> findByRollout(@NotNull Pageable pageable, long rolloutId); Page<RolloutGroup> findByRollout(long rolloutId, @NotNull Pageable pageable);
/** /**
* Retrieves a page of {@link RolloutGroup}s filtered by a given * Retrieves a page of {@link RolloutGroup}s filtered by a given {@link Rollout}.
* {@link Rollout}.
* *
* @param rolloutId the ID of the rollout to filter the {@link RolloutGroup}s * @param rolloutId the ID of the rollout to filter the {@link RolloutGroup}s
* @param pageable the page request to sort and limit the result
* @return a page of found {@link RolloutGroup}s * @return a page of found {@link RolloutGroup}s
*/ */
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
@@ -127,13 +99,13 @@ public interface RolloutGroupManagement {
/** /**
* Get targets of specified rollout group. * Get targets of specified rollout group.
* *
* @param pageable the page request to sort and limit the result
* @param rolloutGroupId rollout group * @param rolloutGroupId rollout group
* @param pageable the page request to sort and limit the result
* @return Page<Target> list of targets of a rollout group * @return Page<Target> list of targets of a rollout group
* @throws EntityNotFoundException if group with ID does not exist * @throws EntityNotFoundException if group with ID does not exist
*/ */
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ)
Page<Target> findTargetsOfRolloutGroup(@NotNull Pageable pageable, long rolloutGroupId); Page<Target> findTargetsOfRolloutGroup(long rolloutGroupId, @NotNull Pageable pageable);
/** /**
* Get targets of specified rollout group. * Get targets of specified rollout group.
@@ -151,7 +123,7 @@ public interface RolloutGroupManagement {
@NotNull String rsqlParam); @NotNull String rsqlParam);
/** /**
* Get {@link RolloutGroup} by Id. * Get {@link RolloutGroup} by id.
* *
* @param rolloutGroupId rollout group id * @param rolloutGroupId rollout group id
* @return rolloutGroup with details of targets count for different statuses * @return rolloutGroup with details of targets count for different statuses

View File

@@ -1,47 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.repository.model;
import lombok.Data;
import org.eclipse.hawkbit.repository.Identifiable;
import org.eclipse.hawkbit.repository.model.Action.Status;
/**
* Target with action status.
*/
@Data
public class TargetWithActionStatus implements Identifiable<Long> {
private Target target;
private Status status;
private Integer lastActionStatusCode;
public TargetWithActionStatus(final Target target) {
this.target = target;
}
public TargetWithActionStatus(final Target target, final Status status) {
this.status = status;
this.target = target;
}
public TargetWithActionStatus(final Target target, final Status status, final Integer lastActionStatusCode) {
this.status = status;
this.target = target;
this.lastActionStatusCode = lastActionStatusCode;
}
@Override
public Long getId() {
return target.getId();
}
}

View File

@@ -206,8 +206,8 @@ public class JpaRolloutExecutor implements RolloutExecutor {
log.debug("handleCreateRollout called for rollout {}", rollout.getId()); log.debug("handleCreateRollout called for rollout {}", rollout.getId());
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout( final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(
PageRequest.of(0, quotaManagement.getMaxRolloutGroupsPerRollout(), Sort.by(Direction.ASC, "id")), rollout.getId(), PageRequest.of(0, quotaManagement.getMaxRolloutGroupsPerRollout(), Sort.by(Direction.ASC, "id"))
rollout.getId()).getContent(); ).getContent();
int readyGroups = 0; int readyGroups = 0;
int totalTargets = 0; int totalTargets = 0;

View File

@@ -20,7 +20,6 @@ import jakarta.persistence.EntityManager;
import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.ListJoin; import jakarta.persistence.criteria.ListJoin;
import jakarta.persistence.criteria.Order; import jakarta.persistence.criteria.Order;
import jakarta.persistence.criteria.Predicate; import jakarta.persistence.criteria.Predicate;
@@ -33,7 +32,6 @@ import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper; import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup_; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup_;
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_;
@@ -47,12 +45,10 @@ import org.eclipse.hawkbit.repository.jpa.repository.RolloutRepository;
import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository; import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications; import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus;
import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetWithActionStatus;
import org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus;
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
@@ -106,7 +102,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
} }
@Override @Override
public Page<RolloutGroup> findByRolloutWithDetailedStatus(final Pageable pageable, final long rolloutId) { public Page<RolloutGroup> findByRolloutWithDetailedStatus(final long rolloutId, final Pageable pageable) {
throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId); throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId);
final Page<JpaRolloutGroup> rolloutGroups = rolloutGroupRepository.findByRolloutId(rolloutId, pageable); final Page<JpaRolloutGroup> rolloutGroups = rolloutGroupRepository.findByRolloutId(rolloutId, pageable);
@@ -131,39 +127,13 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
return JpaManagementHelper.convertPage(rolloutGroups, pageable); return JpaManagementHelper.convertPage(rolloutGroups, pageable);
} }
@Override
public Page<TargetWithActionStatus> findAllTargetsOfRolloutGroupWithActionStatus(final Pageable pageRequest, final long rolloutGroupId) {
throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId);
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<Object[]> query = cb.createQuery(Object[].class);
final Root<RolloutTargetGroup> targetRoot = query.distinct(true).from(RolloutTargetGroup.class);
final Join<RolloutTargetGroup, JpaTarget> targetJoin = targetRoot.join(RolloutTargetGroup_.target);
final ListJoin<RolloutTargetGroup, JpaAction> actionJoin = targetRoot.join(RolloutTargetGroup_.actions, JoinType.LEFT);
final CriteriaQuery<Object[]> multiselect = query
.multiselect(targetJoin, actionJoin.get(JpaAction_.status), actionJoin.get(JpaAction_.lastActionStatusCode))
.where(getRolloutGroupTargetWithRolloutGroupJoinCondition(rolloutGroupId, cb, targetRoot))
.orderBy(getOrderBy(pageRequest, cb, targetJoin, actionJoin));
final List<TargetWithActionStatus> targetWithActionStatus = entityManager.createQuery(multiselect)
.setFirstResult((int) pageRequest.getOffset())
.setMaxResults(pageRequest.getPageSize())
.getResultList()
.stream()
.map(this::getTargetWithActionStatusFromQuery)
.toList();
return new PageImpl<>(targetWithActionStatus, pageRequest, 0);
}
@Override @Override
public Optional<RolloutGroup> get(final long rolloutGroupId) { public Optional<RolloutGroup> get(final long rolloutGroupId) {
return rolloutGroupRepository.findById(rolloutGroupId).map(RolloutGroup.class::cast); return rolloutGroupRepository.findById(rolloutGroupId).map(RolloutGroup.class::cast);
} }
@Override @Override
public Page<RolloutGroup> findByRolloutAndRsql(final Pageable pageable, final long rolloutId, public Page<RolloutGroup> findByRolloutAndRsql(final long rolloutId, final String rsqlParam, final Pageable pageable) {
final String rsqlParam) {
throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId); throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId);
final List<Specification<JpaRolloutGroup>> specList = Arrays.asList( final List<Specification<JpaRolloutGroup>> specList = Arrays.asList(
@@ -175,11 +145,10 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
} }
@Override @Override
public Page<RolloutGroup> findByRolloutAndRsqlWithDetailedStatus(final Pageable pageable, final long rolloutId, public Page<RolloutGroup> findByRolloutAndRsqlWithDetailedStatus(final long rolloutId, final String rsqlParam, final Pageable pageable) {
final String rsqlParam) {
throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId); throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId);
final Page<RolloutGroup> rolloutGroups = findByRolloutAndRsql(pageable, rolloutId, rsqlParam); final Page<RolloutGroup> rolloutGroups = findByRolloutAndRsql(rolloutId, rsqlParam, pageable);
final List<Long> rolloutGroupIds = rolloutGroups.getContent().stream().map(RolloutGroup::getId) final List<Long> rolloutGroupIds = rolloutGroups.getContent().stream().map(RolloutGroup::getId)
.collect(Collectors.toList()); .collect(Collectors.toList());
@@ -202,7 +171,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
} }
@Override @Override
public Page<RolloutGroup> findByRollout(final Pageable pageable, final long rolloutId) { public Page<RolloutGroup> findByRollout(final long rolloutId, final Pageable pageable) {
throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId); throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId);
return JpaManagementHelper.convertPage(rolloutGroupRepository.findByRolloutId(rolloutId, pageable), pageable); return JpaManagementHelper.convertPage(rolloutGroupRepository.findByRolloutId(rolloutId, pageable), pageable);
@@ -216,7 +185,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
} }
@Override @Override
public Page<Target> findTargetsOfRolloutGroup(final Pageable page, final long rolloutGroupId) { public Page<Target> findTargetsOfRolloutGroup(final long rolloutGroupId, final Pageable page) {
final JpaRolloutGroup rolloutGroup = rolloutGroupRepository.findById(rolloutGroupId) final JpaRolloutGroup rolloutGroup = rolloutGroupRepository.findById(rolloutGroupId)
.orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, rolloutGroupId)); .orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, rolloutGroupId));
@@ -322,10 +291,6 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
rolloutGroupId); rolloutGroupId);
} }
private TargetWithActionStatus getTargetWithActionStatusFromQuery(final Object[] o) {
return new TargetWithActionStatus((Target) o[0], (Action.Status) o[1], (Integer) o[2]);
}
private List<Order> getOrderBy(final Pageable pageRequest, final CriteriaBuilder cb, private List<Order> getOrderBy(final Pageable pageRequest, final CriteriaBuilder cb,
final Join<RolloutTargetGroup, JpaTarget> targetJoin, final Join<RolloutTargetGroup, JpaTarget> targetJoin,
final ListJoin<RolloutTargetGroup, JpaAction> actionJoin) { final ListJoin<RolloutTargetGroup, JpaAction> actionJoin) {

View File

@@ -88,6 +88,6 @@ public class RolloutGroupEventTest extends AbstractRemoteEntityEventTest<Rollout
false, new RolloutGroupConditionBuilder().withDefaults() false, new RolloutGroupConditionBuilder().withDefaults()
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10").build()); .successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10").build());
return rolloutGroupManagement.findByRollout(PAGE, entity.getId()).getContent().get(0); return rolloutGroupManagement.findByRollout(entity.getId(), PAGE).getContent().get(0);
} }
} }

View File

@@ -72,7 +72,7 @@ public class ConcurrentDistributionSetInvalidationTest extends AbstractJpaIntegr
Awaitility.await().atMost(Duration.ofSeconds(5)) Awaitility.await().atMost(Duration.ofSeconds(5))
.pollInterval(Duration.ofMillis(100)) .pollInterval(Duration.ofMillis(100))
.until(() -> tenantAware.runAsTenant(tenant, () -> systemSecurityContext .until(() -> tenantAware.runAsTenant(tenant, () -> systemSecurityContext
.runAsSystem(() -> rolloutGroupManagement.findByRollout(PAGE, rollout.getId()).getSize() > 0))); .runAsSystem(() -> rolloutGroupManagement.findByRollout(rollout.getId(), PAGE).getSize() > 0)));
assertThatExceptionOfType(StopRolloutException.class) assertThatExceptionOfType(StopRolloutException.class)
.as("Invalidation of distributionSet should throw an exception") .as("Invalidation of distributionSet should throw an exception")

View File

@@ -317,12 +317,12 @@ class TargetAccessControllerTest extends AbstractAccessControllerTest {
assertThat(rollout.getTotalTargets()).isEqualTo(updateTargets.size()); assertThat(rollout.getTotalTargets()).isEqualTo(updateTargets.size());
final List<RolloutGroup> content = rolloutGroupManagement.findByRollout(Pageable.unpaged(), rollout.getId()) final List<RolloutGroup> content = rolloutGroupManagement.findByRollout(rollout.getId(), Pageable.unpaged())
.getContent(); .getContent();
assertThat(content).hasSize(updateTargets.size()); assertThat(content).hasSize(updateTargets.size());
final List<Target> rolloutTargets = content.stream().flatMap( final List<Target> rolloutTargets = content.stream().flatMap(
group -> rolloutGroupManagement.findTargetsOfRolloutGroup(Pageable.unpaged(), group.getId()).get()) group -> rolloutGroupManagement.findTargetsOfRolloutGroup(group.getId(), Pageable.unpaged()).get())
.toList(); .toList();
assertThat(rolloutTargets).hasSize(updateTargets.size()).allMatch( assertThat(rolloutTargets).hasSize(updateTargets.size()).allMatch(

View File

@@ -11,8 +11,6 @@ package org.eclipse.hawkbit.repository.jpa.management;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import io.qameta.allure.Description; import io.qameta.allure.Description;
import io.qameta.allure.Feature; import io.qameta.allure.Feature;
import io.qameta.allure.Story; import io.qameta.allure.Story;
@@ -28,19 +26,10 @@ import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleUpdatedE
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetWithActionStatus;
import org.eclipse.hawkbit.repository.test.matcher.Expect; import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents; import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.util.CollectionUtils;
@Feature("Component Tests - Repository") @Feature("Component Tests - Repository")
@Story("Rollout Management") @Story("Rollout Management")
@@ -74,140 +63,13 @@ class RolloutGroupManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> rolloutGroupManagement.countByRollout(NOT_EXIST_IDL), "Rollout"); verifyThrownExceptionBy(() -> rolloutGroupManagement.countByRollout(NOT_EXIST_IDL), "Rollout");
verifyThrownExceptionBy(() -> rolloutGroupManagement.countTargetsOfRolloutsGroup(NOT_EXIST_IDL), "RolloutGroup"); verifyThrownExceptionBy(() -> rolloutGroupManagement.countTargetsOfRolloutsGroup(NOT_EXIST_IDL), "RolloutGroup");
verifyThrownExceptionBy(() -> rolloutGroupManagement.findByRolloutWithDetailedStatus(PAGE, NOT_EXIST_IDL), "Rollout"); verifyThrownExceptionBy(() -> rolloutGroupManagement.findByRolloutWithDetailedStatus(NOT_EXIST_IDL, PAGE), "Rollout");
verifyThrownExceptionBy(() -> rolloutGroupManagement.findAllTargetsOfRolloutGroupWithActionStatus(PAGE, NOT_EXIST_IDL), "RolloutGroup"); verifyThrownExceptionBy(() -> rolloutGroupManagement.findByRolloutAndRsql(NOT_EXIST_IDL, "name==*", PAGE), "Rollout");
verifyThrownExceptionBy(() -> rolloutGroupManagement.findByRolloutAndRsql(PAGE, NOT_EXIST_IDL, "name==*"), "Rollout");
verifyThrownExceptionBy(() -> rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE, NOT_EXIST_IDL), "RolloutGroup"); verifyThrownExceptionBy(() -> rolloutGroupManagement.findTargetsOfRolloutGroup(NOT_EXIST_IDL, PAGE), "RolloutGroup");
verifyThrownExceptionBy(() -> rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(PAGE, NOT_EXIST_IDL, "name==*"), "RolloutGroup"); verifyThrownExceptionBy(() -> rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(PAGE, NOT_EXIST_IDL, "name==*"), "RolloutGroup");
} }
@Test
@Description("Verifies that the returned result considers the provided sort parameters.")
void findAllTargetsOfRolloutGroupWithActionStatusConsidersSorting() {
final Rollout rollout = testdataFactory.createAndStartRollout();
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(PAGE, rollout.getId())
.getContent();
final RolloutGroup rolloutGroup = rolloutGroups.get(0);
rolloutManagement.pauseRollout(rollout.getId());
rolloutHandler.handleAll();
final List<Target> targets = rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE, rolloutGroup.getId())
.getContent();
Target targetCancelled = targets.get(0);
final Action actionCancelled = deploymentManagement.findActionsByTarget(targetCancelled.getControllerId(), PAGE)
.getContent().get(0);
deploymentManagement.cancelAction(actionCancelled.getId());
deploymentManagement.forceQuitAction(actionCancelled.getId());
targetCancelled = reloadTarget(targetCancelled);
Target targetCancelling = targets.get(1);
final Action actionCancelling = deploymentManagement
.findActionsByTarget(targetCancelling.getControllerId(), PAGE).getContent().get(0);
deploymentManagement.cancelAction(actionCancelling.getId());
targetCancelling = reloadTarget(targetCancelling);
final List<TargetWithActionStatus> targetsWithActionStatus = rolloutGroupManagement
.findAllTargetsOfRolloutGroupWithActionStatus(PageRequest.of(0, 500, Sort.by(Direction.DESC, "status")),
rolloutGroup.getId())
.getContent();
assertThat(targetsWithActionStatus.get(0).getTarget()).isEqualTo(targetCancelling);
assertThat(targetsWithActionStatus.get(1).getTarget()).isEqualTo(targetCancelled);
final List<TargetWithActionStatus> targetsWithActionStatusOrderedByNameDesc = rolloutGroupManagement
.findAllTargetsOfRolloutGroupWithActionStatus(PageRequest.of(0, 500, Sort.by(Direction.DESC, "name")),
rolloutGroup.getId())
.getContent();
assertThatListIsSortedByTargetName(targetsWithActionStatusOrderedByNameDesc, Direction.DESC);
final List<TargetWithActionStatus> targetsWithActionStatusOrderedByNameAsc = rolloutGroupManagement
.findAllTargetsOfRolloutGroupWithActionStatus(PageRequest.of(0, 500, Sort.by(Direction.ASC, "name")),
rolloutGroup.getId())
.getContent();
assertThatListIsSortedByTargetName(targetsWithActionStatusOrderedByNameAsc, Direction.ASC);
}
@Test
@Description("Verifies that the returned result considers sorting by action status code.")
void findAllTargetsOfRolloutGroupWithActionStatusConsidersSortingByLastActionStatusCode() {
final Rollout rollout = testdataFactory.createAndStartRollout();
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(PAGE, rollout.getId())
.getContent();
final RolloutGroup rolloutGroup = rolloutGroups.get(0);
final List<Action> runningActions = findActionsByRolloutAndStatus(rollout, Status.RUNNING);
final Target target0 = runningActions.get(0).getTarget();
final Target target24 = CollectionUtils.lastElement(runningActions).getTarget();
int i = 0;
for (final Action action : runningActions) {
controllerManagement.addUpdateActionStatus(
entityFactory.actionStatus().create(action.getId()).status(Status.RUNNING).code(i++));
}
List<TargetWithActionStatus> targetsWithActionStatus = rolloutGroupManagement
.findAllTargetsOfRolloutGroupWithActionStatus(
PageRequest.of(0, 500, Sort.by(Direction.ASC, "lastActionStatusCode")),
rolloutGroup.getId())
.getContent();
assertSortedListOfActionStatus(targetsWithActionStatus, target0, 0, target24, 24);
assertThat(targetsWithActionStatus)
.hasSize((int) rolloutGroupManagement.countTargetsOfRolloutsGroup(rolloutGroup.getId()));
targetsWithActionStatus = rolloutGroupManagement.findAllTargetsOfRolloutGroupWithActionStatus(
PageRequest.of(0, 500, Sort.by(Direction.DESC, "lastActionStatusCode")), rolloutGroup.getId())
.getContent();
assertSortedListOfActionStatus(targetsWithActionStatus, target24, 24, target0, 0);
}
@Test
@Description("Verifies that Rollouts in different states are handled correctly.")
void findAllTargetsOfRolloutGroupWithActionStatus() {
final Rollout rollout = testdataFactory.createRollout();
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(PAGE, rollout.getId()).getContent();
rolloutHandler.handleAll();
// check query when no actions exist
final List<TargetWithActionStatus> targetsWithActionStatus = rolloutGroupManagement
.findAllTargetsOfRolloutGroupWithActionStatus(
PageRequest.of(0, 500, Sort.by(Direction.DESC, "lastActionStatusCode")),
rolloutGroups.get(0).getId())
.getContent();
assertThat(targetsWithActionStatus).hasSize((int) rolloutGroupManagement.countTargetsOfRolloutsGroup(rolloutGroups.get(0).getId()));
assertTargetNotNullAndActionStatusNullAndActionStatusCode(targetsWithActionStatus, null);
rolloutManagement.start(rollout.getId());
rolloutHandler.handleAll();
// check query when no action status code exist
final List<Action> scheduledActions = findActionsByRolloutAndStatus(rollout, Status.SCHEDULED);
final RolloutGroup rolloutGroupScheduled = scheduledActions.get(0).getRolloutGroup();
final List<TargetWithActionStatus> targetsWithActionStatusForScheduledRG = rolloutGroupManagement
.findAllTargetsOfRolloutGroupWithActionStatus(
PageRequest.of(0, 500, Sort.by(Direction.DESC, "lastActionStatusCode")),
rolloutGroupScheduled.getId())
.getContent();
assertThat(targetsWithActionStatusForScheduledRG)
.hasSize((int) rolloutGroupManagement.countTargetsOfRolloutsGroup(rolloutGroupScheduled.getId()));
assertTargetNotNullAndActionStatusAndActionStatusCode(targetsWithActionStatusForScheduledRG,
Status.SCHEDULED, null);
final List<Action> runningActions = findActionsByRolloutAndStatus(rollout, Status.RUNNING);
final RolloutGroup rolloutGroupRunning = runningActions.get(0).getRolloutGroup();
for (final Action action : runningActions) {
controllerManagement.addUpdateActionStatus(
entityFactory.actionStatus().create(action.getId()).status(Status.RUNNING).code(100));
}
// check query when action status code exists
final List<TargetWithActionStatus> targetsWithActionStatusForRunningRG = rolloutGroupManagement
.findAllTargetsOfRolloutGroupWithActionStatus(
PageRequest.of(0, 500, Sort.by(Direction.DESC, "lastActionStatusCode")),
rolloutGroupRunning.getId())
.getContent();
assertThat(targetsWithActionStatusForRunningRG)
.hasSize((int) rolloutGroupManagement.countTargetsOfRolloutsGroup(rolloutGroupRunning.getId()));
assertTargetNotNullAndActionStatusAndActionStatusCode(targetsWithActionStatusForRunningRG,
Status.RUNNING, 100);
}
@Test @Test
@Description("Tests the rollout group status mapping.") @Description("Tests the rollout group status mapping.")
void testRolloutGroupStatusConvert() { void testRolloutGroupStatusConvert() {
@@ -221,55 +83,4 @@ class RolloutGroupManagementTest extends AbstractJpaIntegrationTest {
assertThat(rolloutGroupManagement.get(id).orElseThrow().getStatus()).isEqualTo(status); assertThat(rolloutGroupManagement.get(id).orElseThrow().getStatus()).isEqualTo(status);
} }
} }
private void assertSortedListOfActionStatus(final List<TargetWithActionStatus> targetsWithActionStatus,
final Target first, final Integer firstStatusCode, final Target last, final Integer lastStatusCode) {
assertTargetAndActionStatusCode(CollectionUtils.firstElement(targetsWithActionStatus), first, firstStatusCode);
assertTargetAndActionStatusCode(CollectionUtils.lastElement(targetsWithActionStatus), last, lastStatusCode);
}
private void assertTargetAndActionStatusCode(final TargetWithActionStatus targetWithActionStatus,
final Target target, final Integer actionStatusCode) {
assertThat(targetWithActionStatus.getTarget().getControllerId()).isEqualTo(target.getControllerId());
assertThat(targetWithActionStatus.getLastActionStatusCode()).isEqualTo(actionStatusCode);
}
private void assertTargetNotNullAndActionStatusNullAndActionStatusCode(
final List<TargetWithActionStatus> targetsWithActionStatus, final Integer actionStatusCode) {
targetsWithActionStatus.forEach(targetWithActionStatus -> {
assertThat(targetWithActionStatus.getTarget().getControllerId()).isNotNull();
assertThat(targetWithActionStatus.getStatus()).isNull();
assertThat(targetWithActionStatus.getLastActionStatusCode()).isEqualTo(actionStatusCode);
});
}
private void assertTargetNotNullAndActionStatusAndActionStatusCode(
final List<TargetWithActionStatus> targetsWithActionStatus, final Status actionStatus,
final Integer actionStatusCode) {
targetsWithActionStatus.forEach(targetWithActionStatus -> {
assertThat(targetWithActionStatus.getTarget().getControllerId()).isNotNull();
assertThat(targetWithActionStatus.getStatus()).isEqualTo(actionStatus);
assertThat(targetWithActionStatus.getLastActionStatusCode()).isEqualTo(actionStatusCode);
});
}
private void assertThatListIsSortedByTargetName(final List<TargetWithActionStatus> targets,
final Direction sortDirection) {
String previousName = null;
for (final TargetWithActionStatus targetWithActionStatus : targets) {
final String actualName = targetWithActionStatus.getTarget().getName();
if (previousName != null) {
if (Direction.ASC == sortDirection) {
assertThat(actualName).isGreaterThan(previousName);
} else {
assertThat(actualName).isLessThan(previousName);
}
}
previousName = actualName;
}
}
private Target reloadTarget(final Target targetCancelled) {
return targetManagement.get(targetCancelled.getId()).orElseThrow();
}
} }

View File

@@ -58,8 +58,8 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
final Rollout rollout = testdataFactory.createRolloutByVariables(rolloutName, rolloutName, amountGroups, final Rollout rollout = testdataFactory.createRolloutByVariables(rolloutName, rolloutName, amountGroups,
"controllerid==" + targetPrefix + "*", distributionSet, "60", "30", false, false); "controllerid==" + targetPrefix + "*", distributionSet, "60", "30", false, false);
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout( final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(
new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id")), rollout.getId(), new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id"))
rollout.getId()).getContent(); ).getContent();
// add 2 targets not to be included // add 2 targets not to be included
testdataFactory.createTargets(targetPrefix, amountGroups * 3, 2); testdataFactory.createTargets(targetPrefix, amountGroups * 3, 2);
@@ -101,8 +101,8 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
// rollout is READY // rollout is READY
assertRollout(rollout, true, RolloutStatus.READY, amountGroups + 1, amountGroups * 3); assertRollout(rollout, true, RolloutStatus.READY, amountGroups + 1, amountGroups * 3);
List<RolloutGroup> groups = rolloutGroupManagement.findByRollout( List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(
new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id")), rollout.getId(), new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id"))
rollout.getId()).getContent(); ).getContent();
final RolloutGroup dynamic1 = groups.get(amountGroups); final RolloutGroup dynamic1 = groups.get(amountGroups);
assertRollout(rollout, true, RolloutStatus.READY, amountGroups + 1, amountGroups * 3); // + dynamic assertRollout(rollout, true, RolloutStatus.READY, amountGroups + 1, amountGroups * 3); // + dynamic
for (int i = 0; i < amountGroups; i++) { for (int i = 0; i < amountGroups; i++) {
@@ -137,8 +137,8 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
assertRollout(rollout, true, RolloutStatus.RUNNING, amountGroups + 2, amountGroups * 3 + 3); assertRollout(rollout, true, RolloutStatus.RUNNING, amountGroups + 2, amountGroups * 3 + 3);
assertGroup(dynamic1, true, RolloutGroupStatus.RUNNING, 3); assertGroup(dynamic1, true, RolloutGroupStatus.RUNNING, 3);
groups = rolloutGroupManagement.findByRollout( groups = rolloutGroupManagement.findByRollout(
new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id")), rollout.getId(), new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id"))
rollout.getId()).getContent(); ).getContent();
final RolloutGroup dynamic2 = groups.get(amountGroups + 1); final RolloutGroup dynamic2 = groups.get(amountGroups + 1);
assertGroup(dynamic2, true, RolloutGroupStatus.SCHEDULED, 0); assertGroup(dynamic2, true, RolloutGroupStatus.SCHEDULED, 0);
@@ -190,8 +190,8 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
// create third dynamic group // create third dynamic group
rolloutHandler.handleAll(); rolloutHandler.handleAll();
assertThat(rolloutGroupManagement.findByRollout( assertThat(rolloutGroupManagement.findByRollout(
new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id")), rollout.getId(), new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id"))
rollout.getId()).getContent().size()).isEqualTo(amountGroups + 3); ).getContent().size()).isEqualTo(amountGroups + 3);
executeAllFromGroup(rollout, dynamic1, 1); executeAllFromGroup(rollout, dynamic1, 1);
executeAllFromGroup(rollout, dynamic2, 3); executeAllFromGroup(rollout, dynamic2, 3);
assertAndGetRunning(rollout, 0); assertAndGetRunning(rollout, 0);
@@ -218,8 +218,8 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
// rollout is READY, amountGroups + 1 (dynamic) rollout groups and amountGroups * 3 targets in static groups // rollout is READY, amountGroups + 1 (dynamic) rollout groups and amountGroups * 3 targets in static groups
assertRollout(rollout, true, RolloutStatus.READY, amountGroups + 1, amountGroups * 3); assertRollout(rollout, true, RolloutStatus.READY, amountGroups + 1, amountGroups * 3);
List<RolloutGroup> groups = rolloutGroupManagement.findByRollout( List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(
new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id")), rollout.getId(), new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id"))
rollout.getId()).getContent(); ).getContent();
final RolloutGroup dynamic1 = groups.get(amountGroups); final RolloutGroup dynamic1 = groups.get(amountGroups);
assertRollout(rollout, true, RolloutStatus.READY, amountGroups + 1, amountGroups * 3); // + dynamic assertRollout(rollout, true, RolloutStatus.READY, amountGroups + 1, amountGroups * 3); // + dynamic
for (int i = 0; i < amountGroups; i++) { for (int i = 0; i < amountGroups; i++) {
@@ -254,8 +254,8 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
assertRollout(rollout, true, RolloutStatus.RUNNING, amountGroups + 2, amountGroups * 3 + 6); assertRollout(rollout, true, RolloutStatus.RUNNING, amountGroups + 2, amountGroups * 3 + 6);
assertGroup(dynamic1, true, RolloutGroupStatus.RUNNING, 6); assertGroup(dynamic1, true, RolloutGroupStatus.RUNNING, 6);
groups = rolloutGroupManagement.findByRollout( groups = rolloutGroupManagement.findByRollout(
new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id")), rollout.getId(), new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id"))
rollout.getId()).getContent(); ).getContent();
final RolloutGroup dynamic2 = groups.get(amountGroups + 1); final RolloutGroup dynamic2 = groups.get(amountGroups + 1);
assertGroup(dynamic2, true, RolloutGroupStatus.SCHEDULED, 0); assertGroup(dynamic2, true, RolloutGroupStatus.SCHEDULED, 0);
@@ -313,8 +313,8 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
// rollout is READY, amountGroups + 1 (dynamic) rollout groups and amountGroups * 3 targets in static groups // rollout is READY, amountGroups + 1 (dynamic) rollout groups and amountGroups * 3 targets in static groups
assertRollout(rollout, true, RolloutStatus.READY, 1, 0); assertRollout(rollout, true, RolloutStatus.READY, 1, 0);
List<RolloutGroup> groups = rolloutGroupManagement.findByRollout( List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(
new OffsetBasedPageRequest(0, 10, Sort.by(Direction.ASC, "id")), rollout.getId(), new OffsetBasedPageRequest(0, 10, Sort.by(Direction.ASC, "id"))
rollout.getId()).getContent(); ).getContent();
final RolloutGroup dynamic1 = groups.get(0); final RolloutGroup dynamic1 = groups.get(0);
assertRollout(rollout, true, RolloutStatus.READY, 1, 0); // + dynamic assertRollout(rollout, true, RolloutStatus.READY, 1, 0); // + dynamic
assertGroup(dynamic1, true, RolloutGroupStatus.READY, 0); assertGroup(dynamic1, true, RolloutGroupStatus.READY, 0);
@@ -341,8 +341,8 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
assertRollout(rollout, true, RolloutStatus.RUNNING, 2, 6); assertRollout(rollout, true, RolloutStatus.RUNNING, 2, 6);
assertGroup(dynamic1, true, RolloutGroupStatus.RUNNING, 6); assertGroup(dynamic1, true, RolloutGroupStatus.RUNNING, 6);
groups = rolloutGroupManagement.findByRollout( groups = rolloutGroupManagement.findByRollout(
new OffsetBasedPageRequest(0, 10, Sort.by(Direction.ASC, "id")), rollout.getId(), new OffsetBasedPageRequest(0, 10, Sort.by(Direction.ASC, "id"))
rollout.getId()).getContent(); ).getContent();
final RolloutGroup dynamic2 = groups.get(1); final RolloutGroup dynamic2 = groups.get(1);
assertGroup(dynamic2, true, RolloutGroupStatus.SCHEDULED, 0); assertGroup(dynamic2, true, RolloutGroupStatus.SCHEDULED, 0);
@@ -391,8 +391,8 @@ class RolloutManagementFlowTest extends AbstractJpaIntegrationTest {
final Rollout rollout = testdataFactory.createRolloutByVariables(rolloutName, rolloutName, amountGroups, final Rollout rollout = testdataFactory.createRolloutByVariables(rolloutName, rolloutName, amountGroups,
"controllerid==" + targetPrefix + "*", distributionSet, "0", "25", false, false); "controllerid==" + targetPrefix + "*", distributionSet, "0", "25", false, false);
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout( final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(
new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id")), rollout.getId(), new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id"))
rollout.getId()).getContent(); ).getContent();
// start rollout // start rollout
rolloutManagement.start(rollout.getId()); rolloutManagement.start(rollout.getId());

View File

@@ -124,8 +124,8 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutHandler.handleAll(); rolloutHandler.handleAll();
assertRollout(dynamicRollout, true, RolloutStatus.RUNNING, amountGroups + 1, amountGroups * 2); assertRollout(dynamicRollout, true, RolloutStatus.RUNNING, amountGroups + 1, amountGroups * 2);
final List<RolloutGroup> dynamicGroups = rolloutGroupManagement.findByRollout( final List<RolloutGroup> dynamicGroups = rolloutGroupManagement.findByRollout(
new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id")), dynamicRollout.getId(), new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id"))
dynamicRollout.getId()).getContent(); ).getContent();
for (int i = 0; i < dynamicGroups.size(); i++) { for (int i = 0; i < dynamicGroups.size(); i++) {
final RolloutGroup group = dynamicGroups.get(i); final RolloutGroup group = dynamicGroups.get(i);
if (i + 1 == dynamicGroups.size()) { if (i + 1 == dynamicGroups.size()) {
@@ -159,8 +159,8 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutHandler.handleAll(); rolloutHandler.handleAll();
assertRollout(staticRollout, false, RolloutStatus.RUNNING, amountGroups, amountGroups * 3); assertRollout(staticRollout, false, RolloutStatus.RUNNING, amountGroups, amountGroups * 3);
final List<RolloutGroup> staticGroups = rolloutGroupManagement.findByRollout( final List<RolloutGroup> staticGroups = rolloutGroupManagement.findByRollout(
new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id")), staticRollout.getId(), new OffsetBasedPageRequest(0, amountGroups + 10, Sort.by(Direction.ASC, "id"))
staticRollout.getId()).getContent(); ).getContent();
staticGroups.forEach(group -> assertGroup(group, false, RolloutGroupStatus.RUNNING, 3)); staticGroups.forEach(group -> assertGroup(group, false, RolloutGroupStatus.RUNNING, 3));
rolloutManagement.resumeRollout(dynamicRollout.getId()); rolloutManagement.resumeRollout(dynamicRollout.getId());
@@ -331,7 +331,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
amountOtherTargets, amountGroups, successCondition, errorCondition); amountOtherTargets, amountGroups, successCondition, errorCondition);
// verify the split of the target and targetGroup // verify the split of the target and targetGroup
final Page<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(PAGE, createdRollout.getId()); final Page<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(createdRollout.getId(), PAGE);
// we have total of #amountTargetsForRollout in rollouts split in // we have total of #amountTargetsForRollout in rollouts split in
// group size #groupSize // group size #groupSize
assertThat(rolloutGroups).hasSize(amountGroups); assertThat(rolloutGroups).hasSize(amountGroups);
@@ -351,13 +351,13 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
// verify first group is running // verify first group is running
final RolloutGroup firstGroup = rolloutGroupManagement final RolloutGroup firstGroup = rolloutGroupManagement
.findByRollout(new OffsetBasedPageRequest(0, 1, Sort.by(Direction.ASC, "id")), createdRollout.getId()) .findByRollout(createdRollout.getId(), new OffsetBasedPageRequest(0, 1, Sort.by(Direction.ASC, "id")))
.getContent().get(0); .getContent().get(0);
assertThat(firstGroup.getStatus()).isEqualTo(RolloutGroupStatus.RUNNING); assertThat(firstGroup.getStatus()).isEqualTo(RolloutGroupStatus.RUNNING);
// verify other groups are scheduled // verify other groups are scheduled
final List<RolloutGroup> scheduledGroups = rolloutGroupManagement final List<RolloutGroup> scheduledGroups = rolloutGroupManagement
.findByRollout(new OffsetBasedPageRequest(1, 100, Sort.by(Direction.ASC, "id")), createdRollout.getId()) .findByRollout(createdRollout.getId(), new OffsetBasedPageRequest(1, 100, Sort.by(Direction.ASC, "id")))
.getContent(); .getContent();
scheduledGroups.forEach(group -> assertThat(group.getStatus()) scheduledGroups.forEach(group -> assertThat(group.getStatus())
.as("group which should be in scheduled state is in " + group.getStatus() + " state") .as("group which should be in scheduled state is in " + group.getStatus() + " state")
@@ -398,7 +398,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
// verify that now the first and the second group are in running state // verify that now the first and the second group are in running state
final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement
.findByRollout(new OffsetBasedPageRequest(0, 2, Sort.by(Direction.ASC, "id")), createdRollout.getId()) .findByRollout(createdRollout.getId(), new OffsetBasedPageRequest(0, 2, Sort.by(Direction.ASC, "id")))
.getContent(); .getContent();
runningRolloutGroups.forEach(group -> assertThat(group.getStatus()) runningRolloutGroups.forEach(group -> assertThat(group.getStatus())
.as("group should be in running state because it should be started but it is in " + group.getStatus() .as("group should be in running state because it should be started but it is in " + group.getStatus()
@@ -407,7 +407,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
// verify that the other groups are still in schedule state // verify that the other groups are still in schedule state
final List<RolloutGroup> scheduledRolloutGroups = rolloutGroupManagement final List<RolloutGroup> scheduledRolloutGroups = rolloutGroupManagement
.findByRollout(new OffsetBasedPageRequest(2, 10, Sort.by(Direction.ASC, "id")), createdRollout.getId()) .findByRollout(createdRollout.getId(), new OffsetBasedPageRequest(2, 10, Sort.by(Direction.ASC, "id")))
.getContent(); .getContent();
scheduledRolloutGroups.forEach(group -> assertThat(group.getStatus()) scheduledRolloutGroups.forEach(group -> assertThat(group.getStatus())
.as("group should be in scheduled state because it should not be started but it is in " .as("group should be in scheduled state because it should not be started but it is in "
@@ -470,14 +470,14 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
// the first rollout group should be in error state // the first rollout group should be in error state
final List<RolloutGroup> errorGroup = rolloutGroupManagement final List<RolloutGroup> errorGroup = rolloutGroupManagement
.findByRollout(new OffsetBasedPageRequest(0, 1, Sort.by(Direction.ASC, "id")), createdRollout.getId()) .findByRollout(createdRollout.getId(), new OffsetBasedPageRequest(0, 1, Sort.by(Direction.ASC, "id")))
.getContent(); .getContent();
assertThat(errorGroup).hasSize(1); assertThat(errorGroup).hasSize(1);
assertThat(errorGroup.get(0).getStatus()).isEqualTo(RolloutGroupStatus.ERROR); assertThat(errorGroup.get(0).getStatus()).isEqualTo(RolloutGroupStatus.ERROR);
// all other groups should still be in scheduled state // all other groups should still be in scheduled state
final List<RolloutGroup> scheduleGroups = rolloutGroupManagement final List<RolloutGroup> scheduleGroups = rolloutGroupManagement
.findByRollout(new OffsetBasedPageRequest(1, 100, Sort.by(Direction.ASC, "id")), createdRollout.getId()) .findByRollout(createdRollout.getId(), new OffsetBasedPageRequest(1, 100, Sort.by(Direction.ASC, "id")))
.getContent(); .getContent();
scheduleGroups.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.SCHEDULED)); scheduleGroups.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.SCHEDULED));
} }
@@ -513,7 +513,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
// all other groups should still be in scheduled state // all other groups should still be in scheduled state
final List<RolloutGroup> scheduleGroups = rolloutGroupManagement final List<RolloutGroup> scheduleGroups = rolloutGroupManagement
.findByRollout(new OffsetBasedPageRequest(1, 100, Sort.by(Direction.ASC, "id")), createdRollout.getId()) .findByRollout(createdRollout.getId(), new OffsetBasedPageRequest(1, 100, Sort.by(Direction.ASC, "id")))
.getContent(); .getContent();
scheduleGroups.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.SCHEDULED)); scheduleGroups.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.SCHEDULED));
@@ -528,7 +528,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
// next group should be running again after resuming the rollout // next group should be running again after resuming the rollout
final List<RolloutGroup> resumedGroups = rolloutGroupManagement final List<RolloutGroup> resumedGroups = rolloutGroupManagement
.findByRollout(new OffsetBasedPageRequest(1, 1, Sort.by(Direction.ASC, "id")), createdRollout.getId()) .findByRollout(createdRollout.getId(), new OffsetBasedPageRequest(1, 1, Sort.by(Direction.ASC, "id")))
.getContent(); .getContent();
assertThat(resumedGroups).hasSize(1); assertThat(resumedGroups).hasSize(1);
assertThat(resumedGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING); assertThat(resumedGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING);
@@ -564,7 +564,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
// verify all groups are in finished state // verify all groups are in finished state
rolloutGroupManagement rolloutGroupManagement
.findByRollout(new OffsetBasedPageRequest(0, 100, Sort.by(Direction.ASC, "id")), createdRollout.getId()) .findByRollout(createdRollout.getId(), new OffsetBasedPageRequest(0, 100, Sort.by(Direction.ASC, "id")))
.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.FINISHED)); .forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.FINISHED));
// verify that rollout itself is in finished state // verify that rollout itself is in finished state
@@ -763,7 +763,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
// round(5/2)=3 targets SCHEDULED (Group 3) // round(5/2)=3 targets SCHEDULED (Group 3)
// round(2/1)=2 targets SCHEDULED (Group 4) // round(2/1)=2 targets SCHEDULED (Group 4)
createdRollout = reloadRollout(createdRollout); createdRollout = reloadRollout(createdRollout);
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(PAGE, createdRollout.getId()) final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(createdRollout.getId(), PAGE)
.getContent(); .getContent();
Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap(); Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
@@ -804,10 +804,10 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(runningActions.size()).isEqualTo(5); assertThat(runningActions.size()).isEqualTo(5);
// 5 targets are in the group and the DS has been assigned // 5 targets are in the group and the DS has been assigned
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(PAGE, createdRollout.getId()) final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(createdRollout.getId(), PAGE)
.getContent(); .getContent();
final Page<Target> targets = rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE, final Page<Target> targets = rolloutGroupManagement.findTargetsOfRolloutGroup(rolloutGroups.get(0).getId(), PAGE
rolloutGroups.get(0).getId()); );
final List<Target> targetList = targets.getContent(); final List<Target> targetList = targets.getContent();
assertThat(targetList.size()).isEqualTo(5); assertThat(targetList.size()).isEqualTo(5);
@@ -947,7 +947,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3); changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3);
rolloutHandler.handleAll(); rolloutHandler.handleAll();
// verify: 40% error but 60% finished -> should move to next group // verify: 40% error but 60% finished -> should move to next group
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(PAGE, rolloutOne.getId()) final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(rolloutOne.getId(), PAGE)
.getContent(); .getContent();
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap(); final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 5L); expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 5L);
@@ -974,7 +974,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutHandler.handleAll(); rolloutHandler.handleAll();
// verify: 40% error and 60% finished -> should not move to next group // verify: 40% error and 60% finished -> should not move to next group
// because successCondition 80% // because successCondition 80%
final List<RolloutGroup> rolloutGruops = rolloutGroupManagement.findByRollout(PAGE, rolloutOne.getId()) final List<RolloutGroup> rolloutGruops = rolloutGroupManagement.findByRollout(rolloutOne.getId(), PAGE)
.getContent(); .getContent();
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap(); final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus = createInitStatusMap();
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.SCHEDULED, 5L); expectedTargetCountStatus.put(TotalTargetCountStatus.Status.SCHEDULED, 5L);
@@ -1184,7 +1184,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
float percent = rolloutGroupManagement float percent = rolloutGroupManagement
.getWithDetailedStatus( .getWithDetailedStatus(
rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()).getContent().get(0).getId()) rolloutGroupManagement.findByRollout(myRollout.getId(), PAGE).getContent().get(0).getId())
.get().getTotalTargetCountStatus().getFinishedPercent(); .get().getTotalTargetCountStatus().getFinishedPercent();
assertThat(percent).isEqualTo(40); assertThat(percent).isEqualTo(40);
@@ -1193,7 +1193,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
percent = rolloutGroupManagement percent = rolloutGroupManagement
.getWithDetailedStatus( .getWithDetailedStatus(
rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()).getContent().get(0).getId()) rolloutGroupManagement.findByRollout(myRollout.getId(), PAGE).getContent().get(0).getId())
.get().getTotalTargetCountStatus().getFinishedPercent(); .get().getTotalTargetCountStatus().getFinishedPercent();
assertThat(percent).isEqualTo(100); assertThat(percent).isEqualTo(100);
@@ -1203,7 +1203,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
percent = rolloutGroupManagement percent = rolloutGroupManagement
.getWithDetailedStatus( .getWithDetailedStatus(
rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()).getContent().get(1).getId()) rolloutGroupManagement.findByRollout(myRollout.getId(), PAGE).getContent().get(1).getId())
.get().getTotalTargetCountStatus().getFinishedPercent(); .get().getTotalTargetCountStatus().getFinishedPercent();
assertThat(percent).isEqualTo(80); assertThat(percent).isEqualTo(80);
} }
@@ -1234,7 +1234,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
"Target belongs into rollout"); "Target belongs into rollout");
myRollout = reloadRollout(myRollout); myRollout = reloadRollout(myRollout);
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()) final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(myRollout.getId(), PAGE)
.getContent(); .getContent();
Page<Target> targetPage = rolloutGroupManagement.findTargetsOfRolloutGroupByRsql( Page<Target> targetPage = rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(
@@ -1315,7 +1315,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY); assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
final Long myRolloutId = myRollout.getId(); final Long myRolloutId = myRollout.getId();
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(PAGE, myRolloutId).getContent(); final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(myRolloutId, PAGE).getContent();
assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY); assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY);
assertThat(groups.get(0).getTotalTargets()).isEqualTo(1); assertThat(groups.get(0).getTotalTargets()).isEqualTo(1);
@@ -1522,7 +1522,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
myRollout = getRollout(myRollout.getId()); myRollout = getRollout(myRollout.getId());
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING); assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING);
for (final RolloutGroup group : rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()).getContent()) { for (final RolloutGroup group : rolloutGroupManagement.findByRollout(myRollout.getId(), PAGE).getContent()) {
assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.CREATING); assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.CREATING);
} }
@@ -1537,7 +1537,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY); assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
assertThat(myRollout.getTotalTargets()).isEqualTo(amountTargetsInGroup2and3 + amountTargetsInGroup1); assertThat(myRollout.getTotalTargets()).isEqualTo(amountTargetsInGroup2and3 + amountTargetsInGroup1);
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()).getContent(); final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(myRollout.getId(), PAGE).getContent();
assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY); assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY);
assertThat(groups.get(0).getTotalTargets()).isEqualTo(amountTargetsInGroup1); assertThat(groups.get(0).getTotalTargets()).isEqualTo(amountTargetsInGroup1);
@@ -1576,7 +1576,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(getRollout(rolloutId)).satisfies(rollout -> { assertThat(getRollout(rolloutId)).satisfies(rollout -> {
assertThat(rollout.getStatus()).isEqualTo(RolloutStatus.CREATING); assertThat(rollout.getStatus()).isEqualTo(RolloutStatus.CREATING);
for (final RolloutGroup group : rolloutGroupManagement.findByRollout(PAGE, rollout.getId()).getContent()) { for (final RolloutGroup group : rolloutGroupManagement.findByRollout(rollout.getId(), PAGE).getContent()) {
assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.CREATING); assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.CREATING);
} }
}); });
@@ -1590,7 +1590,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
}); });
// verify created rollout groups // verify created rollout groups
final List<Long> rolloutGroupIds = rolloutGroupManagement.findByRollout(PAGE, rolloutId).getContent().stream() final List<Long> rolloutGroupIds = rolloutGroupManagement.findByRollout(rolloutId, PAGE).getContent().stream()
.map(Identifiable::getId).collect(Collectors.toList()); .map(Identifiable::getId).collect(Collectors.toList());
assertThat(rolloutGroupIds).hasSize(2); assertThat(rolloutGroupIds).hasSize(2);
assertRolloutGroup(rolloutGroupIds.get(0), RolloutGroupStatus.READY, true, amountTargetsInGroup1, null); assertRolloutGroup(rolloutGroupIds.get(0), RolloutGroupStatus.READY, true, amountTargetsInGroup1, null);
@@ -1855,7 +1855,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(rolloutManagement.findByRsql(PAGE, "name==*", true).getContent()).hasSize(1); assertThat(rolloutManagement.findByRsql(PAGE, "name==*", true).getContent()).hasSize(1);
assertThat(rolloutManagement.findByRsql(PAGE, "name==*", false).getContent()).isEmpty(); assertThat(rolloutManagement.findByRsql(PAGE, "name==*", false).getContent()).isEmpty();
assertThat(rolloutManagement.count()).isZero(); assertThat(rolloutManagement.count()).isZero();
assertThat(rolloutGroupManagement.findByRolloutWithDetailedStatus(PAGE, createdRollout.getId()).getContent()) assertThat(rolloutGroupManagement.findByRolloutWithDetailedStatus(createdRollout.getId(), PAGE).getContent())
.hasSize(amountGroups); .hasSize(amountGroups);
// verify that all scheduled actions are deleted // verify that all scheduled actions are deleted
@@ -2031,7 +2031,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
final Rollout testRollout = reloadRollout(createdRollout); final Rollout testRollout = reloadRollout(createdRollout);
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement final List<RolloutGroup> rolloutGroups = rolloutGroupManagement
.findByRollout(Pageable.unpaged(), testRollout.getId()).getContent(); .findByRollout(testRollout.getId(), Pageable.unpaged()).getContent();
assertThat(testRollout.getStatus()).isEqualTo(RolloutStatus.READY); assertThat(testRollout.getStatus()).isEqualTo(RolloutStatus.READY);
assertThat(testRollout.getTotalTargets()).isEqualTo(targets.size()); assertThat(testRollout.getTotalTargets()).isEqualTo(targets.size());
@@ -2039,7 +2039,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(rolloutGroups.get(0).getTotalTargets()).isEqualTo(targets.size()); assertThat(rolloutGroups.get(0).getTotalTargets()).isEqualTo(targets.size());
final List<Target> rolloutGroupTargets = rolloutGroupManagement final List<Target> rolloutGroupTargets = rolloutGroupManagement
.findTargetsOfRolloutGroup(Pageable.unpaged(), rolloutGroups.get(0).getId()).getContent(); .findTargetsOfRolloutGroup(rolloutGroups.get(0).getId(), Pageable.unpaged()).getContent();
assertThat(rolloutGroupTargets).hasSize(targets.size()).containsExactlyInAnyOrderElementsOf(targets) assertThat(rolloutGroupTargets).hasSize(targets.size()).containsExactlyInAnyOrderElementsOf(targets)
.doesNotContainAnyElementsOf(incompatibleTargets); .doesNotContainAnyElementsOf(incompatibleTargets);
@@ -2062,7 +2062,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
// second group should in running state // second group should in running state
List<RolloutGroup> rolloutGroups = rolloutGroupManagement List<RolloutGroup> rolloutGroups = rolloutGroupManagement
.findByRollout(new OffsetBasedPageRequest(0, 10, Sort.by(Direction.ASC, "id")), createdRollout.getId()) .findByRollout(createdRollout.getId(), new OffsetBasedPageRequest(0, 10, Sort.by(Direction.ASC, "id")))
.getContent(); .getContent();
assertThat(rolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING); assertThat(rolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING);
assertThat(rolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING); assertThat(rolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING);
@@ -2073,7 +2073,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
// third group should be in running state // third group should be in running state
rolloutGroups = rolloutGroupManagement rolloutGroups = rolloutGroupManagement
.findByRollout(new OffsetBasedPageRequest(0, 10, Sort.by(Direction.ASC, "id")), createdRollout.getId()) .findByRollout(createdRollout.getId(), new OffsetBasedPageRequest(0, 10, Sort.by(Direction.ASC, "id")))
.getContent(); .getContent();
assertThat(rolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING); assertThat(rolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING);
assertThat(rolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING); assertThat(rolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING);
@@ -2190,7 +2190,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
private void checkSecondGroupStatusIsRunning(final Rollout createdRollout) { private void checkSecondGroupStatusIsRunning(final Rollout createdRollout) {
rolloutHandler.handleAll(); rolloutHandler.handleAll();
final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement
.findByRollout(new OffsetBasedPageRequest(0, 10, Sort.by(Direction.ASC, "id")), createdRollout.getId()) .findByRollout(createdRollout.getId(), new OffsetBasedPageRequest(0, 10, Sort.by(Direction.ASC, "id")))
.getContent(); .getContent();
assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED); assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING); assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING);
@@ -2223,7 +2223,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
private void verifyRolloutAndAllGroupsAreFinished(final Rollout createdRollout) { private void verifyRolloutAndAllGroupsAreFinished(final Rollout createdRollout) {
rolloutHandler.handleAll(); rolloutHandler.handleAll();
final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement
.findByRollout(PAGE, createdRollout.getId()).getContent(); .findByRollout(createdRollout.getId(), PAGE).getContent();
assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED); assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED); assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
assertThat(runningRolloutGroups.get(2).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED); assertThat(runningRolloutGroups.get(2).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
@@ -2252,7 +2252,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
} }
private void assertAllActionOfRolloutGroupHavingStatus(final long rolloutGroupId, final Status status) { private void assertAllActionOfRolloutGroupHavingStatus(final long rolloutGroupId, final Status status) {
final List<Target> targets = rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE, rolloutGroupId) final List<Target> targets = rolloutGroupManagement.findTargetsOfRolloutGroup(rolloutGroupId, PAGE)
.getContent(); .getContent();
targets.forEach(target -> { targets.forEach(target -> {
final List<Action> activeActions = deploymentManagement final List<Action> activeActions = deploymentManagement
@@ -2263,7 +2263,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
} }
private void forceQuitAllActionsOfRolloutGroup(final long rolloutGroupId) { private void forceQuitAllActionsOfRolloutGroup(final long rolloutGroupId) {
final List<Target> targets = rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE, rolloutGroupId) final List<Target> targets = rolloutGroupManagement.findTargetsOfRolloutGroup(rolloutGroupId, PAGE)
.getContent(); .getContent();
targets.forEach(target -> { targets.forEach(target -> {
deploymentManagement.findActiveActionsByTarget(PAGE, target.getControllerId()).getContent().stream().map(Identifiable::getId) deploymentManagement.findActiveActionsByTarget(PAGE, target.getControllerId()).getContent().stream().map(Identifiable::getId)

View File

@@ -42,7 +42,7 @@ public class RSQLRolloutGroupFieldTest extends AbstractJpaIntegrationTest {
rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
rollout = rolloutManagement.get(rollout.getId()).get(); rollout = rolloutManagement.get(rollout.getId()).get();
this.rolloutGroupId = rolloutGroupManagement.findByRollout(PAGE, rollout.getId()).getContent().get(0).getId(); this.rolloutGroupId = rolloutGroupManagement.findByRollout(rollout.getId(), PAGE).getContent().get(0).getId();
} }
@Test @Test
@@ -85,8 +85,8 @@ public class RSQLRolloutGroupFieldTest extends AbstractJpaIntegrationTest {
} }
private void assertRSQLQuery(final String rsqlParam, final long expectedTargets) { private void assertRSQLQuery(final String rsqlParam, final long expectedTargets) {
final Page<RolloutGroup> findTargetPage = rolloutGroupManagement.findByRolloutAndRsql(PageRequest.of(0, 100), final Page<RolloutGroup> findTargetPage = rolloutGroupManagement.findByRolloutAndRsql(rollout.getId(), rsqlParam, PageRequest.of(0, 100)
rollout.getId(), rsqlParam); );
final long countTargetsAll = findTargetPage.getTotalElements(); final long countTargetsAll = findTargetPage.getTotalElements();
assertThat(findTargetPage).isNotNull(); assertThat(findTargetPage).isNotNull();
assertThat(countTargetsAll).isEqualTo(expectedTargets); assertThat(countTargetsAll).isEqualTo(expectedTargets);