Skip to content

Commit 65ef88f

Browse files
Implement dangling indices APIs (#4870) (#4880)
This commit implements the dangling indices APIs that can be used to list, import and delete dangling indices. Co-authored-by: Russ Cam <russ.cam@elastic.co>
1 parent af936de commit 65ef88f

22 files changed

+750
-5
lines changed

src/ApiGenerator/Configuration/CodeConfiguration.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ public static class CodeConfiguration
3535

3636
public static string[] IgnoredApisHighLevel { get; } =
3737
{
38-
"dangling_indices.list_dangling_indices.json", // TODO: implement
39-
"dangling_indices.import_dangling_index.json", // TODO: implement
40-
"dangling_indices.delete_dangling_index.json", // TODO: implement
4138
"indices.add_block.json", // TODO: implement
4239
"indices.resolve_index.json", // TODO: implement
4340
"security.clear_cached_privileges.json", // TODO: implement

src/ApiGenerator/Domain/Specification/UrlPart.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public string HighLevelTypeName
104104
case "type":
105105
return Type == "string" ? "Name" : "Names";
106106

107+
case "index_uuid":
108+
return "IndexUuid";
107109

108110
//This forces a compilation error post code generation as intended
109111
default: return Type + "_";
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System;
6+
using Elasticsearch.Net;
7+
8+
namespace Nest
9+
{
10+
public class IndexUuid : IUrlParameter, IEquatable<IndexUuid>
11+
{
12+
public string Value { get; }
13+
14+
public IndexUuid(string value) => Value = value ?? throw new ArgumentNullException(nameof(value));
15+
16+
public string GetString(IConnectionConfigurationValues settings) => Value;
17+
18+
public bool Equals(IndexUuid other)
19+
{
20+
if (ReferenceEquals(null, other)) return false;
21+
if (ReferenceEquals(this, other)) return true;
22+
23+
return Value == other.Value;
24+
}
25+
26+
public override bool Equals(object obj)
27+
{
28+
if (ReferenceEquals(null, obj)) return false;
29+
if (ReferenceEquals(this, obj)) return true;
30+
if (obj.GetType() != GetType()) return false;
31+
32+
return Equals((IndexUuid)obj);
33+
}
34+
35+
public override int GetHashCode() => (Value != null ? Value.GetHashCode() : 0);
36+
37+
public static bool operator ==(IndexUuid left, IndexUuid right) => Equals(left, right);
38+
39+
public static bool operator !=(IndexUuid left, IndexUuid right) => !Equals(left, right);
40+
41+
public static implicit operator IndexUuid(string value) => string.IsNullOrEmpty(value) ? null : new IndexUuid(value);
42+
}
43+
}

src/Nest/CommonAbstractions/Request/RouteValues.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ private RouteValues Route(string name, IUrlParameter routeValue, bool required =
5050
}
5151

5252
internal RouteValues Required(string route, IUrlParameter value) => Route(route, value);
53-
53+
5454
internal RouteValues Optional(string route, IUrlParameter value) => Route(route, value, false);
5555

5656
internal RouteValues Optional(string route, Metrics value) => Route(route, value, false);
5757

5858
internal RouteValues Optional(string route, IndexMetrics value) => Route(route, value, false);
5959

60-
internal TActual Get<TActual>(string route)
60+
internal TActual Get<TActual>(string route)
6161
{
6262
if (TryGetValue(route, out var actual) && actual != null)
6363
return (TActual)actual;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace Nest
6+
{
7+
[MapsApi("dangling_indices.delete_dangling_index.json")]
8+
public partial interface IDeleteDanglingIndexRequest
9+
{
10+
11+
}
12+
13+
public partial class DeleteDanglingIndexRequest : IDeleteDanglingIndexRequest
14+
{
15+
16+
}
17+
18+
public partial class DeleteDanglingIndexDescriptor : IDeleteDanglingIndexRequest
19+
{
20+
21+
}
22+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Runtime.Serialization;
6+
7+
namespace Nest
8+
{
9+
[DataContract]
10+
public class DeleteDanglingIndexResponse : AcknowledgedResponseBase
11+
{
12+
13+
}
14+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace Nest
6+
{
7+
[MapsApi("dangling_indices.import_dangling_index.json")]
8+
public partial interface IImportDanglingIndexRequest
9+
{
10+
11+
}
12+
13+
public partial class ImportDanglingIndexRequest : IImportDanglingIndexRequest
14+
{
15+
16+
}
17+
18+
public partial class ImportDanglingIndexDescriptor : IImportDanglingIndexRequest
19+
{
20+
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Runtime.Serialization;
6+
7+
namespace Nest
8+
{
9+
[DataContract]
10+
public class ImportDanglingIndexResponse : AcknowledgedResponseBase
11+
{
12+
}
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace Nest
6+
{
7+
[MapsApi("dangling_indices.list_dangling_indices.json")]
8+
public partial interface IListDanglingIndicesRequest
9+
{
10+
11+
}
12+
13+
public partial class ListDanglingIndicesRequest : IListDanglingIndicesRequest
14+
{
15+
16+
}
17+
18+
public partial class ListDanglingIndicesDescriptor : IListDanglingIndicesRequest
19+
{
20+
21+
}
22+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Runtime.Serialization;
8+
using Elasticsearch.Net;
9+
10+
namespace Nest
11+
{
12+
[DataContract]
13+
public class ListDanglingIndicesResponse : ResponseBase
14+
{
15+
[DataMember(Name = "dangling_indices")]
16+
public IReadOnlyCollection<AggregatedDanglingIndexInfo> DanglingIndices { get; internal set; } =
17+
EmptyReadOnly<AggregatedDanglingIndexInfo>.Collection;
18+
}
19+
20+
public class AggregatedDanglingIndexInfo
21+
{
22+
private DateTimeOffset? _creationDate;
23+
24+
[DataMember(Name = "index_name")]
25+
public string IndexName { get; internal set; }
26+
27+
[DataMember(Name = "index_uuid")]
28+
public string IndexUUID { get; internal set; }
29+
30+
[DataMember(Name = "creation_date_millis")]
31+
public long CreationDateInMilliseconds { get; internal set; }
32+
33+
[DataMember(Name = "creation_date")]
34+
public DateTimeOffset CreationDate
35+
{
36+
get
37+
{
38+
_creationDate ??= DateTimeOffset.FromUnixTimeMilliseconds(CreationDateInMilliseconds);
39+
return _creationDate.Value;
40+
}
41+
internal set => _creationDate = value;
42+
}
43+
44+
[DataMember(Name = "node_ids")]
45+
public IReadOnlyCollection<string> NodeIds { get; internal set; }
46+
}
47+
}

0 commit comments

Comments
 (0)