API changes to align with es7102
This commit is contained in:
parent
ac367270c1
commit
f8580edda8
9 changed files with 33 additions and 37 deletions
|
@ -24,8 +24,6 @@ public interface AdminClient extends BasicClient {
|
|||
|
||||
Map<String, ?> getMapping(String index) throws IOException;
|
||||
|
||||
Map<String, ?> 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<String> resolveAlias(String alias);
|
||||
|
||||
/**
|
||||
* Resolve alias to all connected indices, sort index names with most recent timestamp on top, return this index
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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<String, ?> getMapping(String index) throws IOException {
|
||||
return getMapping(index, TYPE_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ?> 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<String> 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<String, AliasOrIndex> 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<String, String> oldAliasMap = index.equals(oldIndex) ? null : getAliases(oldIndex);
|
||||
Optional<String> oldIndex = resolveAlias(index).stream().sorted().findFirst();
|
||||
Map<String, String> oldAliasMap = oldIndex.map(this::getAliases).orElse(null);
|
||||
logger.debug("old index = {} old alias map = {}", oldIndex, oldAliasMap);
|
||||
final List<String> newAliases = new ArrayList<>();
|
||||
final List<String> 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<String> optional = resolveAlias(fullName).stream().findFirst();
|
||||
fullIndexName = optional.orElse(fullName);
|
||||
} else {
|
||||
// check if index name already exists, resolve to it
|
||||
fullIndexName = resolveMostRecentIndex(indexName);
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> 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"));
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> 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"));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
|
||||
apply plugin: 'java-library'
|
||||
|
||||
java {
|
||||
modularity.inferModulePath.set(true)
|
||||
}
|
||||
|
||||
compileJava {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
|
|
Loading…
Reference in a new issue