Remove not used WeightValidationHelper (#2916)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -71,7 +71,6 @@ import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
|
||||
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.jpa.utils.WeightValidationHelper;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
@@ -170,7 +169,6 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
public List<DistributionSetAssignmentResult> assignDistributionSets(
|
||||
final List<DeploymentRequest> deploymentRequests, final String actionMessage) {
|
||||
WeightValidationHelper.validate(deploymentRequests);
|
||||
return assignDistributionSets(deploymentRequests, actionMessage, onlineDsAssignmentStrategy);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,6 @@ import org.eclipse.hawkbit.repository.jpa.rollout.condition.StartNextGroupRollou
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.RolloutSpecification;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.QuotaHelper;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.WeightValidationHelper;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.ActionCancellationType;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -718,8 +717,6 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
}
|
||||
|
||||
private JpaRollout createRollout(final JpaRollout rollout, final boolean pureDynamic) {
|
||||
WeightValidationHelper.validate(rollout);
|
||||
|
||||
rollout.setCreatedAt(System.currentTimeMillis());
|
||||
|
||||
final JpaDistributionSet distributionSet = rollout.getDistributionSet();
|
||||
|
||||
@@ -37,7 +37,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetFilterQueryRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetFilterQuerySpecification;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.QuotaHelper;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.WeightValidationHelper;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
@@ -150,7 +149,6 @@ class JpaTargetFilterQueryManagement
|
||||
targetFilterQuery.setAutoAssignInitiatedBy(null);
|
||||
targetFilterQuery.setConfirmationRequired(false);
|
||||
} else {
|
||||
WeightValidationHelper.validate(update);
|
||||
assertMaxTargetsQuota(targetFilterQuery.getQuery(), targetFilterQuery.getName(), update.dsId());
|
||||
|
||||
DistributionSet distributionSet = distributionSetManagement.getValidAndComplete(update.dsId());
|
||||
@@ -215,10 +213,8 @@ class JpaTargetFilterQueryManagement
|
||||
QLSupport.getInstance().validate(query, TargetFields.class, JpaTarget.class);
|
||||
|
||||
// enforce the 'max targets per auto assign' quota right here even if the result of the filter query can vary over time
|
||||
Optional.ofNullable(create.getAutoAssignDistributionSet()).ifPresent(dsId -> {
|
||||
WeightValidationHelper.validate(create);
|
||||
assertMaxTargetsQuota(query, create.getName(), dsId.getId());
|
||||
});
|
||||
Optional.ofNullable(create.getAutoAssignDistributionSet())
|
||||
.ifPresent(dsId -> assertMaxTargetsQuota(query, create.getName(), dsId.getId()));
|
||||
});
|
||||
if (create.getAutoAssignWeight() == null) {
|
||||
create.setAutoAssignWeight(create.getAutoAssignDistributionSet() == null ? 0 : repositoryProperties.getActionWeightIfAbsent());
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2019 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.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.NoWeightProvidedInMultiAssignmentModeException;
|
||||
import org.eclipse.hawkbit.repository.helper.TenantConfigHelper;
|
||||
import org.eclipse.hawkbit.repository.model.DeploymentRequest;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
|
||||
/**
|
||||
* Utility class to handle weight validation in Rollout, Auto Assignments, and Online Assignment.
|
||||
*/
|
||||
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
|
||||
public final class WeightValidationHelper {
|
||||
|
||||
/**
|
||||
* Validating weights associated with all the {@link DeploymentRequest}s
|
||||
*
|
||||
* @param deploymentRequests the {@linkplain List} of {@link DeploymentRequest}s
|
||||
*/
|
||||
public static void validate(final List<DeploymentRequest> deploymentRequests) {
|
||||
final long assignmentsWithWeight = deploymentRequests.stream()
|
||||
.filter(request -> request.getTargetWithActionType().getWeight() != null).count();
|
||||
final boolean containsAssignmentWithWeight = assignmentsWithWeight > 0;
|
||||
final boolean containsAssignmentWithoutWeight = assignmentsWithWeight < deploymentRequests.size();
|
||||
|
||||
validateWeight(containsAssignmentWithWeight, containsAssignmentWithoutWeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validating weight associated with the {@link Rollout}
|
||||
*
|
||||
* @param rollout the {@linkplain Rollout}
|
||||
*/
|
||||
public static void validate(final Rollout rollout) {
|
||||
validateWeight(rollout.getWeight().orElse(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validating weight associated with the target filter query
|
||||
*
|
||||
* @param targetFilterQueryCreate the target filter query
|
||||
*/
|
||||
public static void validate(final TargetFilterQueryManagement.Create targetFilterQueryCreate) {
|
||||
validateWeight(targetFilterQueryCreate.getAutoAssignWeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Validating weight associated with the auto assignment
|
||||
*
|
||||
* @param autoAssignDistributionSetUpdate the auto assignment distribution set update
|
||||
*/
|
||||
public static void validate(final TargetFilterQueryManagement.AutoAssignDistributionSetUpdate autoAssignDistributionSetUpdate) {
|
||||
validateWeight(autoAssignDistributionSetUpdate.weight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the weight is valid
|
||||
*
|
||||
* @param weight weight tied to the rollout, auto assignment, or online assignment.
|
||||
*/
|
||||
public static void validateWeight(final Integer weight) {
|
||||
final boolean hasWeight = weight != null;
|
||||
validateWeight(hasWeight, !hasWeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the weight is valid with the multi-assignments being turned off/on.
|
||||
*
|
||||
* @param hasWeight indicator of the weight if it has numerical value
|
||||
* @param hasNoWeight indicator of the weight if it doesn't have a numerical value
|
||||
*/
|
||||
public static void validateWeight(final boolean hasWeight, final boolean hasNoWeight) {
|
||||
// remove bypassing the weight enforcement as soon as weight can be set via UI
|
||||
final boolean bypassWeightEnforcement = true;
|
||||
if (!bypassWeightEnforcement && hasNoWeight) {
|
||||
throw new NoWeightProvidedInMultiAssignmentModeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user