Decouple auto assign check (#1000)
* Introduce auto assign executer interface to override check method. * Add copyright header. * Move documentation to interface. Annotate the AutoAssignExecutor as FunctionalInterface. * Rename method to match interface name Signed-off-by: Michael Herdt <Michael.Herdt2@bosch-si.com>
This commit is contained in:
@@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -39,6 +39,7 @@ import org.eclipse.hawkbit.repository.TargetManagement;
|
|||||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||||
import org.eclipse.hawkbit.repository.TenantStatsManagement;
|
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.DistributionSetBuilder;
|
||||||
import org.eclipse.hawkbit.repository.builder.DistributionSetTypeBuilder;
|
import org.eclipse.hawkbit.repository.builder.DistributionSetTypeBuilder;
|
||||||
import org.eclipse.hawkbit.repository.builder.RolloutBuilder;
|
import org.eclipse.hawkbit.repository.builder.RolloutBuilder;
|
||||||
@@ -756,9 +757,9 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
|||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
AutoAssignChecker autoAssignChecker(final TargetFilterQueryManagement targetFilterQueryManagement,
|
AutoAssignExecutor autoAssignExecutor(final TargetFilterQueryManagement targetFilterQueryManagement,
|
||||||
final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
|
final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
|
||||||
final PlatformTransactionManager transactionManager) {
|
final PlatformTransactionManager transactionManager) {
|
||||||
return new AutoAssignChecker(targetFilterQueryManagement, targetManagement, deploymentManagement,
|
return new AutoAssignChecker(targetFilterQueryManagement, targetManagement, deploymentManagement,
|
||||||
transactionManager);
|
transactionManager);
|
||||||
}
|
}
|
||||||
@@ -787,10 +788,10 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
|||||||
// test
|
// test
|
||||||
@Profile("!test")
|
@Profile("!test")
|
||||||
@ConditionalOnProperty(prefix = "hawkbit.autoassign.scheduler", name = "enabled", matchIfMissing = true)
|
@ConditionalOnProperty(prefix = "hawkbit.autoassign.scheduler", name = "enabled", matchIfMissing = true)
|
||||||
AutoAssignScheduler autoAssignScheduler(final TenantAware tenantAware, final SystemManagement systemManagement,
|
AutoAssignScheduler autoAssignScheduler(final SystemManagement systemManagement,
|
||||||
final SystemSecurityContext systemSecurityContext, final AutoAssignChecker autoAssignChecker,
|
final SystemSecurityContext systemSecurityContext, final AutoAssignExecutor autoAssignExecutor,
|
||||||
final LockRegistry lockRegistry) {
|
final LockRegistry lockRegistry) {
|
||||||
return new AutoAssignScheduler(systemManagement, systemSecurityContext, autoAssignChecker, lockRegistry);
|
return new AutoAssignScheduler(systemManagement, systemSecurityContext, autoAssignExecutor, lockRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
|||||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
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.jpa.utils.DeploymentHelper;
|
||||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||||
import org.eclipse.hawkbit.repository.model.DeploymentRequest;
|
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
|
* 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.
|
* 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);
|
private static final Logger LOGGER = LoggerFactory.getLogger(AutoAssignChecker.class);
|
||||||
|
|
||||||
@@ -58,8 +59,8 @@ public class AutoAssignChecker {
|
|||||||
private static final int PAGE_SIZE = 1000;
|
private static final int PAGE_SIZE = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The message which is added to the action status when a distribution set
|
* The message which is added to the action status when a distribution set is
|
||||||
* is assigned to an target. First %s is the name of the target filter.
|
* 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";
|
private static final String ACTION_MESSAGE = "Auto assignment by target filter: %s";
|
||||||
|
|
||||||
@@ -84,11 +85,7 @@ public class AutoAssignChecker {
|
|||||||
this.transactionManager = transactionManager;
|
this.transactionManager = transactionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||||
public void check() {
|
public void check() {
|
||||||
LOGGER.debug("Auto assigned check call");
|
LOGGER.debug("Auto assigned check call");
|
||||||
@@ -106,8 +103,8 @@ public class AutoAssignChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the distribution set, gets all controllerIds and assigns the DS
|
* Fetches the distribution set, gets all controllerIds and assigns the DS to
|
||||||
* to them. Catches PersistenceException and own exceptions derived from
|
* them. Catches PersistenceException and own exceptions derived from
|
||||||
* AbstractServerRtException
|
* AbstractServerRtException
|
||||||
*
|
*
|
||||||
* @param targetFilterQuery
|
* @param targetFilterQuery
|
||||||
@@ -162,8 +159,7 @@ public class AutoAssignChecker {
|
|||||||
* @param targetFilterQuery
|
* @param targetFilterQuery
|
||||||
* the query the targets have to match
|
* the query the targets have to match
|
||||||
* @param dsId
|
* @param dsId
|
||||||
* dsId the targets are not allowed to have in their action
|
* dsId the targets are not allowed to have in their action history
|
||||||
* history
|
|
||||||
* @param type
|
* @param type
|
||||||
* action type for targets auto assignment
|
* action type for targets auto assignment
|
||||||
* @param count
|
* @param count
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.autoassign;
|
|||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||||
|
import org.eclipse.hawkbit.repository.autoassign.AutoAssignExecutor;
|
||||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -29,7 +30,7 @@ public class AutoAssignScheduler {
|
|||||||
|
|
||||||
private final SystemSecurityContext systemSecurityContext;
|
private final SystemSecurityContext systemSecurityContext;
|
||||||
|
|
||||||
private final AutoAssignChecker autoAssignChecker;
|
private final AutoAssignExecutor autoAssignExecutor;
|
||||||
|
|
||||||
private final LockRegistry lockRegistry;
|
private final LockRegistry lockRegistry;
|
||||||
|
|
||||||
@@ -40,17 +41,17 @@ public class AutoAssignScheduler {
|
|||||||
* to find all tenants
|
* to find all tenants
|
||||||
* @param systemSecurityContext
|
* @param systemSecurityContext
|
||||||
* to run as system
|
* to run as system
|
||||||
* @param autoAssignChecker
|
* @param autoAssignExecutor
|
||||||
* to run a check as tenant
|
* to run a check as tenant
|
||||||
* @param lockRegistry
|
* @param lockRegistry
|
||||||
* to acquire a lock per tenant
|
* to acquire a lock per tenant
|
||||||
*/
|
*/
|
||||||
public AutoAssignScheduler(final SystemManagement systemManagement,
|
public AutoAssignScheduler(final SystemManagement systemManagement,
|
||||||
final SystemSecurityContext systemSecurityContext, final AutoAssignChecker autoAssignChecker,
|
final SystemSecurityContext systemSecurityContext, final AutoAssignExecutor autoAssignExecutor,
|
||||||
final LockRegistry lockRegistry) {
|
final LockRegistry lockRegistry) {
|
||||||
this.systemManagement = systemManagement;
|
this.systemManagement = systemManagement;
|
||||||
this.systemSecurityContext = systemSecurityContext;
|
this.systemSecurityContext = systemSecurityContext;
|
||||||
this.autoAssignChecker = autoAssignChecker;
|
this.autoAssignExecutor = autoAssignExecutor;
|
||||||
this.lockRegistry = lockRegistry;
|
this.lockRegistry = lockRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +83,7 @@ public class AutoAssignScheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
systemManagement.forEachTenant(tenant -> autoAssignChecker.check());
|
systemManagement.forEachTenant(tenant -> autoAssignExecutor.check());
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user