Skip to content

Commit e8d565c

Browse files
committed
Include stored_scripts response in cluster metadata response. #3757
1 parent 8afb4cc commit e8d565c

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/Nest/Cluster/ClusterState/MetadataState.cs

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

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, ClusterStateResponse, 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.Cluster.State(null, s => s.Metric(ClusterStateMetric.Metadata)),
126+
(client, f) => client.Cluster.StateAsync(null, s => s.Metric(ClusterStateMetric.Metadata)),
127+
(client, r) => client.Cluster.State(new ClusterStateRequest(ClusterStateMetric.Metadata)),
128+
(client, r) => client.Cluster.StateAsync(new ClusterStateRequest(ClusterStateMetric.Metadata))
129+
);
130+
131+
protected override void ExpectResponse(ClusterStateResponse 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)