Add REST method for update rollout (#1749)

* adds PUT method for updating name and description of a rollout
* restrict RolloutUpdate to changing only name and description
* small refactoring

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-06-24 09:16:39 +03:00
committed by GitHub
parent 297775f539
commit 40f99962d2
20 changed files with 321 additions and 343 deletions

View File

@@ -9,18 +9,122 @@
*/
package org.eclipse.hawkbit.repository.jpa.builder;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.builder.AbstractRolloutUpdateCreate;
import org.eclipse.hawkbit.repository.ValidString;
import org.eclipse.hawkbit.repository.builder.AbstractNamedEntityBuilder;
import org.eclipse.hawkbit.repository.builder.RolloutCreate;
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.springframework.util.StringUtils;
import java.util.Optional;
public class JpaRolloutCreate extends AbstractNamedEntityBuilder<RolloutCreate> implements RolloutCreate {
public class JpaRolloutCreate extends AbstractRolloutUpdateCreate<RolloutCreate> implements RolloutCreate {
private final DistributionSetManagement distributionSetManagement;
protected Long distributionSetId;
@ValidString
protected String targetFilterQuery;
protected Action.ActionType actionType;
protected Long forcedTime;
protected Long startAt;
@Min(Action.WEIGHT_MIN)
@Max(Action.WEIGHT_MAX)
protected Integer weight;
private boolean dynamic;
JpaRolloutCreate(final DistributionSetManagement distributionSetManagement) {
this.distributionSetManagement = distributionSetManagement;
}
/**
* {@link DistributionSet} of rollout
*
* @param distributionSetId ID of the distributionSetId
* @return this builder
*/
public RolloutCreate distributionSetId(final long distributionSetId) {
this.distributionSetId = distributionSetId;
return this;
}
/**
* Filter of the rollout
*
* @param targetFilterQuery query
* @return this builder
*/
public RolloutCreate targetFilterQuery(final String targetFilterQuery) {
this.targetFilterQuery = StringUtils.trimWhitespace(targetFilterQuery);
return this;
}
/**
* {@link Action.ActionType} used for {@link Action}s
*
* @param actionType type
* @return this builder
*/
public RolloutCreate actionType(final Action.ActionType actionType) {
this.actionType = actionType;
return this;
}
/**
* forcedTime used for {@link Action}s
*
* @param forcedTime time
* @return this builder
*/
public RolloutCreate forcedTime(final Long forcedTime) {
this.forcedTime = forcedTime;
return this;
}
/**
* weight used for {@link Action}s
*
* @param weight weight
* @return this builder
*/
public RolloutCreate weight(final Integer weight) {
this.weight = weight;
return this;
}
/**
* Set start of the Rollout
*
* @param startAt start time point
* @return this builder
*/
public RolloutCreate startAt(final Long startAt) {
this.startAt = startAt;
return this;
}
public Optional<Long> getDistributionSetId() {
return Optional.ofNullable(distributionSetId);
}
public Optional<Action.ActionType> getActionType() {
return Optional.ofNullable(actionType);
}
public Optional<Long> getForcedTime() {
return Optional.ofNullable(forcedTime);
}
public Optional<Integer> getWeight() {
return Optional.ofNullable(weight);
}
public Optional<Long> getStartAt() {
return Optional.ofNullable(startAt);
}
public RolloutCreate dynamic(final boolean dynamic) {
this.dynamic = dynamic;
@@ -33,7 +137,7 @@ public class JpaRolloutCreate extends AbstractRolloutUpdateCreate<RolloutCreate>
rollout.setName(name);
rollout.setDescription(description);
rollout.setDistributionSet(distributionSetManagement.getValidAndComplete(set));
rollout.setDistributionSet(distributionSetManagement.getValidAndComplete(distributionSetId));
rollout.setTargetFilterQuery(targetFilterQuery);
rollout.setStartAt(startAt);
rollout.setWeight(weight);
@@ -49,4 +153,4 @@ public class JpaRolloutCreate extends AbstractRolloutUpdateCreate<RolloutCreate>
return rollout;
}
}
}

View File

@@ -58,7 +58,6 @@ import org.eclipse.hawkbit.repository.jpa.repository.RolloutRepository;
import org.eclipse.hawkbit.repository.jpa.rollout.condition.StartNextGroupRolloutGroupSuccessAction;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.specifications.RolloutSpecification;
import org.eclipse.hawkbit.repository.jpa.utils.DeploymentHelper;
import org.eclipse.hawkbit.repository.jpa.utils.QuotaHelper;
import org.eclipse.hawkbit.repository.jpa.utils.WeightValidationHelper;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -523,24 +522,9 @@ public class JpaRolloutManagement implements RolloutManagement {
final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(update.getId());
checkIfDeleted(update.getId(), rollout.getStatus());
update.getName().ifPresent(rollout::setName);
update.getDescription().ifPresent(rollout::setDescription);
update.getActionType().ifPresent(rollout::setActionType);
update.getForcedTime().ifPresent(rollout::setForcedTime);
update.getWeight().ifPresent(rollout::setWeight);
// resetting back to manual start is done by setting start at time to
// null
rollout.setStartAt(update.getStartAt().orElse(null));
update.getSet().ifPresent(setId -> {
final DistributionSet set = distributionSetManagement.getValidAndComplete(setId);
rollout.setDistributionSet(set);
});
if (rolloutApprovalStrategy.isApprovalNeeded(rollout)) {
rollout.setStatus(RolloutStatus.WAITING_FOR_APPROVAL);
rollout.setApprovalDecidedBy(null);
rollout.setApprovalRemark(null);
}
return rolloutRepository.save(rollout);
}