Skip to content
Snippets Groups Projects
Commit 5a02fe9c authored by Vibhuti Sharma [Microsoft]'s avatar Vibhuti Sharma [Microsoft]
Browse files

Merge branch 'redis-cache' into 'master'

use redis cache for azure

See merge request !199
parents e3e7c8ed 600f2ec4
No related branches found
No related tags found
1 merge request!199use redis cache for azure
Pipeline #66335 failed
Showing
with 208 additions and 10 deletions
...@@ -342,7 +342,7 @@ The following software have components provided under the terms of this license: ...@@ -342,7 +342,7 @@ The following software have components provided under the terms of this license:
- Doxia :: XDoc Module (from http://maven.apache.org/doxia/doxia/doxia-modules/doxia-module-xdoc/) - Doxia :: XDoc Module (from http://maven.apache.org/doxia/doxia/doxia-modules/doxia-module-xdoc/)
- Doxia :: XHTML Module (from http://maven.apache.org/doxia/doxia/doxia-modules/doxia-module-xhtml/) - Doxia :: XHTML Module (from http://maven.apache.org/doxia/doxia/doxia-modules/doxia-module-xhtml/)
- Doxia Sitetools :: Decoration Model (from http://maven.apache.org/doxia/doxia-sitetools/doxia-decoration-model/) - Doxia Sitetools :: Decoration Model (from http://maven.apache.org/doxia/doxia-sitetools/doxia-decoration-model/)
- Doxia Sitetools :: Site Renderer Component (from http://maven.apache.org/doxia/doxia-sitetools/doxia-site-renderer/) - Doxia Sitetools :: Site Renderer (from https://repo1.maven.org/maven2/org/apache/maven/doxia/doxia-site-renderer)
- Elastic JNA Distribution (from https://github.com/java-native-access/jna) - Elastic JNA Distribution (from https://github.com/java-native-access/jna)
- Expression Language 3.0 (from http://uel.java.net) - Expression Language 3.0 (from http://uel.java.net)
- FindBugs-jsr305 (from http://findbugs.sourceforge.net/) - FindBugs-jsr305 (from http://findbugs.sourceforge.net/)
......
...@@ -39,6 +39,7 @@ az keyvault secret show --vault-name $KEY_VAULT_NAME --name $KEY_VAULT_SECRET_NA ...@@ -39,6 +39,7 @@ az keyvault secret show --vault-name $KEY_VAULT_NAME --name $KEY_VAULT_SECRET_NA
| name | value | description | sensitive? | source | | name | value | description | sensitive? | source |
| --- | --- | --- | --- | --- | | --- | --- | --- | --- | --- |
| `runtime.env.local` | false (change this to `true` when running locally) | Var to check if app is running locally | no | - |
| `server.servlet.contextPath` | `/api/indexer/v2/` | Servlet context path | no | - | | `server.servlet.contextPath` | `/api/indexer/v2/` | Servlet context path | no | - |
| `schema_service_url` | ex `https://schema.azurewebsites.net` | Endpoint of schema service | no | output of infrastructure deployments | | `schema_service_url` | ex `https://schema.azurewebsites.net` | Endpoint of schema service | no | output of infrastructure deployments |
| `SCHEMA_HOST` | `${schema_service_url}/schema` | Endpoint of schema API | no | - | | `SCHEMA_HOST` | `${schema_service_url}/schema` | Endpoint of schema API | no | - |
......
// Copyright © Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.indexer.azure.cache;
import org.opengroup.osdu.core.common.cache.RedisCache;
import org.opengroup.osdu.core.common.provider.interfaces.IIndexCache;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import javax.inject.Named;
@Component
@ConditionalOnProperty(value = "runtime.env.local", havingValue = "false", matchIfMissing = true)
public class IndexRedisCache extends RedisCache<String, Boolean> implements IIndexCache<String, Boolean> {
public IndexRedisCache(final @Named("REDIS_HOST") String host,
final @Named("REDIS_PORT") int port,
final @Named("REDIS_PASSWORD") String password,
final @Named("INDEX_REDIS_TTL") int timeout,
@Value("${redis.database}") final int database) {
super(host, port, password, timeout, database, String.class, Boolean.class);
}
}
...@@ -17,14 +17,16 @@ package org.opengroup.osdu.indexer.azure.cache; ...@@ -17,14 +17,16 @@ package org.opengroup.osdu.indexer.azure.cache;
import org.opengroup.osdu.core.common.cache.VmCache; import org.opengroup.osdu.core.common.cache.VmCache;
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.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class IndexCache implements IIndexCache<String, Boolean> { @ConditionalOnProperty(value = "runtime.env.local", havingValue = "true")
public class IndexVmCache implements IIndexCache<String, Boolean> {
private VmCache<String, Boolean> cache; private VmCache<String, Boolean> cache;
public IndexCache(@Value("${INDEX_CACHE_EXPIRATION}") final String INDEX_CACHE_EXPIRATION, public IndexVmCache(@Value("${INDEX_CACHE_EXPIRATION}") final String INDEX_CACHE_EXPIRATION,
@Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) { @Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) {
cache = new VmCache<>(Integer.parseInt(INDEX_CACHE_EXPIRATION) * 60, cache = new VmCache<>(Integer.parseInt(INDEX_CACHE_EXPIRATION) * 60,
Integer.parseInt(MAX_CACHE_VALUE_SIZE)); Integer.parseInt(MAX_CACHE_VALUE_SIZE));
} }
......
// Copyright © Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.indexer.azure.cache;
import org.opengroup.osdu.core.common.cache.RedisCache;
import org.opengroup.osdu.core.common.model.search.IdToken;
import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import javax.inject.Named;
@Component
@ConditionalOnProperty(value = "runtime.env.local", havingValue = "false", matchIfMissing = true)
public class JwtRedisCache extends RedisCache<String, IdToken> implements IJwtCache<String, IdToken> {
public JwtRedisCache(final @Named("REDIS_HOST") String host,
final @Named("REDIS_PORT") int port,
final @Named("REDIS_PASSWORD") String password,
final @Named("JWT_REDIS_TTL") int timeout,
@Value("${redis.database}") final int database) {
super(host, port, password, timeout, database, String.class, IdToken.class);
}
}
...@@ -18,16 +18,18 @@ import org.opengroup.osdu.core.common.cache.VmCache; ...@@ -18,16 +18,18 @@ import org.opengroup.osdu.core.common.cache.VmCache;
import org.opengroup.osdu.core.common.model.search.IdToken; import org.opengroup.osdu.core.common.model.search.IdToken;
import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache; import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class JwtCache implements IJwtCache<String, IdToken> { @ConditionalOnProperty(value = "runtime.env.local", havingValue = "true")
public class JwtVmCache implements IJwtCache<String, IdToken> {
private VmCache<String, IdToken> cache; private VmCache<String, IdToken> cache;
// Azure service account id_token can be requested only for 1 hr // Azure service account id_token can be requested only for 1 hr
private final static int EXPIRED_AFTER = 59; private final static int EXPIRED_AFTER = 59;
public JwtCache(@Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) { public JwtVmCache(@Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) {
cache = new VmCache<>(EXPIRED_AFTER * 60, Integer.parseInt(MAX_CACHE_VALUE_SIZE)); cache = new VmCache<>(EXPIRED_AFTER * 60, Integer.parseInt(MAX_CACHE_VALUE_SIZE));
} }
......
// Copyright © Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.indexer.azure.cache;
import org.opengroup.osdu.core.common.cache.RedisCache;
import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import javax.inject.Named;
@Component
@ConditionalOnProperty(value = "runtime.env.local", havingValue = "false", matchIfMissing = true)
public class SchemaRedisCache extends RedisCache<String, String> implements ISchemaCache<String, String> {
public SchemaRedisCache(final @Named("REDIS_HOST") String host,
final @Named("REDIS_PORT") int port,
final @Named("REDIS_PASSWORD") String password,
final @Named("SCHEMA_REDIS_TTL") int timeout,
@Value("${redis.database}") final int database) {
super(host, port, password, timeout, database, String.class, String.class);
}
}
...@@ -17,14 +17,16 @@ package org.opengroup.osdu.indexer.azure.cache; ...@@ -17,14 +17,16 @@ package org.opengroup.osdu.indexer.azure.cache;
import org.opengroup.osdu.core.common.cache.VmCache; import org.opengroup.osdu.core.common.cache.VmCache;
import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class SchemaCache implements ISchemaCache<String, String> { @ConditionalOnProperty(value = "runtime.env.local", havingValue = "true")
public class SchemaVmCache implements ISchemaCache<String, String> {
private VmCache<String, String> cache; private VmCache<String, String> cache;
public SchemaCache(@Value("${SCHEMA_CACHE_EXPIRATION}") final String SCHEMA_CACHE_EXPIRATION, public SchemaVmCache(@Value("${SCHEMA_CACHE_EXPIRATION}") final String SCHEMA_CACHE_EXPIRATION,
@Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) { @Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) {
cache = new VmCache<>(Integer.parseInt(SCHEMA_CACHE_EXPIRATION) * 60, cache = new VmCache<>(Integer.parseInt(SCHEMA_CACHE_EXPIRATION) * 60,
Integer.parseInt(MAX_CACHE_VALUE_SIZE)); Integer.parseInt(MAX_CACHE_VALUE_SIZE));
} }
......
// Copyright © Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.indexer.azure.di;
import com.azure.security.keyvault.secrets.SecretClient;
import org.opengroup.osdu.azure.KeyVaultFacade;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.inject.Named;
@Configuration
public class RedisConfig {
@Value("${redis.port:6380}")
private int port;
@Value("${redis.index.ttl:3600}")
public int indexRedisTtl;
// Azure service account id_token can be requested only for 1 hr
@Value("${redis.jwt.ttl:3540}")
public int jwtTtl;
@Value("${redis.schema.ttl:3600}")
public int schemaTtl;
@Bean
@Named("REDIS_PORT")
public int getRedisPort() {
return port;
}
@Bean
@Named("INDEX_REDIS_TTL")
public int getIndexRedisTtl() {
return indexRedisTtl;
}
@Bean
@Named("JWT_REDIS_TTL")
public int getJwtRedisTtl() {
return jwtTtl;
}
@Bean
@Named("SCHEMA_REDIS_TTL")
public int getSchemaRedisTtl() {
return schemaTtl;
}
@Bean
@Named("REDIS_HOST")
public String redisHost(SecretClient kv) {
return KeyVaultFacade.getSecretWithValidation(kv, "redis-hostname");
}
@Bean
@Named("REDIS_PASSWORD")
public String redisPassword(SecretClient kv) {
return KeyVaultFacade.getSecretWithValidation(kv, "redis-password");
}
}
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
runtime.env.local=false
LOG_PREFIX=indexer LOG_PREFIX=indexer
LOG_LEVEL=DEBUG LOG_LEVEL=DEBUG
...@@ -85,4 +87,7 @@ logging.ignore.servlet.paths=/swagger-ui.html ...@@ -85,4 +87,7 @@ logging.ignore.servlet.paths=/swagger-ui.html
tenantFactoryImpl.required=true tenantFactoryImpl.required=true
# Disable keyVault for actuator health check # Disable keyVault for actuator health check
management.health.azure-key-vault.enabled=false management.health.azure-key-vault.enabled=false
\ No newline at end of file
#Redis
redis.database=${REDIS_DATABASE}
\ No newline at end of file
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