Skip to content

Commit 426b359

Browse files
committed
Merge remote-tracking branch 'elastic/master' into global-checkpoint-polling
* elastic/master: SQL: Return correct catalog separator in JDBC (elastic#33670) [CCR] Add validation for max_retry_delay (elastic#33648) [CCR] Add monitoring mapping verification test (elastic#33662) CORE: Disable Setting Type Validation (elastic#33660) (elastic#33669) Revert "Use serializable exception in GCP listeners (elastic#33657)" Adding index refresh (elastic#33647) [DOCS] Moves securing-communications to docs (elastic#33640) [HLRC][ML] Add ML delete datafeed API to HLRC (elastic#33667) Mute testRecoveryWithConcurrentIndexing TEST: decrease logging level in the flush test DOC: Add SQL section on client applications Fix race in global checkpoint listeners test Use serializable exception in GCP listeners (elastic#33657)
2 parents 2890693 + 60ab4f9 commit 426b359

File tree

68 files changed

+756
-127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+756
-127
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/MLRequestConverters.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.lucene.util.BytesRef;
2929
import org.elasticsearch.client.RequestConverters.EndpointBuilder;
3030
import org.elasticsearch.client.ml.CloseJobRequest;
31+
import org.elasticsearch.client.ml.DeleteDatafeedRequest;
3132
import org.elasticsearch.client.ml.DeleteForecastRequest;
3233
import org.elasticsearch.client.ml.DeleteJobRequest;
3334
import org.elasticsearch.client.ml.FlushJobRequest;
@@ -195,6 +196,19 @@ static Request putDatafeed(PutDatafeedRequest putDatafeedRequest) throws IOExcep
195196
return request;
196197
}
197198

199+
static Request deleteDatafeed(DeleteDatafeedRequest deleteDatafeedRequest) {
200+
String endpoint = new EndpointBuilder()
201+
.addPathPartAsIs("_xpack")
202+
.addPathPartAsIs("ml")
203+
.addPathPartAsIs("datafeeds")
204+
.addPathPart(deleteDatafeedRequest.getDatafeedId())
205+
.build();
206+
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
207+
RequestConverters.Params params = new RequestConverters.Params(request);
208+
params.putParam("force", Boolean.toString(deleteDatafeedRequest.isForce()));
209+
return request;
210+
}
211+
198212
static Request deleteForecast(DeleteForecastRequest deleteForecastRequest) throws IOException {
199213
String endpoint = new EndpointBuilder()
200214
.addPathPartAsIs("_xpack")

client/rest-high-level/src/main/java/org/elasticsearch/client/MachineLearningClient.java

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import org.elasticsearch.action.support.master.AcknowledgedResponse;
2323
import org.elasticsearch.client.ml.CloseJobRequest;
2424
import org.elasticsearch.client.ml.CloseJobResponse;
25+
import org.elasticsearch.client.ml.DeleteDatafeedRequest;
2526
import org.elasticsearch.client.ml.DeleteForecastRequest;
2627
import org.elasticsearch.client.ml.DeleteJobRequest;
27-
import org.elasticsearch.client.ml.DeleteJobResponse;
2828
import org.elasticsearch.client.ml.FlushJobRequest;
2929
import org.elasticsearch.client.ml.FlushJobResponse;
3030
import org.elasticsearch.client.ml.ForecastJobRequest;
@@ -204,11 +204,11 @@ public void getJobStatsAsync(GetJobStatsRequest request, RequestOptions options,
204204
* @return action acknowledgement
205205
* @throws IOException when there is a serialization issue sending the request or receiving the response
206206
*/
207-
public DeleteJobResponse deleteJob(DeleteJobRequest request, RequestOptions options) throws IOException {
207+
public AcknowledgedResponse deleteJob(DeleteJobRequest request, RequestOptions options) throws IOException {
208208
return restHighLevelClient.performRequestAndParseEntity(request,
209209
MLRequestConverters::deleteJob,
210210
options,
211-
DeleteJobResponse::fromXContent,
211+
AcknowledgedResponse::fromXContent,
212212
Collections.emptySet());
213213
}
214214

@@ -222,11 +222,11 @@ public DeleteJobResponse deleteJob(DeleteJobRequest request, RequestOptions opti
222222
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
223223
* @param listener Listener to be notified upon request completion
224224
*/
225-
public void deleteJobAsync(DeleteJobRequest request, RequestOptions options, ActionListener<DeleteJobResponse> listener) {
225+
public void deleteJobAsync(DeleteJobRequest request, RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
226226
restHighLevelClient.performRequestAsyncAndParseEntity(request,
227227
MLRequestConverters::deleteJob,
228228
options,
229-
DeleteJobResponse::fromXContent,
229+
AcknowledgedResponse::fromXContent,
230230
listener,
231231
Collections.emptySet());
232232
}
@@ -492,6 +492,46 @@ public void putDatafeedAsync(PutDatafeedRequest request, RequestOptions options,
492492
Collections.emptySet());
493493
}
494494

495+
/**
496+
* Deletes the given Machine Learning Datafeed
497+
* <p>
498+
* For additional info
499+
* see <a href="http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-datafeed.html">
500+
* ML Delete Datafeed documentation</a>
501+
* </p>
502+
* @param request The request to delete the datafeed
503+
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
504+
* @return action acknowledgement
505+
* @throws IOException when there is a serialization issue sending the request or receiving the response
506+
*/
507+
public AcknowledgedResponse deleteDatafeed(DeleteDatafeedRequest request, RequestOptions options) throws IOException {
508+
return restHighLevelClient.performRequestAndParseEntity(request,
509+
MLRequestConverters::deleteDatafeed,
510+
options,
511+
AcknowledgedResponse::fromXContent,
512+
Collections.emptySet());
513+
}
514+
515+
/**
516+
* Deletes the given Machine Learning Datafeed asynchronously and notifies the listener on completion
517+
* <p>
518+
* For additional info
519+
* see <a href="http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-datafeed.html">
520+
* ML Delete Datafeed documentation</a>
521+
* </p>
522+
* @param request The request to delete the datafeed
523+
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
524+
* @param listener Listener to be notified upon request completion
525+
*/
526+
public void deleteDatafeedAsync(DeleteDatafeedRequest request, RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
527+
restHighLevelClient.performRequestAsyncAndParseEntity(request,
528+
MLRequestConverters::deleteDatafeed,
529+
options,
530+
AcknowledgedResponse::fromXContent,
531+
listener,
532+
Collections.emptySet());
533+
}
534+
495535
/**
496536
* Deletes Machine Learning Job Forecasts
497537
*
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.client.ml;
20+
21+
import org.elasticsearch.action.ActionRequest;
22+
import org.elasticsearch.action.ActionRequestValidationException;
23+
24+
import java.util.Objects;
25+
26+
/**
27+
* Request to delete a Machine Learning Datafeed via its ID
28+
*/
29+
public class DeleteDatafeedRequest extends ActionRequest {
30+
31+
private String datafeedId;
32+
private boolean force;
33+
34+
public DeleteDatafeedRequest(String datafeedId) {
35+
this.datafeedId = Objects.requireNonNull(datafeedId, "[datafeed_id] must not be null");
36+
}
37+
38+
public String getDatafeedId() {
39+
return datafeedId;
40+
}
41+
42+
public boolean isForce() {
43+
return force;
44+
}
45+
46+
/**
47+
* Used to forcefully delete a started datafeed.
48+
* This method is quicker than stopping and deleting the datafeed.
49+
*
50+
* @param force When {@code true} forcefully delete a started datafeed. Defaults to {@code false}
51+
*/
52+
public void setForce(boolean force) {
53+
this.force = force;
54+
}
55+
56+
@Override
57+
public ActionRequestValidationException validate() {
58+
return null;
59+
}
60+
61+
@Override
62+
public int hashCode() {
63+
return Objects.hash(datafeedId, force);
64+
}
65+
66+
@Override
67+
public boolean equals(Object obj) {
68+
if (this == obj) {
69+
return true;
70+
}
71+
72+
if (obj == null || obj.getClass() != getClass()) {
73+
return false;
74+
}
75+
76+
DeleteDatafeedRequest other = (DeleteDatafeedRequest) obj;
77+
return Objects.equals(datafeedId, other.datafeedId) && Objects.equals(force, other.force);
78+
}
79+
80+
}

client/rest-high-level/src/main/java/org/elasticsearch/client/ml/DeleteJobResponse.java

Lines changed: 0 additions & 63 deletions
This file was deleted.

client/rest-high-level/src/test/java/org/elasticsearch/client/MLRequestConvertersTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.http.client.methods.HttpPost;
2525
import org.apache.http.client.methods.HttpPut;
2626
import org.elasticsearch.client.ml.CloseJobRequest;
27+
import org.elasticsearch.client.ml.DeleteDatafeedRequest;
2728
import org.elasticsearch.client.ml.DeleteForecastRequest;
2829
import org.elasticsearch.client.ml.DeleteJobRequest;
2930
import org.elasticsearch.client.ml.FlushJobRequest;
@@ -223,6 +224,20 @@ public void testPutDatafeed() throws IOException {
223224
}
224225
}
225226

227+
public void testDeleteDatafeed() {
228+
String datafeedId = randomAlphaOfLength(10);
229+
DeleteDatafeedRequest deleteDatafeedRequest = new DeleteDatafeedRequest(datafeedId);
230+
231+
Request request = MLRequestConverters.deleteDatafeed(deleteDatafeedRequest);
232+
assertEquals(HttpDelete.METHOD_NAME, request.getMethod());
233+
assertEquals("/_xpack/ml/datafeeds/" + datafeedId, request.getEndpoint());
234+
assertEquals(Boolean.toString(false), request.getParameters().get("force"));
235+
236+
deleteDatafeedRequest.setForce(true);
237+
request = MLRequestConverters.deleteDatafeed(deleteDatafeedRequest);
238+
assertEquals(Boolean.toString(true), request.getParameters().get("force"));
239+
}
240+
226241
public void testDeleteForecast() throws Exception {
227242
String jobId = randomAlphaOfLength(10);
228243
DeleteForecastRequest deleteForecastRequest = new DeleteForecastRequest(jobId);

client/rest-high-level/src/test/java/org/elasticsearch/client/MachineLearningIT.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import org.elasticsearch.action.support.master.AcknowledgedResponse;
2626
import org.elasticsearch.client.ml.CloseJobRequest;
2727
import org.elasticsearch.client.ml.CloseJobResponse;
28+
import org.elasticsearch.client.ml.DeleteDatafeedRequest;
2829
import org.elasticsearch.client.ml.DeleteForecastRequest;
2930
import org.elasticsearch.client.ml.DeleteJobRequest;
30-
import org.elasticsearch.client.ml.DeleteJobResponse;
3131
import org.elasticsearch.client.ml.FlushJobRequest;
3232
import org.elasticsearch.client.ml.FlushJobResponse;
3333
import org.elasticsearch.client.ml.ForecastJobRequest;
@@ -129,7 +129,7 @@ public void testDeleteJob() throws Exception {
129129
MachineLearningClient machineLearningClient = highLevelClient().machineLearning();
130130
machineLearningClient.putJob(new PutJobRequest(job), RequestOptions.DEFAULT);
131131

132-
DeleteJobResponse response = execute(new DeleteJobRequest(jobId),
132+
AcknowledgedResponse response = execute(new DeleteJobRequest(jobId),
133133
machineLearningClient::deleteJob,
134134
machineLearningClient::deleteJobAsync);
135135

@@ -312,6 +312,22 @@ public void testPutDatafeed() throws Exception {
312312
assertThat(createdDatafeed.getIndices(), equalTo(datafeedConfig.getIndices()));
313313
}
314314

315+
public void testDeleteDatafeed() throws Exception {
316+
String jobId = randomValidJobId();
317+
Job job = buildJob(jobId);
318+
MachineLearningClient machineLearningClient = highLevelClient().machineLearning();
319+
machineLearningClient.putJob(new PutJobRequest(job), RequestOptions.DEFAULT);
320+
321+
String datafeedId = "datafeed-" + jobId;
322+
DatafeedConfig datafeedConfig = DatafeedConfig.builder(datafeedId, jobId).setIndices("some_data_index").build();
323+
execute(new PutDatafeedRequest(datafeedConfig), machineLearningClient::putDatafeed, machineLearningClient::putDatafeedAsync);
324+
325+
AcknowledgedResponse response = execute(new DeleteDatafeedRequest(datafeedId), machineLearningClient::deleteDatafeed,
326+
machineLearningClient::deleteDatafeedAsync);
327+
328+
assertTrue(response.isAcknowledged());
329+
}
330+
315331
public void testDeleteForecast() throws Exception {
316332
String jobId = "test-delete-forecast";
317333

0 commit comments

Comments
 (0)