[#2746] Add required annotations to MgmtRolloutRestRequestBodyPost (#2818)

+ amountGroups made optional with default value 1 group

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-11-18 14:25:32 +02:00
committed by GitHub
parent fb69372ed5
commit 80165de06a
4 changed files with 10 additions and 9 deletions

View File

@@ -25,8 +25,8 @@ import lombok.experimental.Accessors;
@ToString(callSuper = true)
public abstract class MgmtNamedEntity extends MgmtBaseEntity {
@JsonProperty(required = true)
@Schema(example = "Name of entity")
@JsonProperty(required = true)
private String name;
@Schema(example = "Description of entity")

View File

@@ -14,6 +14,7 @@ import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -64,12 +65,14 @@ import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroup;
public class MgmtRolloutRestRequestBodyPost extends AbstractMgmtRolloutConditionsEntity {
@Schema(description = "Target filter query language expression", example = "id==targets-*")
@JsonProperty(required = true)
private String targetFilterQuery;
@Schema(description = "The ID of distribution set of this rollout", example = "6")
@JsonProperty(required = true)
private long distributionSetId;
@Schema(description = "The amount of groups the rollout should split targets into", example = "5")
@Schema(description = "The amount of groups the rollout should split targets into", example = "5", defaultValue = "1")
private Integer amountGroups;
@Schema(description = "Force time in milliseconds", example = "1691065781929")

View File

@@ -129,7 +129,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
throw new ValidationException("Dynamic rollouts are not supported with groups");
}
if (rolloutRequestBody.getAmountGroups() != null) {
throw new ValidationException("Either 'amountGroups' or 'groups' must be defined in the request");
throw new ValidationException("If 'group' is set the 'amountGroups' must not be set in the request");
}
final List<GroupCreate> rolloutGroups = rolloutRequestBody.getGroups().stream()
.map(mgmtRolloutGroup -> MgmtRolloutMapper.fromRequest(
@@ -137,14 +137,13 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
isConfirmationRequiredForGroup(mgmtRolloutGroup, rolloutRequestBody).orElse(confirmationFlowActive)))
.toList();
rollout = rolloutManagement.create(create, rolloutGroups, rolloutGroupConditions);
} else if (rolloutRequestBody.getAmountGroups() != null) {
} else {
final int amountGroup = Optional.ofNullable(rolloutRequestBody.getAmountGroups()).orElse(1);
final boolean confirmationRequired = rolloutRequestBody.getConfirmationRequired() == null
? confirmationFlowActive
: rolloutRequestBody.getConfirmationRequired();
rollout = rolloutManagement.create(create, rolloutRequestBody.getAmountGroups(), confirmationRequired,
rollout = rolloutManagement.create(create, amountGroup, confirmationRequired,
rolloutGroupConditions, MgmtRolloutMapper.fromRequest(rolloutRequestBody.getDynamicGroupTemplate()));
} else {
throw new ValidationException("Either 'amountGroups' or 'groups' must be defined in the request");
}
return ResponseEntity.status(HttpStatus.CREATED).body(MgmtRolloutMapper.toResponseRollout(rollout, true));

View File

@@ -74,8 +74,7 @@ public interface RolloutManagement extends PermissionSupport {
long count();
/**
* Counts all {@link Rollout}s for a specific {@link DistributionSet} that
* are stoppable
* Counts all {@link Rollout}s for a specific {@link DistributionSet} that are stoppable
* <p/>
* No access control applied
*