Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map additional Recovery API response properties. #4067

Merged
merged 5 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")]
codebrain marked this conversation as resolved.
Show resolved Hide resolved
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")]
codebrain marked this conversation as resolved.
Show resolved Hide resolved
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; }
}
}