[Monitoring] Align MonitoringBulkDoc serialization with 6.0 (elastic/x-pack-elasticsearch#2736)

The version used in serialization must be aligned with 6.0/6.x.

Original commit: elastic/x-pack-elasticsearch@db63b91bc6
This commit is contained in:
Tanguy Leroux 2017-10-11 17:56:24 +02:00 committed by GitHub
parent 2455415a04
commit ea4bff1d43
2 changed files with 12 additions and 12 deletions

View File

@ -55,16 +55,16 @@ public class MonitoringBulkDoc implements Writeable {
public static MonitoringBulkDoc readFrom(StreamInput in) throws IOException {
final MonitoredSystem system = MonitoredSystem.fromSystem(in.readOptionalString());
if (in.getVersion().before(Version.V_7_0_0_alpha1)) {
in.readOptionalString(); // Monitoring version, removed in 7.0
in.readOptionalString(); // Cluster UUID, removed in 7.0
if (in.getVersion().before(Version.V_6_0_0_rc1)) {
in.readOptionalString(); // Monitoring version, removed in 6.0 rc1
in.readOptionalString(); // Cluster UUID, removed in 6.0 rc1
}
final long timestamp = in.readVLong();
if (in.getVersion().before(Version.V_7_0_0_alpha1)) {
in.readOptionalWriteable(MonitoringDoc.Node::new);// Source node, removed in 7.0
MonitoringIndex.readFrom(in);// Monitoring index, removed in 7.0
if (in.getVersion().before(Version.V_6_0_0_rc1)) {
in.readOptionalWriteable(MonitoringDoc.Node::new);// Source node, removed in 6.0 rc1
MonitoringIndex.readFrom(in);// Monitoring index, removed in 6.0 rc1
}
final String type = in.readOptionalString();
@ -73,7 +73,7 @@ public class MonitoringBulkDoc implements Writeable {
final XContentType xContentType = (source != BytesArray.EMPTY) ? XContentType.readFrom(in) : XContentType.JSON;
long interval = 0L;
if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
if (in.getVersion().onOrAfter(Version.V_6_0_0_rc1)) {
interval = in.readVLong();
}
return new MonitoringBulkDoc(system, type, id, timestamp, interval, source, xContentType);
@ -82,12 +82,12 @@ public class MonitoringBulkDoc implements Writeable {
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(system.getSystem());
if (out.getVersion().before(Version.V_7_0_0_alpha1)) {
if (out.getVersion().before(Version.V_6_0_0_rc1)) {
out.writeOptionalString(MonitoringTemplateUtils.TEMPLATE_VERSION);
out.writeOptionalString(null);
}
out.writeVLong(timestamp);
if (out.getVersion().before(Version.V_7_0_0_alpha1)) {
if (out.getVersion().before(Version.V_6_0_0_rc1)) {
out.writeOptionalWriteable(null);
MonitoringIndex.IGNORED_DATA.writeTo(out);
}
@ -97,7 +97,7 @@ public class MonitoringBulkDoc implements Writeable {
if (source != BytesArray.EMPTY) {
xContentType.writeTo(out);
}
if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
if (out.getVersion().onOrAfter(Version.V_6_0_0_rc1)) {
out.writeVLong(interval);
}
}

View File

@ -260,7 +260,7 @@ public class MonitoringBulkRequestTests extends ESTestCase {
originalRequest.add(randomMonitoringBulkDoc());
}
final Version version = randomVersionBetween(random(), Version.V_5_0_0, Version.V_7_0_0_alpha1);
final Version version = randomVersionBetween(random(), Version.V_5_0_0, Version.V_6_0_0_rc1);
final BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(version);
@ -290,7 +290,7 @@ public class MonitoringBulkRequestTests extends ESTestCase {
assertThat(deserialized.getSource(), equalTo(original.getSource()));
assertThat(deserialized.getXContentType(), equalTo(original.getXContentType()));
if (version.onOrAfter(Version.V_7_0_0_alpha1)) {
if (version.onOrAfter(Version.V_6_0_0_rc1)) {
assertThat(deserialized.getInterval(), equalTo(original.getInterval()));
} else {
assertThat(deserialized.getInterval(), equalTo(0L));