From 299d7091a2adc684613d6b3624dfdf970ae0735b Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Sat, 23 Nov 2024 16:52:06 +0200 Subject: [PATCH] Reomve a @Cacheable that might not work (#2102) Signed-off-by: Avgustin Marinov --- .../cache/CacheAutoConfiguration.java | 17 +++++++---------- .../autoconfigure/cache/CacheProperties.java | 5 ++--- .../hawkbit/cache/TenantAwareCacheManager.java | 9 +++------ .../JpaTenantConfigurationManagement.java | 14 ++++++++------ 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheAutoConfiguration.java index e5a6c4986..2e0464a20 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheAutoConfiguration.java @@ -26,7 +26,7 @@ import org.springframework.context.annotation.Primary; /** * A configuration for configuring the spring {@link CacheManager} for specific multi-tenancy caching. The caches between * tenants must not interfere each other. - * + *

* This is done by providing a special {@link TenancyCacheManager} which generates a cache name included the current tenant. */ @Configuration @@ -39,14 +39,14 @@ public class CacheAutoConfiguration { @Bean @ConditionalOnMissingBean @Primary - TenancyCacheManager cacheManager(@Qualifier("directCacheManager") final CacheManager directCacheManager, + TenancyCacheManager cacheManager( + @Qualifier("directCacheManager") final CacheManager directCacheManager, final TenantAware tenantAware) { return new TenantAwareCacheManager(directCacheManager, tenantAware); } /** - * A separate configuration of the direct cache manager for the - * {@link TenantAwareCacheManager} that it can get overridden by another + * A separate configuration of the direct cache manager for the {@link TenantAwareCacheManager} that it can get overridden by another * configuration. */ @Configuration @@ -54,10 +54,8 @@ public class CacheAutoConfiguration { static class DirectCacheManagerConfiguration { /** - * @return the direct cache manager to access without tenant aware - * check, cause in sometimes it's necessary to access the cache - * directly without having the current tenant, e.g. initial - * creation of tenant + * @return the direct cache manager to access without tenant aware check, cause in sometimes it's necessary to access the cache + * directly without having the current tenant, e.g. initial creation of tenant */ @Bean(name = "directCacheManager") @ConditionalOnMissingBean(name = "directCacheManager") @@ -72,6 +70,5 @@ public class CacheAutoConfiguration { return cacheManager; } - } -} +} \ No newline at end of file diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheProperties.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheProperties.java index e759e93c0..0166a4fd3 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheProperties.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheProperties.java @@ -15,9 +15,8 @@ import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; /** - * Properties for configuring the cache within a cluster. The TTL (time to live) - * is used for the lifetime limit of data in caches. After lifetime the data - * gets reloaded out of the database. + * Properties for configuring the cache within a cluster. The TTL (time to live) is used for the lifetime limit of data in caches. + * After lifetime the data gets reloaded out of the database. */ @Data @ConfigurationProperties("hawkbit.cache.global") diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java index 6733b11e1..79e06e8ce 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java @@ -17,12 +17,9 @@ import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; /** - * A {@link CacheManager} delegator which wraps the - * {@link CacheManager#getCache(String)} and - * {@link CacheManager#getCacheNames()} to include the - * {@link TenantAware#getCurrentTenant()} when accessing a cache, so caches are - * seperated. - * + * A {@link CacheManager} delegator which wraps the {@link CacheManager#getCache(String)} and {@link CacheManager#getCacheNames()} + * to include the {@link TenantAware#getCurrentTenant()} when accessing a cache, so caches are seperated. + *

* Additionally, it also provides functionality to retrieve all caches overall tenants at once, for monitoring and system access. */ public class TenantAwareCacheManager implements TenancyCacheManager { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTenantConfigurationManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTenantConfigurationManagement.java index e7ee20b21..421fd9e33 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTenantConfigurationManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTenantConfigurationManagement.java @@ -58,7 +58,8 @@ import org.springframework.validation.annotation.Validated; @Validated public class JpaTenantConfigurationManagement implements TenantConfigurationManagement { - private static final ConfigurableConversionService conversionService = new DefaultConversionService(); + private static final ConfigurableConversionService CONVERSION_SERVICE = new DefaultConversionService(); + @Autowired private TenantConfigurationRepository tenantConfigurationRepository; @Autowired @@ -87,7 +88,7 @@ public class JpaTenantConfigurationManagement implements TenantConfigurationMana public Map> addOrUpdateConfiguration(Map configurations) { // Register a callback to be invoked after the transaction is committed - for cache eviction afterCommitExecutor.afterCommit(() -> { - Cache cache = cacheManager.getCache("tenantConfiguration"); + final Cache cache = cacheManager.getCache("tenantConfiguration"); if (cache != null) { configurations.keySet().forEach(cache::evict); } @@ -116,7 +117,8 @@ public class JpaTenantConfigurationManagement implements TenantConfigurationMana } @Override - @Cacheable(value = "tenantConfiguration", key = "#configurationKeyName") +// TODO - check if cache works +// @Cacheable(value = "tenantConfiguration", key = "#configurationKeyName") public TenantConfigurationValue getConfigurationValue( final String configurationKeyName, final Class propertyType) { checkAccess(configurationKeyName); @@ -141,7 +143,7 @@ public class JpaTenantConfigurationManagement implements TenantConfigurationMana "Cannot parse the database value of type %s into the type %s.", key.getDataType(), propertyType)); } - return conversionService.convert(key.getDefaultValue(), propertyType); + return CONVERSION_SERVICE.convert(key.getDefaultValue(), propertyType); } /** @@ -214,7 +216,7 @@ public class JpaTenantConfigurationManagement implements TenantConfigurationMana .createdAt(updatedTenantConfiguration.getCreatedAt()) .lastModifiedAt(updatedTenantConfiguration.getLastModifiedAt()) .lastModifiedBy(updatedTenantConfiguration.getLastModifiedBy()) - .value(conversionService.convert(updatedTenantConfiguration.getValue(), clazzT)) + .value(CONVERSION_SERVICE.convert(updatedTenantConfiguration.getValue(), clazzT)) .build(); })); } @@ -227,7 +229,7 @@ public class JpaTenantConfigurationManagement implements TenantConfigurationMana .createdAt(tenantConfiguration.getCreatedAt()) .lastModifiedAt(tenantConfiguration.getLastModifiedAt()) .lastModifiedBy(tenantConfiguration.getLastModifiedBy()) - .value(conversionService.convert(tenantConfiguration.getValue(), propertyType)).build(); + .value(CONVERSION_SERVICE.convert(tenantConfiguration.getValue(), propertyType)).build(); } else if (configurationKey.getDefaultValue() != null) {