Skip to content
Snippets Groups Projects
Commit d3db85ce authored by Neelesh Thakur's avatar Neelesh Thakur
Browse files

redis cache for azure

parent 53df22c8
No related branches found
No related tags found
1 merge request!199use redis cache for azure
Pipeline #65088 failed
Pipeline: Indexer

#65091

    Showing
    with 213 additions and 15 deletions
    ...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
    <dependency> <dependency>
    <groupId>org.opengroup.osdu.core.aws</groupId> <groupId>org.opengroup.osdu.core.aws</groupId>
    <artifactId>os-core-lib-aws</artifactId> <artifactId>os-core-lib-aws</artifactId>
    <version>0.11.0-SNAPSHOT</version> <version>0.11.0</version>
    </dependency> </dependency>
    <!-- AWS managed packages --> <!-- AWS managed packages -->
    ......
    ...@@ -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
    ...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
    <dependency> <dependency>
    <groupId>org.opengroup.osdu</groupId> <groupId>org.opengroup.osdu</groupId>
    <artifactId>os-core-common</artifactId> <artifactId>os-core-common</artifactId>
    <version>0.11.0-SNAPSHOT</version> <version>0.12.0-rc1</version>
    </dependency> </dependency>
    <dependency> <dependency>
    ......
    ...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
    <cucumber.version>1.2.5</cucumber.version> <cucumber.version>1.2.5</cucumber.version>
    <junit.jupiter.version>5.6.0</junit.jupiter.version> <junit.jupiter.version>5.6.0</junit.jupiter.version>
    <elasticsearch.version>7.8.1</elasticsearch.version> <elasticsearch.version>7.8.1</elasticsearch.version>
    <os-core-common.version>0.11.0-SNAPSHOT</os-core-common.version> <os-core-common.version>0.12.0-rc1</os-core-common.version>
    </properties> </properties>
    <dependencies> <dependencies>
    ......
    ...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
    <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
    <cucumber.version>1.2.5</cucumber.version> <cucumber.version>1.2.5</cucumber.version>
    <os-core-common.version>0.11.0-SNAPSHOT</os-core-common.version> <os-core-common.version>0.12.0-rc1</os-core-common.version>
    </properties> </properties>
    <dependencies> <dependencies>
    ......
    ...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
    <dependency> <dependency>
    <groupId>org.opengroup.osdu</groupId> <groupId>org.opengroup.osdu</groupId>
    <artifactId>os-core-common</artifactId> <artifactId>os-core-common</artifactId>
    <version>0.3.8</version> <version>0.12.0-rc1</version>
    </dependency> </dependency>
    <dependency> <dependency>
    ......
    ...@@ -138,7 +138,7 @@ public class Steps extends SchemaServiceRecordSteps { ...@@ -138,7 +138,7 @@ public class Steps extends SchemaServiceRecordSteps {
    HttpRequest rq = HttpRequest.post(recordChangeMessage).url(url).headers(dpsHeaders.getHeaders()).build(); HttpRequest rq = HttpRequest.post(recordChangeMessage).url(url).headers(dpsHeaders.getHeaders()).build();
    HttpResponse result = httpClient.send(rq); HttpResponse result = httpClient.send(rq);
    if(result.hasException().equals(false) && result.getResponseCode() == 500) { if(result.hasException() == false && result.getResponseCode() == 500) {
    assertTrue(result.getResponseCode() == 500); assertTrue(result.getResponseCode() == 500);
    } else { } else {
    AppError error = gson.fromJson(result.getBody(), AppError.class); AppError error = gson.fromJson(result.getBody(), AppError.class);
    ......
    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