Skip to content

Commit c4665b7

Browse files
Stuart Camrusscam
authored andcommitted
Adds the x-pack REST API downloads into the client generator. (#3637)
1 parent e647e4a commit c4665b7

34 files changed

+807
-212
lines changed

src/CodeGeneration/ApiGenerator/ApiGenerator.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,31 @@ public class ApiGenerator
2020

2121
private static string[] IgnoredApis { get; } =
2222
{
23+
"ccr.follow_info.json",
24+
"ccr.forget_follower.json",
25+
"ilm.delete_lifecycle.json",
26+
"ilm.explain_lifecycle.json",
27+
"ilm.get_lifecycle.json",
28+
"ilm.get_status.json",
29+
"ilm.move_to_step.json",
30+
"ilm.put_lifecycle.json",
31+
"ilm.remove_policy.json",
32+
"ilm.retry.json",
33+
"ilm.start.json",
34+
"ilm.stop.json",
35+
"indices.freeze.json",
36+
"indices.unfreeze.json",
37+
"xpack.ml.set_upgrade_mode.json",
38+
"security.create_api_key.json",
39+
"security.get_api_key.json",
40+
"security.invalidate_api_key.json",
41+
"xpack.monitoring.bulk.json",
42+
2343
// these API's are not ready for primetime yet
2444
"rank_eval.json",
2545

2646
// these API's are new and need to be mapped
27-
"xpack.ml.find_file_structure.json",
47+
"xpack.ml.find_file_structure.json"
2848
};
2949

3050
public static void Generate(string downloadBranch, params string[] folders)

src/CodeGeneration/ApiGenerator/Program.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,22 @@ private static void Main(string[] args)
3939
if (redownloadCoreSpecification)
4040
RestSpecDownloader.Download(downloadBranch);
4141

42-
ApiGenerator.Generate(downloadBranch, "Core", "Graph", "License", "Security", "Watcher", "Info", "MachineLearning", "Migration", "Sql",
43-
"Rollup", "Ccr", "Ssl");
42+
ApiGenerator.Generate(downloadBranch,
43+
"Ccr",
44+
"Core",
45+
"Graph",
46+
"Ilm",
47+
"Indices",
48+
"Info",
49+
"License",
50+
"MachineLearning",
51+
"Migration",
52+
"Monitoring",
53+
"Rollup",
54+
"Security",
55+
"Sql",
56+
"Ssl",
57+
"Watcher");
4458
}
4559
}
4660
}

src/CodeGeneration/ApiGenerator/RestSpecDownloader.cs

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,43 @@
33
using System.IO;
44
using System.Linq;
55
using System.Net;
6+
using System.Security;
67
using CsQuery;
78
using ShellProgressBar;
89

910
namespace ApiGenerator
1011
{
1112
public class RestSpecDownloader
1213
{
14+
private const string Core = "Core";
15+
private const string XpackTemp = "_Xpack";
16+
1317
private static readonly ProgressBarOptions MainProgressBarOptions = new ProgressBarOptions { BackgroundColor = ConsoleColor.DarkGray };
1418

1519
private static readonly Dictionary<string, string> OnlineSpecifications = new Dictionary<string, string>
1620
{
17-
{ "Core", "https://github.com/elastic/elasticsearch/tree/{version}/rest-api-spec/src/main/resources/rest-api-spec/api" },
21+
{ Core, "https://github.com/elastic/elasticsearch/tree/{version}/rest-api-spec/src/main/resources/rest-api-spec/api" },
22+
{ XpackTemp, "https://github.com/elastic/elasticsearch/tree/{version}/x-pack/plugin/src/test/resources/rest-api-spec/api"}
23+
};
24+
25+
private static readonly Dictionary<string, string> XpackFolderMapping = new Dictionary<string, string>
26+
{
27+
{ "ccr.", "Ccr" },
28+
{ "ilm.", "Ilm" },
29+
{ "indices.", "Indices" },
30+
{ "security.", "Security" },
31+
{ "xpack.graph.", "Graph" },
32+
{ "xpack.info", "Info" },
33+
{ "xpack.usage", "Info" },
34+
{ "xpack.license.", "License" },
35+
{ "xpack.migration.", "Migration" },
36+
{ "xpack.ml.", "MachineLearning" },
37+
{ "xpack.monitoring.", "Monitoring" },
38+
{ "xpack.rollup.", "Rollup" },
39+
{ "xpack.security.", "Security" },
40+
{ "xpack.sql.", "Sql" },
41+
{ "xpack.ssl.", "Ssl" },
42+
{ "xpack.watcher.", "Watcher" }
1843
};
1944

2045
private static readonly ProgressBarOptions SubProgressBarOptions = new ProgressBarOptions
@@ -32,7 +57,6 @@ private RestSpecDownloader(string branch)
3257
let url = kv.Value.Replace("{version}", branch)
3358
select new Specification { FolderOnDisk = kv.Key, Branch = branch, GithubListingUrl = url }).ToList();
3459

35-
3660
using (var pbar = new ProgressBar(specifications.Count, "Downloading specifications", MainProgressBarOptions))
3761
{
3862
foreach (var spec in specifications)
@@ -43,6 +67,40 @@ private RestSpecDownloader(string branch)
4367
}
4468
}
4569

70+
// Move Xpack endpoints into their own folders
71+
var xpackTempPath = Path.Combine(CodeConfiguration.RestSpecificationFolder, XpackTemp);
72+
var xpackFiles = Directory.GetFiles(xpackTempPath, "*.json").ToList();
73+
using (var pbar = new ProgressBar(xpackFiles.Count, "Copying x-pack specifications", MainProgressBarOptions))
74+
{
75+
foreach (var file in xpackFiles)
76+
{
77+
var found = false;
78+
var info = new FileInfo(file);
79+
foreach (var mapping in XpackFolderMapping)
80+
{
81+
if (info.Name.StartsWith(mapping.Key))
82+
{
83+
var target = Path.Combine(CodeConfiguration.RestSpecificationFolder,
84+
"XPack",
85+
mapping.Value,
86+
Path.GetFileName(info.FullName));
87+
if (File.Exists(target))
88+
{
89+
File.Delete(target);
90+
}
91+
File.Move(info.FullName, target);
92+
found = true;
93+
}
94+
}
95+
if (!found)
96+
{
97+
throw new Exception($"XPack file unmapped: {info.Name}");
98+
}
99+
pbar.Tick($"Moved {info.Name}");
100+
}
101+
}
102+
Directory.Delete(xpackTempPath, true);
103+
46104
File.WriteAllText(CodeConfiguration.LastDownloadedVersionFile, branch);
47105
}
48106

src/CodeGeneration/ApiGenerator/RestSpecification/Core/root.html

Lines changed: 183 additions & 167 deletions
Large diffs are not rendered by default.

src/CodeGeneration/ApiGenerator/RestSpecification/XPack/Ccr/ccr.follow.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
"required": true,
1212
"description": "The name of the follower index"
1313
}
14+
},
15+
"params": {
16+
"wait_for_active_shards": {
17+
"type" : "string",
18+
"description" : "Sets the number of shard copies that must be active before returning. Defaults to 0. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)",
19+
"default": "0"
20+
}
1421
}
1522
},
1623
"body": {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"ccr.follow_info": {
3+
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html",
4+
"methods": [ "GET" ],
5+
"url": {
6+
"path": "/{index}/_ccr/info",
7+
"paths": [ "/{index}/_ccr/info" ],
8+
"parts": {
9+
"index": {
10+
"type": "list",
11+
"description": "A comma-separated list of index patterns; use `_all` to perform the operation on all indices"
12+
}
13+
}
14+
}
15+
}
16+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"ccr.forget_follower": {
3+
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/current",
4+
"methods": [ "POST" ],
5+
"url": {
6+
"path": "/{index}/_ccr/forget_follower",
7+
"paths": [ "/{index}/_ccr/forget_follower" ],
8+
"parts": {
9+
"index": {
10+
"type": "string",
11+
"required": true,
12+
"description": "the name of the leader index for which specified follower retention leases should be removed"
13+
}
14+
}
15+
},
16+
"body": {
17+
"description" : "the name and UUID of the follower index, the name of the cluster containing the follower index, and the alias from the perspective of that cluster for the remote cluster containing the leader index",
18+
"required" : true
19+
}
20+
}
21+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"ilm.delete_lifecycle": {
3+
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-delete-lifecycle.html",
4+
"methods": [ "DELETE" ],
5+
"url": {
6+
"path": "/_ilm/policy/{policy}",
7+
"paths": ["/_ilm/policy/{policy}"],
8+
"parts": {
9+
"policy": {
10+
"type" : "string",
11+
"description" : "The name of the index lifecycle policy"
12+
}
13+
},
14+
"params": {
15+
}
16+
},
17+
"body": null
18+
}
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"ilm.explain_lifecycle": {
3+
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-explain-lifecycle.html",
4+
"methods": [ "GET" ],
5+
"url": {
6+
"path": "/{index}/_ilm/explain",
7+
"paths": ["/{index}/_ilm/explain"],
8+
"parts": {
9+
"index": {
10+
"type" : "string",
11+
"description" : "The name of the index to explain"
12+
}
13+
},
14+
"params": {
15+
"human": {
16+
"type" : "boolean",
17+
"default" : "false",
18+
"description" : "Return data such as dates in a human readable format"
19+
}
20+
}
21+
},
22+
"body": null
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"ilm.get_lifecycle": {
3+
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-get-lifecycle.html",
4+
"methods": [ "GET" ],
5+
"url": {
6+
"path": "/_ilm/policy/{policy}",
7+
"paths": ["/_ilm/policy/{policy}", "/_ilm/policy"],
8+
"parts": {
9+
"policy": {
10+
"type" : "string",
11+
"description" : "The name of the index lifecycle policy"
12+
}
13+
},
14+
"params": {
15+
}
16+
},
17+
"body": null
18+
}
19+
}

0 commit comments

Comments
 (0)