Skip to content

Commit 9aaae89

Browse files
committed
Add Allocation Delay and Remaining Delay to Cluster Allocation Explain API
See elastic/elasticsearch#17515
1 parent 6795756 commit 9aaae89

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

src/Nest/Cluster/ClusterAllocationExplain/ClusterAllocationExplainResponse.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,27 @@ public interface IClusterAllocationExplainResponse : IResponse
1414
[JsonProperty("assigned")]
1515
bool Assigned { get; set; }
1616

17+
[JsonProperty("assigned_node_id")]
18+
string AssignedNodeId { get; set; }
19+
20+
[JsonProperty("shard_state_fetch_pending")]
21+
bool ShardStateFetchPending { get; set; }
22+
1723
[JsonProperty("unassigned_info")]
1824
UnassignedInformation UnassignedInformation { get; set; }
1925

26+
[JsonProperty("allocation_delay")]
27+
string AllocationDelay { get; set; }
28+
29+
[JsonProperty("allocation_delay_ms")]
30+
long AllocationDelayInMilliseconds { get; set; }
31+
32+
[JsonProperty("remaining_delay")]
33+
string RemainingDelay { get; set; }
34+
35+
[JsonProperty("remaining_delay_ms")]
36+
long RemainingDelayInMilliseconds { get; set; }
37+
2038
[JsonProperty("nodes")]
2139
[JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))]
2240
Dictionary<string, NodeAllocationExplanation> Nodes { get; set; }
@@ -28,8 +46,20 @@ public class ClusterAllocationExplainResponse : ResponseBase, IClusterAllocation
2846

2947
public bool Assigned { get; set; }
3048

49+
public string AssignedNodeId { get; set; }
50+
51+
public bool ShardStateFetchPending { get; set; }
52+
3153
public UnassignedInformation UnassignedInformation { get; set; }
3254

55+
public string AllocationDelay { get; set; }
56+
57+
public long AllocationDelayInMilliseconds { get; set; }
58+
59+
public string RemainingDelay { get; set; }
60+
61+
public long RemainingDelayInMilliseconds { get; set; }
62+
3363
public Dictionary<string, NodeAllocationExplanation> Nodes { get; set; }
3464
}
3565

@@ -58,17 +88,30 @@ public class NodeAllocationExplanation
5888
[JsonProperty("node_attributes")]
5989
public Dictionary<string,string> NodeAttributes { get; set; }
6090

91+
[JsonProperty("store")]
92+
public AllocationStore Store { get; set; }
93+
6194
// TODO: Are there enum values for this?
6295
[JsonProperty("final_decision")]
6396
public string FinalDecision { get; set; }
6497

98+
[JsonProperty("final_explanation")]
99+
public string FinalExplanation { get; set; }
100+
65101
[JsonProperty("weight")]
66102
public float Weight { get; set; }
67103

68104
[JsonProperty("decisions")]
69105
public IEnumerable<AllocationDecision> Decisions { get; set; }
70106
}
71107

108+
[JsonObject]
109+
public class AllocationStore
110+
{
111+
[JsonProperty("shard_copy")]
112+
public string ShardCopy { get; set; }
113+
}
114+
72115
[JsonObject]
73116
public class AllocationDecision
74117
{

src/Tests/Cluster/ClusterAllocationExplain/ClusterAllocationExplainApiTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,21 @@ protected override void ExpectResponse(IClusterAllocationExplainResponse respons
5454
response.Shard.Id.Should().Be(0);
5555
response.Shard.IndexUniqueId.Should().NotBeNullOrEmpty();
5656
response.Assigned.Should().BeTrue();
57+
response.AssignedNodeId.Should().NotBeNullOrWhiteSpace();
58+
response.ShardStateFetchPending.Should().BeFalse();
5759

5860
foreach (var node in response.Nodes)
5961
{
6062
var explanation = node.Value;
6163

64+
6265
explanation.NodeName.Should().NotBeNullOrEmpty();
6366
explanation.Weight.Should().BeGreaterOrEqualTo(0);
6467
explanation.NodeAttributes.Should().NotBeEmpty();
68+
explanation.Store.Should().NotBeNull();
69+
explanation.Store.ShardCopy.Should().NotBeNullOrEmpty();
6570
explanation.FinalDecision.Should().NotBeNullOrEmpty();
71+
explanation.FinalExplanation.Should().NotBeNullOrEmpty();
6672
explanation.Decisions.Should().NotBeNullOrEmpty();
6773
}
6874
}

src/Tests/Framework/ManagedElasticsearch/Process/ElasticsearchNode.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ private void ValidateLicense(IElasticClient client, XplatManualResetEvent handle
212212

213213
var exceptionMessageStart = "Server has license plugin installed, ";
214214
#if DOTNETCORE
215-
var licenseFile = string.Empty;
215+
var licensePath = @"C:\license.json";
216+
var licenseFile = File.Exists(licensePath) ? licensePath : string.Empty;
216217
#else
217218
var licenseFile = Environment.GetEnvironmentVariable("ES_LICENSE_FILE", EnvironmentVariableTarget.Machine);
218219
#endif
@@ -232,7 +233,13 @@ private void ValidateLicense(IElasticClient client, XplatManualResetEvent handle
232233

233234
Exception exception = null;
234235

235-
if (license.ApiCall.Success && license.License == null)
236+
if (!license.IsValid)
237+
{
238+
exception = license.ApiCall.HttpStatusCode == 404
239+
? new Exception($"{exceptionMessageStart} but the license was not found!")
240+
: new Exception($"{exceptionMessageStart} but a {license.ApiCall.HttpStatusCode} was returned!");
241+
}
242+
else if (license.License == null)
236243
exception = new Exception($"{exceptionMessageStart} but the license was deleted!");
237244

238245
else if (license.License.Status == LicenseStatus.Expired)

0 commit comments

Comments
 (0)