Remove Rollout(Group) builders (#2603)
* Fix entityManager.merge for ds and sm Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com> * Remove Rollout(Group) builders Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com> * Remove EntityFactory Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com> --------- Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaActionStatusBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupBuilder;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
* JPA Implementation of {@link EntityFactory}.
|
||||
*/
|
||||
@Validated
|
||||
public class JpaEntityFactory implements EntityFactory {
|
||||
|
||||
private final RolloutBuilder rolloutBuilder;
|
||||
|
||||
@SuppressWarnings("java:S107")
|
||||
public JpaEntityFactory(final RolloutBuilder rolloutBuilder) {
|
||||
this.rolloutBuilder = rolloutBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionStatusBuilder actionStatus() {
|
||||
return new JpaActionStatusBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolloutGroupBuilder rolloutGroup() {
|
||||
return new JpaRolloutGroupBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolloutBuilder rollout() {
|
||||
return rolloutBuilder;
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,6 @@ import io.micrometer.core.instrument.MeterRegistry;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.eclipse.hawkbit.ContextAware;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.PropertiesQuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.RepositoryConfiguration;
|
||||
@@ -41,7 +39,6 @@ import org.eclipse.hawkbit.repository.artifact.encryption.ArtifactEncryption;
|
||||
import org.eclipse.hawkbit.repository.artifact.encryption.ArtifactEncryptionSecretsStore;
|
||||
import org.eclipse.hawkbit.repository.artifact.encryption.ArtifactEncryptionService;
|
||||
import org.eclipse.hawkbit.repository.autoassign.AutoAssignExecutor;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.event.ApplicationEventFilter;
|
||||
import org.eclipse.hawkbit.repository.event.remote.EventEntityManager;
|
||||
import org.eclipse.hawkbit.repository.event.remote.EventEntityManagerHolder;
|
||||
@@ -53,7 +50,6 @@ import org.eclipse.hawkbit.repository.jpa.autoassign.AutoAssignScheduler;
|
||||
import org.eclipse.hawkbit.repository.jpa.autocleanup.AutoActionCleanup;
|
||||
import org.eclipse.hawkbit.repository.jpa.autocleanup.AutoCleanupScheduler;
|
||||
import org.eclipse.hawkbit.repository.jpa.autocleanup.CleanupTask;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.cluster.DistributedLockRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.cluster.LockProperties;
|
||||
import org.eclipse.hawkbit.repository.jpa.event.JpaEventEntityManager;
|
||||
@@ -92,8 +88,6 @@ import org.eclipse.hawkbit.repository.jpa.rollout.condition.StartNextGroupRollou
|
||||
import org.eclipse.hawkbit.repository.jpa.rollout.condition.ThresholdRolloutGroupErrorCondition;
|
||||
import org.eclipse.hawkbit.repository.jpa.rollout.condition.ThresholdRolloutGroupSuccessCondition;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RsqlUtility;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
@@ -297,15 +291,6 @@ public class JpaRepositoryConfiguration {
|
||||
return e -> e instanceof TargetPollEvent && !repositoryProperties.isPublishTargetPollEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param distributionSetManagement for loading {@link Rollout#getDistributionSet()}
|
||||
* @return RolloutBuilder bean
|
||||
*/
|
||||
@Bean
|
||||
RolloutBuilder rolloutBuilder(final DistributionSetManagement<? extends DistributionSet> distributionSetManagement) {
|
||||
return new JpaRolloutBuilder(distributionSetManagement);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link SystemSecurityContext} singleton bean which make it
|
||||
* accessible in beans which cannot access the service directly, e.g.
|
||||
@@ -409,17 +394,6 @@ public class JpaRepositoryConfiguration {
|
||||
return new DefaultRolloutApprovalStrategy(userAuthoritiesResolver, tenantConfigurationManagement, systemSecurityContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link JpaEntityFactory} bean.
|
||||
*
|
||||
* @return a new {@link EntityFactory}
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
EntityFactory entityFactory(final RolloutBuilder rolloutBuilder) {
|
||||
return new JpaEntityFactory(rolloutBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link EventEntityManagerHolder} bean.
|
||||
*
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupCreate.addSuccessAndErrorConditionsAndActions;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Collection;
|
||||
@@ -719,7 +717,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
|
||||
group.setTargetPercentage(lastGroup.isDynamic() ? lastGroup.getTargetPercentage() : lastGroup.getTotalTargets());
|
||||
group.setTargetFilterQuery(lastGroup.getTargetFilterQuery());
|
||||
|
||||
addSuccessAndErrorConditionsAndActions(group, lastGroup.getSuccessCondition(),
|
||||
JpaRolloutManagement.addSuccessAndErrorConditionsAndActions(group, lastGroup.getSuccessCondition(),
|
||||
lastGroup.getSuccessConditionExp(), lastGroup.getSuccessAction(),
|
||||
lastGroup.getSuccessActionExp(), lastGroup.getErrorCondition(),
|
||||
lastGroup.getErrorConditionExp(), lastGroup.getErrorAction(),
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
|
||||
/**
|
||||
* Builder implementation for {@link ActionStatus}.
|
||||
*/
|
||||
public class JpaActionStatusBuilder implements ActionStatusBuilder {
|
||||
|
||||
@Override
|
||||
public ActionStatusCreate create(final long actionId) {
|
||||
return new JpaActionStatusCreate(actionId);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.builder.AbstractActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
|
||||
/**
|
||||
* Create/build implementation.
|
||||
*/
|
||||
public class JpaActionStatusCreate extends AbstractActionStatusCreate<ActionStatusCreate> implements ActionStatusCreate {
|
||||
|
||||
JpaActionStatusCreate(final Long actionId) {
|
||||
super.actionId = actionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpaActionStatus build() {
|
||||
final JpaActionStatus result = new JpaActionStatus(status, getOccurredAt().orElse(System.currentTimeMillis()));
|
||||
if (messages != null) {
|
||||
messages.forEach(result::addMessage);
|
||||
}
|
||||
if (code != null) {
|
||||
result.setCode(code);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.GenericRolloutUpdate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutUpdate;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
|
||||
/**
|
||||
* Builder implementation for {@link Rollout}.
|
||||
*/
|
||||
public class JpaRolloutBuilder implements RolloutBuilder {
|
||||
|
||||
private final DistributionSetManagement<? extends DistributionSet> distributionSetManagement;
|
||||
|
||||
public JpaRolloutBuilder(final DistributionSetManagement<? extends DistributionSet> distributionSetManagement) {
|
||||
this.distributionSetManagement = distributionSetManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolloutUpdate update(final long id) {
|
||||
return new GenericRolloutUpdate(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolloutCreate create() {
|
||||
return new JpaRolloutCreate(distributionSetManagement);
|
||||
}
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
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;
|
||||
|
||||
public class JpaRolloutCreate extends AbstractNamedEntityBuilder<RolloutCreate> implements RolloutCreate {
|
||||
|
||||
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 final DistributionSetManagement<? extends DistributionSet> distributionSetManagement;
|
||||
private boolean dynamic;
|
||||
|
||||
JpaRolloutCreate(final DistributionSetManagement<? extends DistributionSet> distributionSetManagement) {
|
||||
this.distributionSetManagement = distributionSetManagement;
|
||||
}
|
||||
|
||||
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 = targetFilterQuery == null ? null : targetFilterQuery.strip();
|
||||
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;
|
||||
}
|
||||
|
||||
public RolloutCreate dynamic(final boolean dynamic) {
|
||||
this.dynamic = dynamic;
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpaRollout build() {
|
||||
final JpaRollout rollout = new JpaRollout();
|
||||
|
||||
rollout.setName(name);
|
||||
rollout.setDescription(description);
|
||||
rollout.setDistributionSet(distributionSetManagement.getValidAndComplete(distributionSetId));
|
||||
rollout.setTargetFilterQuery(targetFilterQuery);
|
||||
rollout.setStartAt(startAt);
|
||||
rollout.setWeight(weight);
|
||||
rollout.setDynamic(dynamic);
|
||||
|
||||
if (actionType != null) {
|
||||
rollout.setActionType(actionType);
|
||||
}
|
||||
|
||||
if (forcedTime != null) {
|
||||
rollout.setForcedTime(forcedTime);
|
||||
}
|
||||
|
||||
return rollout;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
|
||||
/**
|
||||
* Builder implementation for {@link RolloutGroup}.
|
||||
*/
|
||||
public class JpaRolloutGroupBuilder implements RolloutGroupBuilder {
|
||||
|
||||
@Override
|
||||
public RolloutGroupCreate create() {
|
||||
return new JpaRolloutGroupCreate();
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.builder.AbstractRolloutGroupCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
|
||||
|
||||
public class JpaRolloutGroupCreate extends AbstractRolloutGroupCreate<RolloutGroupCreate> implements RolloutGroupCreate {
|
||||
|
||||
/**
|
||||
* Set the Success And Error conditions for the rollout group
|
||||
*
|
||||
* @param group The Rollout group
|
||||
* @param conditions The Rollout Success and Error Conditions
|
||||
*/
|
||||
public static void addSuccessAndErrorConditionsAndActions(final JpaRolloutGroup group,
|
||||
final RolloutGroupConditions conditions) {
|
||||
addSuccessAndErrorConditionsAndActions(group, conditions.getSuccessCondition(),
|
||||
conditions.getSuccessConditionExp(), conditions.getSuccessAction(), conditions.getSuccessActionExp(),
|
||||
conditions.getErrorCondition(), conditions.getErrorConditionExp(), conditions.getErrorAction(),
|
||||
conditions.getErrorActionExp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Success And Error conditions for the rollout group
|
||||
*/
|
||||
@SuppressWarnings("java:S107")
|
||||
public static void addSuccessAndErrorConditionsAndActions(final JpaRolloutGroup group,
|
||||
final RolloutGroup.RolloutGroupSuccessCondition successCondition, final String successConditionExp,
|
||||
final RolloutGroup.RolloutGroupSuccessAction successAction, final String successActionExp,
|
||||
final RolloutGroup.RolloutGroupErrorCondition errorCondition, final String errorConditionExp,
|
||||
final RolloutGroup.RolloutGroupErrorAction errorAction, final String errorActionExp) {
|
||||
group.setSuccessCondition(successCondition);
|
||||
group.setSuccessConditionExp(successConditionExp);
|
||||
|
||||
group.setSuccessAction(successAction);
|
||||
group.setSuccessActionExp(successActionExp);
|
||||
|
||||
group.setErrorCondition(errorCondition);
|
||||
group.setErrorConditionExp(errorConditionExp);
|
||||
|
||||
group.setErrorAction(errorAction);
|
||||
group.setErrorActionExp(errorActionExp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpaRolloutGroup build() {
|
||||
final JpaRolloutGroup group = new JpaRolloutGroup();
|
||||
|
||||
group.setName(name);
|
||||
group.setDescription(description);
|
||||
group.setTargetFilterQuery(targetFilterQuery);
|
||||
|
||||
if (targetPercentage == null) {
|
||||
targetPercentage = 100F;
|
||||
}
|
||||
|
||||
group.setTargetPercentage(targetPercentage);
|
||||
|
||||
if (conditions != null) {
|
||||
addSuccessAndErrorConditionsAndActions(group, conditions);
|
||||
}
|
||||
group.setConfirmationRequired(confirmationRequired);
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,13 @@ import static org.eclipse.hawkbit.repository.model.Action.Status.FINISHED;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
@@ -31,6 +31,7 @@ import org.eclipse.hawkbit.repository.jpa.repository.ActionStatusRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.QuotaHelper;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -64,22 +65,30 @@ public class JpaActionManagement {
|
||||
return DOWNLOAD_ONLY == action.getActionType();
|
||||
}
|
||||
|
||||
protected static JpaActionStatus buildJpaActionStatus(final ActionStatusCreate create) {
|
||||
final JpaActionStatus actionStatus = new JpaActionStatus(
|
||||
create.getStatus(),
|
||||
Optional.ofNullable(create.getOccurredAt()).orElseGet(System::currentTimeMillis));
|
||||
Optional.ofNullable(create.getMessages()).ifPresent(messages -> messages.forEach(actionStatus::addMessage));
|
||||
actionStatus.setCode(create.getCode());
|
||||
return actionStatus;
|
||||
}
|
||||
|
||||
protected List<JpaAction> findActiveActionsHavingStatus(final String controllerId, final Action.Status status) {
|
||||
return actionRepository.findAll(ActionSpecifications.byTargetControllerIdAndIsActiveAndStatus(controllerId, status));
|
||||
}
|
||||
|
||||
protected Action addActionStatus(final JpaActionStatusCreate statusCreate) {
|
||||
final Long actionId = statusCreate.getActionId();
|
||||
final JpaActionStatus actionStatus = statusCreate.build();
|
||||
protected Action addActionStatus(final ActionStatusCreate create) {
|
||||
final Long actionId = create.getActionId();
|
||||
final JpaAction action = getActionAndThrowExceptionIfNotFound(actionId);
|
||||
|
||||
if (isUpdatingActionStatusAllowed(action, actionStatus)) {
|
||||
return handleAddUpdateActionStatus(actionStatus, action);
|
||||
if (isUpdatingActionStatusAllowed(action, create)) {
|
||||
return handleAddUpdateActionStatus(create, action);
|
||||
}
|
||||
|
||||
log.debug(
|
||||
"Update of actionStatus {} for action {} not possible since action not active anymore and not allowed as an action terminating.",
|
||||
actionStatus.getStatus(), action.getId());
|
||||
create.getStatus(), action.getId());
|
||||
return action;
|
||||
}
|
||||
|
||||
@@ -91,7 +100,7 @@ public class JpaActionManagement {
|
||||
// can be overwritten to intercept the persistence of the action status
|
||||
}
|
||||
|
||||
protected void assertActionStatusQuota(final JpaActionStatus newActionStatus, final JpaAction action) {
|
||||
protected void assertActionStatusQuota(final ActionStatusCreate newActionStatus, final JpaAction action) {
|
||||
if (isIntermediateStatus(newActionStatus)) {// check for quota only for intermediate statuses
|
||||
QuotaHelper.assertAssignmentQuota(action.getId(), 1, quotaManagement.getMaxStatusEntriesPerAction(),
|
||||
ActionStatus.class, Action.class, actionStatusRepository::countByActionId);
|
||||
@@ -123,7 +132,7 @@ public class JpaActionManagement {
|
||||
.toList();
|
||||
}
|
||||
|
||||
private static boolean isIntermediateStatus(final JpaActionStatus actionStatus) {
|
||||
private static boolean isIntermediateStatus(final ActionStatusCreate actionStatus) {
|
||||
return FINISHED != actionStatus.getStatus() && ERROR != actionStatus.getStatus();
|
||||
}
|
||||
|
||||
@@ -134,7 +143,7 @@ public class JpaActionManagement {
|
||||
* Status.FINISHED are allowed. In the case of a DOWNLOAD_ONLY action, we accept
|
||||
* status updates only once.
|
||||
*/
|
||||
private boolean isUpdatingActionStatusAllowed(final JpaAction action, final JpaActionStatus actionStatus) {
|
||||
private boolean isUpdatingActionStatusAllowed(final JpaAction action, final ActionStatusCreate actionStatus) {
|
||||
if (action.isActive()) {
|
||||
return true;
|
||||
}
|
||||
@@ -151,9 +160,11 @@ public class JpaActionManagement {
|
||||
/**
|
||||
* Sets {@link TargetUpdateStatus} based on given {@link ActionStatus}.
|
||||
*/
|
||||
private Action handleAddUpdateActionStatus(final JpaActionStatus actionStatus, final JpaAction action) {
|
||||
private Action handleAddUpdateActionStatus(final ActionStatusCreate create, final JpaAction action) {
|
||||
// information status entry - check for a potential DOS attack
|
||||
assertActionStatusQuota(actionStatus, action);
|
||||
assertActionStatusQuota(create, action);
|
||||
|
||||
final JpaActionStatus actionStatus = buildJpaActionStatus(create);
|
||||
assertActionStatusMessageQuota(actionStatus);
|
||||
actionStatus.setAction(action);
|
||||
|
||||
|
||||
@@ -9,26 +9,24 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.management;
|
||||
|
||||
import static org.eclipse.hawkbit.repository.RepositoryConstants.SERVER_MESSAGE_PREFIX;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.repository.ConfirmationManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.RepositoryConstants;
|
||||
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.AutoConfirmationAlreadyActiveException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidConfirmationFeedbackException;
|
||||
import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
@@ -39,6 +37,8 @@ import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.ActionStatusRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionStatusCreate.ActionStatusCreateBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.AutoConfirmationStatus;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
|
||||
@@ -62,18 +62,16 @@ import org.springframework.validation.annotation.Validated;
|
||||
public class JpaConfirmationManagement extends JpaActionManagement implements ConfirmationManagement {
|
||||
|
||||
private final EntityManager entityManager;
|
||||
private final EntityFactory entityFactory;
|
||||
private final TargetRepository targetRepository;
|
||||
|
||||
protected JpaConfirmationManagement(
|
||||
final TargetRepository targetRepository,
|
||||
final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository,
|
||||
final RepositoryProperties repositoryProperties, final QuotaManagement quotaManagement,
|
||||
final EntityManager entityManager, final EntityFactory entityFactory) {
|
||||
final EntityManager entityManager) {
|
||||
super(actionRepository, actionStatusRepository, quotaManagement, repositoryProperties);
|
||||
this.targetRepository = targetRepository;
|
||||
this.entityManager = entityManager;
|
||||
this.entityFactory = entityFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,11 +114,8 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
|
||||
if (deviceMessages != null) {
|
||||
messages.addAll(deviceMessages);
|
||||
}
|
||||
messages.add(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target confirmed action."
|
||||
+ " Therefore, it will be set to the running state to proceed with the deployment.");
|
||||
final ActionStatusCreate statusCreate = createConfirmationActionStatus(action.getId(), code, messages)
|
||||
.status(Status.RUNNING);
|
||||
return addActionStatus((JpaActionStatusCreate) statusCreate);
|
||||
messages.add(SERVER_MESSAGE_PREFIX + "Target confirmed action. Therefore, it will be set to the running state to proceed with the deployment.");
|
||||
return addActionStatus(createConfirmationActionStatus(action.getId(), code, messages).status(Status.RUNNING).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,10 +130,8 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
|
||||
if (deviceMessages != null) {
|
||||
messages.addAll(deviceMessages);
|
||||
}
|
||||
messages.add(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target rejected action. Action will stay in confirmation pending state.");
|
||||
final ActionStatusCreate statusCreate = createConfirmationActionStatus(action.getId(), code, messages)
|
||||
.status(Status.WAIT_FOR_CONFIRMATION);
|
||||
return addActionStatus((JpaActionStatusCreate) statusCreate);
|
||||
messages.add(SERVER_MESSAGE_PREFIX + "Target rejected action. Action will stay in confirmation pending state.");
|
||||
return addActionStatus(createConfirmationActionStatus(action.getId(), code, messages).status(Status.WAIT_FOR_CONFIRMATION).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -186,14 +179,22 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
|
||||
}
|
||||
}
|
||||
|
||||
private ActionStatusCreate createConfirmationActionStatus(final long actionId, final Integer code, final Collection<String> messages) {
|
||||
final ActionStatusCreate statusCreate = entityFactory.actionStatus().create(actionId);
|
||||
if (!CollectionUtils.isEmpty(messages)) {
|
||||
statusCreate.messages(messages);
|
||||
}
|
||||
if (code != null) {
|
||||
private ActionStatusCreateBuilder createConfirmationActionStatus(
|
||||
final long actionId, final Integer code, final Collection<String> messages) {
|
||||
final ActionStatusCreateBuilder statusCreate = ActionStatusCreate.builder().actionId(actionId);
|
||||
if (code == null) {
|
||||
if (!CollectionUtils.isEmpty(messages)) {
|
||||
statusCreate.messages(messages);
|
||||
}
|
||||
} else {
|
||||
statusCreate.code(code);
|
||||
statusCreate.message(String.format(CONFIRMATION_CODE_MSG_PREFIX, code));
|
||||
if (CollectionUtils.isEmpty(messages)) {
|
||||
statusCreate.messages(List.of(String.format(CONFIRMATION_CODE_MSG_PREFIX, code)));
|
||||
} else {
|
||||
final List<String> messagesWithCode = new ArrayList<>(messages);
|
||||
messagesWithCode.add(String.format(CONFIRMATION_CODE_MSG_PREFIX, code));
|
||||
statusCreate.messages(messagesWithCode);
|
||||
}
|
||||
}
|
||||
return statusCreate;
|
||||
}
|
||||
@@ -209,11 +210,8 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
|
||||
log.debug("Auto-confirming action is not necessary, since action {} is in RUNNING state already.", action.getId());
|
||||
return action;
|
||||
}
|
||||
final JpaActionStatus actionStatus = (JpaActionStatus) entityFactory.actionStatus()
|
||||
.create(action.getId())
|
||||
.status(Status.RUNNING)
|
||||
.messages(Collections.singletonList(autoConfirmationStatus.constructActionMessage()))
|
||||
.build();
|
||||
final JpaActionStatus actionStatus = new JpaActionStatus(Status.RUNNING, System.currentTimeMillis());
|
||||
actionStatus.addMessage(autoConfirmationStatus.constructActionMessage());
|
||||
log.debug(
|
||||
"Automatically confirm actionId '{}' due to active auto-confirmation initiated by '{}' and rollouts system user '{}'",
|
||||
action.getId(), autoConfirmationStatus.getInitiator(), autoConfirmationStatus.getCreatedBy());
|
||||
|
||||
@@ -49,7 +49,6 @@ import org.eclipse.hawkbit.repository.ConfirmationManagement;
|
||||
import org.eclipse.hawkbit.repository.ControllerManagement;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.MaintenanceScheduleHelper;
|
||||
import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.RepositoryConstants;
|
||||
@@ -59,7 +58,6 @@ import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.UpdateMode;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.event.EventPublisherHolder;
|
||||
import org.eclipse.hawkbit.repository.event.remote.CancelTargetAssignmentEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAttributesRequestedEvent;
|
||||
@@ -70,7 +68,6 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidTargetAttributeException;
|
||||
import org.eclipse.hawkbit.repository.jpa.Jpa;
|
||||
import org.eclipse.hawkbit.repository.jpa.acm.AccessController;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
|
||||
@@ -91,6 +88,7 @@ import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.DeploymentHelper;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.QuotaHelper;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.AutoConfirmationStatus;
|
||||
@@ -240,17 +238,13 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Action addCancelActionStatus(final ActionStatusCreate c) {
|
||||
final JpaActionStatusCreate create = (JpaActionStatusCreate) c;
|
||||
|
||||
public Action addCancelActionStatus(final ActionStatusCreate create) {
|
||||
final JpaAction action = getActionAndThrowExceptionIfNotFound(create.getActionId());
|
||||
|
||||
if (!action.isCancelingOrCanceled()) {
|
||||
throw new CancelActionNotAllowedException("The action is not in canceling state.");
|
||||
}
|
||||
|
||||
final JpaActionStatus actionStatus = create.build();
|
||||
|
||||
final JpaActionStatus actionStatus = buildJpaActionStatus(create);
|
||||
switch (actionStatus.getStatus()) {
|
||||
case CANCELED, FINISHED: {
|
||||
handleFinishedCancelation(actionStatus, action);
|
||||
@@ -263,7 +257,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
}
|
||||
default: {
|
||||
// information status entry - check for a potential DOS attack
|
||||
assertActionStatusQuota(actionStatus, action);
|
||||
assertActionStatusQuota(create, action);
|
||||
assertActionStatusMessageQuota(actionStatus);
|
||||
break;
|
||||
}
|
||||
@@ -289,16 +283,15 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public ActionStatus addInformationalActionStatus(final ActionStatusCreate c) {
|
||||
final JpaActionStatusCreate create = (JpaActionStatusCreate) c;
|
||||
public ActionStatus addInformationalActionStatus(final ActionStatusCreate create) {
|
||||
final JpaAction action = getActionAndThrowExceptionIfNotFound(create.getActionId());
|
||||
final JpaActionStatus statusMessage = create.build();
|
||||
statusMessage.setAction(action);
|
||||
assertActionStatusQuota(create, action);
|
||||
|
||||
assertActionStatusQuota(statusMessage, action);
|
||||
assertActionStatusMessageQuota(statusMessage);
|
||||
final JpaActionStatus actionStatus = buildJpaActionStatus(create);
|
||||
actionStatus.setAction(action);
|
||||
assertActionStatusMessageQuota(actionStatus);
|
||||
|
||||
return actionStatusRepository.save(statusMessage);
|
||||
return actionStatusRepository.save(actionStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -306,7 +299,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Action addUpdateActionStatus(final ActionStatusCreate statusCreate) {
|
||||
return addActionStatus((JpaActionStatusCreate) statusCreate);
|
||||
return addActionStatus(statusCreate);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,16 +9,14 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.management;
|
||||
|
||||
import static org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupCreate.addSuccessAndErrorConditionsAndActions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jakarta.validation.ConstraintDeclarationException;
|
||||
@@ -40,19 +38,15 @@ import org.eclipse.hawkbit.repository.RolloutManagement;
|
||||
import org.eclipse.hawkbit.repository.RolloutStatusCache;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.DynamicRolloutGroupTemplate;
|
||||
import org.eclipse.hawkbit.repository.builder.GenericRolloutUpdate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutUpdate;
|
||||
import org.eclipse.hawkbit.repository.event.EventPublisherHolder;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
|
||||
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException;
|
||||
import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
|
||||
@@ -80,6 +74,7 @@ import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.utils.ObjectCopyUtil;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -89,7 +84,6 @@ import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.retry.annotation.Backoff;
|
||||
import org.springframework.retry.annotation.Retryable;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -181,14 +175,15 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Rollout create(
|
||||
final RolloutCreate rollout, final int amountGroup, final boolean confirmationRequired,
|
||||
final Create rollout, final int amountGroup, final boolean confirmationRequired,
|
||||
final RolloutGroupConditions conditions, final DynamicRolloutGroupTemplate dynamicRolloutGroupTemplate) {
|
||||
return create0(rollout, amountGroup, confirmationRequired, conditions, dynamicRolloutGroupTemplate);
|
||||
}
|
||||
|
||||
private Rollout create0(
|
||||
final RolloutCreate rollout, final int amountGroup, final boolean confirmationRequired,
|
||||
final Create rollout, final int amountGroup, final boolean confirmationRequired,
|
||||
final RolloutGroupConditions conditions, final DynamicRolloutGroupTemplate dynamicRolloutGroupTemplate) {
|
||||
validateDs(rollout);
|
||||
if (amountGroup < 0) {
|
||||
throw new ValidationException("The amount of groups cannot be lower than or equal to zero for static rollouts");
|
||||
} else if (amountGroup == 0) {
|
||||
@@ -200,7 +195,9 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
RolloutHelper.verifyRolloutGroupAmount(amountGroup, quotaManagement);
|
||||
}
|
||||
|
||||
final JpaRollout rolloutRequest = (JpaRollout) rollout.build();
|
||||
final JpaRollout rolloutRequest = new JpaRollout();
|
||||
ObjectCopyUtil.copy(rollout, rolloutRequest, false, UnaryOperator.identity());
|
||||
rolloutRequest.setDynamic(rollout.isDynamic()); // TODO - copy compares isDynamic == false and don't set it to false - remain null
|
||||
// scheduled rollout, the creator shall have permissions to start rollout
|
||||
if (rolloutRequest.getStartAt() != null && rolloutRequest.getStartAt() != Long.MAX_VALUE && // if scheduled rollout
|
||||
!systemSecurityContext.hasPermission(SpPermission.HANDLE_ROLLOUT) &&
|
||||
@@ -220,7 +217,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Rollout create(
|
||||
@NotNull @Valid RolloutCreate create, int amountGroup, boolean confirmationRequired,
|
||||
@NotNull @Valid Create create, int amountGroup, boolean confirmationRequired,
|
||||
@NotNull RolloutGroupConditions conditions) {
|
||||
return create0(create, amountGroup, confirmationRequired, conditions, null);
|
||||
}
|
||||
@@ -229,29 +226,16 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Rollout create(final RolloutCreate rollout, final List<RolloutGroupCreate> groups, final RolloutGroupConditions conditions) {
|
||||
public Rollout create(final Create rollout, final List<GroupCreate> groups, final RolloutGroupConditions conditions) {
|
||||
if (groups.isEmpty()) {
|
||||
throw new ValidationException("The amount of groups cannot be 0");
|
||||
}
|
||||
validateDs(rollout);
|
||||
RolloutHelper.verifyRolloutGroupAmount(groups.size(), quotaManagement);
|
||||
return createRolloutGroups(groups, conditions, createRollout((JpaRollout) rollout.build(), false));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public CompletableFuture<RolloutGroupsValidation> validateTargetsInGroups(
|
||||
final List<RolloutGroupCreate> groups, final String targetFilter, final Long createdAt, final Long dsTypeId) {
|
||||
|
||||
final TargetCount targets = calculateTargets(targetFilter, createdAt, dsTypeId);
|
||||
long totalTargets = targets.total();
|
||||
final String baseFilter = targets.filter();
|
||||
|
||||
if (totalTargets == 0) {
|
||||
throw new ConstraintDeclarationException("Rollout target filter does not match any targets");
|
||||
}
|
||||
|
||||
return CompletableFuture.completedFuture(
|
||||
validateTargetsInGroups(groups.stream().map(RolloutGroupCreate::build).toList(), baseFilter, totalTargets, dsTypeId));
|
||||
final JpaRollout rolloutRequest = new JpaRollout();
|
||||
ObjectCopyUtil.copy(rollout, rolloutRequest, false, UnaryOperator.identity());
|
||||
rolloutRequest.setDynamic(rollout.isDynamic()); // TODO - copy compares isDynamic == false and don't set it to false - remain null
|
||||
return createRolloutGroups(groups, conditions, createRollout(rolloutRequest, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -413,14 +397,11 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Rollout update(final RolloutUpdate u) {
|
||||
final GenericRolloutUpdate update = (GenericRolloutUpdate) u;
|
||||
public Rollout update(final Update update) {
|
||||
final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(update.getId());
|
||||
|
||||
checkIfDeleted(update.getId(), rollout.getStatus());
|
||||
|
||||
update.getName().ifPresent(rollout::setName);
|
||||
update.getDescription().ifPresent(rollout::setDescription);
|
||||
ObjectCopyUtil.copy(update, rollout, false, UnaryOperator.identity());
|
||||
return rolloutRepository.save(rollout);
|
||||
}
|
||||
|
||||
@@ -492,15 +473,24 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
return rollouts;
|
||||
}
|
||||
|
||||
private static void validateDs(final Create rollout) {
|
||||
if (!rollout.getDistributionSet().isValid()) {
|
||||
throw new InvalidDistributionSetException("The distribution set is not valid");
|
||||
}
|
||||
if (!rollout.getDistributionSet().isComplete()) {
|
||||
throw new IncompleteDistributionSetException("The distribution set is not complete");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In case the given group is missing conditions or actions, they will be set from the supplied default conditions.
|
||||
*
|
||||
* @param create group to check
|
||||
* @param conditions default conditions and actions
|
||||
*/
|
||||
private static JpaRolloutGroup prepareRolloutGroupWithDefaultConditions(
|
||||
final RolloutGroupCreate create, final RolloutGroupConditions conditions) {
|
||||
final JpaRolloutGroup group = ((JpaRolloutGroupCreate) create).build();
|
||||
private static JpaRolloutGroup prepareRolloutGroupWithDefaultConditions(final GroupCreate create, final RolloutGroupConditions conditions) {
|
||||
final JpaRolloutGroup group = new JpaRolloutGroup();
|
||||
ObjectCopyUtil.copy(create, group, false, UnaryOperator.identity());
|
||||
|
||||
if (group.getSuccessCondition() == null) {
|
||||
group.setSuccessCondition(conditions.getSuccessCondition());
|
||||
@@ -554,8 +544,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
distributionSet.getType().getId());
|
||||
errMsg = "No failed targets in Rollout";
|
||||
} else {
|
||||
totalTargets = targetManagement.countByRsqlAndCompatible(rollout.getTargetFilterQuery(),
|
||||
distributionSet.getType().getId());
|
||||
totalTargets = targetManagement.countByRsqlAndCompatible(rollout.getTargetFilterQuery(), distributionSet.getType().getId());
|
||||
errMsg = "Rollout does not match any existing targets";
|
||||
}
|
||||
if (totalTargets == 0) {
|
||||
@@ -575,6 +564,13 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
return rollout;
|
||||
}
|
||||
|
||||
private static void addSuccessAndErrorConditionsAndActions(final JpaRolloutGroup group, final RolloutGroupConditions conditions) {
|
||||
addSuccessAndErrorConditionsAndActions(group, conditions.getSuccessCondition(),
|
||||
conditions.getSuccessConditionExp(), conditions.getSuccessAction(), conditions.getSuccessActionExp(),
|
||||
conditions.getErrorCondition(), conditions.getErrorConditionExp(), conditions.getErrorAction(),
|
||||
conditions.getErrorActionExp());
|
||||
}
|
||||
|
||||
@SuppressWarnings("java:S2259") // java:S2259 - false positive, see the java:S2259 comment in code
|
||||
private Rollout createRolloutGroups(
|
||||
final int amountOfGroups, final RolloutGroupConditions conditions,
|
||||
@@ -649,7 +645,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
}
|
||||
|
||||
private Rollout createRolloutGroups(
|
||||
final List<RolloutGroupCreate> groupList, final RolloutGroupConditions conditions, final JpaRollout rollout) {
|
||||
final List<GroupCreate> groupList, final RolloutGroupConditions conditions, final JpaRollout rollout) {
|
||||
RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.CREATING);
|
||||
final DistributionSetType distributionSetType = rollout.getDistributionSet().getType();
|
||||
|
||||
@@ -706,6 +702,24 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
return savedRollout;
|
||||
}
|
||||
|
||||
public static void addSuccessAndErrorConditionsAndActions(final JpaRolloutGroup group,
|
||||
final RolloutGroup.RolloutGroupSuccessCondition successCondition, final String successConditionExp,
|
||||
final RolloutGroup.RolloutGroupSuccessAction successAction, final String successActionExp,
|
||||
final RolloutGroup.RolloutGroupErrorCondition errorCondition, final String errorConditionExp,
|
||||
final RolloutGroup.RolloutGroupErrorAction errorAction, final String errorActionExp) {
|
||||
group.setSuccessCondition(successCondition);
|
||||
group.setSuccessConditionExp(successConditionExp);
|
||||
|
||||
group.setSuccessAction(successAction);
|
||||
group.setSuccessActionExp(successActionExp);
|
||||
|
||||
group.setErrorCondition(errorCondition);
|
||||
group.setErrorConditionExp(errorConditionExp);
|
||||
|
||||
group.setErrorAction(errorAction);
|
||||
group.setErrorActionExp(errorActionExp);
|
||||
}
|
||||
|
||||
private JpaRollout getRolloutOrThrowExceptionIfNotFound(final Long rolloutId) {
|
||||
return rolloutRepository.findById(rolloutId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
|
||||
|
||||
@@ -154,7 +154,7 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event
|
||||
private Boolean dynamic;
|
||||
|
||||
@Setter
|
||||
@Column(name = "access_control_context", nullable = true)
|
||||
@Column(name = "access_control_context")
|
||||
private String accessControlContext;
|
||||
|
||||
@Setter
|
||||
|
||||
@@ -45,6 +45,7 @@ public class JpaSoftwareModuleType extends AbstractJpaTypeEntity implements Soft
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Setter(value = lombok.AccessLevel.PRIVATE) // used via reflection
|
||||
@Column(name = "max_ds_assignments", nullable = false)
|
||||
@Min(1)
|
||||
private int maxAssignments;
|
||||
|
||||
Reference in New Issue
Block a user