diff --git a/src/ApiGenerator/Domain/Specification/UrlPart.cs b/src/ApiGenerator/Domain/Specification/UrlPart.cs index 0e9587400f7..bdf370310ac 100644 --- a/src/ApiGenerator/Domain/Specification/UrlPart.cs +++ b/src/ApiGenerator/Domain/Specification/UrlPart.cs @@ -95,6 +95,7 @@ public string HighLevelTypeName case "application": case "repository": case "snapshot": + case "target_snapshot": case "user": case "username": case "realms": diff --git a/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Snapshot.cs b/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Snapshot.cs index 467651188b5..6e25cdcf8f2 100644 --- a/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Snapshot.cs +++ b/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Snapshot.cs @@ -44,7 +44,7 @@ public TimeSpan Timeout } ///Request options for Clone https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html - public class CloneRequestParameters : RequestParameters + public class CloneSnapshotRequestParameters : RequestParameters { ///Explicit operation timeout for connection to master node public TimeSpan MasterTimeout diff --git a/src/Elasticsearch.Net/ElasticLowLevelClient.Snapshot.cs b/src/Elasticsearch.Net/ElasticLowLevelClient.Snapshot.cs index 8355c976db5..bbbecb0e38e 100644 --- a/src/Elasticsearch.Net/ElasticLowLevelClient.Snapshot.cs +++ b/src/Elasticsearch.Net/ElasticLowLevelClient.Snapshot.cs @@ -61,7 +61,7 @@ public Task CleanupRepositoryAsync(string repository, Clea ///The name of the cloned snapshot to create ///The snapshot clone definition ///Request specific configuration such as querystring parameters & request specific connection settings. - public TResponse Clone(string repository, string snapshot, string targetSnapshot, PostData body, CloneRequestParameters requestParameters = null) + public TResponse Clone(string repository, string snapshot, string targetSnapshot, PostData body, CloneSnapshotRequestParameters requestParameters = null) where TResponse : class, ITransportResponse, new() => DoRequest(PUT, Url($"_snapshot/{repository:repository}/{snapshot:snapshot}/_clone/{targetSnapshot:targetSnapshot}"), body, RequestParams(requestParameters)); ///PUT on /_snapshot/{repository}/{snapshot}/_clone/{target_snapshot} https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html ///A repository name @@ -70,7 +70,7 @@ public TResponse Clone(string repository, string snapshot, string tar ///The snapshot clone definition ///Request specific configuration such as querystring parameters & request specific connection settings. [MapsApi("snapshot.clone", "repository, snapshot, target_snapshot, body")] - public Task CloneAsync(string repository, string snapshot, string targetSnapshot, PostData body, CloneRequestParameters requestParameters = null, CancellationToken ctx = default) + public Task CloneAsync(string repository, string snapshot, string targetSnapshot, PostData body, CloneSnapshotRequestParameters requestParameters = null, CancellationToken ctx = default) where TResponse : class, ITransportResponse, new() => DoRequestAsync(PUT, Url($"_snapshot/{repository:repository}/{snapshot:snapshot}/_clone/{targetSnapshot:targetSnapshot}"), ctx, body, RequestParams(requestParameters)); ///PUT on /_snapshot/{repository}/{snapshot} https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html ///A repository name diff --git a/src/Nest/Descriptors.Snapshot.cs b/src/Nest/Descriptors.Snapshot.cs index a4b0537d3a8..70ef5b78f9d 100644 --- a/src/Nest/Descriptors.Snapshot.cs +++ b/src/Nest/Descriptors.Snapshot.cs @@ -58,6 +58,35 @@ protected CleanupRepositoryDescriptor(): base() public CleanupRepositoryDescriptor Timeout(Time timeout) => Qs("timeout", timeout); } + ///Descriptor for Clone https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + public partial class CloneSnapshotDescriptor : RequestDescriptorBase, ICloneSnapshotRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.SnapshotClone; + protected override HttpMethod HttpMethod => HttpMethod.PUT; + protected override bool SupportsBody => true; + ////_snapshot/{repository}/{snapshot}/_clone/{target_snapshot} + ///this parameter is required + ///this parameter is required + ///this parameter is required + public CloneSnapshotDescriptor(Name repository, Name snapshot, Name targetSnapshot): base(r => r.Required("repository", repository).Required("snapshot", snapshot).Required("target_snapshot", targetSnapshot)) + { + } + + ///Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected CloneSnapshotDescriptor(): base() + { + } + + // values part of the url path + Name ICloneSnapshotRequest.RepositoryName => Self.RouteValues.Get("repository"); + Name ICloneSnapshotRequest.Snapshot => Self.RouteValues.Get("snapshot"); + Name ICloneSnapshotRequest.TargetSnapshot => Self.RouteValues.Get("target_snapshot"); + // Request parameters + ///Explicit operation timeout for connection to master node + public CloneSnapshotDescriptor MasterTimeout(Time mastertimeout) => Qs("master_timeout", mastertimeout); + } + ///Descriptor for Snapshot https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html public partial class SnapshotDescriptor : RequestDescriptorBase, ISnapshotRequest { @@ -322,4 +351,4 @@ protected VerifyRepositoryDescriptor(): base() ///Explicit operation timeout public VerifyRepositoryDescriptor Timeout(Time timeout) => Qs("timeout", timeout); } -} \ No newline at end of file +} diff --git a/src/Nest/ElasticClient.Snapshot.cs b/src/Nest/ElasticClient.Snapshot.cs index 0d88e4036fd..0cffd617513 100644 --- a/src/Nest/ElasticClient.Snapshot.cs +++ b/src/Nest/ElasticClient.Snapshot.cs @@ -61,6 +61,30 @@ internal SnapshotNamespace(ElasticClient client): base(client) /// public Task CleanupRepositoryAsync(ICleanupRepositoryRequest request, CancellationToken ct = default) => DoRequestAsync(request, request.RequestParameters, ct); /// + /// PUT request to the snapshot.clone API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + /// + public CloneSnapshotResponse Clone(Name repository, Name snapshot, Name targetSnapshot, Func selector) => Clone(selector.InvokeOrDefault(new CloneSnapshotDescriptor(repository: repository, snapshot: snapshot, targetSnapshot: targetSnapshot))); + /// + /// PUT request to the snapshot.clone API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + /// + public Task CloneAsync(Name repository, Name snapshot, Name targetSnapshot, Func selector, CancellationToken ct = default) => CloneAsync(selector.InvokeOrDefault(new CloneSnapshotDescriptor(repository: repository, snapshot: snapshot, targetSnapshot: targetSnapshot)), ct); + /// + /// PUT request to the snapshot.clone API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + /// + public CloneSnapshotResponse Clone(ICloneSnapshotRequest request) => DoRequest(request, request.RequestParameters); + /// + /// PUT request to the snapshot.clone API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + /// + public Task CloneAsync(ICloneSnapshotRequest request, CancellationToken ct = default) => DoRequestAsync(request, request.RequestParameters, ct); + /// /// PUT request to the snapshot.create API, read more about this API online: /// /// https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html diff --git a/src/Nest/Modules/SnapshotAndRestore/Snapshot/Clone/CloneSnapshotRequest.cs b/src/Nest/Modules/SnapshotAndRestore/Snapshot/Clone/CloneSnapshotRequest.cs new file mode 100644 index 00000000000..c7cd0773f2c --- /dev/null +++ b/src/Nest/Modules/SnapshotAndRestore/Snapshot/Clone/CloneSnapshotRequest.cs @@ -0,0 +1,39 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +using System.Runtime.Serialization; + +namespace Nest +{ + [MapsApi("snapshot.clone.json")] + [ReadAs(typeof(CloneSnapshotRequest))] + public partial interface ICloneSnapshotRequest + { + /// + /// The indices to clone. + /// + [DataMember(Name = "indices")] + Indices Indices { get; set; } + } + + public partial class CloneSnapshotRequest + { + /// + public Indices Indices { get; set; } + } + + public partial class CloneSnapshotDescriptor + { + Indices ICloneSnapshotRequest.Indices { get; set; } + + /// + public CloneSnapshotDescriptor Index(IndexName index) => Indices(index); + + /// + public CloneSnapshotDescriptor Index() where T : class => Indices(typeof(T)); + + /// + public CloneSnapshotDescriptor Indices(Indices indices) => Assign(indices, (a, v) => a.Indices = v); + } +} diff --git a/src/Nest/Modules/SnapshotAndRestore/Snapshot/Clone/CloneSnapshotResponse.cs b/src/Nest/Modules/SnapshotAndRestore/Snapshot/Clone/CloneSnapshotResponse.cs new file mode 100644 index 00000000000..2a8ea165c1d --- /dev/null +++ b/src/Nest/Modules/SnapshotAndRestore/Snapshot/Clone/CloneSnapshotResponse.cs @@ -0,0 +1,8 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +namespace Nest +{ + public class CloneSnapshotResponse : AcknowledgedResponseBase { } +} diff --git a/src/Nest/Requests.Snapshot.cs b/src/Nest/Requests.Snapshot.cs index b6c9e83d160..4a6540bb418 100644 --- a/src/Nest/Requests.Snapshot.cs +++ b/src/Nest/Requests.Snapshot.cs @@ -80,6 +80,65 @@ public Time Timeout } } + [InterfaceDataContract] + public partial interface ICloneSnapshotRequest : IRequest + { + [IgnoreDataMember] + Name RepositoryName + { + get; + } + + [IgnoreDataMember] + Name Snapshot + { + get; + } + + [IgnoreDataMember] + Name TargetSnapshot + { + get; + } + } + + ///Request for Clone https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + public partial class CloneSnapshotRequest : PlainRequestBase, ICloneSnapshotRequest + { + protected ICloneSnapshotRequest Self => this; + internal override ApiUrls ApiUrls => ApiUrlsLookups.SnapshotClone; + protected override HttpMethod HttpMethod => HttpMethod.PUT; + protected override bool SupportsBody => true; + ////_snapshot/{repository}/{snapshot}/_clone/{target_snapshot} + ///this parameter is required + ///this parameter is required + ///this parameter is required + public CloneSnapshotRequest(Name repository, Name snapshot, Name targetSnapshot): base(r => r.Required("repository", repository).Required("snapshot", snapshot).Required("target_snapshot", targetSnapshot)) + { + } + + ///Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected CloneSnapshotRequest(): base() + { + } + + // values part of the url path + [IgnoreDataMember] + Name ICloneSnapshotRequest.RepositoryName => Self.RouteValues.Get("repository"); + [IgnoreDataMember] + Name ICloneSnapshotRequest.Snapshot => Self.RouteValues.Get("snapshot"); + [IgnoreDataMember] + Name ICloneSnapshotRequest.TargetSnapshot => Self.RouteValues.Get("target_snapshot"); + // Request parameters + ///Explicit operation timeout for connection to master node + public Time MasterTimeout + { + get => Q