Skip to content

Commit 6645893

Browse files
Stuart Camrusscam
authored andcommitted
Delete forecast API (#3591)
Implement Delete Forecast API + integration tests (cherry picked from commit e1a2a13)
1 parent 60021d9 commit 6645893

File tree

20 files changed

+447
-21
lines changed

20 files changed

+447
-21
lines changed

src/CodeGeneration/ApiGenerator/CodeConfiguration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public static class CodeConfiguration
3333
"rank_eval.json",
3434

3535
// these API's are new and need to be mapped
36-
"ml.delete_forecast.json",
3736
"ml.set_upgrade_mode.json",
3837
"ml.find_file_structure.json",
3938
"monitoring.bulk.json",

src/CodeGeneration/ApiGenerator/Domain/ApiUrlPart.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public string ClrTypeName
5151
case "filter_id":
5252
case "id": return Type == "string" ? "Id" : "Ids";
5353
case "category_id": return "CategoryId";
54+
case "forecast_id": return "ForecastIds";
5455
case "nodes":
5556
case "node_id": return Type == "string" ? "NodeId" : "NodeIds";
5657
case "field":
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"ml.delete_forecast": {
3+
"url": {
4+
"path": "/_ml/anomaly_detectors/{job_id}/_forecast/{forecast_id}",
5+
"paths": [
6+
"/_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 class DeleteExpiredDataRequestParameters : RequestParameters<DeleteExpire
23952395
{
23962396
public override HttpMethod DefaultHttpMethod => HttpMethod.DELETE;
23972397
}
2398+
///<summary>Request options for MlDeleteForecast<pre>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html</pre></summary>
2399+
public 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 MlDeleteJob<pre>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html</pre></summary>
23992408
public 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
@@ -2844,6 +2844,18 @@ public TResponse MlDeleteExpiredData<TResponse>(DeleteExpiredDataRequestParamete
28442844
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
28452845
public Task<TResponse> MlDeleteExpiredDataAsync<TResponse>(DeleteExpiredDataRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken))
28462846
where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync<TResponse>(DELETE, Url($"_ml/_delete_expired_data"), ctx, null, _params(requestParameters));
2847+
///<summary>DELETE on /_ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html</para></summary>
2848+
///<param name="job_id">The ID of the job from which to delete forecasts</param>
2849+
///<param name="forecast_id">The ID of the forecast to delete, can be comma delimited list or `_all`</param>
2850+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2851+
public TResponse MlDeleteForecast<TResponse>(string job_id, string forecast_id, DeleteForecastRequestParameters requestParameters = null)
2852+
where TResponse : class, IElasticsearchResponse, new() => this.DoRequest<TResponse>(DELETE, Url($"_ml/anomaly_detectors/{job_id.NotNull("job_id")}/_forecast/{forecast_id.NotNull("forecast_id")}"), null, _params(requestParameters));
2853+
///<summary>DELETE on /_ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html</para></summary>
2854+
///<param name="job_id">The ID of the job from which to delete forecasts</param>
2855+
///<param name="forecast_id">The ID of the forecast to delete, can be comma delimited list or `_all`</param>
2856+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2857+
public Task<TResponse> MlDeleteForecastAsync<TResponse>(string job_id, string forecast_id, DeleteForecastRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken))
2858+
where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync<TResponse>(DELETE, Url($"_ml/anomaly_detectors/{job_id.NotNull("job_id")}/_forecast/{forecast_id.NotNull("forecast_id")}"), ctx, null, _params(requestParameters));
28472859
///<summary>DELETE on /_ml/anomaly_detectors/{job_id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html</para></summary>
28482860
///<param name="job_id">The ID of the job to delete</param>
28492861
///<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
@@ -2282,6 +2282,16 @@ public partial interface IElasticLowLevelClient
22822282
///<summary>DELETE on /_ml/_delete_expired_data <para>TODO</para></summary>
22832283
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
22842284
Task<TResponse> MlDeleteExpiredDataAsync<TResponse>(DeleteExpiredDataRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new();
2285+
///<summary>DELETE on /_ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html</para></summary>
2286+
///<param name="job_id">The ID of the job from which to delete forecasts</param>
2287+
///<param name="forecast_id">The ID of the forecast to delete, can be comma delimited list or `_all`</param>
2288+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2289+
TResponse MlDeleteForecast<TResponse>(string job_id, string forecast_id, DeleteForecastRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new();
2290+
///<summary>DELETE on /_ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html</para></summary>
2291+
///<param name="job_id">The ID of the job from which to delete forecasts</param>
2292+
///<param name="forecast_id">The ID of the forecast to delete, can be comma delimited list or `_all`</param>
2293+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2294+
Task<TResponse> MlDeleteForecastAsync<TResponse>(string job_id, string forecast_id, DeleteForecastRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new();
22852295
///<summary>DELETE on /_ml/anomaly_detectors/{job_id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html</para></summary>
22862296
///<param name="job_id">The ID of the job to delete</param>
22872297
///<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+
[MapsApi("ml.delete_forecast")]
4+
public partial interface IDeleteForecastRequest { }
5+
6+
public partial class DeleteForecastRequest { }
7+
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)