Skip to content
Snippets Groups Projects
Commit 8cafbc6f authored by Bill Wang's avatar Bill Wang
Browse files

fix cache dependency

parent 8a1e51bd
No related branches found
No related tags found
1 merge request!191EKS Deploy
...@@ -14,27 +14,64 @@ ...@@ -14,27 +14,64 @@
package org.opengroup.osdu.indexer.aws.cache; package org.opengroup.osdu.indexer.aws.cache;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.opengroup.osdu.core.common.cache.ICache;
import org.opengroup.osdu.core.common.cache.RedisCache; import org.opengroup.osdu.core.common.cache.RedisCache;
import org.opengroup.osdu.core.common.cache.VmCache;
import org.opengroup.osdu.core.aws.cache.DummyCache;
import org.opengroup.osdu.core.aws.ssm.K8sLocalParameterProvider;
import org.opengroup.osdu.core.aws.ssm.K8sParameterNotFoundException;
import org.opengroup.osdu.core.common.provider.interfaces.IIndexCache; import org.opengroup.osdu.core.common.provider.interfaces.IIndexCache;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Map;
@Component @Component
public class IndexCacheImpl implements IIndexCache<String, Boolean>, AutoCloseable { public class IndexCacheImpl implements IIndexCache<String, Boolean>, AutoCloseable {
private RedisCache<String, Boolean> cache; private ICache<String, Boolean> cache;
private Boolean local;
public IndexCacheImpl(@Value("${aws.elasticache.cluster.endpoint}") final String REDIS_SEARCH_HOST, @Value("${aws.elasticache.cluster.endpoint:null}")
@Value("${aws.elasticache.cluster.port}") final String REDIS_SEARCH_PORT, String REDIS_SEARCH_HOST;
@Value("${aws.elasticache.cluster.key}") final String REDIS_SEARCH_KEY, @Value("${aws.elasticache.cluster.port:null}")
@Value("${aws.elasticache.cluster.index.expiration}") final String INDEX_CACHE_EXPIRATION) { String REDIS_SEARCH_PORT;
cache = new RedisCache<>(REDIS_SEARCH_HOST, Integer.parseInt(REDIS_SEARCH_PORT), REDIS_SEARCH_KEY, @Value("${aws.elasticache.cluster.key:null}")
Integer.parseInt(INDEX_CACHE_EXPIRATION) * 60, String.class, Boolean.class); String REDIS_SEARCH_KEY;
@Value("${aws.elasticache.cluster.index.expiration}")
String INDEX_CACHE_EXPIRATION;
public IndexCacheImpl() throws K8sParameterNotFoundException, JsonProcessingException {
int expTimeSeconds = Integer.parseInt(INDEX_CACHE_EXPIRATION) * 60;
K8sLocalParameterProvider provider = new K8sLocalParameterProvider();
if (provider.getLocalMode()){
if (Boolean.parseBoolean(System.getenv("DISABLE_CACHE"))){
cache = new DummyCache<>();
}else{
cache = new VmCache<String,Boolean>(expTimeSeconds, 10);
}
}else {
String host = provider.getParameterAsStringOrDefault("CACHE_CLUSTER_ENDPOINT", REDIS_SEARCH_HOST);
int port = Integer.parseInt(provider.getParameterAsStringOrDefault("CACHE_CLUSTER_PORT", REDIS_SEARCH_PORT));
Map<String, String > credential =provider.getCredentialsAsMap("CACHE_CLUSTER_KEY");
String password;
if (credential !=null){
password = credential.get("token");
}else{
password = REDIS_SEARCH_KEY;
}
cache = new RedisCache<String, Boolean>(host, port, password, expTimeSeconds, String.class,Boolean.class);
}
local = cache instanceof AutoCloseable;
} }
@Override @Override
public void close() throws Exception { public void close() throws Exception {
this.cache.close(); if (local){
}else{
((AutoCloseable)this.cache).close();
}
} }
@Override @Override
......
...@@ -29,13 +29,13 @@ import java.util.Map; ...@@ -29,13 +29,13 @@ import java.util.Map;
@Component @Component
public class SchemaCacheImpl implements ISchemaCache<String, String>, AutoCloseable { public class SchemaCacheImpl implements ISchemaCache<String, String>, AutoCloseable {
@Value("${aws.elasticache.cluster.endpoint}") @Value("${aws.elasticache.cluster.endpoint:null}")
String REDIS_SEARCH_HOST; String REDIS_SEARCH_HOST;
@Value("${aws.elasticache.cluster.port}") @Value("${aws.elasticache.cluster.port:null}")
String REDIS_SEARCH_PORT; String REDIS_SEARCH_PORT;
@Value("${aws.elasticache.cluster.key}") @Value("${aws.elasticache.cluster.key:null}")
String REDIS_SEARCH_KEY; String REDIS_SEARCH_KEY;
@Value("${aws.elasticache.cluster.schema.expiration}") @Value("${aws.elasticache.cluster.schema.expiration:null}")
String SCHEMA_CACHE_EXPIRATION; String SCHEMA_CACHE_EXPIRATION;
private ICache<String, String> cache; private ICache<String, String> cache;
private Boolean local = false; private Boolean local = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment