diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/autoassign/AutoAssignExecutor.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/autoassign/AutoAssignExecutor.java new file mode 100644 index 000000000..b97f2f063 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/autoassign/AutoAssignExecutor.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2020 Bosch.IO GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.autoassign; + +/** + * An interface declaration which contains the check for the auto assignment + * logic. + */ +@FunctionalInterface +public interface AutoAssignExecutor { + + /** + * Checks all target filter queries with an auto assign distribution set and + * triggers the check and assignment to targets that don't have the design DS + * yet + */ + void check(); + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java index 2b7470689..7e93673be 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java @@ -39,6 +39,7 @@ import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantStatsManagement; +import org.eclipse.hawkbit.repository.autoassign.AutoAssignExecutor; import org.eclipse.hawkbit.repository.builder.DistributionSetBuilder; import org.eclipse.hawkbit.repository.builder.DistributionSetTypeBuilder; import org.eclipse.hawkbit.repository.builder.RolloutBuilder; @@ -756,9 +757,9 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { */ @Bean @ConditionalOnMissingBean - AutoAssignChecker autoAssignChecker(final TargetFilterQueryManagement targetFilterQueryManagement, - final TargetManagement targetManagement, final DeploymentManagement deploymentManagement, - final PlatformTransactionManager transactionManager) { + AutoAssignExecutor autoAssignExecutor(final TargetFilterQueryManagement targetFilterQueryManagement, + final TargetManagement targetManagement, final DeploymentManagement deploymentManagement, + final PlatformTransactionManager transactionManager) { return new AutoAssignChecker(targetFilterQueryManagement, targetManagement, deploymentManagement, transactionManager); } @@ -787,10 +788,10 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { // test @Profile("!test") @ConditionalOnProperty(prefix = "hawkbit.autoassign.scheduler", name = "enabled", matchIfMissing = true) - AutoAssignScheduler autoAssignScheduler(final TenantAware tenantAware, final SystemManagement systemManagement, - final SystemSecurityContext systemSecurityContext, final AutoAssignChecker autoAssignChecker, + AutoAssignScheduler autoAssignScheduler(final SystemManagement systemManagement, + final SystemSecurityContext systemSecurityContext, final AutoAssignExecutor autoAssignExecutor, final LockRegistry lockRegistry) { - return new AutoAssignScheduler(systemManagement, systemSecurityContext, autoAssignChecker, lockRegistry); + return new AutoAssignScheduler(systemManagement, systemSecurityContext, autoAssignExecutor, lockRegistry); } /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignChecker.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignChecker.java index 49bfd7b9f..1f2fb70cd 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignChecker.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignChecker.java @@ -17,6 +17,7 @@ import org.eclipse.hawkbit.exception.AbstractServerRtException; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.autoassign.AutoAssignExecutor; import org.eclipse.hawkbit.repository.jpa.utils.DeploymentHelper; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.DeploymentRequest; @@ -39,7 +40,7 @@ import org.springframework.transaction.annotation.Transactional; * retrieved. All targets get listed per target filter query, that match the TFQ * and that don't have the auto assign DS in their action history. */ -public class AutoAssignChecker { +public class AutoAssignChecker implements AutoAssignExecutor { private static final Logger LOGGER = LoggerFactory.getLogger(AutoAssignChecker.class); @@ -58,8 +59,8 @@ public class AutoAssignChecker { private static final int PAGE_SIZE = 1000; /** - * The message which is added to the action status when a distribution set - * is assigned to an target. First %s is the name of the target filter. + * The message which is added to the action status when a distribution set is + * assigned to an target. First %s is the name of the target filter. */ private static final String ACTION_MESSAGE = "Auto assignment by target filter: %s"; @@ -84,11 +85,7 @@ public class AutoAssignChecker { this.transactionManager = transactionManager; } - /** - * Checks all target filter queries with an auto assign distribution set and - * triggers the check and assignment to targets that don't have the design - * DS yet - */ + @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public void check() { LOGGER.debug("Auto assigned check call"); @@ -106,8 +103,8 @@ public class AutoAssignChecker { } /** - * Fetches the distribution set, gets all controllerIds and assigns the DS - * to them. Catches PersistenceException and own exceptions derived from + * Fetches the distribution set, gets all controllerIds and assigns the DS to + * them. Catches PersistenceException and own exceptions derived from * AbstractServerRtException * * @param targetFilterQuery @@ -162,8 +159,7 @@ public class AutoAssignChecker { * @param targetFilterQuery * the query the targets have to match * @param dsId - * dsId the targets are not allowed to have in their action - * history + * dsId the targets are not allowed to have in their action history * @param type * action type for targets auto assignment * @param count diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignScheduler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignScheduler.java index bacedf55f..0e446b806 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignScheduler.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignScheduler.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.autoassign; import java.util.concurrent.locks.Lock; import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.repository.autoassign.AutoAssignExecutor; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,7 +30,7 @@ public class AutoAssignScheduler { private final SystemSecurityContext systemSecurityContext; - private final AutoAssignChecker autoAssignChecker; + private final AutoAssignExecutor autoAssignExecutor; private final LockRegistry lockRegistry; @@ -40,17 +41,17 @@ public class AutoAssignScheduler { * to find all tenants * @param systemSecurityContext * to run as system - * @param autoAssignChecker + * @param autoAssignExecutor * to run a check as tenant * @param lockRegistry * to acquire a lock per tenant */ public AutoAssignScheduler(final SystemManagement systemManagement, - final SystemSecurityContext systemSecurityContext, final AutoAssignChecker autoAssignChecker, + final SystemSecurityContext systemSecurityContext, final AutoAssignExecutor autoAssignExecutor, final LockRegistry lockRegistry) { this.systemManagement = systemManagement; this.systemSecurityContext = systemSecurityContext; - this.autoAssignChecker = autoAssignChecker; + this.autoAssignExecutor = autoAssignExecutor; this.lockRegistry = lockRegistry; } @@ -82,7 +83,7 @@ public class AutoAssignScheduler { } try { - systemManagement.forEachTenant(tenant -> autoAssignChecker.check()); + systemManagement.forEachTenant(tenant -> autoAssignExecutor.check()); } finally { lock.unlock(); }