From 1899aea9cae17f928e86650cac40664f7fda86c4 Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 29 Dec 2016 15:30:37 +0100 Subject: [PATCH 01/22] [TEST] move randomHeaders method from RestClientTestCase to RestClientTestUtil and simplify headers assertions --- .../RestClientSingleHostIntegTests.java | 32 ++---- .../client/RestClientSingleHostTests.java | 34 ++---- .../client/RestClientTestCase.java | 101 ++++++++---------- .../client/RestClientTestUtil.java | 23 ++++ 4 files changed, 80 insertions(+), 110 deletions(-) diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostIntegTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostIntegTests.java index 2f94de7154c..8f4170add3d 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostIntegTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostIntegTests.java @@ -40,7 +40,6 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -50,7 +49,6 @@ import static org.elasticsearch.client.RestClientTestUtil.getAllStatusCodes; import static org.elasticsearch.client.RestClientTestUtil.getHttpMethods; import static org.elasticsearch.client.RestClientTestUtil.randomStatusCode; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; /** @@ -77,8 +75,7 @@ public class RestClientSingleHostIntegTests extends RestClientTestCase { } httpServer = createHttpServer(); - int numHeaders = randomIntBetween(0, 5); - defaultHeaders = generateHeaders("Header-default", "Header-array", numHeaders); + defaultHeaders = RestClientTestUtil.randomHeaders(getRandom(), "Header-default"); RestClientBuilder restClientBuilder = RestClient.builder( new HttpHost(httpServer.getAddress().getHostString(), httpServer.getAddress().getPort())).setDefaultHeaders(defaultHeaders); if (pathPrefix.length() > 0) { @@ -151,17 +148,11 @@ public class RestClientSingleHostIntegTests extends RestClientTestCase { if (method.equals("HEAD") == false) { standardHeaders.add("Content-length"); } - - final int numHeaders = randomIntBetween(1, 5); - final Header[] headers = generateHeaders("Header", "Header-array", numHeaders); - final Map> expectedHeaders = new HashMap<>(); - - addHeaders(expectedHeaders, defaultHeaders, headers); - + final Header[] requestHeaders = RestClientTestUtil.randomHeaders(getRandom(), "Header"); final int statusCode = randomStatusCode(getRandom()); Response esResponse; try { - esResponse = restClient.performRequest(method, "/" + statusCode, Collections.emptyMap(), headers); + esResponse = restClient.performRequest(method, "/" + statusCode, Collections.emptyMap(), requestHeaders); } catch(ResponseException e) { esResponse = e.getResponse(); } @@ -169,24 +160,13 @@ public class RestClientSingleHostIntegTests extends RestClientTestCase { assertEquals(method, esResponse.getRequestLine().getMethod()); assertEquals(statusCode, esResponse.getStatusLine().getStatusCode()); assertEquals((pathPrefix.length() > 0 ? pathPrefix : "") + "/" + statusCode, esResponse.getRequestLine().getUri()); - + assertHeaders(defaultHeaders, requestHeaders, esResponse.getHeaders(), standardHeaders); for (final Header responseHeader : esResponse.getHeaders()) { - final String name = responseHeader.getName(); - final String value = responseHeader.getValue(); - if (name.startsWith("Header")) { - final List values = expectedHeaders.get(name); - assertNotNull("found response header [" + name + "] that wasn't originally sent: " + value, values); - assertTrue("found incorrect response header [" + name + "]: " + value, values.remove(value)); - - // we've collected them all - if (values.isEmpty()) { - expectedHeaders.remove(name); - } - } else { + String name = responseHeader.getName(); + if (name.startsWith("Header") == false) { assertTrue("unknown header was returned " + name, standardHeaders.remove(name)); } } - assertTrue("some headers that were sent weren't returned: " + expectedHeaders, expectedHeaders.isEmpty()); assertTrue("some expected standard headers weren't returned: " + standardHeaders, standardHeaders.isEmpty()); } } diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java index ce0d6d0936e..865f9b1817a 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java @@ -56,7 +56,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.Future; @@ -70,7 +69,6 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -131,9 +129,7 @@ public class RestClientSingleHostTests extends RestClientTestCase { } }); - - int numHeaders = randomIntBetween(0, 3); - defaultHeaders = generateHeaders("Header-default", "Header-array", numHeaders); + defaultHeaders = RestClientTestUtil.randomHeaders(getRandom(), "Header-default"); httpHost = new HttpHost("localhost", 9200); failureListener = new HostsTrackingFailureListener(); restClient = new RestClient(httpClient, 10000, defaultHeaders, new HttpHost[]{httpHost}, null, failureListener); @@ -339,33 +335,16 @@ public class RestClientSingleHostTests extends RestClientTestCase { */ public void testHeaders() throws IOException { for (String method : getHttpMethods()) { - final int numHeaders = randomIntBetween(1, 5); - final Header[] headers = generateHeaders("Header", null, numHeaders); - final Map> expectedHeaders = new HashMap<>(); - - addHeaders(expectedHeaders, defaultHeaders, headers); - + final Header[] requestHeaders = RestClientTestUtil.randomHeaders(getRandom(), "Header"); final int statusCode = randomStatusCode(getRandom()); Response esResponse; try { - esResponse = restClient.performRequest(method, "/" + statusCode, headers); + esResponse = restClient.performRequest(method, "/" + statusCode, requestHeaders); } catch(ResponseException e) { esResponse = e.getResponse(); } assertThat(esResponse.getStatusLine().getStatusCode(), equalTo(statusCode)); - for (Header responseHeader : esResponse.getHeaders()) { - final String name = responseHeader.getName(); - final String value = responseHeader.getValue(); - final List values = expectedHeaders.get(name); - assertNotNull("found response header [" + name + "] that wasn't originally sent: " + value, values); - assertTrue("found incorrect response header [" + name + "]: " + value, values.remove(value)); - - // we've collected them all - if (values.isEmpty()) { - expectedHeaders.remove(name); - } - } - assertTrue("some headers that were sent weren't returned " + expectedHeaders, expectedHeaders.isEmpty()); + assertHeaders(defaultHeaders, requestHeaders, esResponse.getHeaders(), Collections.emptySet()); } } @@ -424,10 +403,9 @@ public class RestClientSingleHostTests extends RestClientTestCase { } Header[] headers = new Header[0]; - final int numHeaders = randomIntBetween(1, 5); - final Set uniqueNames = new HashSet<>(numHeaders); + final Set uniqueNames = new HashSet<>(); if (randomBoolean()) { - headers = generateHeaders("Header", "Header-array", numHeaders); + headers = RestClientTestUtil.randomHeaders(getRandom(), "Header"); for (Header header : headers) { request.addHeader(header); uniqueNames.add(header.getName()); diff --git a/client/test/src/main/java/org/elasticsearch/client/RestClientTestCase.java b/client/test/src/main/java/org/elasticsearch/client/RestClientTestCase.java index 4296932a002..6a2a45ef281 100644 --- a/client/test/src/main/java/org/elasticsearch/client/RestClientTestCase.java +++ b/client/test/src/main/java/org/elasticsearch/client/RestClientTestCase.java @@ -30,16 +30,19 @@ import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies; import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; - import org.apache.http.Header; -import org.apache.http.message.BasicHeader; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + @TestMethodProviders({ JUnit3MethodProvider.class }) @@ -53,70 +56,56 @@ import java.util.Set; public abstract class RestClientTestCase extends RandomizedTest { /** - * Create the specified number of {@link Header}s. - *

- * Generated header names will be the {@code baseName} plus its index or, rarely, the {@code arrayName} if it's supplied. + * Assert that the actual headers are the expected ones given the original default and request headers. Some headers can be ignored, + * for instance in case the http client is adding its own automatically. * - * @param baseName The base name to use for all headers. - * @param arrayName The optional ({@code null}able) array name to use randomly. - * @param headers The number of headers to create. - * @return Never {@code null}. + * @param defaultHeaders the default headers set to the REST client instance + * @param requestHeaders the request headers sent with a particular request + * @param actualHeaders the actual headers as a result of the provided default and request headers + * @param ignoreHeaders header keys to be ignored as they are not part of default nor request headers, yet they + * will be part of the actual ones */ - protected static Header[] generateHeaders(final String baseName, final String arrayName, final int headers) { - final Header[] generated = new Header[headers]; - for (int i = 0; i < headers; i++) { - String headerName = baseName + i; - if (arrayName != null && rarely()) { - headerName = arrayName; - } - - generated[i] = new BasicHeader(headerName, randomAsciiOfLengthBetween(3, 10)); + protected static void assertHeaders(final Header[] defaultHeaders, final Header[] requestHeaders, + final Header[] actualHeaders, final Set ignoreHeaders) { + final Map> expectedHeaders = new HashMap<>(); + final Set requestHeaderKeys = new HashSet<>(); + for (final Header header : requestHeaders) { + final String name = header.getName(); + addValueToListEntry(expectedHeaders, name, header.getValue()); + requestHeaderKeys.add(name); } - return generated; + for (final Header defaultHeader : defaultHeaders) { + final String name = defaultHeader.getName(); + if (requestHeaderKeys.contains(name) == false) { + addValueToListEntry(expectedHeaders, name, defaultHeader.getValue()); + } + } + Set actualIgnoredHeaders = new HashSet<>(); + for (Header responseHeader : actualHeaders) { + final String name = responseHeader.getName(); + if (ignoreHeaders.contains(name)) { + expectedHeaders.remove(name); + actualIgnoredHeaders.add(name); + continue; + } + final String value = responseHeader.getValue(); + final List values = expectedHeaders.get(name); + assertNotNull("found response header [" + name + "] that wasn't originally sent: " + value, values); + assertTrue("found incorrect response header [" + name + "]: " + value, values.remove(value)); + if (values.isEmpty()) { + expectedHeaders.remove(name); + } + } + assertEquals("some headers meant to be ignored were not part of the actual headers", ignoreHeaders, actualIgnoredHeaders); + assertTrue("some headers that were sent weren't returned " + expectedHeaders, expectedHeaders.isEmpty()); } - /** - * Create a new {@link List} within the {@code map} if none exists for {@code name} or append to the existing list. - * - * @param map The map to manipulate. - * @param name The name to create/append the list for. - * @param value The value to add. - */ - private static void createOrAppendList(final Map> map, final String name, final String value) { + private static void addValueToListEntry(final Map> map, final String name, final String value) { List values = map.get(name); - if (values == null) { values = new ArrayList<>(); map.put(name, values); } - values.add(value); } - - /** - * Add the {@code headers} to the {@code map} so that related tests can more easily assert that they exist. - *

- * If both the {@code defaultHeaders} and {@code headers} contain the same {@link Header}, based on its - * {@linkplain Header#getName() name}, then this will only use the {@code Header}(s) from {@code headers}. - * - * @param map The map to build with name/value(s) pairs. - * @param defaultHeaders The headers to add to the map representing default headers. - * @param headers The headers to add to the map representing request-level headers. - * @see #createOrAppendList(Map, String, String) - */ - protected static void addHeaders(final Map> map, final Header[] defaultHeaders, final Header[] headers) { - final Set uniqueHeaders = new HashSet<>(); - for (final Header header : headers) { - final String name = header.getName(); - createOrAppendList(map, name, header.getValue()); - uniqueHeaders.add(name); - } - for (final Header defaultHeader : defaultHeaders) { - final String name = defaultHeader.getName(); - if (uniqueHeaders.contains(name) == false) { - createOrAppendList(map, name, defaultHeader.getValue()); - } - } - } - } diff --git a/client/test/src/main/java/org/elasticsearch/client/RestClientTestUtil.java b/client/test/src/main/java/org/elasticsearch/client/RestClientTestUtil.java index 4d4aa00f492..dbf85578b19 100644 --- a/client/test/src/main/java/org/elasticsearch/client/RestClientTestUtil.java +++ b/client/test/src/main/java/org/elasticsearch/client/RestClientTestUtil.java @@ -19,7 +19,11 @@ package org.elasticsearch.client; +import com.carrotsearch.randomizedtesting.generators.RandomNumbers; import com.carrotsearch.randomizedtesting.generators.RandomPicks; +import com.carrotsearch.randomizedtesting.generators.RandomStrings; +import org.apache.http.Header; +import org.apache.http.message.BasicHeader; import java.util.ArrayList; import java.util.Arrays; @@ -81,4 +85,23 @@ final class RestClientTestUtil { static List getAllStatusCodes() { return ALL_STATUS_CODES; } + + /** + * Create a random number of {@link Header}s. + * Generated header names will either be the {@code baseName} plus its index, or exactly the provided {@code baseName} so that the + * we test also support for multiple headers with same key and different values. + */ + static Header[] randomHeaders(Random random, final String baseName) { + int numHeaders = RandomNumbers.randomIntBetween(random, 0, 5); + final Header[] headers = new Header[numHeaders]; + for (int i = 0; i < numHeaders; i++) { + String headerName = baseName; + //randomly exercise the code path that supports multiple headers with same key + if (random.nextBoolean()) { + headerName = headerName + i; + } + headers[i] = new BasicHeader(headerName, RandomStrings.randomAsciiOfLengthBetween(random, 3, 10)); + } + return headers; + } } From f0181b19f565ad255a7705190077897ec173ac0f Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 29 Dec 2016 18:16:04 +0100 Subject: [PATCH 02/22] add REST high level client gradle submodule and first simple method The RestHighLevelClient class takes as as an argument a low level client instance RestClient. The first method added is ping, which returns true if the call to HEAD / went ok and false if an IOException was thrown. Any other exception gets bubbled up. There are two kinds of tests, a unit test (RestHighLevelClientTests) that verifies the interaction between high level and low level client, and an integration test (MainActionIT) which relies on an externally started es cluster to send requests to. --- .../test/StandaloneTestBasePlugin.groovy | 10 ++- client/rest-high-level/build.gradle | 41 +++++++++ .../client/RestHighLevelClient.java | 51 +++++++++++ .../client/ESRestHighLevelClientTestCase.java | 48 ++++++++++ .../elasticsearch/client/MainActionIT.java | 27 ++++++ .../client/RestHighLevelClientTests.java | 87 +++++++++++++++++++ settings.gradle | 1 + 7 files changed, 262 insertions(+), 3 deletions(-) create mode 100644 client/rest-high-level/build.gradle create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/MainActionIT.java create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestBasePlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestBasePlugin.groovy index af2b20e4abf..db68035e3eb 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestBasePlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestBasePlugin.groovy @@ -26,6 +26,7 @@ import org.elasticsearch.gradle.VersionProperties import org.elasticsearch.gradle.precommit.PrecommitTasks import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.Task import org.gradle.api.plugins.JavaBasePlugin /** Configures the build to have a rest integration test. */ @@ -40,7 +41,7 @@ public class StandaloneTestBasePlugin implements Plugin { BuildPlugin.configureRepositories(project) // only setup tests to build - project.sourceSets.create('test') + project.sourceSets.maybeCreate('test') project.dependencies.add('testCompile', "org.elasticsearch.test:framework:${VersionProperties.elasticsearch}") project.eclipse.classpath.sourceSets = [project.sourceSets.test] @@ -48,7 +49,10 @@ public class StandaloneTestBasePlugin implements Plugin { project.idea.module.testSourceDirs += project.sourceSets.test.java.srcDirs project.idea.module.scopes['TEST'] = [plus: [project.configurations.testRuntime]] - PrecommitTasks.create(project, false) - project.check.dependsOn(project.precommit) + Task precommitTask = project.tasks.findByName('precommit') + if (precommitTask == null) { + PrecommitTasks.create(project, false) + project.check.dependsOn(project.precommit) + } } } diff --git a/client/rest-high-level/build.gradle b/client/rest-high-level/build.gradle new file mode 100644 index 00000000000..162e8608d44 --- /dev/null +++ b/client/rest-high-level/build.gradle @@ -0,0 +1,41 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you 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. + */ +apply plugin: 'elasticsearch.build' +apply plugin: 'elasticsearch.rest-test' + +group = 'org.elasticsearch.client' + +dependencies { + compile "org.elasticsearch:elasticsearch:${version}" + compile "org.elasticsearch.client:rest:${version}" + + testCompile "org.elasticsearch.client:test:${version}" + testCompile "org.elasticsearch.test:framework:${version}" + testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" + testCompile "junit:junit:${versions.junit}" + testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}" +} + +dependencyLicenses { + // Don't check licenses for dependency that are part of the elasticsearch project + // But any other dependency should have its license/notice/sha1 + dependencies = project.configurations.runtime.fileCollection { + it.group.startsWith('org.elasticsearch') == false + } +} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java new file mode 100644 index 00000000000..4bde0d37e61 --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java @@ -0,0 +1,51 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you 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.elasticsearch.client; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.Header; + +import java.io.IOException; +import java.util.Objects; + +/** + * High level REST client that wraps an instance of the low level {@link RestClient} and allows to build requests and read responses. + * The provided {@link RestClient} is externally built and closed. + */ +public final class RestHighLevelClient { + + private static final Log logger = LogFactory.getLog(RestHighLevelClient.class); + + private final RestClient client; + + public RestHighLevelClient(RestClient client) { + this.client = Objects.requireNonNull(client); + } + + public boolean ping(Header... headers) { + try { + client.performRequest("HEAD", "/", headers); + return true; + } catch(IOException exception) { + return false; + } + } +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java new file mode 100644 index 00000000000..bc12b1433d7 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java @@ -0,0 +1,48 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you 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.elasticsearch.client; + +import org.elasticsearch.test.rest.ESRestTestCase; +import org.junit.AfterClass; +import org.junit.Before; + +import java.io.IOException; + +public abstract class ESRestHighLevelClientTestCase extends ESRestTestCase { + + private static RestHighLevelClient restHighLevelClient; + + @Before + public void initHighLevelClient() throws IOException { + super.initClient(); + if (restHighLevelClient == null) { + restHighLevelClient = new RestHighLevelClient(client()); + } + } + + @AfterClass + public static void cleanupClient() throws IOException { + restHighLevelClient = null; + } + + protected static RestHighLevelClient highLevelClient() { + return restHighLevelClient; + } +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/MainActionIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/MainActionIT.java new file mode 100644 index 00000000000..717ab7a44f3 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/MainActionIT.java @@ -0,0 +1,27 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you 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.elasticsearch.client; + +public class MainActionIT extends ESRestHighLevelClientTestCase { + + public void testPing() { + assertTrue(highLevelClient().ping()); + } +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java new file mode 100644 index 00000000000..7d513e48998 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -0,0 +1,87 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you 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.elasticsearch.client; + +import org.apache.http.Header; +import org.elasticsearch.test.ESTestCase; +import org.junit.Before; +import org.mockito.ArgumentMatcher; +import org.mockito.internal.matchers.ArrayEquals; +import org.mockito.internal.matchers.VarargMatcher; + +import java.io.IOException; +import java.net.SocketTimeoutException; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.argThat; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class RestHighLevelClientTests extends ESTestCase { + + private RestClient restClient; + private RestHighLevelClient restHighLevelClient; + + @Before + public void initClient() throws IOException { + restClient = mock(RestClient.class); + restHighLevelClient = new RestHighLevelClient(restClient); + } + + public void testPing() throws IOException { + assertTrue(restHighLevelClient.ping()); + verify(restClient).performRequest(eq("HEAD"), eq("/"), argThat(new HeadersVarargMatcher())); + } + + public void testPingFailure() throws IOException { + when(restClient.performRequest(any(), any())).thenThrow(new IllegalStateException()); + expectThrows(IllegalStateException.class, () -> restHighLevelClient.ping()); + } + + public void testPingFailed() throws IOException { + when(restClient.performRequest(any(), any())).thenThrow(new SocketTimeoutException()); + assertFalse(restHighLevelClient.ping()); + } + + public void testPingWithHeaders() throws IOException { + Header[] headers = RestClientTestUtil.randomHeaders(random(), "Header"); + assertTrue(restHighLevelClient.ping(headers)); + verify(restClient).performRequest(eq("HEAD"), eq("/"), argThat(new HeadersVarargMatcher(headers))); + } + + private class HeadersVarargMatcher extends ArgumentMatcher implements VarargMatcher { + private Header[] expectedHeaders; + + HeadersVarargMatcher(Header... expectedHeaders) { + this.expectedHeaders = expectedHeaders; + } + + @Override + public boolean matches(Object varargArgument) { + if (varargArgument instanceof Header[]) { + Header[] actualHeaders = (Header[]) varargArgument; + return new ArrayEquals(expectedHeaders).matches(actualHeaders); + } + return false; + } + } +} diff --git a/settings.gradle b/settings.gradle index 609f1b0f8be..1125e84325c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,6 +7,7 @@ List projects = [ 'core', 'docs', 'client:rest', + 'client:rest-high-level', 'client:sniffer', 'client:transport', 'client:test', From 812f63e5ef11bcba0fa7350327a1e81a5cbd4016 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 3 Jan 2017 15:39:36 -0500 Subject: [PATCH 03/22] Require either BuildPlugin or StandaloneTestBasePlugin to use RestTestPlugin It used to be that RestTestPlugin "came with" StandaloneTestBasePlugin but we'd like to use it with BuildPlugin for the high level rest client. --- .../elasticsearch/gradle/BuildPlugin.groovy | 4 ++++ .../gradle/doc/DocsTestPlugin.groovy | 1 + .../gradle/test/RestTestPlugin.groovy | 18 +++++++++++++++-- .../test/StandaloneTestBasePlugin.groovy | 13 ++++++------ distribution/build.gradle | 5 +++-- qa/backwards-5.0/build.gradle | 20 +++++++++++++++++++ qa/smoke-test-client/build.gradle | 3 ++- qa/smoke-test-http/build.gradle | 3 ++- .../http/ContextAndHeaderTransportIT.java | 3 +-- qa/smoke-test-ingest-disabled/build.gradle | 1 + .../build.gradle | 1 + qa/smoke-test-multinode/build.gradle | 19 ++++++++++++++++++ qa/smoke-test-plugins/build.gradle | 2 +- .../build.gradle | 1 + qa/smoke-test-tribe-node/build.gradle | 1 + 15 files changed, 80 insertions(+), 15 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index 628e59de1a6..1cbbe0ac26d 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -21,6 +21,7 @@ package org.elasticsearch.gradle import nebula.plugin.extraconfigurations.ProvidedBasePlugin import org.elasticsearch.gradle.precommit.PrecommitTasks import org.gradle.api.GradleException +import org.gradle.api.InvalidUserDataException import org.gradle.api.JavaVersion import org.gradle.api.Plugin import org.gradle.api.Project @@ -54,6 +55,9 @@ class BuildPlugin implements Plugin { @Override void apply(Project project) { + if (project.pluginManager.hasPlugin('elasticsearch.standalone-test')) { + throw new InvalidUserDataException('elasticsearch.standalone-test and elasticsearch.build are mutually exclusive') + } project.pluginManager.apply('java') project.pluginManager.apply('carrotsearch.randomized-testing') // these plugins add lots of info to our jars diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/DocsTestPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/DocsTestPlugin.groovy index a46a7bda374..bb56360645f 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/DocsTestPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/DocsTestPlugin.groovy @@ -30,6 +30,7 @@ public class DocsTestPlugin extends RestTestPlugin { @Override public void apply(Project project) { + project.pluginManager.apply('elasticsearch.standalone-test') super.apply(project) Map defaultSubstitutions = [ /* These match up with the asciidoc syntax for substitutions but diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestTestPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestTestPlugin.groovy index dc9aa769388..e4f4b35cc78 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestTestPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestTestPlugin.groovy @@ -18,15 +18,29 @@ */ package org.elasticsearch.gradle.test +import org.elasticsearch.gradle.BuildPlugin +import org.gradle.api.InvalidUserDataException import org.gradle.api.Plugin import org.gradle.api.Project -/** A plugin to add rest integration tests. Used for qa projects. */ +/** + * Adds support for starting an Elasticsearch cluster before running integration + * tests. Used in conjunction with {@link StandaloneTestBasePlugin} for qa + * projects and in conjunction with {@link BuildPlugin} for testing the rest + * client. + */ public class RestTestPlugin implements Plugin { + List REQUIRED_PLUGINS = [ + 'elasticsearch.build', + 'elasticsearch.standalone-test'] @Override public void apply(Project project) { - project.pluginManager.apply(StandaloneTestBasePlugin) + if (false == REQUIRED_PLUGINS.any {project.pluginManager.hasPlugin(it)}) { + throw new InvalidUserDataException('elasticsearch.rest-test ' + + 'requires either elasticsearch.build or ' + + 'elasticsearch.standalone-test') + } RestIntegTestTask integTest = project.tasks.create('integTest', RestIntegTestTask.class) integTest.cluster.distribution = 'zip' // rest tests should run with the real zip diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestBasePlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestBasePlugin.groovy index db68035e3eb..b9b865cb62d 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestBasePlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestBasePlugin.groovy @@ -24,6 +24,7 @@ import com.carrotsearch.gradle.junit4.RandomizedTestingPlugin import org.elasticsearch.gradle.BuildPlugin import org.elasticsearch.gradle.VersionProperties import org.elasticsearch.gradle.precommit.PrecommitTasks +import org.gradle.api.InvalidUserDataException import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task @@ -34,6 +35,9 @@ public class StandaloneTestBasePlugin implements Plugin { @Override public void apply(Project project) { + if (project.pluginManager.hasPlugin('elasticsearch.build')) { + throw new InvalidUserDataException('elasticsearch.standalone-test and elasticsearch.build are mutually exclusive') + } project.pluginManager.apply(JavaBasePlugin) project.pluginManager.apply(RandomizedTestingPlugin) @@ -41,7 +45,7 @@ public class StandaloneTestBasePlugin implements Plugin { BuildPlugin.configureRepositories(project) // only setup tests to build - project.sourceSets.maybeCreate('test') + project.sourceSets.create('test') project.dependencies.add('testCompile', "org.elasticsearch.test:framework:${VersionProperties.elasticsearch}") project.eclipse.classpath.sourceSets = [project.sourceSets.test] @@ -49,10 +53,7 @@ public class StandaloneTestBasePlugin implements Plugin { project.idea.module.testSourceDirs += project.sourceSets.test.java.srcDirs project.idea.module.scopes['TEST'] = [plus: [project.configurations.testRuntime]] - Task precommitTask = project.tasks.findByName('precommit') - if (precommitTask == null) { - PrecommitTasks.create(project, false) - project.check.dependsOn(project.precommit) - } + PrecommitTasks.create(project, false) + project.check.dependsOn(project.precommit) } } diff --git a/distribution/build.gradle b/distribution/build.gradle index 2cfd7ebbbce..83f82d9cd6b 100644 --- a/distribution/build.gradle +++ b/distribution/build.gradle @@ -79,7 +79,7 @@ project.rootProject.subprojects.findAll { it.path.startsWith(':modules:') }.each restTestExpansions['expected.modules.count'] += 1 } -// Integ tests work over the rest http layer, so we need a transport included with the integ test zip. +// Integ tests work over the rest http layer, so we need a transport included with the integ test zip. // All transport modules are included so that they may be randomized for testing task buildTransportModules(type: Sync) { into 'build/transport-modules' @@ -104,6 +104,7 @@ subprojects { /***************************************************************************** * Rest test config * *****************************************************************************/ + apply plugin: 'elasticsearch.standalone-test' apply plugin: 'elasticsearch.rest-test' project.integTest { dependsOn project.assemble @@ -116,7 +117,7 @@ subprojects { mustRunAfter ':distribution:integ-test-zip:integTest#stop' } } - + processTestResources { inputs.properties(project(':distribution').restTestExpansions) MavenFilteringHack.filter(it, project(':distribution').restTestExpansions) diff --git a/qa/backwards-5.0/build.gradle b/qa/backwards-5.0/build.gradle index 5347429f03f..6dd165121b7 100644 --- a/qa/backwards-5.0/build.gradle +++ b/qa/backwards-5.0/build.gradle @@ -1,3 +1,23 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you 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. + */ + +apply plugin: 'elasticsearch.standalone-test' apply plugin: 'elasticsearch.rest-test' /* This project runs the core REST tests against a 2 node cluster where one of the nodes has a different minor. diff --git a/qa/smoke-test-client/build.gradle b/qa/smoke-test-client/build.gradle index 260516a5bf6..fca4177d3bb 100644 --- a/qa/smoke-test-client/build.gradle +++ b/qa/smoke-test-client/build.gradle @@ -17,10 +17,11 @@ * under the License. */ +apply plugin: 'elasticsearch.standalone-test' apply plugin: 'elasticsearch.rest-test' // TODO: this test works, but it isn't really a rest test...should we have another plugin for "non rest test that just needs N clusters?" dependencies { testCompile project(path: ':client:transport', configuration: 'runtime') // randomly swapped in as a transport -} \ No newline at end of file +} diff --git a/qa/smoke-test-http/build.gradle b/qa/smoke-test-http/build.gradle index 0bdacc1d48a..2fb61243fe8 100644 --- a/qa/smoke-test-http/build.gradle +++ b/qa/smoke-test-http/build.gradle @@ -17,8 +17,9 @@ * under the License. */ +apply plugin: 'elasticsearch.standalone-test' apply plugin: 'elasticsearch.rest-test' dependencies { testCompile project(path: ':modules:transport-netty4', configuration: 'runtime') // for http -} \ No newline at end of file +} diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java index 4c39d80a674..752e18dc917 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java @@ -22,7 +22,6 @@ package org.elasticsearch.http; import org.apache.http.message.BasicHeader; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; -import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.index.IndexRequest; @@ -317,7 +316,7 @@ public class ContextAndHeaderTransportIT extends HttpSmokeTestCase { } @Override - protected boolean apply(String action, ActionRequest request, ActionListener listener) { + protected boolean apply(String action, ActionRequest request, ActionListener listener) { requests.add(new RequestAndHeaders(threadPool.getThreadContext().getHeaders(), request)); return true; } diff --git a/qa/smoke-test-ingest-disabled/build.gradle b/qa/smoke-test-ingest-disabled/build.gradle index 08dfbf8ae7a..1d7491a3517 100644 --- a/qa/smoke-test-ingest-disabled/build.gradle +++ b/qa/smoke-test-ingest-disabled/build.gradle @@ -17,6 +17,7 @@ * under the License. */ +apply plugin: 'elasticsearch.standalone-test' apply plugin: 'elasticsearch.rest-test' dependencies { diff --git a/qa/smoke-test-ingest-with-all-dependencies/build.gradle b/qa/smoke-test-ingest-with-all-dependencies/build.gradle index df90bf5b982..e4ac1f29f89 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/build.gradle +++ b/qa/smoke-test-ingest-with-all-dependencies/build.gradle @@ -17,6 +17,7 @@ * under the License. */ +apply plugin: 'elasticsearch.standalone-test' apply plugin: 'elasticsearch.rest-test' dependencies { diff --git a/qa/smoke-test-multinode/build.gradle b/qa/smoke-test-multinode/build.gradle index f39f790ba09..52bf2427463 100644 --- a/qa/smoke-test-multinode/build.gradle +++ b/qa/smoke-test-multinode/build.gradle @@ -1,4 +1,23 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you 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. + */ +apply plugin: 'elasticsearch.standalone-test' apply plugin: 'elasticsearch.rest-test' integTest { diff --git a/qa/smoke-test-plugins/build.gradle b/qa/smoke-test-plugins/build.gradle index ab69b02fc8c..a5cf0839639 100644 --- a/qa/smoke-test-plugins/build.gradle +++ b/qa/smoke-test-plugins/build.gradle @@ -19,6 +19,7 @@ import org.elasticsearch.gradle.MavenFilteringHack +apply plugin: 'elasticsearch.standalone-test' apply plugin: 'elasticsearch.rest-test' ext.pluginsCount = 0 @@ -40,4 +41,3 @@ processTestResources { inputs.properties(expansions) MavenFilteringHack.filter(it, expansions) } - diff --git a/qa/smoke-test-reindex-with-painless/build.gradle b/qa/smoke-test-reindex-with-painless/build.gradle index c857db85bfa..d9921d85d9a 100644 --- a/qa/smoke-test-reindex-with-painless/build.gradle +++ b/qa/smoke-test-reindex-with-painless/build.gradle @@ -17,6 +17,7 @@ * under the License. */ +apply plugin: 'elasticsearch.standalone-test' apply plugin: 'elasticsearch.rest-test' integTest { diff --git a/qa/smoke-test-tribe-node/build.gradle b/qa/smoke-test-tribe-node/build.gradle index 6e108e87043..36b0a6ecd1c 100644 --- a/qa/smoke-test-tribe-node/build.gradle +++ b/qa/smoke-test-tribe-node/build.gradle @@ -21,6 +21,7 @@ import org.elasticsearch.gradle.test.ClusterConfiguration import org.elasticsearch.gradle.test.ClusterFormationTasks import org.elasticsearch.gradle.test.NodeInfo +apply plugin: 'elasticsearch.standalone-test' apply plugin: 'elasticsearch.rest-test' List oneNodes From 232af512f4de3861e197d7059b2019263b7c0246 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 4 Jan 2017 14:26:55 -0500 Subject: [PATCH 04/22] Switch from standalone-test to standalone-rest-test standalone-rest-test doesn't configure unit tests and for these integ test only tests, that is what we want. --- .../elasticsearch/gradle/BuildPlugin.groovy | 6 ++++-- .../gradle/doc/DocsTestPlugin.groovy | 2 +- .../gradle/test/RestTestPlugin.groovy | 4 ++-- ...groovy => StandaloneRestTestPlugin.groovy} | 12 ++++++++--- .../gradle/test/StandaloneTestPlugin.groovy | 7 +++++-- ...sticsearch.standalone-rest-test.properties | 20 +++++++++++++++++++ distribution/build.gradle | 4 ++-- qa/backwards-5.0/build.gradle | 2 +- qa/evil-tests/build.gradle | 2 +- qa/no-bootstrap-tests/build.gradle | 1 - qa/smoke-test-client/build.gradle | 2 +- qa/smoke-test-http/build.gradle | 2 +- qa/smoke-test-ingest-disabled/build.gradle | 2 +- .../build.gradle | 2 +- qa/smoke-test-multinode/build.gradle | 2 +- qa/smoke-test-plugins/build.gradle | 2 +- .../build.gradle | 2 +- qa/smoke-test-tribe-node/build.gradle | 2 +- 18 files changed, 53 insertions(+), 23 deletions(-) rename buildSrc/src/main/groovy/org/elasticsearch/gradle/test/{StandaloneTestBasePlugin.groovy => StandaloneRestTestPlugin.groovy} (85%) create mode 100644 buildSrc/src/main/resources/META-INF/gradle-plugins/elasticsearch.standalone-rest-test.properties diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index 1cbbe0ac26d..01bab85b019 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -55,8 +55,10 @@ class BuildPlugin implements Plugin { @Override void apply(Project project) { - if (project.pluginManager.hasPlugin('elasticsearch.standalone-test')) { - throw new InvalidUserDataException('elasticsearch.standalone-test and elasticsearch.build are mutually exclusive') + if (project.pluginManager.hasPlugin('elasticsearch.standalone-rest-test')) { + throw new InvalidUserDataException('elasticsearch.standalone-test, ' + + 'elasticearch.standalone-rest-test, and elasticsearch.build ' + + 'are mutually exclusive') } project.pluginManager.apply('java') project.pluginManager.apply('carrotsearch.randomized-testing') diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/DocsTestPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/DocsTestPlugin.groovy index bb56360645f..66f9f0d4c4e 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/DocsTestPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/DocsTestPlugin.groovy @@ -30,7 +30,7 @@ public class DocsTestPlugin extends RestTestPlugin { @Override public void apply(Project project) { - project.pluginManager.apply('elasticsearch.standalone-test') + project.pluginManager.apply('elasticsearch.standalone-rest-test') super.apply(project) Map defaultSubstitutions = [ /* These match up with the asciidoc syntax for substitutions but diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestTestPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestTestPlugin.groovy index e4f4b35cc78..176b02cf9b0 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestTestPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestTestPlugin.groovy @@ -25,14 +25,14 @@ import org.gradle.api.Project /** * Adds support for starting an Elasticsearch cluster before running integration - * tests. Used in conjunction with {@link StandaloneTestBasePlugin} for qa + * tests. Used in conjunction with {@link StandaloneRestTestPlugin} for qa * projects and in conjunction with {@link BuildPlugin} for testing the rest * client. */ public class RestTestPlugin implements Plugin { List REQUIRED_PLUGINS = [ 'elasticsearch.build', - 'elasticsearch.standalone-test'] + 'elasticsearch.standalone-rest-test'] @Override public void apply(Project project) { diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestBasePlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy similarity index 85% rename from buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestBasePlugin.groovy rename to buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy index b9b865cb62d..6e017671017 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestBasePlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy @@ -30,13 +30,19 @@ import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.plugins.JavaBasePlugin -/** Configures the build to have a rest integration test. */ -public class StandaloneTestBasePlugin implements Plugin { +/** + * Configures the build to compile tests against Elasticsearch's test framework + * and run REST tests. Use BuildPlugin if you want to build main code as well + * as tests. + */ +public class StandaloneRestTestPlugin implements Plugin { @Override public void apply(Project project) { if (project.pluginManager.hasPlugin('elasticsearch.build')) { - throw new InvalidUserDataException('elasticsearch.standalone-test and elasticsearch.build are mutually exclusive') + throw new InvalidUserDataException('elasticsearch.standalone-test, ' + + 'elasticsearch.standalone-test, and elasticsearch.build are ' + + 'mutually exclusive') } project.pluginManager.apply(JavaBasePlugin) project.pluginManager.apply(RandomizedTestingPlugin) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestPlugin.groovy index fefd08fe4e5..de52d75c600 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestPlugin.groovy @@ -25,12 +25,15 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.plugins.JavaBasePlugin -/** A plugin to add tests only. Used for QA tests that run arbitrary unit tests. */ +/** + * Configures the build to compile against Elasticsearch's test framework and + * run integration and unit tests. Use BuildPlugin if you want to build main + * code as well as tests. */ public class StandaloneTestPlugin implements Plugin { @Override public void apply(Project project) { - project.pluginManager.apply(StandaloneTestBasePlugin) + project.pluginManager.apply(StandaloneRestTestPlugin) Map testOptions = [ name: 'test', diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/elasticsearch.standalone-rest-test.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/elasticsearch.standalone-rest-test.properties new file mode 100644 index 00000000000..2daf4dc27c0 --- /dev/null +++ b/buildSrc/src/main/resources/META-INF/gradle-plugins/elasticsearch.standalone-rest-test.properties @@ -0,0 +1,20 @@ +# +# Licensed to Elasticsearch under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch licenses this file to you 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. +# + +implementation-class=org.elasticsearch.gradle.test.StandaloneRestTestPlugin diff --git a/distribution/build.gradle b/distribution/build.gradle index 83f82d9cd6b..8fddd043229 100644 --- a/distribution/build.gradle +++ b/distribution/build.gradle @@ -1,5 +1,5 @@ /* - * Licensed to Elasticsearch under one or more contributor + // * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Elasticsearch licenses this file to you under @@ -104,7 +104,7 @@ subprojects { /***************************************************************************** * Rest test config * *****************************************************************************/ - apply plugin: 'elasticsearch.standalone-test' + apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.rest-test' project.integTest { dependsOn project.assemble diff --git a/qa/backwards-5.0/build.gradle b/qa/backwards-5.0/build.gradle index 6dd165121b7..c5e96757071 100644 --- a/qa/backwards-5.0/build.gradle +++ b/qa/backwards-5.0/build.gradle @@ -17,7 +17,7 @@ * under the License. */ -apply plugin: 'elasticsearch.standalone-test' +apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.rest-test' /* This project runs the core REST tests against a 2 node cluster where one of the nodes has a different minor. diff --git a/qa/evil-tests/build.gradle b/qa/evil-tests/build.gradle index cba9334fbca..472fc872616 100644 --- a/qa/evil-tests/build.gradle +++ b/qa/evil-tests/build.gradle @@ -42,7 +42,7 @@ thirdPartyAudit.excludes = [ 'com.google.common.cache.Striped64$Cell', 'com.google.common.primitives.UnsignedBytes$LexicographicalComparatorHolder$UnsafeComparator', 'com.google.common.primitives.UnsignedBytes$LexicographicalComparatorHolder$UnsafeComparator$1', - + // missing class 'com.ibm.icu.lang.UCharacter', ] diff --git a/qa/no-bootstrap-tests/build.gradle b/qa/no-bootstrap-tests/build.gradle index 16ac5e27693..25731a99dee 100644 --- a/qa/no-bootstrap-tests/build.gradle +++ b/qa/no-bootstrap-tests/build.gradle @@ -23,4 +23,3 @@ */ apply plugin: 'elasticsearch.standalone-test' - diff --git a/qa/smoke-test-client/build.gradle b/qa/smoke-test-client/build.gradle index fca4177d3bb..888d9325242 100644 --- a/qa/smoke-test-client/build.gradle +++ b/qa/smoke-test-client/build.gradle @@ -17,7 +17,7 @@ * under the License. */ -apply plugin: 'elasticsearch.standalone-test' +apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.rest-test' // TODO: this test works, but it isn't really a rest test...should we have another plugin for "non rest test that just needs N clusters?" diff --git a/qa/smoke-test-http/build.gradle b/qa/smoke-test-http/build.gradle index 2fb61243fe8..f394075e0f0 100644 --- a/qa/smoke-test-http/build.gradle +++ b/qa/smoke-test-http/build.gradle @@ -17,7 +17,7 @@ * under the License. */ -apply plugin: 'elasticsearch.standalone-test' +apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.rest-test' dependencies { diff --git a/qa/smoke-test-ingest-disabled/build.gradle b/qa/smoke-test-ingest-disabled/build.gradle index 1d7491a3517..4c4d9c2da12 100644 --- a/qa/smoke-test-ingest-disabled/build.gradle +++ b/qa/smoke-test-ingest-disabled/build.gradle @@ -17,7 +17,7 @@ * under the License. */ -apply plugin: 'elasticsearch.standalone-test' +apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.rest-test' dependencies { diff --git a/qa/smoke-test-ingest-with-all-dependencies/build.gradle b/qa/smoke-test-ingest-with-all-dependencies/build.gradle index e4ac1f29f89..2cfa3af434e 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/build.gradle +++ b/qa/smoke-test-ingest-with-all-dependencies/build.gradle @@ -17,7 +17,7 @@ * under the License. */ -apply plugin: 'elasticsearch.standalone-test' +apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.rest-test' dependencies { diff --git a/qa/smoke-test-multinode/build.gradle b/qa/smoke-test-multinode/build.gradle index 52bf2427463..fc196fd52a4 100644 --- a/qa/smoke-test-multinode/build.gradle +++ b/qa/smoke-test-multinode/build.gradle @@ -17,7 +17,7 @@ * under the License. */ -apply plugin: 'elasticsearch.standalone-test' +apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.rest-test' integTest { diff --git a/qa/smoke-test-plugins/build.gradle b/qa/smoke-test-plugins/build.gradle index a5cf0839639..6fd722e409c 100644 --- a/qa/smoke-test-plugins/build.gradle +++ b/qa/smoke-test-plugins/build.gradle @@ -19,7 +19,7 @@ import org.elasticsearch.gradle.MavenFilteringHack -apply plugin: 'elasticsearch.standalone-test' +apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.rest-test' ext.pluginsCount = 0 diff --git a/qa/smoke-test-reindex-with-painless/build.gradle b/qa/smoke-test-reindex-with-painless/build.gradle index d9921d85d9a..7092c0a7b48 100644 --- a/qa/smoke-test-reindex-with-painless/build.gradle +++ b/qa/smoke-test-reindex-with-painless/build.gradle @@ -17,7 +17,7 @@ * under the License. */ -apply plugin: 'elasticsearch.standalone-test' +apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.rest-test' integTest { diff --git a/qa/smoke-test-tribe-node/build.gradle b/qa/smoke-test-tribe-node/build.gradle index 36b0a6ecd1c..94789b17fdb 100644 --- a/qa/smoke-test-tribe-node/build.gradle +++ b/qa/smoke-test-tribe-node/build.gradle @@ -21,7 +21,7 @@ import org.elasticsearch.gradle.test.ClusterConfiguration import org.elasticsearch.gradle.test.ClusterFormationTasks import org.elasticsearch.gradle.test.NodeInfo -apply plugin: 'elasticsearch.standalone-test' +apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.rest-test' List oneNodes From 0a6827a5cc22c892b11ceb78ab456510736a37d1 Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 5 Jan 2017 11:29:41 +0100 Subject: [PATCH 05/22] Make RestHighLevelClient non final --- .../main/java/org/elasticsearch/client/RestHighLevelClient.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java index 4bde0d37e61..58ecc5f9c2d 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java @@ -48,4 +48,6 @@ public final class RestHighLevelClient { return false; } } + + } From 97f3a9bd79a6b919b79185b8f2b5903758192e83 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 5 Jan 2017 11:31:18 +0100 Subject: [PATCH 06/22] Relax LiveVersionMapTests.testRamBytesUsed. With Java9's new restrictions we cannot compute ram usage as accurately as before. See https://issues.apache.org/jira/browse/LUCENE-7595. --- .../org/elasticsearch/index/engine/LiveVersionMapTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/index/engine/LiveVersionMapTests.java b/core/src/test/java/org/elasticsearch/index/engine/LiveVersionMapTests.java index ed80b98c7f9..a84f78ca3d9 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/LiveVersionMapTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/LiveVersionMapTests.java @@ -36,8 +36,8 @@ public class LiveVersionMapTests extends ESTestCase { } long actualRamBytesUsed = RamUsageTester.sizeOf(map); long estimatedRamBytesUsed = map.ramBytesUsed(); - // less than 25% off - assertEquals(actualRamBytesUsed, estimatedRamBytesUsed, actualRamBytesUsed / 4); + // less than 50% off + assertEquals(actualRamBytesUsed, estimatedRamBytesUsed, actualRamBytesUsed / 2); // now refresh map.beforeRefresh(); From ccc4e414ff2ff8f0e1a45c2144fafa6733fddc72 Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 5 Jan 2017 17:15:34 +0100 Subject: [PATCH 07/22] remove double slash from license header --- distribution/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distribution/build.gradle b/distribution/build.gradle index 8fddd043229..7c01acc1c91 100644 --- a/distribution/build.gradle +++ b/distribution/build.gradle @@ -1,5 +1,5 @@ /* - // * Licensed to Elasticsearch under one or more contributor + * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Elasticsearch licenses this file to you under From cfc106d7213fbdfa78d2c74387586ce2c02d3842 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Thu, 5 Jan 2017 18:11:58 +0100 Subject: [PATCH 08/22] Don't close store under CancellableThreads (#22434) #22325 changed the recovery retry logic to use unique recovery ids. The change also introduced an issue, however, which made it possible for the shard store to be closed under CancellableThreads, triggering assertions in the node locking logic. This commit limits the use of CancellableThreads only to the part where we wait on the old recovery target to be closed. --- .../recovery/RecoveriesCollection.java | 24 +++++++------------ .../indices/recovery/RecoveryTarget.java | 15 ++++++++---- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveriesCollection.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveriesCollection.java index 3bee3febf3f..aed23256108 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveriesCollection.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveriesCollection.java @@ -107,25 +107,17 @@ public class RecoveriesCollection { } // Closes the current recovery target - final AtomicBoolean successfulReset = new AtomicBoolean(); - try { - final RecoveryTarget finalOldRecoveryTarget = oldRecoveryTarget; - newRecoveryTarget.CancellableThreads().executeIO(() -> successfulReset.set(finalOldRecoveryTarget.resetRecovery())); - } catch (CancellableThreads.ExecutionCancelledException e) { - // new recovery target is already cancelled (probably due to shard closing or recovery source changing) - assert onGoingRecoveries.containsKey(newRecoveryTarget.recoveryId()) == false; - logger.trace("{} recovery reset cancelled, recovery from {}, id [{}], previous id [{}]", newRecoveryTarget.shardId(), - newRecoveryTarget.sourceNode(), newRecoveryTarget.recoveryId(), oldRecoveryTarget.recoveryId()); - oldRecoveryTarget.cancel("recovery reset cancelled"); // if finalOldRecoveryTarget.resetRecovery did not even get to execute - return null; - } - if (successfulReset.get() == false) { - cancelRecovery(newRecoveryTarget.recoveryId(), "failed to reset recovery"); - return null; - } else { + boolean successfulReset = oldRecoveryTarget.resetRecovery(newRecoveryTarget.CancellableThreads()); + if (successfulReset) { logger.trace("{} restarted recovery from {}, id [{}], previous id [{}]", newRecoveryTarget.shardId(), newRecoveryTarget.sourceNode(), newRecoveryTarget.recoveryId(), oldRecoveryTarget.recoveryId()); return newRecoveryTarget; + } else { + logger.trace("{} recovery could not be reset as it is already cancelled, recovery from {}, id [{}], previous id [{}]", + newRecoveryTarget.shardId(), newRecoveryTarget.sourceNode(), newRecoveryTarget.recoveryId(), + oldRecoveryTarget.recoveryId()); + cancelRecovery(newRecoveryTarget.recoveryId(), "recovery cancelled during reset"); + return null; } } catch (Exception e) { // fail shard to be safe diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java index 4311d3b2ab1..00dd019aac4 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java @@ -36,6 +36,7 @@ import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.lucene.Lucene; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.Callback; import org.elasticsearch.common.util.CancellableThreads; import org.elasticsearch.common.util.concurrent.AbstractRefCounted; @@ -56,6 +57,8 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; @@ -182,17 +185,21 @@ public class RecoveryTarget extends AbstractRefCounted implements RecoveryTarget * Closes the current recovery target and waits up to a certain timeout for resources to be freed. * Returns true if resetting the recovery was successful, false if the recovery target is already cancelled / failed or marked as done. */ - boolean resetRecovery() throws InterruptedException, IOException { + boolean resetRecovery(CancellableThreads newTargetCancellableThreads) throws IOException { if (finished.compareAndSet(false, true)) { try { - // yes, this is just a logger call in a try-finally block. The reason for this is that resetRecovery is called from - // CancellableThreads and we have to make sure that all references to IndexShard are cleaned up before exiting this method logger.debug("reset of recovery with shard {} and id [{}]", shardId, recoveryId); } finally { // release the initial reference. recovery files will be cleaned as soon as ref count goes to zero, potentially now. decRef(); } - closedLatch.await(); + try { + newTargetCancellableThreads.execute(closedLatch::await); + } catch (CancellableThreads.ExecutionCancelledException e) { + logger.trace("new recovery target cancelled for shard {} while waiting on old recovery target with id [{}] to close", + shardId, recoveryId); + return false; + } RecoveryState.Stage stage = indexShard.recoveryState().getStage(); if (indexShard.recoveryState().getPrimary() && (stage == RecoveryState.Stage.FINALIZE || stage == RecoveryState.Stage.DONE)) { // once primary relocation has moved past the finalization step, the relocation source can be moved to RELOCATED state From 182e8115ded245a15cedfdedc9c3966c62f92741 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Thu, 5 Jan 2017 19:12:21 +0100 Subject: [PATCH 09/22] [TEST] Fix IndexRecoveryIT.testDisconnectsDuringRecovery The test currently checks that the recovering shard is not failed when it is not a primary relocation that has moved past the finalization step. Checking if it has moved past that step is done by intercepting the request between the replication source and the target and checking if it has seen then WAIT_FOR_CLUSTERSTATE action as this is the next action that is called after finalization. This action can, however, occur only after the shard was already failed, and thus trip the assertion. This commit changes the check to look out for the FINALIZE action, independently of whether it succeeded or not. --- .../elasticsearch/indices/recovery/IndexRecoveryIT.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java b/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java index 6bbccb4cfb7..424edb42e68 100644 --- a/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java +++ b/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java @@ -724,14 +724,14 @@ public class IndexRecoveryIT extends ESIntegTestCase { } }); - final AtomicBoolean seenWaitForClusterState = new AtomicBoolean(); + final AtomicBoolean finalized = new AtomicBoolean(); blueMockTransportService.addDelegate(redMockTransportService, new MockTransportService.DelegateTransport(blueMockTransportService.original()) { @Override protected void sendRequest(Connection connection, long requestId, String action, TransportRequest request, TransportRequestOptions options) throws IOException { logger.info("--> sending request {} on {}", action, connection.getNode()); - if (action.equals(PeerRecoveryTargetService.Actions.WAIT_CLUSTERSTATE)) { - seenWaitForClusterState.set(true); + if (action.equals(PeerRecoveryTargetService.Actions.FINALIZE)) { + finalized.set(true); } super.sendRequest(connection, requestId, action, request, options); } @@ -743,7 +743,7 @@ public class IndexRecoveryIT extends ESIntegTestCase { protected void sendRequest(Connection connection, long requestId, String action, TransportRequest request, TransportRequestOptions options) throws IOException { logger.info("--> sending request {} on {}", action, connection.getNode()); - if (primaryRelocation == false || seenWaitForClusterState.get() == false) { + if ((primaryRelocation && finalized.get()) == false) { assertNotEquals(action, ShardStateAction.SHARD_FAILED_ACTION_NAME); } super.sendRequest(connection, requestId, action, request, options); From 93947923925db3db0a09edea0cf34bf8934a6c59 Mon Sep 17 00:00:00 2001 From: javanna Date: Tue, 3 Jan 2017 22:48:59 +0100 Subject: [PATCH 10/22] remove unused ParseFieldMatcher imports/arguments --- .../action/search/SearchRequest.java | 1 - .../BlobStoreIndexShardSnapshot.java | 3 --- .../BlobStoreIndexShardSnapshots.java | 2 -- .../bucket/range/RangeAggregationBuilder.java | 2 +- .../bucket/range/RangeAggregator.java | 3 +-- .../date/DateRangeAggregationBuilder.java | 2 +- .../GeoDistanceAggregationBuilder.java | 4 +--- .../range/ip/IpRangeAggregationBuilder.java | 4 +--- .../bucket/terms/support/IncludeExclude.java | 3 --- .../MovAvgPipelineAggregationBuilder.java | 2 +- .../pipeline/movavg/models/EwmaModel.java | 4 +--- .../movavg/models/HoltLinearModel.java | 4 +--- .../movavg/models/HoltWintersModel.java | 9 +++------ .../pipeline/movavg/models/LinearModel.java | 4 +--- .../pipeline/movavg/models/MovAvgModel.java | 4 +--- .../pipeline/movavg/models/SimpleModel.java | 4 +--- .../internal/FilteredSearchContext.java | 1 - .../search/sort/GeoDistanceSortBuilder.java | 2 -- .../search/suggest/SuggestBuilder.java | 2 -- .../search/suggest/SuggestionBuilder.java | 2 -- .../search/suggest/phrase/SmoothingModel.java | 2 -- .../suggest/term/TermSuggestionBuilder.java | 2 -- .../elasticsearch/snapshots/SnapshotInfo.java | 1 - .../pipeline/moving/avg/MovAvgUnitTests.java | 5 ++--- .../suggest/CustomSuggesterSearchIT.java | 2 -- .../matrix/stats/MatrixStatsParser.java | 3 +-- .../support/MultiValuesSourceParser.java | 20 +++++++------------ .../TransportMultiPercolateAction.java | 3 --- .../percolator/TransportPercolateAction.java | 2 -- 29 files changed, 24 insertions(+), 78 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java b/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java index 3e65bda8ddf..9c69f1a763f 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java @@ -24,7 +24,6 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshot.java b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshot.java index e5f04f02032..37b728d43d6 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshot.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshot.java @@ -23,7 +23,6 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.Version; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.Strings; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.unit.ByteSizeValue; @@ -475,7 +474,6 @@ public class BlobStoreIndexShardSnapshot implements ToXContent { private static final ParseField PARSE_NUMBER_OF_FILES = new ParseField("number_of_files"); private static final ParseField PARSE_TOTAL_SIZE = new ParseField("total_size"); private static final ParseField PARSE_FILES = new ParseField("files"); - private static final ParseFieldMatcher parseFieldMatcher = ParseFieldMatcher.EMPTY; /** * Serializes shard snapshot metadata info into JSON @@ -559,5 +557,4 @@ public class BlobStoreIndexShardSnapshot implements ToXContent { return new BlobStoreIndexShardSnapshot(snapshot, indexVersion, Collections.unmodifiableList(indexFiles), startTime, time, numberOfFiles, totalSize); } - } diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java index 186186ff79b..359c3165f53 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java @@ -21,7 +21,6 @@ package org.elasticsearch.index.snapshots.blobstore; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -153,7 +152,6 @@ public class BlobStoreIndexShardSnapshots implements Iterable, To static final ParseField FILES = new ParseField("files"); static final ParseField SNAPSHOTS = new ParseField("snapshots"); } - private static final ParseFieldMatcher parseFieldMatcher = ParseFieldMatcher.EMPTY; /** * Writes index file for the shard in the following format. diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregationBuilder.java index 8f4f9d6ccd8..e7f0a8a6d80 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregationBuilder.java @@ -57,7 +57,7 @@ public class RangeAggregationBuilder extends AbstractRangeBuilder(parseArrayToSet(parser)), null); } else if (token == XContentParser.Token.START_OBJECT) { - ParseFieldMatcher parseFieldMatcher = context.getParseFieldMatcher(); String currentFieldName = null; Integer partition = null, numPartitions = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregationBuilder.java index 30db30fcafd..bc973ad442f 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregationBuilder.java @@ -406,7 +406,7 @@ public class MovAvgPipelineAggregationBuilder extends AbstractPipelineAggregatio MovAvgModel.AbstractModelParser modelParser = movingAverageMdelParserRegistry.lookup(model, parser.getTokenLocation()); MovAvgModel movAvgModel; try { - movAvgModel = modelParser.parse(settings, pipelineAggregatorName, factory.window(), context.getParseFieldMatcher()); + movAvgModel = modelParser.parse(settings, pipelineAggregatorName, factory.window()); } catch (ParseException exception) { throw new ParsingException(parser.getTokenLocation(), "Could not parse settings for model [" + model + "].", exception); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/EwmaModel.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/EwmaModel.java index c7e6b0e8980..26fb0333b18 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/EwmaModel.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/EwmaModel.java @@ -20,7 +20,6 @@ package org.elasticsearch.search.aggregations.pipeline.movavg.models; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -127,8 +126,7 @@ public class EwmaModel extends MovAvgModel { public static final AbstractModelParser PARSER = new AbstractModelParser() { @Override - public MovAvgModel parse(@Nullable Map settings, String pipelineName, int windowSize, - ParseFieldMatcher parseFieldMatcher) throws ParseException { + public MovAvgModel parse(@Nullable Map settings, String pipelineName, int windowSize) throws ParseException { double alpha = parseDoubleParam(settings, "alpha", DEFAULT_ALPHA); checkUnrecognizedParams(settings); return new EwmaModel(alpha); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltLinearModel.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltLinearModel.java index d8a591972ec..18193337385 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltLinearModel.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltLinearModel.java @@ -20,7 +20,6 @@ package org.elasticsearch.search.aggregations.pipeline.movavg.models; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -191,8 +190,7 @@ public class HoltLinearModel extends MovAvgModel { public static final AbstractModelParser PARSER = new AbstractModelParser() { @Override - public MovAvgModel parse(@Nullable Map settings, String pipelineName, int windowSize, - ParseFieldMatcher parseFieldMatcher) throws ParseException { + public MovAvgModel parse(@Nullable Map settings, String pipelineName, int windowSize) throws ParseException { double alpha = parseDoubleParam(settings, "alpha", DEFAULT_ALPHA); double beta = parseDoubleParam(settings, "beta", DEFAULT_BETA); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltWintersModel.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltWintersModel.java index 3fe2e81ff9c..92b2e4d3ea2 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltWintersModel.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltWintersModel.java @@ -23,7 +23,6 @@ package org.elasticsearch.search.aggregations.pipeline.movavg.models; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -59,11 +58,10 @@ public class HoltWintersModel extends MovAvgModel { * Parse a string SeasonalityType into the byte enum * * @param text SeasonalityType in string format (e.g. "add") - * @param parseFieldMatcher Matcher for field names * @return SeasonalityType enum */ @Nullable - public static SeasonalityType parse(String text, ParseFieldMatcher parseFieldMatcher) { + public static SeasonalityType parse(String text) { if (text == null) { return null; } @@ -379,8 +377,7 @@ public class HoltWintersModel extends MovAvgModel { public static final AbstractModelParser PARSER = new AbstractModelParser() { @Override - public MovAvgModel parse(@Nullable Map settings, String pipelineName, int windowSize, - ParseFieldMatcher parseFieldMatcher) throws ParseException { + public MovAvgModel parse(@Nullable Map settings, String pipelineName, int windowSize) throws ParseException { double alpha = parseDoubleParam(settings, "alpha", DEFAULT_ALPHA); double beta = parseDoubleParam(settings, "beta", DEFAULT_BETA); @@ -399,7 +396,7 @@ public class HoltWintersModel extends MovAvgModel { Object value = settings.get("type"); if (value != null) { if (value instanceof String) { - seasonalityType = SeasonalityType.parse((String)value, parseFieldMatcher); + seasonalityType = SeasonalityType.parse((String)value); settings.remove("type"); } else { throw new ParseException("Parameter [type] must be a String, type `" diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/LinearModel.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/LinearModel.java index 089f3a430ca..3eed0bf603b 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/LinearModel.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/LinearModel.java @@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.pipeline.movavg.models; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -106,8 +105,7 @@ public class LinearModel extends MovAvgModel { public static final AbstractModelParser PARSER = new AbstractModelParser() { @Override - public MovAvgModel parse(@Nullable Map settings, String pipelineName, int windowSize, - ParseFieldMatcher parseFieldMatcher) throws ParseException { + public MovAvgModel parse(@Nullable Map settings, String pipelineName, int windowSize) throws ParseException { checkUnrecognizedParams(settings); return new LinearModel(); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/MovAvgModel.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/MovAvgModel.java index 0837eca38bd..f64117236d6 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/MovAvgModel.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/MovAvgModel.java @@ -20,7 +20,6 @@ package org.elasticsearch.search.aggregations.pipeline.movavg.models; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContent; @@ -143,11 +142,10 @@ public abstract class MovAvgModel implements NamedWriteable, ToXContent { * @param settings Map of settings, extracted from the request * @param pipelineName Name of the parent pipeline agg * @param windowSize Size of the window for this moving avg - * @param parseFieldMatcher Matcher for field names * @return A fully built moving average model */ public abstract MovAvgModel parse(@Nullable Map settings, String pipelineName, - int windowSize, ParseFieldMatcher parseFieldMatcher) throws ParseException; + int windowSize) throws ParseException; /** diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/SimpleModel.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/SimpleModel.java index 14544881883..e30a59d2887 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/SimpleModel.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/SimpleModel.java @@ -20,7 +20,6 @@ package org.elasticsearch.search.aggregations.pipeline.movavg.models; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -99,8 +98,7 @@ public class SimpleModel extends MovAvgModel { public static final AbstractModelParser PARSER = new AbstractModelParser() { @Override - public MovAvgModel parse(@Nullable Map settings, String pipelineName, int windowSize, - ParseFieldMatcher parseFieldMatcher) throws ParseException { + public MovAvgModel parse(@Nullable Map settings, String pipelineName, int windowSize) throws ParseException { checkUnrecognizedParams(settings); return new SimpleModel(); } diff --git a/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java b/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java index 2cf52fb11f5..fb1e2132dee 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java @@ -25,7 +25,6 @@ import org.apache.lucene.search.Query; import org.apache.lucene.util.Counter; import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.index.cache.bitset.BitsetFilterCache; diff --git a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java index 7111cee5766..720637229c9 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java @@ -29,7 +29,6 @@ import org.apache.lucene.util.BitSet; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.Version; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.common.geo.GeoDistance.FixedSourceDistance; @@ -398,7 +397,6 @@ public class GeoDistanceSortBuilder extends SortBuilder */ public static GeoDistanceSortBuilder fromXContent(QueryParseContext context, String elementName) throws IOException { XContentParser parser = context.parser(); - ParseFieldMatcher parseFieldMatcher = context.getParseFieldMatcher(); String fieldName = null; List geoPoints = new ArrayList<>(); DistanceUnit unit = DistanceUnit.DEFAULT; diff --git a/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilder.java index 84c3da8618e..1de59eb3e26 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilder.java @@ -21,7 +21,6 @@ package org.elasticsearch.search.suggest; import org.elasticsearch.action.support.ToXContentToBytes; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -140,7 +139,6 @@ public class SuggestBuilder extends ToXContentToBytes implements Writeable { public static SuggestBuilder fromXContent(QueryParseContext parseContext, Suggesters suggesters) throws IOException { XContentParser parser = parseContext.parser(); - ParseFieldMatcher parseFieldMatcher = parseContext.getParseFieldMatcher(); SuggestBuilder suggestBuilder = new SuggestBuilder(); String fieldName = null; diff --git a/core/src/main/java/org/elasticsearch/search/suggest/SuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/SuggestionBuilder.java index 4f6c4d8c553..2062b696cfa 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/SuggestionBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/SuggestionBuilder.java @@ -22,7 +22,6 @@ package org.elasticsearch.search.suggest; import org.apache.lucene.analysis.Analyzer; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.io.stream.StreamInput; @@ -257,7 +256,6 @@ public abstract class SuggestionBuilder> implemen static SuggestionBuilder fromXContent(QueryParseContext parseContext, Suggesters suggesters) throws IOException { XContentParser parser = parseContext.parser(); - ParseFieldMatcher parsefieldMatcher = parseContext.getParseFieldMatcher(); XContentParser.Token token; String currentFieldName = null; String suggestText = null; diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/SmoothingModel.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/SmoothingModel.java index 26e0b80064b..82f106130ef 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/SmoothingModel.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/SmoothingModel.java @@ -19,7 +19,6 @@ package org.elasticsearch.search.suggest.phrase; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.xcontent.ToXContent; @@ -67,7 +66,6 @@ public abstract class SmoothingModel implements NamedWriteable, ToXContent { public static SmoothingModel fromXContent(QueryParseContext parseContext) throws IOException { XContentParser parser = parseContext.parser(); - ParseFieldMatcher parseFieldMatcher = parseContext.getParseFieldMatcher(); XContentParser.Token token; String fieldName = null; SmoothingModel model = null; diff --git a/core/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilder.java index f7be69e4804..9a7238dbe16 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilder.java @@ -26,7 +26,6 @@ import org.apache.lucene.search.spell.LuceneLevenshteinDistance; import org.apache.lucene.search.spell.NGramDistance; import org.apache.lucene.search.spell.StringDistance; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -391,7 +390,6 @@ public class TermSuggestionBuilder extends SuggestionBuilder otherOptions) throws IOException { + Map otherOptions) throws IOException { if (MULTIVALUE_MODE_FIELD.match(currentFieldName)) { if (token == XContentParser.Token.VALUE_STRING) { otherOptions.put(MULTIVALUE_MODE_FIELD, parser.text()); diff --git a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSourceParser.java b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSourceParser.java index 8d87d1fcd1c..c2e4b4f0c3f 100644 --- a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSourceParser.java +++ b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSourceParser.java @@ -20,13 +20,12 @@ package org.elasticsearch.search.aggregations.support; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.script.Script; -import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregationBuilder.CommonFields; +import org.elasticsearch.search.aggregations.Aggregator; import java.io.IOException; import java.util.ArrayList; @@ -85,8 +84,6 @@ public abstract class MultiValuesSourceParser implement String format = null; Map missingMap = null; Map otherOptions = new HashMap<>(); - final ParseFieldMatcher parseFieldMatcher = context.getParseFieldMatcher(); - XContentParser.Token token; String currentFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -101,7 +98,7 @@ public abstract class MultiValuesSourceParser implement throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]. " + "Multi-field aggregations do not support scripts."); - } else if (!token(aggregationName, currentFieldName, token, parser, context.getParseFieldMatcher(), otherOptions)) { + } else if (!token(aggregationName, currentFieldName, token, parser, otherOptions)) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } @@ -116,7 +113,7 @@ public abstract class MultiValuesSourceParser implement "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]. " + "Multi-field aggregations do not support scripts."); - } else if (!token(aggregationName, currentFieldName, token, parser, context.getParseFieldMatcher(), otherOptions)) { + } else if (!token(aggregationName, currentFieldName, token, parser, otherOptions)) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } @@ -135,11 +132,11 @@ public abstract class MultiValuesSourceParser implement "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } } - } else if (!token(aggregationName, currentFieldName, token, parser, context.getParseFieldMatcher(), otherOptions)) { + } else if (!token(aggregationName, currentFieldName, token, parser, otherOptions)) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } - } else if (!token(aggregationName, currentFieldName, token, parser, context.getParseFieldMatcher(), otherOptions)) { + } else if (!token(aggregationName, currentFieldName, token, parser, otherOptions)) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } @@ -198,8 +195,7 @@ public abstract class MultiValuesSourceParser implement * the target type of the final value output by the aggregation * @param otherOptions * a {@link Map} containing the extra options parsed by the - * {@link #token(String, String, org.elasticsearch.common.xcontent.XContentParser.Token, - * XContentParser, ParseFieldMatcher, Map)} + * {@link #token(String, String, XContentParser.Token, XContentParser, Map)} * method * @return the created factory */ @@ -219,8 +215,6 @@ public abstract class MultiValuesSourceParser implement * the current token for the parser * @param parser * the parser - * @param parseFieldMatcher - * the {@link ParseFieldMatcher} to use to match field names * @param otherOptions * a {@link Map} of options to be populated by successive calls * to this method which will then be passed to the @@ -232,5 +226,5 @@ public abstract class MultiValuesSourceParser implement * if an error occurs whilst parsing */ protected abstract boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser, - ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException; + Map otherOptions) throws IOException; } diff --git a/modules/percolator/src/main/java/org/elasticsearch/percolator/TransportMultiPercolateAction.java b/modules/percolator/src/main/java/org/elasticsearch/percolator/TransportMultiPercolateAction.java index 119b8e35bc9..668df18678f 100644 --- a/modules/percolator/src/main/java/org/elasticsearch/percolator/TransportMultiPercolateAction.java +++ b/modules/percolator/src/main/java/org/elasticsearch/percolator/TransportMultiPercolateAction.java @@ -32,7 +32,6 @@ import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.HandledTransportAction; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.inject.Inject; @@ -53,7 +52,6 @@ import java.util.Map; public class TransportMultiPercolateAction extends HandledTransportAction { private final Client client; - private final ParseFieldMatcher parseFieldMatcher; private final SearchRequestParsers searchRequestParsers; private final NamedXContentRegistry xContentRegistry; @@ -66,7 +64,6 @@ public class TransportMultiPercolateAction extends HandledTransportAction { private final Client client; - private final ParseFieldMatcher parseFieldMatcher; private final SearchRequestParsers searchRequestParsers; private final NamedXContentRegistry xContentRegistry; @@ -76,7 +75,6 @@ public class TransportPercolateAction extends HandledTransportAction Date: Tue, 3 Jan 2017 23:26:05 +0100 Subject: [PATCH 11/22] ObjectParser to no longer require ParseFieldMatcherSupplier as its Context ParseFieldMatcher as well as ParseFieldMatcherSupplier will be soon removed, hence the ObjectParser's context doesn't need to be a ParseFieldMatcherSupplier anymore. That will allow to remove ParseFieldMatcherSupplier's implementations, little by little. --- .../common/xcontent/AbstractObjectParser.java | 3 +-- .../common/xcontent/ConstructingObjectParser.java | 5 ++--- .../org/elasticsearch/common/xcontent/ObjectParser.java | 7 +++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/AbstractObjectParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/AbstractObjectParser.java index 64a5fa4c119..112ba0debda 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/AbstractObjectParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/AbstractObjectParser.java @@ -20,7 +20,6 @@ package org.elasticsearch.common.xcontent; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.ObjectParser.ValueType; import org.elasticsearch.common.xcontent.json.JsonXContent; @@ -34,7 +33,7 @@ import java.util.function.BiFunction; /** * Superclass for {@link ObjectParser} and {@link ConstructingObjectParser}. Defines most of the "declare" methods so they can be shared. */ -public abstract class AbstractObjectParser +public abstract class AbstractObjectParser implements BiFunction, ContextParser { /** diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/ConstructingObjectParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/ConstructingObjectParser.java index 6e646094d06..fe606c130d1 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/ConstructingObjectParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/ConstructingObjectParser.java @@ -20,7 +20,6 @@ package org.elasticsearch.common.xcontent; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.xcontent.ObjectParser.ValueType; @@ -74,7 +73,7 @@ import java.util.function.Function; * Note: if optional constructor arguments aren't specified then the number of allocations is always the worst case. *

*/ -public final class ConstructingObjectParser extends AbstractObjectParser { +public final class ConstructingObjectParser extends AbstractObjectParser { /** * Consumer that marks a field as a required constructor argument instead of a real object field. */ @@ -236,7 +235,7 @@ public final class ConstructingObjectParser extends AbstractObjectParser { +public final class ObjectParser extends AbstractObjectParser { /** * Adapts an array (or varags) setter into a list setter. */ @@ -167,7 +166,7 @@ public final class ObjectParser Date: Tue, 3 Jan 2017 23:45:29 +0100 Subject: [PATCH 12/22] fix unchecked generics warnings in ObjectParser --- .../common/xcontent/ObjectParser.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java index 3e63bc71e00..e84890db7c8 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java @@ -152,7 +152,7 @@ public final class ObjectParser extends AbstractObjectParser fieldParser = null; + FieldParser fieldParser = null; String currentFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { @@ -356,13 +356,13 @@ public final class ObjectParser extends AbstractObjectParser fieldParser, String currentFieldName, Value value, Context context) + private void parseArray(XContentParser parser, FieldParser fieldParser, String currentFieldName, Value value, Context context) throws IOException { assert parser.currentToken() == XContentParser.Token.START_ARRAY : "Token was: " + parser.currentToken(); parseValue(parser, fieldParser, currentFieldName, value, context); } - private void parseValue(XContentParser parser, FieldParser fieldParser, String currentFieldName, Value value, Context context) + private void parseValue(XContentParser parser, FieldParser fieldParser, String currentFieldName, Value value, Context context) throws IOException { try { fieldParser.parser.parse(parser, value, context); @@ -371,7 +371,7 @@ public final class ObjectParser extends AbstractObjectParser fieldParser, String currentFieldName, Value value, Context context) + private void parseSub(XContentParser parser, FieldParser fieldParser, String currentFieldName, Value value, Context context) throws IOException { final XContentParser.Token token = parser.currentToken(); switch (token) { @@ -395,27 +395,27 @@ public final class ObjectParser extends AbstractObjectParser parser = fieldParserMap.get(fieldName); + FieldParser parser = fieldParserMap.get(fieldName); if (parser == null && false == ignoreUnknownFields) { throw new IllegalArgumentException("[" + name + "] unknown field [" + fieldName + "], parser not found"); } return parser; } - public static class FieldParser { - private final Parser parser; + private class FieldParser { + private final Parser parser; private final EnumSet supportedTokens; private final ParseField parseField; private final ValueType type; - public FieldParser(Parser parser, EnumSet supportedTokens, ParseField parseField, ValueType type) { + FieldParser(Parser parser, EnumSet supportedTokens, ParseField parseField, ValueType type) { this.parser = parser; this.supportedTokens = supportedTokens; this.parseField = parseField; this.type = type; } - public void assertSupports(String parserName, XContentParser.Token token, String currentFieldName) { + void assertSupports(String parserName, XContentParser.Token token, String currentFieldName) { if (parseField.match(currentFieldName) == false) { throw new IllegalStateException("[" + parserName + "] parsefield doesn't accept: " + currentFieldName); } From 6102523033740a33faf10dc79a3f755b0de81f6f Mon Sep 17 00:00:00 2001 From: javanna Date: Wed, 4 Jan 2017 15:23:24 +0100 Subject: [PATCH 13/22] remove ParseFieldMatcher usages from Script parsing code --- .../action/update/UpdateRequest.java | 3 +-- .../index/query/ScriptQueryBuilder.java | 4 ++-- .../ScriptScoreFunctionBuilder.java | 2 +- .../java/org/elasticsearch/script/Script.java | 24 +++++-------------- .../heuristics/ScriptHeuristic.java | 2 +- .../ScriptedMetricAggregationBuilder.java | 9 ++++--- .../tophits/TopHitsAggregationBuilder.java | 4 ++-- ...ucketScriptPipelineAggregationBuilder.java | 4 ++-- ...ketSelectorPipelineAggregationBuilder.java | 4 ++-- .../support/ValuesSourceParserHelper.java | 13 +++++----- .../search/builder/SearchSourceBuilder.java | 4 ++-- .../search/sort/ScriptSortBuilder.java | 3 ++- .../phrase/PhraseSuggestionBuilder.java | 2 +- .../org/elasticsearch/script/ScriptTests.java | 3 +-- .../script/mustache/TemplateQueryBuilder.java | 2 +- .../mustache/MustacheScriptEngineTests.java | 6 ++--- .../index/reindex/RestReindexAction.java | 4 ++-- 17 files changed, 39 insertions(+), 54 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java index a812cb22eb6..d31d0c9ae14 100644 --- a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java +++ b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java @@ -27,7 +27,6 @@ import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.action.support.replication.ReplicationRequest; import org.elasticsearch.action.support.single.instance.InstanceShardOperationRequest; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.logging.DeprecationLogger; @@ -714,7 +713,7 @@ public class UpdateRequest extends InstanceShardOperationRequest if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if ("script".equals(currentFieldName)) { - script = Script.parse(parser, ParseFieldMatcher.EMPTY); + script = Script.parse(parser); } else if ("scripted_upsert".equals(currentFieldName)) { scriptedUpsert = parser.booleanValue(); } else if ("upsert".equals(currentFieldName)) { diff --git a/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java index 077a687ed83..526fc2b69ce 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java @@ -100,7 +100,7 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder // skip } else if (token == XContentParser.Token.START_OBJECT) { if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) { - script = Script.parse(parser, parseContext.getParseFieldMatcher(), parseContext.getDefaultScriptLanguage()); + script = Script.parse(parser, parseContext.getDefaultScriptLanguage()); } else { throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]"); } @@ -110,7 +110,7 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) { boost = parser.floatValue(); } else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) { - script = Script.parse(parser, parseContext.getParseFieldMatcher(), parseContext.getDefaultScriptLanguage()); + script = Script.parse(parser, parseContext.getDefaultScriptLanguage()); } else { throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]"); } diff --git a/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java b/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java index b1fee2d6252..68913cd9e21 100644 --- a/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java @@ -112,7 +112,7 @@ public class ScriptScoreFunctionBuilder extends ScoreFunctionBuilder PARSER = new ObjectParser<>("script", Builder::new); + private static final ObjectParser PARSER = new ObjectParser<>("script", Builder::new); static { // Defines the fields necessary to parse a Script as XContent using an ObjectParser. @@ -224,19 +221,11 @@ public final class Script implements ToXContent, Writeable { } /** - * Convenience method to call {@link Script#parse(XContentParser, ParseFieldMatcher, String)} + * Convenience method to call {@link Script#parse(XContentParser, String)} * using the default scripting language. */ - public static Script parse(XContentParser parser, ParseFieldMatcher matcher) throws IOException { - return parse(parser, matcher, DEFAULT_SCRIPT_LANG); - } - - /** - * Convenience method to call {@link Script#parse(XContentParser, ParseFieldMatcher, String)} using the - * {@link ParseFieldMatcher} and scripting language provided by the {@link QueryParseContext}. - */ - public static Script parse(XContentParser parser, QueryParseContext context) throws IOException { - return parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + public static Script parse(XContentParser parser) throws IOException { + return parse(parser, DEFAULT_SCRIPT_LANG); } /** @@ -300,13 +289,12 @@ public final class Script implements ToXContent, Writeable { * } * * @param parser The {@link XContentParser} to be used. - * @param matcher The {@link ParseFieldMatcher} to be used. * @param defaultLang The default language to use if no language is specified. The default language isn't necessarily * the one defined by {@link Script#DEFAULT_SCRIPT_LANG} due to backwards compatiblity requirements * related to stored queries using previously default languauges. * @return The parsed {@link Script}. */ - public static Script parse(XContentParser parser, ParseFieldMatcher matcher, String defaultLang) throws IOException { + public static Script parse(XContentParser parser, String defaultLang) throws IOException { Objects.requireNonNull(defaultLang); Token token = parser.currentToken(); @@ -319,7 +307,7 @@ public final class Script implements ToXContent, Writeable { return new Script(ScriptType.INLINE, defaultLang, parser.text(), Collections.emptyMap()); } - return PARSER.apply(parser, () -> matcher).build(defaultLang); + return PARSER.apply(parser, null).build(defaultLang); } private final ScriptType type; diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/ScriptHeuristic.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/ScriptHeuristic.java index b49ca9fe1c9..083733f31ae 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/ScriptHeuristic.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/ScriptHeuristic.java @@ -158,7 +158,7 @@ public class ScriptHeuristic extends SignificanceHeuristic { currentFieldName = parser.currentName(); } else { if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) { - script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + script = Script.parse(parser, context.getDefaultScriptLanguage()); } else { throw new ElasticsearchParseException("failed to parse [{}] significance heuristic. unknown object [{}]", heuristicName, currentFieldName); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregationBuilder.java index 6b4d1bc1b8f..68a5138271f 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregationBuilder.java @@ -38,7 +38,6 @@ import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; -import java.util.Collections; import java.util.HashSet; import java.util.Map; import java.util.Objects; @@ -255,13 +254,13 @@ public class ScriptedMetricAggregationBuilder extends AbstractAggregationBuilder currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_OBJECT || token == XContentParser.Token.VALUE_STRING) { if (INIT_SCRIPT_FIELD.match(currentFieldName)) { - initScript = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + initScript = Script.parse(parser, context.getDefaultScriptLanguage()); } else if (MAP_SCRIPT_FIELD.match(currentFieldName)) { - mapScript = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + mapScript = Script.parse(parser, context.getDefaultScriptLanguage()); } else if (COMBINE_SCRIPT_FIELD.match(currentFieldName)) { - combineScript = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + combineScript = Script.parse(parser, context.getDefaultScriptLanguage()); } else if (REDUCE_SCRIPT_FIELD.match(currentFieldName)) { - reduceScript = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + reduceScript = Script.parse(parser, context.getDefaultScriptLanguage()); } else if (token == XContentParser.Token.START_OBJECT && PARAMS_FIELD.match(currentFieldName)) { params = parser.map(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java index 7cfc0cf61c1..978060632dc 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java @@ -642,7 +642,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder map = parser.map(); bucketsPathsMap = new HashMap<>(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregationBuilder.java index 8a88f011756..078f50a978f 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregationBuilder.java @@ -141,7 +141,7 @@ public class BucketSelectorPipelineAggregationBuilder extends AbstractPipelineAg } else if (GAP_POLICY.match(currentFieldName)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); } else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) { - script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + script = Script.parse(parser, context.getDefaultScriptLanguage()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); @@ -163,7 +163,7 @@ public class BucketSelectorPipelineAggregationBuilder extends AbstractPipelineAg } } else if (token == XContentParser.Token.START_OBJECT) { if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) { - script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + script = Script.parse(parser, context.getDefaultScriptLanguage()); } else if (BUCKETS_PATH.match(currentFieldName)) { Map map = parser.map(); bucketsPathsMap = new HashMap<>(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceParserHelper.java b/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceParserHelper.java index 2af21192a44..7b174d789f4 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceParserHelper.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceParserHelper.java @@ -35,30 +35,30 @@ public final class ValuesSourceParserHelper { public static void declareAnyFields( ObjectParser, QueryParseContext> objectParser, boolean scriptable, boolean formattable) { - declareFields(objectParser, scriptable, formattable, false, ValuesSourceType.ANY, null); + declareFields(objectParser, scriptable, formattable, false, null); } public static void declareNumericFields( ObjectParser, QueryParseContext> objectParser, boolean scriptable, boolean formattable, boolean timezoneAware) { - declareFields(objectParser, scriptable, formattable, timezoneAware, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + declareFields(objectParser, scriptable, formattable, timezoneAware, ValueType.NUMERIC); } public static void declareBytesFields( ObjectParser, QueryParseContext> objectParser, boolean scriptable, boolean formattable) { - declareFields(objectParser, scriptable, formattable, false, ValuesSourceType.BYTES, ValueType.STRING); + declareFields(objectParser, scriptable, formattable, false, ValueType.STRING); } public static void declareGeoFields( ObjectParser, QueryParseContext> objectParser, boolean scriptable, boolean formattable) { - declareFields(objectParser, scriptable, formattable, false, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT); + declareFields(objectParser, scriptable, formattable, false, ValueType.GEOPOINT); } private static void declareFields( ObjectParser, QueryParseContext> objectParser, - boolean scriptable, boolean formattable, boolean timezoneAware, ValuesSourceType valuesSourceType, ValueType targetValueType) { + boolean scriptable, boolean formattable, boolean timezoneAware, ValueType targetValueType) { objectParser.declareField(ValuesSourceAggregationBuilder::field, XContentParser::text, @@ -84,7 +84,8 @@ public final class ValuesSourceParserHelper { } if (scriptable) { - objectParser.declareField(ValuesSourceAggregationBuilder::script, org.elasticsearch.script.Script::parse, + objectParser.declareField(ValuesSourceAggregationBuilder::script, + (parser, context) -> Script.parse(parser, context.getDefaultScriptLanguage()), Script.SCRIPT_PARSE_FIELD, ObjectParser.ValueType.OBJECT_OR_STRING); } diff --git a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java index 7ecd06c8c83..35c6488136b 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -1341,7 +1341,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ currentFieldName = parser.currentName(); } else if (token.isValue()) { if (SCRIPT_FIELD.match(currentFieldName)) { - script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + script = Script.parse(parser, context.getDefaultScriptLanguage()); } else if (IGNORE_FAILURE_FIELD.match(currentFieldName)) { ignoreFailure = parser.booleanValue(); } else { @@ -1350,7 +1350,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ } } else if (token == XContentParser.Token.START_OBJECT) { if (SCRIPT_FIELD.match(currentFieldName)) { - script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + script = Script.parse(parser, context.getDefaultScriptLanguage()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); diff --git a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java index 6da93b26b8c..f284597e782 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java @@ -216,7 +216,8 @@ public class ScriptSortBuilder extends SortBuilder { a -> new ScriptSortBuilder((Script) a[0], (ScriptSortType) a[1])); static { - PARSER.declareField(constructorArg(), Script::parse, Script.SCRIPT_PARSE_FIELD, ValueType.OBJECT_OR_STRING); + PARSER.declareField(constructorArg(), (parser, context) -> Script.parse(parser, context.getDefaultScriptLanguage()), + Script.SCRIPT_PARSE_FIELD, ValueType.OBJECT_OR_STRING); PARSER.declareField(constructorArg(), p -> ScriptSortType.fromString(p.text()), TYPE_FIELD, ValueType.STRING); PARSER.declareString((b, v) -> b.order(SortOrder.fromString(v)), ORDER_FIELD); PARSER.declareString((b, v) -> b.sortMode(SortMode.fromString(v)), SORTMODE_FIELD); diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java index 20d4f6853c0..12d2af289a9 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java @@ -567,7 +567,7 @@ public class PhraseSuggestionBuilder extends SuggestionBuilder s.versionType(VersionType.fromString(i)), new ParseField("version_type")); - PARSER.declareField((p, v, c) -> sourceParser.parse(p, v, c), new ParseField("source"), ValueType.OBJECT); + PARSER.declareField(sourceParser::parse, new ParseField("source"), ValueType.OBJECT); PARSER.declareField((p, v, c) -> destParser.parse(p, v.getDestination(), c), new ParseField("dest"), ValueType.OBJECT); PARSER.declareInt(ReindexRequest::setSize, new ParseField("size")); - PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p, c.getParseFieldMatcher())), new ParseField("script"), + PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p)), new ParseField("script"), ValueType.OBJECT); PARSER.declareString(ReindexRequest::setConflicts, new ParseField("conflicts")); } From dea7d6543958899d08503e722febf8512348321b Mon Sep 17 00:00:00 2001 From: javanna Date: Wed, 4 Jan 2017 15:29:09 +0100 Subject: [PATCH 14/22] remove ParseFieldMatcher usages from RestSearchTemplateAction --- .../script/mustache/RestSearchTemplateAction.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java index a6d705386fc..192cdc6a463 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java @@ -23,8 +23,6 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -47,7 +45,7 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestSearchTemplateAction extends BaseRestHandler { - private static final ObjectParser PARSER; + private static final ObjectParser PARSER; static { PARSER = new ObjectParser<>("search_template"); PARSER.declareField((parser, request, s) -> @@ -105,7 +103,7 @@ public class RestSearchTemplateAction extends BaseRestHandler { // Creates the search template request SearchTemplateRequest searchTemplateRequest; try (XContentParser parser = request.contentOrSourceParamParser()) { - searchTemplateRequest = PARSER.parse(parser, new SearchTemplateRequest(), () -> ParseFieldMatcher.EMPTY); + searchTemplateRequest = PARSER.parse(parser, new SearchTemplateRequest(), null); } searchTemplateRequest.setRequest(searchRequest); @@ -113,6 +111,6 @@ public class RestSearchTemplateAction extends BaseRestHandler { } public static SearchTemplateRequest parse(XContentParser parser) throws IOException { - return PARSER.parse(parser, new SearchTemplateRequest(), () -> ParseFieldMatcher.EMPTY); + return PARSER.parse(parser, new SearchTemplateRequest(), null); } } From 723bdc45499daf7034a85570841565df67810955 Mon Sep 17 00:00:00 2001 From: javanna Date: Wed, 4 Jan 2017 15:32:53 +0100 Subject: [PATCH 15/22] remove ParseFieldMatcher usages from FetchSourceContext --- .../java/org/elasticsearch/action/bulk/BulkRequest.java | 4 ++-- .../org/elasticsearch/action/update/UpdateRequest.java | 2 +- .../org/elasticsearch/index/query/InnerHitBuilder.java | 2 +- .../metrics/tophits/TopHitsAggregationBuilder.java | 6 +++--- .../elasticsearch/search/builder/SearchSourceBuilder.java | 6 +++--- .../search/fetch/subphase/FetchSourceContext.java | 7 +------ 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java b/core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java index 2ce9f4d47c4..20d5e64f49a 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java @@ -349,7 +349,7 @@ public class BulkRequest extends ActionRequest implements CompositeIndicesReques } else if ("fields".equals(currentFieldName)) { throw new IllegalArgumentException("Action/metadata line [" + line + "] contains a simple value for parameter [fields] while a list is expected"); } else if ("_source".equals(currentFieldName)) { - fetchSourceContext = FetchSourceContext.parse(parser); + fetchSourceContext = FetchSourceContext.fromXContent(parser); } else { throw new IllegalArgumentException("Action/metadata line [" + line + "] contains an unknown parameter [" + currentFieldName + "]"); } @@ -362,7 +362,7 @@ public class BulkRequest extends ActionRequest implements CompositeIndicesReques throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]"); } } else if (token == XContentParser.Token.START_OBJECT && "_source".equals(currentFieldName)) { - fetchSourceContext = FetchSourceContext.parse(parser); + fetchSourceContext = FetchSourceContext.fromXContent(parser); } else if (token != XContentParser.Token.VALUE_NULL) { throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]"); } diff --git a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java index d31d0c9ae14..0d2801e44a0 100644 --- a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java +++ b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java @@ -739,7 +739,7 @@ public class UpdateRequest extends InstanceShardOperationRequest fields(fields.toArray(new String[fields.size()])); } } else if ("_source".equals(currentFieldName)) { - fetchSourceContext = FetchSourceContext.parse(parser); + fetchSourceContext = FetchSourceContext.fromXContent(parser); } } if (script != null) { diff --git a/core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java b/core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java index 5bd7b20cb29..9ef9f2998b0 100644 --- a/core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java @@ -96,7 +96,7 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl ObjectParser.ValueType.OBJECT_ARRAY); PARSER.declareField((p, i, c) -> { try { - i.setFetchSourceContext(FetchSourceContext.parse(c.parser())); + i.setFetchSourceContext(FetchSourceContext.fromXContent(c.parser())); } catch (IOException e) { throw new ParsingException(p.getTokenLocation(), "Could not parse inner _source definition", e); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java index 978060632dc..68932d65b16 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java @@ -616,7 +616,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder scriptFields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -699,7 +699,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder> sorts = SortBuilder.fromXContent(context); factory.sorts(sorts); } else if (SearchSourceBuilder._SOURCE_FIELD.match(currentFieldName)) { - factory.fetchSource(FetchSourceContext.parse(context.parser())); + factory.fetchSource(FetchSourceContext.fromXContent(context.parser())); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); diff --git a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java index 35c6488136b..99cb5a5e6b3 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -948,7 +948,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ } else if (TRACK_SCORES_FIELD.match(currentFieldName)) { trackScores = parser.booleanValue(); } else if (_SOURCE_FIELD.match(currentFieldName)) { - fetchSourceContext = FetchSourceContext.parse(context.parser()); + fetchSourceContext = FetchSourceContext.fromXContent(context.parser()); } else if (STORED_FIELDS_FIELD.match(currentFieldName)) { storedFieldsContext = StoredFieldsContext.fromXContent(SearchSourceBuilder.STORED_FIELDS_FIELD.getPreferredName(), context); @@ -970,7 +970,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ } else if (POST_FILTER_FIELD.match(currentFieldName)) { postQueryBuilder = context.parseInnerQueryBuilder(); } else if (_SOURCE_FIELD.match(currentFieldName)) { - fetchSourceContext = FetchSourceContext.parse(context.parser()); + fetchSourceContext = FetchSourceContext.fromXContent(context.parser()); } else if (SCRIPT_FIELDS_FIELD.match(currentFieldName)) { scriptFields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -1059,7 +1059,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ } } } else if (_SOURCE_FIELD.match(currentFieldName)) { - fetchSourceContext = FetchSourceContext.parse(context.parser()); + fetchSourceContext = FetchSourceContext.fromXContent(context.parser()); } else if (SEARCH_AFTER.match(currentFieldName)) { searchAfterBuilder = SearchAfterBuilder.fromXContent(parser, context.getParseFieldMatcher()); } else if (FIELDS_FIELD.match(currentFieldName)) { diff --git a/core/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java b/core/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java index 55197b91064..f3e8bab93fa 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java @@ -21,7 +21,6 @@ package org.elasticsearch.search.fetch.subphase; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -55,10 +54,6 @@ public class FetchSourceContext implements Writeable, ToXContent { private final String[] excludes; private Function, Map> filter; - public static FetchSourceContext parse(XContentParser parser) throws IOException { - return fromXContent(parser, ParseFieldMatcher.STRICT); - } - public FetchSourceContext(boolean fetchSource, String[] includes, String[] excludes) { this.fetchSource = fetchSource; this.includes = includes == null ? Strings.EMPTY_ARRAY : includes; @@ -127,7 +122,7 @@ public class FetchSourceContext implements Writeable, ToXContent { return null; } - public static FetchSourceContext fromXContent(XContentParser parser, ParseFieldMatcher parseFieldMatcher) throws IOException { + public static FetchSourceContext fromXContent(XContentParser parser) throws IOException { XContentParser.Token token = parser.currentToken(); boolean fetchSource = true; String[] includes = Strings.EMPTY_ARRAY; From d87a30647b501b2fa7d99afb75f718c0ccbcd16f Mon Sep 17 00:00:00 2001 From: javanna Date: Wed, 4 Jan 2017 15:45:23 +0100 Subject: [PATCH 16/22] remove ParseFieldMatcher usages from SearchAfterBuilder --- .../org/elasticsearch/search/builder/SearchSourceBuilder.java | 2 +- .../elasticsearch/search/searchafter/SearchAfterBuilder.java | 3 +-- .../search/searchafter/SearchAfterBuilderTests.java | 4 ++-- .../elasticsearch/search/RandomSearchRequestGenerator.java | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java index 99cb5a5e6b3..520b92692fa 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -1061,7 +1061,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ } else if (_SOURCE_FIELD.match(currentFieldName)) { fetchSourceContext = FetchSourceContext.fromXContent(context.parser()); } else if (SEARCH_AFTER.match(currentFieldName)) { - searchAfterBuilder = SearchAfterBuilder.fromXContent(parser, context.getParseFieldMatcher()); + searchAfterBuilder = SearchAfterBuilder.fromXContent(parser); } else if (FIELDS_FIELD.match(currentFieldName)) { throw new ParsingException(parser.getTokenLocation(), "The field [" + SearchSourceBuilder.FIELDS_FIELD + "] is no longer supported, please use [" + diff --git a/core/src/main/java/org/elasticsearch/search/searchafter/SearchAfterBuilder.java b/core/src/main/java/org/elasticsearch/search/searchafter/SearchAfterBuilder.java index b9a6ca9be57..bc73ad7925b 100644 --- a/core/src/main/java/org/elasticsearch/search/searchafter/SearchAfterBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/searchafter/SearchAfterBuilder.java @@ -23,7 +23,6 @@ import org.apache.lucene.search.FieldDoc; import org.apache.lucene.search.SortField; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -202,7 +201,7 @@ public class SearchAfterBuilder implements ToXContent, Writeable { builder.array(SEARCH_AFTER.getPreferredName(), sortValues); } - public static SearchAfterBuilder fromXContent(XContentParser parser, ParseFieldMatcher parseFieldMatcher) throws IOException { + public static SearchAfterBuilder fromXContent(XContentParser parser) throws IOException { SearchAfterBuilder builder = new SearchAfterBuilder(); XContentParser.Token token = parser.currentToken(); List values = new ArrayList<> (); diff --git a/core/src/test/java/org/elasticsearch/search/searchafter/SearchAfterBuilderTests.java b/core/src/test/java/org/elasticsearch/search/searchafter/SearchAfterBuilderTests.java index 93663d93683..8e372d95236 100644 --- a/core/src/test/java/org/elasticsearch/search/searchafter/SearchAfterBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/searchafter/SearchAfterBuilderTests.java @@ -133,7 +133,7 @@ public class SearchAfterBuilderTests extends ESTestCase { parser.nextToken(); parser.nextToken(); parser.nextToken(); - return SearchAfterBuilder.fromXContent(parser, null); + return SearchAfterBuilder.fromXContent(parser); } private static SearchAfterBuilder serializedCopy(SearchAfterBuilder original) throws IOException { @@ -172,7 +172,7 @@ public class SearchAfterBuilderTests extends ESTestCase { parser.nextToken(); parser.nextToken(); parser.nextToken(); - SearchAfterBuilder secondSearchAfterBuilder = SearchAfterBuilder.fromXContent(parser, null); + SearchAfterBuilder secondSearchAfterBuilder = SearchAfterBuilder.fromXContent(parser); assertNotSame(searchAfterBuilder, secondSearchAfterBuilder); assertEquals(searchAfterBuilder, secondSearchAfterBuilder); assertEquals(searchAfterBuilder.hashCode(), secondSearchAfterBuilder.hashCode()); diff --git a/test/framework/src/main/java/org/elasticsearch/search/RandomSearchRequestGenerator.java b/test/framework/src/main/java/org/elasticsearch/search/RandomSearchRequestGenerator.java index db00d480a8a..fc240e6b555 100644 --- a/test/framework/src/main/java/org/elasticsearch/search/RandomSearchRequestGenerator.java +++ b/test/framework/src/main/java/org/elasticsearch/search/RandomSearchRequestGenerator.java @@ -302,7 +302,7 @@ public class RandomSearchRequestGenerator { parser.nextToken(); parser.nextToken(); parser.nextToken(); - builder.searchAfter(SearchAfterBuilder.fromXContent(parser, null).getSortValues()); + builder.searchAfter(SearchAfterBuilder.fromXContent(parser).getSortValues()); } catch (IOException e) { throw new RuntimeException("Error building search_from", e); } From d60e9bddd058e3dd3efd7ce09c858c3b8d69d413 Mon Sep 17 00:00:00 2001 From: javanna Date: Wed, 4 Jan 2017 15:54:42 +0100 Subject: [PATCH 17/22] remove ParseFieldMatcher usages from IndexGraveyard --- .../cluster/metadata/IndexGraveyard.java | 17 ++++++++--------- .../java/org/elasticsearch/index/Index.java | 10 ++-------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexGraveyard.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexGraveyard.java index 722af7f8750..d60617ea642 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexGraveyard.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexGraveyard.java @@ -22,8 +22,6 @@ package org.elasticsearch.cluster.metadata; import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.NamedDiff; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -70,7 +68,7 @@ public final class IndexGraveyard implements MetaData.Custom { public static final String TYPE = "index-graveyard"; private static final ParseField TOMBSTONES_FIELD = new ParseField("tombstones"); - private static final ObjectParser, ParseFieldMatcherSupplier> GRAVEYARD_PARSER; + private static final ObjectParser, Void> GRAVEYARD_PARSER; static { GRAVEYARD_PARSER = new ObjectParser<>("index_graveyard", ArrayList::new); GRAVEYARD_PARSER.declareObjectArray(List::addAll, Tombstone.getParser(), TOMBSTONES_FIELD); @@ -141,7 +139,7 @@ public final class IndexGraveyard implements MetaData.Custom { } public static IndexGraveyard fromXContent(final XContentParser parser) throws IOException { - return new IndexGraveyard(GRAVEYARD_PARSER.parse(parser, () -> ParseFieldMatcher.STRICT)); + return new IndexGraveyard(GRAVEYARD_PARSER.parse(parser, null)); } @Override @@ -354,16 +352,17 @@ public final class IndexGraveyard implements MetaData.Custom { private static final String INDEX_KEY = "index"; private static final String DELETE_DATE_IN_MILLIS_KEY = "delete_date_in_millis"; private static final String DELETE_DATE_KEY = "delete_date"; - private static final ObjectParser TOMBSTONE_PARSER; + private static final ObjectParser TOMBSTONE_PARSER; static { TOMBSTONE_PARSER = new ObjectParser<>("tombstoneEntry", Tombstone.Builder::new); - TOMBSTONE_PARSER.declareObject(Tombstone.Builder::index, Index::parseIndex, new ParseField(INDEX_KEY)); + TOMBSTONE_PARSER.declareObject(Tombstone.Builder::index, (parser, context) -> Index.fromXContent(parser), + new ParseField(INDEX_KEY)); TOMBSTONE_PARSER.declareLong(Tombstone.Builder::deleteDateInMillis, new ParseField(DELETE_DATE_IN_MILLIS_KEY)); TOMBSTONE_PARSER.declareString((b, s) -> {}, new ParseField(DELETE_DATE_KEY)); } - static ContextParser getParser() { - return (p, c) -> TOMBSTONE_PARSER.apply(p, c).build(); + static ContextParser getParser() { + return (parser, context) -> TOMBSTONE_PARSER.apply(parser, null).build(); } private final Index index; @@ -438,7 +437,7 @@ public final class IndexGraveyard implements MetaData.Custom { } public static Tombstone fromXContent(final XContentParser parser) throws IOException { - return TOMBSTONE_PARSER.parse(parser, () -> ParseFieldMatcher.STRICT).build(); + return TOMBSTONE_PARSER.parse(parser, null).build(); } /** diff --git a/core/src/main/java/org/elasticsearch/index/Index.java b/core/src/main/java/org/elasticsearch/index/Index.java index 25b293ad387..da94ad2ec72 100644 --- a/core/src/main/java/org/elasticsearch/index/Index.java +++ b/core/src/main/java/org/elasticsearch/index/Index.java @@ -21,8 +21,6 @@ package org.elasticsearch.index; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -42,7 +40,7 @@ public class Index implements Writeable, ToXContent { public static final Index[] EMPTY_ARRAY = new Index[0]; private static final String INDEX_UUID_KEY = "index_uuid"; private static final String INDEX_NAME_KEY = "index_name"; - private static final ObjectParser INDEX_PARSER = new ObjectParser<>("index", Builder::new); + private static final ObjectParser INDEX_PARSER = new ObjectParser<>("index", Builder::new); static { INDEX_PARSER.declareString(Builder::name, new ParseField(INDEX_NAME_KEY)); INDEX_PARSER.declareString(Builder::uuid, new ParseField(INDEX_UUID_KEY)); @@ -118,11 +116,7 @@ public class Index implements Writeable, ToXContent { } public static Index fromXContent(final XContentParser parser) throws IOException { - return INDEX_PARSER.parse(parser, () -> ParseFieldMatcher.STRICT).build(); - } - - public static final Index parseIndex(final XContentParser parser, final ParseFieldMatcherSupplier supplier) { - return INDEX_PARSER.apply(parser, supplier).build(); + return INDEX_PARSER.parse(parser, null).build(); } /** From 13dcb8ccbef75dbc68ea0a93a45f052c0be17580 Mon Sep 17 00:00:00 2001 From: javanna Date: Wed, 4 Jan 2017 15:56:25 +0100 Subject: [PATCH 18/22] remove ParseFieldMatcher usages from IngestMetadata --- .../main/java/org/elasticsearch/ingest/IngestMetadata.java | 6 ++---- .../org/elasticsearch/ingest/PipelineConfiguration.java | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/ingest/IngestMetadata.java b/core/src/main/java/org/elasticsearch/ingest/IngestMetadata.java index 6c87d6c5892..012ce5ba68d 100644 --- a/core/src/main/java/org/elasticsearch/ingest/IngestMetadata.java +++ b/core/src/main/java/org/elasticsearch/ingest/IngestMetadata.java @@ -24,8 +24,6 @@ import org.elasticsearch.cluster.DiffableUtils; import org.elasticsearch.cluster.NamedDiff; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; @@ -47,7 +45,7 @@ public final class IngestMetadata implements MetaData.Custom { public static final String TYPE = "ingest"; private static final ParseField PIPELINES_FIELD = new ParseField("pipeline"); - private static final ObjectParser, ParseFieldMatcherSupplier> INGEST_METADATA_PARSER = new ObjectParser<>( + private static final ObjectParser, Void> INGEST_METADATA_PARSER = new ObjectParser<>( "ingest_metadata", ArrayList::new); static { @@ -95,7 +93,7 @@ public final class IngestMetadata implements MetaData.Custom { public static IngestMetadata fromXContent(XContentParser parser) throws IOException { Map pipelines = new HashMap<>(); - List configs = INGEST_METADATA_PARSER.parse(parser, () -> ParseFieldMatcher.STRICT); + List configs = INGEST_METADATA_PARSER.parse(parser, null); for (PipelineConfiguration pipeline : configs) { pipelines.put(pipeline.getId(), pipeline); } diff --git a/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java b/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java index c983c205f8d..543a02d3e86 100644 --- a/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java +++ b/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java @@ -50,8 +50,8 @@ public final class PipelineConfiguration extends AbstractDiffable getParser() { - return (p, c) -> PARSER.apply(p ,c).build(); + public static ContextParser getParser() { + return (parser, context) -> PARSER.apply(parser, null).build(); } private static class Builder { From 975fee402a831f12eb684d1535800ed2e20fcf5a Mon Sep 17 00:00:00 2001 From: javanna Date: Wed, 4 Jan 2017 15:57:49 +0100 Subject: [PATCH 19/22] remove ParseFieldMatcher usages from suggesters --- .../suggest/completion/context/CategoryQueryContext.java | 6 ++---- .../search/suggest/phrase/LinearInterpolation.java | 2 -- .../search/suggest/phrase/PhraseSuggestionBuilder.java | 2 -- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java index a17b7a87b43..59f59075bd3 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java @@ -21,8 +21,6 @@ package org.elasticsearch.search.suggest.completion.context; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -98,7 +96,7 @@ public final class CategoryQueryContext implements ToXContent { return result; } - private static ObjectParser CATEGORY_PARSER = new ObjectParser<>(NAME, null); + private static ObjectParser CATEGORY_PARSER = new ObjectParser<>(NAME, null); static { CATEGORY_PARSER.declareString(Builder::setCategory, new ParseField(CONTEXT_VALUE)); CATEGORY_PARSER.declareInt(Builder::setBoost, new ParseField(CONTEXT_BOOST)); @@ -110,7 +108,7 @@ public final class CategoryQueryContext implements ToXContent { XContentParser.Token token = parser.currentToken(); Builder builder = builder(); if (token == XContentParser.Token.START_OBJECT) { - CATEGORY_PARSER.parse(parser, builder, () -> ParseFieldMatcher.STRICT); + CATEGORY_PARSER.parse(parser, builder, null); } else if (token == XContentParser.Token.VALUE_STRING) { builder.setCategory(parser.text()); } else { diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/LinearInterpolation.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/LinearInterpolation.java index e76868b5b3f..dbd1540b325 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/LinearInterpolation.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/LinearInterpolation.java @@ -23,7 +23,6 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Terms; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -138,7 +137,6 @@ public final class LinearInterpolation extends SmoothingModel { double trigramLambda = 0.0; double bigramLambda = 0.0; double unigramLambda = 0.0; - ParseFieldMatcher matcher = parseContext.getParseFieldMatcher(); while ((token = parser.nextToken()) != Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { fieldName = parser.currentName(); diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java index 12d2af289a9..7611d30263c 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java @@ -22,7 +22,6 @@ package org.elasticsearch.search.suggest.phrase; import org.apache.lucene.analysis.Analyzer; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -491,7 +490,6 @@ public class PhraseSuggestionBuilder extends SuggestionBuilder Date: Wed, 4 Jan 2017 15:59:31 +0100 Subject: [PATCH 20/22] remove ParseFieldMatcher usages from InternalSearchHit --- .../elasticsearch/search/internal/InternalSearchHit.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java index 76de9740c8e..5784c31d99c 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java +++ b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java @@ -23,8 +23,6 @@ import org.apache.lucene.search.Explanation; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.compress.CompressorFactory; @@ -726,7 +724,7 @@ public class InternalSearchHit implements SearchHit { return builder; } - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( "nested_identity", ctorArgs -> new InternalNestedIdentity((String) ctorArgs[0], (int) ctorArgs[1], (InternalNestedIdentity) ctorArgs[2])); static { @@ -736,7 +734,7 @@ public class InternalSearchHit implements SearchHit { } public static InternalNestedIdentity fromXContent(XContentParser parser) { - return PARSER.apply(parser, () -> ParseFieldMatcher.EMPTY); + return PARSER.apply(parser, null); } @Override From 20f90178fe975b0f2526b2834e4d5ca681e38dbb Mon Sep 17 00:00:00 2001 From: Jason Veatch Date: Thu, 5 Jan 2017 14:36:18 -0500 Subject: [PATCH 21/22] Docs: Detail on false/strict dynamic mapping setting (#22451) Reference: https://www.elastic.co/guide/en/elasticsearch/guide/master/dynamic-mapping.html --- docs/reference/mapping/dynamic/field-mapping.asciidoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/reference/mapping/dynamic/field-mapping.asciidoc b/docs/reference/mapping/dynamic/field-mapping.asciidoc index 7bed12b5b78..2b0afa1562d 100644 --- a/docs/reference/mapping/dynamic/field-mapping.asciidoc +++ b/docs/reference/mapping/dynamic/field-mapping.asciidoc @@ -4,7 +4,8 @@ By default, when a previously unseen field is found in a document, Elasticsearch will add the new field to the type mapping. This behaviour can be disabled, both at the document and at the <> level, by -setting the <> parameter to `false` or to `strict`. +setting the <> parameter to `false` (to ignore new fields) or to `strict` (to throw +an exception if an unknown field is encountered). Assuming `dynamic` field mapping is enabled, some simple rules are used to determine which datatype the field should have: From 27c57aeebeaa68dfb361465fe8fb66db97629776 Mon Sep 17 00:00:00 2001 From: Johannes Kanavin Date: Thu, 5 Jan 2017 19:30:05 +0100 Subject: [PATCH 22/22] Fixed id's of 'worked example' in scripted metric aggs docs (#22430) --- .../aggregations/metrics/scripted-metric-aggregation.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc b/docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc index f0ada57b37f..b7193b827cd 100644 --- a/docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc @@ -156,9 +156,9 @@ PUT /transactions/stock/_bulk?refresh {"type": "sale","amount": 80} {"index":{"_id":2}} {"type": "cost","amount": 10} -{"index":{"_id":2}} +{"index":{"_id":3}} {"type": "cost","amount": 30} -{"index":{"_id":2}} +{"index":{"_id":4}} {"type": "sale","amount": 130} -------------------------------------------------- // CONSOLE