Full representation with filtration (#1415)

* fixed RSQL filtration while loading full representation of a Rollout

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

* Added tests

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

* review findings

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

---------

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>
This commit is contained in:
Denislav Prinov
2023-08-16 11:09:46 +03:00
committed by GitHub
parent 4590d004f9
commit a5dba29e74
4 changed files with 67 additions and 20 deletions

View File

@@ -458,4 +458,14 @@ public interface RolloutManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_UPDATE)
void triggerNextGroup(long rolloutId);
/**
* Enrich the rollouts Slice with additional details
*
* @param rollouts
* the rollouts to be enriched.
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_UPDATE)
void setRolloutStatusDetails(final Slice<Rollout> rollouts);
}

View File

@@ -575,8 +575,8 @@ public class JpaRolloutManagement implements RolloutManagement {
return fromCache;
}
private void setRolloutStatusDetails(final Slice<Rollout> rollouts) {
@Override
public void setRolloutStatusDetails(final Slice<Rollout> rollouts) {
final List<Long> rolloutIds = rollouts.getContent().stream().map(Rollout::getId).collect(Collectors.toList());
final Map<Long, List<TotalTargetCountActionStatus>> allStatesForRollout = getStatusCountItemForRollout(
rolloutIds);

View File

@@ -103,26 +103,17 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
final boolean isFullMode = parseRepresentationMode(representationModeParam) == MgmtRepresentationMode.FULL;
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Slice<Rollout> rollouts;
final long totalElements;
final Page<Rollout> rollouts;
if (rsqlParam != null) {
if (isFullMode) {
rollouts = this.rolloutManagement.findByFiltersWithDetailedStatus(pageable, rsqlParam, false);
totalElements = this.rolloutManagement.countByFilters(rsqlParam);
} else {
final Page<Rollout> findRolloutsAll = this.rolloutManagement.findByRsql(pageable, rsqlParam, false);
totalElements = findRolloutsAll.getTotalElements();
rollouts = findRolloutsAll;
}
rollouts = this.rolloutManagement.findByRsql(pageable, rsqlParam, false);
} else {
if (isFullMode) {
rollouts = this.rolloutManagement.findAllWithDetailedStatus(pageable, false);
totalElements = this.rolloutManagement.count();
} else {
final Page<Rollout> findRolloutsAll = this.rolloutManagement.findAll(pageable, false);
totalElements = findRolloutsAll.getTotalElements();
rollouts = findRolloutsAll;
}
rollouts = this.rolloutManagement.findAll(pageable, false);
}
final long totalElements = rollouts.getTotalElements();
if (isFullMode) {
this.rolloutManagement.setRolloutStatusDetails(rollouts);
}
final List<MgmtRolloutResponseBody> rest = MgmtRolloutMapper.toResponseRollout(rollouts.getContent(),

View File

@@ -332,6 +332,52 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("content[0]._links.self.href", startsWith(HREF_ROLLOUT_PREFIX)));
}
@Test
@Description("Retrieves the list of rollouts with representation mode 'full'.")
void retrieveRolloutListFullRepresentationWithFilter() throws Exception {
testdataFactory.createTargets(20, "rollout", "rollout");
final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create a running rollout for the created targets
final Rollout rollout = rolloutManagement.create(
entityFactory.rollout().create().name("rollout1").set(dsA.getId())
.targetFilterQuery("controllerId==rollout*"),
4, false, new RolloutGroupConditionBuilder().withDefaults()
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
rolloutManagement.create(
entityFactory.rollout().create().name("rollout2").set(dsA.getId())
.targetFilterQuery("controllerId==rollout*"),
4, false, new RolloutGroupConditionBuilder().withDefaults()
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
rolloutHandler.handleAll();
rolloutManagement.start(rollout.getId());
rolloutHandler.handleAll();
// request the list of rollouts with full representation
mvc.perform(get("/rest/v1/rollouts?q=name==rollout1&representation=full").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("content[0].id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("content[0].name", equalTo("rollout1")))
.andExpect(jsonPath("content[0].status", equalTo("running")))
.andExpect(jsonPath("content[0].targetFilterQuery", equalTo("controllerId==rollout*")))
.andExpect(jsonPath("content[0].distributionSetId", equalTo(dsA.getId().intValue())))
.andExpect(jsonPath("content[0].totalTargets", equalTo(20)))
.andExpect(jsonPath("content[0].totalTargetsPerStatus").exists())
.andExpect(jsonPath("content[0].totalTargetsPerStatus.running", equalTo(5)))
.andExpect(jsonPath("content[0].totalTargetsPerStatus.notstarted", equalTo(0)))
.andExpect(jsonPath("content[0].totalTargetsPerStatus.scheduled", equalTo(15)))
.andExpect(jsonPath("content[0].totalTargetsPerStatus.cancelled", equalTo(0)))
.andExpect(jsonPath("content[0].totalTargetsPerStatus.finished", equalTo(0)))
.andExpect(jsonPath("content[0].totalTargetsPerStatus.error", equalTo(0)))
.andExpect(jsonPath("content[0].deleted", equalTo(false)))
.andExpect(jsonPath("content[0].totalGroups", equalTo(4)))
.andExpect(jsonPath("content[0]._links.self.href", startsWith(HREF_ROLLOUT_PREFIX)));
}
@ParameterizedTest
@ValueSource(booleans = { true, false })
@Description("Verify the confirmation required flag is not part of the rollout parent entity")