From f8580edda80d5468ae5466f38991f9780d19d1cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Mon, 15 Feb 2021 14:41:49 +0100 Subject: [PATCH] API changes to align with es7102 --- .../java/org/xbib/elx/api/AdminClient.java | 4 +-- .../java/org/xbib/elx/api/BulkClient.java | 3 +- .../xbib/elx/common/AbstractAdminClient.java | 33 +++++++++---------- .../xbib/elx/node/test/BulkClientTest.java | 2 +- .../xbib/elx/node/test/IndexShiftTest.java | 10 +++--- .../elx/transport/test/BulkClientTest.java | 2 +- .../elx/transport/test/IndexShiftTest.java | 10 +++--- gradle.properties | 2 +- gradle/compile/java.gradle | 4 --- 9 files changed, 33 insertions(+), 37 deletions(-) diff --git a/elx-api/src/main/java/org/xbib/elx/api/AdminClient.java b/elx-api/src/main/java/org/xbib/elx/api/AdminClient.java index a7264ab..5db93c4 100644 --- a/elx-api/src/main/java/org/xbib/elx/api/AdminClient.java +++ b/elx-api/src/main/java/org/xbib/elx/api/AdminClient.java @@ -24,8 +24,6 @@ public interface AdminClient extends BasicClient { Map getMapping(String index) throws IOException; - Map getMapping(String index, String type) throws IOException; - void checkMapping(String index); /** @@ -101,7 +99,7 @@ public interface AdminClient extends BasicClient { * @param alias the alias * @return this index name behind the alias or the alias if there is no index */ - String resolveAlias(String alias); + List resolveAlias(String alias); /** * Resolve alias to all connected indices, sort index names with most recent timestamp on top, return this index diff --git a/elx-api/src/main/java/org/xbib/elx/api/BulkClient.java b/elx-api/src/main/java/org/xbib/elx/api/BulkClient.java index 9532af5..7ba88f3 100644 --- a/elx-api/src/main/java/org/xbib/elx/api/BulkClient.java +++ b/elx-api/src/main/java/org/xbib/elx/api/BulkClient.java @@ -14,12 +14,11 @@ import java.util.concurrent.TimeUnit; public interface BulkClient extends BasicClient, Flushable { /** - * Get buulk control. + * Get bulk control. * @return the bulk control */ BulkController getBulkController(); - /** * Create a new index. * diff --git a/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java b/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java index 4d60cde..bad581f 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java @@ -37,6 +37,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.cluster.metadata.AliasAction; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; @@ -75,6 +76,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; @@ -134,17 +136,12 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements @Override public Map getMapping(String index) throws IOException { - return getMapping(index, TYPE_NAME); - } - - @Override - public Map getMapping(String index, String mapping) throws IOException { GetMappingsRequestBuilder getMappingsRequestBuilder = new GetMappingsRequestBuilder(client, GetMappingsAction.INSTANCE) .setIndices(index) - .setTypes(mapping); + .setTypes(TYPE_NAME); GetMappingsResponse getMappingsResponse = getMappingsRequestBuilder.execute().actionGet(); - logger.info("get mappings response = {}", getMappingsResponse.getMappings().get(index).get(mapping).getSourceAsMap()); - return getMappingsResponse.getMappings().get(index).get(mapping).getSourceAsMap(); + logger.info("get mappings response = {}", getMappingsResponse.getMappings().get(index).get(TYPE_NAME).getSourceAsMap()); + return getMappingsResponse.getMappings().get(index).get(TYPE_NAME).getSourceAsMap(); } @Override @@ -231,7 +228,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements } @Override - public String resolveAlias(String alias) { + public List resolveAlias(String alias) { ensureClientIsPresent(); ClusterStateRequest clusterStateRequest = new ClusterStateRequest(); clusterStateRequest.blocks(false); @@ -243,7 +240,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements client.execute(ClusterStateAction.INSTANCE, clusterStateRequest).actionGet(); SortedMap map = clusterStateResponse.getState().getMetaData().getAliasAndIndexLookup(); AliasOrIndex aliasOrIndex = map.get(alias); - return aliasOrIndex != null ? aliasOrIndex.getIndices().iterator().next().getIndex() : null; + return aliasOrIndex != null ? aliasOrIndex.getIndices().stream().map(IndexMetaData::getIndex).collect(Collectors.toList()) : null; } @Override @@ -283,8 +280,8 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements } waitForCluster("YELLOW", 30L, TimeUnit.SECONDS); // two situations: 1. a new alias 2. there is already an old index with the alias - String oldIndex = resolveAlias(index); - Map oldAliasMap = index.equals(oldIndex) ? null : getAliases(oldIndex); + Optional oldIndex = resolveAlias(index).stream().sorted().findFirst(); + Map oldAliasMap = oldIndex.map(this::getAliases).orElse(null); logger.debug("old index = {} old alias map = {}", oldIndex, oldAliasMap); final List newAliases = new ArrayList<>(); final List moveAliases = new ArrayList<>(); @@ -300,7 +297,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements String alias = entry.getKey(); String filter = entry.getValue(); indicesAliasesRequest.addAliasAction(new IndicesAliasesRequest.AliasActions(AliasAction.Type.REMOVE, - oldIndex, alias)); + oldIndex.get(), alias)); if (filter != null) { indicesAliasesRequest.addAliasAction(new IndicesAliasesRequest.AliasActions(AliasAction.Type.ADD, fullIndexName, alias).filter(filter)); @@ -326,7 +323,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements } else { String filter = oldAliasMap.get(additionalAlias); indicesAliasesRequest.addAliasAction(new IndicesAliasesRequest.AliasActions(AliasAction.Type.REMOVE, - oldIndex, additionalAlias)); + oldIndex.get(), additionalAlias)); if (filter != null) { indicesAliasesRequest.addAliasAction(new IndicesAliasesRequest.AliasActions(AliasAction.Type.ADD, fullIndexName, additionalAlias).filter(filter)); @@ -466,9 +463,11 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements String dateTimePattern = settings.get("dateTimePattern"); if (dateTimePattern != null) { // check if index name with current date already exists, resolve to it - fullIndexName = resolveAlias(indexName + DateTimeFormatter.ofPattern(dateTimePattern) - .withZone(ZoneId.systemDefault()) // not GMT - .format(LocalDate.now())); + String fullName = indexName + DateTimeFormatter.ofPattern(dateTimePattern) + .withZone(ZoneId.systemDefault()) // not GMT + .format(LocalDate.now()); + Optional optional = resolveAlias(fullName).stream().findFirst(); + fullIndexName = optional.orElse(fullName); } else { // check if index name already exists, resolve to it fullIndexName = resolveMostRecentIndex(indexName); diff --git a/elx-node/src/test/java/org/xbib/elx/node/test/BulkClientTest.java b/elx-node/src/test/java/org/xbib/elx/node/test/BulkClientTest.java index 7d81298..8a1b540 100644 --- a/elx-node/src/test/java/org/xbib/elx/node/test/BulkClientTest.java +++ b/elx-node/src/test/java/org/xbib/elx/node/test/BulkClientTest.java @@ -91,7 +91,7 @@ class BulkClientTest { .endObject() .endObject(); bulkClient.newIndex("test", Settings.EMPTY, builder); - assertTrue(adminClient.getMapping("test", "doc").containsKey("properties")); + assertTrue(adminClient.getMapping("test").containsKey("properties")); } } diff --git a/elx-node/src/test/java/org/xbib/elx/node/test/IndexShiftTest.java b/elx-node/src/test/java/org/xbib/elx/node/test/IndexShiftTest.java index 615fe82..b192b3e 100644 --- a/elx-node/src/test/java/org/xbib/elx/node/test/IndexShiftTest.java +++ b/elx-node/src/test/java/org/xbib/elx/node/test/IndexShiftTest.java @@ -15,7 +15,9 @@ import org.xbib.elx.node.NodeAdminClientProvider; import org.xbib.elx.node.NodeBulkClient; import org.xbib.elx.node.NodeBulkClientProvider; import java.util.Arrays; +import java.util.Collections; import java.util.Map; +import java.util.Optional; import java.util.concurrent.TimeUnit; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -63,8 +65,8 @@ class IndexShiftTest { assertTrue(aliases.containsKey("b")); assertTrue(aliases.containsKey("c")); assertTrue(aliases.containsKey("test")); - String resolved = adminClient.resolveAlias("test"); - aliases = adminClient.getAliases(resolved); + Optional resolved = adminClient.resolveAlias("test").stream().findFirst(); + aliases = resolved.isPresent() ? adminClient.getAliases(resolved.get()) : Collections.emptyMap(); assertTrue(aliases.containsKey("a")); assertTrue(aliases.containsKey("b")); assertTrue(aliases.containsKey("c")); @@ -93,8 +95,8 @@ class IndexShiftTest { assertTrue(aliases.containsKey("d")); assertTrue(aliases.containsKey("e")); assertTrue(aliases.containsKey("f")); - resolved = adminClient.resolveAlias("test"); - aliases = adminClient.getAliases(resolved); + resolved = adminClient.resolveAlias("test").stream().findFirst(); + aliases = resolved.isPresent() ? adminClient.getAliases(resolved.get()) : Collections.emptyMap(); assertTrue(aliases.containsKey("a")); assertTrue(aliases.containsKey("b")); assertTrue(aliases.containsKey("c")); diff --git a/elx-transport/src/test/java/org/xbib/elx/transport/test/BulkClientTest.java b/elx-transport/src/test/java/org/xbib/elx/transport/test/BulkClientTest.java index 4089d89..ef8822b 100644 --- a/elx-transport/src/test/java/org/xbib/elx/transport/test/BulkClientTest.java +++ b/elx-transport/src/test/java/org/xbib/elx/transport/test/BulkClientTest.java @@ -90,7 +90,7 @@ class BulkClientTest { .endObject() .endObject(); bulkClient.newIndex("test", Settings.EMPTY, builder); - assertTrue(adminClient.getMapping("test", "doc").containsKey("properties")); + assertTrue(adminClient.getMapping("test").containsKey("properties")); } } diff --git a/elx-transport/src/test/java/org/xbib/elx/transport/test/IndexShiftTest.java b/elx-transport/src/test/java/org/xbib/elx/transport/test/IndexShiftTest.java index d6cfd7a..993d798 100644 --- a/elx-transport/src/test/java/org/xbib/elx/transport/test/IndexShiftTest.java +++ b/elx-transport/src/test/java/org/xbib/elx/transport/test/IndexShiftTest.java @@ -16,7 +16,9 @@ import org.xbib.elx.transport.TransportBulkClient; import org.xbib.elx.transport.TransportBulkClientProvider; import java.util.Arrays; +import java.util.Collections; import java.util.Map; +import java.util.Optional; import java.util.concurrent.TimeUnit; import static org.junit.jupiter.api.Assertions.assertNull; @@ -65,8 +67,8 @@ class IndexShiftTest { assertTrue(aliases.containsKey("b")); assertTrue(aliases.containsKey("c")); assertTrue(aliases.containsKey("test")); - String resolved = adminClient.resolveAlias("test"); - aliases = adminClient.getAliases(resolved); + Optional resolved = adminClient.resolveAlias("test").stream().findFirst(); + aliases = resolved.isPresent() ? adminClient.getAliases(resolved.get()) : Collections.emptyMap(); assertTrue(aliases.containsKey("a")); assertTrue(aliases.containsKey("b")); assertTrue(aliases.containsKey("c")); @@ -95,8 +97,8 @@ class IndexShiftTest { assertTrue(aliases.containsKey("d")); assertTrue(aliases.containsKey("e")); assertTrue(aliases.containsKey("f")); - resolved = adminClient.resolveAlias("test"); - aliases = adminClient.getAliases(resolved); + resolved = adminClient.resolveAlias("test").stream().findFirst(); + aliases = resolved.isPresent() ? adminClient.getAliases(resolved.get()) : Collections.emptyMap(); assertTrue(aliases.containsKey("a")); assertTrue(aliases.containsKey("b")); assertTrue(aliases.containsKey("c")); diff --git a/gradle.properties b/gradle.properties index c4a9778..25fbe5a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ group = org.xbib name = elx -version = 2.2.1.25 +version = 2.2.1.26 gradle.wrapper.version = 6.6.1 xbib-metrics.version = 2.1.0 diff --git a/gradle/compile/java.gradle b/gradle/compile/java.gradle index a9d76ce..40e75b5 100644 --- a/gradle/compile/java.gradle +++ b/gradle/compile/java.gradle @@ -1,10 +1,6 @@ apply plugin: 'java-library' -java { - modularity.inferModulePath.set(true) -} - compileJava { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11