From bb4ef4009d601fbc4a7853b0d354396a39942afb Mon Sep 17 00:00:00 2001 From: ZMai <zmai@slb.com> Date: Fri, 18 Aug 2023 08:58:49 -0500 Subject: [PATCH] Refactor the cache package --- .../cache/ChildrenKindsCacheVmImpl.java | 3 +- .../osdu/indexer/cache/FeatureFlagCache.java | 30 ------------- .../osdu/indexer/cache/KindCacheVmImpl.java | 1 + ...rentChildRelationshipSpecsCacheVmImpl.java | 1 + .../PropertyConfigurationsCacheVmImpl.java | 1 + ...pertyConfigurationsEnabledCacheVmImpl.java | 1 + .../cache/RecordChangeInfoCacheVmImpl.java | 1 + .../cache/RelatedObjectCacheVmImpl.java | 1 + .../{ => interfaces}/IChildrenKindsCache.java | 2 +- .../cache/{ => interfaces}/IKindCache.java | 2 +- .../IParentChildRelationshipSpecsCache.java | 2 +- .../IPropertyConfigurationsCache.java | 2 +- .../IPropertyConfigurationsEnabledCache.java | 2 +- .../IRecordChangeInfoCache.java | 2 +- .../{ => interfaces}/IRelatedObjectCache.java | 2 +- .../AbstractPartitionSafeCache.java | 7 ++- .../ChildRelationshipSpecsCache.java} | 7 ++- .../ChildrenKindsCache.java} | 7 ++- .../ConfigurationsEnabledCache.java} | 7 ++- .../cache/partitionsafe/FeatureFlagCache.java | 33 ++++++++++++++ .../FlattenedSchemaCache.java} | 6 +-- .../IndexCache.java} | 15 ++----- .../KindCache.java} | 7 ++- .../PropertyConfigurationsCache.java} | 7 ++- .../partitionsafe/RecordChangeCache.java | 33 ++++++++++++++ .../partitionsafe/RelatedObjectCache.java | 33 ++++++++++++++ .../SchemaCache.java} | 17 +++---- .../service/IndexSchemaServiceImpl.java | 8 ++-- .../service/IndexerMappingServiceImpl.java | 4 +- .../indexer/service/IndicesServiceImpl.java | 5 +-- .../util/BooleanFeatureFlagClient.java | 11 ++--- .../FeatureFlagCacheTest.java | 23 +++++++--- .../IndexCacheTest.java} | 13 +++--- .../service/IndexerMappingServiceTest.java | 4 +- .../service/IndexerSchemaServiceTest.java | 8 ++-- .../indexer/service/IndicesServiceTest.java | 5 +-- ...PropertyConfigurationsServiceImplTest.java | 14 +++--- .../StorageIndexerPayloadMapperTest.java | 5 ++- .../indexer/service/mock/RequestInfoMock.java | 45 +++++++++++++++++++ .../util/BooleanFeatureFlagClientTest.java | 27 ++++++++++- .../cache/RecordChangeInfoRedisCache.java | 2 +- .../azure/cache/RelatedObjectRedisCache.java | 2 +- 42 files changed, 271 insertions(+), 137 deletions(-) delete mode 100644 indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/FeatureFlagCache.java rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{ => interfaces}/IChildrenKindsCache.java (93%) rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{ => interfaces}/IKindCache.java (93%) rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{ => interfaces}/IParentChildRelationshipSpecsCache.java (94%) rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{ => interfaces}/IPropertyConfigurationsCache.java (93%) rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{ => interfaces}/IPropertyConfigurationsEnabledCache.java (93%) rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{ => interfaces}/IRecordChangeInfoCache.java (93%) rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{ => interfaces}/IRelatedObjectCache.java (93%) rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{ => partitionsafe}/AbstractPartitionSafeCache.java (82%) rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{PartitionSafeParentChildRelationshipSpecsCache.java => partitionsafe/ChildRelationshipSpecsCache.java} (82%) rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{PartitionSafeChildrenKindsCache.java => partitionsafe/ChildrenKindsCache.java} (84%) rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{PartitionSafePropertyConfigurationsEnabledCache.java => partitionsafe/ConfigurationsEnabledCache.java} (82%) create mode 100644 indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/FeatureFlagCache.java rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{PartitionSafeSchemaCache.java => partitionsafe/FlattenedSchemaCache.java} (85%) rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{PartitionSafeIndexCache.java => partitionsafe/IndexCache.java} (75%) rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{PartitionSafeKindCache.java => partitionsafe/KindCache.java} (84%) rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{PartitionSafePropertyConfigurationsCache.java => partitionsafe/PropertyConfigurationsCache.java} (83%) create mode 100644 indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/RecordChangeCache.java create mode 100644 indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/RelatedObjectCache.java rename indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/{PartitionSafeFlattenedSchemaCache.java => partitionsafe/SchemaCache.java} (67%) rename indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/{ => partitionsafe}/FeatureFlagCacheTest.java (65%) rename indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/{PartitionSafeIndexCacheTest.java => partitionsafe/IndexCacheTest.java} (82%) create mode 100644 indexer-core/src/test/java/org/opengroup/osdu/indexer/service/mock/RequestInfoMock.java diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ChildrenKindsCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ChildrenKindsCacheVmImpl.java index a200d0b25..435e32835 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ChildrenKindsCacheVmImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ChildrenKindsCacheVmImpl.java @@ -16,12 +16,13 @@ package org.opengroup.osdu.indexer.cache; import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.indexer.cache.interfaces.IChildrenKindsCache; import org.opengroup.osdu.indexer.model.Constants; import org.opengroup.osdu.indexer.model.indexproperty.ChildrenKinds; import org.springframework.stereotype.Component; @Component -public class ChildrenKindsCacheVmImpl implements IChildrenKindsCache{ +public class ChildrenKindsCacheVmImpl implements IChildrenKindsCache { private VmCache<String, ChildrenKinds> cache; public ChildrenKindsCacheVmImpl() { diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/FeatureFlagCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/FeatureFlagCache.java deleted file mode 100644 index d57a5dbff..000000000 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/FeatureFlagCache.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 - * - * https://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.cache; - -import org.opengroup.osdu.core.common.cache.VmCache; -import org.springframework.stereotype.Component; - -@Component -public class FeatureFlagCache extends VmCache<String, Boolean> { - public FeatureFlagCache() { - super(300, 1000); - } - - public boolean containsKey(final String key) { - return this.get(key) != null; - } -} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/KindCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/KindCacheVmImpl.java index 2eec5cead..9b6362c6c 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/KindCacheVmImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/KindCacheVmImpl.java @@ -16,6 +16,7 @@ package org.opengroup.osdu.indexer.cache; import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.indexer.cache.interfaces.IKindCache; import org.opengroup.osdu.indexer.model.Constants; import org.springframework.stereotype.Component; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ParentChildRelationshipSpecsCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ParentChildRelationshipSpecsCacheVmImpl.java index a270ab77d..f630c1d55 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ParentChildRelationshipSpecsCacheVmImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ParentChildRelationshipSpecsCacheVmImpl.java @@ -16,6 +16,7 @@ package org.opengroup.osdu.indexer.cache; import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.indexer.cache.interfaces.IParentChildRelationshipSpecsCache; import org.opengroup.osdu.indexer.model.Constants; import org.opengroup.osdu.indexer.model.indexproperty.ParentChildRelationshipSpecs; import org.springframework.stereotype.Component; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsCacheVmImpl.java index 4e8e06052..38e5f37a7 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsCacheVmImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsCacheVmImpl.java @@ -16,6 +16,7 @@ package org.opengroup.osdu.indexer.cache; import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.indexer.cache.interfaces.IPropertyConfigurationsCache; import org.opengroup.osdu.indexer.model.Constants; import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; import org.springframework.stereotype.Component; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsEnabledCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsEnabledCacheVmImpl.java index 99d2b6d3a..1db22ec6f 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsEnabledCacheVmImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsEnabledCacheVmImpl.java @@ -16,6 +16,7 @@ package org.opengroup.osdu.indexer.cache; import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.indexer.cache.interfaces.IPropertyConfigurationsEnabledCache; import org.opengroup.osdu.indexer.model.Constants; import org.springframework.stereotype.Component; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RecordChangeInfoCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RecordChangeInfoCacheVmImpl.java index 796d13186..529231ee8 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RecordChangeInfoCacheVmImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RecordChangeInfoCacheVmImpl.java @@ -16,6 +16,7 @@ package org.opengroup.osdu.indexer.cache; import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.indexer.cache.interfaces.IRecordChangeInfoCache; import org.opengroup.osdu.indexer.model.Constants; import org.opengroup.osdu.indexer.model.RecordChangeInfo; import org.springframework.stereotype.Component; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RelatedObjectCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RelatedObjectCacheVmImpl.java index c6ba7d090..625d7f74d 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RelatedObjectCacheVmImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RelatedObjectCacheVmImpl.java @@ -17,6 +17,7 @@ package org.opengroup.osdu.indexer.cache; import org.opengroup.osdu.core.common.cache.VmCache; import org.opengroup.osdu.core.common.model.storage.RecordData; +import org.opengroup.osdu.indexer.cache.interfaces.IRelatedObjectCache; import org.opengroup.osdu.indexer.model.Constants; import org.springframework.stereotype.Component; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IChildrenKindsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IChildrenKindsCache.java similarity index 93% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IChildrenKindsCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IChildrenKindsCache.java index dda438458..0341270be 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IChildrenKindsCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IChildrenKindsCache.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.interfaces; import org.opengroup.osdu.core.common.cache.ICache; import org.opengroup.osdu.indexer.model.indexproperty.ChildrenKinds; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IKindCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IKindCache.java similarity index 93% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IKindCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IKindCache.java index c474065de..6898d9d1d 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IKindCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IKindCache.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.interfaces; import org.opengroup.osdu.core.common.cache.ICache; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IParentChildRelationshipSpecsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IParentChildRelationshipSpecsCache.java similarity index 94% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IParentChildRelationshipSpecsCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IParentChildRelationshipSpecsCache.java index 74aa48e4f..b174f1291 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IParentChildRelationshipSpecsCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IParentChildRelationshipSpecsCache.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.interfaces; import org.opengroup.osdu.core.common.cache.ICache; import org.opengroup.osdu.indexer.model.indexproperty.ParentChildRelationshipSpecs; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IPropertyConfigurationsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IPropertyConfigurationsCache.java similarity index 93% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IPropertyConfigurationsCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IPropertyConfigurationsCache.java index 24a51559f..65ee4f96a 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IPropertyConfigurationsCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IPropertyConfigurationsCache.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.interfaces; import org.opengroup.osdu.core.common.cache.ICache; import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IPropertyConfigurationsEnabledCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IPropertyConfigurationsEnabledCache.java similarity index 93% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IPropertyConfigurationsEnabledCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IPropertyConfigurationsEnabledCache.java index 4b6c372d3..98bdbcc5d 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IPropertyConfigurationsEnabledCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IPropertyConfigurationsEnabledCache.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.interfaces; import org.opengroup.osdu.core.common.cache.ICache; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IRecordChangeInfoCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IRecordChangeInfoCache.java similarity index 93% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IRecordChangeInfoCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IRecordChangeInfoCache.java index 25591747a..f4a8baa01 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IRecordChangeInfoCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IRecordChangeInfoCache.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.interfaces; import org.opengroup.osdu.core.common.cache.ICache; import org.opengroup.osdu.indexer.model.RecordChangeInfo; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IRelatedObjectCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IRelatedObjectCache.java similarity index 93% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IRelatedObjectCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IRelatedObjectCache.java index 4ddad5e46..53d47e486 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IRelatedObjectCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IRelatedObjectCache.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.interfaces; import org.opengroup.osdu.core.common.cache.ICache; import org.opengroup.osdu.core.common.model.storage.RecordData; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/AbstractPartitionSafeCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/AbstractPartitionSafeCache.java similarity index 82% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/AbstractPartitionSafeCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/AbstractPartitionSafeCache.java index 52d2cdf9e..25a336649 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/AbstractPartitionSafeCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/AbstractPartitionSafeCache.java @@ -13,20 +13,19 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.partitionsafe; import org.opengroup.osdu.core.common.cache.ICache; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; -import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; -@RequestScope public abstract class AbstractPartitionSafeCache<K, V> implements ICache<K, V> { @Inject private IRequestInfo requestInfo; protected String cacheKey(String s) { - return this.requestInfo.getPartitionId() + "-" + s; + String key = this.requestInfo.getPartitionId() + "-" + this.getClass().getSimpleName() + "-" + s; + return key.toLowerCase(); } } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeParentChildRelationshipSpecsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/ChildRelationshipSpecsCache.java similarity index 82% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeParentChildRelationshipSpecsCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/ChildRelationshipSpecsCache.java index 1ca0c87aa..107811a67 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeParentChildRelationshipSpecsCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/ChildRelationshipSpecsCache.java @@ -13,17 +13,16 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.partitionsafe; +import org.opengroup.osdu.indexer.cache.interfaces.IParentChildRelationshipSpecsCache; import org.opengroup.osdu.indexer.model.indexproperty.ParentChildRelationshipSpecs; import org.springframework.stereotype.Component; -import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; @Component -@RequestScope -public class PartitionSafeParentChildRelationshipSpecsCache extends AbstractPartitionSafeCache<String, ParentChildRelationshipSpecs> { +public class ChildRelationshipSpecsCache extends AbstractPartitionSafeCache<String, ParentChildRelationshipSpecs> { @Inject private IParentChildRelationshipSpecsCache cache; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeChildrenKindsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/ChildrenKindsCache.java similarity index 84% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeChildrenKindsCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/ChildrenKindsCache.java index 59dd35487..165321205 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeChildrenKindsCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/ChildrenKindsCache.java @@ -13,18 +13,17 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.partitionsafe; +import org.opengroup.osdu.indexer.cache.interfaces.IChildrenKindsCache; import org.opengroup.osdu.indexer.model.indexproperty.ChildrenKinds; import org.springframework.stereotype.Component; -import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; @Component -@RequestScope -public class PartitionSafeChildrenKindsCache extends AbstractPartitionSafeCache<String, ChildrenKinds>{ +public class ChildrenKindsCache extends AbstractPartitionSafeCache<String, ChildrenKinds> { @Inject private IChildrenKindsCache cache; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafePropertyConfigurationsEnabledCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/ConfigurationsEnabledCache.java similarity index 82% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafePropertyConfigurationsEnabledCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/ConfigurationsEnabledCache.java index e8bea9da7..086b4b3ce 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafePropertyConfigurationsEnabledCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/ConfigurationsEnabledCache.java @@ -13,16 +13,15 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.partitionsafe; +import org.opengroup.osdu.indexer.cache.interfaces.IPropertyConfigurationsEnabledCache; import org.springframework.stereotype.Component; -import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; @Component -@RequestScope -public class PartitionSafePropertyConfigurationsEnabledCache extends AbstractPartitionSafeCache<String,Boolean> { +public class ConfigurationsEnabledCache extends AbstractPartitionSafeCache<String,Boolean> { @Inject private IPropertyConfigurationsEnabledCache cache; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/FeatureFlagCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/FeatureFlagCache.java new file mode 100644 index 000000000..ea81d3913 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/FeatureFlagCache.java @@ -0,0 +1,33 @@ +package org.opengroup.osdu.indexer.cache.partitionsafe; + +import org.opengroup.osdu.core.common.cache.VmCache; +import org.springframework.stereotype.Component; + +@Component +public class FeatureFlagCache extends AbstractPartitionSafeCache<String, Boolean> { + private VmCache<String, Boolean> cache; + + public FeatureFlagCache() { + cache = new VmCache<>(300, 1000); + } + + @Override + public void put(String s, Boolean o) { + this.cache.put(cacheKey(s), o); + } + + @Override + public Boolean get(String s) { + return this.cache.get(cacheKey(s)); + } + + @Override + public void delete(String s) { + this.cache.delete(cacheKey(s)); + } + + @Override + public void clearAll() { + this.cache.clearAll(); + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeSchemaCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/FlattenedSchemaCache.java similarity index 85% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeSchemaCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/FlattenedSchemaCache.java index 4cbb38658..27e88715b 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeSchemaCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/FlattenedSchemaCache.java @@ -13,17 +13,15 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.partitionsafe; import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; import org.springframework.stereotype.Component; -import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; @Component -@RequestScope -public class PartitionSafeSchemaCache extends AbstractPartitionSafeCache<String, String> { +public class FlattenedSchemaCache extends AbstractPartitionSafeCache<String, String> { @Inject private ISchemaCache schemaCache; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeIndexCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/IndexCache.java similarity index 75% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeIndexCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/IndexCache.java index 0942b5ecb..bb059f907 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeIndexCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/IndexCache.java @@ -12,22 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.partitionsafe; import org.opengroup.osdu.core.common.provider.interfaces.IIndexCache; -import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.web.context.annotation.RequestScope; @Component -@RequestScope -public class PartitionSafeIndexCache { +public class IndexCache extends AbstractPartitionSafeCache<String, Boolean> { @Autowired private IIndexCache indexCache; - @Autowired - private IRequestInfo requestInfo; public void put(String s, Boolean o) { this.indexCache.put(cacheKey(s), o); @@ -44,8 +39,4 @@ public class PartitionSafeIndexCache { public void clearAll() { this.indexCache.clearAll(); } - - private String cacheKey(String s) { - return this.requestInfo.getPartitionId() + "-" + s; - } -} \ No newline at end of file +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeKindCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/KindCache.java similarity index 84% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeKindCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/KindCache.java index e1bc5adce..99275df91 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeKindCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/KindCache.java @@ -13,16 +13,15 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.partitionsafe; +import org.opengroup.osdu.indexer.cache.interfaces.IKindCache; import org.springframework.stereotype.Component; -import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; @Component -@RequestScope -public class PartitionSafeKindCache extends AbstractPartitionSafeCache<String, String> { +public class KindCache extends AbstractPartitionSafeCache<String, String> { @Inject private IKindCache cache; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafePropertyConfigurationsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/PropertyConfigurationsCache.java similarity index 83% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafePropertyConfigurationsCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/PropertyConfigurationsCache.java index 04a4d4082..22752ecfb 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafePropertyConfigurationsCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/PropertyConfigurationsCache.java @@ -13,17 +13,16 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.partitionsafe; +import org.opengroup.osdu.indexer.cache.interfaces.IPropertyConfigurationsCache; import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; import org.springframework.stereotype.Component; -import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; @Component -@RequestScope -public class PartitionSafePropertyConfigurationsCache extends AbstractPartitionSafeCache<String,PropertyConfigurations> { +public class PropertyConfigurationsCache extends AbstractPartitionSafeCache<String,PropertyConfigurations> { @Inject private IPropertyConfigurationsCache cache; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/RecordChangeCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/RecordChangeCache.java new file mode 100644 index 000000000..8c65943c2 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/RecordChangeCache.java @@ -0,0 +1,33 @@ +package org.opengroup.osdu.indexer.cache.partitionsafe; + +import org.opengroup.osdu.indexer.cache.interfaces.IRecordChangeInfoCache; +import org.opengroup.osdu.indexer.model.RecordChangeInfo; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; + +@Component +public class RecordChangeCache extends AbstractPartitionSafeCache<String, RecordChangeInfo> { + @Inject + private IRecordChangeInfoCache cache; + + @Override + public void put(String s, RecordChangeInfo o) { + this.cache.put(cacheKey(s), o); + } + + @Override + public RecordChangeInfo get(String s) { + return this.cache.get(cacheKey(s)); + } + + @Override + public void delete(String s) { + this.cache.delete(cacheKey(s)); + } + + @Override + public void clearAll() { + this.cache.clearAll(); + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/RelatedObjectCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/RelatedObjectCache.java new file mode 100644 index 000000000..d7cab300f --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/RelatedObjectCache.java @@ -0,0 +1,33 @@ +package org.opengroup.osdu.indexer.cache.partitionsafe; + +import org.opengroup.osdu.core.common.model.storage.RecordData; +import org.opengroup.osdu.indexer.cache.interfaces.IRelatedObjectCache; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; + +@Component +public class RelatedObjectCache extends AbstractPartitionSafeCache<String, RecordData> { + @Inject + private IRelatedObjectCache cache; + + @Override + public void put(String s, RecordData o) { + this.cache.put(cacheKey(s), o); + } + + @Override + public RecordData get(String s) { + return this.cache.get(cacheKey(s)); + } + + @Override + public void delete(String s) { + this.cache.delete(cacheKey(s)); + } + + @Override + public void clearAll() { + this.cache.clearAll(); + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeFlattenedSchemaCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/SchemaCache.java similarity index 67% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeFlattenedSchemaCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/SchemaCache.java index 862acb6e9..1ec3f9f86 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeFlattenedSchemaCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/SchemaCache.java @@ -13,42 +13,35 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.partitionsafe; import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; import org.springframework.stereotype.Component; -import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; @Component -@RequestScope -public class PartitionSafeFlattenedSchemaCache extends AbstractPartitionSafeCache<String, String> { - private static final String FLATTENED_SCHEMA = "_flattened"; +public class SchemaCache extends AbstractPartitionSafeCache<String, String> { @Inject private ISchemaCache schemaCache; @Override public void put(String s, String o) { - this.schemaCache.put(getKey(s), o); + this.schemaCache.put(cacheKey(s), o); } @Override public String get(String s) { - return (String)this.schemaCache.get(getKey(s)); + return (String)this.schemaCache.get(cacheKey(s)); } @Override public void delete(String s) { - this.schemaCache.delete(getKey(s)); + this.schemaCache.delete(cacheKey(s)); } @Override public void clearAll() { this.schemaCache.clearAll(); } - - private String getKey(String s) { - return cacheKey(s) + FLATTENED_SCHEMA; - } } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java index 31b63bafb..048e87a39 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java @@ -30,8 +30,8 @@ import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; import org.opengroup.osdu.core.common.model.storage.Schema; import org.opengroup.osdu.core.common.model.storage.SchemaItem; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; -import org.opengroup.osdu.indexer.cache.PartitionSafeFlattenedSchemaCache; -import org.opengroup.osdu.indexer.cache.PartitionSafeSchemaCache; +import org.opengroup.osdu.indexer.cache.partitionsafe.FlattenedSchemaCache; +import org.opengroup.osdu.indexer.cache.partitionsafe.SchemaCache; import org.opengroup.osdu.indexer.model.Kind; import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException; @@ -65,9 +65,9 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { @Inject private IndicesService indicesService; @Inject - private PartitionSafeSchemaCache schemaCache; + private SchemaCache schemaCache; @Inject - private PartitionSafeFlattenedSchemaCache flattenedSchemaCache; + private FlattenedSchemaCache flattenedSchemaCache; @Inject private IVirtualPropertiesSchemaCache virtualPropertiesSchemaCache; @Inject diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java index a18cbd3fb..3ac173b4f 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java @@ -33,7 +33,7 @@ import org.opengroup.osdu.core.common.model.indexer.IndexSchema; import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.opengroup.osdu.core.common.search.Preconditions; -import org.opengroup.osdu.indexer.cache.PartitionSafeIndexCache; +import org.opengroup.osdu.indexer.cache.partitionsafe.IndexCache; import org.opengroup.osdu.indexer.model.Kind; import org.opengroup.osdu.indexer.util.TypeMapper; import org.springframework.beans.factory.annotation.Autowired; @@ -55,7 +55,7 @@ public class IndexerMappingServiceImpl extends MappingServiceImpl implements IMa @Inject private JaxRsDpsLog log; @Autowired - private PartitionSafeIndexCache indexCache; + private IndexCache indexCache; @Autowired private ElasticIndexNameResolver elasticIndexNameResolver; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java index e585fca49..b2a55eb88 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java @@ -24,7 +24,6 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.Request; @@ -44,7 +43,7 @@ import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.search.IndexInfo; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.opengroup.osdu.core.common.search.Preconditions; -import org.opengroup.osdu.indexer.cache.PartitionSafeIndexCache; +import org.opengroup.osdu.indexer.cache.partitionsafe.IndexCache; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -64,7 +63,7 @@ public class IndicesServiceImpl implements IndicesService { @Autowired private ElasticIndexNameResolver elasticIndexNameResolver; @Autowired - private PartitionSafeIndexCache indexCache; + private IndexCache indexCache; @Inject private IndexAliasService indexAliasService; @Autowired diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClient.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClient.java index b21bbb47a..e740c808d 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClient.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClient.java @@ -4,15 +4,13 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.partition.*; import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; -import org.opengroup.osdu.indexer.cache.FeatureFlagCache; +import org.opengroup.osdu.indexer.cache.partitionsafe.FeatureFlagCache; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; @Component public class BooleanFeatureFlagClient { - private static final String TOKEN_PREFIX = "Bearer "; - @Lazy @Autowired private FeatureFlagCache cache; @@ -31,9 +29,8 @@ public class BooleanFeatureFlagClient { public boolean isEnabled(String featureName, boolean defaultValue) { String dataPartitionId = headers.getPartitionId(); - String cacheKey = String.format("%s-%s", dataPartitionId, featureName); - if (cache != null && cache.containsKey(cacheKey)) - return cache.get(cacheKey); + if (cache != null && cache.get(featureName) != null) + return cache.get(featureName); boolean isEnabled = defaultValue; try { @@ -42,7 +39,7 @@ public class BooleanFeatureFlagClient { } catch (Exception e) { this.logger.error(String.format("PartitionService: Error getting %s for dataPartition with Id: %s. Turn on the feature flag by default.", featureName, dataPartitionId), e); } - this.cache.put(cacheKey, isEnabled); + this.cache.put(featureName, isEnabled); return isEnabled; } diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/FeatureFlagCacheTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/partitionsafe/FeatureFlagCacheTest.java similarity index 65% rename from indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/FeatureFlagCacheTest.java rename to indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/partitionsafe/FeatureFlagCacheTest.java index b440c049d..977c466e7 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/FeatureFlagCacheTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/partitionsafe/FeatureFlagCacheTest.java @@ -13,34 +13,47 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.partitionsafe; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.opengroup.osdu.indexer.cache.FeatureFlagCache; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.indexer.cache.partitionsafe.FeatureFlagCache; import org.springframework.test.context.junit4.SpringRunner; +import javax.inject.Inject; + +import static org.mockito.Mockito.when; + @RunWith(SpringRunner.class) public class FeatureFlagCacheTest { private static final String VALID_KEY = "Tenant1-indexer-decimation-enabled"; private static final String INVALID_KEY = "Tenant2-indexer-decimation-enabled"; + + @InjectMocks FeatureFlagCache cache; + @Mock + private IRequestInfo requestInfo; + @Before public void setup() { - cache = new FeatureFlagCache(); + when(requestInfo.getPartitionId()).thenReturn("data-partition-id"); cache.put(VALID_KEY, true); } @Test public void getValidKey() { - Assert.assertTrue(cache.containsKey(VALID_KEY)); + Assert.assertNotNull(cache.get(VALID_KEY)); + Assert.assertTrue(cache.get(VALID_KEY)); } @Test public void getInvalidKey() { - Assert.assertFalse(cache.containsKey(INVALID_KEY)); + Assert.assertNull(cache.get(INVALID_KEY));; } } diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/PartitionSafeIndexCacheTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/partitionsafe/IndexCacheTest.java similarity index 82% rename from indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/PartitionSafeIndexCacheTest.java rename to indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/partitionsafe/IndexCacheTest.java index 106aad0b9..e7eb9a8fa 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/PartitionSafeIndexCacheTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/cache/partitionsafe/IndexCacheTest.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.opengroup.osdu.indexer.cache; +package org.opengroup.osdu.indexer.cache.partitionsafe; import org.junit.Test; import org.junit.runner.RunWith; @@ -20,19 +20,20 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.opengroup.osdu.core.common.provider.interfaces.IIndexCache; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.indexer.cache.partitionsafe.IndexCache; import org.springframework.test.context.junit4.SpringRunner; import static org.mockito.Mockito.*; @RunWith(SpringRunner.class) -public class PartitionSafeIndexCacheTest { +public class IndexCacheTest { @Mock private IIndexCache cache; @Mock private IRequestInfo requestInfo; @InjectMocks - private PartitionSafeIndexCache sut; + private IndexCache sut; @Test public void should_addopendesNamToKey_when_addingToCache() { @@ -40,7 +41,7 @@ public class PartitionSafeIndexCacheTest { this.sut.put("key", true); - verify(this.cache, times(1)).put("opendes-key", true); + verify(this.cache, times(1)).put("opendes-indexcache-key", true); } @Test @@ -49,7 +50,7 @@ public class PartitionSafeIndexCacheTest { this.sut.delete("key"); - verify(this.cache, times(1)).delete("opendes-key"); + verify(this.cache, times(1)).delete("opendes-indexcache-key"); } @Test @@ -58,7 +59,7 @@ public class PartitionSafeIndexCacheTest { this.sut.get("key"); - verify(this.cache, times(1)).get("opendes-key"); + verify(this.cache, times(1)).get("opendes-indexcache-key"); } @Test diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java index d7b8ce8ea..12c098d8f 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java @@ -50,7 +50,7 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.indexer.IndexSchema; import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; -import org.opengroup.osdu.indexer.cache.PartitionSafeIndexCache; +import org.opengroup.osdu.indexer.cache.partitionsafe.IndexCache; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.opengroup.osdu.indexer.util.TypeMapper; import org.mockito.junit.MockitoJUnitRunner; @@ -75,7 +75,7 @@ public class IndexerMappingServiceTest { @Mock private ElasticClientHandler elasticClientHandler; @Mock - private PartitionSafeIndexCache indexCache; + private IndexCache indexCache; @Mock private IndicesService indicesService; @Mock diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java index 584bef57e..be63bc652 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java @@ -32,8 +32,8 @@ import org.opengroup.osdu.core.common.model.indexer.IndexSchema; import org.opengroup.osdu.core.common.model.indexer.OperationType; import org.opengroup.osdu.core.common.model.storage.SchemaItem; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; -import org.opengroup.osdu.indexer.cache.PartitionSafeFlattenedSchemaCache; -import org.opengroup.osdu.indexer.cache.PartitionSafeSchemaCache; +import org.opengroup.osdu.indexer.cache.partitionsafe.FlattenedSchemaCache; +import org.opengroup.osdu.indexer.cache.partitionsafe.SchemaCache; import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException; import org.opengroup.osdu.indexer.schema.converter.interfaces.IVirtualPropertiesSchemaCache; @@ -75,9 +75,9 @@ public class IndexerSchemaServiceTest { @Mock private SchemaService schemaService; @Mock - private PartitionSafeSchemaCache schemaCache; + private SchemaCache schemaCache; @Mock - private PartitionSafeFlattenedSchemaCache flattenedSchemaCache; + private FlattenedSchemaCache flattenedSchemaCache; @Mock private IVirtualPropertiesSchemaCache virtualPropertiesSchemaCache; @Mock diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndicesServiceTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndicesServiceTest.java index 1f0c43a9f..4d3354778 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndicesServiceTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndicesServiceTest.java @@ -20,7 +20,6 @@ import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; -import org.apache.http.util.EntityUtils; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; @@ -41,7 +40,7 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.search.IndexInfo; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; -import org.opengroup.osdu.indexer.cache.PartitionSafeIndexCache; +import org.opengroup.osdu.indexer.cache.partitionsafe.IndexCache; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.springframework.context.annotation.Lazy; import org.springframework.test.context.junit4.SpringRunner; @@ -64,7 +63,7 @@ public class IndicesServiceTest { @Mock private ElasticIndexNameResolver elasticIndexNameResolver; @Mock - private PartitionSafeIndexCache indicesExistCache; + private IndexCache indicesExistCache; @Mock @Lazy private JaxRsDpsLog log; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImplTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImplTest.java index cc4bd6e19..f73dabbee 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImplTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImplTest.java @@ -37,7 +37,9 @@ import org.opengroup.osdu.core.common.model.storage.RecordData; import org.opengroup.osdu.core.common.model.storage.Schema; import org.opengroup.osdu.core.common.model.storage.SchemaItem; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; -import org.opengroup.osdu.indexer.cache.*; +import org.opengroup.osdu.indexer.cache.interfaces.IRecordChangeInfoCache; +import org.opengroup.osdu.indexer.cache.interfaces.IRelatedObjectCache; +import org.opengroup.osdu.indexer.cache.partitionsafe.*; import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.model.*; import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; @@ -70,15 +72,15 @@ public class PropertyConfigurationsServiceImplTest { @Mock private IndexerConfigurationProperties configurationProperties; @Mock - private PartitionSafePropertyConfigurationsCache propertyConfigurationCache; + private PropertyConfigurationsCache propertyConfigurationCache; @Mock - private PartitionSafePropertyConfigurationsEnabledCache propertyConfigurationsEnabledCache; + private ConfigurationsEnabledCache propertyConfigurationsEnabledCache; @Mock - private PartitionSafeParentChildRelationshipSpecsCache parentChildRelationshipSpecsCache; + private ChildRelationshipSpecsCache parentChildRelationshipSpecsCache; @Mock - private PartitionSafeChildrenKindsCache childrenKindsCache; + private ChildrenKindsCache childrenKindsCache; @Mock - private PartitionSafeKindCache kindCache; + private KindCache kindCache; @Mock private IRelatedObjectCache relatedObjectCache; @Mock diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/StorageIndexerPayloadMapperTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/StorageIndexerPayloadMapperTest.java index b56339a96..2310730c2 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/StorageIndexerPayloadMapperTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/StorageIndexerPayloadMapperTest.java @@ -12,12 +12,13 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.indexer.IndexSchema; import org.opengroup.osdu.core.common.model.indexer.JobStatus; -import org.opengroup.osdu.indexer.cache.FeatureFlagCache; +import org.opengroup.osdu.indexer.cache.partitionsafe.FeatureFlagCache; import org.opengroup.osdu.indexer.schema.converter.config.SchemaConverterPropertiesConfig; import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException; import org.opengroup.osdu.indexer.schema.converter.interfaces.IVirtualPropertiesSchemaCache; import org.opengroup.osdu.indexer.schema.converter.tags.SchemaRoot; import org.opengroup.osdu.indexer.schema.converter.tags.VirtualProperties; +import org.opengroup.osdu.indexer.service.mock.RequestInfoMock; import org.opengroup.osdu.indexer.service.mock.ServiceAccountJwtClientMock; import org.opengroup.osdu.indexer.service.mock.VirtualPropertiesSchemaCacheMock; import org.opengroup.osdu.indexer.util.geo.decimator.*; @@ -45,7 +46,7 @@ import static org.junit.Assert.*; BooleanParser.class, DateTimeParser.class, GeoShapeParser.class, DouglasPeuckerReducer.class, GeoShapeDecimator.class, GeometryDecimator.class, GeometryConversionService.class, FeatureFlagCache.class, DpsHeaders.class, JobStatus.class, SchemaConverterPropertiesConfig.class, JaxRsDpsLog.class, - ServiceAccountJwtClientMock.class, VirtualPropertiesSchemaCacheMock.class, }) + ServiceAccountJwtClientMock.class, VirtualPropertiesSchemaCacheMock.class, RequestInfoMock.class}) public class StorageIndexerPayloadMapperTest { public static final String FIRST_OBJECT_INNER_PROPERTY = "FirstObjectInnerProperty"; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/mock/RequestInfoMock.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/mock/RequestInfoMock.java new file mode 100644 index 000000000..3786cc3c6 --- /dev/null +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/mock/RequestInfoMock.java @@ -0,0 +1,45 @@ +package org.opengroup.osdu.indexer.service.mock; + +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.springframework.stereotype.Component; + +import java.util.Map; + +@Component +public class RequestInfoMock implements IRequestInfo { + @Override + public DpsHeaders getHeaders() { + return null; + } + + @Override + public String getPartitionId() { + return null; + } + + @Override + public Map<String, String> getHeadersMap() { + return null; + } + + @Override + public Map<String, String> getHeadersMapWithDwdAuthZ() { + return null; + } + + @Override + public DpsHeaders getHeadersWithDwdAuthZ() { + return null; + } + + @Override + public boolean isCronRequest() { + return false; + } + + @Override + public boolean isTaskQueueRequest() { + return false; + } +} diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClientTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClientTest.java index 4a309df7b..21db5a5d8 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClientTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClientTest.java @@ -21,17 +21,19 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.partition.*; import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; -import org.opengroup.osdu.indexer.cache.FeatureFlagCache; +import org.opengroup.osdu.indexer.cache.partitionsafe.FeatureFlagCache; import org.springframework.test.context.junit4.SpringRunner; import java.util.HashMap; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @RunWith(SpringRunner.class) @@ -56,6 +58,7 @@ public class BooleanFeatureFlagClientTest { @Mock private IServiceAccountJwtClient tokenService; + @Mock IPartitionProvider partitionProvider; @@ -75,6 +78,7 @@ public class BooleanFeatureFlagClientTest { property.setValue("true"); partitionInfo.getProperties().put(PROPERTY_NAME, property); when(this.partitionProvider.get(anyString())).thenReturn(partitionInfo); + when(this.cache.get(anyString())).thenReturn(null); // Default value won't take any effect boolean enabled = sut.isEnabled(PROPERTY_NAME, true); @@ -92,6 +96,7 @@ public class BooleanFeatureFlagClientTest { property.setValue("false"); partitionInfo.getProperties().put(PROPERTY_NAME, property); when(this.partitionProvider.get(anyString())).thenReturn(partitionInfo); + when(this.cache.get(anyString())).thenReturn(null); // Default value won't take any effect boolean enabled = sut.isEnabled(PROPERTY_NAME, true); @@ -106,6 +111,7 @@ public class BooleanFeatureFlagClientTest { // The feature flag is enabled by default PartitionInfo partitionInfo = new PartitionInfo(); when(this.partitionProvider.get(anyString())).thenReturn(partitionInfo); + when(this.cache.get(anyString())).thenReturn(null); boolean enabled = sut.isEnabled(PROPERTY_NAME, true);; Assert.assertTrue(enabled); @@ -117,6 +123,7 @@ public class BooleanFeatureFlagClientTest { public void isDecimationEnabled_return_default_value_when_partitionProvider_throws_exception() throws PartitionException { // The feature flag is enabled by default when(this.partitionProvider.get(anyString())).thenThrow(PartitionException.class); + when(this.cache.get(anyString())).thenReturn(null); boolean enabled = sut.isEnabled(PROPERTY_NAME, true);; Assert.assertTrue(enabled); @@ -124,4 +131,22 @@ public class BooleanFeatureFlagClientTest { Assert.assertFalse(enabled); } + @Test + public void isDecimationEnabled_return_true_from_cache() throws PartitionException { + when(this.cache.get(anyString())).thenReturn(true); + boolean enabled = sut.isEnabled(PROPERTY_NAME, false);; + Assert.assertTrue(enabled); + verify(headers, Mockito.times(0)).getHeaders(); + verify(factory, Mockito.times(0)).create(any()); + } + + @Test + public void isDecimationEnabled_return_false_from_cache() throws PartitionException { + when(this.cache.get(anyString())).thenReturn(false); + boolean enabled = sut.isEnabled(PROPERTY_NAME, false);; + Assert.assertFalse(enabled); + verify(headers, Mockito.times(0)).getHeaders(); + verify(factory, Mockito.times(0)).create(any()); + } + } diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RecordChangeInfoRedisCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RecordChangeInfoRedisCache.java index 0f2634719..b1a7996e0 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RecordChangeInfoRedisCache.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RecordChangeInfoRedisCache.java @@ -16,7 +16,7 @@ package org.opengroup.osdu.indexer.azure.cache; import org.opengroup.osdu.core.common.cache.RedisCache; -import org.opengroup.osdu.indexer.cache.IRecordChangeInfoCache; +import org.opengroup.osdu.indexer.cache.interfaces.IRecordChangeInfoCache; import org.opengroup.osdu.indexer.model.RecordChangeInfo; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RelatedObjectRedisCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RelatedObjectRedisCache.java index 9e6c0b58f..0a65faa92 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RelatedObjectRedisCache.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RelatedObjectRedisCache.java @@ -17,7 +17,7 @@ package org.opengroup.osdu.indexer.azure.cache; import org.opengroup.osdu.core.common.cache.RedisCache; import org.opengroup.osdu.core.common.model.storage.RecordData; -import org.opengroup.osdu.indexer.cache.IRelatedObjectCache; +import org.opengroup.osdu.indexer.cache.interfaces.IRelatedObjectCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Primary; -- GitLab