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