Adjust to XContentBuilder decoupling (elastic/x-pack-elasticsearch#4212)

This is the x-pack side of https://github.com/elastic/elasticsearch/pull/29225
where some methods were renamed or take different arguments.

Original commit: elastic/x-pack-elasticsearch@525e118381
This commit is contained in:
Lee Hinman 2018-03-27 12:58:26 -06:00 committed by GitHub
parent 9cc33f4e29
commit b646abd12c
24 changed files with 43 additions and 42 deletions

View File

@ -393,13 +393,13 @@ public class License implements ToXContentObject {
if (version == VERSION_START) {
builder.field(Fields.SUBSCRIPTION_TYPE, subscriptionType);
}
builder.dateField(Fields.ISSUE_DATE_IN_MILLIS, Fields.ISSUE_DATE, issueDate);
builder.timeField(Fields.ISSUE_DATE_IN_MILLIS, Fields.ISSUE_DATE, issueDate);
if (version == VERSION_START) {
builder.field(Fields.FEATURE, feature);
}
if (expiryDate != LicenseService.BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS) {
builder.dateField(Fields.EXPIRY_DATE_IN_MILLIS, Fields.EXPIRY_DATE, expiryDate);
builder.timeField(Fields.EXPIRY_DATE_IN_MILLIS, Fields.EXPIRY_DATE, expiryDate);
}
builder.field(Fields.MAX_NODES, maxNodes);
builder.field(Fields.ISSUED_TO, issuedTo);
@ -411,7 +411,7 @@ public class License implements ToXContentObject {
builder.humanReadable(previouslyHumanReadable);
}
if (version >= VERSION_START_DATE) {
builder.dateField(Fields.START_DATE_IN_MILLIS, Fields.START_DATE, startDate);
builder.timeField(Fields.START_DATE_IN_MILLIS, Fields.START_DATE, startDate);
}
return builder;
}

View File

@ -128,7 +128,7 @@ public class XPackInfoResponse extends ActionResponse {
.field("type", type)
.field("mode", mode)
.field("status", status.label())
.dateField("expiry_date_in_millis", "expiry_date", expiryDate)
.timeField("expiry_date_in_millis", "expiry_date", expiryDate)
.endObject();
}

View File

@ -246,7 +246,7 @@ public class FlushJobAction extends Action<FlushJobAction.Request, FlushJobActio
builder.startObject();
builder.field("flushed", flushed);
if (lastFinalizedBucketEnd != null) {
builder.dateField(FlushAcknowledgement.LAST_FINALIZED_BUCKET_END.getPreferredName(),
builder.timeField(FlushAcknowledgement.LAST_FINALIZED_BUCKET_END.getPreferredName(),
FlushAcknowledgement.LAST_FINALIZED_BUCKET_END.getPreferredName() + "_string", lastFinalizedBucketEnd.getTime());
}
builder.endObject();

View File

@ -162,8 +162,8 @@ public class ScheduledEvent implements ToXContentObject, Writeable {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(DESCRIPTION.getPreferredName(), description);
builder.dateField(START_TIME.getPreferredName(), START_TIME.getPreferredName() + "_string", startTime.toInstant().toEpochMilli());
builder.dateField(END_TIME.getPreferredName(), END_TIME.getPreferredName() + "_string", endTime.toInstant().toEpochMilli());
builder.timeField(START_TIME.getPreferredName(), START_TIME.getPreferredName() + "_string", startTime.toInstant().toEpochMilli());
builder.timeField(END_TIME.getPreferredName(), END_TIME.getPreferredName() + "_string", endTime.toInstant().toEpochMilli());
builder.field(Calendar.ID.getPreferredName(), calendarId);
if (eventId != null) {
builder.field(EVENT_ID.getPreferredName(), eventId);

View File

@ -556,13 +556,13 @@ public class Job extends AbstractDiffable<Job> implements Writeable, ToXContentO
if (description != null) {
builder.field(DESCRIPTION.getPreferredName(), description);
}
builder.dateField(CREATE_TIME.getPreferredName(), CREATE_TIME.getPreferredName() + humanReadableSuffix, createTime.getTime());
builder.timeField(CREATE_TIME.getPreferredName(), CREATE_TIME.getPreferredName() + humanReadableSuffix, createTime.getTime());
if (finishedTime != null) {
builder.dateField(FINISHED_TIME.getPreferredName(), FINISHED_TIME.getPreferredName() + humanReadableSuffix,
builder.timeField(FINISHED_TIME.getPreferredName(), FINISHED_TIME.getPreferredName() + humanReadableSuffix,
finishedTime.getTime());
}
if (lastDataTime != null) {
builder.dateField(LAST_DATA_TIME.getPreferredName(), LAST_DATA_TIME.getPreferredName() + humanReadableSuffix,
builder.timeField(LAST_DATA_TIME.getPreferredName(), LAST_DATA_TIME.getPreferredName() + humanReadableSuffix,
lastDataTime.getTime());
}
if (establishedModelMemory != null) {

View File

@ -84,7 +84,7 @@ public class FlushAcknowledgement implements ToXContentObject, Writeable {
builder.startObject();
builder.field(ID.getPreferredName(), id);
if (lastFinalizedBucketEnd != null) {
builder.dateField(LAST_FINALIZED_BUCKET_END.getPreferredName(), LAST_FINALIZED_BUCKET_END.getPreferredName() + "_string",
builder.timeField(LAST_FINALIZED_BUCKET_END.getPreferredName(), LAST_FINALIZED_BUCKET_END.getPreferredName() + "_string",
lastFinalizedBucketEnd.getTime());
}
builder.endObject();

View File

@ -576,23 +576,23 @@ public class DataCounts implements ToXContentObject, Writeable {
builder.field(SPARSE_BUCKET_COUNT.getPreferredName(), sparseBucketCount);
builder.field(BUCKET_COUNT.getPreferredName(), bucketCount);
if (earliestRecordTimeStamp != null) {
builder.dateField(EARLIEST_RECORD_TIME.getPreferredName(), EARLIEST_RECORD_TIME.getPreferredName() + "_string",
builder.timeField(EARLIEST_RECORD_TIME.getPreferredName(), EARLIEST_RECORD_TIME.getPreferredName() + "_string",
earliestRecordTimeStamp.getTime());
}
if (latestRecordTimeStamp != null) {
builder.dateField(LATEST_RECORD_TIME.getPreferredName(), LATEST_RECORD_TIME.getPreferredName() + "_string",
builder.timeField(LATEST_RECORD_TIME.getPreferredName(), LATEST_RECORD_TIME.getPreferredName() + "_string",
latestRecordTimeStamp.getTime());
}
if (lastDataTimeStamp != null) {
builder.dateField(LAST_DATA_TIME.getPreferredName(), LAST_DATA_TIME.getPreferredName() + "_string",
builder.timeField(LAST_DATA_TIME.getPreferredName(), LAST_DATA_TIME.getPreferredName() + "_string",
lastDataTimeStamp.getTime());
}
if (latestEmptyBucketTimeStamp != null) {
builder.dateField(LATEST_EMPTY_BUCKET_TIME.getPreferredName(), LATEST_EMPTY_BUCKET_TIME.getPreferredName() + "_string",
builder.timeField(LATEST_EMPTY_BUCKET_TIME.getPreferredName(), LATEST_EMPTY_BUCKET_TIME.getPreferredName() + "_string",
latestEmptyBucketTimeStamp.getTime());
}
if (latestSparseBucketTimeStamp != null) {
builder.dateField(LATEST_SPARSE_BUCKET_TIME.getPreferredName(), LATEST_SPARSE_BUCKET_TIME.getPreferredName() + "_string",
builder.timeField(LATEST_SPARSE_BUCKET_TIME.getPreferredName(), LATEST_SPARSE_BUCKET_TIME.getPreferredName() + "_string",
latestSparseBucketTimeStamp.getTime());
}
builder.field(INPUT_RECORD_COUNT.getPreferredName(), getInputRecordCount());

View File

@ -184,9 +184,9 @@ public class ModelSizeStats implements ToXContentObject, Writeable {
builder.field(TOTAL_PARTITION_FIELD_COUNT_FIELD.getPreferredName(), totalPartitionFieldCount);
builder.field(BUCKET_ALLOCATION_FAILURES_COUNT_FIELD.getPreferredName(), bucketAllocationFailuresCount);
builder.field(MEMORY_STATUS_FIELD.getPreferredName(), memoryStatus);
builder.dateField(LOG_TIME_FIELD.getPreferredName(), LOG_TIME_FIELD.getPreferredName() + "_string", logTime.getTime());
builder.timeField(LOG_TIME_FIELD.getPreferredName(), LOG_TIME_FIELD.getPreferredName() + "_string", logTime.getTime());
if (timestamp != null) {
builder.dateField(TIMESTAMP_FIELD.getPreferredName(), TIMESTAMP_FIELD.getPreferredName() + "_string", timestamp.getTime());
builder.timeField(TIMESTAMP_FIELD.getPreferredName(), TIMESTAMP_FIELD.getPreferredName() + "_string", timestamp.getTime());
}
return builder;

View File

@ -187,7 +187,7 @@ public class ModelSnapshot implements ToXContentObject, Writeable {
builder.field(Job.ID.getPreferredName(), jobId);
builder.field(MIN_VERSION.getPreferredName(), minVersion);
if (timestamp != null) {
builder.dateField(TIMESTAMP.getPreferredName(), TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
builder.timeField(TIMESTAMP.getPreferredName(), TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
}
if (description != null) {
builder.field(DESCRIPTION.getPreferredName(), description);
@ -200,11 +200,11 @@ public class ModelSnapshot implements ToXContentObject, Writeable {
builder.field(ModelSizeStats.RESULT_TYPE_FIELD.getPreferredName(), modelSizeStats);
}
if (latestRecordTimeStamp != null) {
builder.dateField(LATEST_RECORD_TIME.getPreferredName(), LATEST_RECORD_TIME.getPreferredName() + "_string",
builder.timeField(LATEST_RECORD_TIME.getPreferredName(), LATEST_RECORD_TIME.getPreferredName() + "_string",
latestRecordTimeStamp.getTime());
}
if (latestResultTimeStamp != null) {
builder.dateField(LATEST_RESULT_TIME.getPreferredName(), LATEST_RESULT_TIME.getPreferredName() + "_string",
builder.timeField(LATEST_RESULT_TIME.getPreferredName(), LATEST_RESULT_TIME.getPreferredName() + "_string",
latestResultTimeStamp.getTime());
}
if (quantiles != null) {

View File

@ -255,7 +255,7 @@ public class AnomalyRecord implements ToXContentObject, Writeable {
builder.field(BUCKET_SPAN.getPreferredName(), bucketSpan);
builder.field(Detector.DETECTOR_INDEX.getPreferredName(), detectorIndex);
builder.field(Result.IS_INTERIM.getPreferredName(), isInterim);
builder.dateField(Result.TIMESTAMP.getPreferredName(), Result.TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
builder.timeField(Result.TIMESTAMP.getPreferredName(), Result.TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
if (byFieldName != null) {
builder.field(BY_FIELD_NAME.getPreferredName(), byFieldName);
}

View File

@ -181,7 +181,7 @@ public class Bucket implements ToXContentObject, Writeable {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(JOB_ID.getPreferredName(), jobId);
builder.dateField(Result.TIMESTAMP.getPreferredName(), Result.TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
builder.timeField(Result.TIMESTAMP.getPreferredName(), Result.TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
builder.field(ANOMALY_SCORE.getPreferredName(), anomalyScore);
builder.field(BUCKET_SPAN.getPreferredName(), bucketSpan);
builder.field(INITIAL_ANOMALY_SCORE.getPreferredName(), initialAnomalyScore);

View File

@ -140,7 +140,7 @@ public class BucketInfluencer implements ToXContentObject, Writeable {
builder.field(ANOMALY_SCORE.getPreferredName(), anomalyScore);
builder.field(RAW_ANOMALY_SCORE.getPreferredName(), rawAnomalyScore);
builder.field(PROBABILITY.getPreferredName(), probability);
builder.dateField(Result.TIMESTAMP.getPreferredName(), Result.TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
builder.timeField(Result.TIMESTAMP.getPreferredName(), Result.TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
builder.field(BUCKET_SPAN.getPreferredName(), bucketSpan);
builder.field(Result.IS_INTERIM.getPreferredName(), isInterim);
return builder;

View File

@ -136,7 +136,7 @@ public class Forecast implements ToXContentObject, Writeable {
builder.field(BUCKET_SPAN.getPreferredName(), bucketSpan);
builder.field(DETECTOR_INDEX.getPreferredName(), detectorIndex);
if (timestamp != null) {
builder.dateField(Result.TIMESTAMP.getPreferredName(),
builder.timeField(Result.TIMESTAMP.getPreferredName(),
Result.TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
}
if (partitionFieldName != null) {

View File

@ -143,7 +143,7 @@ public class Influencer implements ToXContentObject, Writeable {
builder.field(PROBABILITY.getPreferredName(), probability);
builder.field(BUCKET_SPAN.getPreferredName(), bucketSpan);
builder.field(Result.IS_INTERIM.getPreferredName(), isInterim);
builder.dateField(Result.TIMESTAMP.getPreferredName(), Result.TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
builder.timeField(Result.TIMESTAMP.getPreferredName(), Result.TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
return builder;
}

View File

@ -202,7 +202,7 @@ public class ModelPlot implements ToXContentObject, Writeable {
builder.field(DETECTOR_INDEX.getPreferredName(), detectorIndex);
if (timestamp != null) {
builder.dateField(Result.TIMESTAMP.getPreferredName(),
builder.timeField(Result.TIMESTAMP.getPreferredName(),
Result.TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
}
if (partitionFieldName != null) {

View File

@ -70,7 +70,7 @@ public class OverallBucket implements ToXContentObject, Writeable {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.dateField(Result.TIMESTAMP.getPreferredName(), Result.TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
builder.timeField(Result.TIMESTAMP.getPreferredName(), Result.TIMESTAMP.getPreferredName() + "_string", timestamp.getTime());
builder.field(BUCKET_SPAN.getPreferredName(), bucketSpan);
builder.field(OVERALL_SCORE.getPreferredName(), overallScore);
builder.field(JOBS.getPreferredName(), jobs);

View File

@ -98,7 +98,7 @@ public class CertificateInfo implements ToXContentObject, Writeable {
.field("subject_dn", subjectDn)
.field("serial_number", serialNumber)
.field("has_private_key", hasPrivateKey)
.field("expiry", expiry)
.timeField("expiry", expiry)
.endObject();
}

View File

@ -244,7 +244,7 @@ public class ActionStatus implements ToXContentObject {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder.startObject()
.field(Field.TIMESTAMP.getPreferredName()).value(timestamp, dateTimeFormatter.printer())
.field(Field.TIMESTAMP.getPreferredName()).value(dateTimeFormatter.printer().print(timestamp))
.field(Field.ACK_STATUS_STATE.getPreferredName(), state.name().toLowerCase(Locale.ROOT))
.endObject();
}
@ -342,7 +342,7 @@ public class ActionStatus implements ToXContentObject {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(Field.TIMESTAMP.getPreferredName()).value(timestamp, dateTimeFormatter.printer());
builder.field(Field.TIMESTAMP.getPreferredName()).value(dateTimeFormatter.printer().print(timestamp));
builder.field(Field.EXECUTION_SUCCESSFUL.getPreferredName(), successful);
if (reason != null) {
builder.field(Field.REASON.getPreferredName(), reason);
@ -442,7 +442,7 @@ public class ActionStatus implements ToXContentObject {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder.startObject()
.field(Field.TIMESTAMP.getPreferredName()).value(timestamp, dateTimeFormatter.printer())
.field(Field.TIMESTAMP.getPreferredName()).value(dateTimeFormatter.printer().print(timestamp))
.field(Field.REASON.getPreferredName(), reason)
.endObject();
}

View File

@ -73,8 +73,8 @@ public class QueuedWatch implements Streamable, ToXContentObject {
builder.startObject();
builder.field("watch_id", watchId);
builder.field("watch_record_id", watchRecordId);
builder.field("triggered_time", triggeredTime);
builder.field("execution_time", executionTime);
builder.timeField("triggered_time", triggeredTime);
builder.timeField("execution_time", executionTime);
builder.endObject();
return builder;
}

View File

@ -110,8 +110,8 @@ public class WatchExecutionSnapshot implements Streamable, ToXContentObject {
builder.startObject();
builder.field("watch_id", watchId);
builder.field("watch_record_id", watchRecordId);
builder.field("triggered_time", triggeredTime);
builder.field("execution_time", executionTime);
builder.timeField("triggered_time", triggeredTime);
builder.timeField("execution_time", executionTime);
builder.field("execution_phase", phase);
if (executedActions != null) {
builder.startArray("executed_actions");

View File

@ -250,10 +250,10 @@ public class WatchStatus implements ToXContentObject, Streamable {
builder.field(Field.STATE.getPreferredName(), state, params);
}
if (lastChecked != null) {
builder.field(Field.LAST_CHECKED.getPreferredName(), lastChecked);
builder.timeField(Field.LAST_CHECKED.getPreferredName(), lastChecked);
}
if (lastMetCondition != null) {
builder.field(Field.LAST_MET_CONDITION.getPreferredName(), lastMetCondition);
builder.timeField(Field.LAST_MET_CONDITION.getPreferredName(), lastMetCondition);
}
if (actions != null) {
builder.startObject(Field.ACTIONS.getPreferredName());

View File

@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.ml.job.process.autodetect;
import org.elasticsearch.common.xcontent.XContentElasticsearchExtension;
import org.elasticsearch.core.internal.io.IOUtils;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.ActionListener;
@ -448,13 +449,13 @@ public class AutodetectProcessManager extends AbstractComponent {
msgBuilder.append("] with latest_record_timestamp [");
Date snapshotLatestRecordTimestamp = modelSnapshot.getLatestRecordTimeStamp();
msgBuilder.append(snapshotLatestRecordTimestamp == null ? "N/A" :
XContentBuilder.DEFAULT_DATE_PRINTER.print(
XContentElasticsearchExtension.DEFAULT_DATE_PRINTER.print(
snapshotLatestRecordTimestamp.getTime()));
}
msgBuilder.append("], job latest_record_timestamp [");
Date jobLatestRecordTimestamp = autodetectParams.dataCounts().getLatestRecordTimeStamp();
msgBuilder.append(jobLatestRecordTimestamp == null ? "N/A"
: XContentBuilder.DEFAULT_DATE_PRINTER.print(jobLatestRecordTimestamp.getTime()));
: XContentElasticsearchExtension.DEFAULT_DATE_PRINTER.print(jobLatestRecordTimestamp.getTime()));
msgBuilder.append("]");
String msg = msgBuilder.toString();
logger.info("[{}] {}", jobId, msg);

View File

@ -1149,7 +1149,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail {
Message start() throws IOException {
builder.startObject();
builder.field(Field.TIMESTAMP, timestamp);
builder.timeField(Field.TIMESTAMP, timestamp);
return this;
}

View File

@ -128,7 +128,7 @@ public class Email implements ToXContentObject {
if (priority != null) {
builder.field(Field.PRIORITY.getPreferredName(), priority.value());
}
builder.field(Field.SENT_DATE.getPreferredName(), sentDate);
builder.timeField(Field.SENT_DATE.getPreferredName(), sentDate);
if (to != null) {
builder.field(Field.TO.getPreferredName(), to, params);
}