From e01c0927a6f1faa07990eb3433ea4191e99c4920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Tue, 28 Jul 2015 15:43:38 +0200 Subject: [PATCH 01/54] Aggregations: Make ValueParser.DateMath aware of timezone setting This PR adds a timezone field to ValueParser.DateMath that is set to UTC by default but can be set using the existing constructors. This makes it possible for extended bounds setting in DateHistogram to also use date math expressions that e.g. round by day and apply this rounding in the time zone specified in the date histogram aggregation request. Closes #12278 --- .../support/format/ValueFormat.java | 6 +- .../support/format/ValueParser.java | 21 ++++-- .../aggregations/bucket/DateHistogramIT.java | 71 ++++++++++++++++++- 3 files changed, 85 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/support/format/ValueFormat.java b/core/src/main/java/org/elasticsearch/search/aggregations/support/format/ValueFormat.java index 33cf9cc5099..9a3be56517c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/support/format/ValueFormat.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/support/format/ValueFormat.java @@ -69,14 +69,14 @@ public class ValueFormat { public static final DateTime DEFAULT = new DateTime(DateFieldMapper.Defaults.DATE_TIME_FORMATTER.format(), ValueFormatter.DateTime.DEFAULT, ValueParser.DateMath.DEFAULT); public static DateTime format(String format, DateTimeZone timezone) { - return new DateTime(format, new ValueFormatter.DateTime(format, timezone), new ValueParser.DateMath(format)); + return new DateTime(format, new ValueFormatter.DateTime(format, timezone), new ValueParser.DateMath(format, timezone)); } public static DateTime mapper(DateFieldMapper.DateFieldType fieldType, DateTimeZone timezone) { - return new DateTime(fieldType.dateTimeFormatter().format(), ValueFormatter.DateTime.mapper(fieldType, timezone), ValueParser.DateMath.mapper(fieldType)); + return new DateTime(fieldType.dateTimeFormatter().format(), ValueFormatter.DateTime.mapper(fieldType, timezone), ValueParser.DateMath.mapper(fieldType, timezone)); } - public DateTime(String pattern, ValueFormatter formatter, ValueParser parser) { + private DateTime(String pattern, ValueFormatter formatter, ValueParser parser) { super(pattern, formatter, parser); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/support/format/ValueParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/support/format/ValueParser.java index c650244ce17..acd88f70201 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/support/format/ValueParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/support/format/ValueParser.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.search.aggregations.support.format; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.joda.DateMathParser; import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.joda.Joda; @@ -25,6 +26,7 @@ import org.elasticsearch.index.mapper.core.DateFieldMapper; import org.elasticsearch.index.mapper.ip.IpFieldMapper; import org.elasticsearch.search.aggregations.AggregationExecutionException; import org.elasticsearch.search.internal.SearchContext; +import org.joda.time.DateTimeZone; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; @@ -80,16 +82,21 @@ public interface ValueParser { */ static class DateMath implements ValueParser { - public static final DateMath DEFAULT = new ValueParser.DateMath(new DateMathParser(DateFieldMapper.Defaults.DATE_TIME_FORMATTER)); + public static final DateMath DEFAULT = new ValueParser.DateMath(new DateMathParser(DateFieldMapper.Defaults.DATE_TIME_FORMATTER), DateTimeZone.UTC); private DateMathParser parser; - public DateMath(String format) { - this(new DateMathParser(Joda.forPattern(format))); + private DateTimeZone timezone = DateTimeZone.UTC; + + public DateMath(String format, DateTimeZone timezone) { + this(new DateMathParser(Joda.forPattern(format)), timezone); } - public DateMath(DateMathParser parser) { + public DateMath(DateMathParser parser, @Nullable DateTimeZone timeZone) { this.parser = parser; + if (timeZone != null) { + this.timezone = timeZone; + } } @Override @@ -100,7 +107,7 @@ public interface ValueParser { return searchContext.nowInMillis(); } }; - return parser.parse(value, now); + return parser.parse(value, now, false, timezone); } @Override @@ -108,8 +115,8 @@ public interface ValueParser { return parseLong(value, searchContext); } - public static DateMath mapper(DateFieldMapper.DateFieldType fieldType) { - return new DateMath(new DateMathParser(fieldType.dateTimeFormatter())); + public static DateMath mapper(DateFieldMapper.DateFieldType fieldType, @Nullable DateTimeZone timezone) { + return new DateMath(new DateMathParser(fieldType.dateTimeFormatter()), timezone); } } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java index 4e81448ab6d..60cf352f098 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java @@ -21,9 +21,11 @@ package org.elasticsearch.search.aggregations.bucket; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.common.joda.DateMathParser; import org.elasticsearch.common.joda.Joda; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.mapper.core.DateFieldMapper; +import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.script.Script; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; @@ -42,6 +44,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -558,7 +561,7 @@ public class DateHistogramIT extends ESIntegTestCase { assertThat(bucket.getDocCount(), equalTo(3l)); } - + /* [ Jan 2, Feb 3] @@ -904,7 +907,7 @@ public class DateHistogramIT extends ESIntegTestCase { assertThat(bucket.getDocCount(), equalTo(3l)); } - + /* [ Jan 2, Feb 3] @@ -1195,6 +1198,68 @@ public class DateHistogramIT extends ESIntegTestCase { } } + /** + * Test date histogram aggregation with hour interval, timezone shift and + * extended bounds + */ + @Test + public void singleValueField_WithExtendedBoundsTimezone() throws Exception { + + String index = "test12278"; + prepareCreate(index) + .setSettings(Settings.builder().put(indexSettings()).put("index.number_of_shards", 1).put("index.number_of_replicas", 0)) + .execute().actionGet(); + + DateMathParser parser = new DateMathParser(Joda.getStrictStandardDateFormatter()); + + final Callable callable = new Callable() { + @Override + public Long call() throws Exception { + return System.currentTimeMillis(); + } + }; + + List builders = new ArrayList<>(); + int timeZoneHourOffset = randomIntBetween(-12, 12); + DateTimeZone timezone = DateTimeZone.forOffsetHours(timeZoneHourOffset); + DateTime timeZoneStartToday = new DateTime(parser.parse("now/d", callable, false, timezone), DateTimeZone.UTC); + DateTime timeZoneNoonToday = new DateTime(parser.parse("now/d+12h", callable, false, timezone), DateTimeZone.UTC); + + builders.add(indexDoc(index, timeZoneStartToday, 1)); + builders.add(indexDoc(index, timeZoneNoonToday, 2)); + indexRandom(true, builders); + ensureSearchable(index); + + SearchResponse response = null; + response = client() + .prepareSearch(index) + .setQuery(QueryBuilders.rangeQuery("date").from("now/d").to("now/d").includeLower(true).includeUpper(true).timeZone(timezone.getID())) + .addAggregation( + dateHistogram("histo").field("date").interval(DateHistogramInterval.hours(1)).timeZone(timezone.getID()).minDocCount(0) + .extendedBounds("now/d", "now/d+23h") + ).execute().actionGet(); + assertSearchResponse(response); + + assertThat("Expected 24 buckets for one day aggregation with hourly interval", response.getHits().totalHits(), equalTo(2l)); + + Histogram histo = response.getAggregations().get("histo"); + assertThat(histo, notNullValue()); + assertThat(histo.getName(), equalTo("histo")); + List buckets = histo.getBuckets(); + assertThat(buckets.size(), equalTo(24)); + + for (int i = 0; i < buckets.size(); i++) { + Histogram.Bucket bucket = buckets.get(i); + assertThat(bucket, notNullValue()); + assertThat("Bucket " + i +" had wrong key", (DateTime) bucket.getKey(), equalTo(new DateTime(timeZoneStartToday.getMillis() + (i * 60 * 60 * 1000), DateTimeZone.UTC))); + if (i == 0 || i == 12) { + assertThat(bucket.getDocCount(), equalTo(1l)); + } else { + assertThat(bucket.getDocCount(), equalTo(0l)); + } + } + } + @Test public void singleValue_WithMultipleDateFormatsFromMapping() throws Exception { @@ -1233,7 +1298,7 @@ public class DateHistogramIT extends ESIntegTestCase { .execute().actionGet(); assertSearchResponse(response); - + DateTimeZone tz = DateTimeZone.forID("+01:00"); Histogram histo = response.getAggregations().get("histo"); From 407781e76a7dedd61471e7e26b5f2539562164f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 14 Aug 2015 18:42:45 +0200 Subject: [PATCH 02/54] Adding comments to test --- .../search/aggregations/bucket/DateHistogramIT.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java index 60cf352f098..5b815a40544 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java @@ -1200,7 +1200,7 @@ public class DateHistogramIT extends ESIntegTestCase { /** * Test date histogram aggregation with hour interval, timezone shift and - * extended bounds + * extended bounds (see https://github.com/elastic/elasticsearch/issues/12278) */ @Test public void singleValueField_WithExtendedBoundsTimezone() throws Exception { @@ -1219,18 +1219,20 @@ public class DateHistogramIT extends ESIntegTestCase { } }; + // we pick a random timezone offset of +12/-12 hours and insert two documents + // one at 00:00 in that time zone and one at 12:00 List builders = new ArrayList<>(); int timeZoneHourOffset = randomIntBetween(-12, 12); DateTimeZone timezone = DateTimeZone.forOffsetHours(timeZoneHourOffset); DateTime timeZoneStartToday = new DateTime(parser.parse("now/d", callable, false, timezone), DateTimeZone.UTC); DateTime timeZoneNoonToday = new DateTime(parser.parse("now/d+12h", callable, false, timezone), DateTimeZone.UTC); - builders.add(indexDoc(index, timeZoneStartToday, 1)); builders.add(indexDoc(index, timeZoneNoonToday, 2)); indexRandom(true, builders); ensureSearchable(index); SearchResponse response = null; + // retrieve those docs with the same time zone and extended bounds response = client() .prepareSearch(index) .setQuery(QueryBuilders.rangeQuery("date").from("now/d").to("now/d").includeLower(true).includeUpper(true).timeZone(timezone.getID())) From ea03e5dd176897d4c63a42de8812fea0fba87474 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 17 Aug 2015 15:17:45 +0200 Subject: [PATCH 03/54] Add build short hash to the download manager headers to identify staging builds It might turn out to be useful to have the actual commit hash of the version we are looking for if our download manager can just redirect to the right staging repository. --- .../elasticsearch/common/http/client/HttpDownloadHelper.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/http/client/HttpDownloadHelper.java b/core/src/main/java/org/elasticsearch/common/http/client/HttpDownloadHelper.java index 0ee003c6102..a4a154330aa 100644 --- a/core/src/main/java/org/elasticsearch/common/http/client/HttpDownloadHelper.java +++ b/core/src/main/java/org/elasticsearch/common/http/client/HttpDownloadHelper.java @@ -360,10 +360,11 @@ public class HttpDownloadHelper { if (connection instanceof HttpURLConnection) { ((HttpURLConnection) connection).setInstanceFollowRedirects(false); - ((HttpURLConnection) connection).setUseCaches(true); - ((HttpURLConnection) connection).setConnectTimeout(5000); + connection.setUseCaches(true); + connection.setConnectTimeout(5000); } connection.setRequestProperty("ES-Version", Version.CURRENT.toString()); + connection.setRequestProperty("ES-Build-Hash", Build.CURRENT.hashShort()); connection.setRequestProperty("User-Agent", "elasticsearch-plugin-manager"); // connect to the remote site (may take some time) From 6f124e6eec416e3afb2c93c62ede72e91fe62177 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 17 Aug 2015 15:08:08 -0700 Subject: [PATCH 04/54] Internal: Simplify custom repository type setup Custom repository types are registered through the RepositoriesModule. Later, when a specific repository type is used, the RespositoryModule is installed, which in turn would spawn the module that was registered for that repository type. However, a module is not needed here. Each repository type has two associated classes, a Repository and an IndexShardRepository. This change makes the registration method for custom repository types take both of these classes, instead of a module. See #12783. --- .../common/util/ExtensionPoint.java | 7 +- .../repositories/RepositoriesModule.java | 37 ++++------ .../repositories/RepositoryModule.java | 25 +------ .../repositories/RepositoryTypesRegistry.java | 36 +++++----- .../repositories/fs/FsRepositoryModule.java | 46 ------------ .../repositories/uri/URLRepositoryModule.java | 46 ------------ .../AbstractSnapshotIntegTestCase.java | 3 +- .../DedicatedClusterSnapshotRestoreIT.java | 21 +++--- .../snapshots/RepositoriesIT.java | 3 - .../SharedClusterSnapshotRestoreIT.java | 1 - .../snapshots/mockstore/MockRepository.java | 56 +++++++++++++-- .../mockstore/MockRepositoryModule.java | 42 ----------- .../mockstore/MockRepositoryPlugin.java | 71 ------------------- .../plugin/cloud/aws/CloudAwsPlugin.java | 4 +- .../repositories/s3/S3RepositoryModule.java | 45 ------------ .../cloud/azure/AzureModule.java | 2 + .../plugin/cloud/azure/CloudAzurePlugin.java | 10 ++- .../azure/AzureRepositoryModule.java | 61 ---------------- 18 files changed, 111 insertions(+), 405 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/repositories/fs/FsRepositoryModule.java delete mode 100644 core/src/main/java/org/elasticsearch/repositories/uri/URLRepositoryModule.java delete mode 100644 core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryModule.java delete mode 100644 core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java delete mode 100644 plugins/cloud-aws/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryModule.java delete mode 100644 plugins/cloud-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryModule.java diff --git a/core/src/main/java/org/elasticsearch/common/util/ExtensionPoint.java b/core/src/main/java/org/elasticsearch/common/util/ExtensionPoint.java index 5414c4eb7a6..56163378327 100644 --- a/core/src/main/java/org/elasticsearch/common/util/ExtensionPoint.java +++ b/core/src/main/java/org/elasticsearch/common/util/ExtensionPoint.java @@ -133,13 +133,16 @@ public abstract class ExtensionPoint { * the settings object. * * @param binder the binder to use - * @param settings the settings to look up the key to find the implemetation to bind + * @param settings the settings to look up the key to find the implementation to bind * @param settingsKey the key to use with the settings - * @param defaultValue the default value if they settings doesn't contain the key + * @param defaultValue the default value if the settings do not contain the key, or null if there is no default * @return the actual bound type key */ public String bindType(Binder binder, Settings settings, String settingsKey, String defaultValue) { final String type = settings.get(settingsKey, defaultValue); + if (type == null) { + throw new IllegalArgumentException("Missing setting [" + settingsKey + "]"); + } final Class instance = getExtension(type); if (instance == null) { throw new IllegalArgumentException("Unknown [" + this.name + "] type [" + type + "]"); diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java b/core/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java index bf745905e2a..acad2753f7a 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java @@ -19,44 +19,33 @@ package org.elasticsearch.repositories; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; import org.elasticsearch.action.admin.cluster.snapshots.status.TransportNodesSnapshotsStatus; import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Module; +import org.elasticsearch.index.snapshots.IndexShardRepository; +import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; import org.elasticsearch.repositories.fs.FsRepository; -import org.elasticsearch.repositories.fs.FsRepositoryModule; import org.elasticsearch.repositories.uri.URLRepository; -import org.elasticsearch.repositories.uri.URLRepositoryModule; import org.elasticsearch.snapshots.RestoreService; -import org.elasticsearch.snapshots.SnapshotsService; import org.elasticsearch.snapshots.SnapshotShardsService; - -import java.util.Map; +import org.elasticsearch.snapshots.SnapshotsService; /** - * Module responsible for registering other repositories. - *

- * Repositories implemented as plugins should implement {@code onModule(RepositoriesModule module)} method, in which - * they should register repository using {@link #registerRepository(String, Class)} method. + * Sets up classes for Snapshot/Restore. + * + * Plugins can add custom repository types by calling {@link #registerRepository(String, Class, Class)}. */ public class RepositoriesModule extends AbstractModule { - private Map> repositoryTypes = Maps.newHashMap(); + private final RepositoryTypesRegistry repositoryTypes = new RepositoryTypesRegistry(); public RepositoriesModule() { - registerRepository(FsRepository.TYPE, FsRepositoryModule.class); - registerRepository(URLRepository.TYPE, URLRepositoryModule.class); + registerRepository(FsRepository.TYPE, FsRepository.class, BlobStoreIndexShardRepository.class); + registerRepository(URLRepository.TYPE, URLRepository.class, BlobStoreIndexShardRepository.class); } - /** - * Registers a custom repository type name against a module. - * - * @param type The type - * @param module The module - */ - public void registerRepository(String type, Class module) { - repositoryTypes.put(type, module); + /** Registers a custom repository type to the given {@link Repository} and {@link IndexShardRepository}. */ + public void registerRepository(String type, Class repositoryType, Class shardRepositoryType) { + repositoryTypes.registerRepository(type, repositoryType, shardRepositoryType); } @Override @@ -66,6 +55,6 @@ public class RepositoriesModule extends AbstractModule { bind(SnapshotShardsService.class).asEagerSingleton(); bind(TransportNodesSnapshotsStatus.class).asEagerSingleton(); bind(RestoreService.class).asEagerSingleton(); - bind(RepositoryTypesRegistry.class).toInstance(new RepositoryTypesRegistry(ImmutableMap.copyOf(repositoryTypes))); + bind(RepositoryTypesRegistry.class).toInstance(repositoryTypes); } } diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoryModule.java b/core/src/main/java/org/elasticsearch/repositories/RepositoryModule.java index 2dccc2b0186..eca82cc78e8 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoryModule.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoryModule.java @@ -19,7 +19,6 @@ package org.elasticsearch.repositories; -import com.google.common.collect.ImmutableList; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Modules; @@ -29,12 +28,10 @@ import org.elasticsearch.common.settings.Settings; import java.util.Arrays; import java.util.Collections; -import static org.elasticsearch.common.Strings.toCamelCase; - /** - * This module spawns specific repository module + * Binds repository classes for the specific repository type. */ -public class RepositoryModule extends AbstractModule implements SpawnModules { +public class RepositoryModule extends AbstractModule { private RepositoryName repositoryName; @@ -59,28 +56,12 @@ public class RepositoryModule extends AbstractModule implements SpawnModules { this.typesRegistry = typesRegistry; } - /** - * Returns repository module. - *

- * First repository type is looked up in typesRegistry and if it's not found there, this module tries to - * load repository by it's class name. - * - * @return repository module - */ - @Override - public Iterable spawnModules() { - Class repoModuleClass = typesRegistry.type(repositoryName.type()); - if (repoModuleClass == null) { - throw new IllegalArgumentException("Could not find repository type [" + repositoryName.getType() + "] for repository [" + repositoryName.getName() + "]"); - } - return Collections.unmodifiableList(Arrays.asList(Modules.createModule(repoModuleClass, globalSettings))); - } - /** * {@inheritDoc} */ @Override protected void configure() { + typesRegistry.bindType(binder(), repositoryName.type()); bind(RepositorySettings.class).toInstance(new RepositorySettings(globalSettings, settings)); } } diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java b/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java index 1322b65203d..b1e3041e746 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java @@ -19,31 +19,29 @@ package org.elasticsearch.repositories; -import com.google.common.collect.ImmutableMap; -import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.inject.Binder; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.ExtensionPoint; +import org.elasticsearch.index.snapshots.IndexShardRepository; /** - * Map of registered repository types and associated with these types modules + * A mapping from type name to implementations of {@link Repository} and {@link IndexShardRepository}. */ public class RepositoryTypesRegistry { - private final ImmutableMap> repositoryTypes; + // invariant: repositories and shardRepositories have the same keyset + private final ExtensionPoint.TypeExtensionPoint repositoryTypes = + new ExtensionPoint.TypeExtensionPoint<>("repository", Repository.class); + private final ExtensionPoint.TypeExtensionPoint shardRepositoryTypes = + new ExtensionPoint.TypeExtensionPoint<>("index_repository", IndexShardRepository.class); - /** - * Creates new repository with given map of types - * - * @param repositoryTypes - */ - public RepositoryTypesRegistry(ImmutableMap> repositoryTypes) { - this.repositoryTypes = repositoryTypes; + public void registerRepository(String name, Class repositoryType, Class shardRepositoryType) { + repositoryTypes.registerExtension(name, repositoryType); + shardRepositoryTypes.registerExtension(name, shardRepositoryType); } - /** - * Returns repository module class for the given type - * - * @param type repository type - * @return repository module class or null if type is not found - */ - public Class type(String type) { - return repositoryTypes.get(type); + public void bindType(Binder binder, String type) { + Settings settings = Settings.builder().put("type", type).build(); + repositoryTypes.bindType(binder, settings, "type", null); + shardRepositoryTypes.bindType(binder, settings, "type", null); } } diff --git a/core/src/main/java/org/elasticsearch/repositories/fs/FsRepositoryModule.java b/core/src/main/java/org/elasticsearch/repositories/fs/FsRepositoryModule.java deleted file mode 100644 index 2b8a4f4c15a..00000000000 --- a/core/src/main/java/org/elasticsearch/repositories/fs/FsRepositoryModule.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.repositories.fs; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.index.snapshots.IndexShardRepository; -import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; -import org.elasticsearch.repositories.Repository; - -/** - * File system repository module - */ -public class FsRepositoryModule extends AbstractModule { - - public FsRepositoryModule() { - super(); - } - - /** - * {@inheritDoc} - */ - @Override - protected void configure() { - bind(Repository.class).to(FsRepository.class).asEagerSingleton(); - bind(IndexShardRepository.class).to(BlobStoreIndexShardRepository.class).asEagerSingleton(); - } - -} - diff --git a/core/src/main/java/org/elasticsearch/repositories/uri/URLRepositoryModule.java b/core/src/main/java/org/elasticsearch/repositories/uri/URLRepositoryModule.java deleted file mode 100644 index 949a1b77f2c..00000000000 --- a/core/src/main/java/org/elasticsearch/repositories/uri/URLRepositoryModule.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.repositories.uri; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.index.snapshots.IndexShardRepository; -import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; -import org.elasticsearch.repositories.Repository; - -/** - * URL repository module - */ -public class URLRepositoryModule extends AbstractModule { - - public URLRepositoryModule() { - super(); - } - - /** - * {@inheritDoc} - */ - @Override - protected void configure() { - bind(Repository.class).to(URLRepository.class).asEagerSingleton(); - bind(IndexShardRepository.class).to(BlobStoreIndexShardRepository.class).asEagerSingleton(); - } - -} - diff --git a/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java b/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java index 75e910f48dd..2544f14fa3d 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java +++ b/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java @@ -34,7 +34,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.repositories.RepositoriesService; import org.elasticsearch.snapshots.mockstore.MockRepository; -import org.elasticsearch.snapshots.mockstore.MockRepositoryPlugin; import org.elasticsearch.test.ESIntegTestCase; import java.io.IOException; @@ -57,7 +56,7 @@ public abstract class AbstractSnapshotIntegTestCase extends ESIntegTestCase { @Override protected Settings nodeSettings(int nodeOrdinal) { return settingsBuilder().put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", MockRepositoryPlugin.class.getName()).build(); + .extendArray("plugin.types", MockRepository.Plugin.class.getName()).build(); } public static long getFailureCount(String repository) { diff --git a/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index fa0ebdec5a0..23ea847e2b1 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -24,7 +24,6 @@ import com.carrotsearch.hppc.IntSet; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.ListenableFuture; - import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.ListenableActionFuture; import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; @@ -41,8 +40,8 @@ import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ProcessedClusterStateUpdateTask; -import org.elasticsearch.cluster.metadata.MetaData.Custom; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.cluster.metadata.MetaData.Custom; import org.elasticsearch.cluster.metadata.MetaDataIndexStateService; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; import org.elasticsearch.common.Nullable; @@ -64,11 +63,9 @@ import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.admin.cluster.repositories.get.RestGetRepositoriesAction; import org.elasticsearch.rest.action.admin.cluster.state.RestClusterStateAction; -import org.elasticsearch.snapshots.mockstore.MockRepositoryModule; -import org.elasticsearch.snapshots.mockstore.MockRepositoryPlugin; +import org.elasticsearch.snapshots.mockstore.MockRepository; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.rest.FakeRestRequest; -import org.junit.Ignore; import org.junit.Test; import java.io.IOException; @@ -88,7 +85,15 @@ import static org.elasticsearch.test.ESIntegTestCase.Scope; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertBlocked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.lessThan; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; /** */ @@ -615,7 +620,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest @Test public void registrationFailureTest() { logger.info("--> start first node"); - internalCluster().startNode(settingsBuilder().put("plugin.types", MockRepositoryPlugin.class.getName())); + internalCluster().startNode(settingsBuilder().put("plugin.types", MockRepository.Plugin.class.getName())); logger.info("--> start second node"); // Make sure the first node is elected as master internalCluster().startNode(settingsBuilder().put("node.master", false)); @@ -634,7 +639,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest @Test public void testThatSensitiveRepositorySettingsAreNotExposed() throws Exception { - Settings nodeSettings = settingsBuilder().put("plugin.types", MockRepositoryPlugin.class.getName()).build(); + Settings nodeSettings = settingsBuilder().put("plugin.types", MockRepository.Plugin.class.getName()).build(); logger.info("--> start two nodes"); internalCluster().startNodesAsync(2, nodeSettings).get(); // Register mock repositories diff --git a/core/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java b/core/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java index 27a67588df9..c5221d12f3b 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java +++ b/core/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java @@ -32,15 +32,12 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.repositories.RepositoryException; import org.elasticsearch.repositories.RepositoryVerificationException; -import org.elasticsearch.snapshots.mockstore.MockRepositoryModule; -import org.elasticsearch.snapshots.mockstore.MockRepositoryPlugin; import org.elasticsearch.test.ESIntegTestCase; import org.junit.Test; import java.nio.file.Path; import java.util.List; -import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows; import static org.hamcrest.Matchers.containsString; diff --git a/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java index df7eb4e3b9b..d89eea7206a 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -64,7 +64,6 @@ import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.IndexStore; import org.elasticsearch.indices.InvalidIndexNameException; import org.elasticsearch.repositories.RepositoriesService; -import org.elasticsearch.snapshots.mockstore.MockRepositoryModule; import org.elasticsearch.test.junit.annotations.TestLogging; import org.junit.Test; diff --git a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java index 12e51475c9d..c346e5817bc 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java +++ b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java @@ -19,10 +19,8 @@ package org.elasticsearch.snapshots.mockstore; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.SnapshotId; @@ -30,11 +28,17 @@ import org.elasticsearch.common.blobstore.BlobContainer; import org.elasticsearch.common.blobstore.BlobMetaData; import org.elasticsearch.common.blobstore.BlobPath; import org.elasticsearch.common.blobstore.BlobStore; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.env.Environment; import org.elasticsearch.index.snapshots.IndexShardRepository; +import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; +import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.repositories.RepositoryName; import org.elasticsearch.repositories.RepositorySettings; import org.elasticsearch.repositories.fs.FsRepository; @@ -46,6 +50,10 @@ import java.io.UnsupportedEncodingException; import java.nio.file.Path; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -54,10 +62,48 @@ import java.util.concurrent.atomic.AtomicLong; import static org.elasticsearch.common.settings.Settings.settingsBuilder; -/** - */ public class MockRepository extends FsRepository { + public static class Plugin extends AbstractPlugin { + + @Override + public String name() { + return "mock-repository"; + } + + @Override + public String description() { + return "Mock Repository"; + } + + public void onModule(RepositoriesModule repositoriesModule) { + repositoriesModule.registerRepository("mock", MockRepository.class, BlobStoreIndexShardRepository.class); + } + + @Override + public Collection> modules() { + Collection> modules = new ArrayList<>(); + modules.add(SettingsFilteringModule.class); + return modules; + } + + public static class SettingsFilteringModule extends AbstractModule { + + @Override + protected void configure() { + bind(SettingsFilteringService.class).asEagerSingleton(); + } + } + + public static class SettingsFilteringService { + @Inject + public SettingsFilteringService(SettingsFilter settingsFilter) { + settingsFilter.addFilter("secret.mock.password"); + } + } + + } + private final AtomicLong failureCounter = new AtomicLong(); public long getFailureCount() { diff --git a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryModule.java b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryModule.java deleted file mode 100644 index 0da50f15d61..00000000000 --- a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryModule.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.snapshots.mockstore; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.index.snapshots.IndexShardRepository; -import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; -import org.elasticsearch.repositories.Repository; - -/** - */ -public class MockRepositoryModule extends AbstractModule { - - public MockRepositoryModule() { - super(); - } - - @Override - protected void configure() { - bind(Repository.class).to(MockRepository.class).asEagerSingleton(); - bind(IndexShardRepository.class).to(BlobStoreIndexShardRepository.class).asEagerSingleton(); - } - -} - diff --git a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java deleted file mode 100644 index a09c8601f7f..00000000000 --- a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.snapshots.mockstore; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.settings.SettingsFilter; -import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.repositories.RepositoriesModule; - -import java.util.Collection; - -import static com.google.common.collect.Lists.newArrayList; - -public class MockRepositoryPlugin extends AbstractPlugin { - - @Override - public String name() { - return "mock-repository"; - } - - @Override - public String description() { - return "Mock Repository"; - } - - public void onModule(RepositoriesModule repositoriesModule) { - repositoriesModule.registerRepository("mock", MockRepositoryModule.class); - } - - @Override - public Collection> modules() { - Collection> modules = newArrayList(); - modules.add(SettingsFilteringModule.class); - return modules; - } - - public static class SettingsFilteringModule extends AbstractModule { - - @Override - protected void configure() { - bind(SettingsFilteringService.class).asEagerSingleton(); - } - } - - public static class SettingsFilteringService { - @Inject - public SettingsFilteringService(SettingsFilter settingsFilter) { - settingsFilter.addFilter("secret.mock.password"); - } - } - -} diff --git a/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java b/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java index 4b16400897f..55a0ae51fb1 100644 --- a/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java +++ b/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java @@ -26,10 +26,10 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.ec2.Ec2Discovery; +import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.repositories.s3.S3Repository; -import org.elasticsearch.repositories.s3.S3RepositoryModule; import java.util.ArrayList; import java.util.Collection; @@ -76,7 +76,7 @@ public class CloudAwsPlugin extends AbstractPlugin { public void onModule(RepositoriesModule repositoriesModule) { if (settings.getAsBoolean("cloud.enabled", true)) { - repositoriesModule.registerRepository(S3Repository.TYPE, S3RepositoryModule.class); + repositoriesModule.registerRepository(S3Repository.TYPE, S3Repository.class, BlobStoreIndexShardRepository.class); } } diff --git a/plugins/cloud-aws/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryModule.java b/plugins/cloud-aws/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryModule.java deleted file mode 100644 index 6d51d61fde2..00000000000 --- a/plugins/cloud-aws/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryModule.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.repositories.s3; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.index.snapshots.IndexShardRepository; -import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; -import org.elasticsearch.repositories.Repository; - -/** - * S3 repository module - */ -public class S3RepositoryModule extends AbstractModule { - - public S3RepositoryModule() { - super(); - } - - /** - * {@inheritDoc} - */ - @Override - protected void configure() { - bind(Repository.class).to(S3Repository.class).asEagerSingleton(); - bind(IndexShardRepository.class).to(BlobStoreIndexShardRepository.class).asEagerSingleton(); - } -} - diff --git a/plugins/cloud-azure/src/main/java/org/elasticsearch/cloud/azure/AzureModule.java b/plugins/cloud-azure/src/main/java/org/elasticsearch/cloud/azure/AzureModule.java index eec355af760..29d260ff97a 100644 --- a/plugins/cloud-azure/src/main/java/org/elasticsearch/cloud/azure/AzureModule.java +++ b/plugins/cloud-azure/src/main/java/org/elasticsearch/cloud/azure/AzureModule.java @@ -27,6 +27,7 @@ import org.elasticsearch.cloud.azure.management.AzureComputeSettingsFilter; import org.elasticsearch.cloud.azure.storage.AzureStorageService; import org.elasticsearch.cloud.azure.storage.AzureStorageService.Storage; import org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl; +import org.elasticsearch.cloud.azure.storage.AzureStorageSettingsFilter; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; @@ -73,6 +74,7 @@ public class AzureModule extends AbstractModule { @Override protected void configure() { logger.debug("starting azure services"); + bind(AzureStorageSettingsFilter.class).asEagerSingleton(); bind(AzureComputeSettingsFilter.class).asEagerSingleton(); // If we have set discovery to azure, let's start the azure compute service diff --git a/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java b/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java index e3b5b455584..f60f05da8c3 100644 --- a/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java +++ b/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java @@ -26,13 +26,13 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.azure.AzureDiscovery; +import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.index.store.smbmmapfs.SmbMmapFsIndexStore; import org.elasticsearch.index.store.smbsimplefs.SmbSimpleFsIndexStore; import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.repositories.azure.AzureRepository; -import org.elasticsearch.repositories.azure.AzureRepositoryModule; import java.util.ArrayList; import java.util.Collection; @@ -71,11 +71,9 @@ public class CloudAzurePlugin extends AbstractPlugin { return modules; } - @Override - public void processModule(Module module) { - if (isSnapshotReady(settings, logger) - && module instanceof RepositoriesModule) { - ((RepositoriesModule)module).registerRepository(AzureRepository.TYPE, AzureRepositoryModule.class); + public void onModule(RepositoriesModule module) { + if (isSnapshotReady(settings, logger)) { + module.registerRepository(AzureRepository.TYPE, AzureRepository.class, BlobStoreIndexShardRepository.class); } } diff --git a/plugins/cloud-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryModule.java b/plugins/cloud-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryModule.java deleted file mode 100644 index 11d420b1b07..00000000000 --- a/plugins/cloud-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryModule.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.repositories.azure; - -import org.elasticsearch.cloud.azure.AzureModule; -import org.elasticsearch.cloud.azure.storage.AzureStorageSettingsFilter; -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.snapshots.IndexShardRepository; -import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; -import org.elasticsearch.repositories.Repository; - -/** - * Azure repository module - */ -public class AzureRepositoryModule extends AbstractModule { - - protected final ESLogger logger; - private Settings settings; - - public AzureRepositoryModule(Settings settings) { - super(); - this.logger = Loggers.getLogger(getClass(), settings); - this.settings = settings; - } - - /** - * {@inheritDoc} - */ - @Override - protected void configure() { - bind(AzureStorageSettingsFilter.class).asEagerSingleton(); - if (AzureModule.isSnapshotReady(settings, logger)) { - bind(Repository.class).to(AzureRepository.class).asEagerSingleton(); - bind(IndexShardRepository.class).to(BlobStoreIndexShardRepository.class).asEagerSingleton(); - } else { - logger.debug("disabling azure snapshot and restore features"); - } - } - -} - From 2e90be77ff952407355bc630380fc62c297a5cd3 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 17 Aug 2015 17:01:00 -0700 Subject: [PATCH 05/54] Plugins: Ensure additionalSettings() do not conflict Plugins can preovide additional settings to be added to the settings provided in elasticsearch.yml. However, if two different plugins supply the same setting key, the last one to be loaded wins, which is indeterminate. This change enforces plugins cannot have conflicting settings, at startup time. As a followup, we should do this when installing plugins as well, to give earlier errors when two plugins collide. --- .../elasticsearch/plugins/PluginsService.java | 11 ++- .../plugins/PluginsServiceTests.java | 85 +++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java index 762d497e832..1947953c35d 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -202,9 +202,18 @@ public class PluginsService extends AbstractComponent { } public Settings updatedSettings() { + Map foundSettings = new HashMap<>(); final Settings.Builder builder = Settings.settingsBuilder(); for (Tuple plugin : plugins) { - builder.put(plugin.v2().additionalSettings()); + Settings settings = plugin.v2().additionalSettings(); + for (String setting : settings.getAsMap().keySet()) { + String oldPlugin = foundSettings.put(setting, plugin.v1().getName()); + if (oldPlugin != null) { + throw new IllegalArgumentException("Cannot have additional setting [" + setting + "] " + + "in plugin " + plugin.v1().getName() + ", already added in plugin " + oldPlugin); + } + } + builder.put(settings); } return builder.put(this.settings).build(); } diff --git a/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java b/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java new file mode 100644 index 00000000000..5b0ea2d4eb3 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java @@ -0,0 +1,85 @@ +/* + * 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.plugins; + +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; +import org.elasticsearch.index.store.IndexStoreModule; +import org.elasticsearch.test.ESTestCase; + +public class PluginsServiceTests extends ESTestCase { + public static class AdditionalSettingsPlugin1 extends AbstractPlugin { + @Override + public String name() { + return "additional-settings1"; + } + @Override + public String description() { + return "adds additional setting 'foo.bar'"; + } + @Override + public Settings additionalSettings() { + return Settings.builder().put("foo.bar", "1").put(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.MMAPFS.getSettingsKey()).build(); + } + } + public static class AdditionalSettingsPlugin2 extends AbstractPlugin { + @Override + public String name() { + return "additional-settings2"; + } + @Override + public String description() { + return "adds additional setting 'foo.bar'"; + } + @Override + public Settings additionalSettings() { + return Settings.builder().put("foo.bar", "2").build(); + } + } + + public void testAdditionalSettings() { + Settings settings = Settings.builder() + .put("path.home", createTempDir()) + .put("my.setting", "test") + .put(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.SIMPLEFS.getSettingsKey()) + .putArray("plugin.types", AdditionalSettingsPlugin1.class.getName()).build(); + PluginsService service = new PluginsService(settings, new Environment(settings)); + Settings newSettings = service.updatedSettings(); + assertEquals("test", newSettings.get("my.setting")); // previous settings still exist + assertEquals("1", newSettings.get("foo.bar")); // added setting exists + assertEquals(IndexStoreModule.Type.SIMPLEFS.getSettingsKey(), newSettings.get(IndexStoreModule.STORE_TYPE)); // does not override pre existing settings + } + + public void testAdditionalSettingsClash() { + Settings settings = Settings.builder() + .put("path.home", createTempDir()) + .putArray("plugin.types", AdditionalSettingsPlugin1.class.getName(), AdditionalSettingsPlugin2.class.getName()).build(); + PluginsService service = new PluginsService(settings, new Environment(settings)); + try { + service.updatedSettings(); + fail("Expected exception when building updated settings"); + } catch (IllegalArgumentException e) { + String msg = e.getMessage(); + assertTrue(msg, msg.contains("Cannot have additional setting [foo.bar]")); + assertTrue(msg, msg.contains("plugin additional-settings1")); + assertTrue(msg, msg.contains("plugin additional-settings2")); + } + } +} From 2bf84593e01ca3d0ba7f598a3b0f0adf2c32cb6f Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 17 Aug 2015 20:11:38 -0700 Subject: [PATCH 06/54] Plugins: Simplify Plugin API for constructing modules The Plugin interface currently contains 6 different methods for adding modules. Elasticsearch has 3 different levels of injectors, and for each of those, there are two methods. The first takes no arguments and returns a collection of class objects to construct. The second takes a Settings object and returns a collection of module objects already constructed. The settings argument is unecessary because the plugin can already get the settings from its constructor. Removing that, the only difference between the two versions is returning an already constructed Module, or a module Class, and there is no reason the plugin can't construct all their modules themselves. This change reduces the plugin api down to just 3 methods for adding modules. Each returns a Collection. It also removes the processModule method, which was unnecessary since onModule implementations fullfill the same requirement. And finally, it renames the modules() method to nodeModules() so it is clear these are created once for each node. --- .../client/transport/TransportClient.java | 2 +- .../java/org/elasticsearch/node/Node.java | 6 +- .../elasticsearch/plugins/AbstractPlugin.java | 57 ++++------------- .../plugins/IndexPluginsModule.java | 14 +--- .../org/elasticsearch/plugins/Plugin.java | 38 ++--------- .../elasticsearch/plugins/PluginsModule.java | 14 +--- .../elasticsearch/plugins/PluginsService.java | 41 +++--------- .../plugins/ShardsPluginsModule.java | 14 +--- .../org/elasticsearch/plugins/SitePlugin.java | 64 +------------------ .../cluster/ClusterServiceIT.java | 2 +- .../cluster/settings/SettingsFilteringIT.java | 7 +- .../externalvalues/ExternalMapperPlugin.java | 13 +--- .../index/shard/MockEngineFactoryPlugin.java | 9 +-- .../indices/analysis/DummyAnalysisPlugin.java | 6 +- .../script/CustomScriptContextIT.java | 12 ++-- .../mockstore/MockRepositoryPlugin.java | 7 +- .../ContextAndHeaderTransportIT.java | 6 +- .../analysis/icu/AnalysisICUPlugin.java | 7 +- .../kuromoji/AnalysisKuromojiPlugin.java | 17 +++-- .../smartcn/AnalysisSmartChinesePlugin.java | 7 +- .../stempel/AnalysisStempelPlugin.java | 6 +- .../plugin/cloud/aws/CloudAwsPlugin.java | 4 +- .../plugin/cloud/azure/CloudAzurePlugin.java | 15 ++--- .../plugin/cloud/gce/CloudGcePlugin.java | 9 +-- .../deletebyquery/DeleteByQueryPlugin.java | 7 +- .../plugin/example/JvmExamplePlugin.java | 34 ++-------- .../plugin/mapper/MapperSizePlugin.java | 4 +- 27 files changed, 100 insertions(+), 322 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java index be609e44fa1..5ae074a1027 100644 --- a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -260,7 +260,7 @@ public class TransportClient extends AbstractClient { // ignore, might not be bounded } - for (Class plugin : injector.getInstance(PluginsService.class).services()) { + for (Class plugin : injector.getInstance(PluginsService.class).nodeServices()) { injector.getInstance(plugin).close(); } try { diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 7b9ed73bd3d..45e5522a22c 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -230,7 +230,7 @@ public class Node implements Releasable { // hack around dependency injection problem (for now...) injector.getInstance(Discovery.class).setRoutingService(injector.getInstance(RoutingService.class)); - for (Class plugin : pluginsService.services()) { + for (Class plugin : pluginsService.nodeServices()) { injector.getInstance(plugin).start(); } @@ -297,7 +297,7 @@ public class Node implements Releasable { injector.getInstance(RestController.class).stop(); injector.getInstance(TransportService.class).stop(); - for (Class plugin : pluginsService.services()) { + for (Class plugin : pluginsService.nodeServices()) { injector.getInstance(plugin).stop(); } // we should stop this last since it waits for resources to get released @@ -364,7 +364,7 @@ public class Node implements Releasable { stopWatch.stop().start("percolator_service"); injector.getInstance(PercolatorService.class).close(); - for (Class plugin : pluginsService.services()) { + for (Class plugin : pluginsService.nodeServices()) { stopWatch.stop().start("plugin(" + plugin.getName() + ")"); injector.getInstance(plugin).close(); } diff --git a/core/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java b/core/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java index 0beff2444c5..7ff2fce143e 100644 --- a/core/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java +++ b/core/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java @@ -19,20 +19,16 @@ package org.elasticsearch.plugins; -import com.google.common.collect.ImmutableList; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; import java.io.Closeable; import java.util.Collection; +import java.util.Collections; /** - * A base class for a plugin. - *

- * A plugin can be dynamically injected with {@link Module} by implementing onModule(AnyModule) method - * removing the need to override {@link #processModule(org.elasticsearch.common.inject.Module)} and check using - * instanceof. + * A base class for a plugin which returns no services or modules. */ public abstract class AbstractPlugin implements Plugin { @@ -40,40 +36,24 @@ public abstract class AbstractPlugin implements Plugin { * Defaults to return an empty list. */ @Override - public Collection> modules() { - return ImmutableList.of(); + public Collection nodeModules() { + return Collections.emptyList(); } /** * Defaults to return an empty list. */ @Override - public Collection modules(Settings settings) { - return ImmutableList.of(); + public Collection> nodeServices() { + return Collections.emptyList(); } /** * Defaults to return an empty list. */ @Override - public Collection> services() { - return ImmutableList.of(); - } - - /** - * Defaults to return an empty list. - */ - @Override - public Collection> indexModules() { - return ImmutableList.of(); - } - - /** - * Defaults to return an empty list. - */ - @Override - public Collection indexModules(Settings settings) { - return ImmutableList.of(); + public Collection indexModules() { + return Collections.emptyList(); } /** @@ -81,23 +61,15 @@ public abstract class AbstractPlugin implements Plugin { */ @Override public Collection> indexServices() { - return ImmutableList.of(); + return Collections.emptyList(); } /** * Defaults to return an empty list. */ @Override - public Collection> shardModules() { - return ImmutableList.of(); - } - - /** - * Defaults to return an empty list. - */ - @Override - public Collection shardModules(Settings settings) { - return ImmutableList.of(); + public Collection shardModules() { + return Collections.emptyList(); } /** @@ -105,12 +77,7 @@ public abstract class AbstractPlugin implements Plugin { */ @Override public Collection> shardServices() { - return ImmutableList.of(); - } - - @Override - public void processModule(Module module) { - // nothing to do here + return Collections.emptyList(); } @Override diff --git a/core/src/main/java/org/elasticsearch/plugins/IndexPluginsModule.java b/core/src/main/java/org/elasticsearch/plugins/IndexPluginsModule.java index d9f35aedd52..ad51b39c8f2 100644 --- a/core/src/main/java/org/elasticsearch/plugins/IndexPluginsModule.java +++ b/core/src/main/java/org/elasticsearch/plugins/IndexPluginsModule.java @@ -19,18 +19,12 @@ package org.elasticsearch.plugins; -import com.google.common.collect.Lists; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.PreProcessModule; import org.elasticsearch.common.inject.SpawnModules; import org.elasticsearch.common.settings.Settings; -import java.util.Collection; -import java.util.List; - -import static org.elasticsearch.common.inject.Modules.createModule; - /** * */ @@ -47,13 +41,7 @@ public class IndexPluginsModule extends AbstractModule implements SpawnModules, @Override public Iterable spawnModules() { - List modules = Lists.newArrayList(); - Collection> modulesClasses = pluginsService.indexModules(); - for (Class moduleClass : modulesClasses) { - modules.add(createModule(moduleClass, settings)); - } - modules.addAll(pluginsService.indexModules(settings)); - return modules; + return pluginsService.indexModules(); } @Override diff --git a/core/src/main/java/org/elasticsearch/plugins/Plugin.java b/core/src/main/java/org/elasticsearch/plugins/Plugin.java index 0a459a55277..472bc2af6bb 100644 --- a/core/src/main/java/org/elasticsearch/plugins/Plugin.java +++ b/core/src/main/java/org/elasticsearch/plugins/Plugin.java @@ -29,9 +29,8 @@ import java.util.Collection; /** * An extension point allowing to plug in custom functionality. *

- * A plugin can be dynamically injected with {@link Module} by implementing onModule(AnyModule) method - * removing the need to override {@link #processModule(org.elasticsearch.common.inject.Module)} and check using - * instanceof. + * A plugin can be register custom extensions to builtin behavior by implementing onModule(AnyModule), + * and registering the extension with the given module. */ public interface Plugin { @@ -46,31 +45,19 @@ public interface Plugin { String description(); /** - * Node level modules (classes, will automatically be created). + * Node level modules. */ - Collection> modules(); - - /** - * Node level modules (instances) - * - * @param settings The node level settings. - */ - Collection modules(Settings settings); + Collection nodeModules(); /** * Node level services that will be automatically started/stopped/closed. */ - Collection> services(); + Collection> nodeServices(); /** * Per index modules. */ - Collection> indexModules(); - - /** - * Per index modules. - */ - Collection indexModules(Settings settings); + Collection indexModules(); /** * Per index services that will be automatically closed. @@ -80,24 +67,13 @@ public interface Plugin { /** * Per index shard module. */ - Collection> shardModules(); - - /** - * Per index shard module. - */ - Collection shardModules(Settings settings); + Collection shardModules(); /** * Per index shard service that will be automatically closed. */ Collection> shardServices(); - /** - * Process a specific module. Note, its simpler to implement a custom onModule(AnyModule module) - * method, which will be automatically be called by the relevant type. - */ - void processModule(Module module); - /** * Additional node settings loaded by the plugin. Note that settings that are explicit in the nodes settings can't be * overwritten with the additional settings. These settings added if they don't exist. diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginsModule.java b/core/src/main/java/org/elasticsearch/plugins/PluginsModule.java index baf9f591d2b..050a90140eb 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginsModule.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginsModule.java @@ -19,18 +19,12 @@ package org.elasticsearch.plugins; -import com.google.common.collect.Lists; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.PreProcessModule; import org.elasticsearch.common.inject.SpawnModules; import org.elasticsearch.common.settings.Settings; -import java.util.Collection; -import java.util.List; - -import static org.elasticsearch.common.inject.Modules.createModule; - /** * */ @@ -47,13 +41,7 @@ public class PluginsModule extends AbstractModule implements SpawnModules, PrePr @Override public Iterable spawnModules() { - List modules = Lists.newArrayList(); - Collection> modulesClasses = pluginsService.modules(); - for (Class moduleClass : modulesClasses) { - modules.add(createModule(moduleClass, settings)); - } - modules.addAll(pluginsService.modules(settings)); - return modules; + return pluginsService.nodeModules(); } @Override diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java index 762d497e832..838fda430dc 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -184,7 +184,6 @@ public class PluginsService extends AbstractComponent { public void processModule(Module module) { for (Tuple plugin : plugins()) { - plugin.v2().processModule(module); // see if there are onModule references List references = onModuleReferences.get(plugin.v2()); if (references != null) { @@ -209,42 +208,26 @@ public class PluginsService extends AbstractComponent { return builder.put(this.settings).build(); } - public Collection> modules() { - List> modules = new ArrayList<>(); - for (Tuple plugin : plugins) { - modules.addAll(plugin.v2().modules()); - } - return modules; - } - - public Collection modules(Settings settings) { + public Collection nodeModules() { List modules = new ArrayList<>(); for (Tuple plugin : plugins) { - modules.addAll(plugin.v2().modules(settings)); + modules.addAll(plugin.v2().nodeModules()); } return modules; } - public Collection> services() { + public Collection> nodeServices() { List> services = new ArrayList<>(); for (Tuple plugin : plugins) { - services.addAll(plugin.v2().services()); + services.addAll(plugin.v2().nodeServices()); } return services; } - public Collection> indexModules() { - List> modules = new ArrayList<>(); - for (Tuple plugin : plugins) { - modules.addAll(plugin.v2().indexModules()); - } - return modules; - } - - public Collection indexModules(Settings settings) { + public Collection indexModules() { List modules = new ArrayList<>(); for (Tuple plugin : plugins) { - modules.addAll(plugin.v2().indexModules(settings)); + modules.addAll(plugin.v2().indexModules()); } return modules; } @@ -257,18 +240,10 @@ public class PluginsService extends AbstractComponent { return services; } - public Collection> shardModules() { - List> modules = new ArrayList<>(); - for (Tuple plugin : plugins) { - modules.addAll(plugin.v2().shardModules()); - } - return modules; - } - - public Collection shardModules(Settings settings) { + public Collection shardModules() { List modules = new ArrayList<>(); for (Tuple plugin : plugins) { - modules.addAll(plugin.v2().shardModules(settings)); + modules.addAll(plugin.v2().shardModules()); } return modules; } diff --git a/core/src/main/java/org/elasticsearch/plugins/ShardsPluginsModule.java b/core/src/main/java/org/elasticsearch/plugins/ShardsPluginsModule.java index b9e2178c6f3..b9e03a46cb9 100644 --- a/core/src/main/java/org/elasticsearch/plugins/ShardsPluginsModule.java +++ b/core/src/main/java/org/elasticsearch/plugins/ShardsPluginsModule.java @@ -19,18 +19,12 @@ package org.elasticsearch.plugins; -import com.google.common.collect.Lists; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.PreProcessModule; import org.elasticsearch.common.inject.SpawnModules; import org.elasticsearch.common.settings.Settings; -import java.util.Collection; -import java.util.List; - -import static org.elasticsearch.common.inject.Modules.createModule; - /** * */ @@ -47,13 +41,7 @@ public class ShardsPluginsModule extends AbstractModule implements SpawnModules, @Override public Iterable spawnModules() { - List modules = Lists.newArrayList(); - Collection> modulesClasses = pluginsService.shardModules(); - for (Class moduleClass : modulesClasses) { - modules.add(createModule(moduleClass, settings)); - } - modules.addAll(pluginsService.shardModules(settings)); - return modules; + return pluginsService.shardModules(); } @Override diff --git a/core/src/main/java/org/elasticsearch/plugins/SitePlugin.java b/core/src/main/java/org/elasticsearch/plugins/SitePlugin.java index 0f49764bbb2..4bb8008551e 100644 --- a/core/src/main/java/org/elasticsearch/plugins/SitePlugin.java +++ b/core/src/main/java/org/elasticsearch/plugins/SitePlugin.java @@ -19,16 +19,8 @@ package org.elasticsearch.plugins; -import org.elasticsearch.common.component.LifecycleComponent; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.settings.Settings; - -import java.io.Closeable; -import java.util.Collection; -import java.util.Collections; - /** A site-only plugin, just serves resources */ -final class SitePlugin implements Plugin { +final class SitePlugin extends AbstractPlugin { final String name; final String description; @@ -46,58 +38,4 @@ final class SitePlugin implements Plugin { public String description() { return description; } - - @Override - public Collection> modules() { - return Collections.emptyList(); - } - - @Override - public Collection modules(Settings settings) { - return Collections.emptyList(); - } - - @Override - public Collection> services() { - return Collections.emptyList(); - } - - @Override - public Collection> indexModules() { - return Collections.emptyList(); - } - - @Override - public Collection indexModules(Settings settings) { - return Collections.emptyList(); - } - - @Override - public Collection> indexServices() { - return Collections.emptyList(); - } - - @Override - public Collection> shardModules() { - return Collections.emptyList(); - } - - @Override - public Collection shardModules(Settings settings) { - return Collections.emptyList(); - } - - @Override - public Collection> shardServices() { - return Collections.emptyList(); - } - - @Override - public void processModule(Module module) { - } - - @Override - public Settings additionalSettings() { - return Settings.EMPTY; - } } diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterServiceIT.java b/core/src/test/java/org/elasticsearch/cluster/ClusterServiceIT.java index a174215a174..8aa30d3990b 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterServiceIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterServiceIT.java @@ -1005,7 +1005,7 @@ public class ClusterServiceIT extends ESIntegTestCase { } @Override - public Collection> services() { + public Collection> nodeServices() { List> services = new ArrayList<>(1); services.add(MasterAwareService.class); return services; diff --git a/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java b/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java index 8b3b871113e..a2d741a1993 100644 --- a/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java @@ -31,6 +31,7 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.junit.Test; import java.util.Collection; +import java.util.Collections; import static com.google.common.collect.Lists.newArrayList; import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; @@ -67,10 +68,8 @@ public class SettingsFilteringIT extends ESIntegTestCase { } @Override - public Collection> indexModules() { - Collection> modules = newArrayList(); - modules.add(SettingsFilteringModule.class); - return modules; + public Collection indexModules() { + return Collections.singletonList(new SettingsFilteringModule()); } } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapperPlugin.java b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapperPlugin.java index d9821af6382..d6104b51cad 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapperPlugin.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapperPlugin.java @@ -23,30 +23,23 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.plugins.AbstractPlugin; import java.util.Collection; +import java.util.Collections; import static com.google.common.collect.Lists.newArrayList; public class ExternalMapperPlugin extends AbstractPlugin { - /** - * The name of the plugin. - */ @Override public String name() { return "external-mappers"; } - /** - * The description of the plugin. - */ @Override public String description() { return "External Mappers Plugin"; } @Override - public Collection> indexModules() { - Collection> modules = newArrayList(); - modules.add(ExternalIndexModule.class); - return modules; + public Collection indexModules() { + return Collections.singletonList(new ExternalIndexModule()); } } diff --git a/core/src/test/java/org/elasticsearch/index/shard/MockEngineFactoryPlugin.java b/core/src/test/java/org/elasticsearch/index/shard/MockEngineFactoryPlugin.java index 8ed60609683..ad0f820595a 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/MockEngineFactoryPlugin.java +++ b/core/src/test/java/org/elasticsearch/index/shard/MockEngineFactoryPlugin.java @@ -23,9 +23,8 @@ import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.test.engine.MockEngineFactory; import org.elasticsearch.test.engine.MockEngineSupportModule; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; +import java.util.Collections; // this must exist in the same package as IndexShardModule to allow access to setting the impl public class MockEngineFactoryPlugin extends AbstractPlugin { @@ -38,10 +37,8 @@ public class MockEngineFactoryPlugin extends AbstractPlugin { return "a mock engine factory for testing"; } @Override - public Collection> indexModules() { - List> modules = new ArrayList<>(); - modules.add(MockEngineSupportModule.class); - return modules; + public Collection indexModules() { + return Collections.singletonList(new MockEngineSupportModule()); } public void onModule(IndexShardModule module) { module.engineFactoryImpl = MockEngineFactory.class; diff --git a/core/src/test/java/org/elasticsearch/indices/analysis/DummyAnalysisPlugin.java b/core/src/test/java/org/elasticsearch/indices/analysis/DummyAnalysisPlugin.java index 55d22eb8c91..e9bda623969 100644 --- a/core/src/test/java/org/elasticsearch/indices/analysis/DummyAnalysisPlugin.java +++ b/core/src/test/java/org/elasticsearch/indices/analysis/DummyAnalysisPlugin.java @@ -19,12 +19,12 @@ package org.elasticsearch.indices.analysis; -import com.google.common.collect.ImmutableList; import org.elasticsearch.common.inject.Module; import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.plugins.AbstractPlugin; import java.util.Collection; +import java.util.Collections; public class DummyAnalysisPlugin extends AbstractPlugin { /** @@ -44,8 +44,8 @@ public class DummyAnalysisPlugin extends AbstractPlugin { } @Override - public Collection> modules() { - return ImmutableList.>of(DummyIndicesAnalysisModule.class); + public Collection nodeModules() { + return Collections.singletonList(new DummyIndicesAnalysisModule()); } public void onModule(AnalysisModule module) { diff --git a/core/src/test/java/org/elasticsearch/script/CustomScriptContextIT.java b/core/src/test/java/org/elasticsearch/script/CustomScriptContextIT.java index ef9c4e3ced4..fdf6a728c10 100644 --- a/core/src/test/java/org/elasticsearch/script/CustomScriptContextIT.java +++ b/core/src/test/java/org/elasticsearch/script/CustomScriptContextIT.java @@ -128,14 +128,10 @@ public class CustomScriptContextIT extends ESIntegTestCase { return "Custom script context plugin"; } - @Override - public void processModule(Module module) { - if (module instanceof ScriptModule) { - ScriptModule scriptModule = (ScriptModule) module; - scriptModule.registerScriptContext(new ScriptContext.Plugin(PLUGIN_NAME, "custom_op")); - scriptModule.registerScriptContext(new ScriptContext.Plugin(PLUGIN_NAME, "custom_exp_disabled_op")); - scriptModule.registerScriptContext(new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op")); - } + public void onModule(ScriptModule scriptModule) { + scriptModule.registerScriptContext(new ScriptContext.Plugin(PLUGIN_NAME, "custom_op")); + scriptModule.registerScriptContext(new ScriptContext.Plugin(PLUGIN_NAME, "custom_exp_disabled_op")); + scriptModule.registerScriptContext(new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op")); } } } diff --git a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java index a09c8601f7f..70471c574b1 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java +++ b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java @@ -27,6 +27,7 @@ import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.repositories.RepositoriesModule; import java.util.Collection; +import java.util.Collections; import static com.google.common.collect.Lists.newArrayList; @@ -47,10 +48,8 @@ public class MockRepositoryPlugin extends AbstractPlugin { } @Override - public Collection> modules() { - Collection> modules = newArrayList(); - modules.add(SettingsFilteringModule.class); - return modules; + public Collection nodeModules() { + return Collections.singletonList(new SettingsFilteringModule()); } public static class SettingsFilteringModule extends AbstractModule { diff --git a/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java b/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java index ff6a21b1cef..d433c955796 100644 --- a/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java +++ b/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java @@ -378,10 +378,8 @@ public class ContextAndHeaderTransportIT extends ESIntegTestCase { } @Override - public Collection> modules() { - Collection> classes = new ArrayList<>(); - classes.add(ActionLoggingModule.class); - return classes; + public Collection nodeModules() { + return Collections.singletonList(new ActionLoggingModule()); } } diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java index be73376fd24..12d535f46a6 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java @@ -27,6 +27,7 @@ import org.elasticsearch.plugins.AbstractPlugin; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; /** * @@ -44,10 +45,8 @@ public class AnalysisICUPlugin extends AbstractPlugin { } @Override - public Collection> modules() { - Collection> classes = new ArrayList<>(); - classes.add(IcuIndicesAnalysisModule.class); - return classes; + public Collection nodeModules() { + return Collections.singletonList(new IcuIndicesAnalysisModule()); } /** diff --git a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/plugin/analysis/kuromoji/AnalysisKuromojiPlugin.java b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/plugin/analysis/kuromoji/AnalysisKuromojiPlugin.java index 88d3cee3037..ac095e19852 100644 --- a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/plugin/analysis/kuromoji/AnalysisKuromojiPlugin.java +++ b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/plugin/analysis/kuromoji/AnalysisKuromojiPlugin.java @@ -20,12 +20,21 @@ package org.elasticsearch.plugin.analysis.kuromoji; import org.elasticsearch.common.inject.Module; -import org.elasticsearch.index.analysis.*; +import org.elasticsearch.index.analysis.AnalysisModule; +import org.elasticsearch.index.analysis.JapaneseStopTokenFilterFactory; +import org.elasticsearch.index.analysis.KuromojiAnalyzerProvider; +import org.elasticsearch.index.analysis.KuromojiBaseFormFilterFactory; +import org.elasticsearch.index.analysis.KuromojiIterationMarkCharFilterFactory; +import org.elasticsearch.index.analysis.KuromojiKatakanaStemmerFactory; +import org.elasticsearch.index.analysis.KuromojiPartOfSpeechFilterFactory; +import org.elasticsearch.index.analysis.KuromojiReadingFormFilterFactory; +import org.elasticsearch.index.analysis.KuromojiTokenizerFactory; import org.elasticsearch.indices.analysis.KuromojiIndicesAnalysisModule; import org.elasticsearch.plugins.AbstractPlugin; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; /** * @@ -43,10 +52,8 @@ public class AnalysisKuromojiPlugin extends AbstractPlugin { } @Override - public Collection> modules() { - Collection> classes = new ArrayList<>(); - classes.add(KuromojiIndicesAnalysisModule.class); - return classes; + public Collection nodeModules() { + return Collections.singletonList(new KuromojiIndicesAnalysisModule()); } public void onModule(AnalysisModule module) { diff --git a/plugins/analysis-smartcn/src/main/java/org/elasticsearch/plugin/analysis/smartcn/AnalysisSmartChinesePlugin.java b/plugins/analysis-smartcn/src/main/java/org/elasticsearch/plugin/analysis/smartcn/AnalysisSmartChinesePlugin.java index 08759e284c2..25491a6fbe4 100644 --- a/plugins/analysis-smartcn/src/main/java/org/elasticsearch/plugin/analysis/smartcn/AnalysisSmartChinesePlugin.java +++ b/plugins/analysis-smartcn/src/main/java/org/elasticsearch/plugin/analysis/smartcn/AnalysisSmartChinesePlugin.java @@ -27,6 +27,7 @@ import org.elasticsearch.plugins.AbstractPlugin; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; /** * @@ -44,10 +45,8 @@ public class AnalysisSmartChinesePlugin extends AbstractPlugin { } @Override - public Collection> modules() { - Collection> classes = new ArrayList<>(); - classes.add(SmartChineseIndicesAnalysisModule.class); - return classes; + public Collection nodeModules() { + return Collections.singletonList(new SmartChineseIndicesAnalysisModule()); } public void onModule(AnalysisModule module) { diff --git a/plugins/analysis-stempel/src/main/java/org/elasticsearch/plugin/analysis/stempel/AnalysisStempelPlugin.java b/plugins/analysis-stempel/src/main/java/org/elasticsearch/plugin/analysis/stempel/AnalysisStempelPlugin.java index 8f9fa7d3027..340382c77b5 100644 --- a/plugins/analysis-stempel/src/main/java/org/elasticsearch/plugin/analysis/stempel/AnalysisStempelPlugin.java +++ b/plugins/analysis-stempel/src/main/java/org/elasticsearch/plugin/analysis/stempel/AnalysisStempelPlugin.java @@ -43,10 +43,8 @@ public class AnalysisStempelPlugin extends AbstractPlugin { } @Override - public Collection> modules() { - Collection> classes = new ArrayList<>(); - classes.add(PolishIndicesAnalysisModule.class); - return classes; + public Collection nodeModules() { + return Collections.singletonList(new PolishIndicesAnalysisModule()); } public void onModule(AnalysisModule module) { diff --git a/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java b/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java index 4b16400897f..a2ed9902a50 100644 --- a/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java +++ b/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java @@ -56,7 +56,7 @@ public class CloudAwsPlugin extends AbstractPlugin { } @Override - public Collection modules(Settings settings) { + public Collection nodeModules() { Collection modules = new ArrayList<>(); if (settings.getAsBoolean("cloud.enabled", true)) { modules.add(new AwsModule()); @@ -65,7 +65,7 @@ public class CloudAwsPlugin extends AbstractPlugin { } @Override - public Collection> services() { + public Collection> nodeServices() { Collection> services = new ArrayList<>(); if (settings.getAsBoolean("cloud.enabled", true)) { services.add(AwsModule.getS3ServiceImpl()); diff --git a/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java b/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java index e3b5b455584..d112f3c9738 100644 --- a/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java +++ b/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java @@ -36,6 +36,7 @@ import org.elasticsearch.repositories.azure.AzureRepositoryModule; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import static org.elasticsearch.cloud.azure.AzureModule.isSnapshotReady; @@ -63,20 +64,16 @@ public class CloudAzurePlugin extends AbstractPlugin { } @Override - public Collection> modules() { - Collection> modules = new ArrayList<>(); + public Collection nodeModules() { + List modules = new ArrayList<>(); if (AzureModule.isCloudReady(settings)) { - modules.add(AzureModule.class); + modules.add(new AzureModule(settings)); } return modules; } - @Override - public void processModule(Module module) { - if (isSnapshotReady(settings, logger) - && module instanceof RepositoriesModule) { - ((RepositoriesModule)module).registerRepository(AzureRepository.TYPE, AzureRepositoryModule.class); - } + public void onModule(RepositoriesModule module) { + module.registerRepository(AzureRepository.TYPE, AzureRepositoryModule.class); } public void onModule(DiscoveryModule discoveryModule) { diff --git a/plugins/cloud-gce/src/main/java/org/elasticsearch/plugin/cloud/gce/CloudGcePlugin.java b/plugins/cloud-gce/src/main/java/org/elasticsearch/plugin/cloud/gce/CloudGcePlugin.java index 465b68028d1..9eacfbe9cde 100644 --- a/plugins/cloud-gce/src/main/java/org/elasticsearch/plugin/cloud/gce/CloudGcePlugin.java +++ b/plugins/cloud-gce/src/main/java/org/elasticsearch/plugin/cloud/gce/CloudGcePlugin.java @@ -29,6 +29,7 @@ import org.elasticsearch.plugins.AbstractPlugin; import java.util.ArrayList; import java.util.Collection; +import java.util.List; /** * @@ -52,16 +53,16 @@ public class CloudGcePlugin extends AbstractPlugin { } @Override - public Collection> modules() { - Collection> modules = new ArrayList<>(); + public Collection nodeModules() { + List modules = new ArrayList<>(); if (settings.getAsBoolean("cloud.enabled", true)) { - modules.add(GceModule.class); + modules.add(new GceModule()); } return modules; } @Override - public Collection> services() { + public Collection> nodeServices() { Collection> services = new ArrayList<>(); if (settings.getAsBoolean("cloud.enabled", true)) { services.add(GceModule.getComputeServiceImpl()); diff --git a/plugins/delete-by-query/src/main/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryPlugin.java b/plugins/delete-by-query/src/main/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryPlugin.java index bcc13174ee7..84e15d364bf 100644 --- a/plugins/delete-by-query/src/main/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryPlugin.java +++ b/plugins/delete-by-query/src/main/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryPlugin.java @@ -20,11 +20,10 @@ package org.elasticsearch.plugin.deletebyquery; import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.AbstractPlugin; -import java.util.Arrays; import java.util.Collection; +import java.util.Collections; public class DeleteByQueryPlugin extends AbstractPlugin { @@ -41,7 +40,7 @@ public class DeleteByQueryPlugin extends AbstractPlugin { } @Override - public Collection modules(Settings settings) { - return Arrays.asList((Module) new DeleteByQueryModule()); + public Collection nodeModules() { + return Collections.singletonList(new DeleteByQueryModule()); } } diff --git a/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java b/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java index b67765a1951..292788f97a4 100644 --- a/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java +++ b/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.rest.action.cat.AbstractCatAction; @@ -56,31 +55,18 @@ public class JvmExamplePlugin implements Plugin { } @Override - public Collection> modules() { - Collection> modules = new ArrayList<>(); - modules.add(ConfiguredExampleModule.class); - return modules; + public Collection nodeModules() { + return Collections.singletonList(new ConfiguredExampleModule()); } @Override - public Collection modules(Settings settings) { - Collection modules = new ArrayList<>(); - return modules; - } - - @Override - public Collection> services() { + public Collection> nodeServices() { Collection> services = new ArrayList<>(); return services; } @Override - public Collection> indexModules() { - return Collections.emptyList(); - } - - @Override - public Collection indexModules(Settings settings) { + public Collection indexModules() { return Collections.emptyList(); } @@ -90,12 +76,7 @@ public class JvmExamplePlugin implements Plugin { } @Override - public Collection> shardModules() { - return Collections.emptyList(); - } - - @Override - public Collection shardModules(Settings settings) { + public Collection shardModules() { return Collections.emptyList(); } @@ -104,11 +85,6 @@ public class JvmExamplePlugin implements Plugin { return Collections.emptyList(); } - @Override - public void processModule(Module module) { - - } - @Override public Settings additionalSettings() { return Settings.EMPTY; diff --git a/plugins/mapper-size/src/main/java/org/elasticsearch/plugin/mapper/MapperSizePlugin.java b/plugins/mapper-size/src/main/java/org/elasticsearch/plugin/mapper/MapperSizePlugin.java index 20f52541eef..a89e9084962 100644 --- a/plugins/mapper-size/src/main/java/org/elasticsearch/plugin/mapper/MapperSizePlugin.java +++ b/plugins/mapper-size/src/main/java/org/elasticsearch/plugin/mapper/MapperSizePlugin.java @@ -38,8 +38,8 @@ public class MapperSizePlugin extends AbstractPlugin { } @Override - public Collection> indexModules() { - return Collections.>singleton(MapperSizeIndexModule.class); + public Collection indexModules() { + return Collections.singletonList(new MapperSizeIndexModule()); } } From dc1fa6736a5ecf7ef7b140cce33743ce42760f80 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 18 Aug 2015 02:46:32 -0700 Subject: [PATCH 07/54] Merged AbstractPlugin and Plugin. Also added Settings back to indexModules and shardModules --- .../elasticsearch/plugins/AbstractPlugin.java | 55 +------------------ .../plugins/IndexPluginsModule.java | 2 +- .../org/elasticsearch/plugins/Plugin.java | 35 ++++++++---- .../elasticsearch/plugins/PluginsService.java | 9 ++- .../plugins/ShardsPluginsModule.java | 2 +- .../org/elasticsearch/plugins/SitePlugin.java | 2 +- .../action/IndicesRequestIT.java | 6 +- .../expression/NativeScriptPlugin.java | 4 +- .../plugin/NativeScriptExamplesPlugin.java | 10 +++- .../cache/recycler/MockPageCacheRecycler.java | 2 - .../TransportClientHeadersTests.java | 18 ++++-- .../cluster/ClusterInfoServiceIT.java | 11 ++-- .../cluster/ClusterServiceIT.java | 18 ++++-- .../MockInternalClusterInfoService.java | 4 +- .../allocation/decider/MockDiskUsagesIT.java | 2 +- .../cluster/settings/SettingsFilteringIT.java | 6 +- .../common/util/MockBigArrays.java | 2 - .../DiscoveryWithServiceDisruptionsIT.java | 2 +- .../index/IndexWithShadowReplicasIT.java | 2 +- .../index/TransportIndexFailuresIT.java | 2 +- .../externalvalues/ExternalMapperPlugin.java | 9 ++- .../query/plugin/DummyQueryParserPlugin.java | 4 +- .../index/shard/MockEngineFactoryPlugin.java | 7 ++- .../index/store/CorruptedFileIT.java | 2 +- .../index/store/CorruptedTranslogIT.java | 2 +- .../index/store/ExceptionRetryIT.java | 2 +- .../indices/analysis/DummyAnalysisPlugin.java | 4 +- .../RandomExceptionCircuitBreakerIT.java | 6 +- .../indices/recovery/IndexRecoveryIT.java | 2 +- .../store/IndicesStoreIntegrationIT.java | 2 +- .../template/IndexTemplateFilteringIT.java | 4 +- .../elasticsearch/node/NodeMocksPlugin.java | 4 +- .../nodesinfo/plugin/dummy1/TestPlugin.java | 4 +- .../plugin/dummy2/TestNoVersionPlugin.java | 40 -------------- .../plugins/PluggableTransportModuleIT.java | 2 +- .../loading/classpath/InClassPathPlugin.java | 4 +- .../TestResponseHeaderPlugin.java | 4 +- .../elasticsearch/recovery/RelocationIT.java | 2 +- .../recovery/TruncatedRecoveryIT.java | 2 +- .../script/CustomScriptContextIT.java | 6 +- .../script/NativeScriptTests.java | 2 - .../elasticsearch/script/ScriptFieldIT.java | 4 +- .../search/MockSearchService.java | 5 +- .../SignificantTermsSignificanceScoreIT.java | 25 +++++++-- .../basic/SearchWithRandomExceptionsIT.java | 6 +- .../search/fetch/FetchSubPhasePluginIT.java | 4 +- .../ExplainableScriptPlugin.java | 4 +- .../functionscore/FunctionScorePluginIT.java | 4 +- .../highlight/CustomHighlighterPlugin.java | 4 +- .../search/suggest/CustomSuggesterPlugin.java | 4 +- .../mockstore/MockRepositoryPlugin.java | 6 +- .../test/InternalTestCluster.java | 8 +-- .../test/disruption/NetworkPartitionIT.java | 2 +- .../test/store/MockFSIndexStore.java | 4 +- .../transport/AssertingLocalTransport.java | 11 +++- .../test/transport/MockTransportService.java | 20 +++++-- .../ContextAndHeaderTransportIT.java | 34 +++++++++--- .../transport/netty/NettyTransportIT.java | 6 +- .../update/UpdateByNativeScriptIT.java | 7 +-- .../analysis/icu/AnalysisICUPlugin.java | 5 +- .../kuromoji/AnalysisKuromojiPlugin.java | 5 +- .../analysis/AnalysisPhoneticPlugin.java | 4 +- .../smartcn/AnalysisSmartChinesePlugin.java | 5 +- .../stempel/AnalysisStempelPlugin.java | 7 ++- .../plugin/cloud/aws/CloudAwsPlugin.java | 4 +- .../cloud/aws/AbstractAwsTest.java | 2 +- .../cloud/aws/TestAwsS3Service.java | 4 +- .../plugin/cloud/azure/CloudAzurePlugin.java | 6 +- .../AbstractAzureComputeServiceTest.java | 4 -- .../AbstractAzureRepositoryServiceTest.java | 6 +- .../azure/AzureComputeServiceSimpleMock.java | 10 +++- .../AzureComputeServiceTwoNodesMock.java | 4 +- .../azure/AzureMinimumMasterNodesTest.java | 2 +- .../discovery/azure/AzureSimpleTest.java | 2 +- .../azure/AzureTwoStartedNodesTest.java | 2 +- .../plugin/cloud/gce/CloudGcePlugin.java | 4 +- .../deletebyquery/DeleteByQueryPlugin.java | 4 +- .../example/ExamplePluginConfiguration.java | 13 +---- .../plugin/example/JvmExamplePlugin.java | 6 +- .../plugin/javascript/JavaScriptPlugin.java | 4 +- .../plugin/python/PythonPlugin.java | 4 +- .../plugin/mapper/MapperSizePlugin.java | 7 ++- 82 files changed, 274 insertions(+), 306 deletions(-) delete mode 100644 core/src/test/java/org/elasticsearch/nodesinfo/plugin/dummy2/TestNoVersionPlugin.java diff --git a/core/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java b/core/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java index 7ff2fce143e..e33a2774771 100644 --- a/core/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java +++ b/core/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java @@ -30,59 +30,6 @@ import java.util.Collections; /** * A base class for a plugin which returns no services or modules. */ -public abstract class AbstractPlugin implements Plugin { - - /** - * Defaults to return an empty list. - */ - @Override - public Collection nodeModules() { - return Collections.emptyList(); - } - - /** - * Defaults to return an empty list. - */ - @Override - public Collection> nodeServices() { - return Collections.emptyList(); - } - - /** - * Defaults to return an empty list. - */ - @Override - public Collection indexModules() { - return Collections.emptyList(); - } - - /** - * Defaults to return an empty list. - */ - @Override - public Collection> indexServices() { - return Collections.emptyList(); - } - - /** - * Defaults to return an empty list. - */ - @Override - public Collection shardModules() { - return Collections.emptyList(); - } - - /** - * Defaults to return an empty list. - */ - @Override - public Collection> shardServices() { - return Collections.emptyList(); - } - - @Override - public Settings additionalSettings() { - return Settings.Builder.EMPTY_SETTINGS; - } +public abstract class AbstractPlugin extends Plugin { } diff --git a/core/src/main/java/org/elasticsearch/plugins/IndexPluginsModule.java b/core/src/main/java/org/elasticsearch/plugins/IndexPluginsModule.java index ad51b39c8f2..a45f7d7a08e 100644 --- a/core/src/main/java/org/elasticsearch/plugins/IndexPluginsModule.java +++ b/core/src/main/java/org/elasticsearch/plugins/IndexPluginsModule.java @@ -41,7 +41,7 @@ public class IndexPluginsModule extends AbstractModule implements SpawnModules, @Override public Iterable spawnModules() { - return pluginsService.indexModules(); + return pluginsService.indexModules(settings); } @Override diff --git a/core/src/main/java/org/elasticsearch/plugins/Plugin.java b/core/src/main/java/org/elasticsearch/plugins/Plugin.java index 472bc2af6bb..986d397f6b6 100644 --- a/core/src/main/java/org/elasticsearch/plugins/Plugin.java +++ b/core/src/main/java/org/elasticsearch/plugins/Plugin.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.settings.Settings; import java.io.Closeable; import java.util.Collection; +import java.util.Collections; /** * An extension point allowing to plug in custom functionality. @@ -32,51 +33,65 @@ import java.util.Collection; * A plugin can be register custom extensions to builtin behavior by implementing onModule(AnyModule), * and registering the extension with the given module. */ -public interface Plugin { +public abstract class Plugin { /** * The name of the plugin. */ - String name(); + public abstract String name(); /** * The description of the plugin. */ - String description(); + public abstract String description(); /** * Node level modules. */ - Collection nodeModules(); + public Collection nodeModules() { + return Collections.emptyList(); + } /** * Node level services that will be automatically started/stopped/closed. */ - Collection> nodeServices(); + public Collection> nodeServices() { + return Collections.emptyList(); + } /** * Per index modules. */ - Collection indexModules(); + public Collection indexModules(Settings indexSettings) { + return Collections.emptyList(); + } /** * Per index services that will be automatically closed. */ - Collection> indexServices(); + public Collection> indexServices() { + return Collections.emptyList(); + } /** * Per index shard module. */ - Collection shardModules(); + public Collection shardModules(Settings indexSettings) { + return Collections.emptyList(); + } /** * Per index shard service that will be automatically closed. */ - Collection> shardServices(); + public Collection> shardServices() { + return Collections.emptyList(); + } /** * Additional node settings loaded by the plugin. Note that settings that are explicit in the nodes settings can't be * overwritten with the additional settings. These settings added if they don't exist. */ - Settings additionalSettings(); + public Settings additionalSettings() { + return Settings.Builder.EMPTY_SETTINGS; + } } diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java index 838fda430dc..b3a4a739d4e 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -47,7 +47,6 @@ import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -224,10 +223,10 @@ public class PluginsService extends AbstractComponent { return services; } - public Collection indexModules() { + public Collection indexModules(Settings indexSettings) { List modules = new ArrayList<>(); for (Tuple plugin : plugins) { - modules.addAll(plugin.v2().indexModules()); + modules.addAll(plugin.v2().indexModules(indexSettings)); } return modules; } @@ -240,10 +239,10 @@ public class PluginsService extends AbstractComponent { return services; } - public Collection shardModules() { + public Collection shardModules(Settings indexSettings) { List modules = new ArrayList<>(); for (Tuple plugin : plugins) { - modules.addAll(plugin.v2().shardModules()); + modules.addAll(plugin.v2().shardModules(indexSettings)); } return modules; } diff --git a/core/src/main/java/org/elasticsearch/plugins/ShardsPluginsModule.java b/core/src/main/java/org/elasticsearch/plugins/ShardsPluginsModule.java index b9e03a46cb9..5797b2d0575 100644 --- a/core/src/main/java/org/elasticsearch/plugins/ShardsPluginsModule.java +++ b/core/src/main/java/org/elasticsearch/plugins/ShardsPluginsModule.java @@ -41,7 +41,7 @@ public class ShardsPluginsModule extends AbstractModule implements SpawnModules, @Override public Iterable spawnModules() { - return pluginsService.shardModules(); + return pluginsService.shardModules(settings); } @Override diff --git a/core/src/main/java/org/elasticsearch/plugins/SitePlugin.java b/core/src/main/java/org/elasticsearch/plugins/SitePlugin.java index 4bb8008551e..4c12f2095bb 100644 --- a/core/src/main/java/org/elasticsearch/plugins/SitePlugin.java +++ b/core/src/main/java/org/elasticsearch/plugins/SitePlugin.java @@ -20,7 +20,7 @@ package org.elasticsearch.plugins; /** A site-only plugin, just serves resources */ -final class SitePlugin extends AbstractPlugin { +final class SitePlugin extends Plugin { final String name; final String description; diff --git a/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java b/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java index 3d017cf8f6e..10b34493334 100644 --- a/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java +++ b/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java @@ -89,7 +89,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; import org.elasticsearch.search.action.SearchServiceTransportAction; import org.elasticsearch.test.ESIntegTestCase; @@ -144,7 +144,7 @@ public class IndicesRequestIT extends ESIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", InterceptingTransportService.Plugin.class.getName()) + .extendArray("plugin.types", InterceptingTransportService.TestPlugin.class.getName()) .build(); } @@ -844,7 +844,7 @@ public class IndicesRequestIT extends ESIntegTestCase { public static class InterceptingTransportService extends TransportService { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "intercepting-transport-service"; diff --git a/core/src/test/java/org/elasticsearch/benchmark/scripts/expression/NativeScriptPlugin.java b/core/src/test/java/org/elasticsearch/benchmark/scripts/expression/NativeScriptPlugin.java index c2e8bb9ff7d..92f19a7c358 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/scripts/expression/NativeScriptPlugin.java +++ b/core/src/test/java/org/elasticsearch/benchmark/scripts/expression/NativeScriptPlugin.java @@ -19,10 +19,10 @@ package org.elasticsearch.benchmark.scripts.expression; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptModule; -public class NativeScriptPlugin extends AbstractPlugin { +public class NativeScriptPlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/plugin/NativeScriptExamplesPlugin.java b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/plugin/NativeScriptExamplesPlugin.java index 0d90d9fd6d2..2a25f8f21a5 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/plugin/NativeScriptExamplesPlugin.java +++ b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/plugin/NativeScriptExamplesPlugin.java @@ -18,11 +18,15 @@ */ package org.elasticsearch.benchmark.scripts.score.plugin; -import org.elasticsearch.benchmark.scripts.score.script.*; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.benchmark.scripts.score.script.NativeConstantForLoopScoreScript; +import org.elasticsearch.benchmark.scripts.score.script.NativeConstantScoreScript; +import org.elasticsearch.benchmark.scripts.score.script.NativeNaiveTFIDFScoreScript; +import org.elasticsearch.benchmark.scripts.score.script.NativePayloadSumNoRecordScoreScript; +import org.elasticsearch.benchmark.scripts.score.script.NativePayloadSumScoreScript; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptModule; -public class NativeScriptExamplesPlugin extends AbstractPlugin { +public class NativeScriptExamplesPlugin extends Plugin { @Override diff --git a/core/src/test/java/org/elasticsearch/cache/recycler/MockPageCacheRecycler.java b/core/src/test/java/org/elasticsearch/cache/recycler/MockPageCacheRecycler.java index 1f8ec84e193..ef5e50cfd68 100644 --- a/core/src/test/java/org/elasticsearch/cache/recycler/MockPageCacheRecycler.java +++ b/core/src/test/java/org/elasticsearch/cache/recycler/MockPageCacheRecycler.java @@ -25,8 +25,6 @@ import com.google.common.collect.Sets; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.recycler.Recycler.V; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.node.NodeModule; -import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.threadpool.ThreadPool; diff --git a/core/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java b/core/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java index 758dc3fe0a9..20d14f33dd4 100644 --- a/core/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java +++ b/core/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java @@ -35,9 +35,17 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.*; +import org.elasticsearch.transport.ConnectTransportException; +import org.elasticsearch.transport.Transport; +import org.elasticsearch.transport.TransportException; +import org.elasticsearch.transport.TransportModule; +import org.elasticsearch.transport.TransportRequest; +import org.elasticsearch.transport.TransportRequestOptions; +import org.elasticsearch.transport.TransportResponse; +import org.elasticsearch.transport.TransportResponseHandler; +import org.elasticsearch.transport.TransportService; import org.junit.Test; import java.util.concurrent.CountDownLatch; @@ -58,7 +66,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { TransportClient client = TransportClient.builder().settings(Settings.builder() .put("client.transport.sniff", false) .put("node.name", "transport_client_" + this.getTestName()) - .put("plugin.types", InternalTransportService.Plugin.class.getName()) + .put("plugin.types", InternalTransportService.TestPlugin.class.getName()) .put(headersSettings) .build()).build(); @@ -73,7 +81,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { .put("cluster.name", "cluster1") .put("node.name", "transport_client_" + this.getTestName() + "_1") .put("client.transport.nodes_sampler_interval", "1s") - .put("plugin.types", InternalTransportService.Plugin.class.getName()) + .put("plugin.types", InternalTransportService.TestPlugin.class.getName()) .put(HEADER_SETTINGS) .put("path.home", createTempDir().toString()) .build()).build(); @@ -96,7 +104,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { public static class InternalTransportService extends TransportService { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "mock-transport-service"; diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java b/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java index 40dec515f9c..017d261bdb2 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java @@ -35,11 +35,14 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.store.Store; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.transport.MockTransportService; -import org.elasticsearch.transport.*; +import org.elasticsearch.transport.TransportException; +import org.elasticsearch.transport.TransportRequest; +import org.elasticsearch.transport.TransportRequestOptions; +import org.elasticsearch.transport.TransportService; import org.hamcrest.Matchers; import org.junit.Test; @@ -64,7 +67,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0) public class ClusterInfoServiceIT extends ESIntegTestCase { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { @@ -143,7 +146,7 @@ public class ClusterInfoServiceIT extends ESIntegTestCase { return Settings.builder() // manual collection or upon cluster forming. .put(InternalClusterInfoService.INTERNAL_CLUSTER_INFO_TIMEOUT, "1s") - .putArray("plugin.types", Plugin.class.getName(), MockTransportService.Plugin.class.getName()) + .putArray("plugin.types", Plugin.class.getName(), MockTransportService.TestPlugin.class.getName()) .build(); } diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterServiceIT.java b/core/src/test/java/org/elasticsearch/cluster/ClusterServiceIT.java index 8aa30d3990b..71c2c2941a9 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterServiceIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterServiceIT.java @@ -20,7 +20,6 @@ package org.elasticsearch.cluster; import com.google.common.base.Predicate; import com.google.common.util.concurrent.ListenableFuture; - import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; @@ -36,7 +35,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Singleton; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.MockLogAppender; @@ -44,7 +43,12 @@ import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.threadpool.ThreadPool; import org.junit.Test; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -52,7 +56,11 @@ import java.util.concurrent.atomic.AtomicBoolean; import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.elasticsearch.test.ESIntegTestCase.Scope; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; /** * @@ -992,7 +1000,7 @@ public class ClusterServiceIT extends ESIntegTestCase { } } - public static class TestPlugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/cluster/MockInternalClusterInfoService.java b/core/src/test/java/org/elasticsearch/cluster/MockInternalClusterInfoService.java index 93318346ac2..33ae26e6ebe 100644 --- a/core/src/test/java/org/elasticsearch/cluster/MockInternalClusterInfoService.java +++ b/core/src/test/java/org/elasticsearch/cluster/MockInternalClusterInfoService.java @@ -28,7 +28,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.MockDiskUsagesIT; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.settings.NodeSettingsService; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.threadpool.ThreadPool; import java.util.concurrent.CountDownLatch; @@ -39,7 +39,7 @@ import java.util.concurrent.CountDownLatch; */ public class MockInternalClusterInfoService extends InternalClusterInfoService { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "mock-cluster-info-service"; diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/MockDiskUsagesIT.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/MockDiskUsagesIT.java index 79612d07b0e..978eba5e0bb 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/MockDiskUsagesIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/MockDiskUsagesIT.java @@ -50,7 +50,7 @@ public class MockDiskUsagesIT extends ESIntegTestCase { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) // Use the mock internal cluster info service, which has fake-able disk usages - .extendArray("plugin.types", MockInternalClusterInfoService.Plugin.class.getName()) + .extendArray("plugin.types", MockInternalClusterInfoService.TestPlugin.class.getName()) // Update more frequently .put(InternalClusterInfoService.INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL, "1s") .build(); diff --git a/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java b/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java index a2d741a1993..32551a4fe58 100644 --- a/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java @@ -25,7 +25,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.junit.Test; @@ -50,7 +50,7 @@ public class SettingsFilteringIT extends ESIntegTestCase { .build(); } - public static class SettingsFilteringPlugin extends AbstractPlugin { + public static class SettingsFilteringPlugin extends Plugin { /** * The name of the plugin. */ @@ -68,7 +68,7 @@ public class SettingsFilteringIT extends ESIntegTestCase { } @Override - public Collection indexModules() { + public Collection indexModules(Settings indexSettings) { return Collections.singletonList(new SettingsFilteringModule()); } } diff --git a/core/src/test/java/org/elasticsearch/common/util/MockBigArrays.java b/core/src/test/java/org/elasticsearch/common/util/MockBigArrays.java index 4eb4a376962..1e94285beea 100644 --- a/core/src/test/java/org/elasticsearch/common/util/MockBigArrays.java +++ b/core/src/test/java/org/elasticsearch/common/util/MockBigArrays.java @@ -24,14 +24,12 @@ import com.carrotsearch.randomizedtesting.SeedUtils; import com.google.common.base.Predicate; import com.google.common.collect.Maps; import com.google.common.collect.Sets; - import org.apache.lucene.util.Accountable; import org.apache.lucene.util.Accountables; import org.apache.lucene.util.BytesRef; import org.elasticsearch.cache.recycler.PageCacheRecycler; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.indices.breaker.CircuitBreakerService; -import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.test.ESTestCase; import java.util.Collection; diff --git a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java index 6c466599e66..84b206dec68 100644 --- a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java @@ -143,7 +143,7 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase { .put(DiscoverySettings.PUBLISH_TIMEOUT, "1s") // <-- for hitting simulated network failures quickly .put("http.enabled", false) // just to make test quicker .put("gateway.local.list_timeout", "10s") // still long to induce failures but to long so test won't time out - .put("plugin.types", MockTransportService.Plugin.class.getName()) + .put("plugin.types", MockTransportService.TestPlugin.class.getName()) .build(); private void configureCluster(int numberOfNodes, int minimumMasterNode) throws ExecutionException, InterruptedException { diff --git a/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java b/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java index 0df33c5c9b8..ee85af93215 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java +++ b/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java @@ -416,7 +416,7 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase { Path dataPath = createTempDir(); Settings nodeSettings = Settings.builder() .put("node.add_id_to_custom_path", false) - .put("plugin.types", MockTransportService.Plugin.class.getName()) + .put("plugin.types", MockTransportService.TestPlugin.class.getName()) .put("path.shared_data", dataPath) .build(); diff --git a/core/src/test/java/org/elasticsearch/index/TransportIndexFailuresIT.java b/core/src/test/java/org/elasticsearch/index/TransportIndexFailuresIT.java index 7efc56115ce..77250476aa9 100644 --- a/core/src/test/java/org/elasticsearch/index/TransportIndexFailuresIT.java +++ b/core/src/test/java/org/elasticsearch/index/TransportIndexFailuresIT.java @@ -56,7 +56,7 @@ public class TransportIndexFailuresIT extends ESIntegTestCase { .put(FaultDetection.SETTING_PING_RETRIES, "1") // <-- for hitting simulated network failures quickly .put(DiscoverySettings.PUBLISH_TIMEOUT, "1s") // <-- for hitting simulated network failures quickly .put("discovery.zen.minimum_master_nodes", 1) - .put("plugin.types", MockTransportService.Plugin.class.getName()) + .put("plugin.types", MockTransportService.TestPlugin.class.getName()) .build(); @Override diff --git a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapperPlugin.java b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapperPlugin.java index d6104b51cad..d9cee69f8b0 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapperPlugin.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapperPlugin.java @@ -20,14 +20,13 @@ package org.elasticsearch.index.mapper.externalvalues; import org.elasticsearch.common.inject.Module; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.plugins.Plugin; import java.util.Collection; import java.util.Collections; -import static com.google.common.collect.Lists.newArrayList; - -public class ExternalMapperPlugin extends AbstractPlugin { +public class ExternalMapperPlugin extends Plugin { @Override public String name() { return "external-mappers"; @@ -39,7 +38,7 @@ public class ExternalMapperPlugin extends AbstractPlugin { } @Override - public Collection indexModules() { + public Collection indexModules(Settings indexSettings) { return Collections.singletonList(new ExternalIndexModule()); } } diff --git a/core/src/test/java/org/elasticsearch/index/query/plugin/DummyQueryParserPlugin.java b/core/src/test/java/org/elasticsearch/index/query/plugin/DummyQueryParserPlugin.java index cdffcc8c36b..dbbc3581602 100644 --- a/core/src/test/java/org/elasticsearch/index/query/plugin/DummyQueryParserPlugin.java +++ b/core/src/test/java/org/elasticsearch/index/query/plugin/DummyQueryParserPlugin.java @@ -30,11 +30,11 @@ import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryParser; import org.elasticsearch.index.query.QueryParsingException; import org.elasticsearch.indices.IndicesModule; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import java.io.IOException; -public class DummyQueryParserPlugin extends AbstractPlugin { +public class DummyQueryParserPlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/index/shard/MockEngineFactoryPlugin.java b/core/src/test/java/org/elasticsearch/index/shard/MockEngineFactoryPlugin.java index ad0f820595a..d1b50487c63 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/MockEngineFactoryPlugin.java +++ b/core/src/test/java/org/elasticsearch/index/shard/MockEngineFactoryPlugin.java @@ -19,7 +19,8 @@ package org.elasticsearch.index.shard; import org.elasticsearch.common.inject.Module; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.engine.MockEngineFactory; import org.elasticsearch.test.engine.MockEngineSupportModule; @@ -27,7 +28,7 @@ import java.util.Collection; import java.util.Collections; // this must exist in the same package as IndexShardModule to allow access to setting the impl -public class MockEngineFactoryPlugin extends AbstractPlugin { +public class MockEngineFactoryPlugin extends Plugin { @Override public String name() { return "mock-engine-factory"; @@ -37,7 +38,7 @@ public class MockEngineFactoryPlugin extends AbstractPlugin { return "a mock engine factory for testing"; } @Override - public Collection indexModules() { + public Collection indexModules(Settings indexSettings) { return Collections.singletonList(new MockEngineSupportModule()); } public void onModule(IndexShardModule module) { diff --git a/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java b/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java index 4a2f560c4f4..b9d00741720 100644 --- a/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java +++ b/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java @@ -98,7 +98,7 @@ public class CorruptedFileIT extends ESIntegTestCase { // we really need local GW here since this also checks for corruption etc. // and we need to make sure primaries are not just trashed if we don't have replicas .put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", MockTransportService.Plugin.class.getName()) + .extendArray("plugin.types", MockTransportService.TestPlugin.class.getName()) // speed up recoveries .put(RecoverySettings.INDICES_RECOVERY_CONCURRENT_STREAMS, 10) .put(RecoverySettings.INDICES_RECOVERY_CONCURRENT_SMALL_FILE_STREAMS, 10) diff --git a/core/src/test/java/org/elasticsearch/index/store/CorruptedTranslogIT.java b/core/src/test/java/org/elasticsearch/index/store/CorruptedTranslogIT.java index ec5d24254a1..04b0ed38742 100644 --- a/core/src/test/java/org/elasticsearch/index/store/CorruptedTranslogIT.java +++ b/core/src/test/java/org/elasticsearch/index/store/CorruptedTranslogIT.java @@ -66,7 +66,7 @@ public class CorruptedTranslogIT extends ESIntegTestCase { // we really need local GW here since this also checks for corruption etc. // and we need to make sure primaries are not just trashed if we don't have replicas .put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", MockTransportService.Plugin.class.getName()).build(); + .extendArray("plugin.types", MockTransportService.TestPlugin.class.getName()).build(); } @Test diff --git a/core/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java b/core/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java index bd2adc1e579..9fe2a0fd629 100644 --- a/core/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java +++ b/core/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java @@ -54,7 +54,7 @@ public class ExceptionRetryIT extends ESIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", MockTransportService.Plugin.class.getName()) + .extendArray("plugin.types", MockTransportService.TestPlugin.class.getName()) .build(); } diff --git a/core/src/test/java/org/elasticsearch/indices/analysis/DummyAnalysisPlugin.java b/core/src/test/java/org/elasticsearch/indices/analysis/DummyAnalysisPlugin.java index e9bda623969..003771f8cc7 100644 --- a/core/src/test/java/org/elasticsearch/indices/analysis/DummyAnalysisPlugin.java +++ b/core/src/test/java/org/elasticsearch/indices/analysis/DummyAnalysisPlugin.java @@ -21,12 +21,12 @@ package org.elasticsearch.indices.analysis; import org.elasticsearch.common.inject.Module; import org.elasticsearch.index.analysis.AnalysisModule; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import java.util.Collection; import java.util.Collections; -public class DummyAnalysisPlugin extends AbstractPlugin { +public class DummyAnalysisPlugin extends Plugin { /** * The name of the plugin. */ diff --git a/core/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java b/core/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java index 2e8c1658270..6ff35daf55a 100644 --- a/core/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java +++ b/core/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java @@ -35,7 +35,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.engine.MockEngineSupport; @@ -107,7 +107,7 @@ public class RandomExceptionCircuitBreakerIT extends ESIntegTestCase { Settings.Builder settings = settingsBuilder() .put(indexSettings()) - .extendArray("plugin.types", RandomExceptionDirectoryReaderWrapper.Plugin.class.getName()) + .extendArray("plugin.types", RandomExceptionDirectoryReaderWrapper.TestPlugin.class.getName()) .put(EXCEPTION_TOP_LEVEL_RATIO_KEY, topLevelRate) .put(EXCEPTION_LOW_LEVEL_RATIO_KEY, lowLevelRate) .put(MockEngineSupport.WRAP_READER_RATIO, 1.0d); @@ -202,7 +202,7 @@ public class RandomExceptionCircuitBreakerIT extends ESIntegTestCase { // TODO: Generalize this class and add it as a utility public static class RandomExceptionDirectoryReaderWrapper extends MockEngineSupport.DirectoryReaderWrapper { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "random-exception-reader-wrapper"; 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 a6263eee9d5..c2860c75033 100644 --- a/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java +++ b/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java @@ -519,7 +519,7 @@ public class IndexRecoveryIT extends ESIntegTestCase { final Settings nodeSettings = Settings.builder() .put(RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_NETWORK, "100ms") .put(RecoverySettings.INDICES_RECOVERY_INTERNAL_ACTION_TIMEOUT, "1s") - .put("plugin.types", MockTransportService.Plugin.class.getName()) + .put("plugin.types", MockTransportService.TestPlugin.class.getName()) .put(MockFSDirectoryService.RANDOM_PREVENT_DOUBLE_WRITE, false) // restarted recoveries will delete temp files and write them again .build(); // start a master node diff --git a/core/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java b/core/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java index 8417b227845..898415152ca 100644 --- a/core/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java @@ -87,7 +87,7 @@ public class IndicesStoreIntegrationIT extends ESIntegTestCase { // which is between 1 and 2 sec can cause each of the shard deletion requests to timeout. // to prevent this we are setting the timeout here to something highish ie. the default in practice .put(IndicesStore.INDICES_STORE_DELETE_SHARD_TIMEOUT, new TimeValue(30, TimeUnit.SECONDS)) - .extendArray("plugin.types", MockTransportService.Plugin.class.getName()) + .extendArray("plugin.types", MockTransportService.TestPlugin.class.getName()) .build(); } diff --git a/core/src/test/java/org/elasticsearch/indices/template/IndexTemplateFilteringIT.java b/core/src/test/java/org/elasticsearch/indices/template/IndexTemplateFilteringIT.java index fdabe10888b..e441a952f21 100644 --- a/core/src/test/java/org/elasticsearch/indices/template/IndexTemplateFilteringIT.java +++ b/core/src/test/java/org/elasticsearch/indices/template/IndexTemplateFilteringIT.java @@ -27,7 +27,7 @@ import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; @@ -80,7 +80,7 @@ public class IndexTemplateFilteringIT extends ESIntegTestCase { } } - public static class TestPlugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "test-plugin"; diff --git a/core/src/test/java/org/elasticsearch/node/NodeMocksPlugin.java b/core/src/test/java/org/elasticsearch/node/NodeMocksPlugin.java index 8eed1e16713..f958b2b752e 100644 --- a/core/src/test/java/org/elasticsearch/node/NodeMocksPlugin.java +++ b/core/src/test/java/org/elasticsearch/node/NodeMocksPlugin.java @@ -20,9 +20,9 @@ package org.elasticsearch.node; import org.elasticsearch.cache.recycler.MockPageCacheRecycler; import org.elasticsearch.common.util.MockBigArrays; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; -public class NodeMocksPlugin extends AbstractPlugin { +public class NodeMocksPlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/nodesinfo/plugin/dummy1/TestPlugin.java b/core/src/test/java/org/elasticsearch/nodesinfo/plugin/dummy1/TestPlugin.java index 274e5e51a05..8455a3bf562 100644 --- a/core/src/test/java/org/elasticsearch/nodesinfo/plugin/dummy1/TestPlugin.java +++ b/core/src/test/java/org/elasticsearch/nodesinfo/plugin/dummy1/TestPlugin.java @@ -19,9 +19,9 @@ package org.elasticsearch.nodesinfo.plugin.dummy1; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; -public class TestPlugin extends AbstractPlugin { +public class TestPlugin extends Plugin { static final public class Fields { static public final String NAME = "test-plugin"; diff --git a/core/src/test/java/org/elasticsearch/nodesinfo/plugin/dummy2/TestNoVersionPlugin.java b/core/src/test/java/org/elasticsearch/nodesinfo/plugin/dummy2/TestNoVersionPlugin.java deleted file mode 100644 index 58b5ee007f2..00000000000 --- a/core/src/test/java/org/elasticsearch/nodesinfo/plugin/dummy2/TestNoVersionPlugin.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.nodesinfo.plugin.dummy2; - -import org.elasticsearch.plugins.AbstractPlugin; - -public class TestNoVersionPlugin extends AbstractPlugin { - - static final public class Fields { - static public final String NAME = "test-no-version-plugin"; - static public final String DESCRIPTION = NAME + " description"; - } - - @Override - public String name() { - return Fields.NAME; - } - - @Override - public String description() { - return Fields.DESCRIPTION; - } -} diff --git a/core/src/test/java/org/elasticsearch/plugins/PluggableTransportModuleIT.java b/core/src/test/java/org/elasticsearch/plugins/PluggableTransportModuleIT.java index 514e8460f08..07904389d3c 100644 --- a/core/src/test/java/org/elasticsearch/plugins/PluggableTransportModuleIT.java +++ b/core/src/test/java/org/elasticsearch/plugins/PluggableTransportModuleIT.java @@ -73,7 +73,7 @@ public class PluggableTransportModuleIT extends ESIntegTestCase { assertThat("Expected send request counter to be greather than zero", countAfterRequest, is(greaterThan(countBeforeRequest))); } - public static class CountingSentRequestsPlugin extends AbstractPlugin { + public static class CountingSentRequestsPlugin extends Plugin { @Override public String name() { return "counting-pipelines-plugin"; diff --git a/core/src/test/java/org/elasticsearch/plugins/loading/classpath/InClassPathPlugin.java b/core/src/test/java/org/elasticsearch/plugins/loading/classpath/InClassPathPlugin.java index cf4959e62d1..79b1f244eff 100644 --- a/core/src/test/java/org/elasticsearch/plugins/loading/classpath/InClassPathPlugin.java +++ b/core/src/test/java/org/elasticsearch/plugins/loading/classpath/InClassPathPlugin.java @@ -19,9 +19,9 @@ package org.elasticsearch.plugins.loading.classpath; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; -public class InClassPathPlugin extends AbstractPlugin { +public class InClassPathPlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/plugins/responseheader/TestResponseHeaderPlugin.java b/core/src/test/java/org/elasticsearch/plugins/responseheader/TestResponseHeaderPlugin.java index 48b00b23754..b9282cf05ad 100644 --- a/core/src/test/java/org/elasticsearch/plugins/responseheader/TestResponseHeaderPlugin.java +++ b/core/src/test/java/org/elasticsearch/plugins/responseheader/TestResponseHeaderPlugin.java @@ -19,10 +19,10 @@ package org.elasticsearch.plugins.responseheader; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestModule; -public class TestResponseHeaderPlugin extends AbstractPlugin { +public class TestResponseHeaderPlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java b/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java index 53a71e1dc7b..39622287ea2 100644 --- a/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java +++ b/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java @@ -102,7 +102,7 @@ public class RelocationIT extends ESIntegTestCase { @Override protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() - .put("plugin.types", MockTransportService.Plugin.class.getName()).build(); + .put("plugin.types", MockTransportService.TestPlugin.class.getName()).build(); } diff --git a/core/src/test/java/org/elasticsearch/recovery/TruncatedRecoveryIT.java b/core/src/test/java/org/elasticsearch/recovery/TruncatedRecoveryIT.java index c8943d1ff27..943a1485100 100644 --- a/core/src/test/java/org/elasticsearch/recovery/TruncatedRecoveryIT.java +++ b/core/src/test/java/org/elasticsearch/recovery/TruncatedRecoveryIT.java @@ -58,7 +58,7 @@ public class TruncatedRecoveryIT extends ESIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { Settings.Builder builder = Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", MockTransportService.Plugin.class.getName()) + .extendArray("plugin.types", MockTransportService.TestPlugin.class.getName()) .put(RecoverySettings.INDICES_RECOVERY_FILE_CHUNK_SIZE, new ByteSizeValue(randomIntBetween(50, 300), ByteSizeUnit.BYTES)); return builder.build(); } diff --git a/core/src/test/java/org/elasticsearch/script/CustomScriptContextIT.java b/core/src/test/java/org/elasticsearch/script/CustomScriptContextIT.java index fdf6a728c10..efac975fcc3 100644 --- a/core/src/test/java/org/elasticsearch/script/CustomScriptContextIT.java +++ b/core/src/test/java/org/elasticsearch/script/CustomScriptContextIT.java @@ -20,10 +20,8 @@ package org.elasticsearch.script; import com.google.common.collect.ImmutableSet; - -import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.expression.ExpressionScriptEngineService; import org.elasticsearch.script.groovy.GroovyScriptEngineService; import org.elasticsearch.script.mustache.MustacheScriptEngineService; @@ -117,7 +115,7 @@ public class CustomScriptContextIT extends ESIntegTestCase { } } - public static class CustomScriptContextPlugin extends AbstractPlugin { + public static class CustomScriptContextPlugin extends Plugin { @Override public String name() { return "custom_script_context_plugin"; diff --git a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java index 2ad584bfec5..3c35a286e3b 100644 --- a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java @@ -21,7 +21,6 @@ package org.elasticsearch.script; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; - import org.elasticsearch.common.Nullable; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.ModulesBuilder; @@ -29,7 +28,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; -import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; diff --git a/core/src/test/java/org/elasticsearch/script/ScriptFieldIT.java b/core/src/test/java/org/elasticsearch/script/ScriptFieldIT.java index 471cbb4cf20..c9707f7bdbb 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptFieldIT.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptFieldIT.java @@ -23,7 +23,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.search.SearchHit; import org.elasticsearch.test.ESIntegTestCase; @@ -152,7 +152,7 @@ public class ScriptFieldIT extends ESIntegTestCase { } } - public static class CustomScriptPlugin extends AbstractPlugin { + public static class CustomScriptPlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/search/MockSearchService.java b/core/src/test/java/org/elasticsearch/search/MockSearchService.java index 077f730f2c9..9a7a3efa3dc 100644 --- a/core/src/test/java/org/elasticsearch/search/MockSearchService.java +++ b/core/src/test/java/org/elasticsearch/search/MockSearchService.java @@ -28,9 +28,8 @@ import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.IndicesWarmer; import org.elasticsearch.indices.cache.request.IndicesRequestCache; import org.elasticsearch.node.settings.NodeSettingsService; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.SearchService; import org.elasticsearch.search.dfs.DfsPhase; import org.elasticsearch.search.fetch.FetchPhase; import org.elasticsearch.search.internal.SearchContext; @@ -43,7 +42,7 @@ import java.util.concurrent.ConcurrentHashMap; public class MockSearchService extends SearchService { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "mock-search-service"; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java index f167ce3cbef..c3780e98064 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java @@ -30,7 +30,7 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryParsingException; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.ScriptService; @@ -45,7 +45,14 @@ import org.elasticsearch.search.aggregations.bucket.significant.SignificantStrin import org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms; import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregatorFactory; import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsBuilder; -import org.elasticsearch.search.aggregations.bucket.significant.heuristics.*; +import org.elasticsearch.search.aggregations.bucket.significant.heuristics.ChiSquare; +import org.elasticsearch.search.aggregations.bucket.significant.heuristics.GND; +import org.elasticsearch.search.aggregations.bucket.significant.heuristics.MutualInformation; +import org.elasticsearch.search.aggregations.bucket.significant.heuristics.ScriptHeuristic; +import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristic; +import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicBuilder; +import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser; +import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicStreams; import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; @@ -53,7 +60,12 @@ import org.elasticsearch.test.ESIntegTestCase; import org.junit.Test; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutionException; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; @@ -61,7 +73,10 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.closeTo; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; /** * @@ -154,7 +169,7 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase { } } - public static class CustomSignificanceHeuristicPlugin extends AbstractPlugin { + public static class CustomSignificanceHeuristicPlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java b/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java index 64375138efd..76e24467049 100644 --- a/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java +++ b/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java @@ -35,7 +35,7 @@ import org.elasticsearch.common.settings.Settings.Builder; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ESIntegTestCase; @@ -252,7 +252,7 @@ public class SearchWithRandomExceptionsIT extends ESIntegTestCase { Builder settings = settingsBuilder() .put(indexSettings()) - .extendArray("plugin.types", RandomExceptionDirectoryReaderWrapper.Plugin.class.getName()) + .extendArray("plugin.types", RandomExceptionDirectoryReaderWrapper.TestPlugin.class.getName()) .put(EXCEPTION_TOP_LEVEL_RATIO_KEY, topLevelRate) .put(EXCEPTION_LOW_LEVEL_RATIO_KEY, lowLevelRate) .put(MockEngineSupport.WRAP_READER_RATIO, 1.0d); @@ -313,7 +313,7 @@ public class SearchWithRandomExceptionsIT extends ESIntegTestCase { public static class RandomExceptionDirectoryReaderWrapper extends MockEngineSupport.DirectoryReaderWrapper { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "random-exception-reader-wrapper"; diff --git a/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java b/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java index daf4d11a080..58ec58bfdf3 100644 --- a/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java +++ b/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java @@ -29,7 +29,7 @@ import org.elasticsearch.action.termvectors.TermVectorsResponse; import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.SearchModule; import org.elasticsearch.search.SearchParseElement; @@ -99,7 +99,7 @@ public class FetchSubPhasePluginIT extends ESIntegTestCase { assertThat(((Map) response.getHits().getAt(0).field("term_vectors_fetch").getValues().get(0)).get("sam"), equalTo(1)); } - public static class FetchTermVectorsPlugin extends AbstractPlugin { + public static class FetchTermVectorsPlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptPlugin.java b/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptPlugin.java index d30c9453ec3..a32baa526b5 100644 --- a/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptPlugin.java +++ b/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptPlugin.java @@ -19,10 +19,10 @@ package org.elasticsearch.search.functionscore; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptModule; -public class ExplainableScriptPlugin extends AbstractPlugin { +public class ExplainableScriptPlugin extends Plugin { public ExplainableScriptPlugin() {} @Override diff --git a/core/src/test/java/org/elasticsearch/search/functionscore/FunctionScorePluginIT.java b/core/src/test/java/org/elasticsearch/search/functionscore/FunctionScorePluginIT.java index 61f50a17a26..d1dd06d8d82 100644 --- a/core/src/test/java/org/elasticsearch/search/functionscore/FunctionScorePluginIT.java +++ b/core/src/test/java/org/elasticsearch/search/functionscore/FunctionScorePluginIT.java @@ -28,7 +28,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.functionscore.DecayFunction; import org.elasticsearch.index.query.functionscore.DecayFunctionBuilder; import org.elasticsearch.index.query.functionscore.DecayFunctionParser; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.SearchModule; import org.elasticsearch.test.ESIntegTestCase; @@ -95,7 +95,7 @@ public class FunctionScorePluginIT extends ESIntegTestCase { } - public static class CustomDistanceScorePlugin extends AbstractPlugin { + public static class CustomDistanceScorePlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/search/highlight/CustomHighlighterPlugin.java b/core/src/test/java/org/elasticsearch/search/highlight/CustomHighlighterPlugin.java index 705265ea5f6..80e39a2a6dd 100644 --- a/core/src/test/java/org/elasticsearch/search/highlight/CustomHighlighterPlugin.java +++ b/core/src/test/java/org/elasticsearch/search/highlight/CustomHighlighterPlugin.java @@ -19,10 +19,10 @@ package org.elasticsearch.search.highlight; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchModule; -public class CustomHighlighterPlugin extends AbstractPlugin { +public class CustomHighlighterPlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/search/suggest/CustomSuggesterPlugin.java b/core/src/test/java/org/elasticsearch/search/suggest/CustomSuggesterPlugin.java index 9ba9c530e56..c5e36da2ea7 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/CustomSuggesterPlugin.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/CustomSuggesterPlugin.java @@ -18,13 +18,13 @@ */ package org.elasticsearch.search.suggest; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchModule; /** * */ -public class CustomSuggesterPlugin extends AbstractPlugin { +public class CustomSuggesterPlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java index 70471c574b1..5a6f1353d93 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java +++ b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java @@ -23,15 +23,13 @@ import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.SettingsFilter; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoriesModule; import java.util.Collection; import java.util.Collections; -import static com.google.common.collect.Lists.newArrayList; - -public class MockRepositoryPlugin extends AbstractPlugin { +public class MockRepositoryPlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java index 8ec6f89e44b..1fa655261ee 100644 --- a/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -383,14 +383,14 @@ public final class InternalTestCluster extends TestCluster { .put(SETTING_CLUSTER_NODE_SEED, seed); if (ENABLE_MOCK_MODULES && usually(random)) { builder.extendArray("plugin.types", - MockTransportService.Plugin.class.getName(), - MockFSIndexStore.Plugin.class.getName(), + MockTransportService.TestPlugin.class.getName(), + MockFSIndexStore.TestPlugin.class.getName(), NodeMocksPlugin.class.getName(), MockEngineFactoryPlugin.class.getName(), - MockSearchService.Plugin.class.getName()); + MockSearchService.TestPlugin.class.getName()); } if (isLocalTransportConfigured()) { - builder.extendArray("plugin.types", AssertingLocalTransport.Plugin.class.getName()); + builder.extendArray("plugin.types", AssertingLocalTransport.TestPlugin.class.getName()); } else { builder.put(Transport.TransportSettings.TRANSPORT_TCP_COMPRESS, rarely(random)); } diff --git a/core/src/test/java/org/elasticsearch/test/disruption/NetworkPartitionIT.java b/core/src/test/java/org/elasticsearch/test/disruption/NetworkPartitionIT.java index a1ec62b64fa..e0cbfa5ed90 100644 --- a/core/src/test/java/org/elasticsearch/test/disruption/NetworkPartitionIT.java +++ b/core/src/test/java/org/elasticsearch/test/disruption/NetworkPartitionIT.java @@ -35,7 +35,7 @@ public class NetworkPartitionIT extends ESIntegTestCase { @Override protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() - .put("plugin.types", MockTransportService.Plugin.class.getName()) + .put("plugin.types", MockTransportService.TestPlugin.class.getName()) .build(); } diff --git a/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java b/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java index 47b0baa7c54..c5b5ac36f00 100644 --- a/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java +++ b/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java @@ -28,11 +28,11 @@ import org.elasticsearch.index.store.DirectoryService; import org.elasticsearch.index.store.IndexStore; import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.indices.store.IndicesStore; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; public class MockFSIndexStore extends IndexStore { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "mock-index-store"; diff --git a/core/src/test/java/org/elasticsearch/test/transport/AssertingLocalTransport.java b/core/src/test/java/org/elasticsearch/test/transport/AssertingLocalTransport.java index 7bda47b94c8..d9b9b491c9d 100644 --- a/core/src/test/java/org/elasticsearch/test/transport/AssertingLocalTransport.java +++ b/core/src/test/java/org/elasticsearch/test/transport/AssertingLocalTransport.java @@ -24,12 +24,17 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.*; +import org.elasticsearch.transport.TransportException; +import org.elasticsearch.transport.TransportModule; +import org.elasticsearch.transport.TransportRequest; +import org.elasticsearch.transport.TransportRequestOptions; +import org.elasticsearch.transport.TransportResponse; +import org.elasticsearch.transport.TransportResponseHandler; import org.elasticsearch.transport.local.LocalTransport; import java.io.IOException; @@ -37,7 +42,7 @@ import java.util.Random; public class AssertingLocalTransport extends LocalTransport { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "asserting-local-transport"; diff --git a/core/src/test/java/org/elasticsearch/test/transport/MockTransportService.java b/core/src/test/java/org/elasticsearch/test/transport/MockTransportService.java index ce381af6263..0aa2e3487fa 100644 --- a/core/src/test/java/org/elasticsearch/test/transport/MockTransportService.java +++ b/core/src/test/java/org/elasticsearch/test/transport/MockTransportService.java @@ -32,12 +32,24 @@ import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.*; +import org.elasticsearch.transport.ConnectTransportException; +import org.elasticsearch.transport.RequestHandlerRegistry; +import org.elasticsearch.transport.Transport; +import org.elasticsearch.transport.TransportException; +import org.elasticsearch.transport.TransportModule; +import org.elasticsearch.transport.TransportRequest; +import org.elasticsearch.transport.TransportRequestOptions; +import org.elasticsearch.transport.TransportService; +import org.elasticsearch.transport.TransportServiceAdapter; import java.io.IOException; -import java.util.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; @@ -46,7 +58,7 @@ import java.util.concurrent.CopyOnWriteArrayList; */ public class MockTransportService extends TransportService { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "mock-transport-service"; diff --git a/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java b/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java index d433c955796..811f6e5928d 100644 --- a/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java +++ b/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java @@ -21,7 +21,12 @@ package org.elasticsearch.transport; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import org.elasticsearch.action.*; +import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.ActionModule; +import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionRequestBuilder; +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; @@ -41,8 +46,12 @@ import org.elasticsearch.common.inject.PreProcessModule; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.http.HttpServerTransport; -import org.elasticsearch.index.query.*; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.GeoShapeQueryBuilder; +import org.elasticsearch.index.query.MoreLikeThisQueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.query.TermsLookupQueryBuilder; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestController; import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.groovy.GroovyScriptEngineService; @@ -55,7 +64,13 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; @@ -64,8 +79,13 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.node.Node.HTTP_ENABLED; import static org.elasticsearch.rest.RestStatus.OK; import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; -import static org.hamcrest.Matchers.*; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasStatus; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; @ClusterScope(scope = SUITE) public class ContextAndHeaderTransportIT extends ESIntegTestCase { @@ -365,7 +385,7 @@ public class ContextAndHeaderTransportIT extends ESIntegTestCase { return filterClient; } - public static class ActionLoggingPlugin extends AbstractPlugin { + public static class ActionLoggingPlugin extends Plugin { @Override public String name() { diff --git a/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportIT.java b/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportIT.java index ad38b4c8925..e26998cc0a6 100644 --- a/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportIT.java +++ b/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportIT.java @@ -33,7 +33,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.concurrent.AbstractRunnable; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.ActionNotFoundTransportException; @@ -67,7 +67,7 @@ public class NettyTransportIT extends ESIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return settingsBuilder().put(super.nodeSettings(nodeOrdinal)) .put("node.mode", "network") - .extendArray("plugin.types", ExceptionThrowingNettyTransport.Plugin.class.getName()).build(); + .extendArray("plugin.types", ExceptionThrowingNettyTransport.TestPlugin.class.getName()).build(); } @Test @@ -87,7 +87,7 @@ public class NettyTransportIT extends ESIntegTestCase { public static final class ExceptionThrowingNettyTransport extends NettyTransport { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "exception-throwing-netty-transport"; diff --git a/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java b/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java index 8a7279261f0..2e2edb64bbb 100644 --- a/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java +++ b/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java @@ -19,10 +19,9 @@ package org.elasticsearch.update; import com.google.common.collect.Maps; - import org.elasticsearch.common.Nullable; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.AbstractExecutableScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.NativeScriptEngineService; @@ -50,7 +49,7 @@ public class UpdateByNativeScriptIT extends ESIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", CustomNativeScriptFactory.Plugin.class.getName()) + .extendArray("plugin.types", CustomNativeScriptFactory.TestPlugin.class.getName()) .build(); } @@ -72,7 +71,7 @@ public class UpdateByNativeScriptIT extends ESIntegTestCase { } public static class CustomNativeScriptFactory implements NativeScriptFactory { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "mock-native-script"; diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java index 12d535f46a6..6b9314cacff 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java @@ -23,16 +23,15 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.analysis.IcuAnalysisBinderProcessor; import org.elasticsearch.indices.analysis.IcuIndicesAnalysisModule; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; /** * */ -public class AnalysisICUPlugin extends AbstractPlugin { +public class AnalysisICUPlugin extends Plugin { @Override public String name() { diff --git a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/plugin/analysis/kuromoji/AnalysisKuromojiPlugin.java b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/plugin/analysis/kuromoji/AnalysisKuromojiPlugin.java index ac095e19852..46dce43b307 100644 --- a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/plugin/analysis/kuromoji/AnalysisKuromojiPlugin.java +++ b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/plugin/analysis/kuromoji/AnalysisKuromojiPlugin.java @@ -30,16 +30,15 @@ import org.elasticsearch.index.analysis.KuromojiPartOfSpeechFilterFactory; import org.elasticsearch.index.analysis.KuromojiReadingFormFilterFactory; import org.elasticsearch.index.analysis.KuromojiTokenizerFactory; import org.elasticsearch.indices.analysis.KuromojiIndicesAnalysisModule; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; /** * */ -public class AnalysisKuromojiPlugin extends AbstractPlugin { +public class AnalysisKuromojiPlugin extends Plugin { @Override public String name() { diff --git a/plugins/analysis-phonetic/src/main/java/org/elasticsearch/plugin/analysis/AnalysisPhoneticPlugin.java b/plugins/analysis-phonetic/src/main/java/org/elasticsearch/plugin/analysis/AnalysisPhoneticPlugin.java index dacea45e049..1ef97c62e73 100644 --- a/plugins/analysis-phonetic/src/main/java/org/elasticsearch/plugin/analysis/AnalysisPhoneticPlugin.java +++ b/plugins/analysis-phonetic/src/main/java/org/elasticsearch/plugin/analysis/AnalysisPhoneticPlugin.java @@ -21,11 +21,11 @@ package org.elasticsearch.plugin.analysis; import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.analysis.PhoneticAnalysisBinderProcessor; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; /** */ -public class AnalysisPhoneticPlugin extends AbstractPlugin { +public class AnalysisPhoneticPlugin extends Plugin { @Override public String name() { diff --git a/plugins/analysis-smartcn/src/main/java/org/elasticsearch/plugin/analysis/smartcn/AnalysisSmartChinesePlugin.java b/plugins/analysis-smartcn/src/main/java/org/elasticsearch/plugin/analysis/smartcn/AnalysisSmartChinesePlugin.java index 25491a6fbe4..92b933fd725 100644 --- a/plugins/analysis-smartcn/src/main/java/org/elasticsearch/plugin/analysis/smartcn/AnalysisSmartChinesePlugin.java +++ b/plugins/analysis-smartcn/src/main/java/org/elasticsearch/plugin/analysis/smartcn/AnalysisSmartChinesePlugin.java @@ -23,16 +23,15 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.analysis.SmartChineseAnalysisBinderProcessor; import org.elasticsearch.indices.analysis.smartcn.SmartChineseIndicesAnalysisModule; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; /** * */ -public class AnalysisSmartChinesePlugin extends AbstractPlugin { +public class AnalysisSmartChinesePlugin extends Plugin { @Override public String name() { diff --git a/plugins/analysis-stempel/src/main/java/org/elasticsearch/plugin/analysis/stempel/AnalysisStempelPlugin.java b/plugins/analysis-stempel/src/main/java/org/elasticsearch/plugin/analysis/stempel/AnalysisStempelPlugin.java index 340382c77b5..b22cda173a4 100644 --- a/plugins/analysis-stempel/src/main/java/org/elasticsearch/plugin/analysis/stempel/AnalysisStempelPlugin.java +++ b/plugins/analysis-stempel/src/main/java/org/elasticsearch/plugin/analysis/stempel/AnalysisStempelPlugin.java @@ -23,14 +23,15 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.analysis.pl.PolishAnalysisBinderProcessor; import org.elasticsearch.indices.analysis.pl.PolishIndicesAnalysisModule; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; -import java.util.*; +import java.util.Collection; +import java.util.Collections; /** * */ -public class AnalysisStempelPlugin extends AbstractPlugin { +public class AnalysisStempelPlugin extends Plugin { @Override public String name() { diff --git a/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java b/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java index a2ed9902a50..09231917da5 100644 --- a/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java +++ b/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java @@ -26,7 +26,7 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.ec2.Ec2Discovery; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.repositories.s3.S3Repository; import org.elasticsearch.repositories.s3.S3RepositoryModule; @@ -37,7 +37,7 @@ import java.util.Collection; /** * */ -public class CloudAwsPlugin extends AbstractPlugin { +public class CloudAwsPlugin extends Plugin { private final Settings settings; diff --git a/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/AbstractAwsTest.java b/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/AbstractAwsTest.java index 082f9ca49f6..a44a0f46b3a 100644 --- a/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/AbstractAwsTest.java +++ b/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/AbstractAwsTest.java @@ -75,7 +75,7 @@ public abstract class AbstractAwsTest extends ESIntegTestCase { Settings.Builder settings = Settings.builder() .put(super.nodeSettings(nodeOrdinal)) .put("path.home", createTempDir()) - .extendArray("plugin.types", CloudAwsPlugin.class.getName(), TestAwsS3Service.Plugin.class.getName()) + .extendArray("plugin.types", CloudAwsPlugin.class.getName(), TestAwsS3Service.TestPlugin.class.getName()) .put("cloud.aws.test.random", randomInt()) .put("cloud.aws.test.write_failures", 0.1) .put("cloud.aws.test.read_failures", 0.1); diff --git a/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java b/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java index 1124150ccf0..92e4d72ac27 100644 --- a/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java +++ b/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java @@ -22,12 +22,12 @@ import com.amazonaws.services.s3.AmazonS3; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import java.util.IdentityHashMap; public class TestAwsS3Service extends InternalAwsS3Service { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "mock-s3-service"; diff --git a/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java b/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java index d112f3c9738..c8c8f83d98d 100644 --- a/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java +++ b/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java @@ -29,7 +29,7 @@ import org.elasticsearch.discovery.azure.AzureDiscovery; import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.index.store.smbmmapfs.SmbMmapFsIndexStore; import org.elasticsearch.index.store.smbsimplefs.SmbSimpleFsIndexStore; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.repositories.azure.AzureRepository; import org.elasticsearch.repositories.azure.AzureRepositoryModule; @@ -38,12 +38,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import static org.elasticsearch.cloud.azure.AzureModule.isSnapshotReady; - /** * */ -public class CloudAzurePlugin extends AbstractPlugin { +public class CloudAzurePlugin extends Plugin { private final Settings settings; protected final ESLogger logger = Loggers.getLogger(CloudAzurePlugin.class); diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureComputeServiceTest.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureComputeServiceTest.java index 620c10465f5..2dc5add0a3a 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureComputeServiceTest.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureComputeServiceTest.java @@ -20,14 +20,10 @@ package org.elasticsearch.cloud.azure; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; -import org.elasticsearch.cloud.azure.AzureModule; -import org.elasticsearch.cloud.azure.management.AzureComputeService; import org.elasticsearch.cloud.azure.management.AzureComputeService.Discovery; import org.elasticsearch.cloud.azure.management.AzureComputeService.Management; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugin.cloud.azure.CloudAzurePlugin; -import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; public abstract class AbstractAzureComputeServiceTest extends ESIntegTestCase { diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureRepositoryServiceTest.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureRepositoryServiceTest.java index 9fae8158c3d..fa4131cf7d0 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureRepositoryServiceTest.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureRepositoryServiceTest.java @@ -26,7 +26,7 @@ import org.elasticsearch.cloud.azure.storage.AzureStorageServiceMock; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugin.cloud.azure.CloudAzurePlugin; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoryMissingException; import org.elasticsearch.test.store.MockFSDirectoryService; import org.junit.After; @@ -36,7 +36,7 @@ import java.net.URISyntaxException; public abstract class AbstractAzureRepositoryServiceTest extends AbstractAzureTest { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "mock-stoarge-service"; @@ -77,7 +77,7 @@ public abstract class AbstractAzureRepositoryServiceTest extends AbstractAzureTe @Override protected Settings nodeSettings(int nodeOrdinal) { Settings.Builder builder = Settings.settingsBuilder() - .extendArray("plugin.types", CloudAzurePlugin.class.getName(), Plugin.class.getName()) + .extendArray("plugin.types", CloudAzurePlugin.class.getName(), TestPlugin.class.getName()) .put(Storage.API_IMPLEMENTATION, mock) .put(Storage.CONTAINER, "snapshots"); diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AzureComputeServiceSimpleMock.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AzureComputeServiceSimpleMock.java index 2f161bbd602..6323e91d1df 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AzureComputeServiceSimpleMock.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AzureComputeServiceSimpleMock.java @@ -19,12 +19,16 @@ package org.elasticsearch.cloud.azure; -import com.microsoft.windowsazure.management.compute.models.*; +import com.microsoft.windowsazure.management.compute.models.DeploymentSlot; +import com.microsoft.windowsazure.management.compute.models.DeploymentStatus; +import com.microsoft.windowsazure.management.compute.models.HostedServiceGetDetailedResponse; +import com.microsoft.windowsazure.management.compute.models.InstanceEndpoint; +import com.microsoft.windowsazure.management.compute.models.RoleInstance; import org.elasticsearch.cloud.azure.management.AzureComputeServiceAbstractMock; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.CollectionUtils; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import java.net.InetAddress; @@ -33,7 +37,7 @@ import java.net.InetAddress; */ public class AzureComputeServiceSimpleMock extends AzureComputeServiceAbstractMock { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "mock-compute-service"; diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AzureComputeServiceTwoNodesMock.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AzureComputeServiceTwoNodesMock.java index e8f7fa9e37c..a87a4ef3434 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AzureComputeServiceTwoNodesMock.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AzureComputeServiceTwoNodesMock.java @@ -20,13 +20,11 @@ package org.elasticsearch.cloud.azure; import com.microsoft.windowsazure.management.compute.models.*; -import org.elasticsearch.cloud.azure.AzureModule; import org.elasticsearch.cloud.azure.management.AzureComputeServiceAbstractMock; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.CollectionUtils; -import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.plugins.Plugin; import java.net.InetAddress; @@ -36,7 +34,7 @@ import java.net.InetAddress; * Mock Azure API with two started nodes */ public class AzureComputeServiceTwoNodesMock extends AzureComputeServiceAbstractMock { - public static class Plugin extends AbstractPlugin { + public static class TestPlugin extends Plugin { @Override public String name() { return "mock-compute-service"; diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureMinimumMasterNodesTest.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureMinimumMasterNodesTest.java index c0cde86ccc6..2cbdf4eaa3b 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureMinimumMasterNodesTest.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureMinimumMasterNodesTest.java @@ -44,7 +44,7 @@ import static org.hamcrest.Matchers.nullValue; public class AzureMinimumMasterNodesTest extends AbstractAzureComputeServiceTest { public AzureMinimumMasterNodesTest() { - super(AzureComputeServiceTwoNodesMock.Plugin.class.getName()); + super(AzureComputeServiceTwoNodesMock.TestPlugin.class.getName()); } @Override diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureSimpleTest.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureSimpleTest.java index d99267e3b90..be69bde31ff 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureSimpleTest.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureSimpleTest.java @@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.notNullValue; public class AzureSimpleTest extends AbstractAzureComputeServiceTest { public AzureSimpleTest() { - super(AzureComputeServiceSimpleMock.Plugin.class.getName()); + super(AzureComputeServiceSimpleMock.TestPlugin.class.getName()); } @Test diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureTwoStartedNodesTest.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureTwoStartedNodesTest.java index 818d828197a..f5ec7427cfb 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureTwoStartedNodesTest.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureTwoStartedNodesTest.java @@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.notNullValue; public class AzureTwoStartedNodesTest extends AbstractAzureComputeServiceTest { public AzureTwoStartedNodesTest() { - super(AzureComputeServiceTwoNodesMock.Plugin.class.getName()); + super(AzureComputeServiceTwoNodesMock.TestPlugin.class.getName()); } @Test diff --git a/plugins/cloud-gce/src/main/java/org/elasticsearch/plugin/cloud/gce/CloudGcePlugin.java b/plugins/cloud-gce/src/main/java/org/elasticsearch/plugin/cloud/gce/CloudGcePlugin.java index 9eacfbe9cde..8b2a3d27da3 100644 --- a/plugins/cloud-gce/src/main/java/org/elasticsearch/plugin/cloud/gce/CloudGcePlugin.java +++ b/plugins/cloud-gce/src/main/java/org/elasticsearch/plugin/cloud/gce/CloudGcePlugin.java @@ -25,7 +25,7 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.gce.GceDiscovery; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import java.util.ArrayList; import java.util.Collection; @@ -34,7 +34,7 @@ import java.util.List; /** * */ -public class CloudGcePlugin extends AbstractPlugin { +public class CloudGcePlugin extends Plugin { private final Settings settings; diff --git a/plugins/delete-by-query/src/main/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryPlugin.java b/plugins/delete-by-query/src/main/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryPlugin.java index 84e15d364bf..7e50e932bf6 100644 --- a/plugins/delete-by-query/src/main/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryPlugin.java +++ b/plugins/delete-by-query/src/main/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryPlugin.java @@ -20,12 +20,12 @@ package org.elasticsearch.plugin.deletebyquery; import org.elasticsearch.common.inject.Module; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import java.util.Collection; import java.util.Collections; -public class DeleteByQueryPlugin extends AbstractPlugin { +public class DeleteByQueryPlugin extends Plugin { public static final String NAME = "delete-by-query"; diff --git a/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/ExamplePluginConfiguration.java b/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/ExamplePluginConfiguration.java index 8b8dc255935..430d880766c 100644 --- a/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/ExamplePluginConfiguration.java +++ b/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/ExamplePluginConfiguration.java @@ -20,28 +20,17 @@ package org.elasticsearch.plugin.example; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.multibindings.Multibinder; -import org.elasticsearch.common.inject.name.Names; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.yaml.YamlXContent; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.env.Environment; -import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.rest.action.cat.AbstractCatAction; import java.io.IOException; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; - -import static org.elasticsearch.common.io.Streams.copyToString; import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.file.Files.newBufferedReader; +import static org.elasticsearch.common.io.Streams.copyToString; /** * Example configuration. diff --git a/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java b/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java index 292788f97a4..fc9de8912d6 100644 --- a/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java +++ b/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java @@ -36,7 +36,7 @@ import java.util.Collections; /** * Example of a plugin. */ -public class JvmExamplePlugin implements Plugin { +public class JvmExamplePlugin extends Plugin { private final Settings settings; @@ -66,7 +66,7 @@ public class JvmExamplePlugin implements Plugin { } @Override - public Collection indexModules() { + public Collection indexModules(Settings indexSettings) { return Collections.emptyList(); } @@ -76,7 +76,7 @@ public class JvmExamplePlugin implements Plugin { } @Override - public Collection shardModules() { + public Collection shardModules(Settings indexSettings) { return Collections.emptyList(); } diff --git a/plugins/lang-javascript/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java index 0b4ffd7fae5..a6832fe7afe 100644 --- a/plugins/lang-javascript/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java +++ b/plugins/lang-javascript/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java @@ -19,14 +19,14 @@ package org.elasticsearch.plugin.javascript; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.javascript.JavaScriptScriptEngineService; /** * */ -public class JavaScriptPlugin extends AbstractPlugin { +public class JavaScriptPlugin extends Plugin { @Override public String name() { diff --git a/plugins/lang-python/src/main/java/org/elasticsearch/plugin/python/PythonPlugin.java b/plugins/lang-python/src/main/java/org/elasticsearch/plugin/python/PythonPlugin.java index 78f05311a6f..28dad5135ab 100644 --- a/plugins/lang-python/src/main/java/org/elasticsearch/plugin/python/PythonPlugin.java +++ b/plugins/lang-python/src/main/java/org/elasticsearch/plugin/python/PythonPlugin.java @@ -19,14 +19,14 @@ package org.elasticsearch.plugin.python; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.python.PythonScriptEngineService; /** * */ -public class PythonPlugin extends AbstractPlugin { +public class PythonPlugin extends Plugin { @Override public String name() { diff --git a/plugins/mapper-size/src/main/java/org/elasticsearch/plugin/mapper/MapperSizePlugin.java b/plugins/mapper-size/src/main/java/org/elasticsearch/plugin/mapper/MapperSizePlugin.java index a89e9084962..df95a4e9e67 100644 --- a/plugins/mapper-size/src/main/java/org/elasticsearch/plugin/mapper/MapperSizePlugin.java +++ b/plugins/mapper-size/src/main/java/org/elasticsearch/plugin/mapper/MapperSizePlugin.java @@ -20,12 +20,13 @@ package org.elasticsearch.plugin.mapper; import org.elasticsearch.common.inject.Module; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.plugins.Plugin; import java.util.Collection; import java.util.Collections; -public class MapperSizePlugin extends AbstractPlugin { +public class MapperSizePlugin extends Plugin { @Override public String name() { @@ -38,7 +39,7 @@ public class MapperSizePlugin extends AbstractPlugin { } @Override - public Collection indexModules() { + public Collection indexModules(Settings indexSettings) { return Collections.singletonList(new MapperSizeIndexModule()); } From d7bf510fe03d062a6601fa9af196dce67f43e80f Mon Sep 17 00:00:00 2001 From: kakakakakku Date: Tue, 18 Aug 2015 15:35:04 +0900 Subject: [PATCH 08/54] Fixed section name and api name in docs --- docs/reference/docs/update.asciidoc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/reference/docs/update.asciidoc b/docs/reference/docs/update.asciidoc index ada9e283a45..06958b4e624 100644 --- a/docs/reference/docs/update.asciidoc +++ b/docs/reference/docs/update.asciidoc @@ -114,7 +114,7 @@ If both `doc` and `script` is specified, then `doc` is ignored. Best is to put your field pairs of the partial document in the script itself. [float] -=== `detect_noop` +=== Detecting noop By default if `doc` is specified then the document is always updated even if the merging process doesn't cause any changes. Specifying `detect_noop` @@ -247,12 +247,10 @@ return the full updated source. `version` & `version_type`:: -The Update API uses the Elasticsearch's versioning support internally to make +The update API uses the Elasticsearch's versioning support internally to make sure the document doesn't change during the update. You can use the `version` parameter to specify that the document should only be updated if it's version matches the one specified. By setting version type to `force` you can force the new version of the document after update (use with care! with `force` there is no guarantee the document didn't change).Version types `external` & `external_gte` are not supported. - - From 975eb60a1247066bcdfdb2fbd07dfa40892e15d0 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Tue, 18 Aug 2015 11:53:49 +0200 Subject: [PATCH 09/54] [doc] we don't use `check_lucene` anymore in plugins --- docs/plugins/plugin-script.asciidoc | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/docs/plugins/plugin-script.asciidoc b/docs/plugins/plugin-script.asciidoc index ce6bbf6d955..06263d730ad 100644 --- a/docs/plugins/plugin-script.asciidoc +++ b/docs/plugins/plugin-script.asciidoc @@ -223,18 +223,3 @@ plugin.mandatory: mapper-attachments,lang-groovy For safety reasons, a node will not start if it is missing a mandatory plugin. -[float] -=== Lucene version dependent plugins - -For some plugins, such as analysis plugins, a specific major Lucene version is -required to run. In that case, the plugin provides in its -`es-plugin.properties` file the Lucene version for which the plugin was built for. - -If present at startup the node will check the Lucene version before loading -the plugin. You can disable that check using - -[source,yaml] --------------------------------------------------- -plugins.check_lucene: false --------------------------------------------------- - From 44e6d1aac65c5a8667bd78ee2a623118406f1866 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Tue, 18 Aug 2015 13:00:04 +0200 Subject: [PATCH 10/54] [doc] Move mapper attachment plugin to mapper page --- docs/plugins/api.asciidoc | 6 ------ docs/plugins/mapper.asciidoc | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/plugins/api.asciidoc b/docs/plugins/api.asciidoc index 343d246ae2d..9e3b8f34da4 100644 --- a/docs/plugins/api.asciidoc +++ b/docs/plugins/api.asciidoc @@ -15,12 +15,6 @@ The delete by query plugin adds support for deleting all of the documents replacement for the problematic _delete-by-query_ functionality which has been removed from Elasticsearch core. -https://github.com/elasticsearch/elasticsearch-mapper-attachments[Mapper Attachments Type plugin]:: - -Integrates http://lucene.apache.org/tika/[Apache Tika] to provide a new field -type `attachment` to allow indexing of documents such as PDFs and Microsoft -Word. - [float] === Community contributed API extension plugins diff --git a/docs/plugins/mapper.asciidoc b/docs/plugins/mapper.asciidoc index 226fc4e40d0..c6a3a7b35aa 100644 --- a/docs/plugins/mapper.asciidoc +++ b/docs/plugins/mapper.asciidoc @@ -8,6 +8,12 @@ Mapper plugins allow new field datatypes to be added to Elasticsearch. The core mapper plugins are: +https://github.com/elasticsearch/elasticsearch-mapper-attachments[Mapper Attachments Type plugin]:: + +Integrates http://lucene.apache.org/tika/[Apache Tika] to provide a new field +type `attachment` to allow indexing of documents such as PDFs and Microsoft +Word. + <>:: The mapper-size plugin provides the `_size` meta field which, when enabled, From 717a6dd092711d3c5f6f50fdcfe7a9edc473a6ef Mon Sep 17 00:00:00 2001 From: David Pilato Date: Tue, 18 Aug 2015 13:12:58 +0200 Subject: [PATCH 11/54] [doc] Backport change in cloud-aws doc Related to https://github.com/elastic/elasticsearch/pull/12761 --- docs/plugins/cloud-aws.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/plugins/cloud-aws.asciidoc b/docs/plugins/cloud-aws.asciidoc index 34cac7976f7..7b0fee374e3 100644 --- a/docs/plugins/cloud-aws.asciidoc +++ b/docs/plugins/cloud-aws.asciidoc @@ -259,8 +259,8 @@ The following settings are supported: `base_path`:: - Specifies the path within bucket to repository data. Defaults to root - directory. + Specifies the path within bucket to repository data. Defaults to + value of `repositories.s3.base_path` or to root directory if not set. `access_key`:: From 05678bc10ae61bba29db33ec76cad97b3d66226a Mon Sep 17 00:00:00 2001 From: David Pilato Date: Tue, 18 Aug 2015 13:18:39 +0200 Subject: [PATCH 12/54] [doc] Fix cloud-azure install / remove instructions --- docs/plugins/cloud-azure.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/plugins/cloud-azure.asciidoc b/docs/plugins/cloud-azure.asciidoc index 151cd3380c6..80fd189ad2e 100644 --- a/docs/plugins/cloud-azure.asciidoc +++ b/docs/plugins/cloud-azure.asciidoc @@ -13,7 +13,7 @@ This plugin can be installed using the plugin manager: [source,sh] ---------------------------------------------------------------- -sudo bin/plugin install cloud-aws +sudo bin/plugin install cloud-azure ---------------------------------------------------------------- The plugin must be installed on every node in the cluster, and each node must @@ -27,7 +27,7 @@ The plugin can be removed with the following command: [source,sh] ---------------------------------------------------------------- -sudo bin/plugin remove cloud-aws +sudo bin/plugin remove cloud-azure ---------------------------------------------------------------- The node must be stopped before removing the plugin. From 2b6c5762f4fee1e42fa6b75e3710d75086cd65b7 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 14 Aug 2015 16:21:55 +0200 Subject: [PATCH 13/54] [build] display ignored artifact when checking licenses --- .../src/main/resources/license-check/check_license_and_sha.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/dev-tools/src/main/resources/license-check/check_license_and_sha.pl b/dev-tools/src/main/resources/license-check/check_license_and_sha.pl index 9263244dd2b..4d9d5ba06b8 100755 --- a/dev-tools/src/main/resources/license-check/check_license_and_sha.pl +++ b/dev-tools/src/main/resources/license-check/check_license_and_sha.pl @@ -30,6 +30,7 @@ $Source = File::Spec->rel2abs($Source); say "LICENSE DIR: $License_Dir"; say "SOURCE: $Source"; +say "IGNORE: $Ignore"; die "License dir is not a directory: $License_Dir\n" . usage() unless -d $License_Dir; From 0bb9593596aabdacb4d4b3dafa391307815bb6e2 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 14 Aug 2015 16:22:46 +0200 Subject: [PATCH 14/54] Fix a typo in comment --- core/src/main/java/org/elasticsearch/plugins/PluginManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java index a692504664d..9553ac7a0e3 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java @@ -453,7 +453,7 @@ public class PluginManager { List urls() { List urls = new ArrayList<>(); if (version != null) { - // Elasticsearch new download service uses groupId org.elasticsearch.plugins from 2.0.0 + // Elasticsearch new download service uses groupId org.elasticsearch.plugin from 2.0.0 if (user == null) { // TODO Update to https if (!Strings.isNullOrEmpty(System.getProperty(PROPERTY_SUPPORT_STAGING_URLS))) { From d21afc8090a91dffb4883cf6e0cae293e4a68e60 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 14 Aug 2015 16:52:55 +0200 Subject: [PATCH 15/54] [maven] rename artifactIds from `elasticsearch-something` to `something` In plugins, we are using non consistent naming. We use `elasticsearch-cloud-aws` as the artifactId, which generates a jar file called `elasticsearch-cloud-aws-VERSION.jar`. But when you want to install the plugin, you will end up with a shorter name for the plugin `cloud-aws`. ``` bin/plugin install cloud-aws ``` This commit changes that and use consistent names for `artifactId`, so `finalName`. Also changed maven names. --- migrate.sh | 2 +- plugins/analysis-icu/pom.xml | 6 +++--- plugins/analysis-kuromoji/pom.xml | 7 +++---- plugins/analysis-phonetic/pom.xml | 6 +++--- plugins/analysis-smartcn/pom.xml | 6 +++--- plugins/analysis-stempel/pom.xml | 6 +++--- plugins/cloud-aws/pom.xml | 6 +++--- plugins/cloud-azure/pom.xml | 6 +++--- plugins/cloud-gce/pom.xml | 6 +++--- plugins/delete-by-query/pom.xml | 6 +++--- plugins/jvm-example/pom.xml | 6 +++--- plugins/lang-javascript/pom.xml | 6 +++--- plugins/lang-python/pom.xml | 6 +++--- plugins/mapper-size/pom.xml | 6 +++--- plugins/pom.xml | 4 ++-- plugins/site-example/pom.xml | 6 +++--- pom.xml | 1 + qa/smoke-test-plugins/pom.xml | 28 ++++++++++++++-------------- 18 files changed, 60 insertions(+), 60 deletions(-) diff --git a/migrate.sh b/migrate.sh index c8f80ccd828..a47e73c0482 100755 --- a/migrate.sh +++ b/migrate.sh @@ -68,7 +68,7 @@ function migratePlugin() { mkdir -p plugins/$1 git mv -k * plugins/$1 > /dev/null 2>/dev/null git rm .gitignore > /dev/null 2>/dev/null - # echo "### change $1 groupId to org.elasticsearch.plugins" + # echo "### change $1 groupId to org.elasticsearch.plugin" # Change the groupId to avoid conflicts with existing 2.0.0 versions. replaceLine " org.elasticsearch<\/groupId>" " org.elasticsearch.plugin<\/groupId>" "plugins/$1/pom.xml" diff --git a/plugins/analysis-icu/pom.xml b/plugins/analysis-icu/pom.xml index a25f6f350f5..b13f69dbd53 100644 --- a/plugins/analysis-icu/pom.xml +++ b/plugins/analysis-icu/pom.xml @@ -6,12 +6,12 @@ org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-analysis-icu - Elasticsearch ICU Analysis plugin + analysis-icu + Plugin: Analysis: ICU The ICU Analysis plugin integrates Lucene ICU module into elasticsearch, adding ICU relates analysis components. diff --git a/plugins/analysis-kuromoji/pom.xml b/plugins/analysis-kuromoji/pom.xml index d6e87ad17d9..71d290fddc1 100644 --- a/plugins/analysis-kuromoji/pom.xml +++ b/plugins/analysis-kuromoji/pom.xml @@ -6,13 +6,12 @@ org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-analysis-kuromoji - jar - Elasticsearch Japanese (kuromoji) Analysis plugin + analysis-kuromoji + Plugin: Analysis: Japanese (kuromoji) The Japanese (kuromoji) Analysis plugin integrates Lucene kuromoji analysis module into elasticsearch. diff --git a/plugins/analysis-phonetic/pom.xml b/plugins/analysis-phonetic/pom.xml index ae3b7917872..a5b726ecf7d 100644 --- a/plugins/analysis-phonetic/pom.xml +++ b/plugins/analysis-phonetic/pom.xml @@ -6,12 +6,12 @@ org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-analysis-phonetic - Elasticsearch Phonetic Analysis plugin + analysis-phonetic + Plugin: Analysis: Phonetic The Phonetic Analysis plugin integrates phonetic token filter analysis with elasticsearch. diff --git a/plugins/analysis-smartcn/pom.xml b/plugins/analysis-smartcn/pom.xml index a25e787cccb..294dbaa4b7a 100644 --- a/plugins/analysis-smartcn/pom.xml +++ b/plugins/analysis-smartcn/pom.xml @@ -6,12 +6,12 @@ org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-analysis-smartcn - Elasticsearch Smart Chinese Analysis plugin + analysis-smartcn + Plugin: Analysis: Smart Chinese (smartcn) Smart Chinese Analysis plugin integrates Lucene Smart Chinese analysis module into elasticsearch. diff --git a/plugins/analysis-stempel/pom.xml b/plugins/analysis-stempel/pom.xml index 7fcce1d14af..139e3dbd908 100644 --- a/plugins/analysis-stempel/pom.xml +++ b/plugins/analysis-stempel/pom.xml @@ -6,12 +6,12 @@ org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-analysis-stempel - Elasticsearch Stempel (Polish) Analysis plugin + analysis-stempel + Plugin: Analysis: Polish (stempel) The Stempel (Polish) Analysis plugin integrates Lucene stempel (polish) analysis module into elasticsearch. diff --git a/plugins/cloud-aws/pom.xml b/plugins/cloud-aws/pom.xml index 03d157eadff..157a35077d8 100644 --- a/plugins/cloud-aws/pom.xml +++ b/plugins/cloud-aws/pom.xml @@ -6,12 +6,12 @@ org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-cloud-aws - Elasticsearch AWS cloud plugin + cloud-aws + Plugin: Cloud: AWS The Amazon Web Service (AWS) Cloud plugin allows to use AWS API for the unicast discovery mechanism and add S3 repositories. diff --git a/plugins/cloud-azure/pom.xml b/plugins/cloud-azure/pom.xml index c7c83816320..f7fa9dceb2d 100644 --- a/plugins/cloud-azure/pom.xml +++ b/plugins/cloud-azure/pom.xml @@ -17,12 +17,12 @@ governing permissions and limitations under the License. --> org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-cloud-azure - Elasticsearch Azure cloud plugin + cloud-azure + Plugin: Cloud: Azure The Azure Cloud plugin allows to use Azure API for the unicast discovery mechanism and add Azure storage repositories. diff --git a/plugins/cloud-gce/pom.xml b/plugins/cloud-gce/pom.xml index 1d62fdb327e..724036aafcd 100644 --- a/plugins/cloud-gce/pom.xml +++ b/plugins/cloud-gce/pom.xml @@ -17,12 +17,12 @@ governing permissions and limitations under the License. --> org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-cloud-gce - Elasticsearch Google Compute Engine cloud plugin + cloud-gce + Plugin: Cloud: Google Compute Engine The Google Compute Engine (GCE) Cloud plugin allows to use GCE API for the unicast discovery mechanism. diff --git a/plugins/delete-by-query/pom.xml b/plugins/delete-by-query/pom.xml index d7ea468088e..07d3bb8fbe8 100644 --- a/plugins/delete-by-query/pom.xml +++ b/plugins/delete-by-query/pom.xml @@ -17,12 +17,12 @@ governing permissions and limitations under the License. --> org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-delete-by-query - Elasticsearch Delete By Query plugin + delete-by-query + Plugin: Delete By Query The Delete By Query plugin allows to delete documents in Elasticsearch with a single query. diff --git a/plugins/jvm-example/pom.xml b/plugins/jvm-example/pom.xml index 0bfd84b82b9..be67cf54eb1 100644 --- a/plugins/jvm-example/pom.xml +++ b/plugins/jvm-example/pom.xml @@ -6,12 +6,12 @@ org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-jvm-example - Elasticsearch example JVM plugin + jvm-example + Plugin: JVM example Demonstrates all the pluggable Java entry points in Elasticsearch diff --git a/plugins/lang-javascript/pom.xml b/plugins/lang-javascript/pom.xml index f283aa73989..eaaa29a34b7 100644 --- a/plugins/lang-javascript/pom.xml +++ b/plugins/lang-javascript/pom.xml @@ -6,12 +6,12 @@ org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-lang-javascript - Elasticsearch JavaScript language plugin + lang-javascript + Plugin: Language: JavaScript The JavaScript language plugin allows to have javascript as the language of scripts to execute. diff --git a/plugins/lang-python/pom.xml b/plugins/lang-python/pom.xml index 704aff5379c..7b44f61889b 100644 --- a/plugins/lang-python/pom.xml +++ b/plugins/lang-python/pom.xml @@ -6,12 +6,12 @@ org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-lang-python - Elasticsearch Python language plugin + lang-python + Plugin: Language: Python The Python language plugin allows to have python as the language of scripts to execute. diff --git a/plugins/mapper-size/pom.xml b/plugins/mapper-size/pom.xml index 2ec3d475e2b..bd483e1868d 100644 --- a/plugins/mapper-size/pom.xml +++ b/plugins/mapper-size/pom.xml @@ -17,12 +17,12 @@ governing permissions and limitations under the License. --> org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-mapper-size - Elasticsearch Mapper size plugin + mapper-size + Plugin: Mapper: Size The Mapper Size plugin allows document to record their uncompressed size at index time. diff --git a/plugins/pom.xml b/plugins/pom.xml index fbf88b089fe..f9a976b4946 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -6,10 +6,10 @@ 4.0.0 org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT pom - Elasticsearch Plugin POM + Plugin: Parent POM 2009 A parent project for Elasticsearch plugins diff --git a/plugins/site-example/pom.xml b/plugins/site-example/pom.xml index f346678ffc0..3c25d5ae130 100644 --- a/plugins/site-example/pom.xml +++ b/plugins/site-example/pom.xml @@ -6,12 +6,12 @@ org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-site-example - Elasticsearch Example site plugin + site-example + Plugin: Example site Demonstrates how to serve resources via elasticsearch. diff --git a/pom.xml b/pom.xml index 47f6779ef46..787a4b07f0e 100644 --- a/pom.xml +++ b/pom.xml @@ -1216,6 +1216,7 @@ org.eclipse.jdt.ui.text.custom_code_templates= + diff --git a/qa/smoke-test-plugins/pom.xml b/qa/smoke-test-plugins/pom.xml index b56bc35e57b..5fed8b67d6e 100644 --- a/qa/smoke-test-plugins/pom.xml +++ b/qa/smoke-test-plugins/pom.xml @@ -247,7 +247,7 @@ org.elasticsearch.plugin - elasticsearch-analysis-kuromoji + analysis-kuromoji ${elasticsearch.version} zip true @@ -255,7 +255,7 @@ org.elasticsearch.plugin - elasticsearch-analysis-smartcn + analysis-smartcn ${elasticsearch.version} zip true @@ -263,7 +263,7 @@ org.elasticsearch.plugin - elasticsearch-analysis-stempel + analysis-stempel ${elasticsearch.version} zip true @@ -271,7 +271,7 @@ org.elasticsearch.plugin - elasticsearch-analysis-phonetic + analysis-phonetic ${elasticsearch.version} zip true @@ -279,7 +279,7 @@ org.elasticsearch.plugin - elasticsearch-analysis-icu + analysis-icu ${elasticsearch.version} zip true @@ -287,7 +287,7 @@ org.elasticsearch.plugin - elasticsearch-cloud-gce + cloud-gce ${elasticsearch.version} zip true @@ -295,7 +295,7 @@ org.elasticsearch.plugin - elasticsearch-cloud-azure + cloud-azure ${elasticsearch.version} zip true @@ -303,7 +303,7 @@ org.elasticsearch.plugin - elasticsearch-cloud-aws + cloud-aws ${elasticsearch.version} zip true @@ -311,7 +311,7 @@ org.elasticsearch.plugin - elasticsearch-delete-by-query + delete-by-query ${elasticsearch.version} zip true @@ -319,7 +319,7 @@ org.elasticsearch.plugin - elasticsearch-lang-python + lang-python ${elasticsearch.version} zip true @@ -327,7 +327,7 @@ org.elasticsearch.plugin - elasticsearch-lang-javascript + lang-javascript ${elasticsearch.version} zip true @@ -343,7 +343,7 @@ org.elasticsearch.plugin - elasticsearch-mapper-size + mapper-size ${elasticsearch.version} zip true @@ -351,7 +351,7 @@ org.elasticsearch.plugin - elasticsearch-site-example + site-example ${elasticsearch.version} zip true @@ -359,7 +359,7 @@ org.elasticsearch.plugin - elasticsearch-jvm-example + jvm-example ${elasticsearch.version} zip true From b5eb78875f19dad64db37ac072dc40779644b33c Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 14 Aug 2015 17:18:21 +0200 Subject: [PATCH 16/54] [maven] rename maven names / ids for distribution modules --- distribution/deb/pom.xml | 4 ++-- distribution/fully-loaded/pom.xml | 4 ++-- distribution/pom.xml | 4 ++-- distribution/rpm/pom.xml | 4 ++-- distribution/shaded/pom.xml | 4 ++-- distribution/src/main/resources/bin/elasticsearch | 2 +- distribution/tar/pom.xml | 4 ++-- distribution/zip/pom.xml | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/distribution/deb/pom.xml b/distribution/deb/pom.xml index 4f1a4b0f95b..a86fad9513d 100644 --- a/distribution/deb/pom.xml +++ b/distribution/deb/pom.xml @@ -5,13 +5,13 @@ 4.0.0 org.elasticsearch.distribution - elasticsearch-distribution + distributions 2.1.0-SNAPSHOT org.elasticsearch.distribution.deb elasticsearch - Elasticsearch DEB Distribution + Distribution: Deb diff --git a/distribution/rpm/pom.xml b/distribution/rpm/pom.xml index cd8f321689e..488ed97ac04 100644 --- a/distribution/rpm/pom.xml +++ b/distribution/rpm/pom.xml @@ -5,13 +5,13 @@ 4.0.0 org.elasticsearch.distribution - elasticsearch-distribution + distributions 2.1.0-SNAPSHOT org.elasticsearch.distribution.rpm elasticsearch - Elasticsearch RPM Distribution + Distribution: RPM rpm The RPM distribution of Elasticsearch diff --git a/distribution/shaded/pom.xml b/distribution/shaded/pom.xml index a0624745e03..6a4b54f7b18 100644 --- a/distribution/shaded/pom.xml +++ b/distribution/shaded/pom.xml @@ -5,13 +5,13 @@ 4.0.0 org.elasticsearch.distribution - elasticsearch-distribution + distributions 2.1.0-SNAPSHOT org.elasticsearch.distribution.shaded elasticsearch - Elasticsearch Shaded Distribution + Distribution: Shaded JAR diff --git a/distribution/src/main/resources/bin/elasticsearch b/distribution/src/main/resources/bin/elasticsearch index f35e2d29a1e..2d831485a33 100755 --- a/distribution/src/main/resources/bin/elasticsearch +++ b/distribution/src/main/resources/bin/elasticsearch @@ -47,7 +47,7 @@ # hasn't been done, we assume that this is not a packaged version and the # user has forgotten to run Maven to create a package. IS_PACKAGED_VERSION='${project.parent.artifactId}' -if [ "$IS_PACKAGED_VERSION" != "elasticsearch-distribution" ]; then +if [ "$IS_PACKAGED_VERSION" != "distributions" ]; then cat >&2 << EOF Error: You must build the project with Maven or download a pre-built package before you can run Elasticsearch. See 'Building from Source' in README.textile diff --git a/distribution/tar/pom.xml b/distribution/tar/pom.xml index d84450b1d22..33181b281ab 100644 --- a/distribution/tar/pom.xml +++ b/distribution/tar/pom.xml @@ -5,13 +5,13 @@ 4.0.0 org.elasticsearch.distribution - elasticsearch-distribution + distributions 2.1.0-SNAPSHOT org.elasticsearch.distribution.tar elasticsearch - Elasticsearch TAR Distribution + Distribution: TAR diff --git a/rest-api-spec/pom.xml b/rest-api-spec/pom.xml index 32f231a0252..4adc4600aa7 100644 --- a/rest-api-spec/pom.xml +++ b/rest-api-spec/pom.xml @@ -1,7 +1,7 @@ 4.0.0 org.elasticsearch - elasticsearch-rest-api-spec + rest-api-spec 2.1.0-SNAPSHOT Rest API Specification REST API Specification and tests for use with the Elasticsearch REST Test framework From 692cc80523c94677ad2f987a1959b21765b26922 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Tue, 18 Aug 2015 11:02:23 +0200 Subject: [PATCH 22/54] [maven] also rename parent project artifactId Also fixed bad scm links --- core/pom.xml | 2 +- distribution/pom.xml | 2 +- plugins/pom.xml | 2 +- pom.xml | 8 ++++---- qa/pom.xml | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 7de340bf3a7..5c0dd2555c6 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.elasticsearch - elasticsearch-parent + parent 2.1.0-SNAPSHOT diff --git a/distribution/pom.xml b/distribution/pom.xml index 7e8c52e1caa..52969ee779c 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.elasticsearch - elasticsearch-parent + parent 2.1.0-SNAPSHOT diff --git a/plugins/pom.xml b/plugins/pom.xml index f9a976b4946..e87ef1e0678 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -15,7 +15,7 @@ org.elasticsearch - elasticsearch-parent + parent 2.1.0-SNAPSHOT diff --git a/pom.xml b/pom.xml index 7c6fa5840e0..71129a6689c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.elasticsearch - elasticsearch-parent + parent 2.1.0-SNAPSHOT pom Elasticsearch: Parent POM @@ -27,9 +27,9 @@ - scm:git:git@github.com:elasticsearch/elasticsearch-parent.git - scm:git:git@github.com:elasticsearch/elasticsearch-parent.git - http://github.com/elasticsearch/elasticsearch-parent + scm:git:git@github.com:elastic/elasticsearch.git + scm:git:git@github.com:elastic/elasticsearch.git + http://github.com/elastic/elasticsearch diff --git a/qa/pom.xml b/qa/pom.xml index e303ee27c32..d918de924ae 100644 --- a/qa/pom.xml +++ b/qa/pom.xml @@ -14,7 +14,7 @@ org.elasticsearch - elasticsearch-parent + parent 2.1.0-SNAPSHOT From 807d35e96f21c71c4a4419cd2abc83f881a9fcfc Mon Sep 17 00:00:00 2001 From: David Pilato Date: Tue, 18 Aug 2015 13:43:10 +0200 Subject: [PATCH 23/54] [maven] change murmur3 plugin groupId and name --- plugins/mapper-murmur3/pom.xml | 6 +++--- qa/smoke-test-plugins/pom.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/mapper-murmur3/pom.xml b/plugins/mapper-murmur3/pom.xml index 9d4c7db0000..9c7440d9e72 100644 --- a/plugins/mapper-murmur3/pom.xml +++ b/plugins/mapper-murmur3/pom.xml @@ -17,12 +17,12 @@ governing permissions and limitations under the License. --> org.elasticsearch.plugin - elasticsearch-plugin + plugins 2.1.0-SNAPSHOT - elasticsearch-mapper-murmur3 - Elasticsearch Mapper Murmur3 plugin + mapper-murmur3 + Plugin: Mapper: Murmur3 The Mapper Murmur3 plugin allows to compute hashes of a field's values at index-time and to store them in the index. diff --git a/qa/smoke-test-plugins/pom.xml b/qa/smoke-test-plugins/pom.xml index 5fed8b67d6e..8a08bcd619b 100644 --- a/qa/smoke-test-plugins/pom.xml +++ b/qa/smoke-test-plugins/pom.xml @@ -335,7 +335,7 @@ org.elasticsearch.plugin - elasticsearch-mapper-murmur3 + mapper-murmur3 ${elasticsearch.version} zip true From 1e511eda28e2c91032ce1e377aaddf9b8f6030c0 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 18 Aug 2015 15:44:14 +0200 Subject: [PATCH 24/54] Remove usage or `InetAddress#getLocalHost` this method is very confusing and if it's used it's likely the wrong thing with respect to the actual bound / published address. This change discourages it's use and removes all useage. It's replaced with the actual published address most of the time. --- .../cluster/node/DiscoveryNode.java | 2 +- .../cluster/service/InternalClusterService.java | 5 ++++- .../common/network/NetworkUtils.java | 11 ----------- .../common/transport/DummyTransportAddress.java | 15 +++++++++++++++ .../transport/InetSocketTransportAddress.java | 17 ++++++++++++++++- .../common/transport/LocalTransportAddress.java | 17 ++++++++++++++++- .../common/transport/TransportAddress.java | 17 +++++++++++++++++ .../allocation/decider/MockDiskUsagesIT.java | 3 ++- .../elasticsearch/test/InternalTestCluster.java | 2 +- .../main/resources/forbidden/all-signatures.txt | 3 +++ 10 files changed, 75 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index 87fe5017fa6..cc5ff81e8d8 100644 --- a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -138,7 +138,7 @@ public class DiscoveryNode implements Streamable, ToXContent { * @param version the version of the node. */ public DiscoveryNode(String nodeName, String nodeId, TransportAddress address, Map attributes, Version version) { - this(nodeName, nodeId, NetworkUtils.getLocalHost().getHostName(), NetworkUtils.getLocalHost().getHostAddress(), address, attributes, version); + this(nodeName, nodeId, address.getHost(), address.getAddress(), address, attributes, version); } /** diff --git a/core/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java b/core/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java index 1fea2edec29..b992c3612ee 100644 --- a/core/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java +++ b/core/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java @@ -40,6 +40,8 @@ import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.text.StringText; +import org.elasticsearch.common.transport.BoundTransportAddress; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.*; import org.elasticsearch.discovery.Discovery; @@ -159,7 +161,8 @@ public class InternalClusterService extends AbstractLifecycleComponent nodeAttributes = discoveryNodeService.buildAttributes(); // note, we rely on the fact that its a new id each time we start, see FD and "kill -9" handling final String nodeId = DiscoveryService.generateNodeId(settings); - DiscoveryNode localNode = new DiscoveryNode(settings.get("name"), nodeId, transportService.boundAddress().publishAddress(), nodeAttributes, version); + final TransportAddress publishAddress = transportService.boundAddress().publishAddress(); + DiscoveryNode localNode = new DiscoveryNode(settings.get("name"), nodeId, publishAddress, nodeAttributes, version); DiscoveryNodes.Builder nodeBuilder = DiscoveryNodes.builder().put(localNode).localNodeId(localNode.id()); this.clusterState = ClusterState.builder(clusterState).nodes(nodeBuilder).blocks(initialBlocks).build(); this.transportService.setLocalNode(localNode); diff --git a/core/src/main/java/org/elasticsearch/common/network/NetworkUtils.java b/core/src/main/java/org/elasticsearch/common/network/NetworkUtils.java index 81bf63dae4f..39705e82905 100644 --- a/core/src/main/java/org/elasticsearch/common/network/NetworkUtils.java +++ b/core/src/main/java/org/elasticsearch/common/network/NetworkUtils.java @@ -127,17 +127,6 @@ public abstract class NetworkUtils { return Constants.WINDOWS ? false : true; } - /** Returns localhost, or if its misconfigured, falls back to loopback. Use with caution!!!! */ - // TODO: can we remove this? - public static InetAddress getLocalHost() { - try { - return InetAddress.getLocalHost(); - } catch (UnknownHostException e) { - logger.warn("failed to resolve local host, fallback to loopback", e); - return InetAddress.getLoopbackAddress(); - } - } - /** Returns addresses for all loopback interfaces that are up. */ public static InetAddress[] getLoopbackAddresses() throws SocketException { List list = new ArrayList<>(); diff --git a/core/src/main/java/org/elasticsearch/common/transport/DummyTransportAddress.java b/core/src/main/java/org/elasticsearch/common/transport/DummyTransportAddress.java index 47f089a1e14..74bcfecdc69 100644 --- a/core/src/main/java/org/elasticsearch/common/transport/DummyTransportAddress.java +++ b/core/src/main/java/org/elasticsearch/common/transport/DummyTransportAddress.java @@ -44,6 +44,21 @@ public class DummyTransportAddress implements TransportAddress { return other == INSTANCE; } + @Override + public String getHost() { + return "dummy"; + } + + @Override + public String getAddress() { + return "0.0.0.0"; // see https://en.wikipedia.org/wiki/0.0.0.0 + } + + @Override + public int getPort() { + return 42; + } + @Override public DummyTransportAddress readFrom(StreamInput in) throws IOException { return INSTANCE; diff --git a/core/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java b/core/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java index a13e24f3c3b..f4f686ff2e5 100644 --- a/core/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java +++ b/core/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java @@ -30,7 +30,7 @@ import java.net.InetSocketAddress; /** * A transport address used for IP socket address (wraps {@link java.net.InetSocketAddress}). */ -public class InetSocketTransportAddress implements TransportAddress { +public final class InetSocketTransportAddress implements TransportAddress { private static boolean resolveAddress = false; @@ -92,6 +92,21 @@ public class InetSocketTransportAddress implements TransportAddress { address.getAddress().equals(((InetSocketTransportAddress) other).address.getAddress()); } + @Override + public String getHost() { + return address.getHostName(); + } + + @Override + public String getAddress() { + return address.getAddress().getHostAddress(); + } + + @Override + public int getPort() { + return address.getPort(); + } + public InetSocketAddress address() { return this.address; } diff --git a/core/src/main/java/org/elasticsearch/common/transport/LocalTransportAddress.java b/core/src/main/java/org/elasticsearch/common/transport/LocalTransportAddress.java index 8935275e222..e3efa20af18 100644 --- a/core/src/main/java/org/elasticsearch/common/transport/LocalTransportAddress.java +++ b/core/src/main/java/org/elasticsearch/common/transport/LocalTransportAddress.java @@ -29,7 +29,7 @@ import java.io.IOException; /** * */ -public class LocalTransportAddress implements TransportAddress { +public final class LocalTransportAddress implements TransportAddress { public static final LocalTransportAddress PROTO = new LocalTransportAddress("_na"); @@ -57,6 +57,21 @@ public class LocalTransportAddress implements TransportAddress { return other instanceof LocalTransportAddress && id.equals(((LocalTransportAddress) other).id); } + @Override + public String getHost() { + return "local"; + } + + @Override + public String getAddress() { + return "0.0.0.0"; // see https://en.wikipedia.org/wiki/0.0.0.0 + } + + @Override + public int getPort() { + return 0; + } + @Override public LocalTransportAddress readFrom(StreamInput in) throws IOException { return new LocalTransportAddress(in); diff --git a/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java b/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java index c5051fadbe6..910b1fc6af2 100644 --- a/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java +++ b/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java @@ -28,7 +28,24 @@ import org.elasticsearch.common.io.stream.Writeable; */ public interface TransportAddress extends Writeable { + /** + * Returns the host string for this transport address + */ + String getHost(); + + /** + * Returns the address string for this transport address + */ + String getAddress(); + + /** + * Returns the port of this transport address if applicable + */ + int getPort(); + short uniqueAddressTypeId(); boolean sameHost(TransportAddress other); + + public String toString(); } diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/MockDiskUsagesIT.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/MockDiskUsagesIT.java index 79612d07b0e..b0ae30a06d4 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/MockDiskUsagesIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/MockDiskUsagesIT.java @@ -27,6 +27,7 @@ import org.elasticsearch.cluster.*; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.monitor.fs.FsInfo; import org.elasticsearch.test.ESIntegTestCase; import org.junit.Test; @@ -167,7 +168,7 @@ public class MockDiskUsagesIT extends ESIntegTestCase { usage.getTotalBytes(), usage.getFreeBytes(), usage.getFreeBytes()); paths[0] = path; FsInfo fsInfo = new FsInfo(System.currentTimeMillis(), paths); - return new NodeStats(new DiscoveryNode(nodeName, null, Version.V_2_0_0_beta1), + return new NodeStats(new DiscoveryNode(nodeName, DummyTransportAddress.INSTANCE, Version.CURRENT), System.currentTimeMillis(), null, null, null, null, null, fsInfo, diff --git a/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java index 9eaab6d8b4b..edf133e3fe7 100644 --- a/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -108,6 +108,7 @@ import org.junit.Assert; import java.io.Closeable; import java.io.IOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.nio.file.Path; import java.util.ArrayList; @@ -504,7 +505,6 @@ public final class InternalTestCluster extends TestCluster { public static String clusterName(String prefix, long clusterSeed) { StringBuilder builder = new StringBuilder(prefix); final int childVM = RandomizedTest.systemPropertyAsInt(SysGlobals.CHILDVM_SYSPROP_JVM_ID, 0); - builder.append('-').append(NetworkUtils.getLocalHost().getHostName()); builder.append("-CHILD_VM=[").append(childVM).append(']'); builder.append("-CLUSTER_SEED=[").append(clusterSeed).append(']'); // if multiple maven task run on a single host we better have an identifier that doesn't rely on input params diff --git a/dev-tools/src/main/resources/forbidden/all-signatures.txt b/dev-tools/src/main/resources/forbidden/all-signatures.txt index 642310519c8..f697b323569 100644 --- a/dev-tools/src/main/resources/forbidden/all-signatures.txt +++ b/dev-tools/src/main/resources/forbidden/all-signatures.txt @@ -18,6 +18,9 @@ java.net.URL#getPath() java.net.URL#getFile() +@defaultMessage Usage of getLocalHost is discouraged +java.net.InetAddress#getLocalHost() + @defaultMessage Use java.nio.file instead of java.io.File API java.util.jar.JarFile java.util.zip.ZipFile From 60f273c891230b06b12a8d44f1432b931b14d1d6 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 18 Aug 2015 17:32:20 +0200 Subject: [PATCH 25/54] Suppress forbiddenAPI in logger when using localhost --- .../elasticsearch/common/logging/Loggers.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/logging/Loggers.java b/core/src/main/java/org/elasticsearch/common/logging/Loggers.java index 8f546c93e89..de657c07be2 100644 --- a/core/src/main/java/org/elasticsearch/common/logging/Loggers.java +++ b/core/src/main/java/org/elasticsearch/common/logging/Loggers.java @@ -20,6 +20,7 @@ package org.elasticsearch.common.logging; import com.google.common.collect.Lists; +import org.apache.lucene.util.SuppressForbidden; import org.elasticsearch.common.Classes; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; @@ -74,20 +75,27 @@ public class Loggers { return getLogger(buildClassLoggerName(clazz), settings, prefixes); } + @SuppressForbidden(reason = "using localhost for logging on which host it is is fine") + private static InetAddress getHostAddress() { + try { + return InetAddress.getLocalHost(); + } catch (UnknownHostException e) { + return null; + } + } + public static ESLogger getLogger(String loggerName, Settings settings, String... prefixes) { List prefixesList = newArrayList(); if (settings.getAsBoolean("logger.logHostAddress", false)) { - try { - prefixesList.add(InetAddress.getLocalHost().getHostAddress()); - } catch (UnknownHostException e) { - // ignore + final InetAddress addr = getHostAddress(); + if (addr != null) { + prefixesList.add(addr.getHostAddress()); } } if (settings.getAsBoolean("logger.logHostName", false)) { - try { - prefixesList.add(InetAddress.getLocalHost().getHostName()); - } catch (UnknownHostException e) { - // ignore + final InetAddress addr = getHostAddress(); + if (addr != null) { + prefixesList.add(addr.getHostName()); } } String name = settings.get("name"); From e61c5ce5c3409b4fe7f3dad4eb4c572e21c9f40f Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 18 Aug 2015 09:49:58 -0700 Subject: [PATCH 26/54] Fix naming problem with test plugin --- .../java/org/elasticsearch/cluster/ClusterInfoServiceIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java b/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java index 017d261bdb2..6368e5aa1d9 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java @@ -146,7 +146,7 @@ public class ClusterInfoServiceIT extends ESIntegTestCase { return Settings.builder() // manual collection or upon cluster forming. .put(InternalClusterInfoService.INTERNAL_CLUSTER_INFO_TIMEOUT, "1s") - .putArray("plugin.types", Plugin.class.getName(), MockTransportService.TestPlugin.class.getName()) + .putArray("plugin.types", TestPlugin.class.getName(), MockTransportService.TestPlugin.class.getName()) .build(); } From 4c5cfd02cc25c08d9567653a06f5a97ccf08f21d Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 18 Aug 2015 10:13:01 -0700 Subject: [PATCH 27/54] Add javadocs to repository types registry methods --- .../elasticsearch/repositories/RepositoryTypesRegistry.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java b/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java index b1e3041e746..e66c79da06f 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java @@ -34,11 +34,16 @@ public class RepositoryTypesRegistry { private final ExtensionPoint.TypeExtensionPoint shardRepositoryTypes = new ExtensionPoint.TypeExtensionPoint<>("index_repository", IndexShardRepository.class); + /** Adds a new repository type to the registry, bound to the given implementation classes. */ public void registerRepository(String name, Class repositoryType, Class shardRepositoryType) { repositoryTypes.registerExtension(name, repositoryType); shardRepositoryTypes.registerExtension(name, shardRepositoryType); } + /** + * Looks up the given type and binds the implementation into the given binder. + * Throws an {@link IllegalArgumentException} if the given type does not exist. + */ public void bindType(Binder binder, String type) { Settings settings = Settings.builder().put("type", type).build(); repositoryTypes.bindType(binder, settings, "type", null); From 36f48ff32f0d91e43400476895d029aa630e95d2 Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Tue, 18 Aug 2015 19:13:54 +0200 Subject: [PATCH 28/54] Docs: Added removal of MVEL to migration docs --- docs/reference/migration/migrate_2_0/removals.asciidoc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/reference/migration/migrate_2_0/removals.asciidoc b/docs/reference/migration/migrate_2_0/removals.asciidoc index ab764691042..afdc109244c 100644 --- a/docs/reference/migration/migrate_2_0/removals.asciidoc +++ b/docs/reference/migration/migrate_2_0/removals.asciidoc @@ -16,6 +16,11 @@ Facets, deprecated since 1.0, have now been removed. Instead, use the much more powerful and flexible <> framework. This also means that Kibana 3 will not work with Elasticsearch 2.0. +==== MVEL has been removed + +The MVEL scripting language has been removed. The default scripting language +is now Groovy. + ==== Delete-by-query is now a plugin The old delete-by-query functionality was fast but unsafe. It could lead to From a3afe5779203aaaff50384ded3aa2369f47a79f6 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 18 Aug 2015 10:32:12 -0700 Subject: [PATCH 29/54] Fix compile failure from bad merge after renaming of ExtensionPoint.TypeExtensionPoint --- .../repositories/RepositoryTypesRegistry.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java b/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java index e66c79da06f..d2f02aa5795 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java @@ -29,10 +29,10 @@ import org.elasticsearch.index.snapshots.IndexShardRepository; */ public class RepositoryTypesRegistry { // invariant: repositories and shardRepositories have the same keyset - private final ExtensionPoint.TypeExtensionPoint repositoryTypes = - new ExtensionPoint.TypeExtensionPoint<>("repository", Repository.class); - private final ExtensionPoint.TypeExtensionPoint shardRepositoryTypes = - new ExtensionPoint.TypeExtensionPoint<>("index_repository", IndexShardRepository.class); + private final ExtensionPoint.SelectedType repositoryTypes = + new ExtensionPoint.SelectedType<>("repository", Repository.class); + private final ExtensionPoint.SelectedType shardRepositoryTypes = + new ExtensionPoint.SelectedType<>("index_repository", IndexShardRepository.class); /** Adds a new repository type to the registry, bound to the given implementation classes. */ public void registerRepository(String name, Class repositoryType, Class shardRepositoryType) { From 2a57539a285ab75f8bddbc859f743f45c69701c2 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 18 Aug 2015 10:35:37 -0700 Subject: [PATCH 30/54] Tweak exception message --- .../main/java/org/elasticsearch/plugins/PluginsService.java | 2 +- .../java/org/elasticsearch/plugins/PluginsServiceTests.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java index 1947953c35d..c1dfd7403b9 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -210,7 +210,7 @@ public class PluginsService extends AbstractComponent { String oldPlugin = foundSettings.put(setting, plugin.v1().getName()); if (oldPlugin != null) { throw new IllegalArgumentException("Cannot have additional setting [" + setting + "] " + - "in plugin " + plugin.v1().getName() + ", already added in plugin " + oldPlugin); + "in plugin [" + plugin.v1().getName() + "], already added in plugin [" + oldPlugin + "]"); } } builder.put(settings); diff --git a/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java b/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java index 5b0ea2d4eb3..8a1c8b14693 100644 --- a/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java +++ b/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java @@ -78,8 +78,8 @@ public class PluginsServiceTests extends ESTestCase { } catch (IllegalArgumentException e) { String msg = e.getMessage(); assertTrue(msg, msg.contains("Cannot have additional setting [foo.bar]")); - assertTrue(msg, msg.contains("plugin additional-settings1")); - assertTrue(msg, msg.contains("plugin additional-settings2")); + assertTrue(msg, msg.contains("plugin [additional-settings1]")); + assertTrue(msg, msg.contains("plugin [additional-settings2]")); } } } From 0599f85d2d993cdeb76cb919d510ddd5ea5a5d3e Mon Sep 17 00:00:00 2001 From: David Pilato Date: Tue, 18 Aug 2015 18:19:41 +0200 Subject: [PATCH 31/54] [build] simplify ant script for plugins Now we are using short names for artifactId (see #12879) so we don't need anymore to transform long names `elasticsearch-pluginname` to short names `pluginname` in ant script when we install a plugin. Modify also convert-plugin-name Clean up remaining plugins with old format And fix vagrant tests --- .../main/resources/ant/integration-tests.xml | 19 ++++--------------- qa/vagrant/pom.xml | 2 +- .../packaging/scripts/25_tar_plugins.bats | 12 ++++++------ .../packaging/scripts/50_plugins.bats | 8 ++++---- .../scripts/packaging_test_utils.bash | 2 +- 5 files changed, 16 insertions(+), 27 deletions(-) diff --git a/dev-tools/src/main/resources/ant/integration-tests.xml b/dev-tools/src/main/resources/ant/integration-tests.xml index d710e57a076..f5e87c033e3 100644 --- a/dev-tools/src/main/resources/ant/integration-tests.xml +++ b/dev-tools/src/main/resources/ant/integration-tests.xml @@ -93,21 +93,11 @@ - - - - - - - - - - - + - + @@ -203,8 +193,8 @@ + 'analysis-icu-2.0.0.zip' would return + 'analysis-icu'. --> @@ -213,7 +203,6 @@ - diff --git a/qa/vagrant/pom.xml b/qa/vagrant/pom.xml index 26636be5854..8f3b8ade0f8 100644 --- a/qa/vagrant/pom.xml +++ b/qa/vagrant/pom.xml @@ -94,7 +94,7 @@ org.elasticsearch.plugin - elasticsearch-jvm-example + jvm-example ${elasticsearch.version} zip diff --git a/qa/vagrant/src/test/resources/packaging/scripts/25_tar_plugins.bats b/qa/vagrant/src/test/resources/packaging/scripts/25_tar_plugins.bats index efc0c2e7d73..2b8fe631cec 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/25_tar_plugins.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/25_tar_plugins.bats @@ -61,7 +61,7 @@ setup() { assert_file_exist "/tmp/elasticsearch/config/jvm-example/example.yaml" assert_file_exist "/tmp/elasticsearch/plugins/jvm-example" assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/plugin-descriptor.properties" - assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/elasticsearch-jvm-example-"*".jar" + assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/jvm-example-"*".jar" echo "Running jvm-example's bin script...." /tmp/elasticsearch/bin/jvm-example/test | grep test @@ -106,7 +106,7 @@ setup() { assert_file_exist "/tmp/elasticsearch/config/jvm-example/example.yaml" assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example" assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example/plugin-descriptor.properties" - assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example/elasticsearch-jvm-example-"*".jar" + assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example/jvm-example-"*".jar" # Remove the plugin run /tmp/elasticsearch/bin/plugin remove jvm-example @@ -156,7 +156,7 @@ setup() { assert_file_exist "$TEMP_CONFIG_DIR/jvm-example/example.yaml" assert_file_exist "/tmp/elasticsearch/plugins/jvm-example" assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/plugin-descriptor.properties" - assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/elasticsearch-jvm-example-"*".jar" + assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/jvm-example-"*".jar" # Remove the plugin run /tmp/elasticsearch/bin/plugin remove jvm-example @@ -210,7 +210,7 @@ setup() { assert_file_exist "$TEMP_CONFIG_DIR/jvm-example/example.yaml" assert_file_exist "/tmp/elasticsearch/plugins/jvm-example" assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/plugin-descriptor.properties" - assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/elasticsearch-jvm-example-"*".jar" + assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/jvm-example-"*".jar" # Remove the plugin run /tmp/elasticsearch/bin/plugin remove jvm-example @@ -254,7 +254,7 @@ setup() { assert_file_exist "$ES_DIR/config/jvm-example/example.yaml" assert_file_exist "$ES_DIR/plugins/jvm-example" assert_file_exist "$ES_DIR/plugins/jvm-example/plugin-descriptor.properties" - assert_file_exist "$ES_DIR/plugins/jvm-example/elasticsearch-jvm-example-"*".jar" + assert_file_exist "$ES_DIR/plugins/jvm-example/jvm-example-"*".jar" # Remove the plugin run "$ES_DIR/bin/plugin" remove jvm-example @@ -298,7 +298,7 @@ setup() { assert_file_exist "/tmp/elasticsearch/config/jvm-example/example.yaml" assert_file_exist "/tmp/elasticsearch/plugins/jvm-example" assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/plugin-descriptor.properties" - assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/elasticsearch-jvm-example-"*".jar" + assert_file_exist "/tmp/elasticsearch/plugins/jvm-example/jvm-example-"*".jar" # Remove the plugin run /tmp/elasticsearch/bin/plugin remove jvm-example diff --git a/qa/vagrant/src/test/resources/packaging/scripts/50_plugins.bats b/qa/vagrant/src/test/resources/packaging/scripts/50_plugins.bats index c739296479d..77ce7f0cecb 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/50_plugins.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/50_plugins.bats @@ -74,7 +74,7 @@ install_package() { assert_file_exist "/etc/elasticsearch/jvm-example/example.yaml" assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example" assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/plugin-descriptor.properties" - assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/elasticsearch-jvm-example-"*".jar" + assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/jvm-example-"*".jar" # Remove the plugin run /usr/share/elasticsearch/bin/plugin remove jvm-example @@ -121,7 +121,7 @@ install_package() { assert_file_exist "/etc/elasticsearch/jvm-example/example.yaml" assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example" assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example/plugin-descriptor.properties" - assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example/elasticsearch-jvm-example-"*".jar" + assert_file_exist "$TEMP_PLUGINS_DIR/jvm-example/jvm-example-"*".jar" # Remove the plugin @@ -183,7 +183,7 @@ install_package() { assert_file_exist "$TEMP_CONFIG_DIR/jvm-example/example.yaml" assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example" assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/plugin-descriptor.properties" - assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/elasticsearch-jvm-example-"*".jar" + assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/jvm-example-"*".jar" # Remove the plugin run /usr/share/elasticsearch/bin/plugin remove jvm-example @@ -241,7 +241,7 @@ install_package() { assert_file_exist "$TEMP_CONFIG_DIR/jvm-example/example.yaml" assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example" assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/plugin-descriptor.properties" - assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/elasticsearch-jvm-example-"*".jar" + assert_file_exist "/usr/share/elasticsearch/plugins/jvm-example/jvm-example-"*".jar" # Remove the plugin run /usr/share/elasticsearch/bin/plugin remove jvm-example diff --git a/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash b/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash index a1b16a6943a..c3773b557ef 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash +++ b/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash @@ -27,7 +27,7 @@ # Variables used by tests -EXAMPLE_PLUGIN_ZIP=$(readlink -m elasticsearch-jvm-example-*.zip) +EXAMPLE_PLUGIN_ZIP=$(readlink -m jvm-example-*.zip) # Checks if necessary commands are available to run the tests From 509edefb044b2f26ae02a2f18d4ddf06016366ba Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Tue, 18 Aug 2015 13:22:37 -0400 Subject: [PATCH 32/54] Improve stability of restoreIndexWithMissingShards test Replaced awaitBusy with assertBusy and increased the timeout. --- .../DedicatedClusterSnapshotRestoreIT.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index 23ea847e2b1..cea3233b03d 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -21,7 +21,6 @@ package org.elasticsearch.snapshots; import com.carrotsearch.hppc.IntHashSet; import com.carrotsearch.hppc.IntSet; -import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.ListenableFuture; import org.elasticsearch.ElasticsearchParseException; @@ -471,18 +470,16 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-2") .setIndices("test-idx-all", "test-idx-none", "test-idx-some") .setWaitForCompletion(false).setPartial(true).execute().actionGet(); - awaitBusy(new Predicate() { + assertBusy(new Runnable() { @Override - public boolean apply(Object o) { + public void run() { SnapshotsStatusResponse snapshotsStatusResponse = client().admin().cluster().prepareSnapshotStatus("test-repo").setSnapshots("test-snap-2").get(); ImmutableList snapshotStatuses = snapshotsStatusResponse.getSnapshots(); - if (snapshotStatuses.size() == 1) { - logger.trace("current snapshot status [{}]", snapshotStatuses.get(0)); - return snapshotStatuses.get(0).getState().completed(); - } - return false; + assertEquals(snapshotStatuses.size(), 1); + logger.trace("current snapshot status [{}]", snapshotStatuses.get(0)); + assertTrue(snapshotStatuses.get(0).getState().completed()); } - }); + }, 1, TimeUnit.MINUTES); SnapshotsStatusResponse snapshotsStatusResponse = client().admin().cluster().prepareSnapshotStatus("test-repo").setSnapshots("test-snap-2").get(); ImmutableList snapshotStatuses = snapshotsStatusResponse.getSnapshots(); assertThat(snapshotStatuses.size(), equalTo(1)); @@ -494,19 +491,16 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest // There is slight delay between snapshot being marked as completed in the cluster state and on the file system // After it was marked as completed in the cluster state - we need to check if it's completed on the file system as well - awaitBusy(new Predicate() { + assertBusy(new Runnable() { @Override - public boolean apply(Object o) { + public void run() { GetSnapshotsResponse response = client().admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap-2").get(); assertThat(response.getSnapshots().size(), equalTo(1)); SnapshotInfo snapshotInfo = response.getSnapshots().get(0); - if (snapshotInfo.state().completed()) { - assertThat(snapshotInfo.state(), equalTo(SnapshotState.PARTIAL)); - return true; - } - return false; + assertTrue(snapshotInfo.state().completed()); + assertEquals(SnapshotState.PARTIAL, snapshotInfo.state()); } - }); + }, 1, TimeUnit.MINUTES); } else { logger.info("checking snapshot completion using wait_for_completion flag"); createSnapshotResponse = client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-2") From e07f0396598d322a53efb1c8a7d2abd46f2d05ea Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 18 Aug 2015 16:28:57 -0400 Subject: [PATCH 33/54] Workaround JDK bug 8034057 This causes a FileSystemException when trying to retrieve FileStore for a path, and falsely returns false for Files.isWritable Squashed commit of the following: commit d2cc0d966f3bc94aa836b316a42b3c5724bc01ef Author: Robert Muir Date: Tue Aug 18 15:49:48 2015 -0400 fixes for the non-bogus comments commit 6e0a272f5f8ef7358654ded8ff4ffc31831fa5c7 Author: Robert Muir Date: Tue Aug 18 15:30:43 2015 -0400 Fix isWritable too commit 2a8764ca118fc4c950bfc60d0b97de873e0e82ad Author: Robert Muir Date: Tue Aug 18 14:49:50 2015 -0400 try to workaround filestore bug --- .../common/cli/CheckFileCommand.java | 2 +- .../org/elasticsearch/env/ESFileStore.java | 66 +++++++++++++++++-- .../org/elasticsearch/env/Environment.java | 31 ++++++++- .../elasticsearch/plugins/PluginManager.java | 4 +- .../resources/forbidden/all-signatures.txt | 3 + 5 files changed, 97 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/cli/CheckFileCommand.java b/core/src/main/java/org/elasticsearch/common/cli/CheckFileCommand.java index 3273daf75f9..2c8aa709edb 100644 --- a/core/src/main/java/org/elasticsearch/common/cli/CheckFileCommand.java +++ b/core/src/main/java/org/elasticsearch/common/cli/CheckFileCommand.java @@ -76,7 +76,7 @@ public abstract class CheckFileCommand extends CliTool.Command { if (paths != null && paths.length > 0) { for (Path path : paths) { try { - boolean supportsPosixPermissions = Files.getFileStore(path).supportsFileAttributeView(PosixFileAttributeView.class); + boolean supportsPosixPermissions = Environment.getFileStore(path).supportsFileAttributeView(PosixFileAttributeView.class); if (supportsPosixPermissions) { PosixFileAttributes attributes = Files.readAttributes(path, PosixFileAttributes.class); permissions.put(path, attributes.permissions()); diff --git a/core/src/main/java/org/elasticsearch/env/ESFileStore.java b/core/src/main/java/org/elasticsearch/env/ESFileStore.java index 8963d7868b1..d74432c591a 100644 --- a/core/src/main/java/org/elasticsearch/env/ESFileStore.java +++ b/core/src/main/java/org/elasticsearch/env/ESFileStore.java @@ -26,10 +26,12 @@ import org.elasticsearch.common.io.PathUtils; import java.io.IOException; import java.nio.file.FileStore; +import java.nio.file.FileSystemException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.FileAttributeView; import java.nio.file.attribute.FileStoreAttributeView; +import java.util.Arrays; /** * Implementation of FileStore that supports @@ -73,13 +75,16 @@ class ESFileStore extends FileStore { } } - /** Files.getFileStore(Path) useless here! Don't complain, just try it yourself. */ - static FileStore getMatchingFileStore(Path path, FileStore fileStores[]) throws IOException { - FileStore store = Files.getFileStore(path); - + /** + * Files.getFileStore(Path) useless here! Don't complain, just try it yourself. + */ + @SuppressForbidden(reason = "works around the bugs") + static FileStore getMatchingFileStore(Path path, FileStore fileStores[]) throws IOException { if (Constants.WINDOWS) { - return store; // be defensive, don't even try to do anything fancy. + return getFileStoreWindows(path, fileStores); } + + FileStore store = Files.getFileStore(path); try { String mount = getMountPointLinux(store); @@ -110,6 +115,57 @@ class ESFileStore extends FileStore { // fall back to crappy one we got from Files.getFileStore return store; } + + /** + * remove this code and just use getFileStore for windows on java 9 + * works around https://bugs.openjdk.java.net/browse/JDK-8034057 + */ + @SuppressForbidden(reason = "works around https://bugs.openjdk.java.net/browse/JDK-8034057") + static FileStore getFileStoreWindows(Path path, FileStore fileStores[]) throws IOException { + assert Constants.WINDOWS; + + try { + return Files.getFileStore(path); + } catch (FileSystemException possibleBug) { + final char driveLetter; + // look for a drive letter to see if its the SUBST bug, + // it might be some other type of path, like a windows share + // if something goes wrong, we just deliver the original exception + try { + String root = path.toRealPath().getRoot().toString(); + if (root.length() < 2) { + throw new RuntimeException("root isn't a drive letter: " + root); + } + driveLetter = Character.toLowerCase(root.charAt(0)); + if (Character.isAlphabetic(driveLetter) == false || root.charAt(1) != ':') { + throw new RuntimeException("root isn't a drive letter: " + root); + } + } catch (Throwable checkFailed) { + // something went wrong, + possibleBug.addSuppressed(checkFailed); + throw possibleBug; + } + + // we have a drive letter: the hack begins!!!!!!!! + try { + // we have no choice but to parse toString of all stores and find the matching drive letter + for (FileStore store : fileStores) { + String toString = store.toString(); + int length = toString.length(); + if (length > 3 && toString.endsWith(":)") && toString.charAt(length - 4) == '(') { + if (Character.toLowerCase(toString.charAt(length - 3)) == driveLetter) { + return store; + } + } + } + throw new RuntimeException("no filestores matched"); + } catch (Throwable weTried) { + IOException newException = new IOException("Unable to retrieve filestore for '" + path + "', tried matching against " + Arrays.toString(fileStores), weTried); + newException.addSuppressed(possibleBug); + throw newException; + } + } + } @Override public String name() { diff --git a/core/src/main/java/org/elasticsearch/env/Environment.java b/core/src/main/java/org/elasticsearch/env/Environment.java index f50405eb091..a82dab995e5 100644 --- a/core/src/main/java/org/elasticsearch/env/Environment.java +++ b/core/src/main/java/org/elasticsearch/env/Environment.java @@ -19,6 +19,7 @@ package org.elasticsearch.env; +import org.apache.lucene.util.Constants; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.io.PathUtils; @@ -302,9 +303,37 @@ public class Environment { *
  • Only requires the security permissions of {@link Files#getFileStore(Path)}, * no permissions to the actual mount point are required. *
  • Exception handling has the same semantics as {@link Files#getFileStore(Path)}. + *
  • Works around https://bugs.openjdk.java.net/browse/JDK-8034057. * */ - public FileStore getFileStore(Path path) throws IOException { + public static FileStore getFileStore(Path path) throws IOException { return ESFileStore.getMatchingFileStore(path, fileStores); } + + /** + * Returns true if the path is writable. + * Acts just like {@link Files#isWritable(Path)}, except won't + * falsely return false for paths on SUBST'd drive letters + * See https://bugs.openjdk.java.net/browse/JDK-8034057 + * Note this will set the file modification time (to its already-set value) + * to test access. + */ + @SuppressForbidden(reason = "works around https://bugs.openjdk.java.net/browse/JDK-8034057") + public static boolean isWritable(Path path) throws IOException { + boolean v = Files.isWritable(path); + if (v || Constants.WINDOWS == false) { + return v; + } + + // isWritable returned false on windows, the hack begins!!!!!! + // resetting the modification time is the least destructive/simplest + // way to check for both files and directories, and fails early just + // in getting the current value if file doesn't exist, etc + try { + Files.setLastModifiedTime(path, Files.getLastModifiedTime(path)); + return true; + } catch (Throwable e) { + return false; + } + } } diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java index fbd5b74ee1d..234d719f734 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java @@ -112,7 +112,7 @@ public class PluginManager { Files.createDirectory(environment.pluginsFile()); } - if (!Files.isWritable(environment.pluginsFile())) { + if (!Environment.isWritable(environment.pluginsFile())) { throw new IOException("plugin directory " + environment.pluginsFile() + " is read only"); } @@ -246,7 +246,7 @@ public class PluginManager { } catch (IOException e) { throw new IOException("Could not move [" + binFile + "] to [" + toLocation + "]", e); } - if (Files.getFileStore(toLocation).supportsFileAttributeView(PosixFileAttributeView.class)) { + if (Environment.getFileStore(toLocation).supportsFileAttributeView(PosixFileAttributeView.class)) { // add read and execute permissions to existing perms, so execution will work. // read should generally be set already, but set it anyway: don't rely on umask... final Set executePerms = new HashSet<>(); diff --git a/dev-tools/src/main/resources/forbidden/all-signatures.txt b/dev-tools/src/main/resources/forbidden/all-signatures.txt index f697b323569..e61d58d4328 100644 --- a/dev-tools/src/main/resources/forbidden/all-signatures.txt +++ b/dev-tools/src/main/resources/forbidden/all-signatures.txt @@ -56,3 +56,6 @@ java.io.ObjectInputStream java.io.ObjectInput java.nio.file.Files#isHidden(java.nio.file.Path) @ Dependent on the operating system, use FileSystemUtils.isHidden instead + +java.nio.file.Files#getFileStore(java.nio.file.Path) @ Use Environment.getFileStore() instead, impacted by JDK-8034057 +java.nio.file.Files#isWritable(java.nio.file.Path) @ Use Environment.isWritable() instead, impacted by JDK-8034057 From 0ffd99cca3f297bf3f9707a0b06ff76e6e67f0ef Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 18 Aug 2015 21:36:04 +0200 Subject: [PATCH 34/54] Drop commons-lang dependency commons-lang really is only used by some core classes to join strings or modiy arrays. It's not worth carrying the dependency. This commit removes the dependency on commons-lang entirely. --- core/pom.xml | 4 -- core/src/main/assemblies/common-bin.xml | 1 - .../org/elasticsearch/common/cli/CliTool.java | 1 - .../common/collect/CopyOnWriteHashMap.java | 72 ++++++++++++++----- .../geo/builders/BasePolygonBuilder.java | 11 ++- .../common/geo/builders/ShapeBuilder.java | 11 ++- .../elasticsearch/common/ParseFieldTests.java | 6 +- .../test/ESBackcompatTestCase.java | 6 -- .../elasticsearch/test/ESIntegTestCase.java | 9 +-- .../licenses/commons-lang3-3.3.2.jar.sha1 | 0 .../licenses/commons-lang3-LICENSE.txt | 0 .../licenses/commons-lang3-NOTICE.txt | 0 plugins/pom.xml | 5 -- pom.xml | 6 -- qa/smoke-test-multinode/pom.xml | 5 -- qa/smoke-test-plugins/pom.xml | 5 -- 16 files changed, 75 insertions(+), 67 deletions(-) rename {distribution => plugins/cloud-azure}/licenses/commons-lang3-3.3.2.jar.sha1 (100%) rename {distribution => plugins/cloud-azure}/licenses/commons-lang3-LICENSE.txt (100%) rename {distribution => plugins/cloud-azure}/licenses/commons-lang3-NOTICE.txt (100%) diff --git a/core/pom.xml b/core/pom.xml index 5c0dd2555c6..3186718248f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -161,10 +161,6 @@ org.hdrhistogram HdrHistogram - - org.apache.commons - commons-lang3 - commons-cli commons-cli diff --git a/core/src/main/assemblies/common-bin.xml b/core/src/main/assemblies/common-bin.xml index d40299497f8..35c522e9c98 100644 --- a/core/src/main/assemblies/common-bin.xml +++ b/core/src/main/assemblies/common-bin.xml @@ -23,7 +23,6 @@ com.ning:compress-lzf com.github.spullara.mustache.java:compiler com.tdunning:t-digest - org.apache.commons:commons-lang3 commons-cli:commons-cli com.twitter:jsr166e org.hdrhistogram:HdrHistogram diff --git a/core/src/main/java/org/elasticsearch/common/cli/CliTool.java b/core/src/main/java/org/elasticsearch/common/cli/CliTool.java index 6b11e65147f..b3533b59417 100644 --- a/core/src/main/java/org/elasticsearch/common/cli/CliTool.java +++ b/core/src/main/java/org/elasticsearch/common/cli/CliTool.java @@ -23,7 +23,6 @@ import com.google.common.base.Preconditions; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.GnuParser; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; diff --git a/core/src/main/java/org/elasticsearch/common/collect/CopyOnWriteHashMap.java b/core/src/main/java/org/elasticsearch/common/collect/CopyOnWriteHashMap.java index 6bd3a5bd45b..0675f55c00c 100644 --- a/core/src/main/java/org/elasticsearch/common/collect/CopyOnWriteHashMap.java +++ b/core/src/main/java/org/elasticsearch/common/collect/CopyOnWriteHashMap.java @@ -22,9 +22,9 @@ package org.elasticsearch.common.collect; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; import com.google.common.collect.UnmodifiableIterator; -import org.apache.commons.lang3.ArrayUtils; import org.apache.lucene.util.mutable.MutableValueInt; +import java.lang.reflect.Array; import java.util.*; /** @@ -134,12 +134,13 @@ public final class CopyOnWriteHashMap extends AbstractMap { @Override V get(Object key, int hash) { - final int slot = ArrayUtils.indexOf(keys, key); - if (slot < 0) { - return null; - } else { - return values[slot]; + for (int i = 0; i < keys.length; i++) { + if (key.equals(keys[i])) { + return values[i]; + } } + return null; + } private static T[] replace(T[] array, int index, T value) { @@ -151,14 +152,20 @@ public final class CopyOnWriteHashMap extends AbstractMap { @Override Leaf put(K key, int hash, int hashBits, V value, MutableValueInt newValue) { assert hashBits <= 0 : hashBits; - final int slot = ArrayUtils.indexOf(keys, key); + int slot = -1; + for (int i = 0; i < keys.length; i++) { + if (key.equals(keys[i])) { + slot = i; + break; + } + } final K[] keys2; final V[] values2; if (slot < 0) { - keys2 = ArrayUtils.add(keys, key); - values2 = ArrayUtils.add(values, value); + keys2 = appendElement(keys, key); + values2 = appendElement(values, value); newValue.value = 1; } else { keys2 = replace(keys, slot, key); @@ -170,16 +177,49 @@ public final class CopyOnWriteHashMap extends AbstractMap { @Override Leaf remove(Object key, int hash) { - final int slot = ArrayUtils.indexOf(keys, key); + int slot = -1; + for (int i = 0; i < keys.length; i++) { + if (key.equals(keys[i])) { + slot = i; + break; + } + } if (slot < 0) { return this; } - final K[] keys2 = ArrayUtils.remove(keys, slot); - final V[] values2 = ArrayUtils.remove(values, slot); + final K[] keys2 = removeArrayElement(keys, slot); + final V[] values2 = removeArrayElement(values, slot); return new Leaf<>(keys2, values2); } } + private static T[] removeArrayElement(T[] array, int index) { + final Object result = Array.newInstance(array.getClass().getComponentType(), array.length - 1); + System.arraycopy(array, 0, result, 0, index); + if (index < array.length - 1) { + System.arraycopy(array, index + 1, result, index, array.length - index - 1); + } + + return (T[]) result; + } + + public static T[] appendElement(final T[] array, final T element) { + final T[] newArray = Arrays.copyOf(array, array.length + 1); + newArray[newArray.length - 1] = element; + return newArray; + } + + public static T[] insertElement(final T[] array, final T element, final int index) { + final T[] result = Arrays.copyOf(array, array.length + 1); + System.arraycopy(array, 0, result, 0, index); + result[index] = element; + if (index < array.length) { + System.arraycopy(array, index, result, index + 1, array.length - index); + } + return result; + } + + /** * An inner node in this trie. Inner nodes store up to 64 key-value pairs * and use a bitmap in order to associate hashes to them. For example, if @@ -320,8 +360,8 @@ public final class CopyOnWriteHashMap extends AbstractMap { private InnerNode putNew(K key, int hash6, int slot, V value) { final long mask2 = mask | (1L << hash6); - final K[] keys2 = ArrayUtils.add(keys, slot, key); - final Object[] subNodes2 = ArrayUtils.add(subNodes, slot, value); + final K[] keys2 = insertElement(keys, key, slot); + final Object[] subNodes2 = insertElement(subNodes, value, slot); return new InnerNode<>(mask2, keys2, subNodes2); } @@ -342,8 +382,8 @@ public final class CopyOnWriteHashMap extends AbstractMap { private InnerNode removeSlot(int hash6, int slot) { final long mask2 = mask & ~(1L << hash6); - final K[] keys2 = ArrayUtils.remove(keys, slot); - final Object[] subNodes2 = ArrayUtils.remove(subNodes, slot); + final K[] keys2 = removeArrayElement(keys, slot); + final Object[] subNodes2 = removeArrayElement(subNodes, slot); return new InnerNode<>(mask2, keys2, subNodes2); } diff --git a/core/src/main/java/org/elasticsearch/common/geo/builders/BasePolygonBuilder.java b/core/src/main/java/org/elasticsearch/common/geo/builders/BasePolygonBuilder.java index c1cb9bb32ac..c37c8a66d6b 100644 --- a/core/src/main/java/org/elasticsearch/common/geo/builders/BasePolygonBuilder.java +++ b/core/src/main/java/org/elasticsearch/common/geo/builders/BasePolygonBuilder.java @@ -23,7 +23,7 @@ import com.google.common.collect.Sets; import com.spatial4j.core.exception.InvalidShapeException; import com.spatial4j.core.shape.Shape; import com.vividsolutions.jts.geom.*; -import org.apache.commons.lang3.tuple.Pair; +import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -98,7 +98,6 @@ public abstract class BasePolygonBuilder> extend /** * build new hole to the polygon - * @param hole linear ring defining the hole * @return this */ public Ring hole() { @@ -285,7 +284,7 @@ public abstract class BasePolygonBuilder> extend Edge current = edge; Edge prev = edge; // bookkeep the source and sink of each visited coordinate - HashMap> visitedEdge = new HashMap<>(); + HashMap> visitedEdge = new HashMap<>(); do { current.coordinate = shift(current.coordinate, shiftOffset); current.component = id; @@ -301,7 +300,7 @@ public abstract class BasePolygonBuilder> extend // since we're splitting connected components, we want the edges method to visit // the newly separated component final int visitID = -id; - Edge firstAppearance = visitedEdge.get(current.coordinate).getRight(); + Edge firstAppearance = visitedEdge.get(current.coordinate).v2(); // correct the graph pointers by correcting the 'next' pointer for both the // first appearance and this appearance of the edge Edge temp = firstAppearance.next; @@ -312,12 +311,12 @@ public abstract class BasePolygonBuilder> extend // a non-visited value (anything positive) do { prev.component = visitID; - prev = visitedEdge.get(prev.coordinate).getLeft(); + prev = visitedEdge.get(prev.coordinate).v1(); ++splitIndex; } while (!current.coordinate.equals(prev.coordinate)); ++connectedComponents; } else { - visitedEdge.put(current.coordinate, Pair.of(prev, current)); + visitedEdge.put(current.coordinate, new Tuple(prev, current)); } edges.add(current); prev = current; diff --git a/core/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java b/core/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java index 2443e5156e3..bfb41094214 100644 --- a/core/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java +++ b/core/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java @@ -26,9 +26,8 @@ import com.spatial4j.core.shape.jts.JtsGeometry; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; -import org.apache.commons.lang3.tuple.Pair; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.common.Explicit; +import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.unit.DistanceUnit.Distance; @@ -487,7 +486,7 @@ public abstract class ShapeBuilder implements ToXContent { return top; } - private static final Pair range(Coordinate[] points, int offset, int length) { + private static final double[] range(Coordinate[] points, int offset, int length) { double minX = points[0].x; double maxX = points[0].x; double minY = points[0].y; @@ -507,7 +506,7 @@ public abstract class ShapeBuilder implements ToXContent { maxY = points[offset + i].y; } } - return Pair.of(Pair.of(minX, maxX), Pair.of(minY, maxY)); + return new double[] {minX, maxX, minY, maxY}; } /** @@ -585,8 +584,8 @@ public abstract class ShapeBuilder implements ToXContent { // and convert to a right handed system // compute the bounding box and calculate range - Pair range = range(points, offset, length); - final double rng = (Double)range.getLeft().getRight() - (Double)range.getLeft().getLeft(); + double[] range = range(points, offset, length); + final double rng = range[1] - range[0]; // translate the points if the following is true // 1. shell orientation is cw and range is greater than a hemisphere (180 degrees) but not spanning 2 hemispheres // (translation would result in a collapsed poly) diff --git a/core/src/test/java/org/elasticsearch/common/ParseFieldTests.java b/core/src/test/java/org/elasticsearch/common/ParseFieldTests.java index 6df6a50f9a3..b3397a55b32 100644 --- a/core/src/test/java/org/elasticsearch/common/ParseFieldTests.java +++ b/core/src/test/java/org/elasticsearch/common/ParseFieldTests.java @@ -18,7 +18,6 @@ */ package org.elasticsearch.common; -import org.apache.commons.lang3.ArrayUtils; import org.elasticsearch.test.ESTestCase; import org.junit.Test; @@ -77,7 +76,10 @@ public class ParseFieldTests extends ESTestCase { String[] deprecated = new String[]{"text", "same_as_text"}; String[] allValues = values; if (withDeprecatedNames) { - allValues = ArrayUtils.addAll(values, deprecated); + String[] newArray = new String[allValues.length + deprecated.length]; + System.arraycopy(allValues, 0, newArray, 0, allValues.length); + System.arraycopy(deprecated, 0, newArray, allValues.length, deprecated.length); + allValues = newArray; } ParseField field = new ParseField(randomFrom(values)); diff --git a/core/src/test/java/org/elasticsearch/test/ESBackcompatTestCase.java b/core/src/test/java/org/elasticsearch/test/ESBackcompatTestCase.java index 4c8c0f976de..39780db1026 100644 --- a/core/src/test/java/org/elasticsearch/test/ESBackcompatTestCase.java +++ b/core/src/test/java/org/elasticsearch/test/ESBackcompatTestCase.java @@ -19,7 +19,6 @@ package org.elasticsearch.test; import com.carrotsearch.randomizedtesting.annotations.TestGroup; -import org.apache.commons.lang3.ArrayUtils; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.IndexRoutingTable; @@ -32,13 +31,8 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.recovery.RecoverySettings; import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.test.junit.listeners.LoggingListener; -import org.elasticsearch.test.transport.AssertingLocalTransport; -import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.transport.Transport; import org.elasticsearch.transport.TransportModule; -import org.elasticsearch.transport.TransportService; -import org.elasticsearch.transport.netty.NettyTransport; -import org.junit.Ignore; import java.io.IOException; import java.lang.annotation.ElementType; diff --git a/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java b/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java index 4bb9b7b7b60..80a60ffbd20 100644 --- a/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java @@ -28,12 +28,10 @@ import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.collect.Lists; -import org.apache.commons.lang3.StringUtils; import org.apache.http.impl.client.HttpClients; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; -import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.shard.MergeSchedulerConfig; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.LuceneTestCase; @@ -80,7 +78,6 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; @@ -1920,7 +1917,11 @@ public abstract class ESIntegTestCase extends ESTestCase { } if (list.length != 1) { - throw new IllegalStateException("Backwards index must contain exactly one cluster\n" + StringUtils.join(list, "\n")); + StringBuilder builder = new StringBuilder("Backwards index must contain exactly one cluster\n"); + for (Path line : list) { + builder.append(line.toString()).append('\n'); + } + throw new IllegalStateException(builder.toString()); } Path src = list[0]; Path dest = dataDir.resolve(internalCluster().getClusterName()); diff --git a/distribution/licenses/commons-lang3-3.3.2.jar.sha1 b/plugins/cloud-azure/licenses/commons-lang3-3.3.2.jar.sha1 similarity index 100% rename from distribution/licenses/commons-lang3-3.3.2.jar.sha1 rename to plugins/cloud-azure/licenses/commons-lang3-3.3.2.jar.sha1 diff --git a/distribution/licenses/commons-lang3-LICENSE.txt b/plugins/cloud-azure/licenses/commons-lang3-LICENSE.txt similarity index 100% rename from distribution/licenses/commons-lang3-LICENSE.txt rename to plugins/cloud-azure/licenses/commons-lang3-LICENSE.txt diff --git a/distribution/licenses/commons-lang3-NOTICE.txt b/plugins/cloud-azure/licenses/commons-lang3-NOTICE.txt similarity index 100% rename from distribution/licenses/commons-lang3-NOTICE.txt rename to plugins/cloud-azure/licenses/commons-lang3-NOTICE.txt diff --git a/plugins/pom.xml b/plugins/pom.xml index e87ef1e0678..5bc7f5f83f2 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -177,11 +177,6 @@ t-digest provided - - org.apache.commons - commons-lang3 - provided - commons-cli commons-cli diff --git a/pom.xml b/pom.xml index 71129a6689c..d82b7cab6f9 100644 --- a/pom.xml +++ b/pom.xml @@ -409,12 +409,6 @@ 2.1.6 - - org.apache.commons - commons-lang3 - 3.3.2 - - commons-cli commons-cli diff --git a/qa/smoke-test-multinode/pom.xml b/qa/smoke-test-multinode/pom.xml index 4b44c58665b..4c23f7bba56 100644 --- a/qa/smoke-test-multinode/pom.xml +++ b/qa/smoke-test-multinode/pom.xml @@ -165,11 +165,6 @@ t-digest provided - - org.apache.commons - commons-lang3 - provided - commons-cli commons-cli diff --git a/qa/smoke-test-plugins/pom.xml b/qa/smoke-test-plugins/pom.xml index 8a08bcd619b..9714885b5e6 100644 --- a/qa/smoke-test-plugins/pom.xml +++ b/qa/smoke-test-plugins/pom.xml @@ -170,11 +170,6 @@ t-digest provided - - org.apache.commons - commons-lang3 - provided - commons-cli commons-cli From 32bb49e8298604e93179d8878cc5c1cc26f3cf32 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 18 Aug 2015 23:17:43 +0200 Subject: [PATCH 35/54] [TEST] Make it clear what address we try to bind --- .../test/discovery/ClusterDiscoveryConfiguration.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java b/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java index f3c0da986e2..a170cd128be 100644 --- a/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java +++ b/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java @@ -150,8 +150,7 @@ public class ClusterDiscoveryConfiguration extends SettingsSource { try (ServerSocket serverSocket = new ServerSocket()) { // Set SO_REUSEADDR as we may bind here and not be able to reuse the address immediately without it. serverSocket.setReuseAddress(NetworkUtils.defaultReuseAddress()); - serverSocket.bind(new InetSocketAddress(nextPort)); - + serverSocket.bind(new InetSocketAddress("127.0.0.1", nextPort)); // bind was a success foundPortInRange = true; unicastHostPorts[i] = nextPort; From 54ae55662cd6f2f32a617903b86be60a5972bf3a Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 18 Aug 2015 14:28:03 -0700 Subject: [PATCH 36/54] Remove leftover class and fix compile issues from master merge --- .../elasticsearch/plugins/AbstractPlugin.java | 35 ------------------- .../plugins/PluginsServiceTests.java | 4 +-- .../snapshots/mockstore/MockRepository.java | 12 ++----- .../plugin/mapper/MapperMurmur3Plugin.java | 9 ++--- 4 files changed, 10 insertions(+), 50 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java diff --git a/core/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java b/core/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java deleted file mode 100644 index e33a2774771..00000000000 --- a/core/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.plugins; - -import org.elasticsearch.common.component.LifecycleComponent; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.settings.Settings; - -import java.io.Closeable; -import java.util.Collection; -import java.util.Collections; - -/** - * A base class for a plugin which returns no services or modules. - */ -public abstract class AbstractPlugin extends Plugin { - -} diff --git a/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java b/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java index 8a1c8b14693..6ac34c2297e 100644 --- a/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java +++ b/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java @@ -25,7 +25,7 @@ import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.test.ESTestCase; public class PluginsServiceTests extends ESTestCase { - public static class AdditionalSettingsPlugin1 extends AbstractPlugin { + public static class AdditionalSettingsPlugin1 extends Plugin { @Override public String name() { return "additional-settings1"; @@ -39,7 +39,7 @@ public class PluginsServiceTests extends ESTestCase { return Settings.builder().put("foo.bar", "1").put(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.MMAPFS.getSettingsKey()).build(); } } - public static class AdditionalSettingsPlugin2 extends AbstractPlugin { + public static class AdditionalSettingsPlugin2 extends Plugin { @Override public String name() { return "additional-settings2"; diff --git a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java index c346e5817bc..e430827d881 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java +++ b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java @@ -20,7 +20,6 @@ package org.elasticsearch.snapshots.mockstore; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.SnapshotId; @@ -37,7 +36,6 @@ import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.env.Environment; import org.elasticsearch.index.snapshots.IndexShardRepository; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; -import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.repositories.RepositoryName; import org.elasticsearch.repositories.RepositorySettings; @@ -50,8 +48,6 @@ import java.io.UnsupportedEncodingException; import java.nio.file.Path; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -64,7 +60,7 @@ import static org.elasticsearch.common.settings.Settings.settingsBuilder; public class MockRepository extends FsRepository { - public static class Plugin extends AbstractPlugin { + public static class Plugin extends org.elasticsearch.plugins.Plugin { @Override public String name() { @@ -81,10 +77,8 @@ public class MockRepository extends FsRepository { } @Override - public Collection> modules() { - Collection> modules = new ArrayList<>(); - modules.add(SettingsFilteringModule.class); - return modules; + public Collection nodeModules() { + return Collections.singletonList(new SettingsFilteringModule()); } public static class SettingsFilteringModule extends AbstractModule { diff --git a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/plugin/mapper/MapperMurmur3Plugin.java b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/plugin/mapper/MapperMurmur3Plugin.java index 9b6611decde..429db165b75 100644 --- a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/plugin/mapper/MapperMurmur3Plugin.java +++ b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/plugin/mapper/MapperMurmur3Plugin.java @@ -20,12 +20,13 @@ package org.elasticsearch.plugin.mapper; import org.elasticsearch.common.inject.Module; -import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.plugins.Plugin; import java.util.Collection; import java.util.Collections; -public class MapperMurmur3Plugin extends AbstractPlugin { +public class MapperMurmur3Plugin extends Plugin { @Override public String name() { @@ -38,8 +39,8 @@ public class MapperMurmur3Plugin extends AbstractPlugin { } @Override - public Collection> indexModules() { - return Collections.>singleton(MapperMurmur3IndexModule.class); + public Collection indexModules(Settings settings) { + return Collections.singletonList(new MapperMurmur3IndexModule()); } } From f7f7fecafbf98eea1d8d5e0fa860552e2e0f0036 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 18 Aug 2015 22:27:39 -0400 Subject: [PATCH 37/54] Improve console logging on startup exception Today we show the exception twice: once by the logger and then again by the JVM. This is too noisy, and easy to avoid. --- .../main/java/org/elasticsearch/bootstrap/Bootstrap.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index d1143a54542..74baa320d43 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -277,11 +277,19 @@ public class Bootstrap { closeSysError(); } } catch (Throwable e) { + // disable console logging, so user does not see the exception twice (jvm will show it already) + if (foreground) { + Loggers.disableConsoleLogging(); + } ESLogger logger = Loggers.getLogger(Bootstrap.class); if (INSTANCE.node != null) { logger = Loggers.getLogger(Bootstrap.class, INSTANCE.node.settings().get("name")); } logger.error("Exception", e); + // re-enable it if appropriate, so they can see any logging during the shutdown process + if (foreground) { + Loggers.enableConsoleLogging(); + } throw e; } From 4c9327d983e348bc4f0de0c1581458c8cad953ab Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 18 Aug 2015 22:30:43 -0400 Subject: [PATCH 38/54] Add millisecond parser for dynamic date fields mapped from "yyyy/MM/dd" Dynamic date fields mapped from dates of the form "yyyy-MM-dd" automatically receive the millisecond paresr epoch_millis as an alternative parsing format. However, dynamic date fields mapped from dates of the form "yyyy/MM/dd" do not. This is a bug since the migration documentation currently specifies that a dynamically added date field, by default, includes the epoch_millis format. This commit adds epoch_millis as an alternative parser to dynamic date fields mapped from dates of the form "yyyy/MM/dd". Closes #12873 --- core/src/main/java/org/elasticsearch/common/joda/Joda.java | 4 ++-- .../index/mapper/date/SimpleDateMappingTests.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/joda/Joda.java b/core/src/main/java/org/elasticsearch/common/joda/Joda.java index 5f1ffb4207b..174fe22e15b 100644 --- a/core/src/main/java/org/elasticsearch/common/joda/Joda.java +++ b/core/src/main/java/org/elasticsearch/common/joda/Joda.java @@ -275,9 +275,9 @@ public class Joda { .toFormatter() .withZoneUTC(); - DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[] {longFormatter.getParser(), shortFormatter.getParser()}); + DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[]{longFormatter.getParser(), shortFormatter.getParser(), new EpochTimeParser(true)}); - return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT); + return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT); } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/date/SimpleDateMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/date/SimpleDateMappingTests.java index aacf34b7ba8..fb67401e334 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/date/SimpleDateMappingTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/date/SimpleDateMappingTests.java @@ -83,6 +83,9 @@ public class SimpleDateMappingTests extends ESSingleNodeTestCase { FieldMapper fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field1"); assertThat(fieldMapper, instanceOf(DateFieldMapper.class)); + DateFieldMapper dateFieldMapper = (DateFieldMapper)fieldMapper; + assertEquals("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", dateFieldMapper.fieldType().dateTimeFormatter().format()); + assertEquals(1265587200000L, dateFieldMapper.fieldType().dateTimeFormatter().parser().parseMillis("1265587200000")); fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field2"); assertThat(fieldMapper, instanceOf(DateFieldMapper.class)); From fa701621787c708641b1c4d541e78e86f487d7ad Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 19 Aug 2015 01:26:36 -0400 Subject: [PATCH 39/54] Log network configuration at debug level --- .../common/network/IfConfig.java | 167 ++++++++++++++++++ .../common/network/NetworkService.java | 1 + 2 files changed, 168 insertions(+) create mode 100644 core/src/main/java/org/elasticsearch/common/network/IfConfig.java diff --git a/core/src/main/java/org/elasticsearch/common/network/IfConfig.java b/core/src/main/java/org/elasticsearch/common/network/IfConfig.java new file mode 100644 index 00000000000..6603ab52ce6 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/common/network/IfConfig.java @@ -0,0 +1,167 @@ +/* + * 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.common.network; + +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; + +import java.io.IOException; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.InterfaceAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.List; +import java.util.Locale; + +/** + * Simple class to log {@code ifconfig}-style output at DEBUG logging. + */ +final class IfConfig { + + private static final ESLogger logger = Loggers.getLogger(IfConfig.class); + private static final String INDENT = " "; + + /** log interface configuration at debug level, if its enabled */ + static void logIfNecessary() { + if (logger.isDebugEnabled()) { + try { + doLogging(); + } catch (IOException | SecurityException e) { + logger.warn("unable to gather network information", e); + } + } + } + + /** perform actual logging: might throw exception if things go wrong */ + private static void doLogging() throws IOException { + StringBuilder msg = new StringBuilder(); + for (NetworkInterface nic : NetworkUtils.getInterfaces()) { + msg.append(System.lineSeparator()); + + // ordinary name + msg.append(nic.getName()); + msg.append(System.lineSeparator()); + + // display name (e.g. on windows) + if (!nic.getName().equals(nic.getDisplayName())) { + msg.append(INDENT); + msg.append(nic.getDisplayName()); + msg.append(System.lineSeparator()); + } + + // addresses: v4 first, then v6 + List addresses = nic.getInterfaceAddresses(); + for (InterfaceAddress address : addresses) { + if (address.getAddress() instanceof Inet6Address == false) { + msg.append(INDENT); + msg.append(formatAddress(address)); + msg.append(System.lineSeparator()); + } + } + + for (InterfaceAddress address : addresses) { + if (address.getAddress() instanceof Inet6Address) { + msg.append(INDENT); + msg.append(formatAddress(address)); + msg.append(System.lineSeparator()); + } + } + + // hardware address + byte hardware[] = nic.getHardwareAddress(); + if (hardware != null) { + msg.append(INDENT); + msg.append("hardware "); + for (int i = 0; i < hardware.length; i++) { + if (i > 0) { + msg.append(":"); + } + msg.append(String.format(Locale.ROOT, "%02X", hardware[i])); + } + msg.append(System.lineSeparator()); + } + + // attributes + msg.append(INDENT); + msg.append(formatFlags(nic)); + msg.append(System.lineSeparator()); + } + logger.debug("configuration:" + System.lineSeparator() + "{}", msg.toString()); + } + + /** format internet address: java's default doesn't include everything useful */ + private static String formatAddress(InterfaceAddress interfaceAddress) throws IOException { + StringBuilder sb = new StringBuilder(); + + InetAddress address = interfaceAddress.getAddress(); + if (address instanceof Inet6Address) { + sb.append("inet6 "); + sb.append(address.toString().substring(1)); + sb.append(" prefixlen:"); + sb.append(interfaceAddress.getNetworkPrefixLength()); + } else { + sb.append("inet "); + sb.append(address.toString().substring(1)); + int netmask = 0xFFFFFFFF << (32 - interfaceAddress.getNetworkPrefixLength()); + sb.append(" netmask:" + InetAddress.getByAddress(new byte[] { + (byte)(netmask >>> 24), + (byte)(netmask >>> 16 & 0xFF), + (byte)(netmask >>> 8 & 0xFF), + (byte)(netmask & 0xFF) + }).toString().substring(1)); + InetAddress broadcast = interfaceAddress.getBroadcast(); + if (broadcast != null) { + sb.append(" broadcast:" + broadcast.toString().substring(1)); + } + } + if (address.isLoopbackAddress()) { + sb.append(" scope:host"); + } else if (address.isLinkLocalAddress()) { + sb.append(" scope:link"); + } else if (address.isSiteLocalAddress()) { + sb.append(" scope:site"); + } + return sb.toString(); + } + + /** format network interface flags */ + private static String formatFlags(NetworkInterface nic) throws SocketException { + StringBuilder flags = new StringBuilder(); + if (nic.isUp()) { + flags.append("UP "); + } + if (nic.supportsMulticast()) { + flags.append("MULTICAST "); + } + if (nic.isLoopback()) { + flags.append("LOOPBACK "); + } + if (nic.isPointToPoint()) { + flags.append("POINTOPOINT "); + } + if (nic.isVirtual()) { + flags.append("VIRTUAL "); + } + flags.append("mtu:" + nic.getMTU()); + flags.append(" index:" + nic.getIndex()); + return flags.toString(); + } +} diff --git a/core/src/main/java/org/elasticsearch/common/network/NetworkService.java b/core/src/main/java/org/elasticsearch/common/network/NetworkService.java index 9f6b77aa90d..0e49c1b1118 100644 --- a/core/src/main/java/org/elasticsearch/common/network/NetworkService.java +++ b/core/src/main/java/org/elasticsearch/common/network/NetworkService.java @@ -82,6 +82,7 @@ public class NetworkService extends AbstractComponent { @Inject public NetworkService(Settings settings) { super(settings); + IfConfig.logIfNecessary(); InetSocketTransportAddress.setResolveAddress(settings.getAsBoolean("network.address.serialization.resolve", false)); } From 43fae91ab918f199160790382130532c1a9015ef Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Wed, 19 Aug 2015 10:01:38 +0200 Subject: [PATCH 40/54] Test: ClusterDiscoveryConfiguration.UnicastZen should allow for port ranges The cluster configuration allows to setup a cluster for use with unicast discovery. This means that nodes have to have pre-calculated known addresses which can be used to poplulate the unicast hosts setting. Despite of repeated attempts to select unused ports, we still see test failures where the node can not bind to it's assigned port due to it already being in use (most on CentOS). This commit changes it to allow each node to have a pre-set mutual exclusive range of ports and add all those ports to the unicast hosts list. That's OK because we know the node will only bind to one of those. --- .../ClusterDiscoveryConfiguration.java | 83 +++++++++---------- 1 file changed, 37 insertions(+), 46 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java b/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java index a170cd128be..79f51594daf 100644 --- a/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java +++ b/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java @@ -30,6 +30,7 @@ import org.elasticsearch.transport.local.LocalTransport; import java.io.IOException; import java.net.InetSocketAddress; import java.net.ServerSocket; +import java.util.ArrayList; import java.util.HashSet; import java.util.Set; @@ -62,8 +63,12 @@ public class ClusterDiscoveryConfiguration extends SettingsSource { // this variable is incremented on each bind attempt and will maintain the next port that should be tried private static int nextPort = calcBasePort(); - private final int[] unicastHostOrdinals; - private final int[] unicastHostPorts; + // since we run multiple test iterations, we need some flexibility in the choice of ports a node can have (port may + // stay in use by previous iterations on some OSes - read CentOs). This controls the amount of ports each node + // is assigned. All ports in range will be added to the unicast hosts, which is OK because we know only one will be used. + private static final int NUM_PORTS_PER_NODE = 3; + + private final String[] unicastHosts; private final boolean localMode; public UnicastZen(int numOfNodes) { @@ -80,6 +85,7 @@ public class ClusterDiscoveryConfiguration extends SettingsSource { public UnicastZen(int numOfNodes, int numOfUnicastHosts, Settings extraSettings) { super(numOfNodes, extraSettings); + int[] unicastHostOrdinals; if (numOfUnicastHosts == numOfNodes) { unicastHostOrdinals = new int[numOfNodes]; for (int i = 0; i < numOfNodes; i++) { @@ -93,8 +99,7 @@ public class ClusterDiscoveryConfiguration extends SettingsSource { unicastHostOrdinals = Ints.toArray(ordinals); } this.localMode = nodeSettings.get("node.mode", InternalTestCluster.NODE_MODE).equals("local"); - this.unicastHostPorts = localMode ? new int[0] : unicastHostPorts(numOfNodes); - assert localMode || unicastHostOrdinals.length <= unicastHostPorts.length; + this.unicastHosts = buildUnicastHostSetting(unicastHostOrdinals, localMode); } public UnicastZen(int numOfNodes, int[] unicastHostOrdinals) { @@ -103,73 +108,59 @@ public class ClusterDiscoveryConfiguration extends SettingsSource { public UnicastZen(int numOfNodes, Settings extraSettings, int[] unicastHostOrdinals) { super(numOfNodes, extraSettings); - this.unicastHostOrdinals = unicastHostOrdinals; this.localMode = nodeSettings.get("node.mode", InternalTestCluster.NODE_MODE).equals("local"); - this.unicastHostPorts = localMode ? new int[0] : unicastHostPorts(numOfNodes); - assert localMode || unicastHostOrdinals.length <= unicastHostPorts.length; + this.unicastHosts = buildUnicastHostSetting(unicastHostOrdinals, localMode); } private static int calcBasePort() { return 30000 + InternalTestCluster.BASE_PORT; } + private static String[] buildUnicastHostSetting(int[] unicastHostOrdinals, boolean localMode) { + ArrayList unicastHosts = new ArrayList<>(); + for (int i = 0; i < unicastHostOrdinals.length; i++) { + final int hostOrdinal = unicastHostOrdinals[i]; + if (localMode) { + unicastHosts.add("node_" + hostOrdinal); + } else { + // we need to pin the node port & host so we'd know where to point things + final int[] ports = nodePorts(hostOrdinal); + for (int port : ports) { + unicastHosts.add("localhost:" + port); + } + } + } + return unicastHosts.toArray(new String[unicastHosts.size()]); + } + @Override public Settings node(int nodeOrdinal) { Settings.Builder builder = Settings.builder() .put("discovery.zen.ping.multicast.enabled", false); - String[] unicastHosts = new String[unicastHostOrdinals.length]; if (localMode) { builder.put(LocalTransport.TRANSPORT_LOCAL_ADDRESS, "node_" + nodeOrdinal); - for (int i = 0; i < unicastHosts.length; i++) { - unicastHosts[i] = "node_" + unicastHostOrdinals[i]; - } - } else if (nodeOrdinal >= unicastHostPorts.length) { - throw new ElasticsearchException("nodeOrdinal [" + nodeOrdinal + "] is greater than the number unicast ports [" + unicastHostPorts.length + "]"); } else { // we need to pin the node port & host so we'd know where to point things - builder.put("transport.tcp.port", unicastHostPorts[nodeOrdinal]); - builder.put("transport.host", "localhost"); - for (int i = 0; i < unicastHostOrdinals.length; i++) { - unicastHosts[i] = "localhost:" + (unicastHostPorts[unicastHostOrdinals[i]]); + String ports = ""; + for (int port : nodePorts(nodeOrdinal)) { + ports += "," + port; } + builder.put("transport.tcp.port", ports.substring(1)); + builder.put("transport.host", "localhost"); } builder.putArray("discovery.zen.ping.unicast.hosts", unicastHosts); return builder.put(super.node(nodeOrdinal)).build(); } - protected synchronized static int[] unicastHostPorts(int numHosts) { - int[] unicastHostPorts = new int[numHosts]; + protected static int[] nodePorts(int nodeOridnal) { + int[] unicastHostPorts = new int[NUM_PORTS_PER_NODE]; - final int basePort = calcBasePort(); - final int maxPort = basePort + InternalTestCluster.PORTS_PER_JVM; - int tries = 0; + final int basePort = calcBasePort() + nodeOridnal * NUM_PORTS_PER_NODE; for (int i = 0; i < unicastHostPorts.length; i++) { - boolean foundPortInRange = false; - while (tries < InternalTestCluster.PORTS_PER_JVM && !foundPortInRange) { - try (ServerSocket serverSocket = new ServerSocket()) { - // Set SO_REUSEADDR as we may bind here and not be able to reuse the address immediately without it. - serverSocket.setReuseAddress(NetworkUtils.defaultReuseAddress()); - serverSocket.bind(new InetSocketAddress("127.0.0.1", nextPort)); - // bind was a success - foundPortInRange = true; - unicastHostPorts[i] = nextPort; - } catch (IOException e) { - // Do nothing - } - - nextPort++; - if (nextPort >= maxPort) { - // Roll back to the beginning of the range and do not go into another JVM's port range - nextPort = basePort; - } - tries++; - } - - if (!foundPortInRange) { - throw new ElasticsearchException("could not find enough open ports in range [" + basePort + "-" + maxPort + "]. required [" + unicastHostPorts.length + "] ports"); - } + unicastHostPorts[i] = basePort + i; } + return unicastHostPorts; } } From 828e31ce3279c214b290f227aa8e6e46be7cd26c Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 19 Aug 2015 10:00:30 +0200 Subject: [PATCH 41/54] Add serialization support for InterruptedException it's an important exception to serialize and we see it often in tests etc. but then it's wrapped in NotSerializableExceptionWrapper which is odd. This commit adds native support for this exception. --- .../common/io/stream/StreamInput.java | 2 ++ .../common/io/stream/StreamOutput.java | 3 +++ .../transport/netty/NettyTransport.java | 1 - .../ExceptionSerializationTests.java | 16 ++++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index cb42a9ff1b2..1b22a699913 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -542,6 +542,8 @@ public abstract class StreamInput extends InputStream { return (T) readStackTrace(new IllegalStateException(readOptionalString(), readThrowable()), this); case 17: return (T) readStackTrace(new LockObtainFailedException(readOptionalString(), readThrowable()), this); + case 18: + return (T) readStackTrace(new InterruptedException(readOptionalString()), this); default: assert false : "no such exception for id: " + key; } diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index afd607364c1..8ce9e24d6af 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -590,6 +590,9 @@ public abstract class StreamOutput extends OutputStream { writeVInt(16); } else if (throwable instanceof LockObtainFailedException) { writeVInt(17); + } else if (throwable instanceof InterruptedException) { + writeVInt(18); + writeCause = false; } else { ElasticsearchException ex; final String name = throwable.getClass().getName(); diff --git a/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java b/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java index 8a43e0581bd..e3f36bd24a3 100644 --- a/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java +++ b/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java @@ -497,7 +497,6 @@ public class NettyTransport extends AbstractLifecycleComponent implem serverBootstrap.setOption("child.receiveBufferSizePredictorFactory", receiveBufferSizePredictorFactory); serverBootstrap.setOption("reuseAddress", reuseAddress); serverBootstrap.setOption("child.reuseAddress", reuseAddress); - serverBootstraps.put(name, serverBootstrap); } diff --git a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index 034d31c23f4..889901e549a 100644 --- a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -607,4 +607,20 @@ public class ExceptionSerializationTests extends ESTestCase { assertEquals(ex.status(), e.status()); assertEquals(RestStatus.UNAUTHORIZED, e.status()); } + + public void testInterruptedException() throws IOException { + InterruptedException orig = randomBoolean() ? new InterruptedException("boom") : new InterruptedException(); + InterruptedException ex = serialize(orig); + assertEquals(orig.getMessage(), ex.getMessage()); + } + + public static class UnknownException extends Exception { + public UnknownException(String message) { + super(message); + } + + public UnknownException(String message, Throwable cause) { + super(message, cause); + } + } } From 8454d4955292c10fa875a97a8ccfb8d4e6c6d53f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 7 Aug 2015 16:05:39 +0200 Subject: [PATCH 42/54] Plugins: Add 'name' property to plugin descriptor file to determine plugin name At the moment, when installing from an url, a user provides the plugin name on the command line like: * bin/plugin install [plugin-name] --url [url] This can lead to problems when picking an already existing name from another plugin, and can potentially overwrite plugins already installed with that name. This, this PR introduces a mandatory `name` property to the plugin descriptor file which replaces the name formerly provided by the user. With the addition of the `name` property to the plugin descriptor file, the user does not need to specify the plugin name any longer when installing from a file or url. Because of this, all arguments to `plugin install` command are now either treated as a symbolic name, a URL or a file without the need to specify this with an explicit option. The new syntax for `plugin install` is now: bin/plugin install [name or url] * downloads official plugin bin/plugin install analysis-kuromoji * downloads github plugin bin/plugin install lmenezes/elasticsearch-kopf * install from URL or file bin/plugin install http://link.to/foo.zip bin/plugin install file:/path/to/foo.zip If the argument does not parse to a valid URL, it is assumed to be a name and the download location is resolved like before. Regardless of the source location of the plugin, it is extracted to a temporary directory and the `name` property from the descriptor file is used to determine the final install location. Relates to #12715 --- .../org/elasticsearch/plugins/PluginInfo.java | 15 +++-- .../elasticsearch/plugins/PluginManager.java | 37 +++++++----- .../plugins/PluginManagerCliParser.java | 34 ++++++++--- .../elasticsearch/plugins/plugin-install.help | 12 ++-- .../plugins/PluginInfoTests.java | 45 ++++++++++++--- .../plugins/PluginManagerIT.java | 56 +++++++++++-------- .../plugin-descriptor.properties | 1 + .../dummy/plugin-descriptor.properties | 1 + .../subdir/plugin-descriptor.properties | 1 + .../main/resources/ant/integration-tests.xml | 2 - .../plugin-descriptor.properties | 3 + docs/plugins/plugin-script.asciidoc | 6 +- plugins/pom.xml | 2 + 13 files changed, 148 insertions(+), 67 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java b/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java index 66f24e3a8c8..20b5fe28fff 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java @@ -52,7 +52,7 @@ public class PluginInfo implements Streamable, ToXContent { private String description; private boolean site; private String version; - + private boolean jvm; private String classname; private boolean isolated; @@ -86,7 +86,11 @@ public class PluginInfo implements Streamable, ToXContent { try (InputStream stream = Files.newInputStream(descriptor)) { props.load(stream); } - String name = dir.getFileName().toString(); + String name = props.getProperty("name"); + if (name == null || name.isEmpty()) { + throw new IllegalArgumentException("Property [name] is missing in [" + descriptor + "]"); + } + PluginManager.checkForForbiddenName(name); String description = props.getProperty("description"); if (description == null) { throw new IllegalArgumentException("Property [description] is missing for plugin [" + name + "]"); @@ -95,6 +99,7 @@ public class PluginInfo implements Streamable, ToXContent { if (version == null) { throw new IllegalArgumentException("Property [version] is missing for plugin [" + name + "]"); } + boolean jvm = Boolean.parseBoolean(props.getProperty("jvm")); boolean site = Boolean.parseBoolean(props.getProperty("site")); if (jvm == false && site == false) { @@ -122,7 +127,7 @@ public class PluginInfo implements Streamable, ToXContent { throw new IllegalArgumentException("Property [classname] is missing for jvm plugin [" + name + "]"); } } - + if (site) { if (!Files.exists(dir.resolve("_site"))) { throw new IllegalArgumentException("Plugin [" + name + "] is a site plugin but has no '_site/' directory"); @@ -159,14 +164,14 @@ public class PluginInfo implements Streamable, ToXContent { public boolean isJvm() { return jvm; } - + /** * @return true if jvm plugin has isolated classloader */ public boolean isIsolated() { return isolated; } - + /** * @return jvm plugin's classname */ diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java index 234d719f734..3a3e11e0b89 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java @@ -91,11 +91,11 @@ public class PluginManager { ).build(); private final Environment environment; - private String url; + private URL url; private OutputMode outputMode; private TimeValue timeout; - public PluginManager(Environment environment, String url, OutputMode outputMode, TimeValue timeout) { + public PluginManager(Environment environment, URL url, OutputMode outputMode, TimeValue timeout) { this.environment = environment; this.url = url; this.outputMode = outputMode; @@ -103,8 +103,8 @@ public class PluginManager { } public void downloadAndExtract(String name, Terminal terminal) throws IOException { - if (name == null) { - throw new IllegalArgumentException("plugin name must be supplied with install [name]."); + if (name == null && url == null) { + throw new IllegalArgumentException("plugin name or url must be supplied with install."); } if (!Files.exists(environment.pluginsFile())) { @@ -116,8 +116,14 @@ public class PluginManager { throw new IOException("plugin directory " + environment.pluginsFile() + " is read only"); } - PluginHandle pluginHandle = PluginHandle.parse(name); - checkForForbiddenName(pluginHandle.name); + PluginHandle pluginHandle; + if (name != null) { + pluginHandle = PluginHandle.parse(name); + checkForForbiddenName(pluginHandle.name); + } else { + // if we have no name but url, use temporary name that will be overwritten later + pluginHandle = new PluginHandle("temp_name" + new Random().nextInt(), null, null); + } Path pluginFile = download(pluginHandle, terminal); extract(pluginHandle, terminal, pluginFile); @@ -138,7 +144,7 @@ public class PluginManager { // first, try directly from the URL provided if (url != null) { - URL pluginUrl = new URL(url); + URL pluginUrl = url; boolean isSecureProcotol = "https".equalsIgnoreCase(pluginUrl.getProtocol()); boolean isAuthInfoSet = !Strings.isNullOrEmpty(pluginUrl.getUserInfo()); if (isAuthInfoSet && !isSecureProcotol) { @@ -204,14 +210,10 @@ public class PluginManager { } private void extract(PluginHandle pluginHandle, Terminal terminal, Path pluginFile) throws IOException { - final Path extractLocation = pluginHandle.extractedDir(environment); - if (Files.exists(extractLocation)) { - throw new IOException("plugin directory " + extractLocation.toAbsolutePath() + " already exists. To update the plugin, uninstall it first using 'remove " + pluginHandle.name + "' command"); - } // unzip plugin to a staging temp dir, named for the plugin Path tmp = Files.createTempDirectory(environment.tmpFile(), null); - Path root = tmp.resolve(pluginHandle.name); + Path root = tmp.resolve(pluginHandle.name); unzipPlugin(pluginFile, root); // find the actual root (in case its unzipped with extra directory wrapping) @@ -226,6 +228,13 @@ public class PluginManager { jarHellCheck(root, info.isIsolated()); } + // update name in handle based on 'name' property found in descriptor file + pluginHandle = new PluginHandle(info.getName(), pluginHandle.version, pluginHandle.user); + final Path extractLocation = pluginHandle.extractedDir(environment); + if (Files.exists(extractLocation)) { + throw new IOException("plugin directory " + extractLocation.toAbsolutePath() + " already exists. To update the plugin, uninstall it first using 'remove " + pluginHandle.name + "' command"); + } + // install plugin FileSystemUtils.copyDirectoryRecursively(root, extractLocation); terminal.println("Installed %s into %s", pluginHandle.name, extractLocation.toAbsolutePath()); @@ -334,7 +343,7 @@ public class PluginManager { private void unzipPlugin(Path zip, Path target) throws IOException { Files.createDirectories(target); - + try (ZipInputStream zipInput = new ZipInputStream(Files.newInputStream(zip))) { ZipEntry entry; byte[] buffer = new byte[8192]; @@ -395,7 +404,7 @@ public class PluginManager { } } - private static void checkForForbiddenName(String name) { + static void checkForForbiddenName(String name) { if (!hasLength(name) || BLACKLIST.contains(name.toLowerCase(Locale.ROOT))) { throw new IllegalArgumentException("Illegal plugin name: " + name); } diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginManagerCliParser.java b/core/src/main/java/org/elasticsearch/plugins/PluginManagerCliParser.java index 3732e8bda08..7f521fd4339 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginManagerCliParser.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginManagerCliParser.java @@ -20,6 +20,7 @@ package org.elasticsearch.plugins; import com.google.common.base.Strings; + import org.apache.commons.cli.CommandLine; import org.elasticsearch.common.cli.CliTool; import org.elasticsearch.common.cli.CliToolConfig; @@ -32,7 +33,8 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.plugins.PluginManager.OutputMode; -import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Locale; import static org.elasticsearch.common.cli.CliToolConfig.Builder.cmd; @@ -166,19 +168,29 @@ public class PluginManagerCliParser extends CliTool { private static final String NAME = "install"; private static final CliToolConfig.Cmd CMD = cmd(NAME, Install.class) - .options(option("u", "url").required(false).hasArg(true)) .options(option("t", "timeout").required(false).hasArg(false)) .build(); static Command parse(Terminal terminal, CommandLine cli) { String[] args = cli.getArgs(); + + // install [plugin-name/url] if ((args == null) || (args.length == 0)) { - return exitCmd(ExitStatus.USAGE, terminal, "plugin name is missing (type -h for help)"); + return exitCmd(ExitStatus.USAGE, terminal, "plugin name or url is missing (type -h for help)"); + } + String name = args[0]; + + URL optionalPluginUrl = null; + // try parsing cli argument as URL + try { + optionalPluginUrl = new URL(name); + name = null; + } catch (MalformedURLException e) { + // we tried to parse the cli argument as url and failed + // continue treating it as a symbolic plugin name like `analysis-icu` etc. } - String name = args[0]; TimeValue timeout = TimeValue.parseTimeValue(cli.getOptionValue("t"), DEFAULT_TIMEOUT, "cli"); - String url = cli.getOptionValue("u"); OutputMode outputMode = OutputMode.DEFAULT; if (cli.hasOption("s")) { @@ -188,15 +200,15 @@ public class PluginManagerCliParser extends CliTool { outputMode = OutputMode.VERBOSE; } - return new Install(terminal, name, outputMode, url, timeout); + return new Install(terminal, name, outputMode, optionalPluginUrl, timeout); } final String name; private OutputMode outputMode; - final String url; + final URL url; final TimeValue timeout; - Install(Terminal terminal, String name, OutputMode outputMode, String url, TimeValue timeout) { + Install(Terminal terminal, String name, OutputMode outputMode, URL url, TimeValue timeout) { super(terminal); this.name = name; this.outputMode = outputMode; @@ -207,7 +219,11 @@ public class PluginManagerCliParser extends CliTool { @Override public ExitStatus execute(Settings settings, Environment env) throws Exception { PluginManager pluginManager = new PluginManager(env, url, outputMode, timeout); - terminal.println("-> Installing " + Strings.nullToEmpty(name) + "..."); + if (name != null) { + terminal.println("-> Installing " + Strings.nullToEmpty(name) + "..."); + } else { + terminal.println("-> Installing from " + url + "..."); + } pluginManager.downloadAndExtract(name, terminal); return ExitStatus.OK; } diff --git a/core/src/main/resources/org/elasticsearch/plugins/plugin-install.help b/core/src/main/resources/org/elasticsearch/plugins/plugin-install.help index 9aa943da46c..e09c1bdfaf7 100644 --- a/core/src/main/resources/org/elasticsearch/plugins/plugin-install.help +++ b/core/src/main/resources/org/elasticsearch/plugins/plugin-install.help @@ -4,13 +4,13 @@ NAME SYNOPSIS - plugin install + plugin install DESCRIPTION This command installs an elasticsearch plugin - can be one of the official plugins, or refer to a github repository, or to one of the official plugins + The argument can be a of one of the official plugins, or refer to a github repository The notation of just specifying a plugin name, downloads an officially supported plugin. @@ -20,6 +20,8 @@ DESCRIPTION The notation of 'username/repository' refers to a github repository. + The argument can be an valid which points to a download or file location for the plugin to be loaded from. + EXAMPLES plugin install analysis-kuromoji @@ -28,6 +30,10 @@ EXAMPLES plugin install lmenezes/elasticsearch-kopf + plugin install http://download.elasticsearch.org/elasticsearch/elasticsearch-analysis-kuromoji/elasticsearch-analysis-kuromoji-2.7.0.zip + + plugin install file:/path/to/plugin/elasticsearch-analysis-kuromoji-2.7.0.zip + OFFICIAL PLUGINS The following plugins are officially supported and can be installed by just referring to their name @@ -49,8 +55,6 @@ OFFICIAL PLUGINS OPTIONS - -u,--url URL to retrieve the plugin from - -t,--timeout Timeout until the plugin download is abort -v,--verbose Verbose output diff --git a/core/src/test/java/org/elasticsearch/plugins/PluginInfoTests.java b/core/src/test/java/org/elasticsearch/plugins/PluginInfoTests.java index 2cdf82322bb..64b2ae59312 100644 --- a/core/src/test/java/org/elasticsearch/plugins/PluginInfoTests.java +++ b/core/src/test/java/org/elasticsearch/plugins/PluginInfoTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.plugins; import com.google.common.base.Function; import com.google.common.collect.Lists; + import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.node.info.PluginsInfo; import org.elasticsearch.test.ESTestCase; @@ -53,13 +54,14 @@ public class PluginInfoTests extends ESTestCase { Path pluginDir = createTempDir().resolve("fake-plugin"); writeProperties(pluginDir, "description", "fake desc", + "name", "my_plugin", "version", "1.0", "elasticsearch.version", Version.CURRENT.toString(), "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); PluginInfo info = PluginInfo.readFromProperties(pluginDir); - assertEquals("fake-plugin", info.getName()); + assertEquals("my_plugin", info.getName()); assertEquals("fake desc", info.getDescription()); assertEquals("1.0", info.getVersion()); assertEquals("FakePlugin", info.getClassname()); @@ -69,9 +71,28 @@ public class PluginInfoTests extends ESTestCase { assertNull(info.getUrl()); } - public void testReadFromPropertiesDescriptionMissing() throws Exception { + public void testReadFromPropertiesNameMissing() throws Exception { Path pluginDir = createTempDir().resolve("fake-plugin"); writeProperties(pluginDir); + try { + PluginInfo.readFromProperties(pluginDir); + fail("expected missing name exception"); + } catch (IllegalArgumentException e) { + assertTrue(e.getMessage().contains("Property [name] is missing in")); + } + + writeProperties(pluginDir, "name", ""); + try { + PluginInfo.readFromProperties(pluginDir); + fail("expected missing name exception"); + } catch (IllegalArgumentException e) { + assertTrue(e.getMessage().contains("Property [name] is missing in")); + } + } + + public void testReadFromPropertiesDescriptionMissing() throws Exception { + Path pluginDir = createTempDir().resolve("fake-plugin"); + writeProperties(pluginDir, "name", "fake-plugin"); try { PluginInfo.readFromProperties(pluginDir); fail("expected missing description exception"); @@ -82,7 +103,7 @@ public class PluginInfoTests extends ESTestCase { public void testReadFromPropertiesVersionMissing() throws Exception { Path pluginDir = createTempDir().resolve("fake-plugin"); - writeProperties(pluginDir, "description", "fake desc"); + writeProperties(pluginDir, "description", "fake desc", "name", "fake-plugin"); try { PluginInfo.readFromProperties(pluginDir); fail("expected missing version exception"); @@ -95,7 +116,8 @@ public class PluginInfoTests extends ESTestCase { Path pluginDir = createTempDir().resolve("fake-plugin"); writeProperties(pluginDir, "description", "fake desc", - "version", "1.0"); + "version", "1.0", + "name", "my_plugin"); try { PluginInfo.readFromProperties(pluginDir); fail("expected jvm or site exception"); @@ -108,6 +130,7 @@ public class PluginInfoTests extends ESTestCase { Path pluginDir = createTempDir().resolve("fake-plugin"); writeProperties(pluginDir, "description", "fake desc", + "name", "my_plugin", "version", "1.0", "jvm", "true"); try { @@ -122,6 +145,7 @@ public class PluginInfoTests extends ESTestCase { Path pluginDir = createTempDir().resolve("fake-plugin"); writeProperties(pluginDir, "description", "fake desc", + "name", "my_plugin", "elasticsearch.version", Version.CURRENT.toString(), "version", "1.0", "jvm", "true"); @@ -134,9 +158,11 @@ public class PluginInfoTests extends ESTestCase { } public void testReadFromPropertiesJavaVersionIncompatible() throws Exception { - Path pluginDir = createTempDir().resolve("fake-plugin"); + String pluginName = "fake-plugin"; + Path pluginDir = createTempDir().resolve(pluginName); writeProperties(pluginDir, "description", "fake desc", + "name", pluginName, "elasticsearch.version", Version.CURRENT.toString(), "java.version", "1000000.0", "classname", "FakePlugin", @@ -146,7 +172,7 @@ public class PluginInfoTests extends ESTestCase { PluginInfo.readFromProperties(pluginDir); fail("expected incompatible java version exception"); } catch (IllegalStateException e) { - assertTrue(e.getMessage(), e.getMessage().contains("fake-plugin requires Java")); + assertTrue(e.getMessage(), e.getMessage().contains(pluginName + " requires Java")); } } @@ -156,6 +182,7 @@ public class PluginInfoTests extends ESTestCase { "description", "fake desc", "version", "1.0", "jvm", "true", + "name", "my_plugin", "elasticsearch.version", "bogus"); try { PluginInfo.readFromProperties(pluginDir); @@ -169,6 +196,7 @@ public class PluginInfoTests extends ESTestCase { Path pluginDir = createTempDir().resolve("fake-plugin"); writeProperties(pluginDir, "description", "fake desc", + "name", "my_plugin", "version", "1.0", "jvm", "true", "elasticsearch.version", Version.V_1_7_0.toString()); @@ -184,6 +212,7 @@ public class PluginInfoTests extends ESTestCase { Path pluginDir = createTempDir().resolve("fake-plugin"); writeProperties(pluginDir, "description", "fake desc", + "name", "my_plugin", "version", "1.0", "elasticsearch.version", Version.CURRENT.toString(), "java.version", System.getProperty("java.specification.version"), @@ -201,6 +230,7 @@ public class PluginInfoTests extends ESTestCase { Files.createDirectories(pluginDir.resolve("_site")); writeProperties(pluginDir, "description", "fake desc", + "name", "my_plugin", "version", "1.0", "site", "true"); PluginInfo info = PluginInfo.readFromProperties(pluginDir); @@ -208,11 +238,12 @@ public class PluginInfoTests extends ESTestCase { assertFalse(info.isJvm()); assertEquals("NA", info.getClassname()); } - + public void testReadFromPropertiesSitePluginWithoutSite() throws Exception { Path pluginDir = createTempDir().resolve("fake-plugin"); writeProperties(pluginDir, "description", "fake desc", + "name", "my_plugin", "version", "1.0", "site", "true"); try { diff --git a/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java b/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java index 4acb818c180..e4d13b677b2 100644 --- a/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java +++ b/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java @@ -175,11 +175,13 @@ public class PluginManagerIT extends ESIntegTestCase { Path pluginDir = createTempDir().resolve("fake-plugin"); String pluginUrl = createPlugin(pluginDir, "description", "fake desc", + "name", "fake-plugin", "version", "1.0", "elasticsearch.version", Version.CURRENT.toString(), + "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - assertStatus("install --url " + pluginUrl, USAGE); + assertStatus("install", USAGE); } @Test @@ -191,21 +193,22 @@ public class PluginManagerIT extends ESIntegTestCase { Files.createFile(pluginDir.resolve("bin").resolve("tool")); Files.createDirectories(pluginDir.resolve("config")); Files.createFile(pluginDir.resolve("config").resolve("file")); - + String pluginUrl = createPlugin(pluginDir, "description", "fake desc", + "name", pluginName, "version", "1.0", "elasticsearch.version", Version.CURRENT.toString(), "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - + Environment env = initialSettings.v2(); Path binDir = env.binFile(); Path pluginBinDir = binDir.resolve(pluginName); Path pluginConfigDir = env.configFile().resolve(pluginName); - assertStatusOk("install " + pluginName + " --url " + pluginUrl + " --verbose"); + assertStatusOk("install " + pluginUrl + " --verbose"); terminal.getTerminalOutput().clear(); assertStatusOk("list"); @@ -236,19 +239,20 @@ public class PluginManagerIT extends ESIntegTestCase { // create config/test.txt with contents 'version1' Files.createDirectories(pluginDir.resolve("config")); Files.write(pluginDir.resolve("config").resolve("test.txt"), "version1".getBytes(StandardCharsets.UTF_8)); - + String pluginUrl = createPlugin(pluginDir, "description", "fake desc", + "name", pluginName, "version", "1.0", "elasticsearch.version", Version.CURRENT.toString(), "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - + Environment env = initialSettings.v2(); Path pluginConfigDir = env.configFile().resolve(pluginName); - assertStatusOk(String.format(Locale.ROOT, "install %s --url %s --verbose", pluginName, pluginUrl)); + assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginUrl)); /* First time, our plugin contains: @@ -275,13 +279,14 @@ public class PluginManagerIT extends ESIntegTestCase { Files.write(pluginDir.resolve("config").resolve("dir").resolve("subdir").resolve("testsubdir.txt"), "version1".getBytes(StandardCharsets.UTF_8)); pluginUrl = createPlugin(pluginDir, "description", "fake desc", + "name", pluginName, "version", "2.0", "elasticsearch.version", Version.CURRENT.toString(), "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - - assertStatusOk(String.format(Locale.ROOT, "install %s --url %s --verbose", pluginName, pluginUrl)); + + assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginUrl)); assertFileContent(pluginConfigDir, "test.txt", "version1"); assertFileContent(pluginConfigDir, "test.txt.new", "version2"); @@ -311,13 +316,14 @@ public class PluginManagerIT extends ESIntegTestCase { Files.write(pluginDir.resolve("config").resolve("dir").resolve("subdir").resolve("testsubdir.txt"), "version2".getBytes(StandardCharsets.UTF_8)); pluginUrl = createPlugin(pluginDir, "description", "fake desc", + "name", pluginName, "version", "3.0", "elasticsearch.version", Version.CURRENT.toString(), "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - assertStatusOk(String.format(Locale.ROOT, "install %s --url %s --verbose", pluginName, pluginUrl)); + assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginUrl)); assertFileContent(pluginConfigDir, "test.txt", "version1"); assertFileContent(pluginConfigDir, "test2.txt", "version1"); @@ -339,17 +345,18 @@ public class PluginManagerIT extends ESIntegTestCase { Files.createFile(pluginDir.resolve("bin").resolve("tool"));; String pluginUrl = createPlugin(pluginDir, "description", "fake desc", + "name", "fake-plugin", "version", "1.0", "elasticsearch.version", Version.CURRENT.toString(), "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - + Environment env = initialSettings.v2(); Path binDir = env.binFile(); Path pluginBinDir = binDir.resolve(pluginName); - assertStatusOk(String.format(Locale.ROOT, "install %s --url %s --verbose", pluginName, pluginUrl)); + assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginUrl)); assertThatPluginIsListed(pluginName); assertDirectoryExists(pluginBinDir); } @@ -373,12 +380,13 @@ public class PluginManagerIT extends ESIntegTestCase { Path pluginDir = createTempDir().resolve(pluginName); String pluginUrl = createPlugin(pluginDir, "description", "fake desc", + "name", pluginName, "version", "1.0", "elasticsearch.version", Version.CURRENT.toString(), "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - assertStatusOk(String.format(Locale.ROOT, "install %s --url %s --verbose", pluginName, pluginUrl)); + assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginUrl)); assertThatPluginIsListed(pluginName); } @@ -389,10 +397,11 @@ public class PluginManagerIT extends ESIntegTestCase { Files.createDirectories(pluginDir.resolve("_site")); Files.createFile(pluginDir.resolve("_site").resolve("somefile")); String pluginUrl = createPlugin(pluginDir, - "description", "fake desc", - "version", "1.0", - "site", "true"); - assertStatusOk(String.format(Locale.ROOT, "install %s --url %s --verbose", pluginName, pluginUrl)); + "description", "fake desc", + "name", pluginName, + "version", "1.0", + "site", "true"); + assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginUrl)); assertThatPluginIsListed(pluginName); // We want to check that Plugin Manager moves content to _site assertFileExists(initialSettings.v2().pluginsFile().resolve(pluginName).resolve("_site")); @@ -408,7 +417,7 @@ public class PluginManagerIT extends ESIntegTestCase { "description", "fake desc", "version", "1.0", "site", "true"); - assertStatus(String.format(Locale.ROOT, "install %s --url %s --verbose", pluginName, pluginUrl), + assertStatus(String.format(Locale.ROOT, "install %s --verbose", pluginUrl), ExitStatus.IO_ERROR); assertThatPluginIsNotListed(pluginName); assertFileNotExists(initialSettings.v2().pluginsFile().resolve(pluginName).resolve("_site")); @@ -419,7 +428,7 @@ public class PluginManagerIT extends ESIntegTestCase { if (pluginCoordinates == null) { assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginDescriptor)); } else { - assertStatusOk(String.format(Locale.ROOT, "install %s --url %s --verbose", pluginDescriptor, pluginCoordinates)); + assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginCoordinates)); } assertThatPluginIsListed(pluginName); @@ -493,15 +502,16 @@ public class PluginManagerIT extends ESIntegTestCase { @Test public void testRemovePlugin() throws Exception { String pluginName = "plugintest"; - Path pluginDir = createTempDir().resolve(pluginName); + Path pluginDir = createTempDir().resolve(pluginName); String pluginUrl = createPlugin(pluginDir, "description", "fake desc", + "name", pluginName, "version", "1.0.0", "elasticsearch.version", Version.CURRENT.toString(), "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - + // We want to remove plugin with plugin short name singlePluginInstallAndRemove("plugintest", "plugintest", pluginUrl); @@ -561,7 +571,7 @@ public class PluginManagerIT extends ESIntegTestCase { @Test public void testThatBasicAuthIsRejectedOnHttp() throws Exception { - assertStatus(String.format(Locale.ROOT, "install foo --url http://user:pass@localhost:12345/foo.zip --verbose"), CliTool.ExitStatus.IO_ERROR); + assertStatus(String.format(Locale.ROOT, "install http://user:pass@localhost:12345/foo.zip --verbose"), CliTool.ExitStatus.IO_ERROR); assertThat(terminal.getTerminalOutput(), hasItem(containsString("Basic auth is only supported for HTTPS!"))); } @@ -598,7 +608,7 @@ public class PluginManagerIT extends ESIntegTestCase { Channel channel = serverBootstrap.bind(new InetSocketAddress("localhost", 0)); int port = ((InetSocketAddress) channel.getLocalAddress()).getPort(); // IO_ERROR because there is no real file delivered... - assertStatus(String.format(Locale.ROOT, "install foo --url https://user:pass@localhost:%s/foo.zip --verbose --timeout 1s", port), ExitStatus.IO_ERROR); + assertStatus(String.format(Locale.ROOT, "install https://user:pass@localhost:%s/foo.zip --verbose --timeout 1s", port), ExitStatus.IO_ERROR); // ensure that we did not try any other data source like download.elastic.co, in case we specified our own local URL assertThat(terminal.getTerminalOutput(), not(hasItem(containsString("download.elastic.co")))); diff --git a/core/src/test/resources/org/elasticsearch/test_plugins/anotherplugin/plugin-descriptor.properties b/core/src/test/resources/org/elasticsearch/test_plugins/anotherplugin/plugin-descriptor.properties index 8a08b726b50..66741adf220 100644 --- a/core/src/test/resources/org/elasticsearch/test_plugins/anotherplugin/plugin-descriptor.properties +++ b/core/src/test/resources/org/elasticsearch/test_plugins/anotherplugin/plugin-descriptor.properties @@ -1,3 +1,4 @@ site=true description=anotherplugin version=1.0 +name=anotherplugin diff --git a/core/src/test/resources/org/elasticsearch/test_plugins/dummy/plugin-descriptor.properties b/core/src/test/resources/org/elasticsearch/test_plugins/dummy/plugin-descriptor.properties index 71f5a590274..91ae24c8201 100644 --- a/core/src/test/resources/org/elasticsearch/test_plugins/dummy/plugin-descriptor.properties +++ b/core/src/test/resources/org/elasticsearch/test_plugins/dummy/plugin-descriptor.properties @@ -1,3 +1,4 @@ site=true description=dummy version=1.0 +name=dummy diff --git a/core/src/test/resources/org/elasticsearch/test_plugins/subdir/plugin-descriptor.properties b/core/src/test/resources/org/elasticsearch/test_plugins/subdir/plugin-descriptor.properties index f6a05a4f499..fa8950e2a55 100644 --- a/core/src/test/resources/org/elasticsearch/test_plugins/subdir/plugin-descriptor.properties +++ b/core/src/test/resources/org/elasticsearch/test_plugins/subdir/plugin-descriptor.properties @@ -1,3 +1,4 @@ site=true description=subdir version=1.0 +name=subdir diff --git a/dev-tools/src/main/resources/ant/integration-tests.xml b/dev-tools/src/main/resources/ant/integration-tests.xml index f5e87c033e3..307eaba01ee 100644 --- a/dev-tools/src/main/resources/ant/integration-tests.xml +++ b/dev-tools/src/main/resources/ant/integration-tests.xml @@ -87,8 +87,6 @@ - - diff --git a/dev-tools/src/main/resources/plugin-metadata/plugin-descriptor.properties b/dev-tools/src/main/resources/plugin-metadata/plugin-descriptor.properties index 26bee6df895..09b68b7a24d 100644 --- a/dev-tools/src/main/resources/plugin-metadata/plugin-descriptor.properties +++ b/dev-tools/src/main/resources/plugin-metadata/plugin-descriptor.properties @@ -36,6 +36,9 @@ description=${project.description} # 'version': plugin's version version=${project.version} # +# 'name': the plugin name +name=${elasticsearch.plugin.name} + ### mandatory elements for site plugins: # # 'site': set to true to indicate contents of the _site/ diff --git a/docs/plugins/plugin-script.asciidoc b/docs/plugins/plugin-script.asciidoc index 06263d730ad..fc1c91c1530 100644 --- a/docs/plugins/plugin-script.asciidoc +++ b/docs/plugins/plugin-script.asciidoc @@ -84,15 +84,15 @@ A plugin can also be downloaded directly from a custom location by specifying th [source,shell] ----------------------------------- -sudo bin/plugin install [plugin-name] --url [url] <1> +sudo bin/plugin install [url] <1> ----------------------------------- -<1> Both the URL and the plugin name must be specified. +<1> must be a valid URL, the plugin name is determined from its descriptor. For instance, to install a plugin from your local file system, you could run: [source,shell] ----------------------------------- -sudo bin/plugin install my_plugin --url file:/path/to/plugin.zip +sudo bin/plugin install file:/path/to/plugin.zip ----------------------------------- [[listing-removing]] diff --git a/plugins/pom.xml b/plugins/pom.xml index 5bc7f5f83f2..90bba7e1776 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -22,6 +22,7 @@ ${elasticsearch.tools.directory}/plugin-metadata/plugin-assembly.xml false + ${project.artifactId} true true false @@ -365,6 +366,7 @@ elasticsearch.plugin.classname + elasticsearch.plugin.name From bd56b0a79efe4820469ea907f620da0be207d4c6 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 19 Aug 2015 14:54:56 +0200 Subject: [PATCH 43/54] Only resolve host if explicitly allowed. We have some settings that prevent host name resolution which should be repected by InetSocketTransportAddress#getHost() to only resolve if allowed or desired. --- .../common/transport/InetSocketTransportAddress.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java b/core/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java index f4f686ff2e5..07db52b4fbe 100644 --- a/core/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java +++ b/core/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java @@ -94,7 +94,11 @@ public final class InetSocketTransportAddress implements TransportAddress { @Override public String getHost() { - return address.getHostName(); + if (resolveAddress) { + return address.getHostName(); + } else { + return getAddress(); + } } @Override From 88d482437a39d0d45aeea19b372c9a9f768b9f40 Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Wed, 19 Aug 2015 14:31:30 +0100 Subject: [PATCH 44/54] Aggregations: Throw error if cardinality aggregator has a sub aggregation The cardinality aggregation is a metric aggregation and therefore cannot accept sub-aggregations. It was previously possible to create a rest request with a cardinality aggregation that had sub-aggregations. Now such a request will throw an error in the response. Close #12988 --- .../metrics/cardinality/CardinalityAggregatorFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityAggregatorFactory.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityAggregatorFactory.java index 1e660f06f45..1b2d5fc1014 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityAggregatorFactory.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityAggregatorFactory.java @@ -31,7 +31,7 @@ import java.io.IOException; import java.util.List; import java.util.Map; -final class CardinalityAggregatorFactory extends ValuesSourceAggregatorFactory { +final class CardinalityAggregatorFactory extends ValuesSourceAggregatorFactory.LeafOnly { private final long precisionThreshold; From dba1b52e81797eeb57c7a6ceeecf2e74142e5ce3 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 19 Aug 2015 15:37:28 +0200 Subject: [PATCH 45/54] [build] rpm module should be build on machine with /usr/bin/rpmbuild We build the rpm module automatically if you have either: * `/usr/bin/rpmbuild` * `/usr/local/bin/rpmbuild` available. If your `rpmbuild` is in another location and available in your path, then run maven with `rpm` profile: ```sh mvn deploy -Prpm ``` Closes #12984. --- distribution/pom.xml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/distribution/pom.xml b/distribution/pom.xml index 52969ee779c..41a17293f45 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -33,9 +33,6 @@ ${project.basedir}/../licenses ${integ.scratch} - - /usr/bin/rpmbuild - true @@ -172,6 +169,11 @@ + macos_brew @@ -190,7 +192,7 @@ - ${packaging.rpm.rpmbuild} + /usr/bin/rpmbuild From 22ae0a161f325f7af921df2062a974ce325d526c Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 19 Aug 2015 17:20:48 +0200 Subject: [PATCH 46/54] Log all interfaces we try to bind before binding --- .../java/org/elasticsearch/transport/netty/NettyTransport.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java b/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java index e3f36bd24a3..372c3b42cb6 100644 --- a/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java +++ b/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java @@ -404,6 +404,9 @@ public class NettyTransport extends AbstractLifecycleComponent implem } catch (IOException e) { throw new BindTransportException("Failed to resolve host [" + bindHost + "]", e); } + if (logger.isDebugEnabled()) { + logger.debug("binding server bootstrap to: {}", hostAddresses); + } for (InetAddress hostAddress : hostAddresses) { bindServerBootstrap(name, hostAddress, settings); } From 4cc6359756da6999a1c1ffd75bed3cd7ec0d1007 Mon Sep 17 00:00:00 2001 From: Britta Weber Date: Tue, 18 Aug 2015 17:38:06 +0200 Subject: [PATCH 47/54] fail with better error message if elasticsearch was started already Before it failed with .../es/qa/smoke-test-plugins/target/integ-tests/es.pid doesn't exist which was confusing. --- dev-tools/src/main/resources/ant/integration-tests.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dev-tools/src/main/resources/ant/integration-tests.xml b/dev-tools/src/main/resources/ant/integration-tests.xml index d710e57a076..0e73f13d34b 100644 --- a/dev-tools/src/main/resources/ant/integration-tests.xml +++ b/dev-tools/src/main/resources/ant/integration-tests.xml @@ -157,6 +157,14 @@ + + + + + + Starting up external cluster... From ce120b9c7166386a6e5be3a868e4454bfe1eeeaf Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 19 Aug 2015 12:06:54 -0400 Subject: [PATCH 48/54] Deduplicate addresses from resolver. In some cases this may contain duplicates, although its a misconfiguration, lets not bind to multiple ports. Its no problem for us to dedup, this code doesn't need to be huper-duper fast since its used only for logic around bind/publish --- .../common/network/NetworkUtils.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/network/NetworkUtils.java b/core/src/main/java/org/elasticsearch/common/network/NetworkUtils.java index 39705e82905..af82e052ad0 100644 --- a/core/src/main/java/org/elasticsearch/common/network/NetworkUtils.java +++ b/core/src/main/java/org/elasticsearch/common/network/NetworkUtils.java @@ -21,8 +21,6 @@ package org.elasticsearch.common.network; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.Constants; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; import java.net.Inet4Address; import java.net.Inet6Address; @@ -34,10 +32,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; +import java.util.HashSet; import java.util.List; /** - * Utilities for network interfaces / addresses + * Utilities for network interfaces / addresses binding and publishing. + * Its only intended for that purpose, not general purpose usage!!!! */ public abstract class NetworkUtils { @@ -84,7 +84,7 @@ public abstract class NetworkUtils { * @deprecated remove this when multihoming is really correct */ @Deprecated - private static void sortAddresses(List list) { + static void sortAddresses(List list) { Collections.sort(list, new Comparator() { @Override public int compare(InetAddress left, InetAddress right) { @@ -97,8 +97,6 @@ public abstract class NetworkUtils { }); } - private final static ESLogger logger = Loggers.getLogger(NetworkUtils.class); - /** Return all interfaces (and subinterfaces) on the system */ static List getInterfaces() throws SocketException { List all = new ArrayList<>(); @@ -128,7 +126,7 @@ public abstract class NetworkUtils { } /** Returns addresses for all loopback interfaces that are up. */ - public static InetAddress[] getLoopbackAddresses() throws SocketException { + static InetAddress[] getLoopbackAddresses() throws SocketException { List list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isLoopback() && intf.isUp()) { @@ -143,7 +141,7 @@ public abstract class NetworkUtils { } /** Returns addresses for the first non-loopback interface that is up. */ - public static InetAddress[] getFirstNonLoopbackAddresses() throws SocketException { + static InetAddress[] getFirstNonLoopbackAddresses() throws SocketException { List list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isLoopback() == false && intf.isUp()) { @@ -159,7 +157,7 @@ public abstract class NetworkUtils { } /** Returns addresses for the given interface (it must be marked up) */ - public static InetAddress[] getAddressesForInterface(String name) throws SocketException { + static InetAddress[] getAddressesForInterface(String name) throws SocketException { NetworkInterface intf = NetworkInterface.getByName(name); if (intf == null) { throw new IllegalArgumentException("No interface named '" + name + "' found, got " + getInterfaces()); @@ -176,14 +174,17 @@ public abstract class NetworkUtils { } /** Returns addresses for the given host, sorted by order of preference */ - public static InetAddress[] getAllByName(String host) throws UnknownHostException { + static InetAddress[] getAllByName(String host) throws UnknownHostException { InetAddress addresses[] = InetAddress.getAllByName(host); - sortAddresses(Arrays.asList(addresses)); - return addresses; + // deduplicate, in case of resolver misconfiguration + // stuff like https://bugzilla.redhat.com/show_bug.cgi?id=496300 + List unique = new ArrayList<>(new HashSet<>(Arrays.asList(addresses))); + sortAddresses(unique); + return unique.toArray(new InetAddress[unique.size()]); } /** Returns only the IPV4 addresses in {@code addresses} */ - public static InetAddress[] filterIPV4(InetAddress addresses[]) { + static InetAddress[] filterIPV4(InetAddress addresses[]) { List list = new ArrayList<>(); for (InetAddress address : addresses) { if (address instanceof Inet4Address) { @@ -197,7 +198,7 @@ public abstract class NetworkUtils { } /** Returns only the IPV6 addresses in {@code addresses} */ - public static InetAddress[] filterIPV6(InetAddress addresses[]) { + static InetAddress[] filterIPV6(InetAddress addresses[]) { List list = new ArrayList<>(); for (InetAddress address : addresses) { if (address instanceof Inet6Address) { From f2f95ea115aa3fa2020d034ae4e10d2ef8837d62 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 18 Aug 2015 22:47:30 +0200 Subject: [PATCH 49/54] Removed CachedDfSource and move the dfs logic into the ContextIndexSearcher --- .../elasticsearch/search/SearchService.java | 26 +---- .../search/dfs/CachedDfSource.java | 97 ------------------- .../search/internal/ContextIndexSearcher.java | 52 +++++++--- .../test/ESSingleNodeTestCase.java | 8 +- .../elasticsearch/test/TestSearchContext.java | 20 ++-- 5 files changed, 55 insertions(+), 148 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/search/dfs/CachedDfSource.java diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index 4beacda97f1..50c5053c505 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -26,7 +26,6 @@ import com.google.common.collect.ImmutableMap; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.search.QueryCachingPolicy; import org.apache.lucene.search.TopDocs; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchParseException; @@ -54,7 +53,6 @@ import org.elasticsearch.common.xcontent.XContentLocation; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexService; -import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.fielddata.IndexFieldData; @@ -82,7 +80,6 @@ import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.Template; import org.elasticsearch.script.mustache.MustacheScriptEngineService; -import org.elasticsearch.search.dfs.CachedDfSource; import org.elasticsearch.search.dfs.DfsPhase; import org.elasticsearch.search.dfs.DfsSearchResult; import org.elasticsearch.search.fetch.*; @@ -412,17 +409,8 @@ public class SearchService extends AbstractLifecycleComponent { public QuerySearchResult executeQueryPhase(QuerySearchRequest request) { final SearchContext context = findContext(request.id()); contextProcessing(context); + context.searcher().setAggregatedDfs(request.dfs()); IndexShard indexShard = context.indexShard(); - try { - final IndexCache indexCache = indexShard.indexService().cache(); - final QueryCachingPolicy cachingPolicy = indexShard.getQueryCachingPolicy(); - context.searcher().dfSource(new CachedDfSource(context.searcher().getIndexReader(), request.dfs(), context.similarityService().similarity(), - indexCache.query(), cachingPolicy)); - } catch (Throwable e) { - processFailure(context, e); - cleanContext(context); - throw new QueryPhaseExecutionException(context, "Failed to set aggregated df", e); - } ShardSearchStats shardSearchStats = indexShard.searchService(); try { shardSearchStats.onPreQueryPhase(context); @@ -488,17 +476,7 @@ public class SearchService extends AbstractLifecycleComponent { public QueryFetchSearchResult executeFetchPhase(QuerySearchRequest request) { final SearchContext context = findContext(request.id()); contextProcessing(context); - try { - final IndexShard indexShard = context.indexShard(); - final IndexCache indexCache = indexShard.indexService().cache(); - final QueryCachingPolicy cachingPolicy = indexShard.getQueryCachingPolicy(); - context.searcher().dfSource(new CachedDfSource(context.searcher().getIndexReader(), request.dfs(), context.similarityService().similarity(), - indexCache.query(), cachingPolicy)); - } catch (Throwable e) { - freeContext(context.id()); - cleanContext(context); - throw new QueryPhaseExecutionException(context, "Failed to set aggregated df", e); - } + context.searcher().setAggregatedDfs(request.dfs()); try { ShardSearchStats shardSearchStats = context.indexShard().searchService(); shardSearchStats.onPreQueryPhase(context); diff --git a/core/src/main/java/org/elasticsearch/search/dfs/CachedDfSource.java b/core/src/main/java/org/elasticsearch/search/dfs/CachedDfSource.java deleted file mode 100644 index dbd66ab81db..00000000000 --- a/core/src/main/java/org/elasticsearch/search/dfs/CachedDfSource.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.search.dfs; - -import org.apache.lucene.document.Document; -import org.apache.lucene.index.*; -import org.apache.lucene.search.*; -import org.apache.lucene.search.similarities.Similarity; - -import java.io.IOException; -import java.util.List; - -/** - * - */ -public class CachedDfSource extends IndexSearcher { - - private final AggregatedDfs aggregatedDfs; - - private final int maxDoc; - - public CachedDfSource(IndexReader reader, AggregatedDfs aggregatedDfs, Similarity similarity, - QueryCache queryCache, QueryCachingPolicy queryCachingPolicy) throws IOException { - super(reader); - this.aggregatedDfs = aggregatedDfs; - setSimilarity(similarity); - setQueryCache(queryCache); - setQueryCachingPolicy(queryCachingPolicy); - if (aggregatedDfs.maxDoc() > Integer.MAX_VALUE) { - maxDoc = Integer.MAX_VALUE; - } else { - maxDoc = (int) aggregatedDfs.maxDoc(); - } - } - - - @Override - public TermStatistics termStatistics(Term term, TermContext context) throws IOException { - TermStatistics termStatistics = aggregatedDfs.termStatistics().get(term); - if (termStatistics == null) { - // we don't have stats for this - this might be a must_not clauses etc. that doesn't allow extract terms on the query - return super.termStatistics(term, context); - } - return termStatistics; - } - - @Override - public CollectionStatistics collectionStatistics(String field) throws IOException { - CollectionStatistics collectionStatistics = aggregatedDfs.fieldStatistics().get(field); - if (collectionStatistics == null) { - // we don't have stats for this - this might be a must_not clauses etc. that doesn't allow extract terms on the query - return super.collectionStatistics(field); - } - return collectionStatistics; - } - - public int maxDoc() { - return this.maxDoc; - } - - @Override - public Document doc(int i) { - throw new UnsupportedOperationException(); - } - - @Override - public void doc(int docID, StoredFieldVisitor fieldVisitor) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public Explanation explain(Weight weight, int doc) { - throw new UnsupportedOperationException(); - } - - @Override - protected void search(List leaves, Weight weight, Collector collector) throws IOException { - throw new UnsupportedOperationException(); - } -} diff --git a/core/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java b/core/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java index 11ce914fff3..2f55bf8f541 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java +++ b/core/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java @@ -20,15 +20,13 @@ package org.elasticsearch.search.internal; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.search.Collector; -import org.apache.lucene.search.Explanation; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.Weight; +import org.apache.lucene.index.Term; +import org.apache.lucene.index.TermContext; +import org.apache.lucene.search.*; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.index.engine.Engine; -import org.elasticsearch.search.dfs.CachedDfSource; +import org.elasticsearch.search.dfs.AggregatedDfs; import org.elasticsearch.search.internal.SearchContext.Lifetime; import java.io.IOException; @@ -46,21 +44,23 @@ public class ContextIndexSearcher extends IndexSearcher implements Releasable { private final SearchContext searchContext; - private CachedDfSource dfSource; + private AggregatedDfs aggregatedDfs; public ContextIndexSearcher(SearchContext searchContext, Engine.Searcher searcher) { super(searcher.reader()); in = searcher.searcher(); this.searchContext = searchContext; setSimilarity(searcher.searcher().getSimilarity(true)); + setQueryCache(searchContext.indexShard().indexService().cache().query()); + setQueryCachingPolicy(searchContext.indexShard().getQueryCachingPolicy()); } @Override public void close() { } - public void dfSource(CachedDfSource dfSource) { - this.dfSource = dfSource; + public void setAggregatedDfs(AggregatedDfs aggregatedDfs) { + this.aggregatedDfs = aggregatedDfs; } @Override @@ -75,10 +75,12 @@ public class ContextIndexSearcher extends IndexSearcher implements Releasable { @Override public Weight createNormalizedWeight(Query query, boolean needsScores) throws IOException { + // During tests we prefer to use the wrapped IndexSearcher, because then we use the AssertingIndexSearcher + // it is hacky, because if we perform a dfs search, we don't use the wrapped IndexSearcher... try { // if scores are needed and we have dfs data then use it - if (dfSource != null && needsScores) { - return dfSource.createNormalizedWeight(query, needsScores); + if (aggregatedDfs != null && needsScores) { + return super.createNormalizedWeight(query, needsScores); } return in.createNormalizedWeight(query, needsScores); } catch (Throwable t) { @@ -104,4 +106,32 @@ public class ContextIndexSearcher extends IndexSearcher implements Releasable { searchContext.clearReleasables(Lifetime.COLLECTION); } } + + @Override + public TermStatistics termStatistics(Term term, TermContext context) throws IOException { + if (aggregatedDfs == null) { + // we are either executing the dfs phase or the search_type doesn't include the dfs phase. + return super.termStatistics(term, context); + } + TermStatistics termStatistics = aggregatedDfs.termStatistics().get(term); + if (termStatistics == null) { + // we don't have stats for this - this might be a must_not clauses etc. that doesn't allow extract terms on the query + return super.termStatistics(term, context); + } + return termStatistics; + } + + @Override + public CollectionStatistics collectionStatistics(String field) throws IOException { + if (aggregatedDfs == null) { + // we are either executing the dfs phase or the search_type doesn't include the dfs phase. + return super.collectionStatistics(field); + } + CollectionStatistics collectionStatistics = aggregatedDfs.fieldStatistics().get(field); + if (collectionStatistics == null) { + // we don't have stats for this - this might be a must_not clauses etc. that doesn't allow extract terms on the query + return super.collectionStatistics(field); + } + return collectionStatistics; + } } diff --git a/core/src/test/java/org/elasticsearch/test/ESSingleNodeTestCase.java b/core/src/test/java/org/elasticsearch/test/ESSingleNodeTestCase.java index 4b452d35559..eb1581bd762 100644 --- a/core/src/test/java/org/elasticsearch/test/ESSingleNodeTestCase.java +++ b/core/src/test/java/org/elasticsearch/test/ESSingleNodeTestCase.java @@ -35,7 +35,6 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.IndexService; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.node.Node; @@ -46,12 +45,9 @@ import org.elasticsearch.threadpool.ThreadPool; import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.*; /** * A test that keep a singleton node started for all tests that can be used to get @@ -225,7 +221,7 @@ public abstract class ESSingleNodeTestCase extends ESTestCase { BigArrays bigArrays = indexService.injector().getInstance(BigArrays.class); ThreadPool threadPool = indexService.injector().getInstance(ThreadPool.class); PageCacheRecycler pageCacheRecycler = indexService.injector().getInstance(PageCacheRecycler.class); - return new TestSearchContext(threadPool, pageCacheRecycler, bigArrays, indexService, indexService.cache().query(), indexService.fieldData()); + return new TestSearchContext(threadPool, pageCacheRecycler, bigArrays, indexService); } /** diff --git a/core/src/test/java/org/elasticsearch/test/TestSearchContext.java b/core/src/test/java/org/elasticsearch/test/TestSearchContext.java index 4527fb5f4b0..2e204afb265 100644 --- a/core/src/test/java/org/elasticsearch/test/TestSearchContext.java +++ b/core/src/test/java/org/elasticsearch/test/TestSearchContext.java @@ -19,22 +19,19 @@ package org.elasticsearch.test; import com.carrotsearch.hppc.ObjectObjectAssociativeContainer; - -import org.apache.lucene.search.Collector; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.ScoreDoc; -import org.apache.lucene.search.Sort; +import org.apache.lucene.search.*; import org.apache.lucene.util.Counter; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.cache.recycler.PageCacheRecycler; -import org.elasticsearch.common.*; +import org.elasticsearch.common.HasContext; +import org.elasticsearch.common.HasContextAndHeaders; +import org.elasticsearch.common.HasHeaders; +import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.cache.bitset.BitsetFilterCache; -import org.elasticsearch.index.cache.query.QueryCache; import org.elasticsearch.index.fielddata.IndexFieldDataService; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperService; @@ -76,6 +73,7 @@ public class TestSearchContext extends SearchContext { final BitsetFilterCache fixedBitSetFilterCache; final ThreadPool threadPool; final Map, Collector> queryCollectors = new HashMap<>(); + final IndexShard indexShard; ContextIndexSearcher searcher; int size; @@ -86,7 +84,7 @@ public class TestSearchContext extends SearchContext { private final long originNanoTime = System.nanoTime(); private final Map subPhaseContexts = new HashMap<>(); - public TestSearchContext(ThreadPool threadPool,PageCacheRecycler pageCacheRecycler, BigArrays bigArrays, IndexService indexService, QueryCache filterCache, IndexFieldDataService indexFieldDataService) { + public TestSearchContext(ThreadPool threadPool,PageCacheRecycler pageCacheRecycler, BigArrays bigArrays, IndexService indexService) { super(ParseFieldMatcher.STRICT); this.pageCacheRecycler = pageCacheRecycler; this.bigArrays = bigArrays.withCircuitBreaking(); @@ -94,6 +92,7 @@ public class TestSearchContext extends SearchContext { this.indexFieldDataService = indexService.fieldData(); this.fixedBitSetFilterCache = indexService.bitsetFilterCache(); this.threadPool = threadPool; + this.indexShard = indexService.shard(0); } public TestSearchContext() { @@ -104,6 +103,7 @@ public class TestSearchContext extends SearchContext { this.indexFieldDataService = null; this.threadPool = null; this.fixedBitSetFilterCache = null; + this.indexShard = null; } public void setTypes(String... types) { @@ -282,7 +282,7 @@ public class TestSearchContext extends SearchContext { @Override public IndexShard indexShard() { - return null; + return indexShard; } @Override From dc82262db67b30ca05593f7cff39c0e4885b67a7 Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Wed, 12 Aug 2015 15:54:54 -0400 Subject: [PATCH 50/54] Don't show access_key and filter_key in S3 repository settings In #11265 we added an ability to filter out sensitive repository settings. This commit uses this change to filter out access_key and filter_key in S3 repository settings. Closes elastic/elasticsearch-cloud-aws#184 --- .../test/cloud_aws/20_repository.yaml | 23 +++++++++++++++++++ .../cloud/aws/AwsEc2Service.java | 4 ++++ plugins/pom.xml | 3 +++ 3 files changed, 30 insertions(+) create mode 100644 plugins/cloud-aws/rest-api-spec/test/cloud_aws/20_repository.yaml diff --git a/plugins/cloud-aws/rest-api-spec/test/cloud_aws/20_repository.yaml b/plugins/cloud-aws/rest-api-spec/test/cloud_aws/20_repository.yaml new file mode 100644 index 00000000000..df26e517312 --- /dev/null +++ b/plugins/cloud-aws/rest-api-spec/test/cloud_aws/20_repository.yaml @@ -0,0 +1,23 @@ +# Integration tests for Cloud AWS components +# +"S3 repository can be registereed": + - do: + snapshot.create_repository: + repository: test_repo_s3_1 + verify: false + body: + type: s3 + settings: + bucket: "my_bucket_name" + access_key: "AKVAIQBF2RECL7FJWGJQ" + secret_key: "vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br" + + # Get repositry + - do: + snapshot.get_repository: + repository: test_repo_s3_1 + + - is_true: test_repo_s3_1 + - is_true: test_repo_s3_1.settings.bucket + - is_false: test_repo_s3_1.settings.access_key + - is_false: test_repo_s3_1.settings.secret_key diff --git a/plugins/cloud-aws/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java b/plugins/cloud-aws/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java index 8cc82590038..a8d07b05d49 100644 --- a/plugins/cloud-aws/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java +++ b/plugins/cloud-aws/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java @@ -50,10 +50,14 @@ public class AwsEc2Service extends AbstractLifecycleComponent { @Inject public AwsEc2Service(Settings settings, SettingsFilter settingsFilter, NetworkService networkService, DiscoveryNodeService discoveryNodeService) { super(settings); + // Filter global settings settingsFilter.addFilter("cloud.key"); settingsFilter.addFilter("cloud.account"); settingsFilter.addFilter("cloud.aws.access_key"); settingsFilter.addFilter("cloud.aws.secret_key"); + // Filter repository-specific settings + settingsFilter.addFilter("access_key"); + settingsFilter.addFilter("secret_key"); // add specific ec2 name resolver networkService.addCustomNameResolver(new Ec2NameResolver(settings)); discoveryNodeService.addCustomAttributeProvider(new Ec2CustomNodeAttributes(settings)); diff --git a/plugins/pom.xml b/plugins/pom.xml index 90bba7e1776..4d05a5d68fe 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -283,6 +283,9 @@ api/indices.refresh.json api/nodes.info.json api/count.json + + api/snapshot.create_repository.json + api/snapshot.get_repository.json From f3c7bf0936292f5aa3ad8f0dcca1b5f0886ea631 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 19 Aug 2015 21:55:32 -0400 Subject: [PATCH 51/54] Fix documentation typo to path.repo for UNC path example Closes #13008 --- docs/reference/modules/snapshots.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/modules/snapshots.asciidoc b/docs/reference/modules/snapshots.asciidoc index 86fd952a700..4de66b45019 100644 --- a/docs/reference/modules/snapshots.asciidoc +++ b/docs/reference/modules/snapshots.asciidoc @@ -81,7 +81,7 @@ a prefix and back slashes are properly escaped: [source,yaml] -------------- -repo.path: ["\\\\MY_SERVER\\Snapshots"] +path.repo: ["\\\\MY_SERVER\\Snapshots"] -------------- After all nodes are restarted, the following command can be used to register the shared file system repository with From a0243200e03393d1a99b6e5c8b34ed70a6486229 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 19 Aug 2015 22:14:22 -0400 Subject: [PATCH 52/54] Fix a documentation typo and a code comment typo to path.repo --- .../java/org/elasticsearch/repositories/uri/URLRepository.java | 2 +- docs/reference/modules/snapshots.asciidoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/repositories/uri/URLRepository.java b/core/src/main/java/org/elasticsearch/repositories/uri/URLRepository.java index f3c439b59c5..42a27c1dcd4 100644 --- a/core/src/main/java/org/elasticsearch/repositories/uri/URLRepository.java +++ b/core/src/main/java/org/elasticsearch/repositories/uri/URLRepository.java @@ -156,7 +156,7 @@ public class URLRepository extends BlobStoreRepository { logger.warn("cannot parse the specified url [{}]", url); throw new RepositoryException(repositoryName, "cannot parse the specified url [" + url + "]"); } - // We didn't match white list - try to resolve against repo.path + // We didn't match white list - try to resolve against path.repo URL normalizedUrl = environment.resolveRepoURL(url); if (normalizedUrl == null) { logger.warn("The specified url [{}] doesn't start with any repository paths specified by the path.repo setting: [{}] or by repositories.url.allowed_urls setting: [{}] ", url, environment.repoFiles()); diff --git a/docs/reference/modules/snapshots.asciidoc b/docs/reference/modules/snapshots.asciidoc index 4de66b45019..32f412e204c 100644 --- a/docs/reference/modules/snapshots.asciidoc +++ b/docs/reference/modules/snapshots.asciidoc @@ -141,7 +141,7 @@ This setting supports wildcards in the place of host, path, query, and fragment. repositories.url.allowed_urls: ["http://www.example.org/root/*", "https://*.mydomain.com/*?*#*"] ----------------------------------- -URL repositories with `file:` URLs can only point to locations registered in the `repo.path` setting similiar to +URL repositories with `file:` URLs can only point to locations registered in the `path.repo` setting similiar to shared file system repository. [float] From 551e92ec7133b297868364a8aa4a4ff5990c6043 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 19 Aug 2015 19:31:07 +0200 Subject: [PATCH 53/54] Fix documentation: scrolls are not closed automatically. The documentation states that scrolls are automatically closed when all documents are consumed, but this is not the case. I first tried to fix the code to close scrolls automatically but this made REST tests fail because clearing a scroll that is already closed returned a 4xx error instead of a 2xx code, so this has probably been this way for a very long time. --- docs/reference/search/request/scroll.asciidoc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/reference/search/request/scroll.asciidoc b/docs/reference/search/request/scroll.asciidoc index 338d5d0de1c..6abdd27220f 100644 --- a/docs/reference/search/request/scroll.asciidoc +++ b/docs/reference/search/request/scroll.asciidoc @@ -176,9 +176,11 @@ curl -XGET localhost:9200/_nodes/stats/indices/search?pretty ==== Clear scroll API -Search contexts are removed automatically either when all results have been -retrieved or when the `scroll` timeout has been exceeded. However, you can -clear a search context manually with the `clear-scroll` API: +Search context are automatically removed when the `scroll` timeout has been +exceeded. However keeping scrolls open has a cost, as discussed in the +<> so scrolls should be explicitly +cleared as soon as the scroll is not being used anymore using the +`clear-scroll` API: [source,js] --------------------------------------- From 78c2f1063ac4a38943ea53fdd646cdb5646362f4 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 18 Aug 2015 17:01:47 +0200 Subject: [PATCH 54/54] Optimize sorted scroll when sorting by `_doc`. This change means that we will be able to remove the `SCAN` search type in 3.0 and recommend users to use sorted scrolls instead. --- .../apache/lucene/queries/MinDocQuery.java | 119 ++++++++++++++++++ .../percolator/PercolateContext.java | 17 +-- .../elasticsearch/search/SearchService.java | 39 ++++-- .../search/internal/DefaultSearchContext.java | 21 +--- .../internal/FilteredSearchContext.java | 20 +-- .../search/internal/ScrollContext.java | 33 +++++ .../search/internal/SearchContext.java | 9 +- .../search/internal/SubSearchContext.java | 10 +- .../search/query/QueryPhase.java | 73 ++++++++--- .../search/scan/ScanContext.java | 96 +------------- .../lucene/queries/MinDocQueryTests.java | 61 +++++++++ .../search/scan/ScanContextTests.java | 29 ----- .../search/scroll/DuelScrollIT.java | 83 ++++++++++++ .../elasticsearch/test/TestSearchContext.java | 29 +++-- 14 files changed, 407 insertions(+), 232 deletions(-) create mode 100644 core/src/main/java/org/apache/lucene/queries/MinDocQuery.java create mode 100644 core/src/main/java/org/elasticsearch/search/internal/ScrollContext.java create mode 100644 core/src/test/java/org/apache/lucene/queries/MinDocQueryTests.java diff --git a/core/src/main/java/org/apache/lucene/queries/MinDocQuery.java b/core/src/main/java/org/apache/lucene/queries/MinDocQuery.java new file mode 100644 index 00000000000..169c017804b --- /dev/null +++ b/core/src/main/java/org/apache/lucene/queries/MinDocQuery.java @@ -0,0 +1,119 @@ +/* + * 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.apache.lucene.queries; + +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.search.ConstantScoreScorer; +import org.apache.lucene.search.ConstantScoreWeight; +import org.apache.lucene.search.DocIdSetIterator; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.Scorer; +import org.apache.lucene.search.Weight; +import org.apache.lucene.util.Bits; + +import java.io.IOException; + +/** A {@link Query} that only matches documents that are greater than or equal + * to a configured doc ID. */ +public final class MinDocQuery extends Query { + + private final int minDoc; + + /** Sole constructor. */ + public MinDocQuery(int minDoc) { + this.minDoc = minDoc; + } + + @Override + public int hashCode() { + return 31 * super.hashCode() + minDoc; + } + + @Override + public boolean equals(Object obj) { + if (super.equals(obj) == false) { + return false; + } + MinDocQuery that = (MinDocQuery) obj; + return minDoc == that.minDoc; + } + + @Override + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { + return new ConstantScoreWeight(this) { + @Override + public Scorer scorer(LeafReaderContext context, final Bits acceptDocs) throws IOException { + final int maxDoc = context.reader().maxDoc(); + if (context.docBase + maxDoc <= minDoc) { + return null; + } + final int segmentMinDoc = Math.max(0, minDoc - context.docBase); + final DocIdSetIterator disi = new DocIdSetIterator() { + + int doc = -1; + + @Override + public int docID() { + return doc; + } + + @Override + public int nextDoc() throws IOException { + return advance(doc + 1); + } + + @Override + public int advance(int target) throws IOException { + assert target > doc; + if (doc == -1) { + // skip directly to minDoc + doc = Math.max(target, segmentMinDoc); + } else { + doc = target; + } + while (doc < maxDoc) { + if (acceptDocs == null || acceptDocs.get(doc)) { + break; + } + doc += 1; + } + if (doc >= maxDoc) { + doc = NO_MORE_DOCS; + } + return doc; + } + + @Override + public long cost() { + return maxDoc - segmentMinDoc; + } + + }; + return new ConstantScoreScorer(this, score(), disi); + } + }; + } + + @Override + public String toString(String field) { + return "MinDocQuery(minDoc=" + minDoc + ")"; + } +} diff --git a/core/src/main/java/org/elasticsearch/percolator/PercolateContext.java b/core/src/main/java/org/elasticsearch/percolator/PercolateContext.java index 3e79ef4e783..d42b858ce7b 100644 --- a/core/src/main/java/org/elasticsearch/percolator/PercolateContext.java +++ b/core/src/main/java/org/elasticsearch/percolator/PercolateContext.java @@ -27,7 +27,6 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.Collector; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; -import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Sort; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.Counter; @@ -53,7 +52,6 @@ import org.elasticsearch.index.query.ParsedQuery; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.Scroll; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.aggregations.SearchContextAggregations; @@ -68,6 +66,7 @@ import org.elasticsearch.search.highlight.SearchContextHighlight; import org.elasticsearch.search.internal.ContextIndexSearcher; import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.InternalSearchHitField; +import org.elasticsearch.search.internal.ScrollContext; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.lookup.LeafSearchLookup; @@ -348,12 +347,12 @@ public class PercolateContext extends SearchContext { } @Override - public Scroll scroll() { + public ScrollContext scrollContext() { throw new UnsupportedOperationException(); } @Override - public SearchContext scroll(Scroll scroll) { + public SearchContext scrollContext(ScrollContext scroll) { throw new UnsupportedOperationException(); } @@ -621,16 +620,6 @@ public class PercolateContext extends SearchContext { throw new UnsupportedOperationException(); } - @Override - public void lastEmittedDoc(ScoreDoc doc) { - throw new UnsupportedOperationException(); - } - - @Override - public ScoreDoc lastEmittedDoc() { - throw new UnsupportedOperationException(); - } - @Override public DfsSearchResult dfsResult() { throw new UnsupportedOperationException(); diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index 50c5053c505..fe85bba2919 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -271,7 +271,7 @@ public class SearchService extends AbstractLifecycleComponent { throw new IllegalArgumentException("aggregations are not supported with search_type=scan"); } - if (context.scroll() == null) { + if (context.scrollContext() == null || context.scrollContext().scroll == null) { throw new ElasticsearchException("Scroll must be provided when scanning..."); } @@ -319,7 +319,7 @@ public class SearchService extends AbstractLifecycleComponent { try { shortcutDocIdsToLoadForScanning(context); fetchPhase.execute(context); - if (context.scroll() == null || context.fetchResult().hits().hits().length < context.size()) { + if (context.scrollContext() == null || context.fetchResult().hits().hits().length < context.size()) { freeContext(request.id()); } else { contextProcessedSuccessfully(context); @@ -362,7 +362,7 @@ public class SearchService extends AbstractLifecycleComponent { loadOrExecuteQueryPhase(request, context, queryPhase); - if (context.queryResult().topDocs().scoreDocs.length == 0 && context.scroll() == null) { + if (context.queryResult().topDocs().scoreDocs.length == 0 && context.scrollContext() == null) { freeContext(context.id()); } else { contextProcessedSuccessfully(context); @@ -416,7 +416,7 @@ public class SearchService extends AbstractLifecycleComponent { shardSearchStats.onPreQueryPhase(context); long time = System.nanoTime(); queryPhase.execute(context); - if (context.queryResult().topDocs().scoreDocs.length == 0 && context.scroll() == null) { + if (context.queryResult().topDocs().scoreDocs.length == 0 && context.scrollContext() == null) { // no hits, we can release the context since there will be no fetch phase freeContext(context.id()); } else { @@ -434,6 +434,16 @@ public class SearchService extends AbstractLifecycleComponent { } } + private boolean fetchPhaseShouldFreeContext(SearchContext context) { + if (context.scrollContext() == null) { + // simple search, no scroll + return true; + } else { + // scroll request, but the scroll was not extended + return context.scrollContext().scroll == null; + } + } + public QueryFetchSearchResult executeFetchPhase(ShardSearchRequest request) { final SearchContext context = createAndPutContext(request); contextProcessing(context); @@ -453,7 +463,7 @@ public class SearchService extends AbstractLifecycleComponent { try { shortcutDocIdsToLoad(context); fetchPhase.execute(context); - if (context.scroll() == null) { + if (fetchPhaseShouldFreeContext(context)) { freeContext(context.id()); } else { contextProcessedSuccessfully(context); @@ -493,7 +503,7 @@ public class SearchService extends AbstractLifecycleComponent { try { shortcutDocIdsToLoad(context); fetchPhase.execute(context); - if (context.scroll() == null) { + if (fetchPhaseShouldFreeContext(context)) { freeContext(request.id()); } else { contextProcessedSuccessfully(context); @@ -533,7 +543,7 @@ public class SearchService extends AbstractLifecycleComponent { try { shortcutDocIdsToLoad(context); fetchPhase.execute(context); - if (context.scroll() == null) { + if (fetchPhaseShouldFreeContext(context)) { freeContext(request.id()); } else { contextProcessedSuccessfully(context); @@ -559,13 +569,13 @@ public class SearchService extends AbstractLifecycleComponent { final ShardSearchStats shardSearchStats = context.indexShard().searchService(); try { if (request.lastEmittedDoc() != null) { - context.lastEmittedDoc(request.lastEmittedDoc()); + context.scrollContext().lastEmittedDoc = request.lastEmittedDoc(); } context.docIdsToLoad(request.docIds(), 0, request.docIdsSize()); shardSearchStats.onPreFetchPhase(context); long time = System.nanoTime(); fetchPhase.execute(context); - if (context.scroll() == null) { + if (fetchPhaseShouldFreeContext(context)) { freeContext(request.id()); } else { contextProcessedSuccessfully(context); @@ -620,7 +630,10 @@ public class SearchService extends AbstractLifecycleComponent { SearchContext context = new DefaultSearchContext(idGenerator.incrementAndGet(), request, shardTarget, engineSearcher, indexService, indexShard, scriptService, pageCacheRecycler, bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher, defaultSearchTimeout); SearchContext.setCurrent(context); try { - context.scroll(request.scroll()); + if (request.scroll() != null) { + context.scrollContext(new ScrollContext()); + context.scrollContext().scroll = request.scroll(); + } parseTemplate(request, context); parseSource(context, request.source()); @@ -673,7 +686,7 @@ public class SearchService extends AbstractLifecycleComponent { if (context != null) { try { context.indexShard().searchService().onFreeContext(context); - if (context.scroll() != null) { + if (context.scrollContext() != null) { context.indexShard().searchService().onFreeScrollContext(context); } } finally { @@ -686,7 +699,7 @@ public class SearchService extends AbstractLifecycleComponent { public void freeAllScrollContexts() { for (SearchContext searchContext : activeContexts.values()) { - if (searchContext.scroll() != null) { + if (searchContext.scrollContext() != null) { freeContext(searchContext.id()); } } @@ -880,7 +893,7 @@ public class SearchService extends AbstractLifecycleComponent { private void processScroll(InternalScrollSearchRequest request, SearchContext context) { // process scroll context.from(context.from() + context.size()); - context.scroll(request.scroll()); + context.scrollContext().scroll = request.scroll(); // update the context keep alive based on the new scroll value if (request.scroll() != null && request.scroll().keepAlive() != null) { context.keepAlive(request.scroll().keepAlive().millis()); diff --git a/core/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java b/core/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java index 03c13c61e93..a3015b94bab 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java @@ -49,7 +49,6 @@ import org.elasticsearch.index.query.ParsedQuery; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.Scroll; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.aggregations.SearchContextAggregations; import org.elasticsearch.search.dfs.DfsSearchResult; @@ -98,7 +97,7 @@ public class DefaultSearchContext extends SearchContext { // terminate after count private int terminateAfter = DEFAULT_TERMINATE_AFTER; private List groupStats; - private Scroll scroll; + private ScrollContext scrollContext; private boolean explain; private boolean version = false; // by default, we don't return versions private List fieldNames; @@ -290,13 +289,13 @@ public class DefaultSearchContext extends SearchContext { } @Override - public Scroll scroll() { - return this.scroll; + public ScrollContext scrollContext() { + return this.scrollContext; } @Override - public SearchContext scroll(Scroll scroll) { - this.scroll = scroll; + public SearchContext scrollContext(ScrollContext scrollContext) { + this.scrollContext = scrollContext; return this; } @@ -652,16 +651,6 @@ public class DefaultSearchContext extends SearchContext { this.keepAlive = keepAlive; } - @Override - public void lastEmittedDoc(ScoreDoc doc) { - this.lastEmittedDoc = doc; - } - - @Override - public ScoreDoc lastEmittedDoc() { - return lastEmittedDoc; - } - @Override public SearchLookup lookup() { // TODO: The types should take into account the parsing context in QueryParserContext... 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 e2f6b48f02d..2f79d03234e 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java @@ -23,7 +23,6 @@ import com.carrotsearch.hppc.ObjectObjectAssociativeContainer; import org.apache.lucene.search.Collector; import org.apache.lucene.search.Query; -import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Sort; import org.apache.lucene.util.Counter; import org.elasticsearch.action.search.SearchType; @@ -42,7 +41,6 @@ import org.elasticsearch.index.query.ParsedQuery; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.Scroll; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.aggregations.SearchContextAggregations; import org.elasticsearch.search.dfs.DfsSearchResult; @@ -154,13 +152,13 @@ public abstract class FilteredSearchContext extends SearchContext { } @Override - public Scroll scroll() { - return in.scroll(); + public ScrollContext scrollContext() { + return in.scrollContext(); } @Override - public SearchContext scroll(Scroll scroll) { - return in.scroll(scroll); + public SearchContext scrollContext(ScrollContext scroll) { + return in.scrollContext(scroll); } @Override @@ -483,16 +481,6 @@ public abstract class FilteredSearchContext extends SearchContext { in.keepAlive(keepAlive); } - @Override - public void lastEmittedDoc(ScoreDoc doc) { - in.lastEmittedDoc(doc); - } - - @Override - public ScoreDoc lastEmittedDoc() { - return in.lastEmittedDoc(); - } - @Override public SearchLookup lookup() { return in.lookup(); diff --git a/core/src/main/java/org/elasticsearch/search/internal/ScrollContext.java b/core/src/main/java/org/elasticsearch/search/internal/ScrollContext.java new file mode 100644 index 00000000000..1744b6fd745 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/internal/ScrollContext.java @@ -0,0 +1,33 @@ +/* + * 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.search.internal; + +import org.apache.lucene.search.ScoreDoc; +import org.elasticsearch.search.Scroll; + +/** Wrapper around information that needs to stay around when scrolling. */ +public class ScrollContext { + + public int totalHits = -1; + public float maxScore; + public ScoreDoc lastEmittedDoc; + public Scroll scroll; + +} diff --git a/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java b/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java index 72feec7ba3e..781d13a3b86 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java @@ -24,7 +24,6 @@ import com.google.common.collect.MultimapBuilder; import org.apache.lucene.search.Collector; import org.apache.lucene.search.Query; -import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Sort; import org.apache.lucene.util.Counter; import org.elasticsearch.action.search.SearchType; @@ -159,9 +158,9 @@ public abstract class SearchContext implements Releasable, HasContextAndHeaders protected abstract long nowInMillisImpl(); - public abstract Scroll scroll(); + public abstract ScrollContext scrollContext(); - public abstract SearchContext scroll(Scroll scroll); + public abstract SearchContext scrollContext(ScrollContext scroll); public abstract SearchContextAggregations aggregations(); @@ -303,10 +302,6 @@ public abstract class SearchContext implements Releasable, HasContextAndHeaders public abstract void keepAlive(long keepAlive); - public abstract void lastEmittedDoc(ScoreDoc doc); - - public abstract ScoreDoc lastEmittedDoc(); - public abstract SearchLookup lookup(); public abstract DfsSearchResult dfsResult(); diff --git a/core/src/main/java/org/elasticsearch/search/internal/SubSearchContext.java b/core/src/main/java/org/elasticsearch/search/internal/SubSearchContext.java index f70c9a7e1a4..a1a6fd0abff 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/SubSearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/internal/SubSearchContext.java @@ -21,13 +21,10 @@ package org.elasticsearch.search.internal; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import org.apache.lucene.search.Filter; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Sort; import org.apache.lucene.util.Counter; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.index.query.ParsedQuery; -import org.elasticsearch.search.Scroll; import org.elasticsearch.search.aggregations.SearchContextAggregations; import org.elasticsearch.search.fetch.FetchSearchResult; import org.elasticsearch.search.fetch.innerhits.InnerHitsContext; @@ -101,7 +98,7 @@ public class SubSearchContext extends FilteredSearchContext { } @Override - public SearchContext scroll(Scroll scroll) { + public SearchContext scrollContext(ScrollContext scrollContext) { throw new UnsupportedOperationException("Not supported"); } @@ -304,11 +301,6 @@ public class SubSearchContext extends FilteredSearchContext { throw new UnsupportedOperationException("Not supported"); } - @Override - public void lastEmittedDoc(ScoreDoc doc) { - throw new UnsupportedOperationException("Not supported"); - } - @Override public QuerySearchResult queryResult() { return querySearchResult; diff --git a/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java b/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java index a9105d59237..8f21f460130 100644 --- a/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java +++ b/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java @@ -21,12 +21,16 @@ package org.elasticsearch.search.query; import com.google.common.collect.ImmutableMap; +import org.apache.lucene.queries.MinDocQuery; +import org.apache.lucene.search.BooleanClause.Occur; +import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Collector; import org.apache.lucene.search.FieldDoc; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.MultiCollector; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; +import org.apache.lucene.search.Sort; import org.apache.lucene.search.TimeLimitingCollector; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopDocsCollector; @@ -43,8 +47,8 @@ import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.SearchPhase; import org.elasticsearch.search.SearchService; import org.elasticsearch.search.aggregations.AggregationPhase; +import org.elasticsearch.search.internal.ScrollContext; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.search.internal.SearchContext.Lifetime; import org.elasticsearch.search.rescore.RescorePhase; import org.elasticsearch.search.rescore.RescoreSearchContext; import org.elasticsearch.search.scan.ScanContext.ScanCollector; @@ -52,7 +56,6 @@ import org.elasticsearch.search.sort.SortParseElement; import org.elasticsearch.search.sort.TrackScoresParseElement; import org.elasticsearch.search.suggest.SuggestPhase; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -115,6 +118,7 @@ public class QueryPhase implements SearchPhase { searchContext.queryResult().searchTimedOut(false); + final SearchType searchType = searchContext.searchType(); boolean rescore = false; try { searchContext.queryResult().from(searchContext.from()); @@ -138,7 +142,7 @@ public class QueryPhase implements SearchPhase { return new TopDocs(totalHitCountCollector.getTotalHits(), Lucene.EMPTY_SCORE_DOCS, 0); } }; - } else if (searchContext.searchType() == SearchType.SCAN) { + } else if (searchType == SearchType.SCAN) { query = searchContext.scanContext().wrapQuery(query); final ScanCollector scanCollector = searchContext.scanContext().collector(searchContext); collector = scanCollector; @@ -150,11 +154,32 @@ public class QueryPhase implements SearchPhase { }; } else { // Perhaps have a dedicated scroll phase? + final ScrollContext scrollContext = searchContext.scrollContext(); + assert (scrollContext != null) == (searchContext.request().scroll() != null); final TopDocsCollector topDocsCollector; ScoreDoc lastEmittedDoc; if (searchContext.request().scroll() != null) { numDocs = Math.min(searchContext.size(), totalNumDocs); - lastEmittedDoc = searchContext.lastEmittedDoc(); + lastEmittedDoc = scrollContext.lastEmittedDoc; + + if (Sort.INDEXORDER.equals(searchContext.sort())) { + if (scrollContext.totalHits == -1) { + // first round + assert scrollContext.lastEmittedDoc == null; + // there is not much that we can optimize here since we want to collect all + // documents in order to get the total number of hits + } else { + // now this gets interesting: since we sort in index-order, we can directly + // skip to the desired doc and stop collecting after ${size} matches + if (scrollContext.lastEmittedDoc != null) { + BooleanQuery bq = new BooleanQuery(); + bq.add(query, Occur.MUST); + bq.add(new MinDocQuery(lastEmittedDoc.doc + 1), Occur.FILTER); + query = bq; + } + searchContext.terminateAfter(numDocs); + } + } } else { lastEmittedDoc = null; } @@ -177,7 +202,31 @@ public class QueryPhase implements SearchPhase { topDocsCallable = new Callable() { @Override public TopDocs call() throws Exception { - return topDocsCollector.topDocs(); + TopDocs topDocs = topDocsCollector.topDocs(); + if (scrollContext != null) { + if (scrollContext.totalHits == -1) { + // first round + scrollContext.totalHits = topDocs.totalHits; + scrollContext.maxScore = topDocs.getMaxScore(); + } else { + // subsequent round: the total number of hits and + // the maximum score were computed on the first round + topDocs.totalHits = scrollContext.totalHits; + topDocs.setMaxScore(scrollContext.maxScore); + } + switch (searchType) { + case QUERY_AND_FETCH: + case DFS_QUERY_AND_FETCH: + // for (DFS_)QUERY_AND_FETCH, we already know the last emitted doc + if (topDocs.scoreDocs.length > 0) { + // set the last emitted doc + scrollContext.lastEmittedDoc = topDocs.scoreDocs[topDocs.scoreDocs.length - 1]; + } + default: + break; + } + } + return topDocs; } }; } @@ -227,19 +276,7 @@ public class QueryPhase implements SearchPhase { searchContext.queryResult().terminatedEarly(false); } - final TopDocs topDocs = topDocsCallable.call(); - if (searchContext.request().scroll() != null) { - int size = topDocs.scoreDocs.length; - if (size > 0) { - // In the case of *QUERY_AND_FETCH we don't get back to shards telling them which least - // relevant docs got emitted as hit, we can simply mark the last doc as last emitted - if (searchContext.searchType() == SearchType.QUERY_AND_FETCH || - searchContext.searchType() == SearchType.DFS_QUERY_AND_FETCH) { - searchContext.lastEmittedDoc(topDocs.scoreDocs[size - 1]); - } - } - } - searchContext.queryResult().topDocs(topDocs); + searchContext.queryResult().topDocs(topDocsCallable.call()); } catch (Throwable e) { throw new QueryPhaseExecutionException(searchContext, "Failed to execute main query", e); } diff --git a/core/src/main/java/org/elasticsearch/search/scan/ScanContext.java b/core/src/main/java/org/elasticsearch/search/scan/ScanContext.java index c0018d41020..b09a81bdab9 100644 --- a/core/src/main/java/org/elasticsearch/search/scan/ScanContext.java +++ b/core/src/main/java/org/elasticsearch/search/scan/ScanContext.java @@ -20,18 +20,13 @@ package org.elasticsearch.search.scan; import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.queries.MinDocQuery; import org.apache.lucene.search.CollectionTerminatedException; -import org.apache.lucene.search.ConstantScoreScorer; -import org.apache.lucene.search.ConstantScoreWeight; -import org.apache.lucene.search.DocIdSetIterator; -import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.SimpleCollector; import org.apache.lucene.search.TopDocs; -import org.apache.lucene.search.Weight; -import org.apache.lucene.util.Bits; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.search.internal.SearchContext; @@ -118,93 +113,4 @@ public class ScanContext { } } - /** - * A filtering query that matches all doc IDs that are not deleted and - * greater than or equal to the configured doc ID. - */ - // pkg-private for testing - static class MinDocQuery extends Query { - - private final int minDoc; - - MinDocQuery(int minDoc) { - this.minDoc = minDoc; - } - - @Override - public int hashCode() { - return 31 * super.hashCode() + minDoc; - } - - @Override - public boolean equals(Object obj) { - if (super.equals(obj) == false) { - return false; - } - MinDocQuery that = (MinDocQuery) obj; - return minDoc == that.minDoc; - } - - @Override - public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { - return new ConstantScoreWeight(this) { - @Override - public Scorer scorer(LeafReaderContext context, final Bits acceptDocs) throws IOException { - final int maxDoc = context.reader().maxDoc(); - if (context.docBase + maxDoc <= minDoc) { - return null; - } - final int segmentMinDoc = Math.max(0, minDoc - context.docBase); - final DocIdSetIterator disi = new DocIdSetIterator() { - - int doc = -1; - - @Override - public int docID() { - return doc; - } - - @Override - public int nextDoc() throws IOException { - return advance(doc + 1); - } - - @Override - public int advance(int target) throws IOException { - assert target > doc; - if (doc == -1) { - // skip directly to minDoc - doc = Math.max(target, segmentMinDoc); - } else { - doc = target; - } - while (doc < maxDoc) { - if (acceptDocs == null || acceptDocs.get(doc)) { - break; - } - doc += 1; - } - if (doc >= maxDoc) { - doc = NO_MORE_DOCS; - } - return doc; - } - - @Override - public long cost() { - return maxDoc - minDoc; - } - - }; - return new ConstantScoreScorer(this, score(), disi); - } - }; - } - - @Override - public String toString(String field) { - return "MinDocQuery(minDoc=" + minDoc + ")"; - } - - } } diff --git a/core/src/test/java/org/apache/lucene/queries/MinDocQueryTests.java b/core/src/test/java/org/apache/lucene/queries/MinDocQueryTests.java new file mode 100644 index 00000000000..725bafbdfd6 --- /dev/null +++ b/core/src/test/java/org/apache/lucene/queries/MinDocQueryTests.java @@ -0,0 +1,61 @@ +/* + * 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.apache.lucene.queries; + +import org.apache.lucene.document.Document; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.QueryUtils; +import org.apache.lucene.store.Directory; +import org.elasticsearch.test.ESTestCase; + +import java.io.IOException; + +public class MinDocQueryTests extends ESTestCase { + + public void testBasics() { + MinDocQuery query1 = new MinDocQuery(42); + MinDocQuery query2 = new MinDocQuery(42); + MinDocQuery query3 = new MinDocQuery(43); + QueryUtils.check(query1); + QueryUtils.checkEqual(query1, query2); + QueryUtils.checkUnequal(query1, query3); + } + + public void testRandom() throws IOException { + final int numDocs = randomIntBetween(10, 200); + final Document doc = new Document(); + final Directory dir = newDirectory(); + final RandomIndexWriter w = new RandomIndexWriter(getRandom(), dir); + for (int i = 0; i < numDocs; ++i) { + w.addDocument(doc); + } + final IndexReader reader = w.getReader(); + final IndexSearcher searcher = newSearcher(reader); + for (int i = 0; i <= numDocs; ++i) { + assertEquals(numDocs - i, searcher.count(new MinDocQuery(i))); + } + w.close(); + reader.close(); + dir.close(); + } + +} diff --git a/core/src/test/java/org/elasticsearch/search/scan/ScanContextTests.java b/core/src/test/java/org/elasticsearch/search/scan/ScanContextTests.java index e804393e0ed..38c01cb29e1 100644 --- a/core/src/test/java/org/elasticsearch/search/scan/ScanContextTests.java +++ b/core/src/test/java/org/elasticsearch/search/scan/ScanContextTests.java @@ -27,13 +27,11 @@ import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; -import org.apache.lucene.search.QueryUtils; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Sort; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; -import org.elasticsearch.search.scan.ScanContext.MinDocQuery; import org.elasticsearch.search.scan.ScanContext.ScanCollector; import org.elasticsearch.test.ESTestCase; @@ -44,33 +42,6 @@ import java.util.List; public class ScanContextTests extends ESTestCase { - public void testMinDocQueryBasics() { - MinDocQuery query1 = new MinDocQuery(42); - MinDocQuery query2 = new MinDocQuery(42); - MinDocQuery query3 = new MinDocQuery(43); - QueryUtils.check(query1); - QueryUtils.checkEqual(query1, query2); - QueryUtils.checkUnequal(query1, query3); - } - - public void testMinDocQueryRandom() throws IOException { - final int numDocs = randomIntBetween(10, 200); - final Document doc = new Document(); - final Directory dir = newDirectory(); - final RandomIndexWriter w = new RandomIndexWriter(getRandom(), dir); - for (int i = 0; i < numDocs; ++i) { - w.addDocument(doc); - } - final IndexReader reader = w.getReader(); - final IndexSearcher searcher = newSearcher(reader); - for (int i = 0; i <= numDocs; ++i) { - assertEquals(numDocs - i, searcher.count(new MinDocQuery(i))); - } - w.close(); - reader.close(); - dir.close(); - } - private static TopDocs execute(IndexSearcher searcher, ScanContext ctx, Query query, int pageSize, boolean trackScores) throws IOException { query = ctx.wrapQuery(query); ScanCollector collector = ctx.collector(pageSize, trackScores); diff --git a/core/src/test/java/org/elasticsearch/search/scroll/DuelScrollIT.java b/core/src/test/java/org/elasticsearch/search/scroll/DuelScrollIT.java index d4e354a108b..efa26f25f7d 100644 --- a/core/src/test/java/org/elasticsearch/search/scroll/DuelScrollIT.java +++ b/core/src/test/java/org/elasticsearch/search/scroll/DuelScrollIT.java @@ -21,9 +21,13 @@ package org.elasticsearch.search.scroll; import com.carrotsearch.hppc.IntHashSet; import com.carrotsearch.randomizedtesting.generators.RandomPicks; + import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.sort.SortBuilder; @@ -226,4 +230,83 @@ public class DuelScrollIT extends ESIntegTestCase { } } + private int createIndex(boolean singleShard) throws Exception { + Settings.Builder settings = Settings.builder(); + if (singleShard) { + settings.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1); + } + // no replicas, as they might be ordered differently + settings.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0); + + assertAcked(prepareCreate("test").setSettings(settings.build()).get()); + final int numDocs = randomIntBetween(10, 200); + + IndexRequestBuilder[] builders = new IndexRequestBuilder[numDocs]; + for (int i = 0; i < numDocs; ++i) { + builders[i] = client().prepareIndex("test", "type", Integer.toString(i)).setSource("foo", random().nextBoolean()); + } + indexRandom(true, builders); + return numDocs; + } + + private void testDuelIndexOrder(SearchType searchType, boolean trackScores, int numDocs) throws Exception { + final int size = scaledRandomIntBetween(5, numDocs + 5); + final SearchResponse control = client().prepareSearch("test") + .setSearchType(searchType) + .setSize(numDocs) + .setQuery(QueryBuilders.matchQuery("foo", "true")) + .addSort(SortBuilders.fieldSort("_doc")) + .setTrackScores(trackScores) + .get(); + assertNoFailures(control); + + SearchResponse scroll = client().prepareSearch("test") + .setSearchType(searchType) + .setSize(size) + .setQuery(QueryBuilders.matchQuery("foo", "true")) + .addSort(SortBuilders.fieldSort("_doc")) + .setTrackScores(trackScores) + .setScroll("10m").get(); + + int scrollDocs = 0; + try { + while (true) { + assertNoFailures(scroll); + assertEquals(control.getHits().getTotalHits(), scroll.getHits().getTotalHits()); + assertEquals(control.getHits().getMaxScore(), scroll.getHits().getMaxScore(), 0.01f); + if (scroll.getHits().hits().length == 0) { + break; + } + for (int i = 0; i < scroll.getHits().hits().length; ++i) { + SearchHit controlHit = control.getHits().getAt(scrollDocs + i); + SearchHit scrollHit = scroll.getHits().getAt(i); + assertEquals(controlHit.getId(), scrollHit.getId()); + } + scrollDocs += scroll.getHits().hits().length; + scroll = client().prepareSearchScroll(scroll.getScrollId()).setScroll("10m").get(); + } + assertEquals(control.getHits().getTotalHits(), scrollDocs); + } catch (AssertionError e) { + logger.info("Control:\n" + control); + logger.info("Scroll size=" + size + ", from=" + scrollDocs + ":\n" + scroll); + throw e; + } finally { + clearScroll(scroll.getScrollId()); + } + } + + public void testDuelIndexOrderQueryAndFetch() throws Exception { + final SearchType searchType = RandomPicks.randomFrom(random(), Arrays.asList(SearchType.QUERY_AND_FETCH, SearchType.DFS_QUERY_AND_FETCH)); + // QUERY_AND_FETCH only works with a single shard + final int numDocs = createIndex(true); + testDuelIndexOrder(searchType, false, numDocs); + testDuelIndexOrder(searchType, true, numDocs); + } + + public void testDuelIndexOrderQueryThenFetch() throws Exception { + final SearchType searchType = RandomPicks.randomFrom(random(), Arrays.asList(SearchType.QUERY_THEN_FETCH, SearchType.DFS_QUERY_THEN_FETCH)); + final int numDocs = createIndex(false); + testDuelIndexOrder(searchType, false, numDocs); + testDuelIndexOrder(searchType, true, numDocs); + } } diff --git a/core/src/test/java/org/elasticsearch/test/TestSearchContext.java b/core/src/test/java/org/elasticsearch/test/TestSearchContext.java index 2e204afb265..fa8aeed014b 100644 --- a/core/src/test/java/org/elasticsearch/test/TestSearchContext.java +++ b/core/src/test/java/org/elasticsearch/test/TestSearchContext.java @@ -19,7 +19,11 @@ package org.elasticsearch.test; import com.carrotsearch.hppc.ObjectObjectAssociativeContainer; -import org.apache.lucene.search.*; + +import org.apache.lucene.search.Collector; +import org.apache.lucene.search.Filter; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.Sort; import org.apache.lucene.util.Counter; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.cache.recycler.PageCacheRecycler; @@ -41,7 +45,6 @@ import org.elasticsearch.index.query.ParsedQuery; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.Scroll; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.aggregations.SearchContextAggregations; import org.elasticsearch.search.dfs.DfsSearchResult; @@ -53,6 +56,7 @@ import org.elasticsearch.search.fetch.script.ScriptFieldsContext; import org.elasticsearch.search.fetch.source.FetchSourceContext; import org.elasticsearch.search.highlight.SearchContextHighlight; import org.elasticsearch.search.internal.ContextIndexSearcher; +import org.elasticsearch.search.internal.ScrollContext; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.lookup.SearchLookup; @@ -62,7 +66,11 @@ import org.elasticsearch.search.scan.ScanContext; import org.elasticsearch.search.suggest.SuggestionSearchContext; import org.elasticsearch.threadpool.ThreadPool; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; public class TestSearchContext extends SearchContext { @@ -185,13 +193,13 @@ public class TestSearchContext extends SearchContext { } @Override - public Scroll scroll() { + public ScrollContext scrollContext() { return null; } @Override - public SearchContext scroll(Scroll scroll) { - return null; + public SearchContext scrollContext(ScrollContext scrollContext) { + throw new UnsupportedOperationException(); } @Override @@ -516,15 +524,6 @@ public class TestSearchContext extends SearchContext { public void keepAlive(long keepAlive) { } - @Override - public void lastEmittedDoc(ScoreDoc doc) { - } - - @Override - public ScoreDoc lastEmittedDoc() { - return null; - } - @Override public SearchLookup lookup() { return new SearchLookup(mapperService(), fieldData(), null);