Skip to content

Commit

Permalink
properly mapped restore response, fix #511 #512 #513 #514 #515 #516 #517
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz committed Apr 10, 2014
1 parent 9fbf80d commit 4f1abc7
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
17 changes: 17 additions & 0 deletions src/Nest/Domain/Repository/SnapshotRestore.cs
Original file line number Diff line number Diff line change
@@ -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<string> Indices { get; internal set; }

[JsonProperty("shards")]
public ShardsMetaData Shards { get; internal set; }
}
}
25 changes: 25 additions & 0 deletions src/Nest/Domain/Responses/RestoreResponse.cs
Original file line number Diff line number Diff line change
@@ -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; }

}
}
12 changes: 6 additions & 6 deletions src/Nest/ElasticClient-Restore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ namespace Nest
public partial class ElasticClient
{
/// <inheritdoc />
public IAcknowledgedResponse Restore(string repository, string snapshotName, Func<RestoreDescriptor, RestoreDescriptor> selector = null)
public IRestoreResponse Restore(string repository, string snapshotName, Func<RestoreDescriptor, RestoreDescriptor> selector = null)
{
snapshotName.ThrowIfNullOrEmpty("name");
repository.ThrowIfNullOrEmpty("repository");
selector = selector ?? (s => s);
return this.Dispatch<RestoreDescriptor, RestoreRequestParameters, AcknowledgedResponse>(
return this.Dispatch<RestoreDescriptor, RestoreRequestParameters, RestoreResponse>(
s => selector(s.Snapshot(snapshotName).Repository(repository)),
(p, d) => this.RawDispatch.SnapshotRestoreDispatch<AcknowledgedResponse>(p, d)
(p, d) => this.RawDispatch.SnapshotRestoreDispatch<RestoreResponse>(p, d)
);
}

/// <inheritdoc />
public Task<IAcknowledgedResponse> RestoreAsync(string repository, string snapshotName, Func<RestoreDescriptor, RestoreDescriptor> selector = null)
public Task<IRestoreResponse> RestoreAsync(string repository, string snapshotName, Func<RestoreDescriptor, RestoreDescriptor> selector = null)
{
snapshotName.ThrowIfNullOrEmpty("name");
repository.ThrowIfNullOrEmpty("repository");
selector = selector ?? (s => s);
return this.DispatchAsync<RestoreDescriptor, RestoreRequestParameters, AcknowledgedResponse, IAcknowledgedResponse>(
return this.DispatchAsync<RestoreDescriptor, RestoreRequestParameters, RestoreResponse, IRestoreResponse>(
s => selector(s.Snapshot(snapshotName).Repository(repository)),
(p, d) => this.RawDispatch.SnapshotRestoreDispatchAsync<AcknowledgedResponse>(p, d)
(p, d) => this.RawDispatch.SnapshotRestoreDispatchAsync<RestoreResponse>(p, d)
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Nest/IElasticClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ Task<IExistsResponse> DocumentExistsAsync<T>(Func<DocumentExistsDescriptor<T>, D
/// <param name="repository">The repository name that holds our snapshot</param>
/// <param name="snapshotName">The name of the snapshot that we want to restore</param>
/// <param name="selector">Optionally further describe the restore operation</param>
IAcknowledgedResponse Restore(string repository, string snapshotName, Func<RestoreDescriptor, RestoreDescriptor> selector = null);
IRestoreResponse Restore(string repository, string snapshotName, Func<RestoreDescriptor, RestoreDescriptor> selector = null);

/// <summary>
/// Restore a snapshot
Expand All @@ -1185,6 +1185,6 @@ Task<IExistsResponse> DocumentExistsAsync<T>(Func<DocumentExistsDescriptor<T>, D
/// <param name="repository">The repository name that holds our snapshot</param>
/// <param name="snapshotName">The name of the snapshot that we want to restore</param>
/// <param name="selector">Optionally further describe the restore operation</param>
Task<IAcknowledgedResponse> RestoreAsync(string repository, string snapshotName, Func<RestoreDescriptor, RestoreDescriptor> selector = null);
Task<IRestoreResponse> RestoreAsync(string repository, string snapshotName, Func<RestoreDescriptor, RestoreDescriptor> selector = null);
}
}
2 changes: 2 additions & 0 deletions src/Nest/Nest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@
<Compile Include="Domain\PropertyNameMarker.cs" />
<Compile Include="Domain\PropertyPathMarker.cs" />
<Compile Include="Domain\Repository\Snapshot.cs" />
<Compile Include="Domain\Repository\SnapshotRestore.cs" />
<Compile Include="Domain\Responses\GetSnapshotResponse.cs" />
<Compile Include="Domain\Responses\RestoreResponse.cs" />
<Compile Include="Domain\Responses\SnapshotResponse.cs" />
<Compile Include="DSL\DeleteSnapshotDescriptor.cs" />
<Compile Include="DSL\GetSnapshotDescriptor.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 4f1abc7

Please sign in to comment.