Skip to content

Commit

Permalink
Merge remote-tracking branch 'elastic/master' into global-checkpoint-…
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
jasontedor committed Sep 13, 2018
2 parents 2890693 + 60ab4f9 commit 426b359
Show file tree
Hide file tree
Showing 68 changed files with 756 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.client.RequestConverters.EndpointBuilder;
import org.elasticsearch.client.ml.CloseJobRequest;
import org.elasticsearch.client.ml.DeleteDatafeedRequest;
import org.elasticsearch.client.ml.DeleteForecastRequest;
import org.elasticsearch.client.ml.DeleteJobRequest;
import org.elasticsearch.client.ml.FlushJobRequest;
Expand Down Expand Up @@ -195,6 +196,19 @@ static Request putDatafeed(PutDatafeedRequest putDatafeedRequest) throws IOExcep
return request;
}

static Request deleteDatafeed(DeleteDatafeedRequest deleteDatafeedRequest) {
String endpoint = new EndpointBuilder()
.addPathPartAsIs("_xpack")
.addPathPartAsIs("ml")
.addPathPartAsIs("datafeeds")
.addPathPart(deleteDatafeedRequest.getDatafeedId())
.build();
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params(request);
params.putParam("force", Boolean.toString(deleteDatafeedRequest.isForce()));
return request;
}

static Request deleteForecast(DeleteForecastRequest deleteForecastRequest) throws IOException {
String endpoint = new EndpointBuilder()
.addPathPartAsIs("_xpack")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.ml.CloseJobRequest;
import org.elasticsearch.client.ml.CloseJobResponse;
import org.elasticsearch.client.ml.DeleteDatafeedRequest;
import org.elasticsearch.client.ml.DeleteForecastRequest;
import org.elasticsearch.client.ml.DeleteJobRequest;
import org.elasticsearch.client.ml.DeleteJobResponse;
import org.elasticsearch.client.ml.FlushJobRequest;
import org.elasticsearch.client.ml.FlushJobResponse;
import org.elasticsearch.client.ml.ForecastJobRequest;
Expand Down Expand Up @@ -204,11 +204,11 @@ public void getJobStatsAsync(GetJobStatsRequest request, RequestOptions options,
* @return action acknowledgement
* @throws IOException when there is a serialization issue sending the request or receiving the response
*/
public DeleteJobResponse deleteJob(DeleteJobRequest request, RequestOptions options) throws IOException {
public AcknowledgedResponse deleteJob(DeleteJobRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request,
MLRequestConverters::deleteJob,
options,
DeleteJobResponse::fromXContent,
AcknowledgedResponse::fromXContent,
Collections.emptySet());
}

Expand All @@ -222,11 +222,11 @@ public DeleteJobResponse deleteJob(DeleteJobRequest request, RequestOptions opti
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener Listener to be notified upon request completion
*/
public void deleteJobAsync(DeleteJobRequest request, RequestOptions options, ActionListener<DeleteJobResponse> listener) {
public void deleteJobAsync(DeleteJobRequest request, RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request,
MLRequestConverters::deleteJob,
options,
DeleteJobResponse::fromXContent,
AcknowledgedResponse::fromXContent,
listener,
Collections.emptySet());
}
Expand Down Expand Up @@ -492,6 +492,46 @@ public void putDatafeedAsync(PutDatafeedRequest request, RequestOptions options,
Collections.emptySet());
}

/**
* Deletes the given Machine Learning Datafeed
* <p>
* For additional info
* see <a href="http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-datafeed.html">
* ML Delete Datafeed documentation</a>
* </p>
* @param request The request to delete the datafeed
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return action acknowledgement
* @throws IOException when there is a serialization issue sending the request or receiving the response
*/
public AcknowledgedResponse deleteDatafeed(DeleteDatafeedRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request,
MLRequestConverters::deleteDatafeed,
options,
AcknowledgedResponse::fromXContent,
Collections.emptySet());
}

/**
* Deletes the given Machine Learning Datafeed asynchronously and notifies the listener on completion
* <p>
* For additional info
* see <a href="http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-datafeed.html">
* ML Delete Datafeed documentation</a>
* </p>
* @param request The request to delete the datafeed
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener Listener to be notified upon request completion
*/
public void deleteDatafeedAsync(DeleteDatafeedRequest request, RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request,
MLRequestConverters::deleteDatafeed,
options,
AcknowledgedResponse::fromXContent,
listener,
Collections.emptySet());
}

/**
* Deletes Machine Learning Job Forecasts
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.ml;

import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;

import java.util.Objects;

/**
* Request to delete a Machine Learning Datafeed via its ID
*/
public class DeleteDatafeedRequest extends ActionRequest {

private String datafeedId;
private boolean force;

public DeleteDatafeedRequest(String datafeedId) {
this.datafeedId = Objects.requireNonNull(datafeedId, "[datafeed_id] must not be null");
}

public String getDatafeedId() {
return datafeedId;
}

public boolean isForce() {
return force;
}

/**
* Used to forcefully delete a started datafeed.
* This method is quicker than stopping and deleting the datafeed.
*
* @param force When {@code true} forcefully delete a started datafeed. Defaults to {@code false}
*/
public void setForce(boolean force) {
this.force = force;
}

@Override
public ActionRequestValidationException validate() {
return null;
}

@Override
public int hashCode() {
return Objects.hash(datafeedId, force);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}

if (obj == null || obj.getClass() != getClass()) {
return false;
}

DeleteDatafeedRequest other = (DeleteDatafeedRequest) obj;
return Objects.equals(datafeedId, other.datafeedId) && Objects.equals(force, other.force);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.elasticsearch.client.ml.CloseJobRequest;
import org.elasticsearch.client.ml.DeleteDatafeedRequest;
import org.elasticsearch.client.ml.DeleteForecastRequest;
import org.elasticsearch.client.ml.DeleteJobRequest;
import org.elasticsearch.client.ml.FlushJobRequest;
Expand Down Expand Up @@ -223,6 +224,20 @@ public void testPutDatafeed() throws IOException {
}
}

public void testDeleteDatafeed() {
String datafeedId = randomAlphaOfLength(10);
DeleteDatafeedRequest deleteDatafeedRequest = new DeleteDatafeedRequest(datafeedId);

Request request = MLRequestConverters.deleteDatafeed(deleteDatafeedRequest);
assertEquals(HttpDelete.METHOD_NAME, request.getMethod());
assertEquals("/_xpack/ml/datafeeds/" + datafeedId, request.getEndpoint());
assertEquals(Boolean.toString(false), request.getParameters().get("force"));

deleteDatafeedRequest.setForce(true);
request = MLRequestConverters.deleteDatafeed(deleteDatafeedRequest);
assertEquals(Boolean.toString(true), request.getParameters().get("force"));
}

public void testDeleteForecast() throws Exception {
String jobId = randomAlphaOfLength(10);
DeleteForecastRequest deleteForecastRequest = new DeleteForecastRequest(jobId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.ml.CloseJobRequest;
import org.elasticsearch.client.ml.CloseJobResponse;
import org.elasticsearch.client.ml.DeleteDatafeedRequest;
import org.elasticsearch.client.ml.DeleteForecastRequest;
import org.elasticsearch.client.ml.DeleteJobRequest;
import org.elasticsearch.client.ml.DeleteJobResponse;
import org.elasticsearch.client.ml.FlushJobRequest;
import org.elasticsearch.client.ml.FlushJobResponse;
import org.elasticsearch.client.ml.ForecastJobRequest;
Expand Down Expand Up @@ -129,7 +129,7 @@ public void testDeleteJob() throws Exception {
MachineLearningClient machineLearningClient = highLevelClient().machineLearning();
machineLearningClient.putJob(new PutJobRequest(job), RequestOptions.DEFAULT);

DeleteJobResponse response = execute(new DeleteJobRequest(jobId),
AcknowledgedResponse response = execute(new DeleteJobRequest(jobId),
machineLearningClient::deleteJob,
machineLearningClient::deleteJobAsync);

Expand Down Expand Up @@ -312,6 +312,22 @@ public void testPutDatafeed() throws Exception {
assertThat(createdDatafeed.getIndices(), equalTo(datafeedConfig.getIndices()));
}

public void testDeleteDatafeed() throws Exception {
String jobId = randomValidJobId();
Job job = buildJob(jobId);
MachineLearningClient machineLearningClient = highLevelClient().machineLearning();
machineLearningClient.putJob(new PutJobRequest(job), RequestOptions.DEFAULT);

String datafeedId = "datafeed-" + jobId;
DatafeedConfig datafeedConfig = DatafeedConfig.builder(datafeedId, jobId).setIndices("some_data_index").build();
execute(new PutDatafeedRequest(datafeedConfig), machineLearningClient::putDatafeed, machineLearningClient::putDatafeedAsync);

AcknowledgedResponse response = execute(new DeleteDatafeedRequest(datafeedId), machineLearningClient::deleteDatafeed,
machineLearningClient::deleteDatafeedAsync);

assertTrue(response.isAcknowledged());
}

public void testDeleteForecast() throws Exception {
String jobId = "test-delete-forecast";

Expand Down
Loading

0 comments on commit 426b359

Please sign in to comment.