-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Delete Forecast API + integration tests
- Loading branch information
Showing
20 changed files
with
436 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
.../ApiGenerator/RestSpecification/XPack/MachineLearning/xpack.ml.delete_forecast.patch.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"xpack.ml.delete_forecast": { | ||
"url": { | ||
"path": "/_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id}", | ||
"paths": [ | ||
"/_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id}" | ||
], | ||
"parts": { | ||
"forecast_id": { | ||
"required": true, | ||
"description": "The ID of the forecast to delete, can be comma delimited list or `_all`" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/Nest/CommonAbstractions/Infer/ForecastIds/ForecastIds.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using Elasticsearch.Net; | ||
|
||
namespace Nest | ||
{ | ||
[DebuggerDisplay("{DebugDisplay,nq}")] | ||
public class ForecastIds : IUrlParameter, IEquatable<ForecastIds> | ||
{ | ||
public static ForecastIds All { get; } = new ForecastIds("_all"); | ||
|
||
private readonly List<string> _forecastIds; | ||
|
||
public ForecastIds(IEnumerable<string> forecastIds) => _forecastIds = forecastIds?.ToList(); | ||
|
||
public ForecastIds(string forecastIds) | ||
{ | ||
if (!forecastIds.IsNullOrEmptyCommaSeparatedList(out var ids)) | ||
_forecastIds = ids.ToList(); | ||
} | ||
|
||
private string DebugDisplay => ((IUrlParameter)this).GetString(null); | ||
|
||
public bool Equals(ForecastIds other) | ||
{ | ||
if (other == null) return false; | ||
if (_forecastIds == null && other._forecastIds == null) return true; | ||
if (_forecastIds == null || other._forecastIds == null) return false; | ||
|
||
return _forecastIds.Count == other._forecastIds.Count && | ||
_forecastIds.OrderBy(id => id).SequenceEqual(other._forecastIds.OrderBy(id => id)); | ||
} | ||
|
||
string IUrlParameter.GetString(IConnectionConfigurationValues settings) => string.Join(",", _forecastIds ?? Enumerable.Empty<string>()); | ||
|
||
public static implicit operator ForecastIds(string forecastIds) => | ||
forecastIds.IsNullOrEmptyCommaSeparatedList(out var arr) ? null : new ForecastIds(arr); | ||
|
||
public static implicit operator ForecastIds(string[] forecastIds) => | ||
forecastIds.IsEmpty() ? null : new ForecastIds(forecastIds); | ||
|
||
public override bool Equals(object obj) => obj is ForecastIds other && Equals(other); | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
var hc = 0; | ||
foreach (var id in _forecastIds.OrderBy(id => id)) | ||
hc = hc * 17 + id.GetHashCode(); | ||
return hc; | ||
} | ||
} | ||
|
||
public static bool operator ==(ForecastIds left, ForecastIds right) => Equals(left, right); | ||
|
||
public static bool operator !=(ForecastIds left, ForecastIds right) => !Equals(left, right); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Nest/XPack/MachineLearning/DeleteForecast/DeleteForecastRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Nest | ||
{ | ||
public partial interface IDeleteForecastRequest { } | ||
|
||
public partial class DeleteForecastRequest { } | ||
|
||
[DescriptorFor("XpackMlDeleteForecast")] | ||
public partial class DeleteForecastDescriptor { } | ||
} |
6 changes: 6 additions & 0 deletions
6
src/Nest/XPack/MachineLearning/DeleteForecast/DeleteForecastResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Nest | ||
{ | ||
public interface IDeleteForecastResponse : IAcknowledgedResponse { } | ||
|
||
public class DeleteForecastResponse : AcknowledgedResponseBase, IDeleteForecastResponse { } | ||
} |
56 changes: 56 additions & 0 deletions
56
src/Nest/XPack/MachineLearning/DeleteForecast/ElasticClient-DeleteForecast.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Elasticsearch.Net; | ||
|
||
namespace Nest | ||
{ | ||
public partial interface IElasticClient | ||
{ | ||
/// <summary> | ||
/// Deletes forecasts from a machine learning job. | ||
/// </summary> | ||
IDeleteForecastResponse DeleteForecast(Id jobId, ForecastIds forecastId, Func<DeleteForecastDescriptor, IDeleteForecastRequest> selector = null); | ||
|
||
/// <inheritdoc cref="DeleteForecast(Nest.Id,Nest.ForecastIds,System.Func{Nest.DeleteForecastDescriptor,Nest.IDeleteForecastRequest})" /> | ||
IDeleteForecastResponse DeleteForecast(IDeleteForecastRequest request); | ||
|
||
/// <inheritdoc cref="DeleteForecast(Nest.Id,Nest.ForecastIds,System.Func{Nest.DeleteForecastDescriptor,Nest.IDeleteForecastRequest})" /> | ||
Task<IDeleteForecastResponse> DeleteForecastAsync(Id jobId, ForecastIds forecastId, Func<DeleteForecastDescriptor, IDeleteForecastRequest> selector = null, | ||
CancellationToken cancellationToken = default(CancellationToken) | ||
); | ||
|
||
/// <inheritdoc cref="DeleteForecast(Nest.Id,Nest.ForecastIds,System.Func{Nest.DeleteForecastDescriptor,Nest.IDeleteForecastRequest})" /> | ||
Task<IDeleteForecastResponse> DeleteForecastAsync(IDeleteForecastRequest request, | ||
CancellationToken cancellationToken = default(CancellationToken) | ||
); | ||
} | ||
|
||
public partial class ElasticClient | ||
{ | ||
/// <inheritdoc cref="DeleteForecast(Nest.Id,Nest.ForecastIds,System.Func{Nest.DeleteForecastDescriptor,Nest.IDeleteForecastRequest})" /> | ||
public IDeleteForecastResponse DeleteForecast(Id jobId, ForecastIds forecastId, Func<DeleteForecastDescriptor, IDeleteForecastRequest> selector = null) => | ||
DeleteForecast(selector.InvokeOrDefault(new DeleteForecastDescriptor(jobId, forecastId))); | ||
|
||
/// <inheritdoc cref="DeleteForecast(Nest.Id,Nest.ForecastIds,System.Func{Nest.DeleteForecastDescriptor,Nest.IDeleteForecastRequest})" /> | ||
public IDeleteForecastResponse DeleteForecast(IDeleteForecastRequest request) => | ||
Dispatcher.Dispatch<IDeleteForecastRequest, DeleteForecastRequestParameters, DeleteForecastResponse>( | ||
request, | ||
(p, d) => LowLevelDispatch.XpackMlDeleteForecastDispatch<DeleteForecastResponse>(p) | ||
); | ||
|
||
/// <inheritdoc cref="DeleteForecast(Nest.Id,Nest.ForecastIds,System.Func{Nest.DeleteForecastDescriptor,Nest.IDeleteForecastRequest})" /> | ||
public Task<IDeleteForecastResponse> DeleteForecastAsync(Id jobId, ForecastIds forecastId, | ||
Func<DeleteForecastDescriptor, IDeleteForecastRequest> selector = null, CancellationToken cancellationToken = default(CancellationToken)) => | ||
DeleteForecastAsync(selector.InvokeOrDefault(new DeleteForecastDescriptor(jobId, forecastId)), cancellationToken); | ||
|
||
/// <inheritdoc cref="DeleteForecast(Nest.Id,Nest.ForecastIds,System.Func{Nest.DeleteForecastDescriptor,Nest.IDeleteForecastRequest})" /> | ||
public Task<IDeleteForecastResponse> DeleteForecastAsync(IDeleteForecastRequest request, | ||
CancellationToken cancellationToken = default(CancellationToken)) => | ||
Dispatcher.DispatchAsync<IDeleteForecastRequest, DeleteForecastRequestParameters, DeleteForecastResponse, IDeleteForecastResponse>( | ||
request, | ||
cancellationToken, | ||
(p, d, c) => LowLevelDispatch.XpackMlDeleteForecastDispatchAsync<DeleteForecastResponse>(p, c) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections.Generic; | ||
using Elastic.Xunit.XunitPlumbing; | ||
using FluentAssertions; | ||
using Nest; | ||
|
||
namespace Tests.CommonOptions | ||
{ | ||
public class ForecastIdTests | ||
{ | ||
[U] public void Equal() | ||
{ | ||
var forecastIds1 = new ForecastIds("1,2,3"); | ||
var forecastIds2 = new ForecastIds(new [] { "3", "2", "1" }); | ||
|
||
forecastIds1.Should().Be(forecastIds2); | ||
forecastIds1.GetHashCode().Should().Be(forecastIds2.GetHashCode()); | ||
} | ||
|
||
[U] public void NotEqual() | ||
{ | ||
var forecastIds1 = new ForecastIds("1,2,3,3"); | ||
var forecastIds2 = new ForecastIds(new [] { "3", "2", "1" }); | ||
|
||
forecastIds1.Should().NotBe(forecastIds2); | ||
forecastIds1.GetHashCode().Should().NotBe(forecastIds2.GetHashCode()); | ||
} | ||
} | ||
} |
Oops, something went wrong.