MIFOSX-259: ensure cache type persisted in database is used when platform starts up.
This commit is contained in:
Vendored
+2
-1
@@ -51,7 +51,8 @@ public class CacheApiResource {
|
||||
private final RuntimeDelegatingCacheManager cacheService;
|
||||
|
||||
@Autowired
|
||||
public CacheApiResource(final PlatformSecurityContext context, @Qualifier("runtimeDelegatingCacheManager") final RuntimeDelegatingCacheManager cacheService,
|
||||
public CacheApiResource(final PlatformSecurityContext context,
|
||||
@Qualifier("runtimeDelegatingCacheManager") final RuntimeDelegatingCacheManager cacheService,
|
||||
final DefaultToApiJsonSerializer<CacheData> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.context = context;
|
||||
|
||||
+13
-9
@@ -30,11 +30,12 @@ public class RuntimeDelegatingCacheManager implements CacheManager {
|
||||
|
||||
private final EhCacheCacheManager ehcacheCacheManager;
|
||||
private final CacheManager noOpCacheManager = new NoOpCacheManager();
|
||||
private CacheManager currentCacheManager = this.noOpCacheManager;
|
||||
private CacheManager currentCacheManager;
|
||||
|
||||
@Autowired
|
||||
public RuntimeDelegatingCacheManager(final EhCacheCacheManager ehCacheCacheManager) {
|
||||
this.ehcacheCacheManager = ehCacheCacheManager;
|
||||
this.currentCacheManager = this.noOpCacheManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,19 +50,22 @@ public class RuntimeDelegatingCacheManager implements CacheManager {
|
||||
|
||||
public Collection<CacheData> retrieveAll() {
|
||||
|
||||
final boolean ehcacheEnabled = false;
|
||||
final boolean noCacheEnabled = !ehcacheEnabled;
|
||||
final boolean distributedCacheEnabled = false;
|
||||
final boolean noCacheEnabled = this.currentCacheManager instanceof NoOpCacheManager;
|
||||
final boolean ehcacheEnabled = this.currentCacheManager instanceof EhCacheCacheManager;
|
||||
|
||||
// final boolean distributedCacheEnabled = false;
|
||||
|
||||
final EnumOptionData noCacheType = CacheEnumerations.cacheType(CacheType.NO_CACHE);
|
||||
final EnumOptionData singleNodeCacheType = CacheEnumerations.cacheType(CacheType.SINGLE_NODE);
|
||||
final EnumOptionData multiNodeCacheType = CacheEnumerations.cacheType(CacheType.MULTI_NODE);
|
||||
// final EnumOptionData multiNodeCacheType =
|
||||
// CacheEnumerations.cacheType(CacheType.MULTI_NODE);
|
||||
|
||||
final CacheData noCache = CacheData.instance(noCacheType, noCacheEnabled);
|
||||
final CacheData singleNodeCache = CacheData.instance(singleNodeCacheType, ehcacheEnabled);
|
||||
final CacheData distributedCache = CacheData.instance(multiNodeCacheType, distributedCacheEnabled);
|
||||
// final CacheData distributedCache =
|
||||
// CacheData.instance(multiNodeCacheType, distributedCacheEnabled);
|
||||
|
||||
final Collection<CacheData> caches = Arrays.asList(noCache, singleNodeCache, distributedCache);
|
||||
final Collection<CacheData> caches = Arrays.asList(noCache, singleNodeCache);
|
||||
return caches;
|
||||
}
|
||||
|
||||
@@ -78,15 +82,15 @@ public class RuntimeDelegatingCacheManager implements CacheManager {
|
||||
case NO_CACHE:
|
||||
if (!noCacheEnabled) {
|
||||
changes.put(CacheApiConstants.cacheTypeParameter, toCacheType.getValue());
|
||||
this.currentCacheManager = this.noOpCacheManager;
|
||||
}
|
||||
this.currentCacheManager = this.noOpCacheManager;
|
||||
break;
|
||||
case SINGLE_NODE:
|
||||
if (!ehcacheEnabled) {
|
||||
changes.put(CacheApiConstants.cacheTypeParameter, toCacheType.getValue());
|
||||
clearEhCache();
|
||||
this.currentCacheManager = this.ehcacheCacheManager;
|
||||
}
|
||||
this.currentCacheManager = this.ehcacheCacheManager;
|
||||
break;
|
||||
case MULTI_NODE:
|
||||
if (!distributedCacheEnabled) {
|
||||
|
||||
+20
-1
@@ -15,6 +15,9 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.time.StopWatch;
|
||||
import org.mifosplatform.infrastructure.cache.domain.CacheType;
|
||||
import org.mifosplatform.infrastructure.cache.service.CacheWritePlatformService;
|
||||
import org.mifosplatform.infrastructure.configuration.domain.ConfigurationDomainService;
|
||||
import org.mifosplatform.infrastructure.core.domain.MifosPlatformTenant;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
@@ -48,10 +51,13 @@ import org.springframework.stereotype.Service;
|
||||
@Service(value = "basicAuthenticationProcessingFilter")
|
||||
public class TenantAwareBasicAuthenticationFilter extends BasicAuthenticationFilter {
|
||||
|
||||
private static boolean firstRequestProcessed = false;
|
||||
private final static Logger logger = LoggerFactory.getLogger(TenantAwareBasicAuthenticationFilter.class);
|
||||
|
||||
private final BasicAuthTenantDetailsService basicAuthTenantDetailsService;
|
||||
private final ToApiJsonSerializer<PlatformRequestLog> toApiJsonSerializer;
|
||||
private final ConfigurationDomainService configurationDomainService;
|
||||
private final CacheWritePlatformService cacheWritePlatformService;
|
||||
|
||||
private final String tenantRequestHeader = "X-Mifos-Platform-TenantId";
|
||||
private final boolean exceptionIfHeaderMissing = true;
|
||||
@@ -60,10 +66,13 @@ public class TenantAwareBasicAuthenticationFilter extends BasicAuthenticationFil
|
||||
public TenantAwareBasicAuthenticationFilter(final AuthenticationManager authenticationManager,
|
||||
final AuthenticationEntryPoint authenticationEntryPoint,
|
||||
final BasicAuthTenantDetailsService basicAuthTenantDetailsService,
|
||||
final ToApiJsonSerializer<PlatformRequestLog> toApiJsonSerializer) {
|
||||
final ToApiJsonSerializer<PlatformRequestLog> toApiJsonSerializer,
|
||||
final ConfigurationDomainService configurationDomainService, final CacheWritePlatformService cacheWritePlatformService) {
|
||||
super(authenticationManager, authenticationEntryPoint);
|
||||
this.basicAuthTenantDetailsService = basicAuthTenantDetailsService;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
this.configurationDomainService = configurationDomainService;
|
||||
this.cacheWritePlatformService = cacheWritePlatformService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,6 +104,16 @@ public class TenantAwareBasicAuthenticationFilter extends BasicAuthenticationFil
|
||||
final MifosPlatformTenant tenant = this.basicAuthTenantDetailsService.loadTenantById(tenantIdentifier);
|
||||
|
||||
ThreadLocalContextUtil.setTenant(tenant);
|
||||
|
||||
if (!firstRequestProcessed) {
|
||||
final boolean ehcacheEnabled = this.configurationDomainService.isEhcacheEnabled();
|
||||
if (ehcacheEnabled) {
|
||||
this.cacheWritePlatformService.switchToCache(CacheType.SINGLE_NODE);
|
||||
} else {
|
||||
this.cacheWritePlatformService.switchToCache(CacheType.NO_CACHE);
|
||||
}
|
||||
TenantAwareBasicAuthenticationFilter.firstRequestProcessed = true;
|
||||
}
|
||||
}
|
||||
|
||||
super.doFilter(req, res, chain);
|
||||
|
||||
Reference in New Issue
Block a user