Add validation for deployment groups and rollouts (#1341)
* Add validation for deployment groups and rollouts * NOT_FOUND status code instead of BAD_REQUEST * NOT_FOUND status code instead of BAD_REQUEST * Change the returned message Signed-off-by: Stanislav Trailov <stanislav.trailov@bosch.io>
This commit is contained in:
committed by
GitHub
parent
a2fd46c732
commit
771ef8e83d
@@ -9,6 +9,7 @@
|
||||
package org.eclipse.hawkbit.mgmt.rest.resource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -271,6 +272,11 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
|
||||
|
||||
final RolloutGroup rolloutGroup = rolloutGroupManagement.getWithDetailedStatus(groupId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, rolloutId));
|
||||
|
||||
if (!Objects.equals(rolloutId, rolloutGroup.getRollout().getId())) {
|
||||
throw new EntityNotFoundException(RolloutGroup.class, groupId);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(MgmtRolloutMapper.toResponseRolloutGroup(rolloutGroup, true,
|
||||
tenantConfigHelper.isConfirmationFlowEnabled()));
|
||||
}
|
||||
|
||||
@@ -683,6 +683,33 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
: jsonPath("confirmationRequired").doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("The relation between deploy group and rollout should be validated.")
|
||||
void deployGroupsShouldValidateRelationWithRollout() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 8;
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout1 = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*",
|
||||
false);
|
||||
|
||||
final Rollout rollout2 = createRollout("rollout2", 1, dsA.getId(), "controllerId==rollout*",
|
||||
false);
|
||||
|
||||
rolloutManagement.start(rollout1.getId());
|
||||
rolloutManagement.start(rollout2.getId());
|
||||
rolloutHandler.handleAll();
|
||||
|
||||
final RolloutGroup firstGroup = rolloutGroupManagement
|
||||
.findByRollout(PageRequest.of(0, 1, Direction.ASC, "id"), rollout1.getId()).getContent().get(0);
|
||||
|
||||
// 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())
|
||||
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Testing that starting the rollout switches the state to starting and then to running")
|
||||
void startingRolloutSwitchesIntoRunningState() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user