Skip to content

Commit

Permalink
Add 1000 weight for actions, rollouts and auto assignments without we…
Browse files Browse the repository at this point in the history
…ight

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm committed Jan 14, 2024
1 parent 3f28484 commit a158415
Show file tree
Hide file tree
Showing 30 changed files with 309 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public class JpaRolloutExecutor implements RolloutExecutor {
private final RolloutApprovalStrategy rolloutApprovalStrategy;
private final RolloutGroupEvaluationManager evaluationManager;
private final RolloutManagement rolloutManagement;
private final RepositoryProperties repositoryProperties;

/**
* Constructor
Expand All @@ -128,8 +127,7 @@ public JpaRolloutExecutor(final RolloutTargetGroupRepository rolloutTargetGroupR
final DeploymentManagement deploymentManagement, final TargetManagement targetManagement,
final EventPublisherHolder eventPublisherHolder, final PlatformTransactionManager txManager,
final RolloutApprovalStrategy rolloutApprovalStrategy,
final RolloutGroupEvaluationManager evaluationManager, final RolloutManagement rolloutManagement,
final RepositoryProperties repositoryProperties) {
final RolloutGroupEvaluationManager evaluationManager, final RolloutManagement rolloutManagement) {
this.rolloutTargetGroupRepository = rolloutTargetGroupRepository;
this.entityManager = entityManager;
this.rolloutRepository = rolloutRepository;
Expand All @@ -146,7 +144,6 @@ public JpaRolloutExecutor(final RolloutTargetGroupRepository rolloutTargetGroupR
this.rolloutApprovalStrategy = rolloutApprovalStrategy;
this.evaluationManager = evaluationManager;
this.rolloutManagement = rolloutManagement;
this.repositoryProperties = repositoryProperties;
}

@Override
Expand Down Expand Up @@ -341,7 +338,7 @@ private void handleRunningRollout(final JpaRollout rollout) {
executeLatestRolloutGroup(rollout);
} else {
LOGGER.debug("Rollout {} has {} running groups", rollout.getId(), rolloutGroupsRunning.size());
executeRolloutGroups(rollout, rolloutGroupsRunning);
executeRolloutGroups(rollout, rolloutGroupsRunning, rollout.getRolloutGroups().get(rollout.getRolloutGroups().size() - 1));
}

if (isRolloutComplete(rollout)) {
Expand Down Expand Up @@ -446,7 +443,7 @@ private RolloutGroup evalProxy(final RolloutGroup group, final List<JpaRolloutGr
}
}

private void executeRolloutGroups(final JpaRollout rollout, final List<JpaRolloutGroup> rolloutGroups) {
private void executeRolloutGroups(final JpaRollout rollout, final List<JpaRolloutGroup> rolloutGroups, final RolloutGroup lastRolloutGroup) {
for (final JpaRolloutGroup rolloutGroup : rolloutGroups) {
final long targetCount = countTargetsFrom(rolloutGroup);
if (rolloutGroup.getTotalTargets() != targetCount) {
Expand All @@ -465,7 +462,7 @@ private void executeRolloutGroups(final JpaRollout rollout, final List<JpaRollou
// not in error so check finished state, do we need to
// start the next group?
checkSuccessCondition(rollout, rolloutGroup, evalProxy, rolloutGroup.getSuccessCondition());
if (!(rolloutGroup == rolloutGroups.get(rolloutGroups.size() - 1) && rolloutGroup.isDynamic()) && isRolloutGroupComplete(rollout, rolloutGroup)) {
if (!(rolloutGroup == lastRolloutGroup && rolloutGroup.isDynamic()) && isRolloutGroupComplete(rollout, rolloutGroup)) {
rolloutGroup.setStatus(RolloutGroupStatus.FINISHED);
rolloutGroupRepository.save(rolloutGroup);
}
Expand Down Expand Up @@ -501,11 +498,11 @@ private void callErrorAction(final Rollout rollout, final RolloutGroup rolloutGr
}

private boolean isRolloutGroupComplete(final JpaRollout rollout, final JpaRolloutGroup rolloutGroup) {
final Long actionsLeftForRollout = ActionType.DOWNLOAD_ONLY == rollout.getActionType()
? actionRepository.countByRolloutAndRolloutGroupAndStatusNotIn(rollout, rolloutGroup,
DOWNLOAD_ONLY_ACTION_TERMINATION_STATUSES)
: actionRepository.countByRolloutAndRolloutGroupAndStatusNotIn(rollout, rolloutGroup,
DEFAULT_ACTION_TERMINATION_STATUSES);
final Long actionsLeftForRollout =
actionRepository.countByRolloutAndRolloutGroupAndStatusNotIn(
rollout, rolloutGroup,
ActionType.DOWNLOAD_ONLY == rollout.getActionType() ?
DOWNLOAD_ONLY_ACTION_TERMINATION_STATUSES : DEFAULT_ACTION_TERMINATION_STATUSES);
return actionsLeftForRollout == 0;
}

Expand Down Expand Up @@ -772,7 +769,7 @@ private Long createActionsForDynamicGroupInNewTransaction(final JpaRollout rollo
final PageRequest pageRequest = PageRequest.of(0, Math.toIntExact(limit));
final Slice<Target> targets = targetManagement.findByNotInGEGroupAndNotInActiveActionGEWeightOrInRolloutAndTargetFilterQueryAndCompatibleAndUpdatable(
pageRequest,
rollout.getId(), rollout.getWeight().orElse(repositoryProperties.getActionWeightIfAbsent()),
rollout.getId(), rollout.getWeight().orElse(1000), // Dynamic rollouts shall always have weight!
rolloutGroupRepository.findByRolloutOrderByIdAsc(rollout).get(0).getId(),
targetFilter, rollout.getDistributionSet().getType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,11 @@ TargetFilterQueryManagement targetFilterQueryManagement(
final VirtualPropertyReplacer virtualPropertyReplacer,
final DistributionSetManagement distributionSetManagement, final QuotaManagement quotaManagement,
final JpaProperties properties, final TenantConfigurationManagement tenantConfigurationManagement,
final RepositoryProperties repositoryProperties,
final SystemSecurityContext systemSecurityContext, final ContextAware contextAware) {
return new JpaTargetFilterQueryManagement(targetFilterQueryRepository, targetManagement,
virtualPropertyReplacer, distributionSetManagement, quotaManagement, properties.getDatabase(),
tenantConfigurationManagement, systemSecurityContext, contextAware);
tenantConfigurationManagement, repositoryProperties, systemSecurityContext, contextAware);
}


Expand Down Expand Up @@ -749,12 +750,11 @@ RolloutExecutor rolloutExecutor(final RolloutTargetGroupRepository rolloutTarget
final DeploymentManagement deploymentManagement, final TargetManagement targetManagement,
final EventPublisherHolder eventPublisherHolder, final PlatformTransactionManager txManager,
final RolloutApprovalStrategy rolloutApprovalStrategy,
final RolloutGroupEvaluationManager evaluationManager, final RolloutManagement rolloutManagement,
final RepositoryProperties repositoryProperties) {
final RolloutGroupEvaluationManager evaluationManager, final RolloutManagement rolloutManagement) {
return new JpaRolloutExecutor(rolloutTargetGroupRepository, entityManager, rolloutRepository, actionRepository,
rolloutGroupRepository, afterCommit, tenantAware, rolloutGroupManagement, quotaManagement,
deploymentManagement, targetManagement, eventPublisherHolder, txManager, rolloutApprovalStrategy,
evaluationManager, rolloutManagement, repositoryProperties);
evaluationManager, rolloutManagement);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.RepositoryConstants;
import org.eclipse.hawkbit.repository.RepositoryProperties;
import org.eclipse.hawkbit.repository.event.remote.CancelTargetAssignmentEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
Expand Down Expand Up @@ -67,12 +68,13 @@ public abstract class AbstractDsAssignmentStrategy {
private final QuotaManagement quotaManagement;
private final BooleanSupplier multiAssignmentsConfig;
private final BooleanSupplier confirmationFlowConfig;
private final RepositoryProperties repositoryProperties;

AbstractDsAssignmentStrategy(final TargetRepository targetRepository,
final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder,
final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository,
final QuotaManagement quotaManagement, final BooleanSupplier multiAssignmentsConfig,
final BooleanSupplier confirmationFlowConfig) {
final BooleanSupplier confirmationFlowConfig, final RepositoryProperties repositoryProperties) {
this.targetRepository = targetRepository;
this.afterCommit = afterCommit;
this.eventPublisherHolder = eventPublisherHolder;
Expand All @@ -81,6 +83,7 @@ public abstract class AbstractDsAssignmentStrategy {
this.quotaManagement = quotaManagement;
this.multiAssignmentsConfig = multiAssignmentsConfig;
this.confirmationFlowConfig = confirmationFlowConfig;
this.repositoryProperties = repositoryProperties;
}

/**
Expand Down Expand Up @@ -252,7 +255,9 @@ public JpaAction createTargetAction(final String initiatedBy, final TargetWithAc
final JpaAction actionForTarget = new JpaAction();
actionForTarget.setActionType(targetWithActionType.getActionType());
actionForTarget.setForcedTime(targetWithActionType.getForceTime());
actionForTarget.setWeight(targetWithActionType.getWeight());
actionForTarget.setWeight(
targetWithActionType.getWeight() == null ?
repositoryProperties.getActionWeightIfAbsent() : targetWithActionType.getWeight());
actionForTarget.setActive(true);
actionForTarget.setTarget(target);
actionForTarget.setDistributionSet(set);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ public JpaDeploymentManagement(final EntityManager entityManager, final ActionRe
this.txManager = txManager;
onlineDsAssignmentStrategy = new OnlineDsAssignmentStrategy(targetRepository, afterCommit, eventPublisherHolder,
actionRepository, actionStatusRepository, quotaManagement, this::isMultiAssignmentsEnabled,
this::isConfirmationFlowEnabled);
this::isConfirmationFlowEnabled, repositoryProperties);
offlineDsAssignmentStrategy = new OfflineDsAssignmentStrategy(targetRepository, afterCommit,
eventPublisherHolder, actionRepository, actionStatusRepository, quotaManagement,
this::isMultiAssignmentsEnabled, this::isConfirmationFlowEnabled);
this::isMultiAssignmentsEnabled, this::isConfirmationFlowEnabled, repositoryProperties);
this.tenantConfigurationManagement = tenantConfigurationManagement;
this.systemSecurityContext = systemSecurityContext;
this.tenantAware = tenantAware;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.RepositoryProperties;
import org.eclipse.hawkbit.repository.RolloutApprovalStrategy;
import org.eclipse.hawkbit.repository.RolloutFields;
import org.eclipse.hawkbit.repository.RolloutHelper;
Expand Down Expand Up @@ -110,6 +111,9 @@ public class JpaRolloutManagement implements RolloutManagement {
RolloutStatus.CREATING, RolloutStatus.PAUSED, RolloutStatus.READY, RolloutStatus.STARTING,
RolloutStatus.WAITING_FOR_APPROVAL, RolloutStatus.APPROVAL_DENIED);

@Autowired
private RepositoryProperties repositoryProperties;

@Autowired
private RolloutRepository rolloutRepository;

Expand Down Expand Up @@ -220,6 +224,9 @@ private JpaRollout createRollout(final JpaRollout rollout) {
throw new ValidationException(errMsg);
}
rollout.setTotalTargets(totalTargets);
if (rollout.getWeight().isEmpty()) {
rollout.setWeight(repositoryProperties.getActionWeightIfAbsent());
}
contextAware.getCurrentContext().ifPresent(rollout::setAccessControlContext);
return rolloutRepository.save(rollout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.RepositoryProperties;
import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.repository.TargetFilterQueryFields;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
Expand Down Expand Up @@ -84,6 +85,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
private final DistributionSetManagement distributionSetManagement;
private final QuotaManagement quotaManagement;
private final TenantConfigurationManagement tenantConfigurationManagement;
private final RepositoryProperties repositoryProperties;
private final SystemSecurityContext systemSecurityContext;
private final ContextAware contextAware;

Expand All @@ -93,6 +95,7 @@ public JpaTargetFilterQueryManagement(final TargetFilterQueryRepository targetFi
final TargetManagement targetManagement, final VirtualPropertyReplacer virtualPropertyReplacer,
final DistributionSetManagement distributionSetManagement, final QuotaManagement quotaManagement,
final Database database, final TenantConfigurationManagement tenantConfigurationManagement,
final RepositoryProperties repositoryProperties,
final SystemSecurityContext systemSecurityContext, final ContextAware contextAware) {
this.targetFilterQueryRepository = targetFilterQueryRepository;
this.targetManagement = targetManagement;
Expand All @@ -101,6 +104,7 @@ public JpaTargetFilterQueryManagement(final TargetFilterQueryRepository targetFi
this.quotaManagement = quotaManagement;
this.database = database;
this.tenantConfigurationManagement = tenantConfigurationManagement;
this.repositoryProperties = repositoryProperties;
this.systemSecurityContext = systemSecurityContext;
this.contextAware = contextAware;
}
Expand Down Expand Up @@ -270,7 +274,7 @@ public TargetFilterQuery updateAutoAssignDS(final AutoAssignDistributionSetUpdat
targetFilterQuery.setAccessControlContext(null);
targetFilterQuery.setAutoAssignDistributionSet(null);
targetFilterQuery.setAutoAssignActionType(null);
targetFilterQuery.setAutoAssignWeight(null);
targetFilterQuery.setAutoAssignWeight(0);
targetFilterQuery.setAutoAssignInitiatedBy(null);
targetFilterQuery.setConfirmationRequired(false);
} else {
Expand All @@ -284,9 +288,11 @@ public TargetFilterQuery updateAutoAssignDS(final AutoAssignDistributionSetUpdat
contextAware.getCurrentContext().ifPresent(targetFilterQuery::setAccessControlContext);
targetFilterQuery.setAutoAssignInitiatedBy(contextAware.getCurrentUsername());
targetFilterQuery.setAutoAssignActionType(sanitizeAutoAssignActionType(update.getActionType()));
targetFilterQuery.setAutoAssignWeight(update.getWeight());
final boolean confirmationRequired = update.isConfirmationRequired() == null ? isConfirmationFlowEnabled()
: update.isConfirmationRequired();
targetFilterQuery.setAutoAssignWeight(
update.getWeight() == null ? repositoryProperties.getActionWeightIfAbsent() : update.getWeight());
final boolean confirmationRequired =
update.isConfirmationRequired() == null ?
isConfirmationFlowEnabled() : update.isConfirmationRequired();
targetFilterQuery.setConfirmationRequired(confirmationRequired);
}
return targetFilterQueryRepository.save(targetFilterQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.RepositoryConstants;
import org.eclipse.hawkbit.repository.RepositoryProperties;
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
import org.eclipse.hawkbit.repository.jpa.acm.AccessController;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
Expand Down Expand Up @@ -52,9 +53,9 @@ public class OfflineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder,
final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository,
final QuotaManagement quotaManagement, final BooleanSupplier multiAssignmentsConfig,
final BooleanSupplier confirmationFlowConfig) {
final BooleanSupplier confirmationFlowConfig, final RepositoryProperties repositoryProperties) {
super(targetRepository, afterCommit, eventPublisherHolder, actionRepository, actionStatusRepository,
quotaManagement, multiAssignmentsConfig, confirmationFlowConfig);
quotaManagement, multiAssignmentsConfig, confirmationFlowConfig, repositoryProperties);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.stream.Stream;

import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.RepositoryProperties;
import org.eclipse.hawkbit.repository.event.remote.MultiActionAssignEvent;
import org.eclipse.hawkbit.repository.event.remote.MultiActionCancelEvent;
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
Expand Down Expand Up @@ -55,9 +56,9 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder,
final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository,
final QuotaManagement quotaManagement, final BooleanSupplier multiAssignmentsConfig,
final BooleanSupplier confirmationFlowConfig) {
final BooleanSupplier confirmationFlowConfig, final RepositoryProperties repositoryProperties) {
super(targetRepository, afterCommit, eventPublisherHolder, actionRepository, actionStatusRepository,
quotaManagement, multiAssignmentsConfig, confirmationFlowConfig);
quotaManagement, multiAssignmentsConfig, confirmationFlowConfig, repositoryProperties);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event
@Max(Action.WEIGHT_MAX)
private Integer weight;

@Column(name = "dynamic")
@Column(name = "is_dynamic") // dynamic is reserved keyword in some databases
private Boolean dynamic;

@Column(name = "access_control_context", nullable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGr
@JoinColumn(name = "parent_id")
private JpaRolloutGroup parent;

@Column(name = "dynamic")
@Column(name = "is_dynamic") // dynamic is reserved keyword in some databases
private boolean dynamic;

@Column(name = "success_condition", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public JpaTargetFilterQuery(final String name, final String query, final Distrib
this.query = query;
this.autoAssignDistributionSet = (JpaDistributionSet) autoAssignDistributionSet;
this.autoAssignActionType = autoAssignActionType;
this.autoAssignWeight = autoAssignWeight;
this.autoAssignWeight = autoAssignWeight == null ? 0 : autoAssignWeight;
this.confirmationRequired = confirmationRequired;
}

Expand Down

0 comments on commit a158415

Please sign in to comment.