Merge branch 'stable-2.14' into stable-2.15
* stable-2.14: Add support for Elasticsearch 6.4.0 Upgrade elasticsearch-rest-client to 6.4.0 ElasticVersion: Say 'Unsupported' rather than 'Invalid' Change-Id: Id68197d3f4a43e19711581366ed234cb420957d9
This commit is contained in:
commit
0012691460
|
@ -879,8 +879,8 @@ maven_jar(
|
|||
|
||||
maven_jar(
|
||||
name = "elasticsearch-rest-client",
|
||||
artifact = "org.elasticsearch.client:elasticsearch-rest-client:6.3.2",
|
||||
sha1 = "2077ea5f00fdd2d6af85223b730ba8047303297f",
|
||||
artifact = "org.elasticsearch.client:elasticsearch-rest-client:6.4.0",
|
||||
sha1 = "0eaa13decb9796eb671c5841d0770ae68b348da5",
|
||||
)
|
||||
|
||||
JACKSON_VERSION = "2.6.6"
|
||||
|
|
|
@ -56,6 +56,11 @@ public class ElasticReindexIT extends AbstractReindexTests {
|
|||
return getConfig(ElasticVersion.V6_3);
|
||||
}
|
||||
|
||||
@ConfigSuite.Config
|
||||
public static Config elasticsearchV6_4() {
|
||||
return getConfig(ElasticVersion.V6_4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureIndex(Injector injector) throws Exception {
|
||||
ElasticTestUtils.createAllIndexes(injector);
|
||||
|
|
|
@ -55,6 +55,11 @@ public class ElasticIndexIT extends AbstractIndexTests {
|
|||
return getConfig(ElasticVersion.V6_3);
|
||||
}
|
||||
|
||||
@ConfigSuite.Config
|
||||
public static Config elasticsearchV6_4() {
|
||||
return getConfig(ElasticVersion.V6_4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureIndex(Injector injector) throws Exception {
|
||||
ElasticTestUtils.createAllIndexes(injector);
|
||||
|
|
|
@ -48,6 +48,7 @@ import org.apache.http.HttpEntity;
|
|||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.nio.entity.NStringEntity;
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.Response;
|
||||
|
||||
abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
||||
|
@ -146,10 +147,10 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
|||
public void deleteAll() throws IOException {
|
||||
// Delete the index, if it exists.
|
||||
String endpoint = indexName + client.adapter().indicesExistParam();
|
||||
Response response = client.get().performRequest("HEAD", endpoint);
|
||||
Response response = client.get().performRequest(new Request("HEAD", endpoint));
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode == HttpStatus.SC_OK) {
|
||||
response = client.get().performRequest("DELETE", indexName);
|
||||
response = client.get().performRequest(new Request("DELETE", indexName));
|
||||
statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode != HttpStatus.SC_OK) {
|
||||
throw new IOException(
|
||||
|
@ -238,8 +239,12 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
|||
|
||||
private Response performRequest(
|
||||
String method, Object payload, String uri, Map<String, String> params) throws IOException {
|
||||
Request request = new Request(method, uri);
|
||||
String payloadStr = payload instanceof String ? (String) payload : payload.toString();
|
||||
HttpEntity entity = new NStringEntity(payloadStr, ContentType.APPLICATION_JSON);
|
||||
return client.get().performRequest(method, uri, params, entity);
|
||||
request.setEntity(new NStringEntity(payloadStr, ContentType.APPLICATION_JSON));
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
request.addParameter(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return client.get().performRequest(request);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -41,10 +41,8 @@ class ElasticIndexVersionDiscovery {
|
|||
|
||||
List<String> discover(String prefix, String indexName) throws IOException {
|
||||
String name = prefix + indexName + "_";
|
||||
Response response =
|
||||
client
|
||||
.get()
|
||||
.performRequest(HttpGet.METHOD_NAME, client.adapter().getVersionDiscoveryUrl(name));
|
||||
Request request = new Request("GET", client.adapter().getVersionDiscoveryUrl(name));
|
||||
Response response = client.get().performRequest(request);
|
||||
|
||||
StatusLine statusLine = response.getStatusLine();
|
||||
if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
|
||||
|
|
|
@ -38,6 +38,7 @@ public class ElasticQueryAdapter {
|
|||
case V5_6:
|
||||
case V6_2:
|
||||
case V6_3:
|
||||
case V6_4:
|
||||
this.searchFilteringName = "_source";
|
||||
this.indicesExistParam = "?allow_no_indices=false";
|
||||
this.exactFieldType = "keyword";
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
|
|||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestClientBuilder;
|
||||
|
@ -106,7 +107,7 @@ class ElasticRestClientProvider implements Provider<RestClient>, LifecycleListen
|
|||
|
||||
private ElasticVersion getVersion() throws ElasticException {
|
||||
try {
|
||||
Response response = client.performRequest("GET", "");
|
||||
Response response = client.performRequest(new Request("GET", ""));
|
||||
StatusLine statusLine = response.getStatusLine();
|
||||
if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
|
||||
throw new FailedToGetVersion(statusLine);
|
||||
|
|
|
@ -21,7 +21,8 @@ public enum ElasticVersion {
|
|||
V2_4("2.4.*"),
|
||||
V5_6("5.6.*"),
|
||||
V6_2("6.2.*"),
|
||||
V6_3("6.3.*");
|
||||
V6_3("6.3.*"),
|
||||
V6_4("6.4.*");
|
||||
|
||||
private final String version;
|
||||
private final Pattern pattern;
|
||||
|
@ -31,23 +32,23 @@ public enum ElasticVersion {
|
|||
this.pattern = Pattern.compile(version);
|
||||
}
|
||||
|
||||
public static class InvalidVersion extends ElasticException {
|
||||
public static class UnsupportedVersion extends ElasticException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
InvalidVersion(String version) {
|
||||
UnsupportedVersion(String version) {
|
||||
super(
|
||||
String.format(
|
||||
"Invalid version: [%s]. Supported versions: %s", version, supportedVersions()));
|
||||
"Unsupported version: [%s]. Supported versions: %s", version, supportedVersions()));
|
||||
}
|
||||
}
|
||||
|
||||
public static ElasticVersion forVersion(String version) throws InvalidVersion {
|
||||
public static ElasticVersion forVersion(String version) throws UnsupportedVersion {
|
||||
for (ElasticVersion value : ElasticVersion.values()) {
|
||||
if (value.pattern.matcher(version).matches()) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
throw new InvalidVersion(version);
|
||||
throw new UnsupportedVersion(version);
|
||||
}
|
||||
|
||||
public static String supportedVersions() {
|
||||
|
|
|
@ -50,6 +50,8 @@ public class ElasticContainer<SELF extends ElasticContainer<SELF>> extends Gener
|
|||
return "docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4";
|
||||
case V6_3:
|
||||
return "docker.elastic.co/elasticsearch/elasticsearch-oss:6.3.2";
|
||||
case V6_4:
|
||||
return "docker.elastic.co/elasticsearch/elasticsearch-oss:6.4.0";
|
||||
}
|
||||
throw new IllegalStateException("No tests for version: " + version.name());
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest {
|
|||
return;
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_3);
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_4);
|
||||
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest {
|
|||
return;
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_3);
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_4);
|
||||
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest {
|
|||
return;
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_3);
|
||||
container = ElasticContainer.createAndStart(ElasticVersion.V6_4);
|
||||
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
|
|
|
@ -37,13 +37,16 @@ public class ElasticVersionTest {
|
|||
|
||||
assertThat(ElasticVersion.forVersion("6.3.0")).isEqualTo(ElasticVersion.V6_3);
|
||||
assertThat(ElasticVersion.forVersion("6.3.1")).isEqualTo(ElasticVersion.V6_3);
|
||||
|
||||
assertThat(ElasticVersion.forVersion("6.4.0")).isEqualTo(ElasticVersion.V6_4);
|
||||
assertThat(ElasticVersion.forVersion("6.4.1")).isEqualTo(ElasticVersion.V6_4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsupportedVersion() throws Exception {
|
||||
exception.expect(ElasticVersion.InvalidVersion.class);
|
||||
exception.expect(ElasticVersion.UnsupportedVersion.class);
|
||||
exception.expectMessage(
|
||||
"Invalid version: [4.0.0]. Supported versions: " + ElasticVersion.supportedVersions());
|
||||
"Unsupported version: [4.0.0]. Supported versions: " + ElasticVersion.supportedVersions());
|
||||
ElasticVersion.forVersion("4.0.0");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue