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 a200d0b25a166a40316e320f4d70d4cae247fef7..435e328353af2c137e26d83fe4e271cb44abe443 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 d57a5dbffda83a72c785a692da47d0bb3b756b64..0000000000000000000000000000000000000000 --- 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 2eec5cead55d7a78c62ff3c3a946070edbdca02f..9b6362c6c3f9810400d1ce7fd13abb2f303fa664 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 a270ab77d5141ffca5130f607eec92e40264ba82..f630c1d556c205bf354b251b91e8b5300557e777 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 4e8e0605237f42572ae0f4eb85e59c26a3d8248e..38e5f37a7ba1408711b9ccfbd55016e86e9c4c2d 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 99d2b6d3a6b8f09001164804d6135d06f659e4b5..1db22ec6f4f7ca3da748d8cfefad1ad751547254 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 796d13186d5dfe61f97de41ba8a437c28ccbf0a0..529231ee8f425fd42f3e004a215fdb195c8699de 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 c6ba7d0906690c1bee850805e720e7f903603b5c..625d7f74dac26565e14f63e8426a80567447eb0e 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 dda43845814be42a0cee4131922343acebe9120f..0341270be39e331482cfd3c8604e5eb5adc3a70f 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 c474065deded2a236e41e7d43436b874d9c295c1..6898d9d1d85a2cc63a14905d3675abdbb42a117a 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 74aa48e4fadeb7d477c1fed19aef9dc9662619d7..b174f12915abd55d36ec5db6753b5141eb7674c2 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 24a51559f9955861969a2536de31c397b2e6e85f..65ee4f96ad29808912c80dec1fb14d1a79651f27 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 4b6c372d333c2c5539ab5d1fab3f41dfdabff7e7..98bdbcc5dedeef3f5e1b5bff006a18dccea9afb9 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 25591747a59e9f2d1a4de0f7217331979365d499..f4a8baa0193c34b5d0d9ccfbbf7aa6282683bab2 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 4ddad5e468c7ea554033207cb7216dd55db1c7e0..53d47e4860bf5bf08dcb4b19b0a9c42c9a50d4b4 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 52d2cdf9e7e5220bd4c34293683fe6322b278d87..25a336649e9c5601204529a66d6a002fa94a14c0 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 1ca0c87aa4215064fd15d4f9674db0830184994e..107811a67ef12d7ed5b8177efa2f665684c8a401 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 59dd354871e2d722a444dffb6204dcd9f6a8e018..1653212051961cbdf51f672e63d641f70936a9c0 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 e8bea9da70c3903302e5172dd20bcd9a622687b3..086b4b3ceac97d307d25f17e67e07d23a68cb428 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 0000000000000000000000000000000000000000..ea81d3913d93f34dbfce33bd05f5ff5968ca131b --- /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 4cbb38658b60e8eedc209e8f75023d8f983ccf02..27e88715be65a7c66ecfe9937f7e2843c1764d6c 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 0942b5ecbc5decfc6d9902f96080505b7659f662..bb059f907a118b86c3808b3c640ac0e4ffc4de50 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 e1bc5adce2686070b5cfed0587823b7b2e4700b4..99275df91692891f6581c7ac9181989a6443228f 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 04a4d4082d91071722a2bc3500f86fd676ecae11..22752ecfb6a86b7bdd6b1fc85c94f02b32017529 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 0000000000000000000000000000000000000000..8c65943c23d80a49f39f98cc57c5c7f2b7f24255 --- /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 0000000000000000000000000000000000000000..d7cab300fc39f19ca9bd3a87c2ade3dc9498965d --- /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 862acb6e9399e3a7a32acc1a0d9303c6730de40d..1ec3f9f86a079ef1e7595431ef1010a81df50270 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 31b63bafb3fe19b1ad5a6302b94953c56c7f5c4f..048e87a393dd515143288d1426b0d152e777882a 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 a18cbd3fb4db5f5384e1ffb3585d08b436eb0f8e..3ac173b4fc1aaa65ac693e177f151d7d74585736 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 e585fca490a13a11f53acac4c9a1c5f54ee1a2cf..b2a55eb8870f23123b28070ea4cd6511354877b5 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 b21bbb47aec44f2774bc2cec8486a9c4b77bb5cf..e740c808dda2883b129d098025b8129d76483c13 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 b440c049d04c7575df51732a1c8f83aad8fe5f1a..977c466e74c94e7b8bf371ce9ed64952534598a5 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 106aad0b910d85fc818b307f264a7218fb6cae63..e7eb9a8fa2788dedcd7c45d86cf23a8f77eccb39 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 d7b8ce8ea814f24138780137d4356fb258b85b8f..12c098d8f3ff4f3dca05b037a0a2a8f43f323c4d 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 584bef57ee6d9b1e932494e57b722b5b1350ef5a..be63bc65290b01154deffe67a96e14e18b28abdb 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 1f0c43a9fccd6c56862c0243ff46c54b39052142..4d3354778de3c3a873fc9902917a26cfbc84c6ce 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 cc4bd6e1999a2a5428ed04c8a82df17b11d72f09..f73dabbeee8c95fa6065da8197c02a3f5b5d9534 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 b56339a96f294e8c8035d7844354cf885a7f1f2d..2310730c21be6c16723338cfffb4a7906706ef40 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 0000000000000000000000000000000000000000..3786cc3c676c5f7a40292939d61ea44e1817bd40 --- /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 4a309df7b7abd3028f69e79aa32c027bf08ec327..21db5a5d8e9bd7d2afad4326b80c07c6eec8b69b 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 0f2634719b91a5fe752266cd7a0ed674a1bfbd15..b1a7996e096abca00ef2cc0583f34e69154994c3 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 9e6c0b58f60c51e25f8265f9b5ac36395ad8b7ee..0a65faa92721baada73724f6eb413fe4213d4938 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;