-
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.
This commit adds the indices.add_block API to the client. Co-authored-by: Russ Cam <[email protected]>
- Loading branch information
1 parent
0792de8
commit b53590a
Showing
13 changed files
with
346 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
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
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
25 changes: 25 additions & 0 deletions
25
src/Nest/Indices/IndexManagement/AddBlock/AddIndexBlockRequest.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,25 @@ | ||
// 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 | ||
{ | ||
/// <summary> | ||
/// A request to the indices add block API | ||
/// </summary> | ||
[MapsApi("indices.add_block.json")] | ||
[ReadAs(typeof(AddIndexBlockRequest))] | ||
public partial interface IAddIndexBlockRequest | ||
{ | ||
} | ||
|
||
/// <inheritdoc cref="IAddIndexBlockRequest" /> | ||
public partial class AddIndexBlockRequest | ||
{ | ||
} | ||
|
||
/// <inheritdoc cref="IAddIndexBlockRequest" /> | ||
public partial class AddIndexBlockDescriptor | ||
{ | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Nest/Indices/IndexManagement/AddBlock/AddIndexBlockResponse.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,28 @@ | ||
// 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.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
using Elasticsearch.Net; | ||
|
||
namespace Nest | ||
{ | ||
public class AddIndexBlockResponse : AcknowledgedResponseBase | ||
{ | ||
[DataMember(Name = "shards_acknowledged")] | ||
public bool ShardsAcknowledged { get; internal set; } | ||
|
||
[DataMember(Name = "indices")] | ||
public IReadOnlyCollection<BlockedIndex> Indices { get; internal set; } = EmptyReadOnly<BlockedIndex>.Collection; | ||
} | ||
|
||
public class BlockedIndex | ||
{ | ||
[DataMember(Name = "name")] | ||
public string Name { get; internal set; } | ||
|
||
[DataMember(Name = "blocked")] | ||
public bool Blocked { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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 | ||
|
||
// 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 Elasticsearch.Net; | ||
|
||
namespace Nest | ||
{ | ||
/// <summary> | ||
/// Block type for an index. | ||
/// </summary> | ||
public class IndexBlock : IUrlParameter | ||
{ | ||
private IndexBlock(string value) => Value = value; | ||
|
||
public string Value { get; } | ||
|
||
public string GetString(IConnectionConfigurationValues settings) => Value; | ||
|
||
/// <summary> | ||
/// Disable metadata changes, such as closing the index. | ||
/// </summary> | ||
public static IndexBlock Metadata { get; } = new IndexBlock("metadata"); | ||
|
||
/// <summary> | ||
/// Disable read operations. | ||
/// </summary> | ||
public static IndexBlock Read { get; } = new IndexBlock("read"); | ||
|
||
/// <summary> | ||
/// Disable write operations and metadata changes. | ||
/// </summary> | ||
public static IndexBlock ReadOnly { get; } = new IndexBlock("read_only"); | ||
|
||
/// <summary> | ||
/// Disable write operations. However, metadata changes are still allowed. | ||
/// </summary> | ||
public static IndexBlock Write { get; } = new IndexBlock("write"); | ||
} | ||
} |
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
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
72 changes: 72 additions & 0 deletions
72
tests/Tests/Indices/IndexManagement/AddBlock/AddIndexBlockApiTests.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,72 @@ | ||
// 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; | ||
using System.Linq; | ||
using Elastic.Elasticsearch.Xunit.XunitPlumbing; | ||
using Elasticsearch.Net; | ||
using FluentAssertions; | ||
using Nest; | ||
using Tests.Core.Extensions; | ||
using Tests.Core.ManagedElasticsearch.Clusters; | ||
using Tests.Framework.EndpointTests; | ||
using Tests.Framework.EndpointTests.TestState; | ||
|
||
namespace Tests.Indices.IndexManagement.AddBlock | ||
{ | ||
[SkipVersion("<7.9.0", "indices add index introduced in 7.9.0")] | ||
public class AddIndexBlockApiTests | ||
: ApiIntegrationTestBase<WritableCluster, AddIndexBlockResponse, IAddIndexBlockRequest, AddIndexBlockDescriptor, AddIndexBlockRequest> | ||
{ | ||
public AddIndexBlockApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } | ||
|
||
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values) | ||
{ | ||
foreach (var value in values) | ||
{ | ||
var createIndexResponse = client.Indices.Create(value.Value, c => c | ||
.Settings(s => s | ||
.NumberOfShards(1) | ||
.NumberOfReplicas(0) | ||
) | ||
); | ||
|
||
if (!createIndexResponse.IsValid) | ||
throw new Exception($"exception whilst setting up integration test: {createIndexResponse.DebugInformation}"); | ||
} | ||
} | ||
|
||
protected override bool ExpectIsValid => true; | ||
|
||
protected override int ExpectStatusCode => 200; | ||
|
||
protected override Func<AddIndexBlockDescriptor, IAddIndexBlockRequest> Fluent => d => d; | ||
|
||
protected override HttpMethod HttpMethod => HttpMethod.PUT; | ||
|
||
protected override AddIndexBlockRequest Initializer => new AddIndexBlockRequest(CallIsolatedValue, IndexBlock.Write); | ||
|
||
protected override string UrlPath => $"/{CallIsolatedValue}/_block/write"; | ||
|
||
protected override LazyResponses ClientUsage() => Calls( | ||
(client, f) => client.Indices.AddBlock(CallIsolatedValue, IndexBlock.Write, f), | ||
(client, f) => client.Indices.AddBlockAsync(CallIsolatedValue, IndexBlock.Write, f), | ||
(client, r) => client.Indices.AddBlock(r), | ||
(client, r) => client.Indices.AddBlockAsync(r) | ||
); | ||
|
||
protected override AddIndexBlockDescriptor NewDescriptor() => new AddIndexBlockDescriptor(CallIsolatedValue, IndexBlock.Write); | ||
|
||
protected override void ExpectResponse(AddIndexBlockResponse response) | ||
{ | ||
response.ShouldBeValid(); | ||
response.Acknowledged.Should().BeTrue(); | ||
response.ShardsAcknowledged.Should().BeTrue(); | ||
response.Indices.Should().HaveCount(1); | ||
var first = response.Indices.First(); | ||
first.Name.Should().Be(CallIsolatedValue); | ||
first.Blocked.Should().BeTrue(); | ||
} | ||
} | ||
} |
Oops, something went wrong.