From 169cb387784653262c8de13666772a4942edbecf Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 23 Jan 2019 12:52:17 -0500 Subject: [PATCH] Liberalize StreamOutput#writeStringList (#37768) In some cases we only have a string collection instead of a string list that we want to serialize out. We have a convenience method for writing a list of strings, but no such method for writing a collection of strings. Yet, a list of strings is a collection of strings, so we can simply liberalize StreamOutput#writeStringList to be more generous in the collections that it accepts and write out collections of strings too. On the other side, we do not have a convenience method for reading a list of strings. This commit addresses both of these issues. --- .../template/put/PutIndexTemplateRequest.java | 4 +-- .../metadata/IndexTemplateMetaData.java | 4 +-- .../common/io/stream/StreamInput.java | 18 +++++++++++-- .../common/io/stream/StreamOutput.java | 22 +++++++++------- .../indices/recovery/RecoveryResponse.java | 8 +++--- .../org/elasticsearch/plugins/PluginInfo.java | 4 +-- .../bucket/composite/InternalComposite.java | 4 +-- .../search/builder/SearchSourceBuilder.java | 4 +-- .../common/io/stream/StreamTests.java | 25 +++++++++++++++---- .../xpack/core/ccr/AutoFollowMetadata.java | 4 +-- .../action/PutAutoFollowPatternAction.java | 4 +-- .../RemoveIndexLifecyclePolicyAction.java | 4 +-- .../ml/action/FindFileStructureAction.java | 2 +- .../core/ml/action/GetJobsStatsAction.java | 4 +-- .../core/ml/action/StartDatafeedAction.java | 4 +-- .../core/ml/datafeed/DatafeedConfig.java | 8 +++--- .../core/ml/datafeed/DatafeedUpdate.java | 8 +++--- .../ml/filestructurefinder/FileStructure.java | 8 +++--- .../core/ml/job/config/AnalysisConfig.java | 8 +++--- .../xpack/core/ml/job/config/Job.java | 8 +++--- .../xpack/core/ml/job/config/JobUpdate.java | 4 +-- .../xpack/core/ml/job/results/Bucket.java | 4 +-- .../ml/job/results/CategoryDefinition.java | 4 +-- .../ml/job/results/ForecastRequestStats.java | 4 +-- .../xpack/core/rollup/job/MetricConfig.java | 4 +-- .../privilege/PutPrivilegesResponse.java | 4 +-- .../rolemapping/PutRoleMappingRequest.java | 4 +-- .../support/TokensInvalidationResult.java | 8 +++--- .../support/mapper/ExpressionRoleMapping.java | 4 +-- 29 files changed, 114 insertions(+), 81 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java index ce82d277dbb..0ff5785fcd3 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java @@ -461,7 +461,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest 0 ? indexPatterns.get(0) : ""); } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java index e21aa95865a..e66b55b1a7e 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java @@ -189,7 +189,7 @@ public class IndexTemplateMetaData extends AbstractDiffable List readList(Writeable.Reader reader) throws IOException { + public List readList(final Writeable.Reader reader) throws IOException { return readCollection(reader, ArrayList::new); } + /** + * Reads a list of strings. The list is expected to have been written using {@link StreamOutput#writeStringCollection(Collection)}. + * + * @return the list of strings + * @throws IOException if an I/O exception occurs reading the list + */ + public List readStringList() throws IOException { + return readList(StreamInput::readString); + } + /** * Reads a set of objects */ diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index 699713cb0f8..e9709de1a44 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -1048,23 +1048,27 @@ public abstract class StreamOutput extends OutputStream { } /** - * Writes a collection of generic objects via a {@link Writer} + * Writes a collection of objects via a {@link Writer}. + * + * @param collection the collection of objects + * @throws IOException if an I/O exception occurs writing the collection */ - public void writeCollection(Collection collection, Writer writer) throws IOException { + public void writeCollection(final Collection collection, final Writer writer) throws IOException { writeVInt(collection.size()); - for (T val: collection) { + for (final T val: collection) { writer.write(this, val); } } /** - * Writes a list of strings + * Writes a collection of a strings. The corresponding collection can be read from a stream input using + * {@link StreamInput#readList(Writeable.Reader)}. + * + * @param collection the collection of strings + * @throws IOException if an I/O exception occurs writing the collection */ - public void writeStringList(List list) throws IOException { - writeVInt(list.size()); - for (String string: list) { - this.writeString(string); - } + public void writeStringCollection(final Collection collection) throws IOException { + writeCollection(collection, StreamOutput::writeString); } /** diff --git a/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryResponse.java b/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryResponse.java index 605d202cbaf..acac7e732b3 100644 --- a/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryResponse.java +++ b/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryResponse.java @@ -60,9 +60,9 @@ public final class RecoveryResponse extends TransportResponse { RecoveryResponse(StreamInput in) throws IOException { super(in); - phase1FileNames = in.readList(StreamInput::readString); + phase1FileNames = in.readStringList(); phase1FileSizes = in.readList(StreamInput::readVLong); - phase1ExistingFileNames = in.readList(StreamInput::readString); + phase1ExistingFileNames = in.readStringList(); phase1ExistingFileSizes = in.readList(StreamInput::readVLong); phase1TotalSize = in.readVLong(); phase1ExistingTotalSize = in.readVLong(); @@ -76,9 +76,9 @@ public final class RecoveryResponse extends TransportResponse { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeStringList(phase1FileNames); + out.writeStringCollection(phase1FileNames); out.writeCollection(phase1FileSizes, StreamOutput::writeVLong); - out.writeStringList(phase1ExistingFileNames); + out.writeStringCollection(phase1ExistingFileNames); out.writeCollection(phase1ExistingFileSizes, StreamOutput::writeVLong); out.writeVLong(phase1TotalSize); out.writeVLong(phase1ExistingTotalSize); diff --git a/server/src/main/java/org/elasticsearch/plugins/PluginInfo.java b/server/src/main/java/org/elasticsearch/plugins/PluginInfo.java index d211efef517..3efd149be19 100644 --- a/server/src/main/java/org/elasticsearch/plugins/PluginInfo.java +++ b/server/src/main/java/org/elasticsearch/plugins/PluginInfo.java @@ -103,7 +103,7 @@ public class PluginInfo implements Writeable, ToXContentObject { } this.classname = in.readString(); if (in.getVersion().onOrAfter(Version.V_6_2_0)) { - extendedPlugins = in.readList(StreamInput::readString); + extendedPlugins = in.readStringList(); } else { extendedPlugins = Collections.emptyList(); } @@ -128,7 +128,7 @@ public class PluginInfo implements Writeable, ToXContentObject { } out.writeString(classname); if (out.getVersion().onOrAfter(Version.V_6_2_0)) { - out.writeStringList(extendedPlugins); + out.writeStringCollection(extendedPlugins); } out.writeBoolean(hasNativeController); if (out.getVersion().onOrAfter(Version.V_6_0_0_beta2) && out.getVersion().before(Version.V_6_3_0)) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/InternalComposite.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/InternalComposite.java index 822fdd7ba31..c5a1ab50b82 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/InternalComposite.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/InternalComposite.java @@ -69,7 +69,7 @@ public class InternalComposite public InternalComposite(StreamInput in) throws IOException { super(in); this.size = in.readVInt(); - this.sourceNames = in.readList(StreamInput::readString); + this.sourceNames = in.readStringList(); this.formats = new ArrayList<>(sourceNames.size()); for (int i = 0; i < sourceNames.size(); i++) { if (in.getVersion().onOrAfter(Version.V_6_3_0)) { @@ -90,7 +90,7 @@ public class InternalComposite @Override protected void doWriteTo(StreamOutput out) throws IOException { out.writeVInt(size); - out.writeStringList(sourceNames); + out.writeStringCollection(sourceNames); if (out.getVersion().onOrAfter(Version.V_6_3_0)) { for (DocValueFormat format : formats) { out.writeNamedWriteable(format); diff --git a/server/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java b/server/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java index d7867af9ea1..8e072d36c2c 100644 --- a/server/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -243,7 +243,7 @@ public final class SearchSourceBuilder implements Writeable, ToXContentObject, R } } if (in.readBoolean()) { - stats = in.readList(StreamInput::readString); + stats = in.readStringList(); } suggestBuilder = in.readOptionalWriteable(SuggestBuilder::new); terminateAfter = in.readVInt(); @@ -311,7 +311,7 @@ public final class SearchSourceBuilder implements Writeable, ToXContentObject, R boolean hasStats = stats != null; out.writeBoolean(hasStats); if (hasStats) { - out.writeStringList(stats); + out.writeStringCollection(stats); } out.writeOptionalWriteable(suggestBuilder); out.writeVInt(terminateAfter); diff --git a/server/src/test/java/org/elasticsearch/common/io/stream/StreamTests.java b/server/src/test/java/org/elasticsearch/common/io/stream/StreamTests.java index 53a00111c42..e2cdaf3c7d5 100644 --- a/server/src/test/java/org/elasticsearch/common/io/stream/StreamTests.java +++ b/server/src/test/java/org/elasticsearch/common/io/stream/StreamTests.java @@ -20,6 +20,8 @@ package org.elasticsearch.common.io.stream; import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.CheckedBiConsumer; +import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.Tuple; @@ -39,6 +41,7 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -293,15 +296,27 @@ public class StreamTests extends ESTestCase { } - final int length = randomIntBetween(0, 16); - final Collection fooBars = new ArrayList<>(length); + runWriteReadCollectionTest( + () -> new FooBar(randomInt(), randomInt()), StreamOutput::writeCollection, in -> in.readList(FooBar::new)); + } + + public void testStringCollection() throws IOException { + runWriteReadCollectionTest(() -> randomUnicodeOfLength(16), StreamOutput::writeStringCollection, StreamInput::readStringList); + } + + private void runWriteReadCollectionTest( + final Supplier supplier, + final CheckedBiConsumer, IOException> writer, + final CheckedFunction, IOException> reader) throws IOException { + final int length = randomIntBetween(0, 10); + final Collection collection = new ArrayList<>(length); for (int i = 0; i < length; i++) { - fooBars.add(new FooBar(randomInt(), randomInt())); + collection.add(supplier.get()); } try (BytesStreamOutput out = new BytesStreamOutput()) { - out.writeCollection(fooBars); + writer.accept(out, collection); try (StreamInput in = out.bytes().streamInput()) { - assertThat(fooBars, equalTo(in.readList(FooBar::new))); + assertThat(collection, equalTo(reader.apply(in))); } } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/AutoFollowMetadata.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/AutoFollowMetadata.java index 6b651444f2d..2b59ae21daf 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/AutoFollowMetadata.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/AutoFollowMetadata.java @@ -273,7 +273,7 @@ public class AutoFollowMetadata extends AbstractNamedDiffable i public AutoFollowPattern(StreamInput in) throws IOException { remoteCluster = in.readString(); - leaderIndexPatterns = in.readList(StreamInput::readString); + leaderIndexPatterns = in.readStringList(); followIndexPattern = in.readOptionalString(); maxReadRequestOperationCount = in.readOptionalVInt(); maxReadRequestSize = in.readOptionalWriteable(ByteSizeValue::new); @@ -350,7 +350,7 @@ public class AutoFollowMetadata extends AbstractNamedDiffable i @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(remoteCluster); - out.writeStringList(leaderIndexPatterns); + out.writeStringCollection(leaderIndexPatterns); out.writeOptionalString(followIndexPattern); out.writeOptionalVInt(maxReadRequestOperationCount); out.writeOptionalWriteable(maxReadRequestSize); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java index d0969850705..12d30e4d9f9 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutAutoFollowPatternAction.java @@ -275,7 +275,7 @@ public class PutAutoFollowPatternAction extends Action { super(in); name = in.readString(); remoteCluster = in.readString(); - leaderIndexPatterns = in.readList(StreamInput::readString); + leaderIndexPatterns = in.readStringList(); followIndexNamePattern = in.readOptionalString(); maxReadRequestOperationCount = in.readOptionalVInt(); maxReadRequestSize = in.readOptionalWriteable(ByteSizeValue::new); @@ -294,7 +294,7 @@ public class PutAutoFollowPatternAction extends Action { super.writeTo(out); out.writeString(name); out.writeString(remoteCluster); - out.writeStringList(leaderIndexPatterns); + out.writeStringCollection(leaderIndexPatterns); out.writeOptionalString(followIndexNamePattern); out.writeOptionalVInt(maxReadRequestOperationCount); out.writeOptionalWriteable(maxReadRequestSize); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemoveIndexLifecyclePolicyAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemoveIndexLifecyclePolicyAction.java index 239e748e58d..0e530baa57f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemoveIndexLifecyclePolicyAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemoveIndexLifecyclePolicyAction.java @@ -82,13 +82,13 @@ public class RemoveIndexLifecyclePolicyAction extends Action { public Request(StreamInput in) throws IOException { super(in); jobId = in.readString(); - expandedJobsIds = in.readList(StreamInput::readString); + expandedJobsIds = in.readStringList(); if (in.getVersion().onOrAfter(Version.V_6_1_0)) { allowNoJobs = in.readBoolean(); } @@ -94,7 +94,7 @@ public class GetJobsStatsAction extends Action { public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(jobId); - out.writeStringList(expandedJobsIds); + out.writeStringCollection(expandedJobsIds); if (out.getVersion().onOrAfter(Version.V_6_1_0)) { out.writeBoolean(allowNoJobs); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedAction.java index 12faa157eeb..cdfdf06bf85 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedAction.java @@ -197,7 +197,7 @@ public class StartDatafeedAction extends Action { timeout = TimeValue.timeValueMillis(in.readVLong()); if (in.getVersion().onOrAfter(Version.V_6_6_0)) { jobId = in.readOptionalString(); - datafeedIndices = in.readList(StreamInput::readString); + datafeedIndices = in.readStringList(); } } @@ -274,7 +274,7 @@ public class StartDatafeedAction extends Action { out.writeVLong(timeout.millis()); if (out.getVersion().onOrAfter(Version.V_6_6_0)) { out.writeOptionalString(jobId); - out.writeStringList(datafeedIndices); + out.writeStringCollection(datafeedIndices); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfig.java index 3002a43e9d8..938452d27cc 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfig.java @@ -246,14 +246,14 @@ public class DatafeedConfig extends AbstractDiffable implements this.queryDelay = in.readOptionalTimeValue(); this.frequency = in.readOptionalTimeValue(); if (in.readBoolean()) { - this.indices = Collections.unmodifiableList(in.readList(StreamInput::readString)); + this.indices = Collections.unmodifiableList(in.readStringList()); } else { this.indices = null; } // This consumes the list of types if there was one. if (in.getVersion().before(Version.V_7_0_0)) { if (in.readBoolean()) { - in.readList(StreamInput::readString); + in.readStringList(); } } if (in.getVersion().before(Version.V_6_6_0)) { @@ -408,7 +408,7 @@ public class DatafeedConfig extends AbstractDiffable implements out.writeOptionalTimeValue(frequency); if (indices != null) { out.writeBoolean(true); - out.writeStringList(indices); + out.writeStringCollection(indices); } else { out.writeBoolean(false); } @@ -416,7 +416,7 @@ public class DatafeedConfig extends AbstractDiffable implements // An empty list is expected if (out.getVersion().before(Version.V_7_0_0)) { out.writeBoolean(true); - out.writeStringList(Collections.emptyList()); + out.writeStringCollection(Collections.emptyList()); } if (out.getVersion().before(Version.V_6_6_0)) { out.writeNamedWriteable(getParsedQuery()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdate.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdate.java index 8bc49d4598a..23c2eeccc6a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdate.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdate.java @@ -107,14 +107,14 @@ public class DatafeedUpdate implements Writeable, ToXContentObject { this.queryDelay = in.readOptionalTimeValue(); this.frequency = in.readOptionalTimeValue(); if (in.readBoolean()) { - this.indices = in.readList(StreamInput::readString); + this.indices = in.readStringList(); } else { this.indices = null; } // This consumes the list of types if there was one. if (in.getVersion().before(Version.V_7_0_0)) { if (in.readBoolean()) { - in.readList(StreamInput::readString); + in.readStringList(); } } this.query = in.readOptionalNamedWriteable(QueryBuilder.class); @@ -148,7 +148,7 @@ public class DatafeedUpdate implements Writeable, ToXContentObject { out.writeOptionalTimeValue(frequency); if (indices != null) { out.writeBoolean(true); - out.writeStringList(indices); + out.writeStringCollection(indices); } else { out.writeBoolean(false); } @@ -156,7 +156,7 @@ public class DatafeedUpdate implements Writeable, ToXContentObject { // An empty list is expected if (out.getVersion().before(Version.V_7_0_0)) { out.writeBoolean(true); - out.writeStringList(Collections.emptyList()); + out.writeStringCollection(Collections.emptyList()); } out.writeOptionalNamedWriteable(query); out.writeOptionalWriteable(aggregations); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/filestructurefinder/FileStructure.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/filestructurefinder/FileStructure.java index 12c42f3df4d..acaceace047 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/filestructurefinder/FileStructure.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/filestructurefinder/FileStructure.java @@ -206,20 +206,20 @@ public class FileStructure implements ToXContentObject, Writeable { format = in.readEnum(Format.class); multilineStartPattern = in.readOptionalString(); excludeLinesPattern = in.readOptionalString(); - columnNames = in.readBoolean() ? Collections.unmodifiableList(in.readList(StreamInput::readString)) : null; + columnNames = in.readBoolean() ? Collections.unmodifiableList(in.readStringList()) : null; hasHeaderRow = in.readOptionalBoolean(); delimiter = in.readBoolean() ? (char) in.readVInt() : null; quote = in.readBoolean() ? (char) in.readVInt() : null; shouldTrimFields = in.readOptionalBoolean(); grokPattern = in.readOptionalString(); - jodaTimestampFormats = in.readBoolean() ? Collections.unmodifiableList(in.readList(StreamInput::readString)) : null; - javaTimestampFormats = in.readBoolean() ? Collections.unmodifiableList(in.readList(StreamInput::readString)) : null; + jodaTimestampFormats = in.readBoolean() ? Collections.unmodifiableList(in.readStringList()) : null; + javaTimestampFormats = in.readBoolean() ? Collections.unmodifiableList(in.readStringList()) : null; timestampField = in.readOptionalString(); needClientTimezone = in.readBoolean(); mappings = Collections.unmodifiableSortedMap(new TreeMap<>(in.readMap())); ingestPipeline = in.readBoolean() ? Collections.unmodifiableMap(in.readMap()) : null; fieldStats = Collections.unmodifiableSortedMap(new TreeMap<>(in.readMap(StreamInput::readString, FieldStats::new))); - explanation = Collections.unmodifiableList(in.readList(StreamInput::readString)); + explanation = Collections.unmodifiableList(in.readStringList()); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/AnalysisConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/AnalysisConfig.java index 7d462bd1533..933188c8221 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/AnalysisConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/AnalysisConfig.java @@ -125,7 +125,7 @@ public class AnalysisConfig implements ToXContentObject, Writeable { public AnalysisConfig(StreamInput in) throws IOException { bucketSpan = in.readTimeValue(); categorizationFieldName = in.readOptionalString(); - categorizationFilters = in.readBoolean() ? Collections.unmodifiableList(in.readList(StreamInput::readString)) : null; + categorizationFilters = in.readBoolean() ? Collections.unmodifiableList(in.readStringList()) : null; if (in.getVersion().onOrAfter(Version.V_6_2_0)) { categorizationAnalyzerConfig = in.readOptionalWriteable(CategorizationAnalyzerConfig::new); } else { @@ -134,7 +134,7 @@ public class AnalysisConfig implements ToXContentObject, Writeable { latency = in.readOptionalTimeValue(); summaryCountFieldName = in.readOptionalString(); detectors = Collections.unmodifiableList(in.readList(Detector::new)); - influencers = Collections.unmodifiableList(in.readList(StreamInput::readString)); + influencers = Collections.unmodifiableList(in.readStringList()); multivariateByFields = in.readOptionalBoolean(); } @@ -145,7 +145,7 @@ public class AnalysisConfig implements ToXContentObject, Writeable { out.writeOptionalString(categorizationFieldName); if (categorizationFilters != null) { out.writeBoolean(true); - out.writeStringList(categorizationFilters); + out.writeStringCollection(categorizationFilters); } else { out.writeBoolean(false); } @@ -155,7 +155,7 @@ public class AnalysisConfig implements ToXContentObject, Writeable { out.writeOptionalTimeValue(latency); out.writeOptionalString(summaryCountFieldName); out.writeList(detectors); - out.writeStringList(influencers); + out.writeStringCollection(influencers); out.writeOptionalBoolean(multivariateByFields); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/Job.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/Job.java index 314a533914a..a912b5d65f2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/Job.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/Job.java @@ -187,7 +187,7 @@ public class Job extends AbstractDiffable implements Writeable, ToXContentO jobType = in.readString(); jobVersion = in.readBoolean() ? Version.readVersion(in) : null; if (in.getVersion().onOrAfter(Version.V_6_1_0)) { - groups = Collections.unmodifiableList(in.readList(StreamInput::readString)); + groups = Collections.unmodifiableList(in.readStringList()); } else { groups = Collections.emptyList(); } @@ -444,7 +444,7 @@ public class Job extends AbstractDiffable implements Writeable, ToXContentO out.writeBoolean(false); } if (out.getVersion().onOrAfter(Version.V_6_1_0)) { - out.writeStringList(groups); + out.writeStringCollection(groups); } out.writeOptionalString(description); out.writeVLong(createTime.getTime()); @@ -671,7 +671,7 @@ public class Job extends AbstractDiffable implements Writeable, ToXContentO jobType = in.readString(); jobVersion = in.readBoolean() ? Version.readVersion(in) : null; if (in.getVersion().onOrAfter(Version.V_6_1_0)) { - groups = in.readList(StreamInput::readString); + groups = in.readStringList(); } else { groups = Collections.emptyList(); } @@ -856,7 +856,7 @@ public class Job extends AbstractDiffable implements Writeable, ToXContentO out.writeBoolean(false); } if (out.getVersion().onOrAfter(Version.V_6_1_0)) { - out.writeStringList(groups); + out.writeStringCollection(groups); } out.writeOptionalString(description); if (createTime != null) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/JobUpdate.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/JobUpdate.java index a0519697e59..36e1fc10966 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/JobUpdate.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/JobUpdate.java @@ -125,7 +125,7 @@ public class JobUpdate implements Writeable, ToXContentObject { modelSnapshotRetentionDays = in.readOptionalLong(); resultsRetentionDays = in.readOptionalLong(); if (in.readBoolean()) { - categorizationFilters = in.readList(StreamInput::readString); + categorizationFilters = in.readStringList(); } else { categorizationFilters = null; } @@ -172,7 +172,7 @@ public class JobUpdate implements Writeable, ToXContentObject { out.writeOptionalLong(resultsRetentionDays); out.writeBoolean(categorizationFilters != null); if (categorizationFilters != null) { - out.writeStringList(categorizationFilters); + out.writeStringCollection(categorizationFilters); } out.writeMap(customSettings); out.writeOptionalString(modelSnapshotId); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/Bucket.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/Bucket.java index 793968802c2..d335ba39e00 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/Bucket.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/Bucket.java @@ -139,7 +139,7 @@ public class Bucket implements ToXContentObject, Writeable { in.readList(Bucket::readOldPerPartitionNormalization); } if (in.getVersion().onOrAfter(Version.V_6_2_0)) { - scheduledEvents = in.readList(StreamInput::readString); + scheduledEvents = in.readStringList(); if (scheduledEvents.isEmpty()) { scheduledEvents = Collections.emptyList(); } @@ -165,7 +165,7 @@ public class Bucket implements ToXContentObject, Writeable { out.writeList(Collections.emptyList()); } if (out.getVersion().onOrAfter(Version.V_6_2_0)) { - out.writeStringList(scheduledEvents); + out.writeStringCollection(scheduledEvents); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/CategoryDefinition.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/CategoryDefinition.java index 7d5fb0a1bae..576bed5dcea 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/CategoryDefinition.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/CategoryDefinition.java @@ -77,7 +77,7 @@ public class CategoryDefinition implements ToXContentObject, Writeable { terms = in.readString(); regex = in.readString(); maxMatchingLength = in.readLong(); - examples = new TreeSet<>(in.readList(StreamInput::readString)); + examples = new TreeSet<>(in.readStringList()); if (in.getVersion().onOrAfter(Version.V_6_4_0)) { grokPattern = in.readOptionalString(); } @@ -90,7 +90,7 @@ public class CategoryDefinition implements ToXContentObject, Writeable { out.writeString(terms); out.writeString(regex); out.writeLong(maxMatchingLength); - out.writeStringList(new ArrayList<>(examples)); + out.writeStringCollection(examples); if (out.getVersion().onOrAfter(Version.V_6_4_0)) { out.writeOptionalString(grokPattern); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/ForecastRequestStats.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/ForecastRequestStats.java index a9daa78a636..506fbff640f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/ForecastRequestStats.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/ForecastRequestStats.java @@ -124,7 +124,7 @@ public class ForecastRequestStats implements ToXContentObject, Writeable { forecastId = in.readString(); recordCount = in.readLong(); if (in.readBoolean()) { - messages = in.readList(StreamInput::readString); + messages = in.readStringList(); } else { messages = null; } @@ -147,7 +147,7 @@ public class ForecastRequestStats implements ToXContentObject, Writeable { out.writeLong(recordCount); if (messages != null) { out.writeBoolean(true); - out.writeStringList(messages); + out.writeStringCollection(messages); } else { out.writeBoolean(false); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/MetricConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/MetricConfig.java index 46f0c7397c6..47b45dc69dd 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/MetricConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/MetricConfig.java @@ -86,7 +86,7 @@ public class MetricConfig implements Writeable, ToXContentObject { MetricConfig(final StreamInput in) throws IOException { field = in.readString(); - metrics = in.readList(StreamInput::readString); + metrics = in.readStringList(); } /** @@ -144,7 +144,7 @@ public class MetricConfig implements Writeable, ToXContentObject { @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(field); - out.writeStringList(metrics); + out.writeStringCollection(metrics); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/privilege/PutPrivilegesResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/privilege/PutPrivilegesResponse.java index 6d4a3f1ad44..0e1652af95b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/privilege/PutPrivilegesResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/privilege/PutPrivilegesResponse.java @@ -49,12 +49,12 @@ public final class PutPrivilegesResponse extends ActionResponse implements ToXCo @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeMap(created, StreamOutput::writeString, StreamOutput::writeStringList); + out.writeMap(created, StreamOutput::writeString, StreamOutput::writeStringCollection); } @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - this.created = Collections.unmodifiableMap(in.readMap(StreamInput::readString, si -> si.readList(StreamInput::readString))); + this.created = Collections.unmodifiableMap(in.readMap(StreamInput::readString, StreamInput::readStringList)); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/PutRoleMappingRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/PutRoleMappingRequest.java index 19a84525c30..087e29ec8b5 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/PutRoleMappingRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/PutRoleMappingRequest.java @@ -125,7 +125,7 @@ public class PutRoleMappingRequest extends ActionRequest super.readFrom(in); this.name = in.readString(); this.enabled = in.readBoolean(); - this.roles = in.readList(StreamInput::readString); + this.roles = in.readStringList(); this.rules = ExpressionParser.readExpression(in); this.metadata = in.readMap(); this.refreshPolicy = RefreshPolicy.readFrom(in); @@ -136,7 +136,7 @@ public class PutRoleMappingRequest extends ActionRequest super.writeTo(out); out.writeString(name); out.writeBoolean(enabled); - out.writeStringList(roles); + out.writeStringCollection(roles); ExpressionParser.writeExpression(rules, out); out.writeMap(metadata); refreshPolicy.writeTo(out); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/TokensInvalidationResult.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/TokensInvalidationResult.java index 117ef3316e1..f6e7965d963 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/TokensInvalidationResult.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/TokensInvalidationResult.java @@ -49,8 +49,8 @@ public class TokensInvalidationResult implements ToXContentObject, Writeable { } public TokensInvalidationResult(StreamInput in) throws IOException { - this.invalidatedTokens = in.readList(StreamInput::readString); - this.previouslyInvalidatedTokens = in.readList(StreamInput::readString); + this.invalidatedTokens = in.readStringList(); + this.previouslyInvalidatedTokens = in.readStringList(); this.errors = in.readList(StreamInput::readException); this.attemptCount = in.readVInt(); } @@ -97,8 +97,8 @@ public class TokensInvalidationResult implements ToXContentObject, Writeable { @Override public void writeTo(StreamOutput out) throws IOException { - out.writeStringList(invalidatedTokens); - out.writeStringList(previouslyInvalidatedTokens); + out.writeStringCollection(invalidatedTokens); + out.writeStringCollection(previouslyInvalidatedTokens); out.writeCollection(errors, StreamOutput::writeException); out.writeVInt(attemptCount); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/ExpressionRoleMapping.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/ExpressionRoleMapping.java index 8e3f8e5593d..95d1e9fa771 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/ExpressionRoleMapping.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/ExpressionRoleMapping.java @@ -78,7 +78,7 @@ public class ExpressionRoleMapping implements ToXContentObject, Writeable { public ExpressionRoleMapping(StreamInput in) throws IOException { this.name = in.readString(); this.enabled = in.readBoolean(); - this.roles = in.readList(StreamInput::readString); + this.roles = in.readStringList(); this.expression = ExpressionParser.readExpression(in); this.metadata = in.readMap(); } @@ -87,7 +87,7 @@ public class ExpressionRoleMapping implements ToXContentObject, Writeable { public void writeTo(StreamOutput out) throws IOException { out.writeString(name); out.writeBoolean(enabled); - out.writeStringList(roles); + out.writeStringCollection(roles); ExpressionParser.writeExpression(expression, out); out.writeMap(metadata); }