Refactor caches (#2775)

* added static usage of cache in order access it easier
* added mandatory (in hawkbit-core) registration - always tenant aware caches shall be used - hawkbit depends on it
* added per cache and tenant name configuration
* (not really realted to caches) but in order to be easier evicted entities after commit handlers are now statically accessed

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-10-24 16:42:40 +03:00
committed by GitHub
parent dc8211c64b
commit 98daa696de
48 changed files with 380 additions and 670 deletions

View File

@@ -22,8 +22,8 @@ import org.eclipse.hawkbit.artifact.fs.FileArtifactProperties;
import org.eclipse.hawkbit.artifact.fs.FileArtifactStorage;
import org.eclipse.hawkbit.artifact.urlresolver.PropertyBasedArtifactUrlResolver;
import org.eclipse.hawkbit.artifact.urlresolver.PropertyBasedArtifactUrlResolverProperties;
import org.eclipse.hawkbit.tenancy.cache.TenantAwareCacheManager;
import org.eclipse.hawkbit.im.authentication.Hierarchy;
import org.eclipse.hawkbit.repository.RepositoryConfiguration;
import org.eclipse.hawkbit.repository.RolloutApprovalStrategy;
import org.eclipse.hawkbit.repository.RolloutStatusCache;
import org.eclipse.hawkbit.repository.event.ApplicationEventFilter;
@@ -49,10 +49,10 @@ import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
@@ -78,6 +78,10 @@ import org.springframework.security.concurrent.DelegatingSecurityContextSchedule
@PropertySource("classpath:/hawkbit-test-defaults.properties")
public class TestConfiguration implements AsyncConfigurer {
@Configuration
@Import(RepositoryConfiguration.class)
static class OverridePropertiesSourceFromRepositoryConfiguration {}
@Override
public Executor getAsyncExecutor() {
return asyncExecutor();
@@ -104,7 +108,7 @@ public class TestConfiguration implements AsyncConfigurer {
*/
@Bean
RolloutStatusCache rolloutStatusCache(final TenantAware tenantAware) {
return new RolloutStatusCache(tenantAware, 0);
return new RolloutStatusCache(tenantAware);
}
@Bean
@@ -158,11 +162,6 @@ public class TestConfiguration implements AsyncConfigurer {
return org.mockito.Mockito.spy(new SecurityContextTenantAware(authoritiesResolver, securityContextSerializer, tenantResolver));
}
@Bean
TenantAwareCacheManager cacheManager(final TenantAware tenantAware) {
return new TenantAwareCacheManager(new CaffeineCacheManager(), tenantAware);
}
@Bean(name = AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME)
SimpleApplicationEventMulticaster applicationEventMulticaster(final ApplicationEventFilter applicationEventFilter) {
final SimpleApplicationEventMulticaster simpleApplicationEventMulticaster =

View File

@@ -14,9 +14,9 @@ import java.util.List;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.tenancy.cache.TenantAwareCacheManager;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.TenantAwareCacheManager;
import org.springframework.context.ApplicationContext;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@@ -38,7 +38,6 @@ public class CleanupTestExecutionListener extends AbstractTestExecutionListener
SecurityContextSwitch.callAsPrivileged(() -> {
final ApplicationContext applicationContext = testContext.getApplicationContext();
clearTestRepository(
applicationContext.getBean(TenantAwareCacheManager.class),
applicationContext.getBean(SystemSecurityContext.class),
applicationContext.getBean(SystemManagement.class));
return null;
@@ -46,10 +45,8 @@ public class CleanupTestExecutionListener extends AbstractTestExecutionListener
}
private void clearTestRepository(
final TenantAwareCacheManager cacheManager,
final SystemSecurityContext systemSecurityContext,
final SystemManagement systemManagement) {
final List<String> tenants = systemSecurityContext.runAsSystem(() -> systemManagement.findTenants(PAGE).getContent());
tenants.forEach(tenant -> {
try {
@@ -58,6 +55,6 @@ public class CleanupTestExecutionListener extends AbstractTestExecutionListener
log.error("Error while delete tenant", e);
}
});
cacheManager.getDirectCacheNames().forEach(name -> cacheManager.getDirectCache(name).clear());
TenantAwareCacheManager.getInstance().evictTenant(null);
}
}

View File

@@ -20,9 +20,13 @@ spring.jpa.properties.eclipselink.logging.parameters=true
# Test utility properties for easier fault investigation - END
# Default properties for test that can be overridden during test run - START
# Enforce persistence of targetpolls for test predictability.
# Enforce persistence of target polls for test predictability.
hawkbit.server.repository.eagerPollPersistence=true
# disables Rollout and RoulloutGroup status cache for tests
hawkbit.cache.RolloutStatus.spec=maximumSize=0
hawkbit.cache.RolloutGroupStatus.spec=maximumSize=0
# Default properties for test that can be overridden during test run - END
# Properties that are managed by autoconfigure module at runtime and not available during test - START