Skip to content

Commit 7ad67ec

Browse files
Stuart Camrusscam
authored andcommitted
Delete forecast API (#3591)
Implement Delete Forecast API + integration tests
1 parent 6181f30 commit 7ad67ec

File tree

20 files changed

+436
-21
lines changed

20 files changed

+436
-21
lines changed

src/CodeGeneration/ApiGenerator/ApiGenerator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class ApiGenerator
2828
"rank_eval.json",
2929

3030
// these API's are new and need to be mapped
31-
"xpack.ml.delete_forecast.json",
3231
"xpack.ml.find_file_structure.json",
3332
};
3433

src/CodeGeneration/ApiGenerator/Domain/ApiUrlPart.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public string ClrTypeName
5050
case "filter_id":
5151
case "id": return Type == "string" ? "Id" : "Ids";
5252
case "category_id": return "CategoryId";
53+
case "forecast_id": return "ForecastIds";
5354
case "nodes":
5455
case "node_id": return Type == "string" ? "NodeId" : "NodeIds";
5556
case "scroll_id": return Type == "string" ? "ScrollId" : "ScrollIds";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"xpack.ml.delete_forecast": {
3+
"url": {
4+
"path": "/_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id}",
5+
"paths": [
6+
"/_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id}"
7+
],
8+
"parts": {
9+
"forecast_id": {
10+
"required": true,
11+
"description": "The ID of the forecast to delete, can be comma delimited list or `_all`"
12+
}
13+
}
14+
}
15+
}
16+
}

src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,6 +2395,15 @@ public partial class DeleteExpiredDataRequestParameters : RequestParameters<Dele
23952395
{
23962396
public override HttpMethod DefaultHttpMethod => HttpMethod.DELETE;
23972397
}
2398+
///<summary>Request options for XpackMlDeleteForecast<pre>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html</pre></summary>
2399+
public partial class DeleteForecastRequestParameters : RequestParameters<DeleteForecastRequestParameters>
2400+
{
2401+
public override HttpMethod DefaultHttpMethod => HttpMethod.DELETE;
2402+
///<summary>Whether to ignore if `_all` matches no forecasts</summary>
2403+
public bool? AllowNoForecasts { get => Q<bool?>("allow_no_forecasts"); set => Q("allow_no_forecasts", value); }
2404+
///<summary>Controls the time to wait until the forecast(s) are deleted. Default to 30 seconds</summary>
2405+
public TimeSpan Timeout { get => Q<TimeSpan>("timeout"); set => Q("timeout", value); }
2406+
}
23982407
///<summary>Request options for XpackMlDeleteJob<pre>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html</pre></summary>
23992408
public partial class DeleteJobRequestParameters : RequestParameters<DeleteJobRequestParameters>
24002409
{

src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,6 +3236,18 @@ public TResponse XpackMlDeleteExpiredData<TResponse>(DeleteExpiredDataRequestPar
32363236
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
32373237
public Task<TResponse> XpackMlDeleteExpiredDataAsync<TResponse>(DeleteExpiredDataRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken))
32383238
where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync<TResponse>(DELETE, Url($"_xpack/ml/_delete_expired_data"), ctx, null, _params(requestParameters));
3239+
///<summary>DELETE on /_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html</para></summary>
3240+
///<param name="job_id">The ID of the job from which to delete forecasts</param>
3241+
///<param name="forecast_id">The ID of the forecast to delete, can be comma delimited list or `_all`</param>
3242+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
3243+
public TResponse XpackMlDeleteForecast<TResponse>(string job_id, string forecast_id, DeleteForecastRequestParameters requestParameters = null)
3244+
where TResponse : class, IElasticsearchResponse, new() => this.DoRequest<TResponse>(DELETE, Url($"_xpack/ml/anomaly_detectors/{job_id.NotNull("job_id")}/_forecast/{forecast_id.NotNull("forecast_id")}"), null, _params(requestParameters));
3245+
///<summary>DELETE on /_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html</para></summary>
3246+
///<param name="job_id">The ID of the job from which to delete forecasts</param>
3247+
///<param name="forecast_id">The ID of the forecast to delete, can be comma delimited list or `_all`</param>
3248+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
3249+
public Task<TResponse> XpackMlDeleteForecastAsync<TResponse>(string job_id, string forecast_id, DeleteForecastRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken))
3250+
where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync<TResponse>(DELETE, Url($"_xpack/ml/anomaly_detectors/{job_id.NotNull("job_id")}/_forecast/{forecast_id.NotNull("forecast_id")}"), ctx, null, _params(requestParameters));
32393251
///<summary>DELETE on /_xpack/ml/anomaly_detectors/{job_id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html</para></summary>
32403252
///<param name="job_id">The ID of the job to delete</param>
32413253
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>

src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,6 +2620,16 @@ public partial interface IElasticLowLevelClient
26202620
///<summary>DELETE on /_xpack/ml/_delete_expired_data <para></para></summary>
26212621
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
26222622
Task<TResponse> XpackMlDeleteExpiredDataAsync<TResponse>(DeleteExpiredDataRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new();
2623+
///<summary>DELETE on /_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html</para></summary>
2624+
///<param name="job_id">The ID of the job from which to delete forecasts</param>
2625+
///<param name="forecast_id">The ID of the forecast to delete, can be comma delimited list or `_all`</param>
2626+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2627+
TResponse XpackMlDeleteForecast<TResponse>(string job_id, string forecast_id, DeleteForecastRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new();
2628+
///<summary>DELETE on /_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html</para></summary>
2629+
///<param name="job_id">The ID of the job from which to delete forecasts</param>
2630+
///<param name="forecast_id">The ID of the forecast to delete, can be comma delimited list or `_all`</param>
2631+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2632+
Task<TResponse> XpackMlDeleteForecastAsync<TResponse>(string job_id, string forecast_id, DeleteForecastRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new();
26232633
///<summary>DELETE on /_xpack/ml/anomaly_detectors/{job_id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html</para></summary>
26242634
///<param name="job_id">The ID of the job to delete</param>
26252635
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using Elasticsearch.Net;
6+
7+
namespace Nest
8+
{
9+
[DebuggerDisplay("{DebugDisplay,nq}")]
10+
public class ForecastIds : IUrlParameter, IEquatable<ForecastIds>
11+
{
12+
public static ForecastIds All { get; } = new ForecastIds("_all");
13+
14+
private readonly List<string> _forecastIds;
15+
16+
public ForecastIds(IEnumerable<string> forecastIds) => _forecastIds = forecastIds?.ToList();
17+
18+
public ForecastIds(string forecastIds)
19+
{
20+
if (!forecastIds.IsNullOrEmptyCommaSeparatedList(out var ids))
21+
_forecastIds = ids.ToList();
22+
}
23+
24+
private string DebugDisplay => ((IUrlParameter)this).GetString(null);
25+
26+
public bool Equals(ForecastIds other)
27+
{
28+
if (other == null) return false;
29+
if (_forecastIds == null && other._forecastIds == null) return true;
30+
if (_forecastIds == null || other._forecastIds == null) return false;
31+
32+
return _forecastIds.Count == other._forecastIds.Count &&
33+
_forecastIds.OrderBy(id => id).SequenceEqual(other._forecastIds.OrderBy(id => id));
34+
}
35+
36+
string IUrlParameter.GetString(IConnectionConfigurationValues settings) => string.Join(",", _forecastIds ?? Enumerable.Empty<string>());
37+
38+
public static implicit operator ForecastIds(string forecastIds) =>
39+
forecastIds.IsNullOrEmptyCommaSeparatedList(out var arr) ? null : new ForecastIds(arr);
40+
41+
public static implicit operator ForecastIds(string[] forecastIds) =>
42+
forecastIds.IsEmpty() ? null : new ForecastIds(forecastIds);
43+
44+
public override bool Equals(object obj) => obj is ForecastIds other && Equals(other);
45+
46+
public override int GetHashCode()
47+
{
48+
unchecked
49+
{
50+
var hc = 0;
51+
foreach (var id in _forecastIds.OrderBy(id => id))
52+
hc = hc * 17 + id.GetHashCode();
53+
return hc;
54+
}
55+
}
56+
57+
public static bool operator ==(ForecastIds left, ForecastIds right) => Equals(left, right);
58+
59+
public static bool operator !=(ForecastIds left, ForecastIds right) => !Equals(left, right);
60+
}
61+
}

src/Nest/CommonAbstractions/Request/RouteValues.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class RouteValues
1010
public string ActionId => GetResolved("action_id");
1111
public string Alias => GetResolved("alias");
1212
public string CategoryId => GetResolved("category_id");
13+
public string ForecastId => GetResolved("forecast_id");
1314
public string Context => GetResolved("context");
1415
public string DatafeedId => GetResolved("datafeed_id");
1516
public string Feature => GetResolved("feature");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Nest
2+
{
3+
public partial interface IDeleteForecastRequest { }
4+
5+
public partial class DeleteForecastRequest { }
6+
7+
[DescriptorFor("XpackMlDeleteForecast")]
8+
public partial class DeleteForecastDescriptor { }
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Nest
2+
{
3+
public interface IDeleteForecastResponse : IAcknowledgedResponse { }
4+
5+
public class DeleteForecastResponse : AcknowledgedResponseBase, IDeleteForecastResponse { }
6+
}

0 commit comments

Comments
 (0)