Skip to content

Commit

Permalink
Map additional Recovery API response properties. (#4067)
Browse files Browse the repository at this point in the history
This commit

- Map additonal Recovery API response properties.
- Add NullableDateTimeEpochMillisecondsFormatter

(cherry picked from commit 412b832)
  • Loading branch information
codebrain authored and russcam committed Sep 4, 2019
1 parent 202c07d commit 89dc651
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using Elasticsearch.Net.Utf8Json;

namespace Nest
{
internal class NullableDateTimeEpochMillisecondsFormatter : IJsonFormatter<DateTime?>
{
public DateTime? Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
{
var token = reader.GetCurrentJsonToken();

switch (token)
{
case JsonToken.String:
{
var formatter = formatterResolver.GetFormatter<DateTime>();
return formatter.Deserialize(ref reader, formatterResolver);
}
case JsonToken.Null:
{
reader.ReadNext();
return null;
}
case JsonToken.Number:
{
var millisecondsSinceEpoch = reader.ReadDouble();
var dateTimeOffset = DateTimeUtil.Epoch.AddMilliseconds(millisecondsSinceEpoch);
return dateTimeOffset.DateTime;
}
default:
throw new Exception($"Cannot deserialize {nameof(DateTime)} from token {token}");
}
}

public void Serialize(ref JsonWriter writer, DateTime? value, IJsonFormatterResolver formatterResolver)
{
if (value == null)
{
writer.WriteNull();
return;
}

var dateTimeDifference = (value.Value - DateTimeUtil.Epoch).TotalMilliseconds;
writer.WriteInt64((long)dateTimeDifference);
}
}
}
8 changes: 4 additions & 4 deletions src/Nest/Indices/Monitoring/IndicesRecovery/RecoveryBytes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ namespace Nest
{
public class RecoveryBytes
{
[DataMember(Name ="percent")]
[DataMember(Name = "percent")]
public string Percent { get; internal set; }

[DataMember(Name ="recovered")]
[DataMember(Name = "recovered")]
public long Recovered { get; internal set; }

[DataMember(Name ="reused")]
[DataMember(Name = "reused")]
public long Reused { get; internal set; }

[DataMember(Name ="total")]
[DataMember(Name = "total")]
public long Total { get; internal set; }
}
}
20 changes: 15 additions & 5 deletions src/Nest/Indices/Monitoring/IndicesRecovery/RecoveryIndexStatus.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
using System.Runtime.Serialization;
using System;
using System.Runtime.Serialization;

namespace Nest
{
public class RecoveryIndexStatus
{
[DataMember(Name ="bytes")]
public RecoveryBytes Bytes { get; internal set; }
[Obsolete("Deprecated. Use Size instead. Will be removed in 8.0")]
public RecoveryBytes Bytes => Size;

[DataMember(Name ="files")]
[DataMember(Name = "files")]
public RecoveryFiles Files { get; internal set; }

[DataMember(Name ="total_time_in_millis")]
[DataMember(Name = "size")]
public RecoveryBytes Size { get; internal set; }

[DataMember(Name = "source_throttle_time_in_millis")]
public long SourceThrottleTimeInMilliseconds { get; internal set; }

[DataMember(Name = "target_throttle_time_in_millis")]
public long TargetThrottleTimeInMilliseconds { get; internal set; }

[DataMember(Name = "total_time_in_millis")]
public long TotalTimeInMilliseconds { get; internal set; }
}
}
13 changes: 13 additions & 0 deletions src/Nest/Indices/Monitoring/IndicesRecovery/RecoveryVerifyIndex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Runtime.Serialization;

namespace Nest
{
public class RecoveryVerifyIndex
{
[DataMember(Name ="check_index_time_in_millis")]
public long CheckIndexTimeInMilliseconds { get; internal set; }

[DataMember(Name ="total_time_in_millis")]
public long TotalTimeInMilliseconds { get; internal set; }
}
}
14 changes: 11 additions & 3 deletions src/Nest/Indices/Monitoring/IndicesRecovery/ShardRecovery.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.Serialization;
using Elasticsearch.Net.Utf8Json;

namespace Nest
{
Expand All @@ -20,13 +21,17 @@ public class ShardRecovery
[DataMember(Name ="stage")]
public string Stage { get; internal set; }

[DataMember(Name ="start")]
[Obsolete("Deprecated. Will be removed in 8.0")]
public RecoveryStartStatus Start { get; internal set; }

[DataMember(Name ="start_time")]
// TODO Rename property in 8.0
[JsonFormatter(typeof(NullableDateTimeEpochMillisecondsFormatter))]
[DataMember(Name ="start_time_in_millis")]
public DateTime? StartTime { get; internal set; }

[DataMember(Name ="stop_time")]
// TODO Rename property in 8.0
[JsonFormatter(typeof(NullableDateTimeEpochMillisecondsFormatter))]
[DataMember(Name ="stop_time_in_millis")]
public DateTime? StopTime { get; internal set; }

[DataMember(Name ="target")]
Expand All @@ -40,5 +45,8 @@ public class ShardRecovery

[DataMember(Name ="type")]
public string Type { get; internal set; }

[DataMember(Name ="verify_index")]
public RecoveryVerifyIndex VerifyIndex { get; internal set; }
}
}

0 comments on commit 89dc651

Please sign in to comment.