From 9eaec0c808b282053140d4e9846fed738a75eedb Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Wed, 11 Apr 2018 14:58:19 -0600 Subject: [PATCH] Adjust to decoupling TimeValue from Writeable (elastic/x-pack-elasticsearch#4338) This is the x-pack side of https://github.com/elastic/elasticsearch/pull/29454 Original commit: elastic/x-pack-elasticsearch@fab4d511ca3caf69415d9f4a24f446e46492a6bd --- .../graph/action/GraphExploreRequest.java | 4 ++-- .../xpack/core/ml/action/CloseJobAction.java | 4 ++-- .../core/ml/action/ForecastJobAction.java | 8 +++---- .../core/ml/action/GetJobsStatsAction.java | 4 ++-- .../ml/action/GetOverallBucketsAction.java | 4 ++-- .../core/ml/action/StopDatafeedAction.java | 4 ++-- .../core/ml/datafeed/ChunkingConfig.java | 4 ++-- .../core/ml/datafeed/DatafeedConfig.java | 8 +++---- .../core/ml/datafeed/DatafeedUpdate.java | 8 +++---- .../core/ml/job/config/AnalysisConfig.java | 24 ++++++++++++++----- .../xpack/core/ml/job/config/Job.java | 8 +++---- .../xpack/core/ml/job/config/JobUpdate.java | 4 ++-- .../core/rollup/job/RollupJobConfig.java | 6 ++--- .../action/saml/SamlAuthenticateResponse.java | 4 ++-- .../action/token/CreateTokenResponse.java | 4 ++-- .../action/RestMonitoringBulkActionTests.java | 2 +- .../sql/plugin/AbstractSqlQueryRequest.java | 8 +++---- .../notification/email/AccountTests.java | 2 +- 18 files changed, 61 insertions(+), 49 deletions(-) diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/graph/action/GraphExploreRequest.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/graph/action/GraphExploreRequest.java index 85abc81ba07..e44f9f76037 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/graph/action/GraphExploreRequest.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/graph/action/GraphExploreRequest.java @@ -149,7 +149,7 @@ public class GraphExploreRequest extends ActionRequest implements IndicesRequest indicesOptions = IndicesOptions.readIndicesOptions(in); types = in.readStringArray(); routing = in.readOptionalString(); - timeout = in.readOptionalWriteable(TimeValue::new); + timeout = in.readOptionalTimeValue(); sampleSize = in.readInt(); sampleDiversityField = in.readOptionalString(); maxDocsPerDiversityValue = in.readInt(); @@ -175,7 +175,7 @@ public class GraphExploreRequest extends ActionRequest implements IndicesRequest indicesOptions.writeIndicesOptions(out); out.writeStringArray(types); out.writeOptionalString(routing); - out.writeOptionalWriteable(timeout); + out.writeOptionalTimeValue(timeout); out.writeInt(sampleSize); out.writeOptionalString(sampleDiversityField); diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/CloseJobAction.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/CloseJobAction.java index 4be867c3052..c66686136e7 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/CloseJobAction.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/CloseJobAction.java @@ -137,7 +137,7 @@ public class CloseJobAction extends Action implements public DatafeedConfig(StreamInput in) throws IOException { this.id = in.readString(); this.jobId = in.readString(); - this.queryDelay = in.readOptionalWriteable(TimeValue::new); - this.frequency = in.readOptionalWriteable(TimeValue::new); + this.queryDelay = in.readOptionalTimeValue(); + this.frequency = in.readOptionalTimeValue(); if (in.readBoolean()) { this.indices = in.readList(StreamInput::readString); } else { @@ -267,8 +267,8 @@ public class DatafeedConfig extends AbstractDiffable implements public void writeTo(StreamOutput out) throws IOException { out.writeString(id); out.writeString(jobId); - out.writeOptionalWriteable(queryDelay); - out.writeOptionalWriteable(frequency); + out.writeOptionalTimeValue(queryDelay); + out.writeOptionalTimeValue(frequency); if (indices != null) { out.writeBoolean(true); out.writeStringList(indices); diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdate.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdate.java index 0bc50a5bdfe..6255be9f438 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdate.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedUpdate.java @@ -103,8 +103,8 @@ public class DatafeedUpdate implements Writeable, ToXContentObject { public DatafeedUpdate(StreamInput in) throws IOException { this.id = in.readString(); this.jobId = in.readOptionalString(); - this.queryDelay = in.readOptionalWriteable(TimeValue::new); - this.frequency = in.readOptionalWriteable(TimeValue::new); + this.queryDelay = in.readOptionalTimeValue(); + this.frequency = in.readOptionalTimeValue(); if (in.readBoolean()) { this.indices = in.readList(StreamInput::readString); } else { @@ -141,8 +141,8 @@ public class DatafeedUpdate implements Writeable, ToXContentObject { public void writeTo(StreamOutput out) throws IOException { out.writeString(id); out.writeOptionalString(jobId); - out.writeOptionalWriteable(queryDelay); - out.writeOptionalWriteable(frequency); + out.writeOptionalTimeValue(queryDelay); + out.writeOptionalTimeValue(frequency); if (indices != null) { out.writeBoolean(true); out.writeStringList(indices); diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/AnalysisConfig.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/AnalysisConfig.java index 386adab6ec1..02d8b6f5293 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/AnalysisConfig.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/AnalysisConfig.java @@ -155,7 +155,7 @@ public class AnalysisConfig implements ToXContentObject, Writeable { } public AnalysisConfig(StreamInput in) throws IOException { - bucketSpan = new TimeValue(in); + bucketSpan = in.readTimeValue(); categorizationFieldName = in.readOptionalString(); categorizationFilters = in.readBoolean() ? in.readList(StreamInput::readString) : null; if (in.getVersion().onOrAfter(Version.V_6_2_0)) { @@ -163,20 +163,29 @@ public class AnalysisConfig implements ToXContentObject, Writeable { } else { categorizationAnalyzerConfig = null; } - latency = in.readOptionalWriteable(TimeValue::new); + latency = in.readOptionalTimeValue(); summaryCountFieldName = in.readOptionalString(); detectors = in.readList(Detector::new); influencers = in.readList(StreamInput::readString); overlappingBuckets = in.readOptionalBoolean(); resultFinalizationWindow = in.readOptionalLong(); multivariateByFields = in.readOptionalBoolean(); - multipleBucketSpans = in.readBoolean() ? in.readList(TimeValue::new) : null; + if (in.readBoolean()) { + final int arraySize = in.readVInt(); + final List spans = new ArrayList<>(arraySize); + for (int i = 0; i < arraySize; i++) { + spans.add(in.readTimeValue()); + } + multipleBucketSpans = spans; + } else { + multipleBucketSpans = null; + } usePerPartitionNormalization = in.readBoolean(); } @Override public void writeTo(StreamOutput out) throws IOException { - bucketSpan.writeTo(out); + out.writeTimeValue(bucketSpan); out.writeOptionalString(categorizationFieldName); if (categorizationFilters != null) { out.writeBoolean(true); @@ -187,7 +196,7 @@ public class AnalysisConfig implements ToXContentObject, Writeable { if (out.getVersion().onOrAfter(Version.V_6_2_0)) { out.writeOptionalWriteable(categorizationAnalyzerConfig); } - out.writeOptionalWriteable(latency); + out.writeOptionalTimeValue(latency); out.writeOptionalString(summaryCountFieldName); out.writeList(detectors); out.writeStringList(influencers); @@ -196,7 +205,10 @@ public class AnalysisConfig implements ToXContentObject, Writeable { out.writeOptionalBoolean(multivariateByFields); if (multipleBucketSpans != null) { out.writeBoolean(true); - out.writeList(multipleBucketSpans); + out.writeVInt(multipleBucketSpans.size()); + for (TimeValue span : multipleBucketSpans) { + out.writeTimeValue(span); + } } else { out.writeBoolean(false); } diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/Job.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/Job.java index c806c31d76e..dc109ba084a 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/Job.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/Job.java @@ -241,7 +241,7 @@ public class Job extends AbstractDiffable implements Writeable, ToXContentO dataDescription = in.readOptionalWriteable(DataDescription::new); modelPlotConfig = in.readOptionalWriteable(ModelPlotConfig::new); renormalizationWindowDays = in.readOptionalLong(); - backgroundPersistInterval = in.readOptionalWriteable(TimeValue::new); + backgroundPersistInterval = in.readOptionalTimeValue(); modelSnapshotRetentionDays = in.readOptionalLong(); resultsRetentionDays = in.readOptionalLong(); customSettings = in.readMap(); @@ -517,7 +517,7 @@ public class Job extends AbstractDiffable implements Writeable, ToXContentO out.writeOptionalWriteable(dataDescription); out.writeOptionalWriteable(modelPlotConfig); out.writeOptionalLong(renormalizationWindowDays); - out.writeOptionalWriteable(backgroundPersistInterval); + out.writeOptionalTimeValue(backgroundPersistInterval); out.writeOptionalLong(modelSnapshotRetentionDays); out.writeOptionalLong(resultsRetentionDays); out.writeMap(customSettings); @@ -753,7 +753,7 @@ public class Job extends AbstractDiffable implements Writeable, ToXContentO dataDescription = in.readOptionalWriteable(DataDescription::new); modelPlotConfig = in.readOptionalWriteable(ModelPlotConfig::new); renormalizationWindowDays = in.readOptionalLong(); - backgroundPersistInterval = in.readOptionalWriteable(TimeValue::new); + backgroundPersistInterval = in.readOptionalTimeValue(); modelSnapshotRetentionDays = in.readOptionalLong(); resultsRetentionDays = in.readOptionalLong(); customSettings = in.readMap(); @@ -960,7 +960,7 @@ public class Job extends AbstractDiffable implements Writeable, ToXContentO out.writeOptionalWriteable(dataDescription); out.writeOptionalWriteable(modelPlotConfig); out.writeOptionalLong(renormalizationWindowDays); - out.writeOptionalWriteable(backgroundPersistInterval); + out.writeOptionalTimeValue(backgroundPersistInterval); out.writeOptionalLong(modelSnapshotRetentionDays); out.writeOptionalLong(resultsRetentionDays); out.writeMap(customSettings); diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/JobUpdate.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/JobUpdate.java index 24a1835d4e0..8644254b921 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/JobUpdate.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/JobUpdate.java @@ -109,7 +109,7 @@ public class JobUpdate implements Writeable, ToXContentObject { modelPlotConfig = in.readOptionalWriteable(ModelPlotConfig::new); analysisLimits = in.readOptionalWriteable(AnalysisLimits::new); renormalizationWindowDays = in.readOptionalLong(); - backgroundPersistInterval = in.readOptionalWriteable(TimeValue::new); + backgroundPersistInterval = in.readOptionalTimeValue(); modelSnapshotRetentionDays = in.readOptionalLong(); resultsRetentionDays = in.readOptionalLong(); if (in.readBoolean()) { @@ -146,7 +146,7 @@ public class JobUpdate implements Writeable, ToXContentObject { out.writeOptionalWriteable(modelPlotConfig); out.writeOptionalWriteable(analysisLimits); out.writeOptionalLong(renormalizationWindowDays); - out.writeOptionalWriteable(backgroundPersistInterval); + out.writeOptionalTimeValue(backgroundPersistInterval); out.writeOptionalLong(modelSnapshotRetentionDays); out.writeOptionalLong(resultsRetentionDays); out.writeBoolean(categorizationFilters != null); diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfig.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfig.java index 9ec6af72c1e..a799cbe9447 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfig.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfig.java @@ -90,7 +90,7 @@ public class RollupJobConfig implements NamedWriteable, ToXContentObject { cron = in.readString(); groupConfig = in.readOptionalWriteable(GroupConfig::new); metricsConfig = in.readList(MetricConfig::new); - timeout = new TimeValue(in); + timeout = in.readTimeValue(); pageSize = in.readInt(); } @@ -182,7 +182,7 @@ public class RollupJobConfig implements NamedWriteable, ToXContentObject { out.writeString(cron); out.writeOptionalWriteable(groupConfig); out.writeList(metricsConfig); - timeout.writeTo(out); + out.writeTimeValue(timeout); out.writeInt(pageSize); } @@ -400,7 +400,7 @@ public class RollupJobConfig implements NamedWriteable, ToXContentObject { out.writeOptionalString(cron); out.writeOptionalWriteable(groupConfig); out.writeList(metricsConfig); - timeout.writeTo(out); + out.writeTimeValue(timeout); out.writeInt(pageSize); } } diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateResponse.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateResponse.java index 3363d4a5137..84e029adac7 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateResponse.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateResponse.java @@ -56,7 +56,7 @@ public final class SamlAuthenticateResponse extends ActionResponse { out.writeString(principal); out.writeString(tokenString); out.writeString(refreshToken); - expiresIn.writeTo(out); + out.writeTimeValue(expiresIn); } @Override @@ -65,6 +65,6 @@ public final class SamlAuthenticateResponse extends ActionResponse { principal = in.readString(); tokenString = in.readString(); refreshToken = in.readString(); - expiresIn = new TimeValue(in); + expiresIn = in.readTimeValue(); } } diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenResponse.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenResponse.java index 7e887643a41..1cb1029e820 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenResponse.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenResponse.java @@ -57,7 +57,7 @@ public final class CreateTokenResponse extends ActionResponse implements ToXCont public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(tokenString); - expiresIn.writeTo(out); + out.writeTimeValue(expiresIn); out.writeOptionalString(scope); if (out.getVersion().onOrAfter(Version.V_6_2_0)) { out.writeString(refreshToken); @@ -68,7 +68,7 @@ public final class CreateTokenResponse extends ActionResponse implements ToXCont public void readFrom(StreamInput in) throws IOException { super.readFrom(in); tokenString = in.readString(); - expiresIn = new TimeValue(in); + expiresIn = in.readTimeValue(); scope = in.readOptionalString(); if (in.getVersion().onOrAfter(Version.V_6_2_0)) { refreshToken = in.readString(); diff --git a/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java b/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java index bd96be6c928..15a19c8a135 100644 --- a/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java +++ b/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java @@ -84,7 +84,7 @@ public class RestMonitoringBulkActionTests extends ESTestCase { public void testWrongInterval() { final RestRequest restRequest = createRestRequest(randomSystem().getSystem(), TEMPLATE_VERSION, "null"); - final ElasticsearchParseException exception = expectThrows(ElasticsearchParseException.class, () -> prepareRequest(restRequest)); + final IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> prepareRequest(restRequest)); assertThat(exception.getMessage(), containsString("failed to parse setting [interval] with value [null]")); } diff --git a/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/AbstractSqlQueryRequest.java b/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/AbstractSqlQueryRequest.java index 0272d71ccd5..615d0b3a6b4 100644 --- a/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/AbstractSqlQueryRequest.java +++ b/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/AbstractSqlQueryRequest.java @@ -192,8 +192,8 @@ public abstract class AbstractSqlQueryRequest extends AbstractSqlRequest impleme params = in.readList(SqlTypedParamValue::new); timeZone = DateTimeZone.forID(in.readString()); fetchSize = in.readVInt(); - requestTimeout = new TimeValue(in); - pageTimeout = new TimeValue(in); + requestTimeout = in.readTimeValue(); + pageTimeout = in.readTimeValue(); filter = in.readOptionalNamedWriteable(QueryBuilder.class); } @@ -204,8 +204,8 @@ public abstract class AbstractSqlQueryRequest extends AbstractSqlRequest impleme out.writeList(params); out.writeString(timeZone.getID()); out.writeVInt(fetchSize); - requestTimeout.writeTo(out); - pageTimeout.writeTo(out); + out.writeTimeValue(requestTimeout); + out.writeTimeValue(pageTimeout); out.writeOptionalNamedWriteable(filter); } diff --git a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/AccountTests.java b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/AccountTests.java index 62320f52e73..4eae885c4af 100644 --- a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/AccountTests.java +++ b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/AccountTests.java @@ -285,7 +285,7 @@ public class AccountTests extends ESTestCase { } public void testAccountTimeoutsConfiguredAsNumberAreRejected() { - expectThrows(ElasticsearchException.class, () -> { + expectThrows(IllegalArgumentException.class, () -> { new Account(new Account.Config("default", Settings.builder() .put("smtp.host", "localhost") .put("smtp.port", server.port())