Skip to content

Commit 08bcde1

Browse files
committed
Properly format IndexGraveyard deletion date as date (#27362)
The toXContent method for IndexGraveYard (which is a collection of tombstones for explicitly marking indices as deleted in the cluster state) confused timeValue with dateField, resulting in output of the form "delete_date" : "23424.3d" instead of "delete_date":"2017-11-13T15:50:51.614Z".
1 parent 2bb6f83 commit 08bcde1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

core/src/main/java/org/elasticsearch/cluster/metadata/IndexGraveyard.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.elasticsearch.common.xcontent.XContentBuilder;
3535
import org.elasticsearch.common.xcontent.XContentParser;
3636
import org.elasticsearch.index.Index;
37+
import org.joda.time.DateTime;
38+
import org.joda.time.DateTimeZone;
3739

3840
import java.io.IOException;
3941
import java.util.ArrayList;
@@ -432,7 +434,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
432434
builder.startObject();
433435
builder.field(INDEX_KEY);
434436
index.toXContent(builder, params);
435-
builder.timeValueField(DELETE_DATE_IN_MILLIS_KEY, DELETE_DATE_KEY, deleteDateInMillis, TimeUnit.MILLISECONDS);
437+
builder.dateField(DELETE_DATE_IN_MILLIS_KEY, DELETE_DATE_KEY, deleteDateInMillis);
436438
return builder.endObject();
437439
}
438440

core/src/test/java/org/elasticsearch/cluster/metadata/IndexGraveyardTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.cluster.metadata;
2121

22+
import org.elasticsearch.common.Strings;
2223
import org.elasticsearch.common.UUIDs;
2324
import org.elasticsearch.common.io.stream.BytesStreamOutput;
2425
import org.elasticsearch.common.settings.Settings;
@@ -36,6 +37,7 @@
3637
import java.util.List;
3738
import java.util.stream.Collectors;
3839

40+
import static org.hamcrest.Matchers.containsString;
3941
import static org.hamcrest.Matchers.equalTo;
4042
import static org.hamcrest.Matchers.lessThan;
4143
import static org.hamcrest.Matchers.not;
@@ -66,6 +68,11 @@ public void testXContent() throws IOException {
6668
builder.startObject();
6769
graveyard.toXContent(builder, ToXContent.EMPTY_PARAMS);
6870
builder.endObject();
71+
if (graveyard.getTombstones().size() > 0) {
72+
// check that date properly printed
73+
assertThat(Strings.toString(graveyard, false, true),
74+
containsString(XContentBuilder.DEFAULT_DATE_PRINTER.print(graveyard.getTombstones().get(0).getDeleteDateInMillis())));
75+
}
6976
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
7077
parser.nextToken(); // the beginning of the parser
7178
assertThat(IndexGraveyard.fromXContent(parser), equalTo(graveyard));

0 commit comments

Comments
 (0)