Skip to content

Commit a337b32

Browse files
authored
Include stored_scripts response in cluster metadata response. (#3757)
Include stored_scripts response in cluster metadata response. Fixes #3746
1 parent 41fdbb1 commit a337b32

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/Nest/Cluster/ClusterState/MetadataState.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ public class MetadataState
1515
[JsonProperty("templates")]
1616
[JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter<string, TemplateMapping>))]
1717
public IReadOnlyDictionary<string, TemplateMapping> Templates { get; internal set; }
18+
19+
[JsonProperty("stored_scripts")]
20+
[JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter<string, StoredScriptMapping>))]
21+
public IReadOnlyDictionary<string, StoredScriptMapping> StoredScripts { get; internal set; }
1822
}
1923
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Nest
5+
{
6+
public class StoredScriptMapping
7+
{
8+
[JsonProperty("lang")]
9+
public string Language { get; internal set; }
10+
11+
[JsonProperty("source")]
12+
public string Source { get; internal set; }
13+
14+
[JsonProperty("options")]
15+
public IReadOnlyDictionary<string, string> Options { get; internal set; } = EmptyReadOnly<string, string>.Dictionary;
16+
}
17+
}

src/Tests/Tests/Cluster/ClusterState/ClusterStateApiTests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using Elastic.Xunit.XunitPlumbing;
34
using Elasticsearch.Net;
45
using FluentAssertions;
56
using Nest;
@@ -102,4 +103,44 @@ protected void Assert(RoutingNodesState routingNodes, string master)
102103
node.State.Should().NotBeNullOrWhiteSpace();
103104
}
104105
}
106+
107+
[SkipVersion("<6.5.0", "Validated against 6.5.0")]
108+
public class ClusterStateStoredScriptApiTests
109+
: ApiIntegrationTestBase<WritableCluster, IClusterStateResponse, IClusterStateRequest, ClusterStateDescriptor, ClusterStateRequest>
110+
{
111+
public ClusterStateStoredScriptApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
112+
113+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
114+
{
115+
client.PutScript("my-script-id", s => s.Painless("return 0"));
116+
client.PutScript("my-other-script-id", s => s.Painless("return 1"));
117+
}
118+
119+
protected override bool ExpectIsValid => true;
120+
protected override int ExpectStatusCode => 200;
121+
protected override HttpMethod HttpMethod => HttpMethod.GET;
122+
protected override string UrlPath => "/_cluster/state/metadata";
123+
124+
protected override LazyResponses ClientUsage() => Calls(
125+
(client, f) => client.ClusterState(s => s.Metric(ClusterStateMetric.Metadata)),
126+
(client, f) => client.ClusterStateAsync(s => s.Metric(ClusterStateMetric.Metadata)),
127+
(client, r) => client.ClusterState(new ClusterStateRequest(ClusterStateMetric.Metadata)),
128+
(client, r) => client.ClusterStateAsync(new ClusterStateRequest(ClusterStateMetric.Metadata))
129+
);
130+
131+
protected override void ExpectResponse(IClusterStateResponse response)
132+
{
133+
response.Metadata.Should().NotBeNull();
134+
response.Metadata.StoredScripts.Should().NotBeNull();
135+
response.Metadata.StoredScripts.Count.Should().Be(2);
136+
137+
response.Metadata.StoredScripts["my-script-id"].Language.Should().Be("painless");
138+
response.Metadata.StoredScripts["my-script-id"].Source.Should().Be("return 0");
139+
response.Metadata.StoredScripts["my-script-id"].Options.Should().BeEmpty();
140+
141+
response.Metadata.StoredScripts["my-other-script-id"].Language.Should().Be("painless");
142+
response.Metadata.StoredScripts["my-other-script-id"].Source.Should().Be("return 1");
143+
response.Metadata.StoredScripts["my-other-script-id"].Options.Should().BeEmpty();
144+
}
145+
}
105146
}

0 commit comments

Comments
 (0)