Management API: Expose forceTime and startAt fields in rollout representation (#1336)
* Expose forceTime and startAt fields in rollout representation in Mgmt API * Change "forceTime" to "forcetime" * Add checks when making a POST request in the tests * Change forced to timeforced in tests and extend validity check * Pass aforcetime and startat arguments as test checks * remove unused import Signed-off-by: Stanislav Trailov <stanislav.trailov@bosch.io>
This commit is contained in:
committed by
GitHub
parent
5baf65c1f0
commit
85feeba681
@@ -397,7 +397,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
mvc.perform(post("/rest/v1/rollouts")
|
||||
.content(JsonBuilder.rollout("rollout2", "desc", null, dsA.getId(), "id==ro-target*",
|
||||
rolloutGroupConditions, rolloutGroups, null, null, false))
|
||||
rolloutGroupConditions, rolloutGroups, null, null, null, null, false))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()).andReturn();
|
||||
|
||||
@@ -438,7 +438,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
mvc.perform(post("/rest/v1/rollouts")
|
||||
.content(JsonBuilder.rollout("rollout2", "desc", null, dsA.getId(), "id==ro-target*",
|
||||
rolloutGroupConditions, rolloutGroups, null, null, null))
|
||||
rolloutGroupConditions, rolloutGroups, null, null, null, null, null))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()).andReturn();
|
||||
|
||||
@@ -585,6 +585,25 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(jsonPath("content[1]._links.self.href", startsWith(HREF_ROLLOUT_PREFIX)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void retrieveRolloutWithStartAtAndForcedTimeResponseFields() throws Exception {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
final Long startAt = 21L;
|
||||
final Long forcetime = 45L;
|
||||
|
||||
testdataFactory.createTargets(20, "target", "rollout");
|
||||
postRollout("rollout1", 5, dsA.getId(), "id==target*", 20, Action.ActionType.TIMEFORCED,
|
||||
startAt, forcetime);
|
||||
postRollout("rollout2", 5, dsA.getId(), "id==target-0001*", 10, Action.ActionType.TIMEFORCED,
|
||||
startAt, forcetime);
|
||||
|
||||
// Run here, because Scheduler is disabled during tests
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
retrieveAndCompareRolloutsContent(dsA, "/rest/v1/rollouts", false, true, startAt, forcetime);
|
||||
retrieveAndCompareRolloutsContent(dsA, "/rest/v1/rollouts?representation=full", true, true, startAt, forcetime);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Testing representation mode of rollout paged list")
|
||||
void rolloutPagedListRepresentationMode() throws Exception {
|
||||
@@ -1180,9 +1199,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final int weight = 66;
|
||||
|
||||
final String invalideWeightRequest = JsonBuilder.rollout("withWeight", "d", 2, dsId, "id==rollout*",
|
||||
new RolloutGroupConditionBuilder().withDefaults().build(), null, null, Action.WEIGHT_MIN - 1, null);
|
||||
new RolloutGroupConditionBuilder().withDefaults().build(), null, null, Action.WEIGHT_MIN - 1, null, null, null);
|
||||
final String valideWeightRequest = JsonBuilder.rollout("withWeight", "d", 2, dsId, "id==rollout*",
|
||||
new RolloutGroupConditionBuilder().withDefaults().build(), null, null, weight, null);
|
||||
new RolloutGroupConditionBuilder().withDefaults().build(), null, null, weight, null, null, null);
|
||||
|
||||
mvc.perform(post("/rest/v1/rollouts").content(valideWeightRequest).contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
@@ -1202,11 +1221,18 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
assertThat(rollouts.get(0).getWeight()).get().isEqualTo(weight);
|
||||
}
|
||||
|
||||
|
||||
private void postRollout(final String name, final int groupSize, final Long distributionSetId,
|
||||
final String targetFilterQuery, final int targets, final Action.ActionType type) throws Exception {
|
||||
final String targetFilterQuery, final int targets, final Action.ActionType type) throws Exception {
|
||||
postRollout(name, groupSize, distributionSetId, targetFilterQuery, targets, type, null, null);
|
||||
}
|
||||
|
||||
private void postRollout(final String name, final int groupSize, final Long distributionSetId,
|
||||
final String targetFilterQuery, final int targets, final Action.ActionType type, final Long startTime, final Long forceTime) throws Exception {
|
||||
final String actionType = MgmtRestModelMapper.convertActionType(type).getName();
|
||||
final String rollout = JsonBuilder.rollout(name, "desc", groupSize, distributionSetId, targetFilterQuery,
|
||||
new RolloutGroupConditionBuilder().withDefaults().build(), null, actionType, null, null);
|
||||
new RolloutGroupConditionBuilder().withDefaults().build(), null, actionType, null, startTime,
|
||||
forceTime, null);
|
||||
|
||||
mvc.perform(post("/rest/v1/rollouts").content(rollout).contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
|
||||
@@ -1220,6 +1246,12 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(jsonPath("$.lastModifiedBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("$.lastModifiedAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("$.totalTargets", equalTo(targets)))
|
||||
.andExpect(startTime != null ?
|
||||
jsonPath("$.startAt", equalTo(startTime.intValue()))
|
||||
: jsonPath("$.startAt").doesNotExist())
|
||||
.andExpect(forceTime != null ?
|
||||
jsonPath("$.forcetime", equalTo(forceTime.intValue()))
|
||||
: jsonPath("$.forcetime", equalTo(0)))
|
||||
.andExpect(jsonPath("$.totalTargetsPerStatus.running", equalTo(0)))
|
||||
.andExpect(jsonPath("$.totalTargetsPerStatus.notstarted", equalTo(targets)))
|
||||
.andExpect(jsonPath("$.totalTargetsPerStatus.scheduled", equalTo(0)))
|
||||
@@ -1330,87 +1362,98 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
private void retrieveAndCompareRolloutsContent(final DistributionSet dsA, final String urlTemplate,
|
||||
final boolean isFullRepresentation) throws Exception {
|
||||
retrieveAndCompareRolloutsContent(dsA, urlTemplate, isFullRepresentation, false, null, null);
|
||||
}
|
||||
|
||||
private void retrieveAndCompareRolloutsContent(final DistributionSet dsA, final String urlTemplate,
|
||||
final boolean isFullRepresentation, final boolean isStartTypeScheduled, final Long startAt, final Long forcetime) throws Exception {
|
||||
mvc.perform(get(urlTemplate).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2)))
|
||||
.andExpect(jsonPath("content[0].name", equalTo("rollout1")))
|
||||
.andExpect(jsonPath("content[0].status", equalTo("ready")))
|
||||
.andExpect(jsonPath("content[0].targetFilterQuery", equalTo("id==target*")))
|
||||
.andExpect(jsonPath("content[0].distributionSetId", equalTo(dsA.getId().intValue())))
|
||||
.andExpect(jsonPath("content[0].createdBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("content[0].createdAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("content[0].lastModifiedBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("content[0].lastModifiedAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("content[0].totalTargets", equalTo(20)))
|
||||
.andExpect(isFullRepresentation ? jsonPath("$.content[0].totalTargetsPerStatus").exists()
|
||||
: jsonPath("content[0].totalTargetsPerStatus").doesNotExist())
|
||||
.andExpect(isFullRepresentation ? jsonPath("$.content[0].totalGroups", equalTo(5))
|
||||
: jsonPath("content[0].totalGroups").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.start.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.start.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.pause.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.pause.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.resume.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.resume.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.triggerNextGroup.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.triggerNextGroup.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.approve.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.approve.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.deny.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.deny.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.groups.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.groups.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.distributionset.href",
|
||||
startsWith("http://localhost/rest/v1/distributionsets/"))
|
||||
: jsonPath("content[0]._links.distributionset.href").doesNotExist())
|
||||
.andExpect(jsonPath("content[0]._links.self.href", startsWith(HREF_ROLLOUT_PREFIX)))
|
||||
.andExpect(jsonPath("content[1].name", equalTo("rollout2")))
|
||||
.andExpect(jsonPath("content[1].status", equalTo("ready")))
|
||||
.andExpect(jsonPath("content[1].targetFilterQuery", equalTo("id==target-0001*")))
|
||||
.andExpect(jsonPath("content[1].distributionSetId", equalTo(dsA.getId().intValue())))
|
||||
.andExpect(jsonPath("content[1].createdBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("content[1].createdAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("content[1].lastModifiedBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("content[1].lastModifiedAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("content[1].totalTargets", equalTo(10)))
|
||||
.andExpect(isFullRepresentation ? jsonPath("$.content[1].totalTargetsPerStatus").exists()
|
||||
: jsonPath("content[1].totalTargetsPerStatus").doesNotExist())
|
||||
.andExpect(isFullRepresentation ? jsonPath("$.content[0].totalGroups", equalTo(5))
|
||||
: jsonPath("content[0].totalGroups").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.start.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.start.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.pause.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.pause.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.resume.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.resume.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.triggerNextGroup.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.triggerNextGroup.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.approve.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.approve.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.deny.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.deny.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.groups.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.groups.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.distributionset.href",
|
||||
startsWith("http://localhost/rest/v1/distributionsets/"))
|
||||
: jsonPath("content[1]._links.distributionset.href").doesNotExist())
|
||||
.andExpect(jsonPath("content[1]._links.self.href", startsWith(HREF_ROLLOUT_PREFIX)));
|
||||
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2)))
|
||||
.andExpect(jsonPath("content[0].name", equalTo("rollout1")))
|
||||
.andExpect(jsonPath("content[0].status", equalTo("ready")))
|
||||
.andExpect(jsonPath("content[0].targetFilterQuery", equalTo("id==target*")))
|
||||
.andExpect(jsonPath("content[0].distributionSetId", equalTo(dsA.getId().intValue())))
|
||||
.andExpect(jsonPath("content[0].createdBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("content[0].createdAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("content[0].lastModifiedBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("content[0].lastModifiedAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("content[0].totalTargets", equalTo(20)))
|
||||
.andExpect(jsonPath("content[0].forcetime", equalTo(isStartTypeScheduled ? forcetime.intValue() : 0)))
|
||||
.andExpect(isFullRepresentation ? jsonPath("$.content[0].totalTargetsPerStatus").exists()
|
||||
: jsonPath("content[0].totalTargetsPerStatus").doesNotExist())
|
||||
.andExpect(isFullRepresentation ? jsonPath("$.content[0].totalGroups", equalTo(5))
|
||||
: jsonPath("content[0].totalGroups").doesNotExist())
|
||||
.andExpect(isFullRepresentation && isStartTypeScheduled ? jsonPath("$.content[0].startAt", equalTo(startAt.intValue()))
|
||||
: jsonPath("$.content[0].startAt").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.start.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.start.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.pause.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.pause.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.resume.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.resume.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.triggerNextGroup.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.triggerNextGroup.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.approve.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.approve.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.deny.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.deny.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.groups.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[0]._links.groups.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[0]._links.distributionset.href",
|
||||
startsWith("http://localhost/rest/v1/distributionsets/"))
|
||||
: jsonPath("content[0]._links.distributionset.href").doesNotExist())
|
||||
.andExpect(jsonPath("content[0]._links.self.href", startsWith(HREF_ROLLOUT_PREFIX)))
|
||||
.andExpect(jsonPath("content[1].name", equalTo("rollout2")))
|
||||
.andExpect(jsonPath("content[1].status", equalTo("ready")))
|
||||
.andExpect(jsonPath("content[1].targetFilterQuery", equalTo("id==target-0001*")))
|
||||
.andExpect(jsonPath("content[1].distributionSetId", equalTo(dsA.getId().intValue())))
|
||||
.andExpect(jsonPath("content[1].createdBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("content[1].createdAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("content[1].lastModifiedBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("content[1].lastModifiedAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("content[1].totalTargets", equalTo(10)))
|
||||
.andExpect(jsonPath("content[1].forcetime", equalTo(isStartTypeScheduled ? forcetime.intValue() : 0)))
|
||||
.andExpect(isFullRepresentation ? jsonPath("$.content[1].totalTargetsPerStatus").exists()
|
||||
: jsonPath("content[1].totalTargetsPerStatus").doesNotExist())
|
||||
.andExpect(isFullRepresentation ? jsonPath("$.content[1].totalGroups", equalTo(5))
|
||||
: jsonPath("content[1].totalGroups").doesNotExist())
|
||||
.andExpect(isFullRepresentation && isStartTypeScheduled ? jsonPath("content[1].startAt", equalTo(startAt.intValue()))
|
||||
: jsonPath("content[1].startAt").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.start.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.start.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.pause.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.pause.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.resume.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.resume.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.triggerNextGroup.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.triggerNextGroup.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.approve.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.approve.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.deny.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.deny.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.groups.href", startsWith(HREF_ROLLOUT_PREFIX))
|
||||
: jsonPath("content[1]._links.groups.href").doesNotExist())
|
||||
.andExpect(isFullRepresentation
|
||||
? jsonPath("$.content[1]._links.distributionset.href",
|
||||
startsWith("http://localhost/rest/v1/distributionsets/"))
|
||||
: jsonPath("content[1]._links.distributionset.href").doesNotExist())
|
||||
.andExpect(jsonPath("content[1]._links.self.href", startsWith(HREF_ROLLOUT_PREFIX)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user