From 4f1abc79d79dadde08b5867da60943a50babdb86 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Thu, 10 Apr 2014 12:11:05 +0200 Subject: [PATCH] properly mapped restore response, fix #511 #512 #513 #514 #515 #516 #517 --- src/Nest/Domain/Repository/SnapshotRestore.cs | 17 +++++++++++++ src/Nest/Domain/Responses/RestoreResponse.cs | 25 +++++++++++++++++++ src/Nest/ElasticClient-Restore.cs | 12 ++++----- src/Nest/IElasticClient.cs | 4 +-- src/Nest/Nest.csproj | 2 ++ .../Core/Repository/RestoreTests.cs | 6 ++++- 6 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 src/Nest/Domain/Repository/SnapshotRestore.cs create mode 100644 src/Nest/Domain/Responses/RestoreResponse.cs diff --git a/src/Nest/Domain/Repository/SnapshotRestore.cs b/src/Nest/Domain/Repository/SnapshotRestore.cs new file mode 100644 index 00000000000..65a3a703bff --- /dev/null +++ b/src/Nest/Domain/Repository/SnapshotRestore.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Nest +{ + public class SnapshotRestore + { + [JsonProperty("snapshot")] + public string Name { get; internal set; } + [JsonProperty("indices")] + public IEnumerable Indices { get; internal set; } + + [JsonProperty("shards")] + public ShardsMetaData Shards { get; internal set; } + } +} \ No newline at end of file diff --git a/src/Nest/Domain/Responses/RestoreResponse.cs b/src/Nest/Domain/Responses/RestoreResponse.cs new file mode 100644 index 00000000000..e318161092f --- /dev/null +++ b/src/Nest/Domain/Responses/RestoreResponse.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Nest; +using Newtonsoft.Json; + +namespace Nest +{ + public interface IRestoreResponse : IResponse + { + + [JsonProperty("snapshot")] + SnapshotRestore Snapshot { get; set; } + } + + [JsonObject] + public class RestoreResponse : BaseResponse, IRestoreResponse + { + + [JsonProperty("snapshot")] + public SnapshotRestore Snapshot { get; set; } + + } +} diff --git a/src/Nest/ElasticClient-Restore.cs b/src/Nest/ElasticClient-Restore.cs index 601d799dd03..4cad6df57fb 100644 --- a/src/Nest/ElasticClient-Restore.cs +++ b/src/Nest/ElasticClient-Restore.cs @@ -10,26 +10,26 @@ namespace Nest public partial class ElasticClient { /// - public IAcknowledgedResponse Restore(string repository, string snapshotName, Func selector = null) + public IRestoreResponse Restore(string repository, string snapshotName, Func selector = null) { snapshotName.ThrowIfNullOrEmpty("name"); repository.ThrowIfNullOrEmpty("repository"); selector = selector ?? (s => s); - return this.Dispatch( + return this.Dispatch( s => selector(s.Snapshot(snapshotName).Repository(repository)), - (p, d) => this.RawDispatch.SnapshotRestoreDispatch(p, d) + (p, d) => this.RawDispatch.SnapshotRestoreDispatch(p, d) ); } /// - public Task RestoreAsync(string repository, string snapshotName, Func selector = null) + public Task RestoreAsync(string repository, string snapshotName, Func selector = null) { snapshotName.ThrowIfNullOrEmpty("name"); repository.ThrowIfNullOrEmpty("repository"); selector = selector ?? (s => s); - return this.DispatchAsync( + return this.DispatchAsync( s => selector(s.Snapshot(snapshotName).Repository(repository)), - (p, d) => this.RawDispatch.SnapshotRestoreDispatchAsync(p, d) + (p, d) => this.RawDispatch.SnapshotRestoreDispatchAsync(p, d) ); } } diff --git a/src/Nest/IElasticClient.cs b/src/Nest/IElasticClient.cs index 8b1bf5ebc6b..1b3e302720f 100644 --- a/src/Nest/IElasticClient.cs +++ b/src/Nest/IElasticClient.cs @@ -1176,7 +1176,7 @@ Task DocumentExistsAsync(Func, D /// The repository name that holds our snapshot /// The name of the snapshot that we want to restore /// Optionally further describe the restore operation - IAcknowledgedResponse Restore(string repository, string snapshotName, Func selector = null); + IRestoreResponse Restore(string repository, string snapshotName, Func selector = null); /// /// Restore a snapshot @@ -1185,6 +1185,6 @@ Task DocumentExistsAsync(Func, D /// The repository name that holds our snapshot /// The name of the snapshot that we want to restore /// Optionally further describe the restore operation - Task RestoreAsync(string repository, string snapshotName, Func selector = null); + Task RestoreAsync(string repository, string snapshotName, Func selector = null); } } \ No newline at end of file diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index b809bd8ffd6..d28c0dbaa67 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -132,7 +132,9 @@ + + diff --git a/src/Tests/Nest.Tests.Integration/Core/Repository/RestoreTests.cs b/src/Tests/Nest.Tests.Integration/Core/Repository/RestoreTests.cs index 140bb9ef3b6..b6354738a97 100644 --- a/src/Tests/Nest.Tests.Integration/Core/Repository/RestoreTests.cs +++ b/src/Tests/Nest.Tests.Integration/Core/Repository/RestoreTests.cs @@ -54,8 +54,12 @@ public void SnapshotRestore() .Index(indexName) .IgnoreUnavailable(true)); - restoreResponse.IsValid.Should().BeTrue(); var restoredIndexName = indexName.Replace(d + "_", d + "_restored_"); + restoreResponse.IsValid.Should().BeTrue(); + restoreResponse.Snapshot.Should().NotBeNull(); + restoreResponse.Snapshot.Name.Should().Be(backupName); + restoreResponse.Snapshot.Indices.Should().Equal(new string[] { restoredIndexName }); + var indexExistsResponse = this._client.IndexExists(f => f.Index(restoredIndexName)); indexExistsResponse.Exists.Should().BeTrue();