Skip to content

Commit a2f98b6

Browse files
authored
Convert SLM API dates returned as long to DateTimeOffset (#4173)
This commit updates the SLM API responses to convert date properties that are returned long values representing milliseconds since epoch to DateTimeOffset. This is consistent with other API responses where longs are returned. What is slightly different with this API is that Human=true can be specified on the request to also return the properties as string values. With this change, the client now effectively ignores these values as they serve little purpose, since both would end up being converted to DateTimeOffset when deserialized.
1 parent 78220c6 commit a2f98b6

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

src/Nest/XPack/Slm/SnapshotLifecyclePolicyMetadata.cs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,17 @@ public class SnapshotLifecyclePolicyMetadata
1111
{
1212
/// <summary>
1313
/// The modified date.
14-
/// Returned only when Human is set to <c>true</c> on the request
15-
/// </summary>
16-
[DataMember(Name = "modified_date")]
17-
public DateTimeOffset? ModifiedDate { get; internal set; }
18-
19-
/// <summary>
20-
/// The modified date in milliseconds
2114
/// </summary>
2215
[DataMember(Name = "modified_date_millis")]
23-
public long ModifiedDateInMilliseconds { get; internal set; }
16+
[JsonFormatter(typeof(DateTimeOffsetEpochMillisecondsFormatter))]
17+
public DateTimeOffset ModifiedDate { get; internal set; }
2418

2519
/// <summary>
2620
/// The next execution date.
27-
/// Returned only when Human is set to <c>true</c> on the request
28-
/// </summary>
29-
[DataMember(Name = "next_execution")]
30-
public DateTimeOffset? NextExecution { get; internal set; }
31-
32-
/// <summary>
33-
/// The next execution date in milliseconds
3421
/// </summary>
3522
[DataMember(Name = "next_execution_millis")]
36-
public long NextExecutionInMilliseconds { get; internal set; }
23+
[JsonFormatter(typeof(DateTimeOffsetEpochMillisecondsFormatter))]
24+
public DateTimeOffset NextExecution { get; internal set; }
3725

3826
/// <summary>
3927
/// The snapshot lifecycle policy
@@ -51,7 +39,7 @@ public class SnapshotLifecyclePolicyMetadata
5139
/// If a snapshot is currently in progress this will return information about the snapshot.
5240
/// </summary>
5341
[DataMember(Name = "in_progress")]
54-
public LifecycleSnapshotInProgress InProgress { get; internal set; }
42+
public SnapshotLifecycleInProgress InProgress { get; internal set; }
5543

5644
/// <summary>
5745
/// Information about the last time the policy successfully initiated a snapshot.
@@ -80,13 +68,13 @@ public class SnapshotLifecycleInvocationRecord
8068
/// If a snapshot is in progress when calling the Get Snapshot Lifecycle metadata
8169
/// this will hold some minimal information about the in flight snapshot
8270
/// </summary>
83-
public class LifecycleSnapshotInProgress
71+
public class SnapshotLifecycleInProgress
8472
{
8573
/// <summary> The name of the snapshot currently being taken </summary>
8674
[DataMember(Name = "name")]
8775
public string Name { get; internal set; }
8876

89-
/// <summary> The UUI of the snapshot currently being taken </summary>
77+
/// <summary> The UUID of the snapshot currently being taken </summary>
9078
[DataMember(Name = "uuid")]
9179
public string UUID { get; internal set; }
9280

@@ -98,6 +86,5 @@ public class LifecycleSnapshotInProgress
9886
[DataMember(Name = "start_time_millis")]
9987
[JsonFormatter(typeof(DateTimeOffsetEpochMillisecondsFormatter))]
10088
public DateTimeOffset StartTime { get; internal set; }
101-
10289
}
10390
}

src/Tests/Tests/XPack/Slm/SlmApiTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ [I] public async Task GetSnapshotLifecycleResponse() => await Assert<GetSnapshot
153153

154154
metadata.Version.Should().Be(1);
155155
metadata.ModifiedDate.Should().BeAfter(DateTimeOffset.MinValue);
156-
metadata.ModifiedDateInMilliseconds.Should().BeGreaterThan(0);
157156
metadata.NextExecution.Should().BeAfter(DateTimeOffset.MinValue);
158-
metadata.NextExecutionInMilliseconds.Should().BeGreaterThan(0);
159157
metadata.Policy.Name.Should().Be(v);
160158
metadata.Policy.Repository.Should().Be(v);
161159
metadata.Policy.Schedule.Should().BeEquivalentTo(new CronExpression("0 0 0 1 1 ? *"));

0 commit comments

Comments
 (0)