Skip to content

Commit 6f0c7b9

Browse files
committed
Map node failures. (#4019)
Fixes #3851
1 parent dc0af28 commit 6f0c7b9

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/Nest/Cluster/NodesResponseBase.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Runtime.Serialization;
1+
using System.Collections.Generic;
2+
using System.Runtime.Serialization;
3+
using Elasticsearch.Net;
24

35
namespace Nest
46
{
@@ -20,6 +22,7 @@ public class NodeStatistics
2022
[DataMember(Name = "total")]
2123
public int Total { get; internal set; }
2224

23-
//TODO map failures
25+
[DataMember(Name = "failures")]
26+
public IReadOnlyCollection<ErrorCause> Failures { get; internal set; } = EmptyReadOnly<ErrorCause>.Collection;
2427
}
2528
}

src/Tests/Tests/Cluster/NodesUsage/NodesUsageUnitTests.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using Elastic.Xunit.XunitPlumbing;
45
using FluentAssertions;
56
using Tests.Core.Client;
@@ -19,7 +20,30 @@ public void ShouldDeserialize()
1920
{
2021
total = 1,
2122
successful = 1,
22-
failed = 0
23+
failed = 0,
24+
failures = new[]
25+
{
26+
new
27+
{
28+
type = "illegal_argument_exception",
29+
reason = "failed to execute script",
30+
caused_by = new
31+
{
32+
type = "script_exception",
33+
reason = "failed to run inline script [use(java.lang.Exception) {throw new Exception(\"Customized Exception\")}] using lang [groovy]",
34+
caused_by = new
35+
{
36+
type = "privileged_action_exception",
37+
reason = (string)null,
38+
caused_by = new
39+
{
40+
type="exception",
41+
reason= "Custom Exception"
42+
}
43+
}
44+
}
45+
}
46+
}
2347
},
2448
cluster_name = "my_cluster",
2549
nodes = new Dictionary<string, object>
@@ -54,6 +78,11 @@ public void ShouldDeserialize()
5478
response.NodeStatistics.Total.Should().Be(1);
5579
response.NodeStatistics.Successful.Should().Be(1);
5680
response.NodeStatistics.Failed.Should().Be(0);
81+
response.NodeStatistics.Failures.Should().HaveCount(1);
82+
var failure = response.NodeStatistics.Failures.First();
83+
failure.Type.Should().NotBeNull();
84+
failure.Reason.Should().NotBeNull();
85+
failure.CausedBy.Should().NotBeNull();
5786

5887
response.Nodes.Should().NotBeNull();
5988
response.Nodes.Should().HaveCount(1);

0 commit comments

Comments
 (0)