diff --git a/search-core/src/main/java/org/opengroup/osdu/search/cache/IndexAliasCache.java b/search-core/src/main/java/org/opengroup/osdu/search/cache/IndexAliasCache.java deleted file mode 100644 index 9861d743ff61d9a98b16e96afe392bd56f127a10..0000000000000000000000000000000000000000 --- a/search-core/src/main/java/org/opengroup/osdu/search/cache/IndexAliasCache.java +++ /dev/null @@ -1,25 +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 -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.search.cache; - -import org.opengroup.osdu.core.common.cache.VmCache; -import org.springframework.stereotype.Component; - -@Component -public class IndexAliasCache extends VmCache<String, String> { - public IndexAliasCache() { - super(7 * 24 * 3600, 2000); - } -} diff --git a/search-core/src/main/java/org/opengroup/osdu/search/service/IndexAliasServiceImpl.java b/search-core/src/main/java/org/opengroup/osdu/search/service/IndexAliasServiceImpl.java index eee17a75765d0e0df7bccde0589d1ed409755087..5121649bcec64766370c3ee1241a1dda9c25c2b6 100644 --- a/search-core/src/main/java/org/opengroup/osdu/search/service/IndexAliasServiceImpl.java +++ b/search-core/src/main/java/org/opengroup/osdu/search/service/IndexAliasServiceImpl.java @@ -25,13 +25,13 @@ import org.elasticsearch.cluster.metadata.AliasMetadata; import org.elasticsearch.rest.RestStatus; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; -import org.opengroup.osdu.search.cache.IndexAliasCache; import org.opengroup.osdu.search.util.ElasticClientHandler; import org.springframework.stereotype.Component; import javax.inject.Inject; import java.io.IOException; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @Component @@ -41,10 +41,11 @@ public class IndexAliasServiceImpl implements IndexAliasService { @Inject private ElasticIndexNameResolver elasticIndexNameResolver; @Inject - private IndexAliasCache indexAliasCache; - @Inject private JaxRsDpsLog log; + private final Map<String, String> KIND_ALIAS_MAP = new ConcurrentHashMap(); + + @Override public Map<String, String> getIndicesAliases(List<String> kinds) { Map<String, String> aliases = new HashMap<>(); @@ -52,7 +53,7 @@ public class IndexAliasServiceImpl implements IndexAliasService { List<String> validKinds = kinds.stream().filter(k -> elasticIndexNameResolver.isIndexAliasSupported(k)).collect(Collectors.toList()); for(String kind: validKinds) { - String alias = indexAliasCache.get(kind); + String alias = KIND_ALIAS_MAP.get(kind); if(!Strings.isNullOrEmpty(alias)) { aliases.put(kind, alias); } @@ -67,15 +68,20 @@ public class IndexAliasServiceImpl implements IndexAliasService { for(String kind: unresolvedKinds) { String alias = elasticIndexNameResolver.getIndexAliasFromKind(kind); if(!allExistingAliases.contains(alias)) { - alias = createIndexAlias(restClient, kind); + try { + alias = createIndexAlias(restClient, kind); + } + catch(Exception e) { + log.error(String.format("Fail to create index alias for kind '%s'", kind), e); + } } if(!Strings.isNullOrEmpty(alias)) { aliases.put(kind, alias); - indexAliasCache.put(kind, alias); + KIND_ALIAS_MAP.put(kind, alias); } } } catch (Exception e) { - log.error(String.format("Fail to get or create index aliases for kinds"), e); + log.error(String.format("Fail to get index aliases for kinds"), e); } } @@ -86,7 +92,7 @@ public class IndexAliasServiceImpl implements IndexAliasService { if(!elasticIndexNameResolver.isIndexAliasSupported(kind)) return null; - String alias = indexAliasCache.get(kind); + String alias = KIND_ALIAS_MAP.get(kind); if(Strings.isNullOrEmpty(alias)) { try (RestHighLevelClient restClient = this.elasticClientHandler.createRestClient()) { if(isIndexAliasExistForKind(restClient, kind)) { @@ -97,7 +103,7 @@ public class IndexAliasServiceImpl implements IndexAliasService { } if(!Strings.isNullOrEmpty(alias)) { - indexAliasCache.put(kind, alias); + KIND_ALIAS_MAP.put(kind, alias); } } catch (Exception e) {