MgmtRolloutResource implements MgmtRolloutRestApi { @Override public ResponseEntity<MgmtRolloutResponseBody> create( @RequestBody final MgmtRolloutRestRequestBody rolloutRequestBody) { targetFilterQueryManagement.verifyTargetFilterQuerySyntax(rolloutRequestBody.getTargetFilterQuery()); final DistributionSet distributionSet = findDistributionSetOrThrowException(rolloutRequestBody); final RolloutGroupConditions rolloutGroupConditions = MgmtRolloutMapper.fromRequest(rolloutRequestBody, true); final RolloutCreate create = MgmtRolloutMapper.fromRequest(entityFactory, rolloutRequestBody, distributionSet); Rollout rollout; if (rolloutRequestBody.getGroups() != null) { final List<RolloutGroupCreate> rolloutGroups = rolloutRequestBody.getGroups().stream() .map(mgmtRolloutGroup -> MgmtRolloutMapper.fromRequest(entityFactory, mgmtRolloutGroup)) .collect(Collectors.toList()); rollout = rolloutManagement.create(create, rolloutGroups, rolloutGroupConditions); } else if (rolloutRequestBody.getAmountGroups() != null) { rollout = rolloutManagement.create(create, rolloutRequestBody.getAmountGroups(), rolloutGroupConditions); } else { throw new ValidationException("Either 'amountGroups' or 'groups' must be defined in the request"); } return ResponseEntity.status(HttpStatus.CREATED).body(MgmtRolloutMapper.toResponseRollout(rollout, true)); } MgmtRolloutResource(final RolloutManagement rolloutManagement, final RolloutGroupManagement rolloutGroupManagement,
            final DistributionSetManagement distributionSetManagement,
            final TargetFilterQueryManagement targetFilterQueryManagement, final EntityFactory entityFactory); @Override ResponseEntity<PagedList<MgmtRolloutResponseBody>> getRollouts(
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam); @Override ResponseEntity<MgmtRolloutResponseBody> getRollout(@PathVariable("rolloutId") final Long rolloutId); @Override ResponseEntity<MgmtRolloutResponseBody> create(
            @RequestBody final MgmtRolloutRestRequestBody rolloutRequestBody); @Override ResponseEntity<Void> approve(@PathVariable("rolloutId") final Long rolloutId, final String remark); @Override ResponseEntity<Void> deny(@PathVariable("rolloutId") final Long rolloutId, final String remark); @Override ResponseEntity<Void> start(@PathVariable("rolloutId") final Long rolloutId); @Override ResponseEntity<Void> pause(@PathVariable("rolloutId") final Long rolloutId); @Override ResponseEntity<Void> delete(@PathVariable("rolloutId") final Long rolloutId); @Override ResponseEntity<Void> resume(@PathVariable("rolloutId") final Long rolloutId); @Override ResponseEntity<PagedList<MgmtRolloutGroupResponseBody>> getRolloutGroups(
            @PathVariable("rolloutId") final Long rolloutId,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam); @Override ResponseEntity<MgmtRolloutGroupResponseBody> getRolloutGroup(@PathVariable("rolloutId") final Long rolloutId,
            @PathVariable("groupId") final Long groupId); @Override ResponseEntity<PagedList<MgmtTarget>> getRolloutGroupTargets(@PathVariable("rolloutId") final Long rolloutId,
            @PathVariable("groupId") final Long groupId,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam);  }
@Test @Description("Testing that rollout can be created with groups") public void createRolloutWithGroupDefinitions() throws Exception { final DistributionSet dsA = testdataFactory.createDistributionSet("ro"); final int amountTargets = 10; testdataFactory.createTargets(amountTargets, "ro-target", "rollout"); final float percentTargetsInGroup1 = 20; final float percentTargetsInGroup2 = 100; final List<RolloutGroup> rolloutGroups = Arrays.asList( entityFactory.rolloutGroup().create().name("Group1").description("Group1desc") .targetPercentage(percentTargetsInGroup1).build(), entityFactory.rolloutGroup().create().name("Group2").description("Group2desc") .targetPercentage(percentTargetsInGroup2).build()); final RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder().withDefaults().build(); mvc.perform(post("/rest/v1/rollouts") .content(JsonBuilder.rollout("rollout2", "desc", null, dsA.getId(), "id==ro-target*", rolloutGroupConditions, rolloutGroups)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()).andReturn(); }
@Test @Description("Testing that no rollout with groups that have illegal percentages can be created") public void createRolloutWithTooLowPercentage() throws Exception { final DistributionSet dsA = testdataFactory.createDistributionSet("ro2"); final int amountTargets = 10; testdataFactory.createTargets(amountTargets, "ro-target", "rollout"); final List<RolloutGroup> rolloutGroups = Arrays.asList( entityFactory.rolloutGroup().create().name("Group1").description("Group1desc").targetPercentage(0F) .build(), entityFactory.rolloutGroup().create().name("Group2").description("Group2desc").targetPercentage(100F) .build()); final RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder().withDefaults().build(); mvc.perform(post("/rest/v1/rollouts") .content(JsonBuilder.rollout("rollout4", "desc", null, dsA.getId(), "id==ro-target*", rolloutGroupConditions, rolloutGroups)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()) .andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.repo.constraintViolation"))); }
@Test @Description("Testing that no rollout with groups that have illegal percentages can be created") public void createRolloutWithTooHighPercentage() throws Exception { final DistributionSet dsA = testdataFactory.createDistributionSet("ro2"); final int amountTargets = 10; testdataFactory.createTargets(amountTargets, "ro-target", "rollout"); final List<RolloutGroup> rolloutGroups = Arrays.asList( entityFactory.rolloutGroup().create().name("Group1").description("Group1desc").targetPercentage(1F) .build(), entityFactory.rolloutGroup().create().name("Group2").description("Group2desc").targetPercentage(101F) .build()); final RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder().withDefaults().build(); mvc.perform(post("/rest/v1/rollouts") .content(JsonBuilder.rollout("rollout4", "desc", null, dsA.getId(), "id==ro-target*", rolloutGroupConditions, rolloutGroups)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()) .andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.repo.constraintViolation"))); }
@Test @Description("Retrieves single rollout from management API including extra data that is delivered only for single rollout access.") public void retrieveSingleRollout() throws Exception { testdataFactory.createTargets(20, "rollout", "rollout"); final DistributionSet dsA = testdataFactory.createDistributionSet(""); final Rollout rollout = rolloutManagement.create( entityFactory.rollout().create().name("rollout1").set(dsA.getId()) .targetFilterQuery("controllerId==rollout*"), 4, new RolloutGroupConditionBuilder().withDefaults() .successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build()); retrieveAndVerifyRolloutInCreating(dsA, rollout); retrieveAndVerifyRolloutInReady(rollout); retrieveAndVerifyRolloutInStarting(rollout); retrieveAndVerifyRolloutInRunning(rollout); }
@Test @Description("Testing that a single rollout group can be retrieved") public void retrieveSingleRolloutGroup() throws Exception { final int amountTargets = 20; testdataFactory.createTargets(amountTargets, "rollout", "rollout"); final DistributionSet dsA = testdataFactory.createDistributionSet(""); final Rollout rollout = rolloutManagement.create( entityFactory.rollout().create().name("rollout1").set(dsA.getId()) .targetFilterQuery("controllerId==rollout*"), 4, new RolloutGroupConditionBuilder().withDefaults() .successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build()); final RolloutGroup firstGroup = rolloutGroupManagement .findByRollout(PageRequest.of(0, 1, Direction.ASC, "id"), rollout.getId()).getContent().get(0); final RolloutGroup secondGroup = rolloutGroupManagement .findByRollout(PageRequest.of(1, 1, Direction.ASC, "id"), rollout.getId()).getContent().get(0); retrieveAndVerifyRolloutGroupInCreating(rollout, firstGroup); retrieveAndVerifyRolloutGroupInReady(rollout, firstGroup); retrieveAndVerifyRolloutGroupInRunningAndScheduled(rollout, firstGroup, secondGroup); }