diff --git a/NOTICE b/NOTICE index 5ecd5163d222a9189e94f560d3fd9e197639024b..9f73f35a77859057022281e6d7b40175092cc745 100644 --- a/NOTICE +++ b/NOTICE @@ -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 :: 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 :: 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) - Expression Language 3.0 (from http://uel.java.net) - FindBugs-jsr305 (from http://findbugs.sourceforge.net/) diff --git a/provider/indexer-azure/README.md b/provider/indexer-azure/README.md index 8f12c581017ae8e3ae0d9d264107fab0eb8f97d1..bc6a63ec3e33284229283fc5ba59caab611971a6 100644 --- a/provider/indexer-azure/README.md +++ b/provider/indexer-azure/README.md @@ -39,6 +39,7 @@ az keyvault secret show --vault-name $KEY_VAULT_NAME --name $KEY_VAULT_SECRET_NA | 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 | - | | `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 | - | diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/IndexRedisCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/IndexRedisCache.java new file mode 100644 index 0000000000000000000000000000000000000000..8ac5b0f10ff27d25a18c57572e5ff8c8c473e1e9 --- /dev/null +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/IndexRedisCache.java @@ -0,0 +1,37 @@ +// 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); + } +} diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/IndexCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/IndexVmCache.java similarity index 77% rename from provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/IndexCache.java rename to provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/IndexVmCache.java index 8ca5500c282716c31ebda76606ee3315a7d41aa2..d242c05b03d62dbee2f27da78a88fb2b2b8910eb 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/IndexCache.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/IndexVmCache.java @@ -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.provider.interfaces.IIndexCache; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.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; - public IndexCache(@Value("${INDEX_CACHE_EXPIRATION}") final String INDEX_CACHE_EXPIRATION, - @Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) { + public IndexVmCache(@Value("${INDEX_CACHE_EXPIRATION}") final String INDEX_CACHE_EXPIRATION, + @Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) { cache = new VmCache<>(Integer.parseInt(INDEX_CACHE_EXPIRATION) * 60, Integer.parseInt(MAX_CACHE_VALUE_SIZE)); } diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/JwtRedisCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/JwtRedisCache.java new file mode 100644 index 0000000000000000000000000000000000000000..1c1a3571fb14551ea952a76456dd420e2b6ac810 --- /dev/null +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/JwtRedisCache.java @@ -0,0 +1,37 @@ +// 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); + } +} diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/JwtCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/JwtVmCache.java similarity index 83% rename from provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/JwtCache.java rename to provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/JwtVmCache.java index 07e4f0403961315e41fc1267452dc0ed057e3bc9..429100969e6502e8ac772c6fb5204d18bf8e82d1 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/JwtCache.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/JwtVmCache.java @@ -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.provider.interfaces.IJwtCache; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.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; // Azure service account id_token can be requested only for 1 hr 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)); } diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/SchemaRedisCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/SchemaRedisCache.java new file mode 100644 index 0000000000000000000000000000000000000000..b5f78c4dd114631c07a02d633da1d5e1786a559e --- /dev/null +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/SchemaRedisCache.java @@ -0,0 +1,36 @@ +// 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); + } +} diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/SchemaCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/SchemaVmCache.java similarity index 77% rename from provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/SchemaCache.java rename to provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/SchemaVmCache.java index 97a5f1810ccc2d0f5e3ce07d33aa655422756fa7..ba19d519d54789c065e89570f0fe637b86e6814b 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/SchemaCache.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/SchemaVmCache.java @@ -17,14 +17,16 @@ package org.opengroup.osdu.indexer.azure.cache; import org.opengroup.osdu.core.common.cache.VmCache; 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; @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; - public SchemaCache(@Value("${SCHEMA_CACHE_EXPIRATION}") final String SCHEMA_CACHE_EXPIRATION, - @Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) { + public SchemaVmCache(@Value("${SCHEMA_CACHE_EXPIRATION}") final String SCHEMA_CACHE_EXPIRATION, + @Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) { cache = new VmCache<>(Integer.parseInt(SCHEMA_CACHE_EXPIRATION) * 60, Integer.parseInt(MAX_CACHE_VALUE_SIZE)); } diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/RedisConfig.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/RedisConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..6b98eb7ce0eb6f54dff8cb13279224b91add958f --- /dev/null +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/RedisConfig.java @@ -0,0 +1,76 @@ +// 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"); + } +} diff --git a/provider/indexer-azure/src/main/resources/application.properties b/provider/indexer-azure/src/main/resources/application.properties index 59231e1ae9e1df6c0312d6e6334749cf4f179280..0d27fa48835d20b515d0fe4a6ecd692a8d922ee6 100644 --- a/provider/indexer-azure/src/main/resources/application.properties +++ b/provider/indexer-azure/src/main/resources/application.properties @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +runtime.env.local=false + LOG_PREFIX=indexer LOG_LEVEL=DEBUG @@ -85,4 +87,7 @@ logging.ignore.servlet.paths=/swagger-ui.html tenantFactoryImpl.required=true # Disable keyVault for actuator health check -management.health.azure-key-vault.enabled=false \ No newline at end of file +management.health.azure-key-vault.enabled=false + +#Redis +redis.database=${REDIS_DATABASE} \ No newline at end of file