-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Map additional Recovery API response properties. (#4067)
This commit - Map additonal Recovery API response properties. - Add NullableDateTimeEpochMillisecondsFormatter (cherry picked from commit 412b832)
- Loading branch information
Showing
5 changed files
with
90 additions
and
12 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...onAbstractions/SerializationBehavior/JsonFormatters/DateTimeEpochMillisecondsFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 15 additions & 5 deletions
20
src/Nest/Indices/Monitoring/IndicesRecovery/RecoveryIndexStatus.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
src/Nest/Indices/Monitoring/IndicesRecovery/RecoveryVerifyIndex.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters