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@fab4d511ca
This commit is contained in:
Lee Hinman 2018-04-11 14:58:19 -06:00 committed by GitHub
parent bd834b7357
commit 9eaec0c808
18 changed files with 61 additions and 49 deletions

View File

@ -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);

View File

@ -137,7 +137,7 @@ public class CloseJobAction extends Action<CloseJobAction.Request, CloseJobActio
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
jobId = in.readString();
timeout = new TimeValue(in);
timeout = in.readTimeValue();
force = in.readBoolean();
openJobIds = in.readStringArray();
local = in.readBoolean();
@ -150,7 +150,7 @@ public class CloseJobAction extends Action<CloseJobAction.Request, CloseJobActio
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(jobId);
timeout.writeTo(out);
out.writeTimeValue(timeout);
out.writeBoolean(force);
out.writeStringArray(openJobIds);
out.writeBoolean(local);

View File

@ -117,15 +117,15 @@ public class ForecastJobAction extends Action<ForecastJobAction.Request, Forecas
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
this.duration = in.readOptionalWriteable(TimeValue::new);
this.expiresIn = in.readOptionalWriteable(TimeValue::new);
this.duration = in.readOptionalTimeValue();
this.expiresIn = in.readOptionalTimeValue();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalWriteable(duration);
out.writeOptionalWriteable(expiresIn);
out.writeOptionalTimeValue(duration);
out.writeOptionalTimeValue(expiresIn);
}
@Override

View File

@ -184,7 +184,7 @@ public class GetJobsStatsAction extends Action<GetJobsStatsAction.Request, GetJo
state = JobState.fromStream(in);
node = in.readOptionalWriteable(DiscoveryNode::new);
assignmentExplanation = in.readOptionalString();
openTime = in.readOptionalWriteable(TimeValue::new);
openTime = in.readOptionalTimeValue();
}
public String getJobId() {
@ -263,7 +263,7 @@ public class GetJobsStatsAction extends Action<GetJobsStatsAction.Request, GetJo
state.writeTo(out);
out.writeOptionalWriteable(node);
out.writeOptionalString(assignmentExplanation);
out.writeOptionalWriteable(openTime);
out.writeOptionalTimeValue(openTime);
}
@Override

View File

@ -213,7 +213,7 @@ public class GetOverallBucketsAction
super.readFrom(in);
jobId = in.readString();
topN = in.readVInt();
bucketSpan = in.readOptionalWriteable(TimeValue::new);
bucketSpan = in.readOptionalTimeValue();
overallScore = in.readDouble();
excludeInterim = in.readBoolean();
start = in.readOptionalLong();
@ -226,7 +226,7 @@ public class GetOverallBucketsAction
super.writeTo(out);
out.writeString(jobId);
out.writeVInt(topN);
out.writeOptionalWriteable(bucketSpan);
out.writeOptionalTimeValue(bucketSpan);
out.writeDouble(overallScore);
out.writeBoolean(excludeInterim);
out.writeOptionalLong(start);

View File

@ -149,7 +149,7 @@ public class StopDatafeedAction
super.readFrom(in);
datafeedId = in.readString();
resolvedStartedDatafeedIds = in.readStringArray();
stopTimeout = new TimeValue(in);
stopTimeout = in.readTimeValue();
force = in.readBoolean();
if (in.getVersion().onOrAfter(Version.V_6_1_0)) {
allowNoDatafeeds = in.readBoolean();
@ -161,7 +161,7 @@ public class StopDatafeedAction
super.writeTo(out);
out.writeString(datafeedId);
out.writeStringArray(resolvedStartedDatafeedIds);
stopTimeout.writeTo(out);
out.writeTimeValue(stopTimeout);
out.writeBoolean(force);
if (out.getVersion().onOrAfter(Version.V_6_1_0)) {
out.writeBoolean(allowNoDatafeeds);

View File

@ -67,13 +67,13 @@ public class ChunkingConfig implements ToXContentObject, Writeable {
public ChunkingConfig(StreamInput in) throws IOException {
mode = Mode.readFromStream(in);
timeSpan = in.readOptionalWriteable(TimeValue::new);
timeSpan = in.readOptionalTimeValue();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
mode.writeTo(out);
out.writeOptionalWriteable(timeSpan);
out.writeOptionalTimeValue(timeSpan);
}
ChunkingConfig(Mode mode, @Nullable TimeValue timeSpan) {

View File

@ -169,8 +169,8 @@ public class DatafeedConfig extends AbstractDiffable<DatafeedConfig> 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<DatafeedConfig> 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);

View File

@ -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);

View File

@ -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<TimeValue> 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);
}

View File

@ -241,7 +241,7 @@ public class Job extends AbstractDiffable<Job> 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<Job> 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<Job> 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<Job> 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);

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -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();

View File

@ -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]"));
}

View File

@ -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);
}

View File

@ -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())